Search in sources :

Example 6 with JwtRsaSsaPssPublicKey

use of com.google.crypto.tink.proto.JwtRsaSsaPssPublicKey in project tink by google.

the class JwtRsaSsaPssSignKeyManagerTest 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") JwtRsaSsaPssAlgorithm algorithm, int keySize) throws Exception {
    if (TestUtil.isTsan()) {
        // We do not use assume because Theories expects to find something which is not skipped.
        return;
    }
    JwtRsaSsaPssKeyFormat format = createKeyFormat(algorithm, keySize, RSAKeyGenParameterSpec.F4);
    JwtRsaSsaPssPrivateKey originalKey = factory.createKey(format);
    byte[] originalN = originalKey.getPublicKey().getN().toByteArray();
    originalN[0] = (byte) (originalN[0] ^ 0x01);
    ByteString corruptedN = ByteString.copyFrom(originalN);
    JwtRsaSsaPssPublicKey corruptedPub = JwtRsaSsaPssPublicKey.newBuilder().setVersion(originalKey.getPublicKey().getVersion()).setN(corruptedN).setE(originalKey.getPublicKey().getE()).build();
    JwtRsaSsaPssPrivateKey corruptedKey = JwtRsaSsaPssPrivateKey.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 : JwtRsaSsaPssPublicKey(com.google.crypto.tink.proto.JwtRsaSsaPssPublicKey) JwtRsaSsaPssPrivateKey(com.google.crypto.tink.proto.JwtRsaSsaPssPrivateKey) ByteString(com.google.protobuf.ByteString) JwtRsaSsaPssKeyFormat(com.google.crypto.tink.proto.JwtRsaSsaPssKeyFormat) Theory(org.junit.experimental.theories.Theory)

Aggregations

JwtRsaSsaPssPublicKey (com.google.crypto.tink.proto.JwtRsaSsaPssPublicKey)6 JwtRsaSsaPssPrivateKey (com.google.crypto.tink.proto.JwtRsaSsaPssPrivateKey)4 JwtRsaSsaPssKeyFormat (com.google.crypto.tink.proto.JwtRsaSsaPssKeyFormat)3 KeyData (com.google.crypto.tink.proto.KeyData)2 Keyset (com.google.crypto.tink.proto.Keyset)2 ByteString (com.google.protobuf.ByteString)2 BigInteger (java.math.BigInteger)2 Theory (org.junit.experimental.theories.Theory)2 CleartextKeysetHandle (com.google.crypto.tink.CleartextKeysetHandle)1 KeyTemplate (com.google.crypto.tink.KeyTemplate)1 KeysetHandle (com.google.crypto.tink.KeysetHandle)1 JwtRsaSsaPssAlgorithm (com.google.crypto.tink.proto.JwtRsaSsaPssAlgorithm)1 InputStream (java.io.InputStream)1 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)1 RSAPrivateCrtKey (java.security.interfaces.RSAPrivateCrtKey)1 RSAPublicKey (java.security.interfaces.RSAPublicKey)1 RSAKeyGenParameterSpec (java.security.spec.RSAKeyGenParameterSpec)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1