Skip to content

allanjuhanson/MID

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 

Repository files navigation

MID API

1. Introduction

MID REST interface offers the entry point to main use cases for Mobile-ID, i.e. certificate choice, creating signature and authentication.

1.1. Terminology

  • Relying Party (RP) - a provider of some kind of e-service. Relying Party authenticates users via MID REST service. 
  • Session- A proccess initated by Relying Party, which contains a single certificate choice, authentication or signing operation.

2. General description

Mobile-ID API is exposed over a REST interface as described below. All messages are encoded using UTF-8. 

2.1. UUID encoding

UUID values are encoded as strings containing hexadecimal digits, in canonical 8-4-4-4-12 format, for example:    de305d54-75b4-431b-adb2-eb6b9e546014 

2.2.  relyingPartyName handling

relyingPartyName request field is case insensitive. The string is passed to end user as sent in via API.

2.3. Hash algorithms

MID REST supports signature operations based on SHA-2 family of hash algorithms, namely SHA-256, SHA-384 and SHA-512. Their corresponding identifiers in API are "SHA256", "SHA384" and "SHA512".

2.4. Verification code

Verification code is a 4-digit number used in mobile authentication and mobile signing which is cryptographically linked with hash value to be signed. Verification code is displayed both in mobile phone and application in order to provide for authenticity of the signing request.

During Mobile-ID authentication and signing this is required that e-service provider calculates verification code from the hash what will be signed and displays it to the user.

2.4.1. Verification code calculation algroithm

6 bits from the beginning of DTBS (hash senior bits) and 7 bits from the end of DTBS are taken. The resulting 13 bits are transformed into decimal number and printed out. The Verification code is a decimal 4-digits number in range 0000-8192, always 4 digits are displayed (e.g. 0041).

Example:

  • Hash value: 2f665f6a6999e0ef0752e00ec9f453adf59d8cb6
  • Binary representation of hash: 0010 1111 0110 0110 1111 .... 1000 1100 1011 0110
  • Verification code – binary value:0010110110110
  • Verification code – decimal value (displayed for the user): 1462

3. REST API

3.1. Session management 

Session is created using one of the POST requests and it ends when a result gets created or when session ends with an error. Session result can be obtained using GET request described below. 

3.2. HTTP status code usage

Normally, all positive responses are given using HTTP status code "200 OK". 

In some cases, 4xx series error codes are used, those cases are described per request. All 5xx series error codes indicate some kind of fatal server error. 

Response on successful session creation 

This response is returned from all POST method calls that create a new session. 

Parameter Type Mandatory Description
sessionId string + A string that can be used to request operation result, see below.

{
"sessionId" : "de305d54-75b4-431b-adb2-eb6b9e546015"
}

4. REST API main flows

BASE: mid-api

4.1. Certificate request

**Method** **URL**
POST BASE/certificate

This method retrieves the signing certificate.

This method is necessary for *AdES-styled digital signatures which require knowledge of the certificate before creating the signature.

NB! This method will be updated during February 2018. Please come back for updated version soon.

4.1.1. Preconditions 

  • User identified in the request (by relyingPartyName, relyingPartyUUID and IP-address)

4.1.2. Postconditions

  • Request result has been returned to user. 

4.1.3. Request parameters

Parameter

Type

Mandatory

Description

relyingPartyName string + Name of the relying party – previously agreed with Application Provider and DigiDocService operator.
relyingPartyUUID string + UUID of the relying party
phoneNumber string + Phone number of the signer with the country code in the format of +xxxxxxxxx
nationalIdentityNumber string + Identification number of the signer (personal national ID number)

4.1.4. Example request

{

"relyingPartyUUID" : "de305d54-75b4-431b-adb2-eb6b9e546014" ,
"relyingPartyName" : "BANK123",
"phoneNumber" : "+3726234566" ,
"nationalIdentityNumber" : "31111111111"

}

4.1.5. Example response

{
"result": "OK",
"cert": "MIIHhjCCBW6gAwIBAgIQDNYLtVwrKURYStrYApYViTANBgkqhkiG9w0B..."
}

4.1.6. Response structure 

Parameter

Type

Mandatory

Description

result string + End result of the transaction.
cert string for OK result Certificate value, DER + Base64 encoded.

4.1.7. Error conditions

Error code Error message Reason
500 Error retrieving certificate response Getting sessionId from cert-store fails. Cert-store throws internal server error
404 Something went wrong, response not found Cert-store cannot find response for given request.
400 RelyingParty name cannot be null. Parameter in request is missing on has incorrect format/value
401 Failed to authorize user User authorization by relyingPartyName, relyingPartyUUID and IP-address fails
405 Method Not Allowed

