forked from I2P_Developers/i2p.i2p
SAM: Cherrypick from patch in ticket #1318:
- Check for extra bytes in private key string - checkPrivateDestination() returns boolean instead of throws
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user