forked from I2P_Developers/i2p.i2p
Crypto: Check for error return from sign()
This commit is contained in:
@@ -216,6 +216,8 @@ class PacketLocal extends Packet implements MessageOutputStream.WriteStatus {
|
|||||||
SigningPrivateKey key = _session.getPrivateKey();
|
SigningPrivateKey key = _session.getPrivateKey();
|
||||||
int size = writePacket(buffer, offset, key.getType().getSigLen());
|
int size = writePacket(buffer, offset, key.getType().getSigLen());
|
||||||
_optionSignature = _context.dsa().sign(buffer, offset, size, key);
|
_optionSignature = _context.dsa().sign(buffer, offset, size, key);
|
||||||
|
if (_optionSignature == null)
|
||||||
|
throw new IllegalStateException("Signature failed");
|
||||||
//if (false) {
|
//if (false) {
|
||||||
// Log l = ctx.logManager().getLog(Packet.class);
|
// Log l = ctx.logManager().getLog(Packet.class);
|
||||||
// l.error("Signing: " + toString());
|
// l.error("Signing: " + toString());
|
||||||
|
@@ -285,8 +285,8 @@ public class DSAEngine {
|
|||||||
try {
|
try {
|
||||||
return altSign(data, offset, length, signingKey);
|
return altSign(data, offset, length, signingKey);
|
||||||
} catch (GeneralSecurityException gse) {
|
} catch (GeneralSecurityException gse) {
|
||||||
if (_log.shouldLog(Log.WARN))
|
if (_log.shouldLog(Log.ERROR))
|
||||||
_log.warn(type + " Sign Fail", gse);
|
_log.error(type + " Sign Fail", gse);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -417,6 +417,8 @@ public class KeyGenerator {
|
|||||||
RandomSource.getInstance().nextBytes(src);
|
RandomSource.getInstance().nextBytes(src);
|
||||||
long start = System.nanoTime();
|
long start = System.nanoTime();
|
||||||
Signature sig = DSAEngine.getInstance().sign(src, privkey);
|
Signature sig = DSAEngine.getInstance().sign(src, privkey);
|
||||||
|
if (sig == null)
|
||||||
|
throw new GeneralSecurityException("signature generation failed");
|
||||||
long mid = System.nanoTime();
|
long mid = System.nanoTime();
|
||||||
boolean ok = DSAEngine.getInstance().verifySignature(sig, src, pubkey);
|
boolean ok = DSAEngine.getInstance().verifySignature(sig, src, pubkey);
|
||||||
long end = System.nanoTime();
|
long end = System.nanoTime();
|
||||||
|
@@ -171,8 +171,12 @@ public abstract class DatabaseEntry extends DataStructureImpl {
|
|||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
byte[] bytes = getBytes();
|
byte[] bytes = getBytes();
|
||||||
if (bytes == null) throw new DataFormatException("Not enough data to sign");
|
if (bytes == null) throw new DataFormatException("Not enough data to sign");
|
||||||
|
if (key == null)
|
||||||
|
throw new DataFormatException("No signing key");
|
||||||
// now sign with the key
|
// now sign with the key
|
||||||
_signature = DSAEngine.getInstance().sign(bytes, key);
|
_signature = DSAEngine.getInstance().sign(bytes, key);
|
||||||
|
if (_signature == null)
|
||||||
|
throw new DataFormatException("Signature failed with " + key.getType() + " key");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -405,7 +405,10 @@ public class PrivateKeyFile {
|
|||||||
System.arraycopy(this.dest.getPublicKey().getData(), 0, data, 0, PublicKey.KEYSIZE_BYTES);
|
System.arraycopy(this.dest.getPublicKey().getData(), 0, data, 0, PublicKey.KEYSIZE_BYTES);
|
||||||
System.arraycopy(this.dest.getSigningPublicKey().getData(), 0, data, PublicKey.KEYSIZE_BYTES, SigningPublicKey.KEYSIZE_BYTES);
|
System.arraycopy(this.dest.getSigningPublicKey().getData(), 0, data, PublicKey.KEYSIZE_BYTES, SigningPublicKey.KEYSIZE_BYTES);
|
||||||
byte[] payload = new byte[Hash.HASH_LENGTH + Signature.SIGNATURE_BYTES];
|
byte[] payload = new byte[Hash.HASH_LENGTH + Signature.SIGNATURE_BYTES];
|
||||||
byte[] sig = DSAEngine.getInstance().sign(new ByteArrayInputStream(data), spk2).getData();
|
Signature sign = DSAEngine.getInstance().sign(new ByteArrayInputStream(data), spk2);
|
||||||
|
if (sign == null)
|
||||||
|
return null;
|
||||||
|
byte[] sig = sign.getData();
|
||||||
System.arraycopy(sig, 0, payload, 0, Signature.SIGNATURE_BYTES);
|
System.arraycopy(sig, 0, payload, 0, Signature.SIGNATURE_BYTES);
|
||||||
// Add dest2's Hash for reference
|
// Add dest2's Hash for reference
|
||||||
byte[] h2 = d2.calculateHash().getData();
|
byte[] h2 = d2.calculateHash().getData();
|
||||||
|
@@ -121,7 +121,11 @@ public class SessionConfig extends DataStructureImpl {
|
|||||||
public void signSessionConfig(SigningPrivateKey signingKey) throws DataFormatException {
|
public void signSessionConfig(SigningPrivateKey signingKey) throws DataFormatException {
|
||||||
byte data[] = getBytes();
|
byte data[] = getBytes();
|
||||||
if (data == null) throw new DataFormatException("Unable to retrieve bytes for signing");
|
if (data == null) throw new DataFormatException("Unable to retrieve bytes for signing");
|
||||||
|
if (signingKey == null)
|
||||||
|
throw new DataFormatException("No signing key");
|
||||||
_signature = DSAEngine.getInstance().sign(data, signingKey);
|
_signature = DSAEngine.getInstance().sign(data, signingKey);
|
||||||
|
if (_signature == null)
|
||||||
|
throw new DataFormatException("Signature failed with " + signingKey.getType() + " key");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user