4.1.8. Possible result values

Response Reason
OK Active certificate was found
NOT_FOUND No certificate for the user was found
NOT_ACTIVE Certificate was found but is not active

4.3. Signature request

**Method** **URL**
POST BASE/signature

This method is the main entry point to signing logic.

4.3.1. Preconditions

  • User identified in the request.

4.3.2. Postconditions

  • a new session with ID is returned in response. 

4.3.3. Request parameters

Parameter

Type

Mandatory

Description

relyingPartyName string + Name of the relying party – previously agreed with Application Provider and DigiDocService operator.
relyingPartyUUID string + UUID of the relying party
phoneNumber string + Phone number of the signer with the country code in the format of +xxxxxxxxx
nationalIdentityNumber string + Identification number of the signer (personal national ID number)
hash string + Base64 encoded hash function output to be signed.
hashType string + Hash algorithm.
language string + Language for user dialog in mobile phone. 3-letters capitalized acronyms are used. Possible values: EST, ENG, RUS, LIT
displayText string - Text displayed in addition to ServiceName and before asking authentication PIN. Maximum length is 40 bytes. In case of Latin letters, this means also a 40 character long text, but Cyrillic characters may be encoded by two bytes and you will not be able to send more than 20 symbols.

4.3.4. Example request

{

"relyingPartyUUID" "de305d54-75b4-431b-adb2-eb6b9e546014" ,
"relyingPartyName" "BANK123" ,
"phoneNumber" "+3726234566" ,
"nationalIdentityNumber" "31111111111" ,
"hash" "ZHNmYmhkZmdoZGcgZmRmMTM0NTM..." ,
"hashType" "SHA256" ,
"language" "EST" ,
"displayText" "Sign contract"

}

4.3.5. Example response

{   
"sessionId" "de305d54-75b4-431b-adb2-eb6b9e546015"
}

4.3.6. Error codes

Error code Error message Reason
500 Error retrieving certificate/mssp response Happens when getting sessionId from cert-store/mssp fails. Cert-store/MSSP throws internal server error
404 Something went wrong, response not found Happens when cert-store/mssp cannot find response for given request.
400 Happens when parameter in request is missing on has incorrect format/value
400 Required sessionId is missing :sessionID Happens when sessionID is missing.
400 The length of the hash must match the type of hash Hash length does not match the type of hash. For example: hash: SHA256, hashtype:SHA384
400 Hash must be Base64 encoded Hash is not base64 encoded.
401 Failed to authorize user User authorization by relyingPartyName, relyingPartyUUID and IP-address fails
405 Method Not Allowed

4.4. Signature status

**Method** **URL**
GET BASE/signature/session/:sessionId

Query parameter timeoutMs Request long poll timeout value in milliseconds. If not provided, a default is used. Server configuration may force this value into a certain range

This method can be used to retrieve session result for signature from MID.

This is a long poll method, meaning it might not return until a timeout expires. Caller can tune the request parameters inside the bounds set by service operator by using the timeoutMs query parameter.

Example:

BASE/signature/session/93de76af-68c1-4b55-91f7-3dad52b3115d?timeoutMs=10000

4.4.1. Preconditions

  • Session is present in the system and the request is either running or has been completed less than x minutes ago. 

4.4.2. Postconditions

  • Request result has been returned to user. 

4.4.3. Response structure 

Parameter

Type

Mandatory

Description

state string + State of request. "RUNNING"/"COMPLETE".
result string + End result of the transaction.
signature string + Structure describing the signature result, if any.
signature.value string + Signature value, base64 encoded.
signature.algorithm string + Signature algorithm, in the form of sha256WithRSAEncryption

successful response when still waiting for user's response

{
"state" "RUNNING" ,
"result" : {}
}

 
successful response after completion

{
"state": "COMPLETE",
"result": "OK",
"signature": {
"value": "B+C9XVjIAZnCHH9vfBSv...",
"algorithm": "sha512WithRSAEncryption"
}
}

4.4.4. Error codes

Error code Error message Reason
500 Error retrieving mssp response Happens when getting session status from mssp fails. MSSP throws internal server error
404 SessionId not found :sessionID SessionID in request is not found
400 Required sessionId is missing :sessionID Happens when sessionID is missing.
401 Failed to authorize user User authorization by sessionID and IP-address fails
405 Method Not Allowed

4.5. Authentication request

**Method** **URL**
POST BASE/authentication

This method is the main entry point to authentication logic.

4.5.1. Preconditions

  • User identified in the request. 

4.5.2. Preconditions

  • New session has been created in the system and its ID returned in response. 

4.5.3. Authentication request parameters

Parameter

Type

Mandatory

Description

