[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [metrics-lib/master] Add parsing support for ntor-onion-key line.
commit 785fd43246dfd9a229951e701d30f4319b7a8f37
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Mon Jan 7 05:23:22 2013 +0100
Add parsing support for ntor-onion-key line.
Spotted by atagar; see #7867.
---
.../torproject/descriptor/ServerDescriptor.java | 4 ++
.../descriptor/impl/ServerDescriptorImpl.java | 17 ++++++-
.../descriptor/impl/ServerDescriptorImplTest.java | 50 ++++++++++++++++++++
3 files changed, 70 insertions(+), 1 deletions(-)
diff --git a/src/org/torproject/descriptor/ServerDescriptor.java b/src/org/torproject/descriptor/ServerDescriptor.java
index 01c3672..4180adc 100644
--- a/src/org/torproject/descriptor/ServerDescriptor.java
+++ b/src/org/torproject/descriptor/ServerDescriptor.java
@@ -143,5 +143,9 @@ public interface ServerDescriptor extends Descriptor {
/* Return the port list of the IPv6 port summary or null if the server
* descriptor didn't contain an IPv6 port summary line. */
public String getIpv6PortList();
+
+ /* Return the ntor onion key base64 string with padding omitted, or null
+ * if the server descriptors didn't contain an ntor onion key line. */
+ public String getNtorOnionKey();
}
diff --git a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
index b25d17a..1fb39f5 100644
--- a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
@@ -49,7 +49,7 @@ public class ServerDescriptorImpl extends DescriptorImpl
+ "read-history,write-history,eventdns,caches-extra-info,"
+ "extra-info-digest,hidden-service-dir,protocols,"
+ "allow-single-hop-exits,onion-key,signing-key,ipv6-policy,"
- + "router-signature").split(",")));
+ + "ntor-onion-key,router-signature").split(",")));
this.checkAtMostOnceKeywords(atMostOnceKeywords);
this.checkFirstKeyword("router");
if (this.getKeywordCount("accept") == 0 &&
@@ -129,6 +129,8 @@ public class ServerDescriptorImpl extends DescriptorImpl
this.parseRouterDigestLine(line, lineNoOpt, partsNoOpt);
} else if (keyword.equals("ipv6-policy")) {
this.parseIpv6PolicyLine(line, lineNoOpt, partsNoOpt);
+ } else if (keyword.equals("ntor-onion-key")) {
+ this.parseNtorOnionKeyLine(line, lineNoOpt, partsNoOpt);
} else if (line.startsWith("-----BEGIN")) {
crypto = new StringBuilder();
crypto.append(line + "\n");
@@ -500,6 +502,14 @@ public class ServerDescriptorImpl extends DescriptorImpl
}
}
+ private void parseNtorOnionKeyLine(String line, String lineNoOpt,
+ String[] partsNoOpt) throws DescriptorParseException {
+ if (partsNoOpt.length != 2) {
+ throw new DescriptorParseException("Illegal line '" + line + "'.");
+ }
+ this.ntorOnionKey = partsNoOpt[1].replaceAll("=", "");
+ }
+
private void calculateDigest() throws DescriptorParseException {
if (this.serverDescriptorDigest != null) {
/* We already learned the descriptor digest of this bridge
@@ -690,5 +700,10 @@ public class ServerDescriptorImpl extends DescriptorImpl
public String getIpv6PortList() {
return this.ipv6PortList;
}
+
+ private String ntorOnionKey;
+ public String getNtorOnionKey() {
+ return this.ntorOnionKey;
+ }
}
diff --git a/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java b/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
index a5a7d84..5bd73af 100644
--- a/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
+++ b/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
@@ -188,6 +188,13 @@ public class ServerDescriptorImplTest {
db.ipv6PolicyLine = line;
return new ServerDescriptorImpl(db.buildDescriptor(), true);
}
+ private String ntorOnionKeyLine = null;
+ private static ServerDescriptor createWithNtorOnionKeyLine(
+ String line) throws DescriptorParseException {
+ DescriptorBuilder db = new DescriptorBuilder();
+ db.ntorOnionKeyLine = line;
+ return new ServerDescriptorImpl(db.buildDescriptor(), true);
+ }
private String routerSignatureLines = "router-signature\n"
+ "-----BEGIN SIGNATURE-----\n"
+ "o4j+kH8UQfjBwepUnr99v0ebN8RpzHJ/lqYsTojXHy9kMr1RNI9IDeSzA7PSqT"
@@ -274,6 +281,9 @@ public class ServerDescriptorImplTest {
if (this.ipv6PolicyLine != null) {
sb.append(this.ipv6PolicyLine + "\n");
}
+ if (this.ntorOnionKeyLine != null) {
+ sb.append(this.ntorOnionKeyLine + "\n");
+ }
if (this.unrecognizedLine != null) {
sb.append(this.unrecognizedLine + "\n");
}
@@ -1188,6 +1198,46 @@ public class ServerDescriptorImplTest {
+ "ipv6-policy accept 80,1194,1220,1293");
}
+ @Test()
+ public void testNtorOnionKeyLine() throws DescriptorParseException {
+ ServerDescriptor descriptor = DescriptorBuilder.
+ createWithNtorOnionKeyLine("ntor-onion-key "
+ + "Y/XgaHcPIJVa4D55kir9QLH8rEYAaLXuv3c3sm8jYhY=");
+ assertEquals("Y/XgaHcPIJVa4D55kir9QLH8rEYAaLXuv3c3sm8jYhY",
+ descriptor.getNtorOnionKey());
+ }
+
+ @Test()
+ public void testNtorOnionKeyLineNoPadding()
+ throws DescriptorParseException {
+ ServerDescriptor descriptor = DescriptorBuilder.
+ createWithNtorOnionKeyLine("ntor-onion-key "
+ + "Y/XgaHcPIJVa4D55kir9QLH8rEYAaLXuv3c3sm8jYhY");
+ assertEquals("Y/XgaHcPIJVa4D55kir9QLH8rEYAaLXuv3c3sm8jYhY",
+ descriptor.getNtorOnionKey());
+ }
+
+ @Test(expected = DescriptorParseException.class)
+ public void testNtorOnionKeyLineNoKey()
+ throws DescriptorParseException {
+ DescriptorBuilder.createWithNtorOnionKeyLine("ntor-onion-key ");
+ }
+
+ @Test(expected = DescriptorParseException.class)
+ public void testNtorOnionKeyLineTwoKeys()
+ throws DescriptorParseException {
+ DescriptorBuilder.createWithNtorOnionKeyLine("ntor-onion-key "
+ + "Y/XgaHcPIJVa4D55kir9QLH8rEYAaLXuv3c3sm8jYhY "
+ + "Y/XgaHcPIJVa4D55kir9QLH8rEYAaLXuv3c3sm8jYhY");
+ }
+
+ @Test(expected = DescriptorParseException.class)
+ public void testTwoNtorOnionKeyLines() throws DescriptorParseException {
+ DescriptorBuilder.createWithNtorOnionKeyLine("ntor-onion-key "
+ + "Y/XgaHcPIJVa4D55kir9QLH8rEYAaLXuv3c3sm8jYhY\nntor-onion-key "
+ + "Y/XgaHcPIJVa4D55kir9QLH8rEYAaLXuv3c3sm8jYhY\n");
+ }
+
@Test(expected = DescriptorParseException.class)
public void testUnrecognizedLineFail()
throws DescriptorParseException {
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits