PublicKey publicKey = identityCertificate.getPublicKey();
verifyIdentityKey(publicKey);
RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey;
if(rsaPublicKey.getModulus().bitLength() != 1024) {
throw new ConnectionHandshakeException("Invalid RSA modulus length in router identity key");
}
try {
identityCertificate.checkValidity();
identityCertificate.verify(rsaPublicKey);
linkCertificate.checkValidity();
linkCertificate.verify(rsaPublicKey);
} catch (GeneralSecurityException e) {
throw new ConnectionHandshakeException("Router presented invalid certificate chain in CERTS cell");
}
RSAPublicKey rsa2 = (RSAPublicKey) linkCertificate.getPublicKey();
if(!getConnectionPublicKey().getModulus().equals(rsa2.getModulus())) {
throw new ConnectionHandshakeException("Link certificate in CERTS cell does not match connection certificate");
}
}