commit d242a2aa4d37ff0dcaf3b0093548ccb139c8ce46 Author: Karsten Loesing karsten.loesing@gmx.net Date: Thu May 4 10:05:23 2017 +0200
Add descriptor digest to vote and streamline method names.
Implements #20333. --- CHANGELOG.md | 2 + .../org/torproject/descriptor/DirSourceEntry.java | 10 +++++ .../descriptor/DirectoryKeyCertificate.java | 10 +++++ .../torproject/descriptor/DirectorySignature.java | 11 +++++ .../torproject/descriptor/ExtraInfoDescriptor.java | 47 ++++++++++++++++++++++ .../org/torproject/descriptor/Microdescriptor.java | 11 +++++ .../torproject/descriptor/NetworkStatusEntry.java | 11 +++++ .../org/torproject/descriptor/RelayDirectory.java | 11 +++++ .../torproject/descriptor/RelayNetworkStatus.java | 11 +++++ .../descriptor/RelayNetworkStatusConsensus.java | 13 +++++- .../descriptor/RelayNetworkStatusVote.java | 10 ++++- .../torproject/descriptor/ServerDescriptor.java | 46 +++++++++++++++++++++ .../descriptor/impl/DirSourceEntryImpl.java | 5 +++ .../impl/DirectoryKeyCertificateImpl.java | 5 +++ .../descriptor/impl/DirectorySignatureImpl.java | 5 +++ .../descriptor/impl/ExtraInfoDescriptorImpl.java | 20 +++++++++ .../descriptor/impl/MicrodescriptorImpl.java | 5 +++ .../descriptor/impl/NetworkStatusEntryImpl.java | 5 +++ .../descriptor/impl/RelayDirectoryImpl.java | 5 +++ .../impl/RelayNetworkStatusConsensusImpl.java | 5 +++ .../descriptor/impl/RelayNetworkStatusImpl.java | 5 +++ .../impl/RelayNetworkStatusVoteImpl.java | 43 +++++++++++++++++++- .../descriptor/impl/ServerDescriptorImpl.java | 20 +++++++++ .../impl/ExtraInfoDescriptorImplTest.java | 8 ++-- .../impl/RelayNetworkStatusConsensusImplTest.java | 2 +- .../impl/RelayNetworkStatusVoteImplTest.java | 9 +++-- .../descriptor/impl/ServerDescriptorImplTest.java | 8 ++-- 27 files changed, 328 insertions(+), 15 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md index e713a42..e636780 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,12 @@ - Add support for six new key-value pairs added by OnionPerf. - Fix a bug where DescriptorIndexCollector would not delete extraneous local files if remote paths start with /. + - Add previously missing method to obtain the digest of a vote.
* Minor changes - Accept extra arguments in statistics-related extra-info descriptor lines, as permitted by dir-spec.txt. + - Streamline digest method names.
# Changes in version 1.6.0 - 2017-02-17 diff --git a/src/main/java/org/torproject/descriptor/DirSourceEntry.java b/src/main/java/org/torproject/descriptor/DirSourceEntry.java index 49d7f8a..9996ff2 100644 --- a/src/main/java/org/torproject/descriptor/DirSourceEntry.java +++ b/src/main/java/org/torproject/descriptor/DirSourceEntry.java @@ -89,8 +89,18 @@ public interface DirSourceEntry { * Return the SHA-1 vote digest, encoded as 40 lower-case hexadecimal * characters. * + * @deprecated Renamed to {@link #getVoteDigestSha1Hex()}. + * * @since 1.0.0 */ public String getVoteDigest(); + + /** + * Return the SHA-1 vote digest, encoded as 40 lower-case hexadecimal + * characters. + * + * @since 1.7.0 + */ + public String getVoteDigestSha1Hex(); }
diff --git a/src/main/java/org/torproject/descriptor/DirectoryKeyCertificate.java b/src/main/java/org/torproject/descriptor/DirectoryKeyCertificate.java index 5a7877b..f2d37ad 100644 --- a/src/main/java/org/torproject/descriptor/DirectoryKeyCertificate.java +++ b/src/main/java/org/torproject/descriptor/DirectoryKeyCertificate.java @@ -102,8 +102,18 @@ public interface DirectoryKeyCertificate extends Descriptor { * Return the SHA-1 certificate digest, encoded as 40 lower-case * hexadecimal characters. * + * @deprecated Renamed to {@link #getDigestSha1Hex()}. + * * @since 1.0.0 */ public String getCertificateDigest(); + + /** + * Return the SHA-1 certificate digest, encoded as 40 lower-case + * hexadecimal characters. + * + * @since 1.7.0 + */ + public String getDigestSha1Hex(); }
diff --git a/src/main/java/org/torproject/descriptor/DirectorySignature.java b/src/main/java/org/torproject/descriptor/DirectorySignature.java index 0b1c993..bb3d5c4 100644 --- a/src/main/java/org/torproject/descriptor/DirectorySignature.java +++ b/src/main/java/org/torproject/descriptor/DirectorySignature.java @@ -37,11 +37,22 @@ public interface DirectorySignature { * in the version 3 directory protocol, encoded as 40 upper-case * hexadecimal characters. * + * @deprecated Renamed to {@link #getSigningKeyDigestSha1Hex()}. + * * @since 1.0.0 */ public String getSigningKeyDigest();
/** + * Return the SHA-1 digest of the authority's medium-term signing key + * in the version 3 directory protocol, encoded as 40 upper-case + * hexadecimal characters. + * + * @since 1.7.0 + */ + public String getSigningKeyDigestSha1Hex(); + + /** * Return the directory signature string made with the authority's * identity key in the version 3 directory protocol. * diff --git a/src/main/java/org/torproject/descriptor/ExtraInfoDescriptor.java b/src/main/java/org/torproject/descriptor/ExtraInfoDescriptor.java index cd63394..bb1cbe6 100644 --- a/src/main/java/org/torproject/descriptor/ExtraInfoDescriptor.java +++ b/src/main/java/org/torproject/descriptor/ExtraInfoDescriptor.java @@ -48,20 +48,43 @@ public interface ExtraInfoDescriptor extends Descriptor { * characters, that is used to reference this descriptor from a server * descriptor. * + * @deprecated Renamed to {@link #getDigestSha1Hex()}. + * * @since 1.0.0 */ public String getExtraInfoDigest();
/** + * Return the SHA-1 descriptor digest, encoded as 40 lower-case (relay + * descriptors) or upper-case (bridge descriptors) hexadecimal + * characters, that is used to reference this descriptor from a server + * descriptor. + * + * @since 1.7.0 + */ + public String getDigestSha1Hex(); + + /** * Return the SHA-256 descriptor digest, encoded as 43 base64 * characters without padding characters, that may be used to reference * this descriptor from a server descriptor. * + * @deprecated Renamed to {@link #getDigestSha256Base64()}. + * * @since 1.1.0 */ public String getExtraInfoDigestSha256();
/** + * Return the SHA-256 descriptor digest, encoded as 43 base64 + * characters without padding characters, that may be used to reference + * this descriptor from a server descriptor. + * + * @since 1.7.0 + */ + public String getDigestSha256Base64(); + + /** * Return the server's nickname consisting of 1 to 19 alphanumeric * characters. * @@ -112,21 +135,45 @@ public interface ExtraInfoDescriptor extends Descriptor { * upper-case hexadecimal characters, or null if no GeoIP database * digest is included. * + * @deprecated Renamed to {@link #getGeoipDbDigestSha1Hex()}. + * * @since 1.0.0 */ public String getGeoipDbDigest();
/** + * Return a SHA-1 digest of the GeoIP database file used by this server + * to resolve client IP addresses to country codes, encoded as 40 + * upper-case hexadecimal characters, or null if no GeoIP database + * digest is included. + * + * @since 1.7.0 + */ + public String getGeoipDbDigestSha1Hex(); + + /** * Return a SHA-1 digest of the GeoIPv6 database file used by this * server to resolve client IP addresses to country codes, encoded as 40 * upper-case hexadecimal characters, or null if no GeoIPv6 database * digest is included. * + * @deprecated Renamed to {@link #getGeoip6DbDigestSha1Hex()}. + * * @since 1.0.0 */ public String getGeoip6DbDigest();
/** + * Return a SHA-1 digest of the GeoIPv6 database file used by this + * server to resolve client IP addresses to country codes, encoded as 40 + * upper-case hexadecimal characters, or null if no GeoIPv6 database + * digest is included. + * + * @since 1.7.0 + */ + public String getGeoip6DbDigestSha1Hex(); + + /** * Return the time in milliseconds since the epoch when the included * directory request statistics interval ended, or -1 if no such * statistics are included. diff --git a/src/main/java/org/torproject/descriptor/Microdescriptor.java b/src/main/java/org/torproject/descriptor/Microdescriptor.java index 155c799..b49b8bb 100644 --- a/src/main/java/org/torproject/descriptor/Microdescriptor.java +++ b/src/main/java/org/torproject/descriptor/Microdescriptor.java @@ -28,11 +28,22 @@ public interface Microdescriptor extends Descriptor { * characters without padding characters, that is used to reference this * descriptor from a vote or microdescriptor consensus. * + * @deprecated Renamed to {@link #getDigestSha256Base64()}. + * * @since 1.0.0 */ public String getMicrodescriptorDigest();
/** + * Return the SHA-256 descriptor digest, encoded as 43 base64 + * characters without padding characters, that is used to reference this + * descriptor from a vote or microdescriptor consensus. + * + * @since 1.7.0 + */ + public String getDigestSha256Base64(); + + /** * Return the RSA-1024 public key in PEM format used to encrypt CREATE * cells for this server, or null if the descriptor doesn't contain an * onion key. diff --git a/src/main/java/org/torproject/descriptor/NetworkStatusEntry.java b/src/main/java/org/torproject/descriptor/NetworkStatusEntry.java index ba413bb..c59eab9 100644 --- a/src/main/java/org/torproject/descriptor/NetworkStatusEntry.java +++ b/src/main/java/org/torproject/descriptor/NetworkStatusEntry.java @@ -93,11 +93,22 @@ public interface NetworkStatusEntry { * containing network status is a vote or microdesc consensus, or null * otherwise. * + * @deprecated Renamed to {@link #getMicrodescriptorDigestsSha256Base64()}. + * * @since 1.0.0 */ public Set<String> getMicrodescriptorDigests();
/** + * Return the (possibly empty) set of microdescriptor digests if the + * containing network status is a vote or microdesc consensus, or null + * otherwise. + * + * @since 1.7.0 + */ + public Set<String> getMicrodescriptorDigestsSha256Base64(); + + /** * Return additional IP addresses and TCP ports where this server * accepts TLS connections for the main OR protocol, or an empty list if * the network status doesn't contain any such additional addresses and diff --git a/src/main/java/org/torproject/descriptor/RelayDirectory.java b/src/main/java/org/torproject/descriptor/RelayDirectory.java index fb07a41..dd696cf 100644 --- a/src/main/java/org/torproject/descriptor/RelayDirectory.java +++ b/src/main/java/org/torproject/descriptor/RelayDirectory.java @@ -97,8 +97,19 @@ public interface RelayDirectory extends Descriptor { * hexadecimal characters, that the directory authority used to sign the * directory. * + * @deprecated Renamed to {@link #getDigestSha1Hex()}. + * * @since 1.0.0 */ public String getDirectoryDigest(); + + /** + * Return the SHA-1 directory digest, encoded as 40 lower-case + * hexadecimal characters, that the directory authority used to sign the + * directory. + * + * @since 1.7.0 + */ + public String getDigestSha1Hex(); }
diff --git a/src/main/java/org/torproject/descriptor/RelayNetworkStatus.java b/src/main/java/org/torproject/descriptor/RelayNetworkStatus.java index 86361cd..b14d0c3 100644 --- a/src/main/java/org/torproject/descriptor/RelayNetworkStatus.java +++ b/src/main/java/org/torproject/descriptor/RelayNetworkStatus.java @@ -169,8 +169,19 @@ public interface RelayNetworkStatus extends Descriptor { * characters, that the directory authority used to sign the network * status. * + * @deprecated Renamed to {@link #getDigestSha1Hex()}. + * * @since 1.0.0 */ public String getStatusDigest(); + + /** + * Return the SHA-1 status digest, encoded as 40 lower-case hexadecimal + * characters, that the directory authority used to sign the network + * status. + * + * @since 1.7.0 + */ + public String getDigestSha1Hex(); }
diff --git a/src/main/java/org/torproject/descriptor/RelayNetworkStatusConsensus.java b/src/main/java/org/torproject/descriptor/RelayNetworkStatusConsensus.java index 57a8dd6..fe66007 100644 --- a/src/main/java/org/torproject/descriptor/RelayNetworkStatusConsensus.java +++ b/src/main/java/org/torproject/descriptor/RelayNetworkStatusConsensus.java @@ -282,12 +282,23 @@ public interface RelayNetworkStatusConsensus extends Descriptor { public SortedMap<String, Integer> getBandwidthWeights();
/** - * Return the SHA-1 digest of this consensus, encoded as 40 upper-case + * Return the SHA-1 digest of this consensus, encoded as 40 lower-case * hexadecimal characters that directory authorities use to sign the * consensus. * + * @deprecated Renamed to {@link #getDigestSha1Hex()}. + * * @since 1.0.0 */ public String getConsensusDigest(); + + /** + * Return the SHA-1 digest of this consensus, encoded as 40 lower-case + * hexadecimal characters that directory authorities use to sign the + * consensus. + * + * @since 1.7.0 + */ + public String getDigestSha1Hex(); }
diff --git a/src/main/java/org/torproject/descriptor/RelayNetworkStatusVote.java b/src/main/java/org/torproject/descriptor/RelayNetworkStatusVote.java index cfb012b..5d9d039 100644 --- a/src/main/java/org/torproject/descriptor/RelayNetworkStatusVote.java +++ b/src/main/java/org/torproject/descriptor/RelayNetworkStatusVote.java @@ -415,7 +415,7 @@ public interface RelayNetworkStatusVote extends Descriptor { * @deprecated Removed in order to be more explicit that authorities may * use different digest algorithms than "sha1"; see * {@link #getSignatures()} and - * {@link DirectorySignature#getSigningKeyDigest()} for + * {@link DirectorySignature#getSigningKeyDigestSha1Hex()} for * alternatives. * * @since 1.0.0 @@ -491,5 +491,13 @@ public interface RelayNetworkStatusVote extends Descriptor { * @since 1.3.0 */ public List<DirectorySignature> getSignatures(); + + /** + * Return the SHA-1 digest of this vote, encoded as 40 lower-case hexadecimal + * characters that is used to reference this vote from a consensus. + * + * @since 1.7.0 + */ + public String getDigestSha1Hex(); }
diff --git a/src/main/java/org/torproject/descriptor/ServerDescriptor.java b/src/main/java/org/torproject/descriptor/ServerDescriptor.java index 4ecade6..3ac0cc9 100644 --- a/src/main/java/org/torproject/descriptor/ServerDescriptor.java +++ b/src/main/java/org/torproject/descriptor/ServerDescriptor.java @@ -51,20 +51,43 @@ public interface ServerDescriptor extends Descriptor { * characters, that is used to reference this descriptor from a network * status descriptor. * + * @deprecated Renamed to {@link #getDigestSha1Hex()}. + * * @since 1.0.0 */ public String getServerDescriptorDigest();
/** + * Return the SHA-1 descriptor digest, encoded as 40 lower-case (relay + * descriptors) or upper-case (bridge descriptors) hexadecimal + * characters, that is used to reference this descriptor from a network + * status descriptor. + * + * @since 1.7.0 + */ + public String getDigestSha1Hex(); + + /** * Return the SHA-256 descriptor digest, encoded as 43 base64 * characters without padding characters, that may be used to reference * this server descriptor from a network status descriptor. * + * @deprecated Renamed to {@link #getDigestSha256Base64()}. + * * @since 1.1.0 */ public String getServerDescriptorDigestSha256();
/** + * Return the SHA-256 descriptor digest, encoded as 43 base64 + * characters without padding characters, that may be used to reference + * this server descriptor from a network status descriptor. + * + * @since 1.7.0 + */ + public String getDigestSha256Base64(); + + /** * Return the server's nickname consisting of 1 to 19 alphanumeric * characters. * @@ -299,21 +322,44 @@ public interface ServerDescriptor extends Descriptor { * encoded as 40 upper-case hexadecimal characters, or null if the * server did not upload a corresponding extra-info descriptor. * + * @deprecated Renamed to {@link #getExtraInfoDigestSha1Hex()}. + * * @since 1.0.0 */ public String getExtraInfoDigest();
/** + * Return the SHA-1 digest of the server's extra-info descriptor, + * encoded as 40 upper-case hexadecimal characters, or null if the + * server did not upload a corresponding extra-info descriptor. + * + * @since 1.7.0 + */ + public String getExtraInfoDigestSha1Hex(); + + /** * Return the SHA-256 digest of the server's extra-info descriptor, * encoded as 43 base64 characters without padding characters, or null * if the server either did not upload a corresponding extra-info * descriptor or did not refer to it using a SHA-256 digest. * + * @deprecated Renamed to {@link #getExtraInfoDigestSha256Base64()}. + * * @since 1.1.0 */ public String getExtraInfoDigestSha256();
/** + * Return the SHA-256 digest of the server's extra-info descriptor, + * encoded as 43 base64 characters without padding characters, or null + * if the server either did not upload a corresponding extra-info + * descriptor or did not refer to it using a SHA-256 digest. + * + * @since 1.7.0 + */ + public String getExtraInfoDigestSha256Base64(); + + /** * Return the list of hidden service descriptor version numbers that * this server stores and serves, or null if it doesn't store and serve * any hidden service descriptors. diff --git a/src/main/java/org/torproject/descriptor/impl/DirSourceEntryImpl.java b/src/main/java/org/torproject/descriptor/impl/DirSourceEntryImpl.java index 9e5995b..539d211 100644 --- a/src/main/java/org/torproject/descriptor/impl/DirSourceEntryImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/DirSourceEntryImpl.java @@ -228,6 +228,11 @@ public class DirSourceEntryImpl implements DirSourceEntry {
@Override public String getVoteDigest() { + return this.getVoteDigestSha1Hex(); + } + + @Override + public String getVoteDigestSha1Hex() { return this.voteDigest; } } diff --git a/src/main/java/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java b/src/main/java/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java index df479f4..64df7aa 100644 --- a/src/main/java/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java @@ -312,6 +312,11 @@ public class DirectoryKeyCertificateImpl extends DescriptorImpl
@Override public String getCertificateDigest() { + return this.getDigestSha1Hex(); + } + + @Override + public String getDigestSha1Hex() { return this.certificateDigest; } } diff --git a/src/main/java/org/torproject/descriptor/impl/DirectorySignatureImpl.java b/src/main/java/org/torproject/descriptor/impl/DirectorySignatureImpl.java index 995f525..7cf427a 100644 --- a/src/main/java/org/torproject/descriptor/impl/DirectorySignatureImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/DirectorySignatureImpl.java @@ -109,6 +109,11 @@ public class DirectorySignatureImpl implements DirectorySignature {
@Override public String getSigningKeyDigest() { + return this.getSigningKeyDigestSha1Hex(); + } + + @Override + public String getSigningKeyDigestSha1Hex() { return this.signingKeyDigest; }
diff --git a/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java index bbaae19..e2b3827 100644 --- a/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java @@ -889,6 +889,11 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
@Override public String getExtraInfoDigest() { + return this.getDigestSha1Hex(); + } + + @Override + public String getDigestSha1Hex() { return this.extraInfoDigest; }
@@ -896,6 +901,11 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
@Override public String getExtraInfoDigestSha256() { + return this.getDigestSha256Base64(); + } + + @Override + public String getDigestSha256Base64() { return this.extraInfoDigestSha256; }
@@ -938,6 +948,11 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
@Override public String getGeoipDbDigest() { + return this.getGeoipDbDigestSha1Hex(); + } + + @Override + public String getGeoipDbDigestSha1Hex() { return this.geoipDbDigest; }
@@ -945,6 +960,11 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
@Override public String getGeoip6DbDigest() { + return this.getGeoip6DbDigestSha1Hex(); + } + + @Override + public String getGeoip6DbDigestSha1Hex() { return this.geoip6DbDigest; }
diff --git a/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java index b199a20..5c94371 100644 --- a/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java @@ -264,6 +264,11 @@ public class MicrodescriptorImpl extends DescriptorImpl
@Override public String getMicrodescriptorDigest() { + return this.getDigestSha256Base64(); + } + + @Override + public String getDigestSha256Base64() { return this.microdescriptorDigest; }
diff --git a/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java b/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java index f67e6bd..152546a 100644 --- a/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java @@ -337,6 +337,11 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
@Override public Set<String> getMicrodescriptorDigests() { + return this.getMicrodescriptorDigestsSha256Base64(); + } + + @Override + public Set<String> getMicrodescriptorDigestsSha256Base64() { return this.microdescriptorDigests == null ? null : new HashSet<>(this.microdescriptorDigests); } diff --git a/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java b/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java index ff32934..fc8f07b 100644 --- a/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java @@ -556,6 +556,11 @@ public class RelayDirectoryImpl extends DescriptorImpl
@Override public String getDirectoryDigest() { + return this.getDigestSha1Hex(); + } + + @Override + public String getDigestSha1Hex() { return this.directoryDigest; } } diff --git a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java index dcb8938..ef135d4 100644 --- a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java @@ -397,6 +397,11 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl
@Override public String getConsensusDigest() { + return this.getDigestSha1Hex(); + } + + @Override + public String getDigestSha1Hex() { return this.consensusDigest; }
diff --git a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java index 7c01e3c..143540c 100644 --- a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java @@ -299,6 +299,11 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
@Override public String getStatusDigest() { + return this.getDigestSha1Hex(); + } + + @Override + public String getDigestSha1Hex() { return this.statusDigest; }
diff --git a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java index 1f64173..05f5cc2 100644 --- a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java @@ -7,6 +7,9 @@ import org.torproject.descriptor.DescriptorParseException; import org.torproject.descriptor.DirectorySignature; import org.torproject.descriptor.RelayNetworkStatusVote;
+import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; @@ -18,6 +21,7 @@ import java.util.SortedMap; import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; +import javax.xml.bind.DatatypeConverter;
/* Contains a network status vote. */ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl @@ -64,6 +68,36 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl this.checkAtLeastOnceKeywords(atLeastOnceKeywords); this.checkFirstKeyword("network-status-version"); this.clearParsedKeywords(); + this.calculateDigest(); + } + + private void calculateDigest() throws DescriptorParseException { + try { + String ascii = new String(this.getRawDescriptorBytes(), "US-ASCII"); + String startToken = "network-status-version "; + String sigToken = "\ndirectory-signature "; + if (!ascii.contains(sigToken)) { + return; + } + int start = ascii.indexOf(startToken); + int sig = ascii.indexOf(sigToken) + sigToken.length(); + if (start >= 0 && sig >= 0 && sig > start) { + byte[] forDigest = new byte[sig - start]; + System.arraycopy(this.getRawDescriptorBytes(), start, + forDigest, 0, sig - start); + this.digestSha1Hex = DatatypeConverter.printHexBinary( + MessageDigest.getInstance("SHA-1").digest(forDigest)) + .toLowerCase(); + } + } catch (UnsupportedEncodingException e) { + /* Handle below. */ + } catch (NoSuchAlgorithmException e) { + /* Handle below. */ + } + if (this.digestSha1Hex == null) { + throw new DescriptorParseException("Could not calculate vote " + + "digest."); + } }
protected void parseHeader(byte[] headerBytes) @@ -615,6 +649,13 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl } }
+ private String digestSha1Hex; + + @Override + public String getDigestSha1Hex() { + return this.digestSha1Hex; + } + private String nickname;
@Override @@ -769,7 +810,7 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl for (DirectorySignature signature : this.signatures) { if (DirectorySignatureImpl.DEFAULT_ALGORITHM.equals( signature.getAlgorithm())) { - signingKeyDigest = signature.getSigningKeyDigest(); + signingKeyDigest = signature.getSigningKeyDigestSha1Hex(); break; } } diff --git a/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java index 309cad4..ac113d2 100644 --- a/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java @@ -743,6 +743,11 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
@Override public String getServerDescriptorDigest() { + return this.getDigestSha1Hex(); + } + + @Override + public String getDigestSha1Hex() { return this.serverDescriptorDigest; }
@@ -750,6 +755,11 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
@Override public String getServerDescriptorDigestSha256() { + return this.getDigestSha256Base64(); + } + + @Override + public String getDigestSha256Base64() { return this.serverDescriptorDigestSha256; }
@@ -933,6 +943,11 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
@Override public String getExtraInfoDigest() { + return this.getExtraInfoDigestSha1Hex(); + } + + @Override + public String getExtraInfoDigestSha1Hex() { return this.extraInfoDigest; }
@@ -940,6 +955,11 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
@Override public String getExtraInfoDigestSha256() { + return this.getExtraInfoDigestSha256Base64(); + } + + @Override + public String getExtraInfoDigestSha256Base64() { return this.extraInfoDigestSha256; }
diff --git a/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java b/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java index 118ada8..76a2148 100644 --- a/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java +++ b/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java @@ -1115,7 +1115,7 @@ public class ExtraInfoDescriptorImplTest { .createWithGeoipDbDigestLine("geoip-db-digest " + "916A3CA8B7DF61473D5AE5B21711F35F301CE9E8"); assertEquals("916A3CA8B7DF61473D5AE5B21711F35F301CE9E8", - descriptor.getGeoipDbDigest()); + descriptor.getGeoipDbDigestSha1Hex()); }
@Test(expected = DescriptorParseException.class) @@ -1155,7 +1155,7 @@ public class ExtraInfoDescriptorImplTest { .createWithGeoip6DbDigestLine("geoip6-db-digest " + "916A3CA8B7DF61473D5AE5B21711F35F301CE9E8"); assertEquals("916A3CA8B7DF61473D5AE5B21711F35F301CE9E8", - descriptor.getGeoip6DbDigest()); + descriptor.getGeoip6DbDigestSha1Hex()); }
@Test() @@ -1969,7 +1969,7 @@ public class ExtraInfoDescriptorImplTest { RelayExtraInfoDescriptor descriptor = new RelayExtraInfoDescriptorImpl(descriptorBytes, true); assertEquals("Pt1BtzfRwhYqGCDo8jjchS8nJP3ovrDyHGn+dqPbMgw", - descriptor.getExtraInfoDigestSha256()); + descriptor.getDigestSha256Base64()); }
@Test() @@ -1993,7 +1993,7 @@ public class ExtraInfoDescriptorImplTest { BridgeExtraInfoDescriptor descriptor = new BridgeExtraInfoDescriptorImpl(descriptorBytes, true); assertEquals("TvrqpjI7OmCtwGwair/NHUxg5ROVVQYz6/EDyXsDHR4", - descriptor.getExtraInfoDigestSha256()); + descriptor.getDigestSha256Base64()); } }
diff --git a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java index b150a6a..6298668 100644 --- a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java +++ b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java @@ -389,7 +389,7 @@ public class RelayNetworkStatusConsensusImplTest { if ("14C131DFC5C6F93646BE72FA1401C02A8DF2E8B4".equals( signature.getIdentity())) { assertEquals("3509BA5A624403A905C74DA5C8A0CEC9E0D3AF86", - signature.getSigningKeyDigest()); + signature.getSigningKeyDigestSha1Hex()); } } assertEquals(285, (int) consensus.getBandwidthWeights().get("Wbd")); diff --git a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java index 727d707..4a61f1c 100644 --- a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java +++ b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java @@ -734,7 +734,7 @@ public class RelayNetworkStatusVoteImplTest { assertEquals("80550987E1D626E3EBA5E5E75A458DE0626D088C", signature.getIdentity()); assertEquals("EEB9299D295C1C815E289FBF2F2BBEA5F52FDD19", - signature.getSigningKeyDigest()); + signature.getSigningKeyDigestSha1Hex()); assertEquals("-----BEGIN SIGNATURE-----\n" + "iHEU3Iidya5RIrjyYgv8tlU0R+rF56/3/MmaaZi0a67e7ZkISfQ4dghScHxn" + "F3Yh\nrXVaaoP07r6Ta+s0g1Zijm3lms50Nk/4tV2p8Y63c3F4Q3DAnK40Oi" @@ -1512,15 +1512,18 @@ public class RelayNetworkStatusVoteImplTest { assertEquals("sha256", firstSignature.getAlgorithm()); assertEquals(identitySha256, firstSignature.getIdentity()); assertEquals(signingKeyDigestSha256, - firstSignature.getSigningKeyDigest()); + firstSignature.getSigningKeyDigestSha1Hex()); assertEquals(signatureSha256 + "\n", firstSignature.getSignature()); DirectorySignature secondSignature = vote.getSignatures().get(1); assertEquals("sha1", secondSignature.getAlgorithm()); assertEquals(identitySha1, secondSignature.getIdentity()); assertEquals(signingKeyDigestSha1, - secondSignature.getSigningKeyDigest()); + secondSignature.getSigningKeyDigestSha1Hex()); assertEquals(signatureSha1 + "\n", secondSignature.getSignature()); assertEquals(signingKeyDigestSha1, vote.getSigningKeyDigest()); + System.out.println(new String(vote.getRawDescriptorBytes())); + assertEquals("c0d58c8d3c3695526f6eb5c0d9f8452b2234d303", + vote.getDigestSha1Hex()); }
@Test() diff --git a/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java b/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java index b713dd6..4a84764 100644 --- a/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java +++ b/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java @@ -472,7 +472,7 @@ public class ServerDescriptorImplTest { assertEquals(51200, (int) descriptor.getBandwidthBurst()); assertEquals(53470, (int) descriptor.getBandwidthObserved()); assertEquals("1469D1550738A25B1E7B47CDDBCD7B2899F51B74", - descriptor.getExtraInfoDigest()); + descriptor.getExtraInfoDigestSha1Hex()); assertEquals(Arrays.asList(new Integer[] {2}), descriptor.getHiddenServiceDirVersions()); assertEquals("Random Person <nobody AT example dot com>", @@ -828,7 +828,7 @@ public class ServerDescriptorImplTest { .createWithExtraInfoDigestLine("extra-info-digest " + "1469D1550738A25B1E7B47CDDBCD7B2899F51B74"); assertEquals("1469D1550738A25B1E7B47CDDBCD7B2899F51B74", - descriptor.getExtraInfoDigest()); + descriptor.getExtraInfoDigestSha1Hex()); }
@Test(expected = DescriptorParseException.class) @@ -858,7 +858,7 @@ public class ServerDescriptorImplTest { throws DescriptorParseException { ServerDescriptor descriptor = DescriptorBuilder .createWithExtraInfoDigestLine(null); - assertNull(descriptor.getExtraInfoDigest()); + assertNull(descriptor.getExtraInfoDigestSha1Hex()); }
@Test() @@ -871,7 +871,7 @@ public class ServerDescriptorImplTest { extraInfoDigest, additionalExtraInfoDigest); ServerDescriptor descriptor = DescriptorBuilder .createWithExtraInfoDigestLine(extraInfoDigestLine); - assertEquals(extraInfoDigest, descriptor.getExtraInfoDigest()); + assertEquals(extraInfoDigest, descriptor.getExtraInfoDigestSha1Hex()); }
@Test()