Page tree
Skip to end of metadata
Go to start of metadata

Paketes kopsavilkuma aprēķināšanas piemērs

Scope

Provide a signable data value calculation from the signable file by using the end-user signature certificate received.

Description

1. Start signing session. If there are problems with the files or the request does not meet the format requirements for the document signing, the process is terminated and an error is returned;
2. The hash of each file to be signed are calculated as well as signable data;
3. The signature algorithm  is determined from certificate;
4. The prepared signable data in base64 format is returned to the requester for signature.

Request

The Service provider's application sends the following GET request using TLS:

POST /api-sign/v1.0/CalculateDigest 

Authorization

The request must contain an Authorization header with an OAuth Introspect access token obtained via Integration Platform a Service provider's credentials grant flow.

 Sign API authorization - Obtain a Introspect access token

Introspect piekļuves talona (token) saņemšana

Description

This operation obtains an OAuth 2.0 access token. This operation can be invoked as part of an OAuth 2.0 Service provider's credentials grant flow.

Introspect access token

When the Service provider's credentials grant flow is used, the obtained access token demonstrates the administrative authorization of the Service provider's application making the call for accessing certain resources or services (i.e., without direct intervention of the resource's owner), or for accessing resources of the Service provider's application. Token is issued when the authorization server that processes the request is not associated to an identity provider. A token of this type can be used for accessing resources not associated to end-users or to end-user resources of any domain.

This type of access token is used to get access to Signature creation and validation service API's

Request

To obtain the token, the Service provider's application must send a request like the following to authorization server using TLS. This request is sent directly from the Service provider’s application to authorization server and does not go via the browser.

POST /trustedx-authserver/oauth/{as}/token

Parameter

Title

Type

Field

Description

as

path

mandatory

Use "lvrtc-eipsign-as"

Host:

Test environment: eidas-demo.eparaksts.lv

Production: eidas.eparaksts.lv

Content-Type Header

Content-Type: application/x-www-form-urlencoded; charset=UTF-8


In HTTP POST request is necessary to incorporated the following main attribute: Authorization – API access token.

Authorization: Basic <API-Key>

How to generate API Access Key

 API Access Key basics...

Before Service provider access Integration platform API, LVRTC shall register Service provider as customer of Integration platform. After signing a contract with LVRTC (Test of Production environment) LVRTC generates Service Provider’s application identifier – (client_id) and shared secret (client_secret), intended for the customer usage.
API Access Key (API Key) is generated from the Service provider’s application identifier (client_id), a secret shared with the platform (client_secret)  on the following basis:

Service provider's application identifier client_id are converted using the UTF-8 character encoding and URL encoding conditions.

(warning)  For example, value "Portāls" conversion result is "port%C4%81ls".

Service provider's application password client_secret is converted by using the UTF-8 character encoding and URL encoding conditions.

(warning)  For example, value "drošība" conversion result is "dro%C5%A1%C4%ABba".

Both values of the previous two steps must be combined with separator colon “:” between them.

(warning)  For example, by using previous examples, the result will be "port%C4%81ls:dro%C5%A1%C4%ABba".

Obtained value must be converted using base 64 encoding without line breaks.

(warning)  For example, values "port%C4%81ls:dro%C5%A1%C4%ABba" conversion result is "CG94ydCVDNCUMWxzOmRybyVDNSVBMSVDNCVBQmJh".

"MIME Tools" tool in "Notepad + +" can be used for this purpose.

API-Key = base64[url_encode(utf8(<client_id>)) ':' url_encode(utf8(<client_secret>))]

Body

The content of the request for Introspect access token (used for access SignAPI service):

Property

Usage

Description

grant_type

mandatory

Must have the client_credentials value .

scopemandatoryMust have the urn:safelayer:eidas:oauth:token:introspect value

Example (Introspect access token)

The following example shows a situation in which the Service provider’s application with the identifier "Portal" and the password "drošība" authority shall transmit the request to the server with the identifier "lvrtc-eips-as":

POST /trustedx-authserver/oauth/lvrtc-eipsign-as/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Authorization: Basic CG94ydCVDNCUMWxzOmRybyVDNSVBMSVDNCVBQmJh
Host: eidas-demo.eparaksts.lv
grant_type=client_credentials&
			scope=urn%3Asafelayer%3Aeidas%3Aoauth%3Atoken%3Aintrospect

Response

In response, Integration platform authorization server issues a bearer-type OAuth 2.0 access token and returns it in a JSON structure.

{
"access_token" : {string}, 
"token_type" : "Bearer", 
"expires_in" : {number}
}

Parameter

PropertyDescription
access_token
Access token generated by Authorization server. The token has the characteristics specified in the configuration of the authorization server that processed the request and consists of a random string of the number of bytes specified in the Access token number of random bytes (by default, 32), encoded in hexadecimal.
token_type
Type of access token. Always has the "bearer" value. (Bearer type OAuth 2.0 access token).
expires_in
Lifetime (in seconds) of the access token. The Service provider’s application must perform the access the token authorizes before the token expires. This value can be configured in the Token timeout option of the authorization server (by default, 120 seconds). Once this timeout has expired, the token becomes invalid, and the Service provider’s application must obtain another one if it wants to continue invoking the protected services.

Example

Introspect access token:

HTTP/1.1 200 OK
Content-Type: application/json;charset=utf-8 
Cache-Control: no-store, no-cache, must-revalidate 
Pragma: no-cache
{
 "scope": "urn:safelayer:eidas:oauth:token:introspect",
 "access_token": "dfffb0d7f90bed142464750cacad5e4b9e23f58ecb1d77e3bdf706ba208ad16a",
 "token_type": "Bearer",
 "expires_in": 600
}



Body

{
"sessions":[
    {
      "sessionId": "string"
    }
  ],
  "certificate": "string",
  "signAsPdf": true,
  "createNewEdoc": true
}

PropertyDescription
sessions
Information about file processing sessions
sessions.sessionId
File processing session identifier. It is possible to specify multiple sessions.
certificate
Signing certificate in base64 format
signAsPdf
True - will be signed as PDF (can only be used for signing PDFs and only one PDF file per session). In this case, the propery "createNewEdoc" will be ignored.
False - will create XAdES signature in ASICE container (EDOC).
createNewEdoc

True - Always creates new ASICE container (even if signable file is already a ASICE container - ASICE in the ASICE container);

False - If existing file is ASICE container, new signature will be added within existing ASICE container. If file is not ASICE, it will be added in ASICE container.


Example of single session signing

POST /api-sign/v1.0/CalculateDigest HTTP/1.1
Authorization: Bearer a477b3a3366768c07e4c458f518711b4b351e8d2c2f0f78a1524e4d3efd00603
Host: signapi-prep.eparaksts.lv
{
  "sessions": [
     {
        "sessionId": "fefdaec2b14bf2977d32a861fb49545244c654f7a4736dcc081ae1857a3a3dd4"
     }
  ],
  "certificate": "MIIG/j.......<sign certificate base64 here>.......xFP/IP==",
  "signAsPdf": false,
  "createNewEdoc": false
}

Example of batch session signing

POST /api-signing/v1.0/CalculateDigest HTTP/1.1
Authorization: Bearer a477b3a3366768c07e4c458f518711b4b351e8d2c2f0f78a1524e4d3efd00603
Host: signapi-prep.eparaksts.lv
{
  "sessions": [
          {
                 "sessionId": "fefdaec2b14bf2977d32a861fb49545244c654f7a4736dcc081ae1857a3a3dd4"
          },
          {
                 "sessionId": "fefdaec2b14bf2977d32a861fb49545244c654f7a4736dcc081ae18512121212"
          },
          {
                 "sessionId": "fefdaec2b14bf2977d32a861fb49545244c654f7a4736dcc081ae185bbbbbbbb"
          }
  ],
  "certificate": "MIIG/j.......<sign certificate base64 here>.......xFP/IP==",
  "signAsPdf": false,
  "createNewEdoc": false
}


Response

JSON object:

{
"sessionDigests":[
    {
      "sessionId": "string",
      "digest": "string",
      "error": {
          "code": "string",
          "message": "string"
      }
    }
  ],
  "digests_summary": "string",
  "algorithm": "string"
}

PropertyDescription
sessionDigest
Information about signable data session
sessionDigest.sessionId
File processing session identifier
sessionDigest.diggest

Signable data in base64 format

In case of server signing - received "diggest" property value shall be used (as is, without any reformatting) in Electronic signature provider API when Create a Digital Signature on the Server as "digest_value" property value.

In case of signing with Smart Card by using LVRTC provided browser extension integration, then this value shall be converted to HEX.

sessionDigests.error
Session error if any
sessionDigests.error.code
Session error code
sessionDigests.error.message
Session error message 
digests_summary

(warning) This parameter must only be used to obtain the authorization from the end-user for generating a digital signature with a server signing identity enabled via password stored on the HSM. (warning)

It is already precalculated digest summary. In case of server signing - "digests_summary" property value shall be used (as is, without any reformatting) in OAuth2.0 Authorization API when obtaining authorization code for signing operation as "digests_summary" property value.

algorithm
Algorithm of the digital signature


Example of single session signing

{
   "data": {
       "sessionDigests": [
           {
               "sessionId": "a37e460b4c65cb01a01dce5c58149806ca2d20dab22e99905d45128c4e693a90",
               "digest": "4xZX5G+R4gTbK2r6RlismZw4EBftvbSDcE3lXfpLMM4="
           }
       ],
       "digests_summary": "mnF3XVRWujh/Tsc3oA2HVGl0SI8VNb3pmscMcDhEzDo=",
       "algorithm": "SHA256"
   }
}

Example of batch session signing 

{
  "data": {
          "sessionDigests": [
                 {
                    "sessionId": "fefdaec2b14bf2977d32a861fb49545244c654f7a4736dcc081ae1857a3a3dd4",
                    "digest": "wRX+DNmDdlDrMK8X/MEdersGZbsgTiSFHi26domxjwA="
                 },
                 {
                    "sessionId": "fefdaec2b14bf2977d32a861fb49545244c654f7a4736dcc081ae18512121212",
                    "digest": "wRX+DNmDdlDrMK8X/MEdersGZbsgTiSFHi26domxjwA="
                 },
                 {
                    "sessionId": "fefdaec2b14bf2977d32a861fb49545244c654f7a4736dcc081ae185bbbbbbbb",
                    "digest": "wRX+DNmDdlDrMK8X/MEdersGZbsgTiSFHi26domxjwA="
                 }
           ],
                  "digests_summary": "mnF3XVRWujh/Tsc3oA2HVGl0SI8VNb3pmscMcDhEzDo=",
         "algorithm": "SHA256"
  }
}



  • No labels