SIM Signing using CIBA (PKCS1)

Step by step instructions for service providers on how to Signing using CIBA and SIM certificate.

Table of Contents

 

Requirements

For all steps to be successful the following must be at hand.

During setup

  • Client Id (received from Auðkenni)

  • Client secret (received from Auðkenni)

  • Related party (not necessary)

  • Base URI (received from Auðkenni)

  • Private Key (to sign a JSON Web Token)

  • Public Key (to give to Auðkenni for configuration)

Information needed at runtime

  • User’s mobile number

  • Message text for user (Including any verification messages: number, text etc.)

 

Setup requirements used in the examples

  • Client id: myCibaClientId

  • Client secret: MyApiClientP4$sW

  • Base URI: pfzww.audkenni.is

  • Private Key: Not shown here for security reasons

  • Public Key: Not shown

All code examples are generated using Postman. They are therefore only for demo.

 

Step 1

Step 1: (Creating JSON Web Token)

The first step is to create a signed JWT to use for CIBA communication.

What the JWT need to include

  • login_hint (the users mobile number)

  • scope (openid, profile, signature. Also possible to add “related party” info here (see example))

  • acr_values (“sim-sign-pkcs1”. This value is different between authentication/signing methods)

  • iss (the Client id)

  • aud (Should have “https://pfzww.audkenni.is:443/sso/oauth2/realms/root/realms/audkenni“)

  • exp (the lifetime of the token)

  • binding_message (the message to display at users mobile device)

  • binding_content (base64 string of a SHA256 hash)

Also needed to create the JWT

  • Private key (to sign the JWT)

  • Alg info (Should be “RS256”)

Example of JWT

eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJsb2dpbl9oaW50IjoiOTg3NjU0MyIsInNjb3BlIjoib3BlbmlkIHByb2ZpbGUgc2lnbmF0dXJlIFJFTEFURURQQVJUWTpNeU93bkNsaWVudCIsImFjcl92YWx1ZXMiOiJzaW0tc2lnbi1wa2NzMSIsImlzcyI6Im15Q2liYUNsaWVudElkIiwiYXVkIjoiaHR0cHM6Ly9wZnp3dy5hdWRrZW5uaS5pczo0NDMvc3NvL29hdXRoMi9yZWFsbXMvcm9vdC9yZWFsbXMvYXVka2VubmkiLCJleHAiOjE2MTExNDk0NTkuMTIyLCJiaW5kaW5nX21lc3NhZ2UiOiJBdcOwa2VubmkgU0lNIFNpZ25pbmciLCJiaW5kaW5nX2NvbnRlbnQiOiJQR1RMZitkeUtZU0EvR0tRMnJacUVRZXBmL3JZSExnZ0pyY3RZa0xHYlN3PSJ9.DRHn9-ueuLhr0y3RMu7NTS6_i3L2LbxLbwhnZg8JO6oLwmHtXenZXRGpF3n6Lgo3YRZPhpK6Tc_6kvMHmTyMQW2g2fTyFMylX2Z19rWwS5oHqTFGaqfLuePhzSxIFPUI56ofKp6jS4mb1dC85mxKrMxgvrlBgIlvA_rx9DqNUgSYyETzeBELlTwWdTOhJuCv-N53Ngt7Ro-s_FDceyOeVl_V-BJALO8Y6r2PF2DkKYFHW-4ykQc_MX3lhJYdaY6w26yYC1XkggmXsLz-JWVbwveB0JMv_5j2j6OiPnuKhkFWAoVKlS0rVENZCSZ_rptgPq9VT7ajlyeebB8mbcSm7w

 

Example of JWT Payload

{ "login_hint": "9876543", "scope": "openid profile signature RELATEDPARTY:MyOwnClient", "acr_values": "sim-sign-pkcs1", "iss": "myCibaClientId", "aud": "https://pfzww.audkenni.is:443/sso/oauth2/realms/root/realms/audkenni", "exp": 1611149459.122, "binding_message": "Auðkenni SIM Signing", "binding_content": "PGTLf+dyKYSA/GKQ2rZqEQepf/rYHLggJrctYkLGbSw=" }

 

 

Step 2

 

Step 2: (Sign)

To sign using mobile (SIM) we send a POST call to following URI:
https://pfzww.audkenni.is:443/sso/oauth2/realms/root/realms/audkenni/bc-authorize

 

Parameters needed in call

We need to add following header parameter

  • A Basic Auth header, using the Client id and Client secret

We need to add following parameter

  • request (the value should be the JWT from step 1)

 

CURL example of the call

curl --location --request POST 'https://pfzww.audkenni.is:443/sso/oauth2/realms/root/realms/audkenni/bc-authorize' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --header 'Authorization: Basic bXlDaWJhQ2xpZW50SWQ6TXlBcGlDbGllbnRQNCRzVw==' \ --data-urlencode 'request=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJsb2dpbl9oaW50IjoiNjE3ODg4OCIsInNjb3BlIjoib3BlbmlkIHByb2ZpbGUgc2lnbmF0dXJlIFJFTEFURURQQVJUWTpNeU93bkNsaWVudCIsImFjcl92YWx1ZXMiOiJzaW0tc2lnbiIsImlzcyI6Im15Q2liYUNsaWVudElkIiwiYXVkIjoiaHR0cHM6Ly9wZnp3dy5hdWRrZW5uaS5pczo0NDMvc3NvL29hdXRoMi9yZWFsbXMvcm9vdC9yZWFsbXMvYXVka2VubmkiLCJleHAiOjE2MTExNDIzMDAuMSwiYmluZGluZ19tZXNzYWdlIjoiQXXDsGtlbm5pIFNJTSBTaWduaW5nIiwiYmluZGluZ19jb250ZW50IjoiUEdUTGYrZHlLWVNBL0dLUTJyWnFFUWVwZi9yWUhMZ2dKcmN0WWtMR2JTdz0ifQ.TpDlBSbcmY11lD-725snq_Hn-vAN1T5SA_-9FT8l7k2Wwax6MtD1qF_2kPFUvV6-xsK1mK-lMqpmqUlwctkE8zIUkMtc-vrmunfaHin9EvkNGPCfjV7FfCZdzSZMrz1YombfC6Vte3dC33AMxTimMZkD3lRwnlX-lHap00ERbZReEngt10ZvEJgrjOY3Z6jROgMCLSBDkPs3mAEZSfcimYpXjiNUUa5Pras-kD7HgisAtVP-9eTBQeCwoM_rsYEXSsrkhNBYj_JTLt3Q5z3zqTj2km-Rwl4ITn9yAn055fC2FnPOTbHQ2sHahqVdDlLBMSUOhkdn3N9syx1-NOUjsw'

 

C# - RestSharp example of the call

 

 

Step 2: Expected response

The CIBA service answer is in JSON format.

When Step 2 is executed the signing process at the users device starts.

The response should include following

  • auth_req_id (to use in next step)

  • expires_in (the lifetime of th id)

  • interval

 

Example of answer from Step 2

 

 

Step 3

 

Step 3: (Poll for token)

After executing Step 2 the signing process at the users device starts. It depends on the user, the device and the network how long time this process takes.

In this step we poll for results from the signing process. When signing process is finished successfully you will receive answer with Access and Id token of the user.

To poll for tokens we send another POST call to following URI:
https://pfzww.audkenni.is:443/sso/oauth2/realms/root/realms/audkenni/access_token

 

Parameters needed in call

We need to add following header parameter

  • A Basic Auth header, using the Client id and Client secret

We need to add following parameter

  • grant_type (the value should be: “urn:openid:params:grant-type:ciba”)

  • auth_req_id (the value should be the auth_req_id from last step answer)

 

CURL example of the call

 

C# - RestSharp example of the call

 

 

Step 3: Expected response (Signing still in process)

If you run the poll call before the user signing process is finished you will receive a answer notifying the process isn’t finished.

The REST API service answer is in JSON format.

If you get answer like this you need to wait for short time and run Step 3 call again.

The response should include following

  • error_description

  • error

Example of answer from Step 3

 

Step 3: Expected response (Signing is finished)

The answer from this call should give you the Access and Id tokens along type and lifetime info.

The Id token contains a PKCS1 signature and a signing certificate.

The REST API service answer is in JSON format.

Best practice

Best practice is to verify the signature and the certificate. Verify the user’s info in the Id token against the certificate. By decoding the signature using the certificate you should end up with the hash from the earlier step.

The response should include following

  • access_token

  • scope

  • id_token

  • token_type

  • expires_in (lifetime of the tokens)

Example of answer from step 3

 

Example of the payload in Access token

 

Example of the payload in Id token

 

 

 

Step 4

 

Step 4: (Userinfo)

Here we ask for the users info using the Access token as Authorization header parameter.

To get the Userinfo we send a POST call to following URI:
https://pfzww.audkenni.is:443/sso/oauth2/realms/root/realms/audkenni/userinfo

Parameters needed in call

We need to add following header parameter

  • Token (Bearer, using the Access token from last call as value)

 

CURL example of the call

 

C# - RestSharp example of the call

 

 

Step 4: Expected response

The answer from this call should give you a PKCS1 Signature and a signing certificate. The same signature and certificate as is in the Id token from last step.

The REST API service answer is in JSON format.

Best practice

Best practice is to verify the signature and the certificate. Verify the user’s info in answer against the certificate. By decoding the signature using the certificate you should end up with the hash from the earlier step.

The response should include following

  • signature (PKCS1)

  • documentNr (should be “na”)

  • certificate (signing certificate)

  • nationalRegisterId (The social id number of the user)

  • name (The users name)

  • sub (A unique Id of the user in our system)

  • subname (A unique Id of the user in our system)

Example of answer from step 4