Introduction
The REST interface offered by SWS is exposed at the path:
http://<IP-APPLIANCE>:8080/SignEngineWeb/rest/
This path is composed by other sub-path for every of purpose:
- admin: method for sws like remove certificate from cache
- enquiry: contain the method for obtain the information like signatures available, signer certificate, timestamps available ecc...
- sign: this is the principal path of SWS and contain the methods for apply the signature
- timestamps: methods for apply the timestamp on every type of file
And in this guide will be described how manage the error generated by the REST interface.
NOTE: this interface is available from SWS version: 2.5.52
Convention (manage the response)
SWS rest interface use this convention for create the response
Request is CORRECT, will return response code 200 with response body (if present) . Like in this example:
Request NOT-CORRECT with error managed, will return response code 400 and the header will have the field "errorMsg" with error description (in Italian) and field "errorCode" with code error. Like in this example:
NOTE: if you want the "errorMsg" in a specified language, you can use the method "enquiry/errors" will be described in the next section.
Enquiry
ENQUIRY: certificate
Description | return the certifcate associated to "device_signer" |
HttpMethod | POST |
---|---|
Path | /rest/enquiry/certificate |
Request | |
Response | return the byte array of certificate associated to device_signer |
ENQUIRY: signatures
Description | return the numer of signatures apposed from "device_signer" | |
HttpMethod | POST | |
---|---|---|
Path | /rest/enquiry/signatures | |
Request | ||
Response | Number of signatures apposed |
ENQUIRY: signatures-available
Description | return the number of signatures which "device_signer" can apply |
HttpMethod | POST |
---|---|
Path | /rest/enquiry/signatures-available |
Request | |
Response | Number of signatures available |
ENQUIRY: otps
Description | return the otp list associated to "device_signer" |
HttpMethod | POST |
---|---|
Path | /rest/enquiry/otps |
Request | |
Response |
ENQUIRY: timestamps-available
Description | return the numeber of timestamp available (valid only for Namirial TSA account) |
HttpMethod | POST |
---|---|
Path | /rest/enquiry/timestamps-available |
Request | |
Response | Number of timestamps available |
ENQUIRY: errors
Description | return the error description associated to error code |
HttpMethod | POST |
---|---|
Path | /rest/enquiry/errors |
Request | |
Response |
ENQUIRY: all-signature-fields-with-preferences
Description | return a list of SignatureFieldName |
HttpMethod | POST |
---|---|
Path | /rest/enquiry/all-signature-fields-with-preferences |
Header | Content-Type = multipart/form-data Accept = application/json |
Request | |
preferences | { "withDetails": boolean, "withCertificate": boolean, "encryptionPassword": string } |
buffer | PDF file to extract field |
Response | [ { "identifier": string, "signatureDetails": { "name": string, "signDate": unixtime, "location": string, "reason": string, "page": integer, "appearance": { "width": float, "height": float, "x": float, "y": float }, "certificate": "<base64-encoded certificate>", "subjectDN": "string" }, "signed": boolean }, ... ] |
ENQUIRY: available-signature-fields
Description | return a list with name of signature field |
HttpMethod | POST |
---|---|
Path | /rest/enquiry/available-signature-fields |
Header | Content-Type = multipart/form-data Accept = application/json |
Request | |
buffer | PDF file to extract field |
encryptionPassword | password to open PDF if present |
Response | [ "FieldName-1", "FieldName-2", ... ] |
Admin
ADMIN: remove-certificate-from-cache
Description | remove the certificate from cache of SWS |
HttpMethod | PUT |
---|---|
Path | /rest/admin/remove-certificate-from-cache |
Request | |
Response |
Timestamps
TIMESTAMPS: apply
Description | permits to apply timestamp on specified file |
HttpMethod | POST |
---|---|
Path | /rest/timestamps/apply |
Request | |
timestampPreferences | |
content | file to apply timestamp |
Response |
User
USER: change-password
Description | permits to change the password associated to device signer |
HttpMethod | POST |
---|---|
Path | /rest/user/change-password |
Request (for remote device signer) | |
Request (for automatic device signer) | |
Response | Password update succesfully |
Sign
SIGN: openSession
Description | permits to open the sessione for apply multiple sign with remote device |
HttpMethod | POST |
---|---|
Path | /rest/sign/openSession |
Request | |
Response | String with the session |
SIGN: getRemainingTimeForSession
Description | permits to obtain the time until the session is valid |
HttpMethod | POST |
---|---|
Path | /rest/sign/getRemainingTimeForSession |
Request | |
Response | Seconds until the session is valid |
SIGN: closeSession
Description | permits to destroy the session before will expire |
HttpMethod | POST |
---|---|
Path | /rest/sign/closeSession |
Request | |
Response |
SIGN: sendOtpBySMS
Description | permits to destroy the session before will expire |
HttpMethod | POST |
---|---|
Path | /rest/sign/sendOtpBySMS |
Request | |
Response |
SIGN: signCades
Description | permits to apply the cades signature |
HttpMethod | POST |
---|---|
Path | /rest/sign/signCades |
Request | |
credentials | |
cadesPreferences | |
buffer | file to sign |
Response | byte array of signed files |
SIGN: signCades (detached output p7s)
If you want make the Cades detached signature, SWS not require all files to sign, but only the hash. The tag "buffer" will be the hash of the file.
For example if we want the cades detached signature of this PDF the procedure is:
Calculate the hash of this file, for example with the openssl:
openssl dgst -sha256 -binary FILE_TO_BE_SIGN | openssl enc -a
And in output will obtain the hash to sign, will be:
HASH TO SIGN = msj3f4hJCSELbMkWjkFwNrf0XhkebTnAKaKhx4686DY=
Now you can decode this string and will be the input relates to field "buffer"
This string "msj.....DY=" decoded will be the "buffer" on REST signCades like this file (this it the byte array to sign)
Description | permits to obtain the cades detached signature (p7s) , from the hash associated to the file to sign |
HttpMethod | POST |
---|---|
Path | /rest/sign/signCades |
Request | |
credentials | |
cadesPreferences | |
buffer | btye array relates to the hash files to sign |
Response | byte array related to sign of the hash and the certificate associate |
REST RESPONSE:
In output will obtain the hash signed and the certificate associated to the private key which has signed the hash, the response will be this
SIGN: signPades
Description | permits to apply the pades signature |
HttpMethod | POST |
---|---|
Path | /rest/sign/signPades |
Request | |
credentials | |
padesPreferences | |
image | file with image (of appereance) |
buffer | PDF file to sign |
Response | byte array of signed files |
SIGN: signXades
Description | permits to apply the xades signature |
HttpMethod | POST |
---|---|
Path | /rest/sign/signXades |
Request | |
credentials | |
xadesPreferences | |
buffer | XML file to sign |
Response | byte array of signed files |
SIGN: signPKCS1
Description | permits to apply the raw signature (PKCS1) |
HttpMethod | POST |
---|---|
Path | /rest/sign/signPKCS1 |
Request | |
credentials | |
signPreferences | |
buffer | hash to sign |
Response | byte array associated to hash signed |
Verify
VERIFY: signatures
Description | permits to verify the signatures |
HttpMethod | POST |
---|---|
Path | /rest/verify/signatures |
Request | |
signedContent | file to verify |
preferences | |
Response | Report with verify, this is a complex object: "SignedDocumentReportBean" |
Verify timestamp
With SWS is possible to verify TSD and TSR using the preferences, below will be described the REST request.
VERIFY: tsr or tsd
Description | permits to verify the timestamps in tsd or tsr format |
HttpMethod | POST |
---|---|
Path | /rest/verify/timestamps |
Request | |
timestampedContent | file with timestamp |
detachedContent | file original, where timestamp has ben applied (use this field only if you are verifying TSR) |
preferences | |
Response | Return a complex object "TimestampReportBeanSummary" |
VERIFY: tsd
Description | permits to verify the timestamps |
HttpMethod | POST |
---|---|
Path | /rest/verify/timestamps/tsd |
Request | |
tsd | timestamp to verify |
preferences | |
Response | Return a list of complex objects: "TimestampReportBean" |
VERIFY: tsr
Description | permits to verify the timestamps |
HttpMethod | POST |
---|---|
Path | /rest/verify/timestamps/tsr |
Request | |
tsr | timestamp to verify |
content | file original, where timestamp has ben applied |
preferences | |
Response | Return a complex object "TimestampReportBean" |