<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Security | Jacob Aloysious</title><link>https://jacobaloysious.in/tag/security/</link><atom:link href="https://jacobaloysious.in/tag/security/index.xml" rel="self" type="application/rss+xml"/><description>Security</description><generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator><language>en-us</language><lastBuildDate>Fri, 03 Dec 2021 00:00:00 +0000</lastBuildDate><image><url>https://jacobaloysious.in/images/icon_hu4591c05f594249c11c1e99a3a8f1f246_3759739_512x512_fill_lanczos_center_2.png</url><title>Security</title><link>https://jacobaloysious.in/tag/security/</link></image><item><title>PKCE</title><link>https://jacobaloysious.in/post/tech_pkce/</link><pubDate>Fri, 03 Dec 2021 00:00:00 +0000</pubDate><guid>https://jacobaloysious.in/post/tech_pkce/</guid><description>&lt;p>
&lt;a href="https://jacobaloysious.in/post/tech_oauth/" title="OAuth">Prerequisite: OAuth2.0&lt;/a>&lt;/p>
&lt;p>PKCE is pronounced as &amp;lsquo;pixie&amp;rsquo;. PKCE - Proof Key for Code Exchange =&amp;gt;
&lt;a href="https://www.youtube.com/watch?v=5cQNwifDq1U" target="_blank" rel="noopener">Credits&lt;/a>&lt;/p>
&lt;h3 id="concepts">Concepts:&lt;/h3>
&lt;h4 id="what-is-confidential-client">What is Confidential Client?&lt;/h4>
&lt;p>Any backend application written in languages like .Net, Java, NodeJS can be considered as Confidential Client. As they have the ability to &amp;ldquo;store variables&amp;rdquo; in our case Secret Keys - without exposing them to the end user - as the code is running on the server side. The secret key would be used to generate the Access Token in the OAuth Flow.&lt;/p>
&lt;h4 id="what-is-public-client">What is public Client?&lt;/h4>
&lt;ol>
&lt;li>
&lt;p>Any Single Page Application (SPA), where all the code is downloaded to the users browser would be considered a Public Client. Coz: the secret key cannot be securely stored as the hacker could do a &amp;ldquo;view source code&amp;rdquo; and look at the secret key which is usually in plain text/string format.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Another example are Mobile Apps - the user can download and de-compile/reverse engineer - the application and find the secret key.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h3 id="why-do-you-need-pkce">Why do you need PKCE?&lt;/h3>
&lt;p>Once the secret key is available - the hacker can impersonate as the Client and generate the access token (note: clientID is public and secret key is private). Once the access token is available - the hacker can access lot more confidential information about the user. So the existing
&lt;a href="https://jacobaloysious.in/post/tech_oauth/" title="OAuth">OAuth2.0&lt;/a> model is not secure for both SPA and mobile apps. To solve this challenge -
&lt;a href="https://www.rfc-editor.org/rfc/pdfrfc/rfc7636.txt.pdf" target="_blank" rel="noopener">PKCE&lt;/a> was introduced.&lt;/p>
&lt;h4 id="oauth-20-normal-flow">OAuth 2.0 Normal Flow:&lt;/h4>
&lt;p>&lt;img src="oauth-normal-flow.jpg" alt="alt Components" title="OAuth2.0 Normal Flow">&lt;/p>
&lt;h4 id="pkce-flow">PKCE Flow:&lt;/h4>
&lt;p>&lt;img src="pkce-flow-2.jpg" alt="alt Components" title="PKCE Flow">&lt;/p>
&lt;h3 id="what-is-new-in-pkce">What is new in PKCE?&lt;/h3>
&lt;ol>
&lt;li>In the PKCE flow: Instead of a constant Secret Key - Everytime an OAuth flow is initiated - &lt;strong>A new &amp;ldquo;Secret Key&amp;rdquo;&lt;/strong> is generated and Hashed.&lt;/li>
&lt;li>Hash is shared with the Authentication Server(AS) when requesting for the Temporary Code. AS would remember this Hash value.&lt;/li>
&lt;li>When the client request for the Access Token - it sends the newly generated &amp;ldquo;Secret Key&amp;rdquo; - the AS would check, if the secret matches the Hash (it already remembers - #2).&lt;/li>
&lt;/ol>
&lt;h3 id="reference">Reference:&lt;/h3>
&lt;p>
&lt;a href="https://www.rfc-editor.org/rfc/pdfrfc/rfc7636.txt.pdf" target="_blank" rel="noopener">RFC7636&lt;/a>,
&lt;a href="https://www.youtube.com/watch?v=aU9RsE4fcRM" target="_blank" rel="noopener">Oauth Hack&lt;/a>,
&lt;a href="https://www.youtube.com/watch?v=5cQNwifDq1U" target="_blank" rel="noopener">What&amp;rsquo;s the difference between Confidential and Public clients&lt;/a>&lt;/p></description></item><item><title>Designated Authentication - OAuth2.0</title><link>https://jacobaloysious.in/post/tech_oauth/</link><pubDate>Thu, 02 Dec 2021 00:00:00 +0000</pubDate><guid>https://jacobaloysious.in/post/tech_oauth/</guid><description>&lt;p>
&lt;a href="https://www.youtube.com/watch?v=996OiexHze0" target="_blank" rel="noopener">OAuth2.0 and OpenID&lt;/a> - is one of the best videos (62 mins) on this topic - Highly recommended. This blog is just a quick summary (4 mins read) of it.&lt;/p>
&lt;h3 id="what-is-oauth">What is OAuth?&lt;/h3>
&lt;p>OAuth is a security standard where you give one application permission to access your data from another application i.e. you authorized one application to use data from another application on your behalf, without giving them your username and password. The steps to grant permission(s) or consent is often reffered to as authorization or delegated authorization. Permissions are scoped e.g. client can be given access to read your GMail contacts but cannot Read/Write your email. OAuth is not exactly used for user identification (who loggged in), instead its used to access API&amp;rsquo;s for resources like gmail contact list.&lt;/p>
&lt;p>&lt;img src="access-card-example.jpg" alt="alt Components" title="Access Card Example">&lt;/p>
&lt;ul>
&lt;li>You check-in to a hotel.&lt;/li>
&lt;li>At the front desk - You give your details like Passport and Reservation&lt;/li>
&lt;li>Front Desk would in turn - give you the Key Card i.e. Access Token&lt;/li>
&lt;li>You can use the Key Card to access your reserved Room&lt;/li>
&lt;/ul>
&lt;p>Here, the Front Desk is the Authentication Server - the key card is your Access token used to acess your Room (Resources API). The API doesn&amp;rsquo;t really care who is accessing the Resource as long as they have the access token.&lt;/p>
&lt;h3 id="oauth-terminologies">OAuth Terminologies:&lt;/h3>
&lt;p>Lets assume you are giving Yelp access to your Gmail account contacts..&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Resource Owner:&lt;/strong> Represent you the owner of the gmail account; who can give permission/authorize.&lt;/li>
&lt;li>&lt;strong>Client&lt;/strong>: Represent Yelp i.e. the application which would like to perform action on behalf of you.&lt;/li>
&lt;li>&lt;strong>Authorization Server:&lt;/strong> One who validates the gmail uname/password and authenticate - in this case &lt;em>accounts.google.com&lt;/em>. Resource owner will already have an account with this server (gmail).&lt;/li>
&lt;li>&lt;strong>Resource Server:&lt;/strong> Server (API) which has the actual content/resources like contact list in this case &lt;em>contacts.google.com&lt;/em>. Which client would talk to get the actual data.&lt;/li>
&lt;li>&lt;strong>Authorization Grant:&lt;/strong> Once authenticated an &lt;em>Authorizatiion Code&lt;/em> or temporary code is sent back to he client. So, the client has been granted relevant access to the resource owners gmail contacts. This is short lived, this is used to inturn get the access token (long lived).&lt;/li>
&lt;li>&lt;strong>Redirect URI:&lt;/strong> Also known as Callback. It is the URI to which the response of Authentication #5 should be sent back to client #2&lt;/li>
&lt;li>&lt;strong>Access Token:&lt;/strong> Token/Key used by the Client to access all the resources of the owner; based on the authorized permissions.&lt;/li>
&lt;li>&lt;strong>Response Type&lt;/strong>: The type of information the client would like to receive e.g: code (authorization code)&lt;/li>
&lt;li>&lt;strong>Scope:&lt;/strong> Granular permission the client wants acess to like Read Contact, Read Profile basic info.&lt;/li>
&lt;li>&lt;strong>Consent:&lt;/strong> Whether the client can be given permission to access the requested information.&lt;/li>
&lt;li>&lt;strong>ClientID:&lt;/strong> Unique ID of the client, which is used to talk to the authorization server.&lt;/li>
&lt;li>&lt;strong>Client Secret:&lt;/strong> Secret Key - only the client and the auth server shares. Helps Client and Resource Server to share information secretly behind the scenes.&lt;/li>
&lt;/ol>
&lt;h3 id="oauth-flow">OAuth Flow:&lt;/h3>
&lt;h4 id="prerequisite">Prerequisite:&lt;/h4>
&lt;p>Client and the Authorization Server should establish a working relationship. Both the &amp;ldquo;ClientID (AppID)&amp;rdquo; and &amp;ldquo;Client Secret(AppSecret)&amp;rdquo; are generated by the Authorization Server. The client ID would be used to uniquely identify the client. Its the responsibility of the client to ensure the &amp;ldquo;ClientSecret&amp;rdquo; is kept secret and its only know by client and authorization server. As there are the only means for the Auth Server to verify the client.&lt;/p>
&lt;h4 id="actual-flow">Actual Flow:&lt;/h4>
&lt;p>In this example, Yelp would want to authenticate a user based on GMail Authentication, and access Profile/Contacts information.&lt;/p>
&lt;p>&lt;img src="oauth-code-flow.jpg" alt="alt Components" title="OAuth Code Flow">&lt;/p>
&lt;ol>
&lt;li>Client(Yelp) would make a request to Authenticate - to &amp;ldquo;Autorization Server&amp;rdquo; (accounts.google.com); as part of the request:
&lt;ol>
&lt;li>&amp;ldquo;RedirectURI&amp;rdquo; is set to a callback URL of the client &amp;ldquo;yelp.com/callback&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;Respose Type&amp;rdquo; is set to &amp;ldquo;Code&amp;rdquo;, so a auth code is sent back as response to 1.a&lt;/li>
&lt;li>&amp;ldquo;Client ID&amp;rdquo; and &amp;ldquo;Scope&amp;rdquo; (Profile/Contacts)&lt;/li>
&lt;/ol>
&lt;/li>
&lt;li>Auth Server pops up a dialog (mostly) - where user gets to enter the GMail credentials (uname/pass) and authenticate&lt;/li>
&lt;li>Auth Server shows up a consent form - list the info access requested (like contacts, profile) - user gets to choose Yes or NO&lt;/li>
&lt;li>Once concent(Yes) is given - an &amp;ldquo;Auth Code&amp;rdquo; is generated and sent back to the the client - to specifiied callback/redirectURI.&lt;/li>
&lt;li>Then, the client sends the &amp;ldquo;Auth Code + ClientID + ClientSecret&amp;rdquo; to &amp;ldquo;Authorization Server&amp;rdquo; and gets back an &amp;ldquo;Access Token&amp;rdquo;&lt;/li>
&lt;li>Using the &amp;ldquo;Access Token&amp;rdquo;, Client can contact the resource server (contacts.google.com) to get the actual resources (profile, contacts) of the user.&lt;/li>
&lt;/ol>
&lt;p>Reference: &lt;a href="https://www.youtube.com/watch?v=aU9RsE4fcRM">https://www.youtube.com/watch?v=aU9RsE4fcRM&lt;/a>&lt;/p></description></item></channel></rss>