Tabella dei contenuti
How to verify a response signed by a producer
The ModI leaves it to the producer’s discretion to indicate what the correct payload signing and verification procedure by the consumer should be.
Below is, by way of example, a possible management of the response payload signing mechanism of an e-service.
For more information, see the dedicated section.
When a consumer receives a response signed by the producer, they can verify the authenticity and integrity of the data received in the response through the kid (key ID) inserted in the payload and the public key that the producer has stored in their Producer Keychain, associated with the e-service.
Step 1 - Deserializing the response
Once the payload created by the producer in the previous tutorial has been deserialized, the consumer will find the JSON response that the producer sent, structured as follows:
1{
2 "data": {
3 "field1": "value1",
4 "field2": "value2"
5 },
6 "signature": "<rsa_signature_in_base64>",
7 "kid": "<id_public_key>"
8}
9
10
Field name | Meaning |
---|---|
data | contains the payload, i.e., the actual data that the e-service transmits to consumers |
signature | contains the digital signature of the data field, calculated by the e-service using an RSA private key (belonging to an e-service keystore) and encoded in Base64 format |
kid | identifier of the key used for signing; allows the consumer to know which public key to use to verify the signature |
The process then continues with the signature verification.
Step 2 - Identification of the public key
The key corresponding to the kid is available on the APIs exposed by PDND.
To obtain the key from PDND, the consumer must have:
- created a client of type API Interop (read tutorial);
- generated at least one set of cryptographic material and uploaded the corresponding public key to PDND within the client (read tutorial);
- obtained a valid voucher for the APIs of PDND (read tutorial).
The consumer will find it at the path GET /keys/{kid} in JWK format.
Step 3 - Recalculating the hash
The consumer calculates the hash of the content of data using the same algorithm used by the producer: SHA256.
Step 4 - Verifying the signature
With the public key obtained in Step 2, the consumer verifies that the signature (the signature field) matches the hash calculated in Step 3. If the two values match, the payload is authentic and intact; otherwise, it may have been altered or may not come from the e-service, and it is possible to contact the producer for more information.
Hai bisogno di aiuto?
Apri un ticket utilizzando l’apposita funzione all’interno della tua Area Riservata