commit 02fa685e9ca3f0c577fec850d31650a2452f1926 Author: Karsten Loesing karsten.loesing@gmx.net Date: Wed May 16 17:35:17 2012 +0200
Looks like blank lines are allowed in v2 statuses.
For the moment, we still disallow blank lines in all other descriptors. If this is not correct, we can easily fix that. --- .../descriptor/impl/BridgeNetworkStatusImpl.java | 2 +- .../descriptor/impl/BridgePoolAssignmentImpl.java | 2 +- .../torproject/descriptor/impl/DescriptorImpl.java | 17 +++++++++-------- .../impl/DirectoryKeyCertificateImpl.java | 2 +- .../torproject/descriptor/impl/ExitListImpl.java | 6 +----- .../descriptor/impl/ExtraInfoDescriptorImpl.java | 2 +- .../descriptor/impl/NetworkStatusImpl.java | 10 ++++------ .../impl/RelayNetworkStatusConsensusImpl.java | 2 +- .../descriptor/impl/RelayNetworkStatusImpl.java | 5 ++++- .../impl/RelayNetworkStatusVoteImpl.java | 2 +- .../descriptor/impl/ServerDescriptorImpl.java | 2 +- 11 files changed, 25 insertions(+), 27 deletions(-)
diff --git a/src/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java b/src/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java index e6d1942..09f2f86 100644 --- a/src/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java +++ b/src/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java @@ -15,7 +15,7 @@ public class BridgeNetworkStatusImpl extends NetworkStatusImpl protected BridgeNetworkStatusImpl(byte[] statusBytes, String fileName, boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { - super(statusBytes, failUnrecognizedDescriptorLines, false); + super(statusBytes, failUnrecognizedDescriptorLines, false, false); this.setPublishedMillisFromFileName(fileName); }
diff --git a/src/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java b/src/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java index 7b87657..c4be80d 100644 --- a/src/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java +++ b/src/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java @@ -37,7 +37,7 @@ public class BridgePoolAssignmentImpl extends DescriptorImpl protected BridgePoolAssignmentImpl(byte[] descriptorBytes, boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { - super(descriptorBytes, failUnrecognizedDescriptorLines); + super(descriptorBytes, failUnrecognizedDescriptorLines, false); this.parseDescriptorBytes(); Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList( new String[] { "bridge-pool-assignment" })); diff --git a/src/org/torproject/descriptor/impl/DescriptorImpl.java b/src/org/torproject/descriptor/impl/DescriptorImpl.java index 7503419..88db60a 100644 --- a/src/org/torproject/descriptor/impl/DescriptorImpl.java +++ b/src/org/torproject/descriptor/impl/DescriptorImpl.java @@ -131,13 +131,13 @@ public abstract class DescriptorImpl implements Descriptor { }
protected DescriptorImpl(byte[] rawDescriptorBytes, - boolean failUnrecognizedDescriptorLines) + boolean failUnrecognizedDescriptorLines, boolean blankLinesAllowed) throws DescriptorParseException { this.rawDescriptorBytes = rawDescriptorBytes; this.failUnrecognizedDescriptorLines = failUnrecognizedDescriptorLines; this.cutOffAnnotations(rawDescriptorBytes); - this.countKeywords(rawDescriptorBytes); + this.countKeywords(rawDescriptorBytes, blankLinesAllowed); }
/* Parse annotation lines from the descriptor bytes. */ @@ -167,15 +167,15 @@ public abstract class DescriptorImpl implements Descriptor { private String firstKeyword, lastKeyword; private Map<String, Integer> parsedKeywords = new HashMap<String, Integer>(); - private void countKeywords(byte[] rawDescriptorBytes) - throws DescriptorParseException { + private void countKeywords(byte[] rawDescriptorBytes, + boolean blankLinesAllowed) throws DescriptorParseException { if (rawDescriptorBytes.length == 0) { throw new DescriptorParseException("Descriptor is empty."); } String descriptorString = new String(rawDescriptorBytes); - if (descriptorString.startsWith("\n") || - descriptorString.contains("\n\n")) { - throw new DescriptorParseException("Empty lines are not allowed."); + if (!blankLinesAllowed && (descriptorString.startsWith("\n") || + descriptorString.contains("\n\n"))) { + throw new DescriptorParseException("Blank lines are not allowed."); } boolean skipCrypto = false; Scanner s = new Scanner(descriptorString).useDelimiter("\n"); @@ -185,7 +185,8 @@ public abstract class DescriptorImpl implements Descriptor { skipCrypto = true; } else if (line.startsWith("-----END")) { skipCrypto = false; - } else if (!line.startsWith("@") && !skipCrypto) { + } else if (!line.isEmpty() && !line.startsWith("@") && + !skipCrypto) { String lineNoOpt = line.startsWith("opt ") ? line.substring("opt ".length()) : line; String keyword = lineNoOpt.split(" ", -1)[0]; diff --git a/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java b/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java index 2483aa1..338f8e6 100644 --- a/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java +++ b/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java @@ -38,7 +38,7 @@ public class DirectoryKeyCertificateImpl extends DescriptorImpl protected DirectoryKeyCertificateImpl(byte[] rawDescriptorBytes, boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { - super(rawDescriptorBytes, failUnrecognizedDescriptorLines); + super(rawDescriptorBytes, failUnrecognizedDescriptorLines, false); this.parseDescriptorBytes(); this.calculateDigest(); Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList(( diff --git a/src/org/torproject/descriptor/impl/ExitListImpl.java b/src/org/torproject/descriptor/impl/ExitListImpl.java index dae2fb2..277112f 100644 --- a/src/org/torproject/descriptor/impl/ExitListImpl.java +++ b/src/org/torproject/descriptor/impl/ExitListImpl.java @@ -20,7 +20,7 @@ public class ExitListImpl extends DescriptorImpl implements ExitList { protected ExitListImpl(byte[] rawDescriptorBytes, String fileName, boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { - super(rawDescriptorBytes, failUnrecognizedDescriptorLines); + super(rawDescriptorBytes, failUnrecognizedDescriptorLines, false); this.setPublishedMillisFromFileName(fileName); this.splitAndParseExitListEntries(rawDescriptorBytes); } @@ -50,10 +50,6 @@ public class ExitListImpl extends DescriptorImpl implements ExitList { throw new DescriptorParseException("Descriptor is empty."); } String descriptorString = new String(rawDescriptorBytes); - if (descriptorString.startsWith("\n") || - descriptorString.contains("\n\n")) { - throw new DescriptorParseException("Empty lines are not allowed."); - } Scanner s = new Scanner(descriptorString).useDelimiter("\n"); StringBuilder sb = new StringBuilder(); while (s.hasNext()) { diff --git a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java index 184598a..d8fbc8d 100644 --- a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java +++ b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java @@ -41,7 +41,7 @@ public class ExtraInfoDescriptorImpl extends DescriptorImpl protected ExtraInfoDescriptorImpl(byte[] descriptorBytes, boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { - super(descriptorBytes, failUnrecognizedDescriptorLines); + super(descriptorBytes, failUnrecognizedDescriptorLines, false); this.parseDescriptorBytes(); this.calculateDigest(); Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList(( diff --git a/src/org/torproject/descriptor/impl/NetworkStatusImpl.java b/src/org/torproject/descriptor/impl/NetworkStatusImpl.java index 35e63b3..5a6af9e 100644 --- a/src/org/torproject/descriptor/impl/NetworkStatusImpl.java +++ b/src/org/torproject/descriptor/impl/NetworkStatusImpl.java @@ -18,8 +18,10 @@ public abstract class NetworkStatusImpl extends DescriptorImpl {
protected NetworkStatusImpl(byte[] rawDescriptorBytes, boolean failUnrecognizedDescriptorLines, - boolean containsDirSourceEntries) throws DescriptorParseException { - super(rawDescriptorBytes, failUnrecognizedDescriptorLines); + boolean containsDirSourceEntries, boolean blankLinesAllowed) + throws DescriptorParseException { + super(rawDescriptorBytes, failUnrecognizedDescriptorLines, + blankLinesAllowed); this.splitAndParseParts(rawDescriptorBytes, containsDirSourceEntries); }
@@ -29,10 +31,6 @@ public abstract class NetworkStatusImpl extends DescriptorImpl { throw new DescriptorParseException("Descriptor is empty."); } String descriptorString = new String(rawDescriptorBytes); - if (descriptorString.startsWith("\n") || - descriptorString.contains("\n\n")) { - throw new DescriptorParseException("Empty lines are not allowed."); - } int startIndex = 0; int firstDirSourceIndex = !containsDirSourceEntries ? -1 : this.findFirstIndexOfKeyword(descriptorString, "dir-source"); diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java index 14082b8..f296fa6 100644 --- a/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java +++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java @@ -41,7 +41,7 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl protected RelayNetworkStatusConsensusImpl(byte[] consensusBytes, boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { - super(consensusBytes, failUnrecognizedDescriptorLines, true); + super(consensusBytes, failUnrecognizedDescriptorLines, true, false); Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList(( "vote-status,consensus-method,valid-after,fresh-until," + "valid-until,voting-delay,known-flags").split(","))); diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java index f3ab34a..78cacd0 100644 --- a/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java +++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java @@ -39,7 +39,7 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl protected RelayNetworkStatusImpl(byte[] statusBytes, boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { - super(statusBytes, failUnrecognizedDescriptorLines, false); + super(statusBytes, failUnrecognizedDescriptorLines, false, true); Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList(( "network-status-version,dir-source,fingerprint,contact," + "dir-signing-key,published").split(","))); @@ -84,6 +84,9 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl StringBuilder crypto = null; while (s.hasNext()) { String line = s.next(); + if (line.isEmpty()) { + continue; + } String[] parts = line.split(" "); String keyword = parts[0]; if (keyword.equals("network-status-version")) { diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java index 7cce313..d5b87c1 100644 --- a/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java +++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java @@ -39,7 +39,7 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl protected RelayNetworkStatusVoteImpl(byte[] voteBytes, boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { - super(voteBytes, failUnrecognizedDescriptorLines, false); + super(voteBytes, failUnrecognizedDescriptorLines, false, false); Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList(( "vote-status,consensus-methods,published,valid-after,fresh-until," + "valid-until,voting-delay,known-flags,dir-source," diff --git a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java index 54f8f92..77b06dd 100644 --- a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java +++ b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java @@ -38,7 +38,7 @@ public class ServerDescriptorImpl extends DescriptorImpl protected ServerDescriptorImpl(byte[] descriptorBytes, boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { - super(descriptorBytes, failUnrecognizedDescriptorLines); + super(descriptorBytes, failUnrecognizedDescriptorLines, false); this.parseDescriptorBytes(); this.calculateDigest(); Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList(
tor-commits@lists.torproject.org