Commit d6e9a0d7 authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Fix NPE when parsing invalid crypto blocks.

parent a8e0cb7a
# Changes in version 2.?.? - 2019-1?-??
* Minor changes
- Fix a NullPointerException when parsing an invalid crypto block
starting with "-----END " rather than "-----BEGIN ".
# Changes in version 2.9.1 - 2019-11-09
......
......@@ -80,6 +80,10 @@ public class DirectoryKeyCertificateImpl extends DescriptorImpl
crypto.append(line).append(NL);
break;
case CRYPTO_END:
if (null == crypto) {
throw new DescriptorParseException(Key.CRYPTO_END + " before "
+ Key.CRYPTO_BEGIN);
}
crypto.append(line).append(NL);
String cryptoString = crypto.toString();
crypto = null;
......
......@@ -70,6 +70,10 @@ public class DirectorySignatureImpl implements DirectorySignature {
crypto.append(line).append(NL);
break;
case CRYPTO_END:
if (null == crypto) {
throw new DescriptorParseException(Key.CRYPTO_END + " before "
+ Key.CRYPTO_BEGIN);
}
crypto.append(line).append(NL);
String cryptoString = crypto.toString();
crypto = null;
......
......@@ -242,6 +242,10 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
cryptoLines.add(line);
break;
case CRYPTO_END:
if (null == cryptoLines) {
throw new DescriptorParseException(Key.CRYPTO_END + " before "
+ Key.CRYPTO_BEGIN);
}
cryptoLines.add(line);
StringBuilder sb = new StringBuilder();
for (String cryptoLine : cryptoLines) {
......
......@@ -71,6 +71,10 @@ public class MicrodescriptorImpl extends DescriptorImpl
crypto.append(line).append(NL);
break;
case CRYPTO_END:
if (null == crypto) {
throw new DescriptorParseException(Key.CRYPTO_END + " before "
+ Key.CRYPTO_BEGIN);
}
crypto.append(line).append(NL);
String cryptoString = crypto.toString();
crypto = null;
......
......@@ -125,6 +125,10 @@ public class RelayDirectoryImpl extends DescriptorImpl
crypto.append(line).append(NL);
break;
case CRYPTO_END:
if (null == crypto) {
throw new DescriptorParseException(Key.CRYPTO_END + " before "
+ Key.CRYPTO_BEGIN);
}
crypto.append(line).append(NL);
String cryptoString = crypto.toString();
crypto = null;
......@@ -215,6 +219,10 @@ public class RelayDirectoryImpl extends DescriptorImpl
crypto.append(line).append(NL);
break;
case CRYPTO_END:
if (null == crypto) {
throw new DescriptorParseException(Key.CRYPTO_END + " before "
+ Key.CRYPTO_BEGIN);
}
crypto.append(line).append(NL);
String cryptoString = crypto.toString();
crypto = null;
......
......@@ -81,6 +81,10 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
crypto.append(line).append(NL);
break;
case CRYPTO_END:
if (null == crypto) {
throw new DescriptorParseException(Key.CRYPTO_END + " before "
+ Key.CRYPTO_BEGIN);
}
crypto.append(line).append(NL);
String cryptoString = crypto.toString();
crypto = null;
......@@ -130,6 +134,10 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
crypto.append(line).append(NL);
break;
case CRYPTO_END:
if (null == crypto) {
throw new DescriptorParseException(Key.CRYPTO_END + " before "
+ Key.CRYPTO_BEGIN);
}
crypto.append(line).append(NL);
String cryptoString = crypto.toString();
crypto = null;
......
......@@ -186,6 +186,10 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
crypto.append(line).append(NL);
break;
case CRYPTO_END:
if (null == crypto) {
throw new DescriptorParseException(Key.CRYPTO_END + " before "
+ Key.CRYPTO_BEGIN);
}
crypto.append(line).append(NL);
String cryptoString = crypto.toString();
crypto = null;
......
......@@ -181,6 +181,10 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
cryptoLines.add(line);
break;
case CRYPTO_END:
if (null == cryptoLines) {
throw new DescriptorParseException(Key.CRYPTO_END + " before "
+ Key.CRYPTO_BEGIN);
}
cryptoLines.add(line);
StringBuilder sb = new StringBuilder();
for (String cryptoLine : cryptoLines) {
......
......@@ -2243,6 +2243,16 @@ public class ExtraInfoDescriptorImplTest {
MASTER_KEY_ED25519_LINE, ROUTER_SIG_ED25519_LINE);
}
@Test
public void testEd25519IdentityInvalidCrypto()
throws DescriptorParseException {
this.thrown.expect(DescriptorParseException.class);
this.thrown.expectMessage("CRYPTO_END before CRYPTO_BEGIN");
DescriptorBuilder.createWithEd25519Lines("identity-ed25519\n"
+ "-----END ED25519 CERT-----\n-----BEGIN ED25519 CERT-----",
MASTER_KEY_ED25519_LINE, ROUTER_SIG_ED25519_LINE);
}
@Test
public void testEd25519MasterKeyMissing()
throws DescriptorParseException {
......
......@@ -1825,6 +1825,16 @@ public class ServerDescriptorImplTest {
MASTER_KEY_ED25519_LINE, ROUTER_SIG_ED25519_LINE);
}
@Test
public void testEd25519IdentityInvalidCrypto()
throws DescriptorParseException {
this.thrown.expect(DescriptorParseException.class);
this.thrown.expectMessage("CRYPTO_END before CRYPTO_BEGIN");
DescriptorBuilder.createWithEd25519Lines("identity-ed25519\n"
+ "-----END ED25519 CERT-----\n-----BEGIN ED25519 CERT-----",
MASTER_KEY_ED25519_LINE, ROUTER_SIG_ED25519_LINE);
}
@Test
public void testEd25519MasterKeyMissing()
throws DescriptorParseException {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment