<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shardul Pathak</title>
    <description>The latest articles on DEV Community by Shardul Pathak (@shapaaa).</description>
    <link>https://dev.to/shapaaa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F195728%2F324e2751-3be9-45a7-871c-41010dfbb33f.png</url>
      <title>DEV Community: Shardul Pathak</title>
      <link>https://dev.to/shapaaa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shapaaa"/>
    <language>en</language>
    <item>
      <title>Understanding HTTPS</title>
      <dc:creator>Shardul Pathak</dc:creator>
      <pubDate>Sun, 11 Jul 2021 09:21:11 +0000</pubDate>
      <link>https://dev.to/shapaaa/understanding-https-j2n</link>
      <guid>https://dev.to/shapaaa/understanding-https-j2n</guid>
      <description>&lt;p&gt;In this post, we are going to deep dive into HTTPS.&lt;/p&gt;

&lt;p&gt;This post contains the following points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Overview of HTTP&lt;/li&gt;
&lt;li&gt;Overview of HTTPS&lt;/li&gt;
&lt;li&gt;How HTTPS connection is achieved&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  HTTP
&lt;/h4&gt;

&lt;p&gt;It is a protocol from the application layer used for the transfer of hypertext, image, videos, etc from client to server.&lt;br&gt;
During client-server communication, the data travels from several devices which are called proxies.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--g6qEzuml--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n600lhk80ntozpprnfbe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--g6qEzuml--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n600lhk80ntozpprnfbe.png" alt="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n600lhk80ntozpprnfbe.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before a client and server can exchange an HTTP request/response pair, they must establish a TCP connection, a process that requires several round-trips.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--itTgPwvO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ks2zctvbz9brppcv2s0m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--itTgPwvO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ks2zctvbz9brppcv2s0m.png" alt="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ks2zctvbz9brppcv2s0m.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After successful connection client can send requests to &amp;amp; read responses from the server. Then it can reuse the connection or can close it.&lt;/p&gt;

&lt;h4&gt;
  
  
  HTTPS
&lt;/h4&gt;

&lt;p&gt;HTTPS is just a secure HTTP connection between client &amp;amp; server needed to achieve 3 main goals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Privacy: Only you can see your data.&lt;/li&gt;
&lt;li&gt;Integrity: There is no tampering of data while transfer from client to server.&lt;/li&gt;
&lt;li&gt;Identification: The website we are visiting is actually that rather than any other proxy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  How HTTPS connection is achieved
&lt;/h4&gt;

&lt;p&gt;To make the connection secure SSL/TLS security gets added to the previous HTTP stack.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NLH_2ua6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p0u2q6j9dilbusr6f38j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NLH_2ua6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p0u2q6j9dilbusr6f38j.png" alt="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p0u2q6j9dilbusr6f38j.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To transfer data between any two entities securely on the internet it should be encrypted using some encryption technique. Cryptographic algorithms are used to make such encryption.&lt;br&gt;
Let's talk about the two types of encryption algorithms.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Secret key cryptography: 
Anyone having this key can either encrypt or decrypt the data.Where Ciphertext is encrypted data.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9HghxQJ9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bwp2pjqixd74zwcvdl23.png" alt="image"&gt; &lt;/li&gt;
&lt;li&gt;Public-Private key cryptography: 
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9eANs_cT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7qaleewrk3nqaa1a729w.png" alt="image"&gt; 
public key has the ability to only encrypt the message &amp;amp; only the private key can decrypt it.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Secret key cryptography can't be used directly for communication on the internet. But Public-Private key cryptography is computationally costly than its counterparts in secret-key cryptography.&lt;/p&gt;

&lt;p&gt;Also there is one more caveat, anyone in between client and server such as proxy servers as shown above can pretend that they are the actual server.&lt;br&gt;
For ex: If you made a request to google.com from a browser and the device in between can pretend that they are actually google and send you a response and maintaining connection from their own end to google server. &lt;strong&gt;This is called a middle man attack.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To prevent that there are third-party Certification Authorities present. A root store is basically a database of trusted CAs which is preinstalled on each browser.&lt;/p&gt;

&lt;p&gt;Let's take a walkthrough of how HTTPS achieved:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Browser sends a list of SSL/TLS versions and encryption algorithms that it can work with a server of that site.&lt;/li&gt;
&lt;li&gt;Server chooses the best algorithm generates public and private keys.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Then server reaches to CA and gives it's public key to get CA signed Public key certificate.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2jUex_Ri--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ara1dwh5em14pr6fsna6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2jUex_Ri--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ara1dwh5em14pr6fsna6.png" alt="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ara1dwh5em14pr6fsna6.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sends this certificate to the client in response. The client verifies that this response is from a valid source by decrypting the signature present in the signed certificate.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If valid then it generates the &lt;strong&gt;pre-master key&lt;/strong&gt; and sends it to the server encrypting with the public key sent in a previous response.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On server, it decrypts data using the private key present.&lt;br&gt;
Now they both generate the same 'shared secret' that they are going to use as a symmetric key to encrypt and decrypt data.&lt;br&gt;
&lt;strong&gt;This is called a TLS handshake.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Well, this is how both secret-key &amp;amp; public-private key cryptography are used in combination to achieve HTTPS connection.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>security</category>
      <category>computerscience</category>
      <category>https</category>
    </item>
    <item>
      <title>Cross Origin Resource Sharing</title>
      <dc:creator>Shardul Pathak</dc:creator>
      <pubDate>Tue, 17 Nov 2020 17:44:28 +0000</pubDate>
      <link>https://dev.to/shapaaa/understanding-cors-54ef</link>
      <guid>https://dev.to/shapaaa/understanding-cors-54ef</guid>
      <description>&lt;p&gt;What is CORS?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Simply CORS is fetching resources from other application having a different origin than the client-side.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Who applies CORS?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Applying a CORS restriction is a security feature defined by a server and implemented by a browser.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  How to know we are making a cross-origin-request?
&lt;/h4&gt;

&lt;p&gt;First, we have to know what origin comprises of.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oylG3sfq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xqmjb1t96boc9t8kkumf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oylG3sfq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xqmjb1t96boc9t8kkumf.png" alt="yaSnKRc0O"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So when we make a request to an origin which differs in any of the above mentioned parameters then it is CORS.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4JL0GB6J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/83utmb4r2cy8d20s6ms2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4JL0GB6J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/83utmb4r2cy8d20s6ms2.png" alt="tFikbNh-l"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  So how it works:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt; So when any application having endpoint &lt;code&gt;https://example.com&lt;/code&gt; makes a request to a &lt;code&gt;https://example-server.com&lt;/code&gt; browser embeds&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vi_VWf8V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gstdvyxztkxthc3hmewu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vi_VWf8V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gstdvyxztkxthc3hmewu.png" alt="w0VKnJNsP"&gt;&lt;/a&gt;&lt;br&gt;
in the request.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When the server receives a request &amp;amp; if it wants to share its resources then it will add &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pPKREj4T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lyz1qzzsskkqe9zxbxxf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pPKREj4T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lyz1qzzsskkqe9zxbxxf.png" alt="BQJJ5gaYW"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Along with that server also adds another field response.type of cors or opaque which can be useful to know if you don't have control over server side api.&lt;/li&gt;
&lt;li&gt;If a request is made for a resource on another origin which returns the CORS headers, then the type is cors.&lt;/li&gt;
&lt;li&gt;Opaque response is for a request made for a resource on a different origin that doesn't return CORS headers.&lt;/li&gt;
&lt;li&gt;When the browser receives a response if it finds the relevant Access-Control-Allow-Origin header, the browser allows the response data to be shared with the client site.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
