use of com.google.crypto.tink.proto.JwtRsaSsaPkcs1PrivateKey in project tink by google.
the class JwtRsaSsaPkcs1SignKeyManagerTest method createCorruptedModulusPrimitive_throws.
// Note: we use Theory as a parametrized test -- different from what the Theory framework intends.
@Theory
public void createCorruptedModulusPrimitive_throws(@FromDataPoints("algorithmParam") JwtRsaSsaPkcs1Algorithm algorithm, @FromDataPoints("sizes") int keySize) throws Exception {
if (TestUtil.isTsan()) {
// We do not use assume because Theories expects to find something which is not skipped.
return;
}
JwtRsaSsaPkcs1KeyFormat format = createKeyFormat(algorithm, keySize, RSAKeyGenParameterSpec.F4);
JwtRsaSsaPkcs1PrivateKey originalKey = factory.createKey(format);
byte[] originalN = originalKey.getPublicKey().getN().toByteArray();
originalN[0] = (byte) (originalN[0] ^ 0x01);
ByteString corruptedN = ByteString.copyFrom(originalN);
JwtRsaSsaPkcs1PublicKey corruptedPub = JwtRsaSsaPkcs1PublicKey.newBuilder().setVersion(originalKey.getPublicKey().getVersion()).setN(corruptedN).setE(originalKey.getPublicKey().getE()).build();
JwtRsaSsaPkcs1PrivateKey corruptedKey = JwtRsaSsaPkcs1PrivateKey.newBuilder().setVersion(originalKey.getVersion()).setPublicKey(corruptedPub).setD(originalKey.getD()).setP(originalKey.getP()).setQ(originalKey.getQ()).setDp(originalKey.getDp()).setDq(originalKey.getDq()).setCrt(originalKey.getCrt()).build();
assertThrows(GeneralSecurityException.class, () -> manager.getPrimitive(corruptedKey, JwtPublicKeySignInternal.class));
}
use of com.google.crypto.tink.proto.JwtRsaSsaPkcs1PrivateKey in project tink by google.
the class JwtRsaSsaPkcs1VerifyKeyManagerTest method validateKey_ok.
// Note: we use Theory as a parametrized test -- different from what the Theory framework intends.
@Theory
public void validateKey_ok(@FromDataPoints("algorithmParam") JwtRsaSsaPkcs1Algorithm algorithm, @FromDataPoints("sizes") int keySize) throws Exception {
if (TestUtil.isTsan()) {
// factory.createKey is too slow in Tsan.
return;
}
JwtRsaSsaPkcs1KeyFormat keyFormat = JwtRsaSsaPkcs1KeyFormat.newBuilder().setAlgorithm(algorithm).setModulusSizeInBits(keySize).setPublicExponent(ByteString.copyFrom(RSAKeyGenParameterSpec.F4.toByteArray())).build();
JwtRsaSsaPkcs1PrivateKey privateKey = factory.createKey(keyFormat);
JwtRsaSsaPkcs1PublicKey publicKey = signManager.getPublicKey(privateKey);
verifyManager.validateKey(publicKey);
}
Aggregations