Reputation: 1668
I have a small JSON file which contains an EC signature generated by SubtleCrypto.sign() ECDSA algorithm and SHA512 digest. Now I manually generate the signature, but I would like to automate it. I have a restriction to use the nginx:alpine
base image to do that. So I have installed OpenSSL, but it turns out, SubbtleCrypto.verify() needs the signature in IEEE P1363 format, but OpenSSL uses the ASN1 format. Is there a way to use the signature generated by openssl
in the browser?
Note:
I created the EC key pair in the browser and it is working fine when the signature is generated with SubtleCrypto.sign().
Then I have exported the private key in PKCS#8 format, and saved it as a PEM file to be used as an input for OpenSSL.
-----BEGIN EC PRIVATE KEY-----
<Base64 encoded content here...>
-----END EC PRIVATE KEY-----
and use the following to generate the signature in Base64 for {}
(data.json)
$ openssl dgst -sha512 -sign private.pem data.json | base64
MIGHAkEZ0YthoqLqCW1ll0MvPEYdhoz+p1zxQnLt0sl0rSvD8eI0BdAeQUqS1fUlNi8O39ClI6OI
JDZJqJ3OkTFkMyqzaAJCAT8koJnhqv2PUHla7EWV/qVIBb9LtPovQODl0+CsBQlkGO+TKkX3X57+
rpOZMqYv1tIOAz1m5ry0sOo0hGSe4c8X
then I used this website (the link contains the signature as well in Base64 encoded ASN1 format): asn1 decoder to get the r and s decimal values, and then followed this SO answer:
r = 346169932049245619871744113024266741326899713498883047336224784039276978051811648336988371154157537871201508197563500632048282301939214838670217488915673960
s = 4279009059525041370739088323750483074176965727856497966083564113228214038964554024207556176396942898795827323835166902701178318351093672293528073206493204247
hex_val = 19D18B61A2A2EA096D6597432F3C461D868CFEA75CF14272EDD2C974AD2BC3F1E23405D01E414A92D5F525362F0EDFD0A523A388243649A89DCE913164332AB368013F24A099E1AAFD8F50795AEC4595FEA54805BF4BB4FA2F40E0E5D3E0AC05096418EF932A45F75F9EFEAE939932A62FD6D20E033D66E6BCB4B0EA3484649EE1CF17
and the resulting base64 signature is
GdGLYaKi6gltZZdDLzxGHYaM/qdc8UJy7dLJdK0rw/HiNAXQHkFKktX1JTYvDt/QpSOjiCQ2SaidzpExZDMqs2gBPySgmeGq/Y9QeVrsRZX+pUgFv0u0+i9A4OXT4KwFCWQY75MqRfdfnv6uk5kypi/W0g4DPWbmvLSw6jSEZJ7hzxc=
and that fails to verify in the browser.
Edit:
I have created an example with the calculations I have made here. I generated the signature with the above openssl command with the key file given and a json file containing {}
only.
Upvotes: 0
Views: 496