relyingPartyName string + Name of the relying party – previously agreed with Application Provider and DigiDocService operator.
relyingPartyUUID string + UUID of the relying party
phoneNumber string + Phone number of the signer with the country code in the format of +xxxxxxxxx
nationalIdentityNumber string + Identification number of the signer (personal national ID number)
hash string + Base64 encoded hash function output to be signed.
hashType string + Hash algorithm.
language string + Language for user dialog in mobile phone. 3-letters capitalized acronyms are used. Possible values: EST, ENG, RUS, LIT
displayText string - Text displayed in addition to ServiceName and before asking authentication PIN. Maximum length is 40 bytes. In case of Latin letters, this means also a 40 character long text, but Cyrillic characters may be encoded by two bytes and you will not be able to send more than 20 symbols.

4.5.4. Example request

{

"relyingPartyUUID": "de305d54-75b4-431b-adb2-eb6b9e546014",
"relyingPartyName": "BANK123",
"phoneNumber": "+3726234566", "nationalIdentityNumber": "31111111111",
"hash": "ZHNmYmhkZmdoZGcgZmRmMTM0NTM...",
"hashType": "SHA256",
"language": "EST",
"displayText": "Log into internet banking system"

}

4.5.5. Example response

{   
"sessionId" "de305d54-75b4-431b-adb2-eb6b9e546015"
}

4.5.6. Error codes

Error code Error message Reason
500 Error retrieving certificate/mssp response Happens when getting sessionId from cert-store/mssp fails. Cert-store/MSSP throws internal server error
404 Something went wrong, response not found Happens when cert-store/mssp cannot find response for given request.
400 Happens when parameter in request is missing on has incorrect format/value
400 Required sessionId is missing :sessionID Happens when sessionID is missing.
400 The length of the hash must match the type of hash Hash length does not match the type of hash. For example: hash: SHA256, hashtype:SHA384
400 Hash must be Base64 encoded Hash is not base64 encoded.
401 Failed to authorize user User authorization by relyingPartyName, relyingPartyUUID and IP-address fails

4.6. Authentication status

**Method** **URL**
GET BASE/authentication/session/:sessionId

Query parameter timeoutMs Request long poll timeout value in milliseconds. If not provided, a default is used. Server configuration may force this value into a certain range

This method can be used to retrieve session result for authentication from MID.

This is a long poll method, meaning it might not return until a timeout expires. Caller can tune the request parameters inside the bounds set by service operator by using the timeoutMs query parameter.

Example:

BASE/authentication/session/93de76af-68c1-4b55-91f7-3dad52b3115d?timeoutMs=10000

4.6.1. Preconditions

  • Session is present in the system and the request is either running or has been completed less than x minutes ago. 

4.6.2. Postconditions

  • Request result has been returned to user. 

4.6.3. Response structure 

Parameter

Type

Mandatory

Description

state string + State of request. "RUNNING"/"COMPLETE".
result string + End result of the transaction.
signature string + Structure describing the signature result, if any.
signature.value string + Signature value, base64 encoded.
signature.algorithm string + Signature algorithm, in the form of sha256WithRSAEncryption
cert string for OK Certificate value, DER + Base64 encoded.

successful response when still waiting for user's response

{
"state" "RUNNING" ,
"result" : {}
}

 
successful response after completion

{
   "state" "COMPLETE" ,
   "result" : "OK" ,
   "signature" : {
       "value" "B+C9XVjIAZnCHH9vfBSv..." ,
       "algorithm" "sha512WithRSAEncryption"
   },
   "cert" : "B+C9XVjIAZnCHH9vfBSv..."
}

4.6.4. Error codes

Error code Error message Reason
500 Error retrieving signature response Happens when getting session status from mssp fails. MSSP throws internal server error
404 SessionId not found :sessionID SessionID in request is not found
400 Required sessionId is missing :sessionID Happens when sessionID is missing.
401 Failed to authorize user User authorization by sessionID and IP-address fails
405 Method Not Allowed

5. Session end result codes

Response Reason
OK Session was completed successfully
TIMEOUT There was a timeout, i.e. end user did not confirm or refuse the operation within given timeframe. 
ERROR There was error getting response from MSSP/certificate service
NOT_MID_CLIENT Given user has no active certificates and is not M-ID client.
EXPIRED_TRANSACTION MSSP transaction timed out.
USER_CANCELLED User cancelled the operation
MID_NOT_READY Mobile-ID not ready
PHONE_ABSENT  Sim not available
DELIVERY_ERROR SMS sending error
SIM_ERROR Invalid response from card
SIGNATURE_HASH_MISMATCH Hash does not match with certificate type
INTERNAL_ERROR All other technical errors

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published