Search in sources :

Example 6 with JwtRsaSsaPkcs1PrivateKey

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));
}
Also used : JwtRsaSsaPkcs1KeyFormat(com.google.crypto.tink.proto.JwtRsaSsaPkcs1KeyFormat) ByteString(com.google.protobuf.ByteString) JwtRsaSsaPkcs1PrivateKey(com.google.crypto.tink.proto.JwtRsaSsaPkcs1PrivateKey) JwtRsaSsaPkcs1PublicKey(com.google.crypto.tink.proto.JwtRsaSsaPkcs1PublicKey) Theory(org.junit.experimental.theories.Theory)

Example 7 with JwtRsaSsaPkcs1PrivateKey

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);
}
Also used : JwtRsaSsaPkcs1KeyFormat(com.google.crypto.tink.proto.JwtRsaSsaPkcs1KeyFormat) JwtRsaSsaPkcs1PrivateKey(com.google.crypto.tink.proto.JwtRsaSsaPkcs1PrivateKey) JwtRsaSsaPkcs1PublicKey(com.google.crypto.tink.proto.JwtRsaSsaPkcs1PublicKey) Theory(org.junit.experimental.theories.Theory)

Aggregations

JwtRsaSsaPkcs1PrivateKey (com.google.crypto.tink.proto.JwtRsaSsaPkcs1PrivateKey)7 JwtRsaSsaPkcs1KeyFormat (com.google.crypto.tink.proto.JwtRsaSsaPkcs1KeyFormat)4 ByteString (com.google.protobuf.ByteString)4 JwtRsaSsaPkcs1PublicKey (com.google.crypto.tink.proto.JwtRsaSsaPkcs1PublicKey)3 Keyset (com.google.crypto.tink.proto.Keyset)3 Test (org.junit.Test)3 Theory (org.junit.experimental.theories.Theory)3 CleartextKeysetHandle (com.google.crypto.tink.CleartextKeysetHandle)2 KeyTemplate (com.google.crypto.tink.KeyTemplate)2 KeysetHandle (com.google.crypto.tink.KeysetHandle)2 JwtRsaSsaPkcs1Algorithm (com.google.crypto.tink.proto.JwtRsaSsaPkcs1Algorithm)2 Enums (com.google.crypto.tink.subtle.Enums)2 RsaSsaPkcs1SignJce (com.google.crypto.tink.subtle.RsaSsaPkcs1SignJce)2 JsonObject (com.google.gson.JsonObject)2 RSAPrivateCrtKey (java.security.interfaces.RSAPrivateCrtKey)2 KeyData (com.google.crypto.tink.proto.KeyData)1 TreeSet (java.util.TreeSet)1