RsaSsaPkcs1VerifyKeyManager extends KeyTypeManager<RsaSsaPkcs1PublicKey> { @Override public void validateKey(RsaSsaPkcs1PublicKey pubKey) throws GeneralSecurityException { Validators.validateVersion(pubKey.getVersion(), getVersion()); Validators.validateRsaModulusSize((new BigInteger(1, pubKey.getN().toByteArray())).bitLength()); Validators.validateRsaPublicExponent(new BigInteger(1, pubKey.getE().toByteArray())); SigUtil.validateRsaSsaPkcs1Params(pubKey.getParams()); } RsaSsaPkcs1VerifyKeyManager(); @Override String getKeyType(); @Override int getVersion(); @Override KeyMaterialType keyMaterialType(); @Override RsaSsaPkcs1PublicKey parseKey(ByteString byteString); @Override void validateKey(RsaSsaPkcs1PublicKey pubKey);  }
@Test public void validateKey_empty_throws() throws Exception { try { verifyManager.validateKey(RsaSsaPkcs1PublicKey.getDefaultInstance()); fail(); } catch (GeneralSecurityException e) { } }
@Test public void validateKey_generated() throws Exception { if (TestUtil.isTsan()) { return; } RsaSsaPkcs1KeyFormat keyFormat = RsaSsaPkcs1KeyFormat.newBuilder() .setParams(RsaSsaPkcs1Params.newBuilder().setHashType(HashType.SHA256)) .setModulusSizeInBits(3072) .setPublicExponent(ByteString.copyFrom(RSAKeyGenParameterSpec.F4.toByteArray())) .build(); RsaSsaPkcs1PrivateKey privateKey = factory.createKey(keyFormat); RsaSsaPkcs1PublicKey publicKey = signManager.getPublicKey(privateKey); verifyManager.validateKey(publicKey); }
@Test public void validateKey_testVector() throws Exception { RsaSsaPkcs1PublicKey publicKey = nistTestVectors[0].publicKeyProto; verifyManager.validateKey(publicKey); }
@Test public void validateKey_wrongVersion() throws Exception { RsaSsaPkcs1PublicKey publicKey = nistTestVectors[0].publicKeyProto; RsaSsaPkcs1PublicKey invalidKey = RsaSsaPkcs1PublicKey.newBuilder(publicKey).setVersion(1).build(); try { verifyManager.validateKey(invalidKey); fail(); } catch (GeneralSecurityException e) { } }
@Test public void validateKey_smallModulus() throws Exception { RsaSsaPkcs1PublicKey publicKey = nistTestVectors[0].publicKeyProto; RsaSsaPkcs1PublicKey invalidKey = RsaSsaPkcs1PublicKey.newBuilder(publicKey) .setN(ByteString.copyFrom(TestUtil.hexDecode("23"))) .setE(ByteString.copyFrom(TestUtil.hexDecode("03"))) .build(); try { verifyManager.validateKey(invalidKey); fail(); } catch (GeneralSecurityException e) { } }