Verify AWS SNS signature with PEM certificate
Hello, I'm trying to verify aws sns messages in deno given a signing cert (in pem format, RSA sha1) and signature. However, when I do crypto.subtle.importKey, I keep getting this error:
My attempt:
thanks
2 Replies
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the error message you've provided, it seems like there might be an issue with the format of the DER-encoded key you're trying to import. The error suggests that the ASN.1 DER structure is not as expected for an OBJECT IDENTIFIER.
From the code snippet you've shared, it looks like you're trying to import a PEM certificate as a SPKI (SubjectPublicKeyInfo) format, which is generally correct for public keys. However, please ensure that you are correctly converting the PEM certificate to the binary DER format before attempting to import it. The PEM certificate should have the "BEGIN CERTIFICATE" and "END CERTIFICATE" headers removed, and the remaining base64-encoded string should be converted to a Uint8Array (binary format).
Here's a general approach to convert a PEM certificate to DER format:
Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of this advice. If the issue persists after ensuring the PEM to DER conversion is correct, you may want to verify that the certificate is indeed in the correct format and that there are no issues with the certificate itself.
This ^ but I had to extract the public key from the cert using https://deno.land/x/jose@v5.2.1/index.ts, export that to public key string, then do this ^ but removing BEGIN PUBLIC KEY and END PUBLIC KEY, and then doing crypto.subtle.importKey() on that