I need to sign certificate by using key from googles KMS and later verify, that coming certificate was actually sign with that key. I'm using bouncycastle provider for most stuff, but having trouble finding right AlgorithmIdentifier for EC_SIGN_P256_SHA256 (algorithm that google use to sign content).
Certificate creation looks like this:
X509v3CertificateBuilder certificateBuilder = new X509v3CertificateBuilder(...);
ContentSigner contentSigner = new ContentSigner() {
...
public AlgorithmIdentifier getAlgorithmIdentifier() {
return new AlgorithmIdentifier(X9ObjectIdentifiers.prime256v1); // wrong
}
public byte[] getSignature() {
byte[] messageHash = MessageDigest.getInstance("SHA-256").digest(this.out.toByteArray());
return signAsymmetric(getKmsKeyName(), messageHash);
}
}
X509CertificateHolder certificateHolder = certificateBuilder.build(contentSigner);
Certificate cert = new JcaX509CertificateConverter().getCertificate(certificateHolder);
signAsymmetric - is more or less copy-paste from google example and seems to be fine.
verification is done like this:
public void verifyCertificate(Certificate signatureCertificate) {
PublicKey publicKey = getAsymmetricPublicKey(getKmsKeyName());
signatureCertificate.verify(publicKey);
}
If I'm using prime256v1 on signatureCertificate.verify(...) it gives "java.security.NoSuchAlgorithmException: 1.2.840.10045.3.1.7 Signature not available", with some other algorithms it just gives signature validation exception. So what would be right way or algorithm id to use? Or it's not possible in such way at all?