Articles > Esignature API

How to verify callback data

Legalesign API callbacks, aka webhooks, aka event notifications include a signed string you can use to verify the integrity of the data.

The procedure is the same as verifying AWS SNS broadcasts.

You will need:

  • the data that was sent in JSON format - JSON_DATA_THAT_WE_SENT
  • the signing data - SIGNED_STRING_WE_SENT
  • the X509 certificate (below) - X509_CERT_TEXT

How to find the data:

There are two types of callback, this is how to get the relevant data:

  1. Callback every 6 minutes - the callback is POSTED in two parts, 'data' and 'signed'. The SIGNED_STRING is within the 'signed' part, and the JSON_DATA is within the 'data'.
  2. Callback upon signing - the callback POST dictionary contains 'json_signed', this is the JSON_DATA you will need, and the request will include the custom header X-Signed (or HTTP-X-SIGNED), this is the SIGNED_STRING.

This is the verification procedure in python 2/3, you will need the M2Crypto module:

from M2Crypto import X509
from base64 import b64decode

cert = X509.load_cert_string(str(X509_CERT_TEXT))
pubkey = cert.get_pubkey()
pubkey.reset_context(md='sha1')
pubkey.verify_init()
pubkey.verify_update(JSON_DATA_THAT_WE_SENT) #python2
pubkey.verify_update(JSON_DATA_THAT_WE_SENT.encode()) #python3
verified  = pubkey.verify_final(b64decode(SIGNED_STRING_WE_SENT))
if verified == 1:
   print 'success!'
else:
   print 'fail :('

X509 certificate:

-----BEGIN CERTIFICATE-----
MIIFSjCCAzICAQAwDQYJKoZIhvcNAQEFBQAwazEeMBwGA1UEBxMVRWRpbmJ1cmdo
LFNjb3RsYW5kLEdCMRswGQYDVQQKExJMZWdhbGVzaWduIExpbWl0ZWQxLDAqBgNV
BAMUI2xlZ2FsZXNpZ24uY29tL2VtYWlsQGxlZ2FsZXNpZ24uY29tMB4XDTEzMDIw
MTE2MjgyN1oXDTMzMDIwMTE2MjgyN1owazEeMBwGA1UEBxMVRWRpbmJ1cmdoLFNj
b3RsYW5kLEdCMRswGQYDVQQKExJMZWdhbGVzaWduIExpbWl0ZWQxLDAqBgNVBAMU
I2xlZ2FsZXNpZ24uY29tL2VtYWlsQGxlZ2FsZXNpZ24uY29tMIICIjANBgkqhkiG
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VSaRgJ5JZBkUtr2eTvvhL
iPBwjOfdba4rulqVni7joN1k4ulYnrpf6jmC/sbUPQkU9HbAUOhibyLEkysEhUPb
78aFbM+4c6rhzSRL5gvN7lVmBTZimmIs0x5y+Q5+GSIrRZgHkSxOGkrQtdsrJStg
zerSTb5dF+L9Jv0d2AhIWMLP4KIO4NMj/ljiPOwtqPHU2KSsRivJA1xybFI4peBE
aAocb936W/RabYdVCPITLsYA4ThApMI+jpJPvG8JKTrauOwZRBOq82lBJuoBgkAp
h6A3SPeR5GCnCRmPIvrv21Q7dm7Gg4lbPtEemH3QdNlCIY1BzADD/H1zDAU+0J5P
+PUQCjWRM3JmFbuYTjs=
-----END CERTIFICATE-----

You can force the system to send a test API notification to your callback URL if you are still in sandbox mode by using the /api/v1/sandbox/ endpoint .

curl --dump-header - -H "Authorization: ApiKey [x]:[y]"  -X GET "https://eu-api.legalesign.com/api/v1/sandbox/?resource_uri=test&value=1"