Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Network Health
Metrics
Library
Commits
d6e9a0d7
Commit
d6e9a0d7
authored
Nov 20, 2019
by
Karsten Loesing
Browse files
Fix NPE when parsing invalid crypto blocks.
parent
a8e0cb7a
Changes
11
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
d6e9a0d7
# 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
...
...
src/main/java/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
View file @
d6e9a0d7
...
...
@@ -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
;
...
...
src/main/java/org/torproject/descriptor/impl/DirectorySignatureImpl.java
View file @
d6e9a0d7
...
...
@@ -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
;
...
...
src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
View file @
d6e9a0d7
...
...
@@ -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
)
{
...
...
src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java
View file @
d6e9a0d7
...
...
@@ -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
;
...
...
src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java
View file @
d6e9a0d7
...
...
@@ -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
;
...
...
src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
View file @
d6e9a0d7
...
...
@@ -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
;
...
...
src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
View file @
d6e9a0d7
...
...
@@ -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
;
...
...
src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java
View file @
d6e9a0d7
...
...
@@ -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
)
{
...
...
src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
View file @
d6e9a0d7
...
...
@@ -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
{
...
...
src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
View file @
d6e9a0d7
...
...
@@ -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
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment