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
1413dfb1
Commit
1413dfb1
authored
May 20, 2016
by
Karsten Loesing
Browse files
Parse crypto parts in network status votes.
parent
4299213a
Changes
3
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
1413dfb1
...
...
@@ -11,6 +11,7 @@
-
Rename properties for overriding default descriptor source
implementation classes.
-
Actually return the signing key digest in network status votes.
-
Parse crypto parts in network status votes.
*
Minor changes
-
Include a Torperf results line with more than one unrecognized
...
...
src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
View file @
1413dfb1
...
...
@@ -3,6 +3,7 @@
package
org.torproject.descriptor.impl
;
import
org.torproject.descriptor.DescriptorParseException
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashSet
;
...
...
@@ -75,7 +76,8 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
this
.
ignoringAdvertisedBws
=
-
1
;
Scanner
s
=
new
Scanner
(
new
String
(
headerBytes
)).
useDelimiter
(
"\n"
);
boolean
skipCrypto
=
false
;
/* TODO Parse crypto parts. */
String
nextCrypto
=
""
;
StringBuilder
crypto
=
null
;
while
(
s
.
hasNext
())
{
String
line
=
s
.
next
();
String
[]
parts
=
line
.
split
(
"[ \t]+"
);
...
...
@@ -145,18 +147,52 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
this
.
parseDirKeyExpiresLine
(
line
,
parts
);
break
;
case
"dir-identity-key"
:
this
.
parseDirIdentityKeyLine
(
line
,
parts
);
nextCrypto
=
"dir-identity-key"
;
break
;
case
"dir-signing-key"
:
this
.
parseDirSigningKeyLine
(
line
,
parts
);
nextCrypto
=
"dir-signing-key"
;
break
;
case
"dir-key-crosscert"
:
this
.
parseDirKeyCrosscertLine
(
line
,
parts
);
nextCrypto
=
"dir-key-crosscert"
;
break
;
case
"dir-key-certification"
:
this
.
parseDirKeyCertificationLine
(
line
,
parts
);
nextCrypto
=
"dir-key-certification"
;
break
;
case
"-----BEGIN"
:
skipCrypto
=
true
;
crypto
=
new
StringBuilder
();
crypto
.
append
(
line
).
append
(
"\n"
);
break
;
case
"-----END"
:
skipCrypto
=
false
;
crypto
.
append
(
line
).
append
(
"\n"
);
String
cryptoString
=
crypto
.
toString
();
crypto
=
null
;
switch
(
nextCrypto
)
{
case
"dir-identity-key"
:
this
.
dirIdentityKey
=
cryptoString
;
break
;
case
"dir-signing-key"
:
this
.
dirSigningKey
=
cryptoString
;
break
;
case
"dir-key-crosscert"
:
this
.
dirKeyCrosscert
=
cryptoString
;
break
;
case
"dir-key-certification"
:
this
.
dirKeyCertification
=
cryptoString
;
break
;
default
:
throw
new
DescriptorParseException
(
"Unrecognized crypto "
+
"block in vote."
);
}
nextCrypto
=
""
;
break
;
default
:
if
(!
skipCrypto
)
{
if
(
crypto
!=
null
)
{
crypto
.
append
(
line
).
append
(
"\n"
);
}
else
{
if
(
this
.
failUnrecognizedDescriptorLines
)
{
throw
new
DescriptorParseException
(
"Unrecognized line '"
+
line
+
"' in vote."
);
...
...
@@ -414,6 +450,34 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
parts
,
1
,
2
);
}
private
void
parseDirIdentityKeyLine
(
String
line
,
String
[]
parts
)
throws
DescriptorParseException
{
if
(!
line
.
equals
(
"dir-identity-key"
))
{
throw
new
DescriptorParseException
(
"Illegal line '"
+
line
+
"'."
);
}
}
private
void
parseDirSigningKeyLine
(
String
line
,
String
[]
parts
)
throws
DescriptorParseException
{
if
(!
line
.
equals
(
"dir-signing-key"
))
{
throw
new
DescriptorParseException
(
"Illegal line '"
+
line
+
"'."
);
}
}
private
void
parseDirKeyCrosscertLine
(
String
line
,
String
[]
parts
)
throws
DescriptorParseException
{
if
(!
line
.
equals
(
"dir-key-crosscert"
))
{
throw
new
DescriptorParseException
(
"Illegal line '"
+
line
+
"'."
);
}
}
private
void
parseDirKeyCertificationLine
(
String
line
,
String
[]
parts
)
throws
DescriptorParseException
{
if
(!
line
.
equals
(
"dir-key-certification"
))
{
throw
new
DescriptorParseException
(
"Illegal line '"
+
line
+
"'."
);
}
}
protected
void
parseFooter
(
byte
[]
footerBytes
)
throws
DescriptorParseException
{
Scanner
s
=
new
Scanner
(
new
String
(
footerBytes
)).
useDelimiter
(
"\n"
);
...
...
@@ -488,6 +552,26 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
return
this
.
dirKeyExpiresMillis
;
}
private
String
dirIdentityKey
;
public
String
getDirIdentityKey
()
{
return
this
.
dirIdentityKey
;
}
private
String
dirSigningKey
;
public
String
getDirSigningKey
()
{
return
this
.
dirSigningKey
;
}
private
String
dirKeyCrosscert
;
public
String
getDirKeyCrosscert
()
{
return
this
.
dirKeyCrosscert
;
}
private
String
dirKeyCertification
;
public
String
getDirKeyCertification
()
{
return
this
.
dirKeyCertification
;
}
public
String
getSigningKeyDigest
()
{
String
signingKeyDigest
=
null
;
if
(!
this
.
directorySignatures
.
isEmpty
())
{
...
...
test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
View file @
1413dfb1
...
...
@@ -506,6 +506,21 @@ public class RelayNetworkStatusVoteImplTest {
assertEquals
(
"Tor 0.2.1.29 (r8e9b25e6c7a2e70c)"
,
vote
.
getStatusEntry
(
"00343A8024F70E214728F0C5AF7ACE0C1508F073"
).
getVersion
());
assertEquals
(
3
,
vote
.
getDirKeyCertificateVersion
());
assertEquals
(
"80550987E1D626E3EBA5E5E75A458DE0626D088C"
,
vote
.
getIdentity
());
assertEquals
(
1303882477000L
,
/* 2011-04-27 05:34:37 */
vote
.
getDirKeyPublishedMillis
());
assertEquals
(
1335504877000L
,
/* 2012-04-27 05:34:37 */
vote
.
getDirKeyExpiresMillis
());
assertEquals
(
"-----BEGIN RSA PUBLIC KEY-----"
,
vote
.
getDirIdentityKey
().
split
(
"\n"
)[
0
]);
assertEquals
(
"-----BEGIN RSA PUBLIC KEY-----"
,
vote
.
getDirSigningKey
().
split
(
"\n"
)[
0
]);
assertEquals
(
"-----BEGIN ID SIGNATURE-----"
,
vote
.
getDirKeyCrosscert
().
split
(
"\n"
)[
0
]);
assertEquals
(
"-----BEGIN SIGNATURE-----"
,
vote
.
getDirKeyCertification
().
split
(
"\n"
)[
0
]);
assertTrue
(
vote
.
getUnrecognizedLines
().
isEmpty
());
}
...
...
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