mv com/google/domain/registry google/registry

This change renames directories in preparation for the great package
rename. The repository is now in a broken state because the code
itself hasn't been updated. However this should ensure that git
correctly preserves history for each file.
This commit is contained in:
Justine Tunney 2016-05-13 18:55:08 -04:00
parent a41677aea1
commit 5012893c1d
2396 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,23 @@
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.domain.registry.model.smd;
/**
* Marker interface for signed mark types.
*
* @see EncodedSignedMark
* @see SignedMark
*/
public interface AbstractSignedMark {}

View file

@ -0,0 +1,76 @@
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.domain.registry.model.smd;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.io.BaseEncoding.base64;
import com.google.appengine.api.datastore.Text;
import com.google.domain.registry.model.ImmutableObject;
import com.googlecode.objectify.annotation.Embed;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
* Encoded data representation of a {@link SignedMark} object.
*
* @see <a href="http://tools.ietf.org/html/draft-lozano-tmch-smd-02#section-2.4">
* draft-lozano-tmch-smd-02 § 2.4</a>
*/
@Embed
@XmlRootElement(name = "encodedSignedMark")
public class EncodedSignedMark extends ImmutableObject implements AbstractSignedMark {
private static final String ENCODING_DEFAULT = "base64";
/** Encoding used for contained data. Default is {@value #ENCODING_DEFAULT}. */
@XmlAttribute
String encoding;
/**
* Encoded data. This is stored in a Text field rather than a String because Objectify cannot
* autoconvert Strings greater than 500 characters to Text within {@link Embed} collections.
*/
@XmlValue
@XmlJavaTypeAdapter(RemoveWhitespaceTextAdapter.class)
Text encodedData;
public String getEncoding() {
return firstNonNull(encoding, ENCODING_DEFAULT);
}
public String getEncodedData() {
return encodedData == null ? "" : encodedData.getValue();
}
public static EncodedSignedMark create(String encoding, String encodedData) {
EncodedSignedMark instance = new EncodedSignedMark();
instance.encoding = encoding;
instance.encodedData = new Text(encodedData);
return instance;
}
public byte[] getBytes() {
try {
return base64().decode(getEncodedData());
} catch (IllegalArgumentException e) {
throw new IllegalStateException(e); // Turn e into a runtime exception.
}
}
}

View file

@ -0,0 +1,69 @@
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.domain.registry.model.smd;
import com.google.domain.registry.model.ImmutableObject;
import com.google.domain.registry.model.mark.MarkPhoneNumber;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
/** Holds information about the issuer of a mark registration. */
public class IssuerInfo extends ImmutableObject {
@XmlAttribute(name = "issuerID")
String issuerId;
/** The issuer identifier. */
@XmlElement(name = "issuerID")
String id;
/** The organization name of the issuer. */
@XmlElement(name = "org")
String organization;
/** Issuer customer support email address. */
String email;
/** The HTTP URL of the issuer's site. */
String url;
/** The issuer's voice telephone number. */
MarkPhoneNumber voice;
public String getIssuerId() {
return issuerId;
}
public String getId() {
return id;
}
public String getOrganization() {
return organization;
}
public String getEmail() {
return email;
}
public String getUrl() {
return url;
}
public MarkPhoneNumber getVoice() {
return voice;
}
}

View file

@ -0,0 +1,39 @@
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.domain.registry.model.smd;
import com.google.appengine.api.datastore.Text;
import com.google.common.base.CharMatcher;
import javax.xml.bind.annotation.adapters.XmlAdapter;
/**
* {@link XmlAdapter} which removes all whitespace from a string and then converts the result a
* {@link Text} object.
*/
public class RemoveWhitespaceTextAdapter extends XmlAdapter<String, Text> {
private static final CharMatcher WHITESPACE = CharMatcher.anyOf(" \t\r\n");
@Override
public Text unmarshal(String value) {
return (value == null) ? null : new Text(WHITESPACE.removeFrom(value));
}
@Override
public String marshal(Text t) {
return (t == null) ? null : t.getValue();
}
}

View file

@ -0,0 +1,86 @@
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.domain.registry.model.smd;
import com.google.domain.registry.model.ImmutableObject;
import com.google.domain.registry.model.mark.Mark;
import org.joda.time.DateTime;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Represents an XML fragment that is digitally signed by the TMCH to prove ownership over a mark.
**/
@XmlRootElement(name = "signedMark")
public class SignedMark extends ImmutableObject implements AbstractSignedMark {
/** XSD ID for use with an IDREF URI from the Signature element. */
@XmlAttribute(name = "id")
String xsdId;
/**
* Signed mark identifier. This is a concatenation of the local identifier, followed by a hyphen,
* followed by the issuer identifier.
*/
String id;
/** Information of the issuer of the mark registration. */
IssuerInfo issuerInfo;
/** Creation time of this signed mark. */
@XmlElement(name = "notBefore")
DateTime creationTime;
/** Expiration time of this signed mark. */
@XmlElement(name = "notAfter")
DateTime expirationTime;
/** Mark information. */
@XmlElementRef(type = Mark.class)
Mark mark;
/**
* Digital signature of the signed mark. Note that we don't unmarshal this data, as there is
* already an existing Java library to handle validation of this signature.
*
* @see javax.xml.crypto.dsig.XMLSignature
*/
@XmlElement(name = "Signature", namespace = "http://www.w3.org/2000/09/xmldsig#")
Object xmlSignature;
public String getId() {
return id;
}
public DateTime getCreationTime() {
return creationTime;
}
public DateTime getExpirationTime() {
return expirationTime;
}
public Mark getMark() {
return mark;
}
public boolean hasSignature() {
return xmlSignature != null;
}
}

View file

@ -0,0 +1,191 @@
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.domain.registry.model.smd;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Iterables.isEmpty;
import static com.google.domain.registry.model.common.EntityGroupRoot.getCrossTldKey;
import static com.google.domain.registry.model.ofy.ObjectifyService.allocateId;
import static com.google.domain.registry.model.ofy.ObjectifyService.ofy;
import static com.google.domain.registry.util.CacheUtils.memoizeWithShortExpiration;
import static com.google.domain.registry.util.DateTimeUtils.START_OF_TIME;
import static com.google.domain.registry.util.DateTimeUtils.isBeforeOrAt;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.domain.registry.model.ImmutableObject;
import com.google.domain.registry.model.annotations.NotBackedUp;
import com.google.domain.registry.model.annotations.NotBackedUp.Reason;
import com.google.domain.registry.model.common.EntityGroupRoot;
import com.google.domain.registry.util.CollectionUtils;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.VoidWork;
import com.googlecode.objectify.Work;
import com.googlecode.objectify.annotation.EmbedMap;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Ignore;
import com.googlecode.objectify.annotation.OnSave;
import com.googlecode.objectify.annotation.Parent;
import org.joda.time.DateTime;
import java.util.Map;
/**
* Signed Mark Data Revocation List (SMDRL).
* <p>
* Represents a SMDRL file downloaded from the TMCH MarksDB each day. The list holds the ids of
* all the {@link SignedMark SignedMarks} that have been revoked. A new list is created for each
* new file that's created, depending on the timestamp.
* <p>
* We'll be putting the entire table into a single entity for the sake of performance. But in order
* to avoid exceeding the one megabyte max entity size limit, we'll also be sharding that entity
* into multiple entities, each entity containing {@value #SHARD_SIZE} rows.
*
* @see com.google.domain.registry.tmch.SmdrlCsvParser
* @see "http://tools.ietf.org/html/draft-lozano-tmch-func-spec-08#section-6.2"
*/
@Entity
@NotBackedUp(reason = Reason.EXTERNALLY_SOURCED)
public class SignedMarkRevocationList extends ImmutableObject {
@VisibleForTesting
static final int SHARD_SIZE = 10000;
/** Common ancestor for queries. */
@Parent
Key<EntityGroupRoot> parent = getCrossTldKey();
/** ID for the sharded entity. */
@Id
long id;
/** Time when this list was last updated, as specified in the first line of the CSV file. */
DateTime creationTime;
/** A map from SMD IDs to revocation time. */
@EmbedMap
Map</*@MatchesPattern("[0-9]+-[0-9]+")*/ String, DateTime> revokes;
/** Indicates that this is a shard rather than a "full" list. */
@Ignore
boolean isShard;
/**
* A cached supplier that fetches the SMDRL shards from the datastore and recombines them into a
* single {@link SignedMarkRevocationList} object.
*/
private static final Supplier<SignedMarkRevocationList> CACHE =
memoizeWithShortExpiration(new Supplier<SignedMarkRevocationList>() {
@Override
public SignedMarkRevocationList get() {
// Open a new transactional read even if we are in a transaction currently.
return ofy().transactNewReadOnly(new Work<SignedMarkRevocationList>() {
@Override
public SignedMarkRevocationList run() {
Iterable<SignedMarkRevocationList> shards = ofy()
.load()
.type(SignedMarkRevocationList.class)
.ancestor(getCrossTldKey());
DateTime creationTime =
isEmpty(shards)
? START_OF_TIME
: checkNotNull(Iterables.get(shards, 0).creationTime, "creationTime");
ImmutableMap.Builder<String, DateTime> revokes = new ImmutableMap.Builder<>();
for (SignedMarkRevocationList shard : shards) {
revokes.putAll(shard.revokes);
checkState(
creationTime.equals(shard.creationTime),
"Inconsistent creation times: %s vs. %s", creationTime, shard.creationTime);
}
return create(creationTime, revokes.build());
}});
}});
/** Return a single logical instance that combines all the datastore shards. */
public static SignedMarkRevocationList get() {
return CACHE.get();
}
/** Create a new {@link SignedMarkRevocationList} without saving it. */
public static SignedMarkRevocationList create(
DateTime creationTime, ImmutableMap<String, DateTime> revokes) {
SignedMarkRevocationList instance = new SignedMarkRevocationList();
instance.creationTime = checkNotNull(creationTime, "creationTime");
instance.revokes = checkNotNull(revokes, "revokes");
return instance;
}
/** Returns {@code true} if the SMD ID has been revoked at the given point in time. */
public boolean isSmdRevoked(String smdId, DateTime now) {
DateTime revoked = revokes.get(checkNotNull(smdId, "smdId"));
if (revoked == null) {
return false;
}
return isBeforeOrAt(revoked, now);
}
/** Returns the creation timestamp specified at the top of the SMDRL CSV file. */
public DateTime getCreationTime() {
return creationTime;
}
/** Returns the number of revocations. */
public int size() {
return revokes.size();
}
/** Save this list to the datastore in sharded form. Returns {@code this}. */
public SignedMarkRevocationList save() {
ofy().transact(new VoidWork() {
@Override
public void vrun() {
ofy().deleteWithoutBackup().keys(ofy()
.load()
.type(SignedMarkRevocationList.class)
.ancestor(getCrossTldKey())
.keys());
ofy().saveWithoutBackup().entities(FluentIterable
.from(CollectionUtils.partitionMap(revokes, SHARD_SIZE))
.transform(new Function<ImmutableMap<String, DateTime>, SignedMarkRevocationList>() {
@Override
public SignedMarkRevocationList apply(ImmutableMap<String, DateTime> shardRevokes) {
SignedMarkRevocationList shard = create(creationTime, shardRevokes);
shard.id = allocateId();
shard.isShard = true; // Avoid the exception in disallowUnshardedSaves().
return shard;
}}));
}});
return this;
}
/** As a safety mechanism, fail if someone tries to save this class directly. */
@OnSave
void disallowUnshardedSaves() {
if (!isShard) {
throw new UnshardedSaveException();
}
}
/** Exception when trying to directly save a {@link SignedMarkRevocationList} without sharding. */
public static class UnshardedSaveException extends RuntimeException {}
}

View file

@ -0,0 +1,31 @@
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
@XmlSchema(
namespace = "urn:ietf:params:xml:ns:signedMark-1.0",
xmlns = @XmlNs(prefix = "smd", namespaceURI = "urn:ietf:params:xml:ns:signedMark-1.0"),
elementFormDefault = XmlNsForm.QUALIFIED)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlJavaTypeAdapter(UtcDateTimeAdapter.class)
package com.google.domain.registry.model.smd;
import com.google.domain.registry.xml.UtcDateTimeAdapter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;