RsaSsaPssVerifyKeyManager extends KeyTypeManager<RsaSsaPssPublicKey> { @Override public void validateKey(RsaSsaPssPublicKey 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.validateRsaSsaPssParams(pubKey.getParams()); } RsaSsaPssVerifyKeyManager(); @Override String getKeyType(); @Override int getVersion(); @Override KeyMaterialType keyMaterialType(); @Override RsaSsaPssPublicKey parseKey(ByteString byteString); @Override void validateKey(RsaSsaPssPublicKey pubKey);  }
@Test public void validateKey_empty_throws() throws Exception { try { verifyManager.validateKey(RsaSsaPssPublicKey.getDefaultInstance()); fail(); } catch (GeneralSecurityException e) { } }
@Test public void validateKey_generated() throws Exception { if (TestUtil.isTsan()) { return; } RsaSsaPssKeyFormat keyFormat = RsaSsaPssKeyFormat.newBuilder() .setParams( RsaSsaPssParams.newBuilder() .setSigHash(HashType.SHA256) .setMgf1Hash(HashType.SHA256) .setSaltLength(32)) .setModulusSizeInBits(3072) .setPublicExponent(ByteString.copyFrom(RSAKeyGenParameterSpec.F4.toByteArray())) .build(); RsaSsaPssPrivateKey privateKey = factory.createKey(keyFormat); RsaSsaPssPublicKey publicKey = signManager.getPublicKey(privateKey); verifyManager.validateKey(publicKey); }
@Test public void validateKey_testVector() throws Exception { if (TestUtil.isTsan()) { return; } RsaSsaPssPublicKey publicKey = nistTestVectors[0].publicKeyProto; verifyManager.validateKey(publicKey); }
@Test public void validateKey_wrongVersion() throws Exception { RsaSsaPssPublicKey publicKey = nistTestVectors[0].publicKeyProto; RsaSsaPssPublicKey invalidKey = RsaSsaPssPublicKey.newBuilder(publicKey).setVersion(1).build(); try { verifyManager.validateKey(invalidKey); fail(); } catch (GeneralSecurityException e) { } }
@Test public void validateKey_smallModulus() throws Exception { RsaSsaPssPublicKey publicKey = nistTestVectors[0].publicKeyProto; RsaSsaPssPublicKey invalidKey = RsaSsaPssPublicKey.newBuilder(publicKey) .setN(ByteString.copyFrom(TestUtil.hexDecode("23"))) .setE(ByteString.copyFrom(TestUtil.hexDecode("03"))) .build(); try { verifyManager.validateKey(invalidKey); fail(); } catch (GeneralSecurityException e) { } }