<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Géry Ducatel on Medium]]></title>
        <description><![CDATA[Stories by Géry Ducatel on Medium]]></description>
        <link>https://medium.com/@gery-ducatel?source=rss-17857a70e115------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hY3EqOongVjCoYsKC5jvgg.jpeg</url>
            <title>Stories by Géry Ducatel on Medium</title>
            <link>https://medium.com/@gery-ducatel?source=rss-17857a70e115------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 03:34:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gery-ducatel/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Scripted Event Driven Role Provisioning for Ping IGA]]></title>
            <link>https://gery-ducatel.medium.com/scripted-event-driven-role-provisioning-for-ping-iga-169e3811a4c1?source=rss-17857a70e115------2</link>
            <guid isPermaLink="false">https://medium.com/p/169e3811a4c1</guid>
            <category><![CDATA[iga]]></category>
            <category><![CDATA[scripting]]></category>
            <category><![CDATA[ping-identity]]></category>
            <category><![CDATA[governance]]></category>
            <dc:creator><![CDATA[Géry Ducatel]]></dc:creator>
            <pubDate>Mon, 08 Dec 2025 17:36:34 GMT</pubDate>
            <atom:updated>2025-12-08T17:36:34.798Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sh96_KNeniJXJ7PNBzjLHg.jpeg" /><figcaption>Photo de <a href="https://unsplash.com/fr/@vinaybhushan?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Vinay Bhushan Meesala</a> sur <a href="https://unsplash.com/fr/photos/papier-ligne-blanc-sur-table-en-bois-brun-J5k-Ma9Wy0Y?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>This article describes how to use scripts to customise <strong>event driven role management</strong> with PingOne Advanced Identity Cloud© (a.k.a. P1 AIC). The event driven functionality is part of an Add-on called Identity Governance (a.k.a. Identity Governance and Administration, or IGA). This Add-on provides P1 AIC with a full governance suite to provide role management compliance with any type of organisation.</p><p>This article assumes that some basics are in place. In particular that data sources and targets are in place, roles, and their entitlements are defined already. For this initial setup please refer to the P1 AIC documentation:</p><p><a href="https://docs.pingidentity.com/pingoneaic/latest/identity-governance/about-identity-governance.html">About Identity Governance</a></p><p>Ping IGA will provide out of the box workflows with drag and drop codeless solutions. However sometimes scripting can be used to address specific use cases. This article provides simple scripts that demonstrate how Ping IGA can be finely adapted and provide customised provisioning.</p><h3>Pre-Requisites</h3><p>Automation of role assignment relies on the following elements:</p><ul><li>Application with entitlements (pre-requisite)</li><li>Role with associated entitlements named “Certified Avenger” (pre-requisite)</li><li>Users are loaded in AIC — they have been synchronized from sources (pre-requisite)</li><li>Event</li><li>Workflow</li></ul><p>Once the elements above are ready, some simple scripting can be used to customise business logic and unlock provisioning flows such as:</p><ol><li>User profile is modified</li><li>The approval request is created automatically</li><li>The workflow kicks off</li><li>Approvers are notified and can approve role or not</li><li>Provisioning is executed</li></ol><p>For the request to succeed we have to collect all the information that is needed. In this case:</p><ul><li>User ID</li><li>Role ID</li><li>Approver(s) ID</li></ul><p>We could assign the duty of approval to anyone such as a manager, a role member, or a combination of these. In this case we are going to use a <strong>role owner</strong>. This will help illustrate how some <strong>scripting</strong> can be used to assign who the approver needs to be.</p><h3>The Objective</h3><p>When a user is updated with a specific attribute value, a workflow is triggered. This workflow will send an approval request to the role owner. The role owner will be able to accept or reject this provisioning request. If the request is approved the user will be provisioned into an external target user directory.</p><h3>The Glossary</h3><p>The glossary allows us to manage properties to objects. We are going to use a default role: <strong>Role Owner</strong> assigned to Role objects.</p><p><em>Governance &gt; Glossary &gt; Role &gt; + Role Glossary Item</em></p><ul><li>Name : roleOwner</li><li>Display Name: Role Owner</li><li>Description: Role owner of role object</li><li>Type: User</li><li>Multi-Valued: false</li><li>Searchable: true</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6JT32EUBXInBdGy64sQNAQ.png" /><figcaption>Glossary role “Owner” available per default</figcaption></figure><h3>The Event</h3><p>We are going to use the generic attribute <em>frUnindexedString4</em> and give it a title. We call the attribute <em>super</em>. If this profile attribute is given the value “<em>avenger</em>” then the role owner will be notified and the person will either be granted, or denied this title. If the title is granted the person will be provisioned into an external user repository (where only certified avengers can be populated…).</p><p><em>Native Console &gt; Configure &gt; Managed Objects &gt; Alpha_Users &gt; frUnindexedString4</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B1j08TCgm2Sqz1XvMRcImw.png" /><figcaption>Modify frUnindexedString4 readable title</figcaption></figure><p>We are going to add an event:</p><p><em>Governance &gt; event &gt; user updated &gt; workflow</em></p><p>This gives us the event form. We will call this event “<em>Certified Avenger</em>”. During the creation of the event we will associate the Event with a Role, it will happen page 2 (Workflow Details).</p><p>Page 1 will look like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G5XHJbhMOcIOFENRKfAu0Q.png" /><figcaption>An Event with a Trigger</figcaption></figure><p>This step sets up the name of the <strong>Event</strong> and the <strong>Trigger</strong> which only happens to select users. The value of the “<em>Super Certification</em>” attribute is set to “<em>avenger</em>”.</p><p>The link between the role and the event is provided by the workflow variable which will be shared with the workflow. It is a text value that will be string matched in a workflow script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QBLeAURXqPFkc3CrEG7WvA.png" /><figcaption><em>A variable “</em>roleName<em>” is given the value “Certified Avenger” which needs to be a real role name for the workflow to be able to provision into this role.</em></figcaption></figure><h3>The Workflow</h3><p>Default workflows are available. We will duplicate the <em>“Basic Role Grant</em>” workflow (under <em>Governance &gt; Workflow &gt; Basic Role Grant</em>) and name it <em>Certified Avenger Role Grant</em>. Note the “<em>Auto-Approval</em>” path has been kept in which allows an administrator to by-pass the approval process. This path is not discussed in this article.</p><p>After modifications the workflow will look like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jRrfjOv9NnjnHSSYzsFYAw.png" /><figcaption>Workflow with scripted nodes</figcaption></figure><p>The first script (1) is here to establish the initial context. In our case we will be modifying the default script so as to get the following facts:</p><ul><li>Identify the user targeted for the role</li><li>Identify the role being requested using the role name</li><li>Identify the role owner using the role ID (to whom we are going to send the approval request)</li></ul><p>We also disable the Auto Approval route by setting the skipApproval variable to false.</p><p>The script is the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*m6HLFle4vO1pIz11XAIuug.png" /><figcaption>Important sections of script 1</figcaption></figure><ol><li>The user role and user ID are checked from the request (the user role is the manually provided String in the Event definition)</li><li>The role is checked to extract a role ID</li><li>The role ID is used to get the role owner from the Glossary</li></ol><p>The script ends with initialisation of variables accessible to other scripts in the workflow.</p><p>Script (2) is assigning the approval task to the role owner. This is often achieved using an approver from the list available in the node configuration, but if your choice is not in the list then you can use a script to appoint someone else. Here we are appointing the role owner retrieved from script (1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*gIw9D04H_zoChcgwK84H-g.png" /><figcaption>Script 2</figcaption></figure><p>Script (3a) is executed when the approver has provided a response. We are following a happy path with an approved request. Script (3a) is a safety check to prevent provisioning a user to a role that does not exist:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*NqrxT5i9cmDOXvVunTKO3w.png" /><figcaption>Script 3a with a role “read” request checking if the role exists</figcaption></figure><p>Following script (3a) we have script 4a which finalises the happy path:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*9kF9idUZ8WWBewXCqphPUw.png" /><figcaption>Script 4a with important steps</figcaption></figure><p>In step 1 the request ID is checked just in case it would have been deleted by an administrator. Step 2 is the provisioning request itself. It is a POST request to <strong>/iga/governance/user/[user id]/roles</strong> with an action: add, and a body where the request ID and the role ID are present.</p><p>Finally, in step 3 the request is marked as complete.</p><p>If the request is rejected, the following script (3b) is unchanged from the default route:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*Ix6cdJz0jHNFvpluh7A3Vg.png" /><figcaption>Script 3b (provided by default)</figcaption></figure><p>The request is marked as denied.</p><p>Finally if the request fails validation (e.g. the request is deleted, or the role does not exist) script (4b) is played:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*jF9EZfSLKkHsgq7tzfPgCg.png" /><figcaption>Script 4b marking the request as failed</figcaption></figure><h3>Conclusion</h3><p>These are the elements and scripts needed to have a working event driven provisioning setup. P1AIC IGA gives us the template and some scripting skills help customise this with a great degree of flexibility.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=169e3811a4c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your Secret is Safe with IG]]></title>
            <link>https://gery-ducatel.medium.com/your-secret-is-safe-with-ig-bff4e40be017?source=rss-17857a70e115------2</link>
            <guid isPermaLink="false">https://medium.com/p/bff4e40be017</guid>
            <category><![CDATA[secrets]]></category>
            <category><![CDATA[ig]]></category>
            <dc:creator><![CDATA[Géry Ducatel]]></dc:creator>
            <pubDate>Sat, 15 May 2021 01:08:32 GMT</pubDate>
            <atom:updated>2021-05-15T10:09:16.167Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8ZhRlzK7bqlC3KdxznFgDA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@benwhitephotography?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Ben White</a> on <a href="https://unsplash.com/@benwhitephotography?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Of course no one shares secrets lightly. When you have been mischievous and you are harbouring burning secrets it is imperative that you confide only into your most trusted friends because real friends would not resurface those deeds unless they knew it was safe to do so. That is what IG can do for you and this article is there to tell you how.</p><p>First, some basics. IG provides a number of Secret Stores. Those are used to save and retrieve secrets as and when it is needed. The approach is to define secret stores in some initialisation phase. Secrets are then accessible on demand inside IG routes. Below is an example taken from the IG documentation:</p><pre>{<br>  &quot;heap&quot;: [<br>    {<br>      &quot;name&quot;: &quot;SystemAndEnvSecretStore-1&quot;,<br>      &quot;type&quot;: &quot;SystemAndEnvSecretStore&quot;,<br>      &quot;config&quot;: {<br>        &quot;format&quot;: &quot;PLAIN&quot;<br>      }<br>    },<br>    {<br>      &quot;name&quot;: &quot;AmService-1&quot;,<br>      &quot;type&quot;: &quot;AmService&quot;,<br>      &quot;config&quot;: {<br>        &quot;url&quot;: &quot;http://openam.example.com:8088/openam&quot;,<br>        &quot;agent&quot;: {<br>          &quot;username&quot;: &quot;ig_agent&quot;,<br>          &quot;passwordSecretId&quot;: &quot;agent.secret.id&quot;<br>        },<br>        &quot;secretsProvider&quot;: &quot;SystemAndEnvSecretStore-1&quot;,<br>        &quot;version&quot;: &quot;7&quot;,<br>        &quot;notifications&quot;: {<br>          &quot;enabled&quot;: true<br>        }<br>      }<br>    }<br>  ],<br>  &quot;handler&quot;: {<br>    &quot;type&quot;: &quot;Chain&quot;,<br>    &quot;config&quot;: {<br>      &quot;filters&quot;: [<br>        {<br>          &quot;type&quot;: &quot;SingleSignOnFilter&quot;,<br>          &quot;config&quot;: {<br>            &quot;amService&quot;: &quot;AmService-1&quot;<br>          }<br>        }<br>      ],<br>      &quot;handler&quot;: &quot;ReverseProxyHandler&quot;<br>    }<br>  },<br>  &quot;condition&quot;: &quot;${matches(request.uri.path, &#39;/home/systemandenvsecret&#39;)}&quot;,<br>  &quot;baseURI&quot;: &quot;http://app.example.com:8081&quot;<br>}</pre><p>The example above defines a Secret Store called <em>SystemAndEnvSecretStore1</em>. This type of secret store will take your system environment variables and provide them inside your routes as secrets. There is an AM Service called <em>AMService-1</em> which describes how to connect to AM. Finally the route shown here is a reverse proxy which needs users to authenticate if their URI is a match to a condition: (<em>/home/systemandenvsecret</em>). Crucially, the secret store delivers one secret to the AM Service (the agent password). IG uses this password to authenticate and check session validity of end users. This stuff is a great and a straightforward use of secret stores. In fact, it is secret management as IG intended.</p><p>But what if you need your own business logic to be scripted? What if your scripts need to obtain a secret? How will you fetch this secret so that your script can process it? IG wouldn’t let you down, would it? Well no.</p><p>In this scenario we need to write a script (IG has a Groovy scripting engine), provide the secret store to the script as a parameter, and extract the secret from inside the script programmatically. The secret store definition would now look like this:</p><pre>[...] <br>{<br>  &quot;name&quot;: &quot;SecretsProvider-1&quot;,<br>  &quot;type&quot;: &quot;SecretsProvider&quot;,<br>  &quot;config&quot;: {<br>    &quot;stores&quot;: [<br>      {<br>        &quot;name&quot;: &quot;SystemAndEnvSecretStore-2&quot;,<br>        &quot;type&quot;: &quot;SystemAndEnvSecretStore&quot;,<br>          &quot;config&quot;: {<br>          &quot;format&quot;: &quot;BASE64&quot;,<br>          &quot;mappings&quot;: [<br>            {<br>              &quot;secretId&quot;: &quot;my.secret&quot;,<br>              &quot;format&quot;: &quot;BASE64&quot;<br>            }<br>          ]<br>        }<br>      }<br>    ]<br>  }<br>}<br>[...]</pre><p>There are two differences with the example we have seen above:</p><ol><li>The Secret Store is now wrapped up in a Secret Provider named SecretsProvider-1</li><li>The Secret Store now includes a mapping definition</li></ol><p>We will see how this is used below. First we need to include a scripted filter for our Groovy script. It will look something like that:</p><pre>[...]<br>{<br>  &quot;name&quot;: &quot;ScriptableFilter-1&quot;,<br>  &quot;type&quot;: &quot;ScriptableFilter&quot;,<br>  &quot;config&quot;: {<br>    &quot;type&quot;: &quot;application/x-groovy&quot;,<br>    &quot;file&quot;: &quot;SecretBusinessLogic.groovy&quot;,<br>    &quot;args&quot;: {<br>      &quot;secretsProvider&quot;: &quot;${heap[&#39;SecretsProvider-1&#39;]}&quot;,<br>      &quot;secretId&quot;: &quot;my.secret&quot;<br>    }<br>  }<br>}<br>[...]</pre><p>Now you can see how the secrets provider wrapper is useful, you can pass it as a generic argument (i.e. it is the same for any secret store type you may choose to use). You also include the secret ID key (<em>my.secret</em>). The intention is to share a secret we refer to as “my.secret” to a script called <em>SecretBusinessLogic.groovy</em>. Everything is in place for the final act.</p><p>We need to get to the value of the secret so that we can use it, but the secret store needs to be told how. It can be achieved like this:</p><pre>import org.forgerock.services.context.*;<br>import org.forgerock.openig.secrets.*;<br>import org.forgerock.secrets.*;</pre><pre>[...]<br>def enviable = Purpose.purpose(secretId, GenericSecret.class);<br>Object pwd = secretsProvider.getActiveSecret(enviable).get();<br>def bigSecret = pwd.revealAsUtf8(String.&amp;valueOf);<br>logger.info(&quot;Secret: &quot; + bigSecret);<br>[...]</pre><p>In our script we declare a Purpose called <em>enviable</em> which is intended to refer to one secret alias (<em>my.secret</em>). We use the <em>SecretsProvider </em>(<em>secretsProvider</em>) object to obtain a <em>GenericSecret</em> object (<em>pwd</em>). The <em>GenericSecret</em> “reveal as UTF-8” function takes a method pointer operator (<em>.&amp;</em>) because the argument of this function needs to be another function as per the <a href="https://backstage.forgerock.com/docs/ig/7/apidocs/org/forgerock/secrets/GenericSecret.html">JavaDoc</a>.</p><p>Note that the secret here is captured only so that it can be seen in the standard output for debug purposes. Of course it is not the intended use. The reveal function should be used directly (i.e. not passed through a variable) and the secret would only be available in memory for a short period of time. And that is it, the secret has been passed to the script and can be used to unlock the expected logic.</p><p>Before we finish, I would like to share with you something else about IG, in fact this article was only needed to clear the way for the real secret which is this: did you know it is possible to write your very own secret store and add it to IG; how to do it is a closely guarded secret. No worries though because this will be the topic of a follow up article, see you soon!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bff4e40be017" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Signature and Encryption Options for OAuth 2.0 and OIDC — part 2]]></title>
            <link>https://gery-ducatel.medium.com/signature-and-encryption-options-for-oauth-2-0-and-oidc-part-2-ae13c750894a?source=rss-17857a70e115------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae13c750894a</guid>
            <category><![CDATA[jwe]]></category>
            <category><![CDATA[jwa]]></category>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[oidc]]></category>
            <dc:creator><![CDATA[Géry Ducatel]]></dc:creator>
            <pubDate>Mon, 11 Jan 2021 18:29:43 GMT</pubDate>
            <atom:updated>2021-01-25T00:26:34.282Z</atom:updated>
            <content:encoded><![CDATA[<h3><a href="https://medium.com/@gery.ducatel/signature-and-encryption-options-for-oauth-2-0-and-oidc-part-1-4d1a533fcced?source=your_stories_page-------------------------------------">Signature and Encryption Options for OAuth 2.0 and OIDC — part </a>2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cETuyHBeFZl-TUuEauGq2A.jpeg" /><figcaption>photo from <a href="https://unsplash.com/">unsplash</a> by <a href="https://unsplash.com/@lunarts">Volodymyr Hryshchenko</a></figcaption></figure><h3>Introduction</h3><p>In <a href="https://medium.com/@gery.ducatel/signature-and-encryption-options-for-oauth-2-0-and-oidc-part-1-4d1a533fcced">part 1</a> we looked at OAuth 2.0, and OIDC token signatures, trust, and integrity. This second part is about implementing data confidentiality. This is where we look at token encryption. Encrypting tokens is not always exercised and it may well be something that is overlooked because of the added complexity. Welcome to part 2 of applied cryptography for OIDC and OAuth 2.0 tokens.</p><p>An OAuth 2.0, or an OIDC token encryption follows the standard defined for JWT tokens (JavaScript Object Notation -JSON- Web Token). The leading standard for this is the IETF RFC 7516¹ which is referred to as JWE (JSON Web Encryption). Encryption algorithms are defined in the IETF RFC 7518² JWA (JSON Web Algorithms). The standard ignores the difference between OAuth 2.0 and OIDC tokens. In practice the case to encrypt OIDC tokens is often more relevant, and OAuth 2.0 tokens seldom need to be encrypted.</p><p>This article starts by describing the list of options available for cryptography. The following section discusses key sharing algorithms performance and some aspects of security. Finally this concludes with the actual token encryption options. There is also a TL; DR section at the bottom (yeah!).</p><h3>Token Encryption</h3><p>As with the previous article I propose to start with the raw list of formal options which we need to pick from. The first obvious difference with token encryption compared to signatures is that here we have two tables: Table 1 is a list of key sharing strategies, and Table 2 is the list of encryption algorithms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*BzclVGGLpwj-6Cx6boy0Ug.png" /><figcaption>Table 1: JWE supported algorithms for the encryption of the key</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*EhoE1fn6XJLFkVPCf_84_w.png" /><figcaption>Table 2: JWE supported algorithm for the encryption of the content</figcaption></figure><p>Again there is a lot of information packed in those tables so let’s see what we have. Table 1 lists four types of algorithms RSA, AES, ECDH, and PBES:</p><ul><li><strong>RSA</strong>: Rivest Shamir Alderman a.k.a. public/private encryption keys which we have already seen in part 1.</li><li><strong>AES</strong>: Advanced Encryption Standard is a widespread symmetric encryption algorithm.</li><li><strong>ECDH</strong>: Elliptic Curve Diffie Hellman is another public/private key encryption solution.</li><li><strong>PBES</strong>: Password Based Encryption Scheme is, as the name suggests, a means of generating keys from passwords.</li></ul><p>Key exchange is the guarantee of confidentiality. In applied cryptography it is the hard part. We will look at how JWE proposes to solve this. Table 2 which references the encryption algorithms for the tokens simply shows two versions of the AES encryption algorithm which we will compare.</p><p>So the crucial step here is how are we going to pick a key sharing solution. Whilst it has many (seventeen) algorithms to choose from, the JSON Web Algorithms (JWA) key sharing standards can be divided into four broad categories: key wrapping, key encryption, direct key agreement, and key agreement with key wrapping. What we are trying to share is the Content Encryption Key (CEK) which is the one we use to encrypt or decrypt the data. We also want to protect the CEK from unwarranted parties. Each key sharing strategy presents interesting characteristics which will help narrow down our algorithm selection. Let us go through those one by one:</p><ul><li><strong>Key Wrapping</strong>: This involves another key called the Key Encryption Key (KEK). The KEK is used to encrypt the CEK. When the CEK is in its encrypted form it is called a<em> JWE Encrypted Key</em>. So with key wrapping you still have the KEK to share between the communicating parties (i.e. the Authorisation Server and the relying party or client). There is still a benefit in proceeding in this way. The Authorisation Server does not need to keep storing every key it ever creates to encrypt tokens. Another benefit is content deletion, if the KEK is discarded the token is no longer accessible. This is why Key Wrapping is popular for content that is distributed in untrusted environments such as public clouds. The main drawback of this approach is that the KEK needs to be exchanged beforehand somehow. It is not very practical when there are many client/relying parties consuming tokens. Obviously they all need different keys and every so often they need to be refreshed.</li><li><strong>Key Encryption</strong>: this time the CEK is encrypted using an asymmetric algorithm (RSA). The recipient needs to share a public key either in text format, or in JSON Web Key (JWK) format, or as a JWK URI³. The JWK format is described in RFC 7517⁴. This makes things simpler than key wrapping especially when the recipient and the Authorization Server are two distinct entities; typically the recipient will share a public URI. For key rotation the recipient has to share a new key or update the URI. The obvious benefit is that there is no key to share secretly. However the standard is starting to date and we will see that there is another issue which renders this solution less attractive — performance.</li><li><strong>Direct Key Agreement</strong>: a key agreement algorithm is used to generate the CEK (there is no KEK). The key agreement principle may be less commonly understood that RSA but it brings really good benefits. JWE recommends a real mouthful: the <em>Elliptic Curve Diffie Hellman — Ephemeral Static with concatenation Key Derivation Function</em>. The intention is not to explain the cryptography behind this and luckily there is ample academic literature available for that. Yet we want to know when to use this so we need to explain briefly what the different parts are: <br>The <em>Diffie Hellman</em> part is the established algorithm to generate and share a symmetric key securely. It means that two parties enter a dialogue and they both end up with the same shared secret. This protocol is baked in long established standards such as Transport Layer Security (TLS). This means it is everywhere and we use it online all the time. <br>The <em>Elliptic Curve</em> part is a variant of the algorithm using said curves. The algorithm involves public keys that can be <em>Static</em> (always the same ones) or <em>Ephemeral</em> (new keys are generated for each cipher text). Here the <em>Ephemeral Static</em> part means that the sender uses ephemeral keys, and the recipient sends static keys. <br>The <em>concatenation Key Derivation Function</em> (concat KDF) is used to generate the final key to its desired size. <br>In theory the level of security that can be achieved with Elliptic Curves is higher than with the RSA algorithm. The down-side may be that as it involves Elliptic Curve cryptography it is easy to get things wrong and implement poor security.</li><li><strong>Key Agreement with Key Wrapping</strong>: This is a hybrid solution. The same key agreement algorithm described above is used to generate the KEK. The CEK is therefore encrypted with the generated KEK: this means we can implement key wrapping and we do not have to share the KEK separately. This does add complexity but it brings a subtle benefit because the <em>JWE Encryption Key</em> can be kept with the token and the KEK can be managed separately. This approach may be more familiar to a recipient used to handling KEK.</li><li><strong>Direct Encryption</strong>: for the purpose of this article it is not counted as a key sharing strategy because in direct encryption the CEK itself is exchanged so there is no real key sharing implementation.</li></ul><p>Table 3 shows how algorithms from Table 1 are classified. Hopefully even if you are not a cryptographer table 1 and 2 should start to make more sense. We can carry on with performance analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pAMNZetnvIkt922aVFpC_A.png" /><figcaption>Table 3: JWE algorithm classification</figcaption></figure><h3>General Overview</h3><p>Cryptography adds an overhead to CPU computation, and it is good to be able to gage the impact. I start this overview with the performance side of the JWE algorithms. We have two figures, Figure 1 for the Authentication Servers in charge of generating the CEK and implementing the key sharing solutions. Figure 2 is for the client/relying party in charge of recovering the CEK. The test consists of running the process 1,000 times and check how long it takes in milliseconds. Note that a few of the JWE algorithm variations are intentionally omitted so as to avoid overcrowding the figures. The tests were run on my laptop which has the following CPU:</p><p><em>2,4 GHz Intel Core i9 8 cores — T2 Hardware Encryption Acceleration chip (no specification details known)</em></p><p>We observe that RSA encryption is acceptable but the decryption is literally off the chart (indeed it could not be plotted on this chart or it would have dwarfed everything else). The time it took to decrypt was over 10,000 milliseconds for the 1,000 iterations, so well off the chart meaning RSA decryption went off like a lead balloon, and we need something better. Expectedly the AES Key Wrap solution is the simplest and therefore the fastest to generate an encrypted key, or to recover it. The alternative to RSA public/private key solution is ECDH . We can see that performance varies significantly depending on the curve chosen. Curves P-384, and P-521 show poor results. The P-256 curve is the only one with good performance. Note that the ephemeral part of the algorithm means that performance is impacted because it needs to include a key generation which RSA does not have to do. However I also threw in the popular X25519, and X448 (not JWE standard strictly speaking but good software vendors are already implementing them anyway) and the former is so good it almost compares with AES encryption, whilst the latter is not as fast but still very performant. With the hybrid key agreement and key wrapping the results are similar albeit slightly slower due to the added key wrapping part, but performance is largely driven by the ECDH algorithm. Finally the AES GCM with key wrapping and the PBES2 algorithm show very acceptable performances both with encryption and decryption.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*QoekaVAq9DCXg-ekaeWNoA.png" /><figcaption>Figure 1: Key Sharing algorithm performance Authentication Server side (CPU related). I.e. time generate an encrypted Content Encryption Key in milliseconds (1000 iterations)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*YnnlneyzRZHwh00jrF1fqw.png" /><figcaption>Figure 2: Key Sharing algorithm performance recipient side (CPU related). I.e. time to recover a Content Encryption Key in milliseconds (1000 iterations)</figcaption></figure><p>Now we have had an overview we can look at those solutions in more details. There are two aspects that we are mostly interested in: theoretical strength and performance.</p><h3>RSA Key Encryption</h3><p>The JWE standard includes three flavours of the RSA Encryption Scheme RSAES-PKCS1-v1_5, RSA OAEP, and RSA OAEP using SHA-256 and MGF1 with SHA-256. The first one is being deprecated, it is the original Encryption Scheme with Public Key Cryptography Standard; it is not evaluated here. It has been replaced with the RSA Optimal Asymmetric Encryption Padding (RSA OAEP). This is considered more secure against a number of attacks. The third option adds a Mask Generating Function (MGF1) allowing the cipher text to be stretched with padding of a desired length. This makes it a slightly more secure choice (apparently). As with any other RSA based solution the key size is important for security. A minimum size of 2048 bits is expected (part 1 discusses RSA key sizes in more details, the same applies here). The performance tests show that encryption is reasonably fast, but decryption is orders of magnitude slower. As a result it may not be the best choice to a client/relying party that is already running high on CPU power. Due to poor performance RSA based solutions seem to be better suited to signatures than encryption.</p><h3>AES Key Wrap</h3><p>This the simplest solution of all. It relies on the standard AES Key Wrapping, i.e. encrypt the decryption key with the data. The algorithm does not require extra input but the KEK needs to be shared in some way beforehand. This is a simple choice for simple small scale deployments. The size of the KEK can be 128-bit, 192-bit, or 256-bit. The size of the KEK does not noticeably affect performance. One advantage of this Key Wrapping solution is that there is no need to pass any parameters to the recipient. It does however introduce some risk of data tampering therefore the environment and the participants should all be trusted.</p><h3>ECDH Direct Key Agreement</h3><p>This is the other public/private key solution that is available to encrypt the CEK. The algorithm yields a CEK directly. The implementation uses Ephemeral — Static keys meaning that the Authentication Server has an ephemeral keys, and the recipient uses a static key this means that the recipient can be authenticated and this helps preventing a man in the middle attack⁶. The sender needs to share the Ephemeral Public Key (EPK), other parameters are optional. The recipient shares a Static Public Key using either a JWK, or a URI.</p><p>With ECDH the key size is directly related to the selected curve⁷. P-256 provides a 128-bit security which matches RSA 3072 bit, P-384 is equivalent to an RSA 7680 bit, and P-521 is akin to an RSA 15360 bit. The X25519 curve provides a 128-bit security therefore also equivalent to P-256 or RSA 3072 but considerably faster. Finally X448 has 224-bit of security. This is at the same level as a 10498 bit RSA key, and with a performance roughly comparable to a P-256 curve!</p><p>We have seen that the curve significantly affects performance with Figures 1 and 2. Standard curves outperform RSA key encryption for an equivalent security but non standard curves (X25519, and X448) outperform standard ones. Therefore ECDH is a faster and stronger solution than RSA. Elliptic Curves cryptograhy does add complexity that should be reviewed carefully so as to not introduce security loopholes.</p><h3>ECDH Agreement with Key Wrap</h3><p>The algorithm reveals a KEK that can be used to decrypt the CEK. This approach might be interesting if tokens are distributed to different services and decryption is managed by means of releasing the KEK to authorised systems. As for the direct agreement the sender shares at least an Ephemeral Public Key (EPK). The recipient shares a Static Public Key with a JWK, or a URI.</p><p>The ECDH part is the same as direct key agreement described above and therefore the performance is also the same if we ignore the small impact of the AES Wrap. The Key Wrap does not really add to the theoretical security. Choosing this option is related to the token decryption management. This can be a good choice if the OIDC or OAuth 2.0 tokens have multiple destinations and end to end encryption is a requirement. Again security should be checked carefully when implementing Elliptic Curves.</p><h3>AES GCM Key Wrap</h3><p>This is a type of AES Key Wrap that has an additional property called Authenticated Encryption provided by the Galois/Counter Mode (GCM) . This means that it provides a protection against “chosen cipher text attack”⁸. The attack consists of analysing decryption of some selected cipher text in order to retrieve the decryption key. The GCM part introduces two mandatory parameters: an Initialisation Vector (IV), and a Tag (a.k.a. Authentication Tag). The sender generates the IV which is a 96-bit random string. The tag is generated by the algorithm and is a 128-bit string. The recipient needs to have received the KEK beforehand. Therefore the decryption requires the cipher text, the KEK, the IV, and the Tag. If we operate in a non trusted environment this solution is superior the AES Key Wrap from a security standpoint.</p><p>The standard has three key sizes 128-bit, 192-bit, and 256-bit. This is the same as the AES Key Wrap alone. We can observe a minimal impact on performance due to these overheads compared to the AES Key Wrap.</p><h3>PBES2 Key Wrap</h3><p>The PBES2 means Password Based Encryption Scheme no 2. It uses a password based Key Derivation Function. This combines a password with hashing and salting to provide a key of the desired length. The sender and the recipient have shared a password (which is likely to be the client password). The sender produces the KEK and uses it to wrap the CEK. The sender shares two parameters for the recipient to recompose the KEK: PBES2 Salt Input (P2S), and an iteration counter for the hashing called PBES2 Count (P2C).</p><p>Again keys can be of three sizes: 128-bit, 192-bit, and 256-bit. As we can see from Figures 1 and 2. Key sizes’ impact on performance is barely noticeable. The benefit of this Key Wrap is that the password helps preventing the exchange of the KEK. However, this implies that a password management is put in place with the usual password reset, password policy, etc… This also means that the password may not be hashed because it is required to produce the KEK.</p><h3>Token Encryption</h3><p>Now that we have reviewed key exchange we can look at the encryption of the token itself. This is described in Table 2 (reproduced here for convenience):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*EhoE1fn6XJLFkVPCf_84_w.png" /><figcaption>Table 2 (same as the one all the way up): JWE supported algorithm for the encryption of the content</figcaption></figure><p>We can see that there is one type of encryption: Advanced Encryption Standard (AES) and that there are two variations available (one of which that we have already seen above). Both types of encryption are categorised as Authenticated Encryption algorithms and both use a combination of Initialisation Vector and Hashing to create the Authenticated Encryption property. In practice both algorithms produce an authentication tag which is checked by the recipient for tampering.</p><p>The AES CBC means Cipher Block Chaining, and the AES GCM means Galois/Counter Mode. The former is a block cipher (it handles chunks of data), and the latter a stream cipher (it handles one byte at a time). Other than that options are pretty much the same.</p><p>In terms of security 128-bit is considered fully resistant to brute force so it may be used safely. However only a 256-bit AES key is considered quantum resistant⁵, which may be totally anecdotal in the context of OIDC or OAuth 2.0 tokens that tend to be short lived anyway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*VjYo2PFEpqdloAUVT6DlLQ.png" /><figcaption>Figure 3: JWE content encryption and decryption per algorithm for 10,000 iterations in milliseconds</figcaption></figure><p>Figure 3 shows the performance comparison between all the algorithms. Basically, the result is that AES GCM is more performant than the AES CBC version.</p><h3>Conclusion</h3><p>Now we have looked at token signatures and encryption from an applied cryptograhy perspective. Note that if the token is both signed and encrypted the correct order is signed first and encrypted after as mentioned in the OpenID standard definition⁹.</p><p>Choosing encryption for OIDC tokens requires much pondering and back and forth conversations with — rightfully — security minded colleagues. This can be a source of delay and frustration. In the worst case it can lead to poorly implemented security. Hopefully this article has shed some light on how to select the algorithm that best suit a given use case.</p><p>I see a lot of articles including a TL; DR section so I also got mine here:</p><p>You have five standard ways of setting up OIDC token encryption:</p><ul><li><strong>Key Wrapping</strong>: Choose the tamper proof solution (AES GCM) if you can. Or maybe the password based encryption (PBES2) if you have to.</li><li><strong>Key Encryption</strong>: RSA public/private scheme. Don’t do that one because it is too slow. Do the next one.</li><li><strong>Key Agreement</strong>: ECDH public/private scheme. Fast and scalable solution. More complex than RSA but also more secure and performance can be really good if you use the non standard curves.</li><li><strong>Key Agreement with Key Wrap</strong>: ECDH also same as the above. Better suited when OIDC tokens are distributed to different systems as you may split the decryption key and share it with a centrally managed key distribution (or something similar).</li><li>Alternatively forget about standards: just encrypt and share the key.</li></ul><p>Thanks to Ali S, and Christian B who helped me with both part 1 and 2 giving me invaluable advice.</p><p>1: <a href="https://tools.ietf.org/html/rfc7516">https://tools.ietf.org/html/rfc7516</a></p><p>2: <a href="https://tools.ietf.org/html/rfc7516">https://tools.ietf.org/html/rfc751</a>8</p><p>3: URI: Universal Resource Identifier</p><p>4: <a href="https://tools.ietf.org/html/rfc7517">https://tools.ietf.org/html/rfc7517</a></p><p>5: <a href="https://en.wikipedia.org/wiki/Grover%27s_algorithm">https://en.wikipedia.org/wiki/Grover%27s_algorithm</a></p><p>6: <a href="https://en.wikipedia.org/wiki/Elliptic-curve_Diffie%E2%80%93Hellman">https://en.wikipedia.org/wiki/Elliptic-curve_Diffie%E2%80%93Hellman</a></p><p>7: <a href="https://www.ecrypt.eu.org/csa/documents/D5.4-FinalAlgKeySizeProt.pdf">https://www.ecrypt.eu.org/csa/documents/D5.4-FinalAlgKeySizeProt.pdf</a></p><p>8: <a href="https://en.wikipedia.org/wiki/Authenticated_encryption">https://en.wikipedia.org/wiki/Authenticated_encryption</a></p><p>9: <a href="https://openid.net/specs/openid-connect-core-1_0.html">https://openid.net/specs/openid-connect-core-1_0.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae13c750894a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Well Behaved AM Session with Quotas]]></title>
            <link>https://gery-ducatel.medium.com/well-behaved-am-session-with-quotas-ed0c3cec900a?source=rss-17857a70e115------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed0c3cec900a</guid>
            <dc:creator><![CDATA[Géry Ducatel]]></dc:creator>
            <pubDate>Thu, 01 Oct 2020 09:05:11 GMT</pubDate>
            <atom:updated>2020-10-01T10:30:50.425Z</atom:updated>
            <content:encoded><![CDATA[<p>Wouldn’t it be great to see a pop-up message telling you that your other existing sessions would be terminated if you proceeded to login sometimes (Figure 1)? If you have looked at ForgeRock AM 6.5 session management behaviours you have found that AM supports session quotas, and there are four different behaviours that can be applied in case users hit the limit. They are the following:</p><ul><li>Deny access</li><li>Destroy next expiring</li><li>Destroy oldest session</li><li>Destroy all old sessions</li></ul><p>AM applies the behaviour automatically and will display a message if access is denied due to the maximum number of session being reached.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R1BjDZB6U5eZXriPP5b2bg.png" /><figcaption>Figure 1: Logging in will kill your other sessions</figcaption></figure><p>So, what is the problem with that? Well here it is: we are not allowing users to choose a behaviour. So, if you leave your session open on your smart phone and you happen to login with another device you cannot control what happens to your previous session, and it may be that you terminate a precious session inadvertently. It might be a minor inconvenience if you were simply browsing a site casually, but if you were in the middle of a money transaction, or you had a basket full of your weekly shopping something dreadful can happen: before you realise, you have lost it all — and you have to do it all over again. From the user point of view this is a waste of time, and for the web site owner, this means potential loss of custom.</p><p>Before we look at a solution to this problem we must discuss something called Tree Based Authentication¹, and the Authentication Session concept. In a tree based authentication a dialogue goes back and forth between AM and the end user during which an authentication context is built up. For example AM might ask for a username, then it might silently request the device fingerprint, and some geo-location, then it might ask for a password. Every step is handled by a tree node, each time the context is added to the state of the Authentication Session. This state is called the shared state. This carries on until AM validates authentication challenges and reaches a decision to either return a success, or a failure. So what we are interested in doing is to intervene into this dialogue, preferably early, and do two things: check how many sessions we have already running for our users, then we can use a pop-up window to ask them what they want to do: login, or cancel. We will be using the shared state to capture the users’ responses. So what we need is an Authentication Tree improved with a few customised nodes of our own.</p><p>The project source code² can be found on GitHub. Our first node will be a Groovy script. In order to add such a script into AM 6.5.x you may follow the documentation³. Apply the instructions to create a new script and copy/paste the source code. Note you will have to add the imported Java classes to the white list of authorized Java objects⁴. The APIs used in the script require elevated credentials therefore the script obtains those through shared environment variables (alongside other parameterized values). Then the script uses those credentials to call the AM REST APIs and obtain the current number of active sessions for the user logging in.</p><p>The other important thing to notice is that the user password is saved into a variable and pushed into the aforementioned <em>shared</em> state. Going up two paragraphs we saw that the shared state is indeed what stores the dialogue context between AM and the user. In this case, pushing the password into this state is a necessity that requires extra considerations. First of which being that the password needs to be encrypted by the script using a standard AES algorithm. As discussed already, the shared state needs to reach the subsequent nodes therefore it has to be persisted throughout the login process. It can be configured to be stateful, i.e. to stay on the server side, either in memory, or through the Core Token Service⁵, but equally it can be left with its default settings traveling back and forth between AM and our users’ browsers, which is a stateless option. This is the reason the password is encrypted. Note, that the shared state is also typically encrypted (as per default), but it can be set to travel in clear text. Also, the communication for this would be happening over HTTPS so, the password ends up being encrypted thrice: twice in the payload, and once more in transit. Note that this can be handled differently from AM 7.0 which introduces a <em>secure</em> state to address this type of problem (with a built-in similar approach).</p><p>Groovy scripts are great for authentication trees because they allow to write custom nodes without the pesky code maintenance overhead of native nodes. However, Groovy scripts are server side, and we need to push some javascript to the browser. So we are going to use a little known convenient type of script called <em>client side authentication</em>. Here we can write a JavaScript pop-up which will deliver our session management message to end users. Again, the code is available on GitHub, and you need to follow the same copy/paste process as before.</p><p>The client side authentication script does not deliver itself to the browser though. We need a native node to do this job. Although such node is not provided by default in AM 6.5 one can be found in the MarketPlace hosted by ForgeRock. It is called the <em>Client Script Auth Tree Node</em>⁶. How to deploy a native custom node is not in scope here but that is no biggy because there is a dedicated user guide in the ForgeRock backstage documentation⁷. The native node will package a client side script (our JavaScript pop-up) and collect the result to be passed to the next node.</p><p>Our next node called CheckSessionResponse is receiving the response from the user. If the intention is to login the user password is decrypted and is shared for validation with the next node using the <em>transient</em> state. If the response is to cancel login then the authentication tree ends in failure (and existing sessions are not destroyed). Now I hear you say two things: why did I not mention that transient state earlier saving us all that password encryption debacle, and at which point in this is any session terminated? Unfortunately for us the transient state is not persisted if a node has a user callback (i.e. it interfaces directly with the user modifying the shared state) so we cannot use it because the pop-up node is effectively that callback. As for the session management we simply configure a behaviour such as Destroy All Sessions, or whichever is more relevant. If the login completes the behaviour applies and the new session is created. This way the script does not have to take care of session termination. Figure 2 shows our final Authentication Tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*315hEsqYLPf6VieV6DOFYg.png" /><figcaption>Figure 2: An Authentication Tree</figcaption></figure><p>This shows how to improve on the default behaviours of AM 6.5 and provide users with the option to cancel a login in order to protect existing sessions. The pop-up only shows up when the user exceeds a maximum number of open sessions so the extra “login friction” inconvenience (i.e. the pop-up) is limited.</p><p>These instructions are meant for an AM 6.5 instance. This would in all likelyhood work on an AM 7.0 deployment however, if we are going to do that we would do well to simplify the Groovy scripts by removing the encryption functionalities and use the new built in ones.</p><p>[1] Find more information about Tree Based Authentication: <a href="https://backstage.forgerock.com/docs/am/7/auth-nodes/about-nodes.html#about-nodes">https://backstage.forgerock.com/docs/am/7/auth-nodes/about-nodes.html#about-nodes</a></p><p>[2] <a href="https://github.com/JazzDeben/SessionManagement">https://github.com/JazzDeben/SessionManagement</a></p><p>[3] <a href="https://backstage.forgerock.com/docs/am/6.5/authentication-guide/index.html#manage-scripts-console">https://backstage.forgerock.com/docs/am/6.5/authentication-guide/index.html#manage-scripts-console</a></p><p>[4] <a href="https://backstage.forgerock.com/docs/am/6.5/dev-guide/index.html#script-engine-security">https://backstage.forgerock.com/docs/am/6.5/dev-guide/index.html#script-engine-security</a></p><p>[5] <a href="https://backstage.forgerock.com/docs/am/6.5/install-guide/#chap-install-cts-implementation">https://backstage.forgerock.com/docs/am/6.5/install-guide/#chap-install-cts-implementation</a></p><p>[6] <a href="https://backstage.forgerock.com/marketplace/api/catalog/entries/AWAm-FCxfKvOhw29pnIp">https://backstage.forgerock.com/marketplace/api/catalog/entries/AWAm-FCxfKvOhw29pnIp</a></p><p>[7] <a href="https://backstage.forgerock.com/docs/am/6.5/auth-nodes/">https://backstage.forgerock.com/docs/am/6.5/auth-nodes/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed0c3cec900a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Signature and Encryption Options for OAuth 2.0 and OIDC — part 1]]></title>
            <link>https://gery-ducatel.medium.com/signature-and-encryption-options-for-oauth-2-0-and-oidc-part-1-4d1a533fcced?source=rss-17857a70e115------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d1a533fcced</guid>
            <category><![CDATA[oidc]]></category>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[signature]]></category>
            <dc:creator><![CDATA[Géry Ducatel]]></dc:creator>
            <pubDate>Fri, 10 Jul 2020 14:02:03 GMT</pubDate>
            <atom:updated>2021-01-16T14:23:28.727Z</atom:updated>
            <content:encoded><![CDATA[<h3>Signature and Encryption Options for OAuth 2.0 and OIDC — part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aQX12qZJjiojSsQvop-YxA.jpeg" /><figcaption>photo fom <a href="https://unsplash.com/">unsplash</a> by <a href="https://unsplash.com/@nocookie4you">David Nitschke</a></figcaption></figure><h3>Introduction</h3><p>Identity standards have been streamlined and made more accessible. OAuth 2.0 and OIDC (OpenID Connect) offer many options to transfer personal data across internet services. This is very popular with social media but also on-line retail, health, banking, or in other words, anything online. Data travels from centrally held user stores across to multiple parties, or between different services of a single legal entity.</p><p>These protocols work by exchanging JWTs (JavaScript Object Notation Web Tokens) that is essentially a data representation. This data content can be used to access user information (OAuth 2.0), or it can carry identity information itself (OIDC). This information needs to be trusted and secure. Respectively signature and encryption provide reliable solutions. But there are many options and therefore the question is how to make a rational selection.</p><p>This article discusses how to select signatures. A follow up article will address encryption. In the following sections I talk about signatures supported by the OAuth 2.0 and OIDC standard: HMAC, RSA, and EC — respectively Hash Message Authentication Code, Rivest Shamir Alderman (a.k.a. private/public key encryption), and Elliptic Curve (i.e. keys derived from said curves).</p><h3>Token Signatures</h3><p>Let’s look at the signature algorithm available first, and then I will discuss their properties and particularities. Table 1 shows the IETF¹ standard signatures. Or more formally: JWA (JavaScript Object Algorithms) for JWS (JavaScript Object Notation — Web Signature) which we can use to sign OIDC or OAuth 2.0 tokens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*15qiSmzv1Q44CvWIXJsiaA.png" /><figcaption>Table 1: Supported algorithms for JWS (JSON Web Signatures) specifications used to sign OAuth 2.0, and OIDC tokens.</figcaption></figure><p>This Table 1 is not easy to take all in, in fact it is copy/paste of the IETF documentation (so not bedside reading material), so let’s break it down a bit. Looking at the supported signature solutions we can recognise the three types of signatures: HS[xxx], RS/PS[xxx], and ES[xxx] respectively corresponding to three families: HMAC, RSA-SSA (RSA, Signature Scheme with Appendix), and ECDSA (Elliptic Curve Digital Signature Algorithm).</p><p>So I would like to compare the different algorithms from performance and security levels. I consider the following characteristics:</p><ul><li><strong>Security level</strong>: the strength of a cryptographic primitive or function². It measures the number of operations necessary to be able to compromise the security.</li><li><strong>Performance and time complexity</strong>: The time complexity reflects the number of operations necessary to run the encryption or decryption. The time complexity is affected by the encryption algorithm and the input size. Therefore we need to make sure that input size is identical for a fair comparison.</li></ul><p>As I am not a cryptographer the strength analysis is not explored in any depth. The actual intent is to review performance of secure solutions for the different types of algorithms so that it becomes easier to make an informed decisions and select the best options given any use case. When it comes to signatures the most important characteristic is whether an attacker can forge that signature or not. We do not want keys to be guessed, nor do we want fraudulent messages to be granted legitimacy by reusing previous signatures in clever ways.</p><p>For comparison purposes I reduce the strength of algorithms to their theoretical robustness ignoring attacks on implementation, or hardware flaws. This gives me a very black and white view, either a solution is acceptable, or it is not.</p><h3>Overview</h3><p>In choosing a signature algorithm for OAuth 2.0 and OIDC tokens we want to select one that is secure but also fast. To obtain performance data I implemented the signature algorithm on my laptop. For reference here is the processing power available:</p><p><em>2,4 GHz Intel Core i9 8 cores — T2 Hardware Encryption Acceleration chip (no specification details known)</em></p><p>Tests presented here computing signatures for a string of 250 characters which is roughly representative of an OAuth 2.0 token, or an OIDC token. The size is always the same for every algorithm presented here. The test runs measure the time needed in seconds for the laptop to perform 1 million signatures, and 1 million verifications.</p><p>The first diagram Figures 1 and 2 illustrate the performance for signing and verifying messages comparing the three types of algorithms head to head (note two variations of the RSA algorithm are represented which means four algorithms are on the diagrams). Note that the HS256 algorithm does not show on the diagrams because its response time is so fast the bars can hardly represent it. Already it is obvious that the most performant is the hashing solution both for signing, and verifying. This shows also very clearly that asymmetric algorithms can be divided into two categories: solutions that are fast to sign (e.g. ES256), but slow to verify, or slow to sign (e.g. RS256 and PS256), but fast to verify.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0itZUzmq-Usjeoyh" /><figcaption>Figure 1: Time in seconds to sign 1M messages. The HS512 solution — leftmost — is so thin it can hardly be seen</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JPVSjGYRcEQK6eF0" /><figcaption>Figure 2: Time in seconds to verify signatures for 1M messages. — the only solution clearly visible is ES512 because it is the slowest, The hashing solution bar (in blue) is too thin to be seen.</figcaption></figure><p>The following sections describe in more details the different options available for each type of signature.</p><h3>HS[xxx]: HMAC based signatures</h3><p>An HMAC signature is using hashing algorithms. In particular the algorithm used is called SHA for Secure Hash Algorithm. In SHA[xxx] the number (xxx) reflects the output size of the hash. The SHA family of algorithms needs an input key and message, and in output it produces a hash. The security level of this is related to the size of both the secret, and the output hash size. It is considered to be the lesser of the two. E.g. a SHA256 hash with a key size of 256 bit offers 2²⁵⁶ brute force “options”. This is already considered fully resistant. But a SHA256 hash with a key size of say 64 bit (e.g. your secret is “password”) gives 2⁶⁴ possibilities, and that might be brute forced. The important thing to remember is to choose a key size at least as big as the output size so you do not dumb down security.</p><p>Note there are possible attacks against hashing techniques in different contexts such as passwords (rainbow tables, collisions, etc…). However HMAC signatures are a different scenario altogether which is much harder to attack because messages cannot be random like with a collision, and so even finding a collision alone does not help an attacker.</p><p>This means you and I can go ahead and trust any of the SHA-2 algorithms (all three belong to this sub-family of SHA algorithms). Next I need to know how much CPU is required to compute the signatures. In the case of HMAC this depends on the key and output size, but the complexity grows linearly therefore the time complexity is often simplified with the O(n) notation. Here are some results from the tests I ran on my laptop (making sure the key size is simply as big as the output size).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*s5mcHglDY7kYi6so" /><figcaption>Figure 3: Performance of the HMAC based Signatures — consistently less than two seconds to process one million signatures</figcaption></figure><p>Surprisingly, Figure 3 shows no significant difference in the time required to compute an HMAC 256 hash to any other hash. It is possible that some hardware/encryption acceleration is responsible for this levelling up.</p><p>As expected verification times are roughly the same as signing because it is the same operation… In just under 2 seconds the laptop was able to sign or verify 1 million messages regardless of which SHA-2 flavour was selected.</p><h3>RS/PS[xxx]: RSA based signature</h3><p>The RSA-SSA signature is leveraging the private and public keys scheme. Let’s spend one minute clarifying one possible source of confusion here. There are two variations of this algorithm supported by the IETF JWA (i.e. the signatures) standard, namely the PKCS v 1.5 (Public Key Cryptographic Standards) and PSS (Probabilistic Signature Scheme). In the top Table 1 they are referred to as RS[xxx], and PS[xxx]. The former is the original standard, and the latter has added security including salt which makes the verification of the signature a little bit more complicated (for programmers). Therefore these are both RSA algorithms, and the PSS one is more robust, but generally speaking PKCS is considered safe enough — for signatures — by authoritative organizations (e.g.IETF³) or by the literature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/0*oOAI9HYk7aRoWnR8" /><figcaption>Figure 4: RSA SSA key size 2048</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/0*jz37W_Qsx2U0tqpY" /><figcaption>Figure 5: RSA SSA PSS key size 2048</figcaption></figure><p>The security level of the algorithm is also related to the key size. Frequently used key sizes are 1024, 2048, or 4096 bits. However real strength of RSA algorithms is extremely difficult to express even with a solid maths degree (which I don’t have) therefore the values are basically there to compare orders of magnitude between each key sizes. Unfortunately this does not really reflect how robusts those options really are in the real wide wild cyberworld. What is known for sure is that computer power is closing in on key sizes under 1024 bits, in fact those keys are considered insecure full stop. At the time of writing published academic material demonstrate that key sizes of 829 bits can be cracked⁴; reportedly achieved with the following hardware:</p><p><em>2700 core-years, using Intel Xeon — Gold 6130 CPUs (2.1GHz)</em></p><p>Therefore the recommendation for the RSA algorithm is to not use key sizes of 1024 bits so, what are the options? Traditionally computer programmers have a particular affection for 2x values and would traditionally jump from 1024 to 2048 and then to 4096. It is more about conventions than anything else. We know however that key sizes of 2048 bits are considered safe (but only until 2030 apparently⁵), still if for whatever reason you think future proofing is important you may select larger keys of 4096 or more if your servers can take the hit (during these tests I found that keys of 4096 bit took about four and a half times longer to produce a signature than the 2048 bit keys). In the end you may find that a stronger key size is a futile protection anyway given the recent progress in quantum physics — but who knows. Figures 4 and 5 show a comparison of the time it takes on the same laptop to compute RSA based signatures of sizes 2048 (remember 1024 is not safe). As you can see PKCS, and PSS have very comparable performance capabilities with the expected minor hit on PSS results.</p><p>A striking measurement is the RSA signature verification. No matter how big the key is, verification is extremely fast. This will make it a popular choice for OAuth 2.0, and OIDC clients. Both RSA algorithms can verify 1 million signatures between 44 and 56 seconds. In testing it shows that the verification duration seems to increase linearly with the size of the key. I.e. double the size of the key and you roughly double the time it takes to verify a signature.</p><h3>ES[xxx]: Elliptic Curve Signatures</h3><p>Finally Elliptic Curve signatures. Again, reporting on theoretical strength. I refer to the comparison value tables which is reported by OpenSSL⁶. It shows that the least strong of HMAC signatures (HS256) with a 2²⁵⁶ possible combinations is as good as the best Elliptic Curve P-521. Nonetheless P-256, and P-384 curves are considered robust to brute force attacks.</p><p>When it comes to performance however things are more interesting. Signing with any EC-DSA with curve P-256 takes half the time compared to RSA with a 2048 bit key, and the strength is equivalent. If we select a stronger curve either P-384, or P-521 performance drops significantly (see Figure 6) but the equivalent key strength in RSA would have to grow beyond reasonable proportions for most cases. Indeed P-384 is equivalent to a 7680 bit RSA key, and P-521 to a 15360 bit RSA key. Therefore — like for like — ECDSA consistently performs better at signing.</p><p>Verifying a signature on the other hand takes an awfully long time, it is slower than signing with an RSA key and therefore can be a real showstopper if you are on the verifying end of the protocol.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/0*eWcXipq_W_1YRmAK" /><figcaption>Figure 6: EC DSA P-256, P-384, and P-521 curves</figcaption></figure><h3>Conclusion</h3><p>Algorithms that are standard under the IETF guidance are considered safe so long as the key size is chosen appropriately. Asymmetric solutions are practical where third parties are involved because of the public key publishing mechanism. Keys are publicly available through a standardised URI (Uniform Resource Identifier) known as JWKS (JavaScript Object Notation Web Key Set) and therefore no prerequisite setup is necessary.</p><p>Elliptic Curves with key sizes of 256 bits are considered as robust as RSA keys of size 3072 bit⁷. However given the drop in performance one has to be careful to choose the correct key size in relation to expected traffic. The main trouble with this encryption is that there are many concepts to grasp and that poor implementations will lead to flawed security. Therefore choosing this solution demands that you use skilled people to validate your implementation.</p><p>RSA algorithms are easier to implement and are frequently used. It is a de-facto choice and when it comes to JWKs (JavaScript Object Notation Web Keys) a self signed key is all you need provided that your communication is already over HTTPS. The size of the hash (i.e. SHA256, SHA384, or SHA512) hardly matters at all since it is only used to re-enforce integrity and even SHA256 is considered robust enough (2¹²⁸ resistance to collision), there is no impact on performance either. Therefore the only key size that really matters for RSA is the asymmetric one.</p><p>Quantum capable monster machines will probably break asymmetric cryptography sooner or later, RSA or Elliptic Curves but we do not know when. Therefore choosing a key size beyond 2048, or 256 bits respectively is an attempt to protect data beyond the horizon of 2030 provided quantum computers do not come first. So, unless the data sent will be sensitive even beyond the decade it would not be increasing security that much. Finally hashing algorithms are reportedly more resistant⁸ to quantum crypto-power than asymmetric options.</p><p>As for SHA-2 signatures, they are the most performant keys but as you need to exchange a secret with the party verifying the signature the implementation is not always easy. In some controlled environments it might be a sensible choice, e.g. an all internal deployment.</p><p>So factors such as the amount of traffic, how long does privacy matters for, how much computer power is available, or how near capacity is a full deployment may have an impact on which signature algorithm is used. And hopefully by now table 1 will make more sense to the non cryptographers amongst us.</p><p><a href="https://gery-ducatel.medium.com/signature-and-encryption-options-for-oauth-2-0-and-oidc-part-2-ae13c750894a">Part 2 is now available here</a></p><p>Thanks to Ali S, and Christian B who helped me with both part 1 and 2 giving me invaluable advice.</p><p>1: <a href="https://tools.ietf.org/html/rfc7518#section-3">https://tools.ietf.org/html/rfc7518#section-3</a></p><p>2: <a href="https://www.ssl.com/article/comparing-ecdsa-vs-rsa/">https://www.ssl.com/article/comparing-ecdsa-vs-rsa/</a></p><p>3: <a href="https://tools.ietf.org/html/rfc3447">https://tools.ietf.org/html/rfc3447</a></p><p>4: <a href="https://caramba.loria.fr/rsa250.txt">https://caramba.loria.fr/rsa250.txt</a></p><p>5: <a href="https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar2.pdf">https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar2.pdf</a></p><p>6: <a href="https://wiki.openssl.org/index.php/Elliptic_Curve_Cryptography">https://wiki.openssl.org/index.php/Elliptic_Curve_Cryptography</a></p><p>7: <a href="https://en.wikipedia.org/wiki/Elliptic-curve_cryptography">https://en.wikipedia.org/wiki/Elliptic-curve_cryptography</a></p><p>8: <a href="https://blog.cryptographyengineering.com/2018/04/07/hash-based-signatures-an-illustrated-primer/">https://blog.cryptographyengineering.com/2018/04/07/hash-based-signatures-an-illustrated-primer/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d1a533fcced" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>