use of com.google.crypto.tink.proto.JwtEcdsaKeyFormat in project tink by google.
the class JwtEcdsaSignKeyManagerTest method createCorruptedPublicKeyPrimitive_throws.
// Note: we use Theory as a parametrized test -- different from what the Theory framework intends.
@Theory
public void createCorruptedPublicKeyPrimitive_throws(@FromDataPoints("parametersAlgos") JwtEcdsaAlgorithm algorithm) throws Exception {
JwtEcdsaKeyFormat format = createKeyFormat(algorithm);
JwtEcdsaPrivateKey originalKey = factory.createKey(format);
byte[] originalPubX = originalKey.getPublicKey().getX().toByteArray();
byte[] originalPubY = originalKey.getPublicKey().getY().toByteArray();
originalPubX[0] = (byte) (originalPubX[0] ^ 0x01);
ByteString corruptedPubX = ByteString.copyFrom(originalPubX);
JwtEcdsaPublicKey corruptedPub = JwtEcdsaPublicKey.newBuilder().setVersion(originalKey.getPublicKey().getVersion()).setAlgorithm(algorithm).setX(corruptedPubX).setY(ByteString.copyFrom(originalPubY)).build();
JwtEcdsaPrivateKey corruptedKey = JwtEcdsaPrivateKey.newBuilder().setVersion(originalKey.getVersion()).setPublicKey(corruptedPub).setKeyValue(originalKey.getKeyValue()).build();
assertThrows(GeneralSecurityException.class, () -> manager.getPrimitive(corruptedKey, JwtPublicKeySignInternal.class));
}
use of com.google.crypto.tink.proto.JwtEcdsaKeyFormat in project tink by google.
the class JwtEcdsaVerifyKeyManagerTest method createPrimitive_anotherKey_throw.
// Note: we use Theory as a parametrized test -- different from what the Theory framework intends.
@Theory
public void createPrimitive_anotherKey_throw(@FromDataPoints("parametersAlgos") JwtEcdsaAlgorithm algorithm) throws Exception {
if (TestUtil.isTsan()) {
// factory.createKey is too slow in Tsan.
return;
}
JwtEcdsaKeyFormat keyFormat = JwtEcdsaKeyFormat.newBuilder().setAlgorithm(algorithm).build();
JwtEcdsaPrivateKey privateKey = factory.createKey(keyFormat);
// Create a different key.
JwtEcdsaPublicKey publicKey = signManager.getPublicKey(factory.createKey(keyFormat));
JwtPublicKeySignInternal signer = signManager.getPrimitive(privateKey, JwtPublicKeySignInternal.class);
JwtPublicKeyVerifyInternal verifier = verifyManager.getPrimitive(publicKey, JwtPublicKeyVerifyInternal.class);
RawJwt token = RawJwt.newBuilder().withoutExpiration().build();
JwtValidator validator = JwtValidator.newBuilder().allowMissingExpiration().build();
assertThrows(GeneralSecurityException.class, () -> verifier.verifyAndDecodeWithKid(signer.signAndEncodeWithKid(token, Optional.empty()), validator, Optional.empty()));
}
use of com.google.crypto.tink.proto.JwtEcdsaKeyFormat in project tink by google.
the class JwtEcdsaVerifyKeyManagerTest method validateKey_ok.
// Note: we use Theory as a parametrized test -- different from what the Theory framework intends.
@Theory
public void validateKey_ok(@FromDataPoints("parametersAlgos") JwtEcdsaAlgorithm algorithm) throws Exception {
if (TestUtil.isTsan()) {
// factory.createKey is too slow in Tsan.
return;
}
JwtEcdsaKeyFormat keyFormat = JwtEcdsaKeyFormat.newBuilder().setAlgorithm(algorithm).build();
JwtEcdsaPrivateKey privateKey = factory.createKey(keyFormat);
JwtEcdsaPublicKey publicKey = signManager.getPublicKey(privateKey);
verifyManager.validateKey(publicKey);
}
use of com.google.crypto.tink.proto.JwtEcdsaKeyFormat in project tink by google.
the class JwtEcdsaVerifyKeyManagerTest method createPrimitive_ok.
// Note: we use Theory as a parametrized test -- different from what the Theory framework intends.
@Theory
public void createPrimitive_ok(@FromDataPoints("parametersAlgos") JwtEcdsaAlgorithm algorithm) throws Exception {
if (TestUtil.isTsan()) {
// factory.createKey is too slow in Tsan.
return;
}
JwtEcdsaKeyFormat keyFormat = JwtEcdsaKeyFormat.newBuilder().setAlgorithm(algorithm).build();
JwtEcdsaPrivateKey privateKey = factory.createKey(keyFormat);
JwtEcdsaPublicKey publicKey = signManager.getPublicKey(privateKey);
JwtPublicKeySignInternal signer = signManager.getPrimitive(privateKey, JwtPublicKeySignInternal.class);
JwtPublicKeyVerifyInternal verifier = verifyManager.getPrimitive(publicKey, JwtPublicKeyVerifyInternal.class);
RawJwt token = RawJwt.newBuilder().withoutExpiration().build();
JwtValidator validator = JwtValidator.newBuilder().allowMissingExpiration().build();
verifier.verifyAndDecodeWithKid(signer.signAndEncodeWithKid(token, Optional.empty()), validator, Optional.empty());
}
Aggregations