I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 3379432e authored by zzz's avatar zzz
Browse files

SAM: Cherrypick from patch in ticket #1318:

   - Check for extra bytes in private key string
   - checkPrivateDestination() returns boolean instead of throws
parent bb9129b6
No related branches found
No related tags found
No related merge requests found
......@@ -77,31 +77,27 @@ class SAMUtils {
return false;
}
}
public static class InvalidDestinationException extends Exception {
private static final long serialVersionUID = 0x1;
}
/**
* Check whether a base64-encoded {dest,privkey,signingprivkey} is valid
*
* @param dest The base64-encoded destination and keys to be checked (same format as PrivateKeyFile)
*
* @throws InvalidDestination if invalid
* @return true if valid
*/
public static void checkPrivateDestination(String dest) throws InvalidDestinationException {
public static boolean checkPrivateDestination(String dest) {
ByteArrayInputStream destKeyStream = new ByteArrayInputStream(Base64.decode(dest));
try {
Destination d = new Destination();
d.readBytes(destKeyStream);
new PrivateKey().readBytes(destKeyStream);
SigningPrivateKey spk = new SigningPrivateKey(d.getSigningPublicKey().getType());
spk.readBytes(destKeyStream);
} catch (Exception e) {
throw new InvalidDestinationException();
} catch (DataFormatException e) {
return false;
} catch (IOException e) {
return false;
}
return destKeyStream.available() == 0;
}
......
......@@ -500,11 +500,8 @@ class SAMv3Handler extends SAMv1Handler
_log.debug("Custom destination specified [" + dest + "]");
}
try {
SAMUtils.checkPrivateDestination(dest);
} catch ( SAMUtils.InvalidDestinationException e ) {
return writeString("SESSION STATUS RESULT=INVALID_KEY\n");
}
if (!SAMUtils.checkPrivateDestination(dest))
return writeString("SESSION STATUS RESULT=INVALID_KEY\n");
nick = props.getProperty("ID");
if (nick == null) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment