
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>Ritik Kumar</title>
 <link href="https://dev-ritik.github.io/atom.xml" rel="self"/>
 <link href="https://dev-ritik.github.io/"/>
 <updated>2026-03-19T19:29:43+00:00</updated>
 <id>https://dev-ritik.github.io</id>
 <author>
   <name>Ritik Kumar</name>
   <email>ritikkne@gmail.com</email>
 </author>

 
 <entry>
   <title>I Analyzed 300+ Indian IPOs. Here’s What Actually Works.</title>
   <link href="https://dev-ritik.github.io/blog/2025/12/31/i-analyzed-300-indian-ipos-heres-what-actually-works/"/>
   <updated>2025-12-31T00:00:00+00:00</updated>
   <id>https://dev-ritik.github.io/blog/2025/12/31/i-analyzed-300-indian-ipos-heres-what-actually-works</id>
   <content type="html">&lt;p&gt;In India, &lt;strong&gt;103 major IPOs hit the market in 2025 alone.&lt;/strong&gt; That’s roughly &lt;strong&gt;two IPOs every single week.&lt;/strong&gt; And this happened in a year when the broader markets weren’t exactly on fire. Still, we saw IPOs clock &lt;strong&gt;listing gains north of 65%&lt;/strong&gt; - which is wild, by any standard.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Disclaimer: This post is purely a data-driven analysis. It’s not investment advice. IPO investing carries risk, and past patterns don’t guarantee future gains. Always do your own research and be prepared for potential losses.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For better or worse, &lt;strong&gt;IPO investing in India has historically been a mix of data, instinct, and straight-up luck.&lt;/strong&gt; If you understand how the game works, subscription trends, GMP chatter, and market mood, it’s &lt;em&gt;generally&lt;/em&gt; been a decent way to make quick, short-term returns. The playbook is familiar: apply, hope you get an allotment, and exit on listing day to book the pop.
&lt;!--break--&gt;&lt;/p&gt;

&lt;p&gt;There’s no shortage of opinions and anecdotal wisdom floating around. And if you think heuristically, it’s easy to form thumb rules about how to position yourself. But beyond that, it often comes down to &lt;strong&gt;luck and timing.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This post is an attempt to &lt;strong&gt;separate intuition from evidence&lt;/strong&gt; and let the data do the talking.&lt;/p&gt;

&lt;p&gt;We’ll dig into questions like:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;What actually &lt;em&gt;drives&lt;/em&gt; listing gains, and which signals are genuinely useful when betting on IPOs?&lt;/li&gt;
  &lt;li&gt;When does it make sense to &lt;strong&gt;sell on listing day&lt;/strong&gt;, and when is holding the smarter move?&lt;/li&gt;
  &lt;li&gt;And finally, &lt;strong&gt;how much of the IPO “hype” survives beyond the first trading session?&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;the-data&quot;&gt;The Data&lt;/h1&gt;
&lt;p&gt;The IPO-level data used in this analysis is sourced from &lt;a href=&quot;https://www.chittorgarh.com/ipo/ipo_dashboard.asp&quot;&gt;Chittorgarh.com&lt;/a&gt;, while post-listing, ticker-level price data comes from &lt;strong&gt;Fyers&lt;/strong&gt;. Together, these cover both the &lt;em&gt;IPO phase and what happens after the stock actually starts trading.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I have collected the data of 300+ listings in the Indian market since 2021 for this analysis.&lt;/strong&gt;&lt;/p&gt;

&lt;h2 id=&quot;what-is-gmp&quot;&gt;What is GMP?&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;GMP (Grey Market Premium)&lt;/strong&gt; is the unofficial price at which IPO shares trade in the grey market before listing.
In simple terms, it reflects &lt;strong&gt;market excitement&lt;/strong&gt; around an IPO.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;A higher GMP typically indicates stronger demand and expectations of a positive listing, while a low or negative GMP suggests weak interest. It’s not regulated, not guaranteed - but it’s often treated as the pulse of IPO sentiment.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;One can find the GMP of a particular stock through websites like Chittorgarh.com&lt;/p&gt;

&lt;h2 id=&quot;what-is-subscription&quot;&gt;What is Subscription?&lt;/h2&gt;
&lt;p&gt;Subscription data shows how many times an IPO has been applied for compared to the shares available in that category.
This is broken down by investor categories:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;QIB&lt;/strong&gt; - Qualified Institutional Buyers&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;NII&lt;/strong&gt; - Non-Institutional Investors (HNIs)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Retail&lt;/strong&gt; - Individual investors&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Employees&lt;/strong&gt; - If applicable&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;Oversubscription indicates strong demand, but who is oversubscribing matters just as much as how much.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;what-is-ipo-success-really&quot;&gt;What Is “IPO Success”, Really?&lt;/h2&gt;
&lt;p&gt;To keep things objective, this analysis uses a straightforward definition:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Listing success = 1% + return on the listing day&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Listing return = (open price - issue price) / issue price&lt;/code&gt;&lt;/p&gt;

&lt;h3 id=&quot;holding-returns&quot;&gt;Holding Returns&lt;/h3&gt;
&lt;p&gt;Performance of the stock &lt;em&gt;after&lt;/em&gt; listing, tracked over periods like one week, one month, and one year.&lt;/p&gt;

&lt;p&gt;Importantly, predicting direction is much easier than predicting magnitude.&lt;/p&gt;

&lt;h2 id=&quot;what-is-sale-type&quot;&gt;What is Sale Type?&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Sale type&lt;/strong&gt; describes how the company is raising money through the IPO:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Fresh Issue / Fresh Capital&lt;/strong&gt; → Company is raising new funds to grow or repay debt.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;OFS (Offer for Sale)&lt;/strong&gt; → Existing shareholders (promoters, early investors) are selling their shares.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Combination (Fresh + OFS)&lt;/strong&gt; → Both new shares are issued, and some existing shareholders are selling.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;why-it-matters&quot;&gt;Why it matters:&lt;/h3&gt;
&lt;p&gt;Fresh issues signal the company is raising money for growth, while OFS-heavy IPOs are more about exiting investors. This can influence demand, pricing, and post-listing performance.&lt;/p&gt;

&lt;h1 id=&quot;correlation&quot;&gt;Correlation&lt;/h1&gt;
&lt;p&gt;To study how IPO signals relate to &lt;strong&gt;listing day returns&lt;/strong&gt;, two types of correlation are used.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pearson correlation&lt;/strong&gt; checks whether two values move together in a straight line. If higher GMP consistently leads to proportionally higher listing gains, Pearson picks that up.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Spearman correlation&lt;/strong&gt; is more forgiving and more realistic. It only looks at ranking - whether IPOs with higher GMP &lt;em&gt;generally&lt;/em&gt; perform better than those with lower GMP.&lt;/p&gt;

&lt;p&gt;Why this matters:&lt;/p&gt;

&lt;p&gt;A GMP of 40% doesn’t guarantee twice the gains of a GMP at 20%. But IPOs with 40% GMP still tend to outperform IPOs at 20%. Pearson struggles with this nuance; Spearman captures it well.&lt;/p&gt;

&lt;h2 id=&quot;how-to-read-correlation-numbers&quot;&gt;How to Read Correlation Numbers&lt;/h2&gt;
&lt;p&gt;Both Pearson r and Spearman ρ range from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;–1&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+1&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;+1 → strong positive relationship
0 → no real relationship
–1 → strong negative relationship


As a rule of thumb:
0.2–0.4 → weak
0.4–0.6 → moderate
0.6–0.8 → strong
0.8+ → very strong
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Using both helps distinguish between exact prediction and directional edge, which is far more useful in messy, real-world markets.&lt;/p&gt;

&lt;p&gt;Below is the correlation of&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Signal&lt;/th&gt;
      &lt;th&gt;Pearson r&lt;/th&gt;
      &lt;th&gt;Spearman ρ&lt;/th&gt;
      &lt;th&gt;What it Tells Us&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;GMP (%)&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;0.82&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;0.76&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Strongest predictor by a wide margin&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Total Subscription&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;0.70&lt;/td&gt;
      &lt;td&gt;0.72&lt;/td&gt;
      &lt;td&gt;Demand matters, but less than GMP&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;QIB Subscription&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;0.67&lt;/td&gt;
      &lt;td&gt;0.73&lt;/td&gt;
      &lt;td&gt;Institutional interest is a key signal&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;NII Subscription&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;0.58&lt;/td&gt;
      &lt;td&gt;0.62&lt;/td&gt;
      &lt;td&gt;HNI demand has moderate impact&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Retail Subscription&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;0.46&lt;/td&gt;
      &lt;td&gt;0.56&lt;/td&gt;
      &lt;td&gt;Weakest, but not irrelevant&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Clearly, GMP has the best correlation.&lt;/p&gt;

&lt;p&gt;To demonstrate this better, below is a plot of GMP, total subscription and listing gains. Note that the x and y axes are log scales (for clarity) and the listing gains are represented by colour (this is rounded to 0.5% to 20% for the sake of clarity)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:1100/format:webp/1*lofBmXS_ElPuznwoD6zu4A.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Clearly, there’s a good chance of listing gains if GMP is 20% or more and/or subscription is 25x or more.&lt;/p&gt;

&lt;p&gt;The following section gives a closer look at the same stats.&lt;/p&gt;

&lt;h2 id=&quot;listing-gains-by-gmp&quot;&gt;Listing gains by GMP&lt;/h2&gt;
&lt;p&gt;Below is the bucketized GMP and listing gains stats. A successful listing is when the listing of an IPO gives more than 1% returns.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;br /&gt;gmp_bucket&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;count&lt;br /&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;success_rate&lt;br /&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;median_return&lt;br /&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&amp;lt;0&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;40&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.38&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.00&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0–10&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;99&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.49&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.00&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;10-15&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;29&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.62&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.04&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;15–20&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;20&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.85&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.14&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;20–25&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;21&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.81&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.19&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;25–30&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;22&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.82&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.23&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;30–60&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;57&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.98&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.37&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;60+&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;34&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1.00&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.74&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Clearly, there’s a good chance of listing gains for cases when GMP is more than 15%&lt;/p&gt;

&lt;h2 id=&quot;listing-gains-by-total-subscription&quot;&gt;Listing Gains by total subscription&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;br /&gt;total_sub_bucket&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;count&lt;br /&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;success_rate&lt;br /&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;median_return&lt;br /&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&amp;lt;1x&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;5&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.20&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-0.01&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1–10x&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;100&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.43&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.00&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;10–20x&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;32&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.62&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.08&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;20–30x&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;24&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.50&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.01&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;30-50x&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;32&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.81&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.12&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;50x+&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;129&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.95&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.36&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Here, above 30x total subscription, we stand a decent chance of making good returns&lt;/p&gt;

&lt;h2 id=&quot;listing-gains-by-sale-type&quot;&gt;Listing Gains by sale type&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;br /&gt;sale_type&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;count&lt;br /&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;success_rate&lt;br /&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;median_return&lt;br /&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Fresh Capital&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;57&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.74&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.12&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Fresh Capital &amp;amp; OFS&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;204&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.69&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.10&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Offer For Sale&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;61&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.69&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.08&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;There’s a slight statistical bias towards fresh capital, which is kinda intuitive. Money going to the company can later be used to pay off debt or for Capex and expansion, etc which is better for the new shareholders&lt;/p&gt;

&lt;h2 id=&quot;post-listing-1st-day-return&quot;&gt;Post listing 1st day return&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;br /&gt;sale_type&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;mean&lt;br /&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;median&lt;br /&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;count&lt;br /&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Fresh Capital&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;3.77&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;5.00&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;57&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Fresh Capital &amp;amp; OFS&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.16&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-0.14&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;204&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Offer For Sale&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-0.11&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-0.54&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;61&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Here again, there’s a good bias to fresh capital, meaning it may be worth holding IPOs with fresh capital.&lt;/p&gt;

&lt;h2 id=&quot;post-listing&quot;&gt;Post listing&lt;/h2&gt;
&lt;p&gt;The goal of the following table was to understand, statistically, if there is a correlation between listing gains and returns in the 1st week, month and year of listing&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;br /&gt;&lt;br /&gt;listing_gain_bucket&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;next_week_return&lt;br /&gt;mean&lt;br /&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;next_week_return&lt;br /&gt;median&lt;br /&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;next_week_return&lt;br /&gt;count&lt;br /&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;next_month_return&lt;br /&gt;mean&lt;br /&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;next_month_return&lt;br /&gt;median&lt;br /&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;next_month_return&lt;br /&gt;count&lt;br /&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;next_year_return&lt;br /&gt;mean&lt;br /&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;next_year_return&lt;br /&gt;median&lt;br /&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;next_year_return&lt;br /&gt;count&lt;br /&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Loss&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1.60&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-0.26&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;91&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;2.02&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-1.44&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;87&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;8.71&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-4.42&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;58&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0–5%&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.79&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-1.70&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;42&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;3.83&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-1.64&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;42&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;20.25&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1.54&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;27&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;5–10%&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.92&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-2.03&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;30&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1.11&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-1.51&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;29&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;6.81&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-2.01&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;21&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;10–20%&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;3.95&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1.69&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;49&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;4.27&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-1.06&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;48&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;27.87&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-0.52&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;31&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;20–50%&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.41&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-2.90&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;65&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-0.16&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-3.23&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;62&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;20.51&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;3.01&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;48&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;50%+&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-0.07&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-2.14&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;45&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-2.52&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-5.28&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;45&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;11.23&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-15.36&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;41&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;But clearly, it’s not a good signal. The hold/ buy call based on just listing gains doesn’t make sense.&lt;/p&gt;

&lt;h2 id=&quot;average-subscription&quot;&gt;Average subscription&lt;/h2&gt;
&lt;p&gt;The data below shows the &lt;strong&gt;average ratio between retail and sNII subscriptions&lt;/strong&gt;. This is a fairly consistent trend: &lt;strong&gt;retail investors usually have better chances of getting an allocation&lt;/strong&gt; based on subscription numbers. However, in terms of &lt;strong&gt;absolute returns&lt;/strong&gt;, investing around Rs2 lakh in the sNII category often offers &lt;strong&gt;more upside&lt;/strong&gt;. On average, the multiple tends to be around &lt;strong&gt;2.5x&lt;/strong&gt;.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;br /&gt;gmp_bucket&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;sub_sNII (bids below Rs10L)&lt;br /&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;sub_Retail&lt;br /&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;sNII_to_Retail_ratio&lt;br /&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&amp;lt;0&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1.97&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;3.17&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0.62&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0–5&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;4.54&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;3.13&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1.45&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;5–10&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;29.21&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;9.63&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;3.03&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;10–20&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;55.03&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;21.89&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;2.51&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;20–50&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;106.96&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;36.40&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;2.94&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;50+&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;150.36&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;59.76&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;2.52&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;conclusion-data-over-hype&quot;&gt;Conclusion: Data Over Hype&lt;/h1&gt;
&lt;p&gt;The numbers reveal a clear pattern: IPO success in India isn’t just a roll of the dice; it’s a signal-driven game. To navigate this market effectively, keep these three data-backed rules in mind:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Trust the GMP&lt;/strong&gt;: With a 0.76 correlation, the Grey Market Premium is your most reliable North Star. A GMP above 20% is the historical sweet spot for high-probability listing gains.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The 30x Threshold&lt;/strong&gt;: Subscription matters, but only at scale. Once total demand crosses 30x, the likelihood of a successful listing (1%+ gain) becomes significantly more stable.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quality of Capital&lt;/strong&gt;: IPOs focused on Fresh Capital consistently outperform OFS-heavy exits. If the money stays in the company, the market usually rewards it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Final Word: A massive listing “pop” does not guarantee long-term growth. The data shows no strong link between Day 1 gains and Year 1 returns. For the short-term trader, follow the signals; for the long-term investor, look beyond the first day’s excitement.&lt;/p&gt;

&lt;p&gt;If you have ideas for other comparisons or signals to analyse, I’d love to hear them! Drop your suggestions in the comments, and let’s dig deeper together.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>From Announcement to Action: The Impact of Capex News on Stock Prices</title>
   <link href="https://dev-ritik.github.io/blog/2024/11/21/from-announcement-to-action-the-impact-of-capex-news-on-stock-prices/"/>
   <updated>2024-11-21T00:00:00+00:00</updated>
   <id>https://dev-ritik.github.io/blog/2024/11/21/from-announcement-to-action-the-impact-of-capex-news-on-stock-prices</id>
   <content type="html">&lt;p&gt;In the stock market, reacting to news is a well-known tactic. Investors often trade or make swing and long-term positions based on announcements, aiming to capitalize on sharp price movements. But how impactful can a single piece of news be?&lt;/p&gt;

&lt;p&gt;This case study focuses on a striking example of how a &lt;strong&gt;capital expenditure (capex)&lt;/strong&gt; announcement transformed market sentiment within hours.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;the-company-in-focus-deepak-nitrite&quot;&gt;The Company in Focus: Deepak Nitrite&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;Deepak Nitrite&lt;/strong&gt; is one of India’s fastest-growing and most trusted names in chemical intermediates. Known for its consistent performance and strategic expansions, the company has built a solid reputation in the industry and the stock market alike.
&lt;!--break--&gt;&lt;/p&gt;

&lt;h1 id=&quot;the-big-day-may-24-2024&quot;&gt;The Big Day: May 24, 2024&lt;/h1&gt;
&lt;p&gt;On this day, &lt;strong&gt;Deepak Nitrite&lt;/strong&gt; issued a notification that sent ripples through the market. Investors responded with overwhelming enthusiasm, pushing the stock price up by an impressive &lt;strong&gt;10%&lt;/strong&gt; by the day’s close.&lt;/p&gt;

&lt;h1 id=&quot;what-did-the-notification-say&quot;&gt;What Did the Notification Say?&lt;/h1&gt;
&lt;p&gt;Here’s a snippet from the announcement: &lt;a href=&quot;https://www.bseindia.com/xml-data/corpfiling/AttachHis/e948f772-4498-4f74-a68d-bf3020adabb7.pdf&quot;&gt;[src]&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Sub: Intimation under Regulation 30 of SEBI (Listing Obligations and Disclosure Requirements) Regulations, 2015&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Pursuant to the requirement of Regutation 30 of SEBI (Listing Obtigations and Disclosure Requirements) Regulations, 2015, this is to inform you that the Company’s wholly owned subsidiary, Deepak Chem Tech Limited (formerly known as Deepak Clean Tech Limited) has signed a Memorandum of Understanding with Government of Gujarat on 23rd May, 2023 with an intent to invest around Rs. 5,000 Crores in next 4 years for setting up projects to manufacture Speciality Chemicals, Phenol / Acetone and Bisphenol at Dahej / Nandesari, in the State of Gujarat.&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;The proposed investment is expected to generate around 1,500 direct and indirect employment opportunities.&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;The proposed investment will also help reduce India’s import bill. Products out of these projects have varied end use such as:&lt;/em&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;
      &lt;p&gt;&lt;em&gt;Speciality Chemicals cater to the demand of Agro Chemicals and Pharma industries.&lt;/em&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;&lt;em&gt;Phenol and Acetone are used in varied end-user segments like laminates, plywood, pharma, paint, adhesives etc.&lt;/em&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;&lt;em&gt;Bisphenol caters to Epoxy and Adhesives and is the most important feedstock towards Polycarbonate which has various applications across Automotive, Electronic and Consumer Goods, Defense, Medical Equipment etc.&lt;/em&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;em&gt;Please take the same on your record.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;timeline-of-deepak-nitrites-stock-movement&quot;&gt;Timeline of Deepak Nitrite’s Stock Movement&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:1100/format:webp/1*nXiD8mj3x6MQ9-qLOTnh3g.jpeg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;How the news broke&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;🕒 &lt;strong&gt;09:15:00 - Market Opens&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Opening Price:&lt;/strong&gt; Rs. 1948 per share.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The market starts its day quietly, with no signs of the storm brewing ahead.&lt;/p&gt;

&lt;p&gt;🕒 &lt;strong&gt;10:25:57 - News Hits the BSE&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Price at Announcement:&lt;/strong&gt; Rs. 1944.95 per share.
This will serve as our &lt;strong&gt;reference point&lt;/strong&gt; to measure the stock’s upside potential.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🕒 &lt;strong&gt;10:29:56 - NSE Publishes the News&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Price:&lt;/strong&gt; Rs. 1956.15 per share &lt;strong&gt;(+0.575% in 4 minutes)&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Volume Spike:&lt;/strong&gt; From &lt;strong&gt;200–300 per minute&lt;/strong&gt; to &lt;strong&gt;6,000–7,000 per minute&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The sudden activity likely signals the presence of &lt;strong&gt;automated trading bots&lt;/strong&gt;, responding faster than human traders could.&lt;/p&gt;

&lt;p&gt;🕒 &lt;strong&gt;10:31:00 - Reuters on TradingView&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Price:&lt;/strong&gt; Rs. 1955 per share &lt;strong&gt;(+0.5%)&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Volume:&lt;/strong&gt; Continues at heightened levels.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Despite the news spreading further, the price sees little movement, consolidating gains.&lt;/p&gt;

&lt;p&gt;🕒 &lt;strong&gt;11:55:04 - Major Public Coverage (Business Standard)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Price:&lt;/strong&gt; Rs. 2125 per share &lt;strong&gt;(+9.25% from the reference price)&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Volume:&lt;/strong&gt; Peaks in six-digit figures per minute.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For nearly &lt;strong&gt;1.5 hours&lt;/strong&gt;, the stock showed a &lt;strong&gt;linear price increase&lt;/strong&gt;, offering a golden window for attentive traders to capitalize. By this point, &lt;strong&gt;most of the upside had already been captured&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;🕒 &lt;strong&gt;15:30:00 - Market Closes&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Closing Price:&lt;/strong&gt; Rs. 2130.05 per share.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Final Upside:&lt;/strong&gt; Minimal movement since the Business Standard article.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;key-takeaway-timing-is-everything&quot;&gt;Key Takeaway: Timing is Everything&lt;/h1&gt;
&lt;p&gt;By the time news reaches the &lt;strong&gt;mainstream media&lt;/strong&gt;, it’s often &lt;strong&gt;too late&lt;/strong&gt; for the average investor. In this case, the majority of returns were realized &lt;strong&gt;within 1.5 hours&lt;/strong&gt; of the initial announcement. This underscores the advantage of being well-informed and having the tools to act swiftly.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;further-timeline&quot;&gt;Further timeline&lt;/h1&gt;
&lt;p&gt;🕒 &lt;strong&gt;11:34:24 (May 25)&lt;/strong&gt; - Exchange Seeks Clarification&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;The Exchange has sought clarification from Deepak Nitrite Ltd on May 25, 2023, with reference to Movement in Volume.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;🕒 &lt;strong&gt;12:47:09 (May 25)&lt;/strong&gt; - Standard Response&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Further, there is no information / announcement (including pending announcement) which in our opinion may have bearing on the Price / Volume behavior in the scrip and which is required to be informed to Stock Exchanges in terms of Regulation 30 of SEBI (LODR) Regulations, 2015.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*f7lq28bduyFLJRn0zlWI_w.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;It’s still 20% high since that days closing even in this bearish market&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;To wrap things up, there’s a similar and even more fascinating story in the book Business Adventures: Twelve Classic Tales from the World of Wall Street. In the chapter “A Reasonable Amount of Time”, it talks about how insiders at Texas Gulf Sulphur tried to cash in on secret information before the news went public. It’s a gripping tale that ended up changing how insider trading is dealt with today. If you found this case interesting, that one’s definitely worth checking out!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;hr /&gt;

&lt;p&gt;Feel free to share your thoughts or insights in the comments!&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Raspberry Pi Camera Live Streaming: Step-by-Step Setup</title>
   <link href="https://dev-ritik.github.io/blog/2023/10/01/raspberry-pi-camera-live-streaming-step-by-step-setup/"/>
   <updated>2023-10-01T00:00:00+00:00</updated>
   <id>https://dev-ritik.github.io/blog/2023/10/01/raspberry-pi-camera-live-streaming-step-by-step-setup</id>
   <content type="html">&lt;blockquote&gt;
  &lt;p&gt;Are you ready for some weekend tech fun? Buckle up because we’re about to embark on an exciting journey! Our mission? To create a cutting-edge Raspberry Pi-based image streaming service that brings real-time images right to your phone, no matter where you are. And the best part? It’s all about keeping things locked down tight — your feed, your privacy, and your excitement!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;🔧 What You’ll Need for this Awesome Project 🔧&lt;/p&gt;

&lt;p&gt;Gather up your tools because we’re about to embark on a tech adventure that’s as exciting as it is educational! Here’s your checklist:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;🍇&lt;a href=&quot;https://amzn.to/3RGIlPn&quot;&gt;Raspberry Pi&lt;/a&gt;: The tiny computer with mighty capabilities, perfect for running small computing tasks right from the comfort of your home or lab.&lt;/li&gt;
  &lt;li&gt;📷&lt;a href=&quot;https://amzn.to/3tcUAsX&quot;&gt;Raspberry Pi Camera&lt;/a&gt;: A budget-friendly 5MP camera that captures surprisingly sharp and clear images.&lt;/li&gt;
  &lt;li&gt;☁️AWS EC2, Azure VM, or a Cloud VM Hosting Service of Your Choice: We’ll harness the power of the cloud to set up our very own Nginx server with mutual certificate authentication.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;setting-up-raspberry-pi&quot;&gt;Setting up Raspberry Pi&lt;/h1&gt;
&lt;p&gt;Having any OS on Pi should be fine. We shall be using Python in this project. However, I recommend popular Linux distros like Debian or any OS based on Debian.&lt;/p&gt;

&lt;p&gt;You can skip this step if you already have a working Pi. Or follow resources like &lt;a href=&quot;https://raspberrytips.com/install-debian-on-raspberry-pi/&quot;&gt;this&lt;/a&gt; to flash your SD card and boot and set up Debian on the PI.&lt;/p&gt;

&lt;h1 id=&quot;connecting-the-pi-camera&quot;&gt;Connecting the Pi Camera&lt;/h1&gt;
&lt;p&gt;With the Pi setup complete and the Pi up and running, let’s get the PI camera on the Pi. Many resources are available on the internet to help us with this. You may follow this &lt;a href=&quot;https://raspberrytips.com/install-camera-raspberry-pi/&quot;&gt;one&lt;/a&gt;.&lt;/p&gt;

&lt;h1 id=&quot;pipeline&quot;&gt;Pipeline&lt;/h1&gt;
&lt;p&gt;In this project, we shall be creating this pipeline. A brief overview of the steps:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Python program uses the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;picamera2&lt;/code&gt; module to periodically capture images&lt;/li&gt;
  &lt;li&gt;Encode and send the picture as an HTML file using SCP&lt;/li&gt;
  &lt;li&gt;Create an Nginx config file to serve the file&lt;/li&gt;
  &lt;li&gt;Create and install a key certificate to authenticate the client&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:1100/format:webp/1*mhHbZVLoaL4oJraUVR1sbg.jpeg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Pipeline image
&lt;!--break--&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;the-code&quot;&gt;The Code&lt;/h1&gt;
&lt;p&gt;We are using Python 3 here, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;picamera&lt;/code&gt; Module. However, picamera doesn’t work with python3. To fix that, there is this &lt;em&gt;Picamera2&lt;/em&gt; replacement (still in beta); we shall use that instead.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;picamera2&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Picamera2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Preview&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;picam2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Picamera2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;preview_config&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;picam2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;create_preview_configuration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;picam2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;preview_config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;picam2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Clicking picture&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
          &lt;span class=&quot;n&quot;&gt;metadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;picam2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;capture_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IMAGE_PATH&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
          &lt;span class=&quot;c1&quot;&gt;# Image to Base 64 string
&lt;/span&gt;          &lt;span class=&quot;n&quot;&gt;image_b64&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;get_b64_string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IMAGE_PATH&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
          &lt;span class=&quot;c1&quot;&gt;# Format a boiler html with this string
&lt;/span&gt;          &lt;span class=&quot;n&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;get_html&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;image_b64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;datetime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
          &lt;span class=&quot;c1&quot;&gt;# scp the file to the server
&lt;/span&gt;          &lt;span class=&quot;n&quot;&gt;export_html_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;html&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
          &lt;span class=&quot;n&quot;&gt;sleep&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SLEEP_DURATION&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Exception&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exception&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;Failed: &apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;picam2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;picam2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;When Creating a valid HTML string from the base 64 encoded image, add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;meta http-equiv=”refresh” content=”{refresh}”&amp;gt;&lt;/code&gt; to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;head&lt;/code&gt; tag to auto-refresh the image in the browser.&lt;/p&gt;

&lt;h2 id=&quot;running-the-script-in-daemon-mode&quot;&gt;Running the script in daemon mode&lt;/h2&gt;
&lt;p&gt;Once the code is up and running and sending images to the remote server, we need to ensure that it gets up and running automatically when the PI restarts.&lt;/p&gt;

&lt;p&gt;To achieve this, let’s use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;systemctl&lt;/code&gt;. Create and paste the following code into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/systemd/system/picam.service&lt;/code&gt; file:&lt;/p&gt;

&lt;div class=&quot;language-toml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nn&quot;&gt;[Unit]&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;Description&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;PiCam&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;process.&lt;/span&gt;

&lt;span class=&quot;nn&quot;&gt;[Service]&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;simple&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;lt;user&amp;gt;&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;Group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;lt;user&amp;gt;&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;ExecStart&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;/bin/bash&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;-c&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;/usr/bin/python /&amp;lt;project main file path&amp;gt;&apos;&lt;/span&gt;

&lt;span class=&quot;nn&quot;&gt;[Install]&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;WantedBy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;multi-user.target&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This will create a basic systemd service to run the program. To set it to auto-start on reboot, run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo systemctl enable picam&lt;/code&gt; to enable it. Check &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo systemctl status picam&lt;/code&gt; to see if there were any errors.&lt;/p&gt;

&lt;h1 id=&quot;on-the-server&quot;&gt;On the Server&lt;/h1&gt;
&lt;p&gt;We all want our private feeds to be secure, but who wants the hassle of entering IDs and passwords every time? Not us! That’s why we’ve got a game-changer in store: SSL Mutual Authentication.&lt;/p&gt;

&lt;h2 id=&quot;authenticating-via-certificates-ssl-mutual-authentication-setup&quot;&gt;Authenticating via certificates: SSL mutual authentication setup&lt;/h2&gt;
&lt;p&gt;By default, HTTPS is a one-way authorization where the client checks if the server is indeed who he claims to be. However, it also supports mutual authentication, where not only does the server verify the client’s identity, but the client can also verify the server’s identity.&lt;/p&gt;

&lt;p&gt;To set it up, we need to generate some certificates and keys&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# Generate an RSA private key&lt;/span&gt;
openssl genrsa &lt;span class=&quot;nt&quot;&gt;-out&lt;/span&gt; client.key 4096
&lt;span class=&quot;c&quot;&gt;# Generate self-signed certificate&lt;/span&gt;
openssl req &lt;span class=&quot;nt&quot;&gt;-new&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-x509&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-days&lt;/span&gt; 365 &lt;span class=&quot;nt&quot;&gt;-key&lt;/span&gt; client.key &lt;span class=&quot;nt&quot;&gt;-out&lt;/span&gt; client.crt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;nginx-setup&quot;&gt;Nginx setup&lt;/h2&gt;
&lt;p&gt;Added this in the server block to enable client validation&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;location /&amp;lt;image_feed_url_slug&amp;gt;.html {
if ($ssl_client_verify != &quot;SUCCESS&quot;) { return 403; }
alias /&amp;lt;image_path&amp;gt;.html;
}

# our self signed certificate
ssl_client_certificate /&amp;lt;path&amp;gt;/client.crt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;on-the-client-machine-browsers&quot;&gt;On the client machine (browsers)&lt;/h2&gt;
&lt;p&gt;Run the following to get a PKCS12 file&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# Export the private key and certificate to PKCS12 file. Remember the password&lt;/span&gt;
openssl pkcs12 &lt;span class=&quot;nt&quot;&gt;-export&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-inkey&lt;/span&gt; ./client.key &lt;span class=&quot;nt&quot;&gt;-in&lt;/span&gt; ./client.crt &lt;span class=&quot;nt&quot;&gt;-out&lt;/span&gt; ./client.p12
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can install this PKCS12 file in the browser’s user cert section of the certificate settings page. (Use the password when prompted)&lt;/p&gt;

&lt;p&gt;For Android devices, if the above doesn’t work, you need to do the following additional steps (based on the answers &lt;a href=&quot;https://stackoverflow.com/questions/71872900/installing-pcks12-certificate-in-android-wrong-password-bug&quot;&gt;here&lt;/a&gt;) to get a legacy PKCS12 file:&lt;/p&gt;
&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# Converts the PKCS12 file to a PEM file without password&lt;/span&gt;
openssl pkcs12 &lt;span class=&quot;nt&quot;&gt;-noenc&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-in&lt;/span&gt; client.p12 &lt;span class=&quot;nt&quot;&gt;-out&lt;/span&gt; temp_client.pem
&lt;span class=&quot;c&quot;&gt;# Converts the PEM file to legacy PKCS12 file. The -legacy option tells OpenSSL to use the legacy PKCS12 format, which is compatible with older devices.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# Add a password&lt;/span&gt;
openssl pkcs12 &lt;span class=&quot;nt&quot;&gt;-export&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-legacy&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-in&lt;/span&gt; temp_client.pem &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; client_legacy.p12 &lt;span class=&quot;c&quot;&gt;# Add new password for android&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Install this legacy PKCS12 on the Android device with the new password. Set it in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;VPN and app user certificate&lt;/code&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;blockquote&gt;
  &lt;p&gt;If all went well, you must be able to see the live image feed from the camera on you browser&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;what-lies-ahead&quot;&gt;What Lies Ahead&lt;/h1&gt;
&lt;h2 id=&quot;taking-your-project-to-the-next-level&quot;&gt;Taking Your Project to the Next Level:&lt;/h2&gt;
&lt;p&gt;As you wrap up this fantastic journey of setting up your Raspberry Pi-based image streaming service, it’s time to look to the future. Here are some exciting possibilities to explore:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Enhanced Performance&lt;/strong&gt;: Take your streaming to the next level by implementing optimizations like sending only the difference in images or transmitting images when motion is detected. These tweaks can make your service even more efficient and responsive.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dynamic Live Feeds&lt;/strong&gt;: You can expand your project to support video-based live feeds. Imagine having real-time video streaming from your Raspberry Pi straight to your phone. The possibilities are endless!&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;By delving into these further steps, you can continue to elevate your project, making it even more powerful and versatile. The world of DIY tech is yours to explore, so keep innovating, experimenting, and enjoying every moment of your tech journey. 🚀🔍📹&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>Income Tax Filing for Foreign Assets</title>
   <link href="https://dev-ritik.github.io/blog/2023/07/27/income-tax-filing-for-foreign-assets/"/>
   <updated>2023-07-27T00:00:00+00:00</updated>
   <id>https://dev-ritik.github.io/blog/2023/07/27/income-tax-filing-for-foreign-assets</id>
   <content type="html">&lt;p&gt;Let’s be real — filing for income tax in India can be a bit of a head-scratcher. It’s like trying to solve a puzzle where the rules keep changing, and for someone new to the whole earning-and-tax thing, it can get seriously overwhelming. You’ve got the basics down, but what about those foreign assets? The whole “I didn’t sell, why bother” strategy might not be the tax-saver it seems.&lt;/p&gt;

&lt;p&gt;And don’t get me started on the CA route. It turns out that even they sometimes draw a blank regarding the nitty-gritty details.&lt;/p&gt;

&lt;p&gt;And here’s the kicker — mishandling those foreign assets can trigger notices, bringing you face-to-face with the &lt;strong&gt;Black Money Act&lt;/strong&gt;. Massive penalties lurk and the prospect of jail time is not just a distant threat.
&lt;!--break--&gt;&lt;/p&gt;

&lt;p&gt;Wait, there’s more: India and the US have agreements that allow them to exchange details about their residents’ assets. So, thinking your overseas investments are flying under the radar? Think again!&lt;/p&gt;

&lt;p&gt;People around have been getting away with not disclosing foreign assets. The luck factor may be in play here, and you may be living on borrowed time. The department can issue notices anytime, and there is no time limitation.&lt;/p&gt;

&lt;p&gt;Let’s unravel the tax web together, ditch the confusion, and arm you with the know-how to breeze through this financial maze. Because in the world of taxes, knowledge is definitely power! 💪💰🔍&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;There’s not much information on the internet available on how to fill details regarding foreign assets. This blog is my efforts on consolidating on whatever I could find from the internet and some CAs around.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;disclaimer&quot;&gt;Disclaimer&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;The following Medium blog is my perspective, and I might be wrong. The discussion is focused on stocks held in United States by Indian Residents. Things may change if you hold stocks elsewhere. Things may also change drastically with time and the details here can turn outright incorrect for that time period.&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Please do your due diligence before using any information here. Your case might be different than what I discuss. Consulting your tax advisor is highly recommended.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;concept&quot;&gt;Concept&lt;/h2&gt;
&lt;p&gt;Before we start, let’s clear a few things:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Conversion rate&lt;/strong&gt;: We should use RBI’s reference rate or SBI’s telegraphic transfer buying rate (&lt;strong&gt;TTBR&lt;/strong&gt;) for any USD-INR conversion. I am referring to &lt;a href=&quot;https://incometaxindia.gov.in/Rules/Income-Tax%2520Rules/103120000000007546.htm&quot;&gt;this rule&lt;/a&gt; I found on income tax. If it is a holiday, we should take the TTBR of the immediately preceding working day. Pick the table from the TTBR pdf with “to be used as a reference” mentioned. However, SBI doesn’t provide historical data, so we may use these sources to get that:&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;https://github.com/sahilgupta/sbi_forex_rates/blob/main/csv_files/SBI_REFERENCE_RATES_USD.csv?source=post_page-----a98d77a5895e--------------------------------&quot;&gt;sbi_forex_rates/csv_files/SBI_REFERENCE_RATES_USD.csv&lt;/a&gt;&lt;/p&gt;
    &lt;blockquote&gt;
      &lt;p&gt;This project downloads and stores the daily SBI forex rates in a CSV file enabling you to access historical rates…&lt;/p&gt;
    &lt;/blockquote&gt;

    &lt;p&gt;&lt;a href=&quot;https://github.com/skbly7/sbi-tt-rates-historical?source=post_page-----a98d77a5895e--------------------------------&quot;&gt;skbly7/sbi-tt-rates-historical&lt;/a&gt;&lt;/p&gt;
    &lt;blockquote&gt;
      &lt;p&gt;Historical SBI TT rates since 02 July 2020. These are one of important rates required for ITR purposes and not made…&lt;/p&gt;
    &lt;/blockquote&gt;

    &lt;p&gt;&lt;a href=&quot;https://mksco.in/forexrate/?source=post_page-----a98d77a5895e--------------------------------&quot;&gt;Forex Card Rates&lt;/a&gt;&lt;/p&gt;
    &lt;blockquote&gt;
      &lt;p&gt;All the content on this site is published in good faith and for general information purpose only. Mksco does not make…&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;For filing Foreign Asset-related schedules, you can opt for ITR2 or ITR3. Choose ITR3 if you have some business income.&lt;/li&gt;
  &lt;li&gt;Rounding errors: Please use all the required decimals for the calculations. Round up the final number while filing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Relevant Schedules when having Foreign Assets are:&lt;/p&gt;

&lt;h1 id=&quot;schedule-foreign-assets-fa&quot;&gt;Schedule Foreign Assets (FA)&lt;/h1&gt;
&lt;p&gt;The department expects any Indian resident to declare whatever foreign asset one might have. The following excuses will not work:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;It is RSU, and the company has already deducted the required tax and declared it in Form 16.&lt;/li&gt;
  &lt;li&gt;I didn’t sell anything.&lt;/li&gt;
  &lt;li&gt;I didn’t move the money to India.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This schedule is only for declaration and bookkeeping by the department. United States issues proofs in &lt;strong&gt;January to December&lt;/strong&gt; cycle (current year). Hence, we should declare assets till December.&lt;/p&gt;

&lt;p&gt;This schedule has a lot of tables for declaring the different kinds of assets. I will only discuss cases when we have bought stocks or have RSUs from the company.&lt;/p&gt;

&lt;h2 id=&quot;stock-declaration&quot;&gt;Stock declaration&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Use Table A3 for Schedule FA. Some people use Table D (which is simple) as well but Table A3 is recommended.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In Table A3, we should fill each individual holding separately. It must be acceptable to club all the buy trade for a day in a single entry but across multiple days should have its separate entry. Currently, we will have to enter the details manually every time. This is cumbersome, but it’s good to do it this way. For RSUs, what this means is that all unsold/ partially sold vesting should be added separately.&lt;/p&gt;

&lt;p&gt;Sample Table A3 will have the below essential fields, which I have explained using this example.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;I bought 100 units on 21 Dec 2021 @ $200 and sold 40 units from Jan 2022 to Dec 2022 @ $300&lt;/code&gt;. For FY 2022–2023, in foreign assets, I should fill the following:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Date of acquiring&lt;/strong&gt;: Date of purchase (or vesting date): 21st Dec 2021&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Initial value of the investment&lt;/strong&gt;: Amount paid on the purchase. = &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;100 * 200 * TTBR conversion rate on the date of investment&lt;/code&gt;. If you have these units at a discount via ESPP (Employee Stock Purchase Program), you should probably add the undiscounted fair market value here.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Peak value&lt;/strong&gt;: Max value of the investment during the holding period between Jan to Dec = &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;100 * max value of the stock during the period * TTBR of the date when that stock has max value&lt;/code&gt;. In practice, people likely take the peak value for the entire year (not just the holding period maximum).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Closing value&lt;/strong&gt;: The closing value of investment till 31st Dec = &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;60 * closing value of stock on 31st Dec * TTBR&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Total gross amount paid/credited with respect to the holding during the period&lt;/strong&gt;: Calculate the total dividend and interest for this particular unit from Jan to Dec. The conversion rate probably will be calculated based on the dividend payment date. Take the TTBR of the last date of the immediately preceding month. &lt;em&gt;This is the most computational work of the entire process&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Total gross proceeds from sale or redemption of investment during the period&lt;/strong&gt;: Total value of stock sold during the Jan to Dec period from that lot = &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;40 * 300 * TTBR on the date of selling of stocks&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every data should be proportionally reduced for the next year to match 60 unit holding.&lt;/p&gt;

&lt;h2 id=&quot;broker-balance-declaration&quot;&gt;Broker balance declaration&lt;/h2&gt;
&lt;p&gt;The broker balance (presumably because of the dividends and interest accumulated) is also a foreign asset that must be declared. Choose &lt;strong&gt;Table A2&lt;/strong&gt; for filing the details. For the closing balance, use the dollar balance as of 31st December and multiply with the TTBR on that day to find the amount in INR. Report details of deposits transferred into the account directly or through dividends. If we sold some units during the current year, please consider that too for peak and closing balance calculation.&lt;/p&gt;

&lt;p&gt;Even if the account has no balance, it’s good to declare it as such.&lt;/p&gt;

&lt;h1 id=&quot;schedule-foreign-source-income-fsi&quot;&gt;Schedule Foreign Source Income (FSI)&lt;/h1&gt;
&lt;p&gt;Unlike Schedule FA, all details here should be according to Financial Year in India, i.e., from April to March. Add details for any income received or receivable even if the money is yet to move to India. &lt;strong&gt;Also, do consider advance tax in mind&lt;/strong&gt;. If you don’t pay the taxes appropriately in the time frame of advance taxes, the advance tax penalty may also be levied.&lt;/p&gt;

&lt;h2 id=&quot;tax-treatment-of-dividends&quot;&gt;Tax treatment of dividends&lt;/h2&gt;
&lt;p&gt;Ordinarily, Indian dividends are subject to be taxed on the hands of the receiver based on his slab. The same applies to any foreign dividends received. However, the United States government already deducts 25% of the dividend as tax before distributing it. In essence, there could be a case of double taxation on the same income.&lt;/p&gt;

&lt;p&gt;The Indian and US governments signed the Double Taxation Avoidance Agreement (&lt;strong&gt;DTAA&lt;/strong&gt;) to help taxpayers with this issue. Effectively, we are still taxed the same in India. However, we request the Indian government to give us relief for the 25% already paid which is added as a credit in the final tax liability calculation.&lt;/p&gt;

&lt;p&gt;So effectively, if you are in the 30% slab, you still need to pay 5% more.&lt;/p&gt;

&lt;p&gt;Relevant fields here:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Income from outside India (included in Part B-Ti)&lt;/strong&gt;: Total dividend pre-tax calculated using TTBR of the last date of the previous month.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tax paid outside India&lt;/strong&gt;: 25% of the total dividend withheld.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tax payable on such income under normal provision in India&lt;/strong&gt;: Manually calculate and add the tax based on the slab.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Relevant article of DTAA if relief claimed u/s 90 or 90A&lt;/strong&gt;: 10, 25.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;stock-capital-gains&quot;&gt;Stock Capital Gains&lt;/h2&gt;
&lt;p&gt;For the stocks, the capital gains are the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(sell value in $ — buy value in $) * TTBR on the last date of the preceding month to the sell date&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;interest-on-broker-balance&quot;&gt;Interest on broker balance&lt;/h2&gt;
&lt;p&gt;Similarly, fill interest received on broker balance here.&lt;/p&gt;

&lt;h1 id=&quot;schedule-tax-relief-tr&quot;&gt;Schedule Tax Relief (TR)&lt;/h1&gt;
&lt;p&gt;Put the summary of tax relief claimed for taxes paid outside India here. Add the same relief amount (calculated above) again in this section.&lt;/p&gt;

&lt;p&gt;For the Tax Relief Claimed under section (specify 90, 90A or 91), for RSUs, stocks and dividends in the US add section 90.&lt;/p&gt;

&lt;h1 id=&quot;form-67&quot;&gt;Form 67&lt;/h1&gt;
&lt;p&gt;Form 67 is a statutory form used by resident taxpayers in India to claim credit for foreign tax paid outside India.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Add the exact details here as well. The numbers across Form 67, Schedule FSI and Schedule TR should match. It is also advised to submit form 67 before submitting the ITR.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As understandable, this section should also be filled according to the Indian financial year.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Proof is required&lt;/strong&gt; to be uploaded when submitting this form. We should get Form 1042-S from the broker for the dividends and interests. Form 1042-S is an information return filed by withholding agents to report amounts paid to foreign persons from the US. However, this document is only issued in the current year, January to December. (You can probably submit the broker statements for the period Jan to March)&lt;/p&gt;

&lt;h1 id=&quot;schedule-income-from-other-sources-os&quot;&gt;Schedule Income from other sources (OS)&lt;/h1&gt;
&lt;p&gt;This is the schedule for adding all the additional interest and dividends received from foreign shares during the financial year: April to June.&lt;/p&gt;

&lt;p&gt;Ideally, for all individual dividends received, you should convert the pre-tax amount to INR using TTBR of the last date of the immediately preceding month. Add the cumulative INR in the dividend section. You should give the division among various advanced tax periods for the dividend received.&lt;/p&gt;

&lt;p&gt;Do the same thing for interest on the broker balance and add it under the “Others” row in the interest section.&lt;/p&gt;

&lt;h1 id=&quot;schedule-capital-gains&quot;&gt;Schedule Capital Gains&lt;/h1&gt;
&lt;p&gt;All capital gains (including those relating to foreign assets) should be reported here. For foreign assets, taxation is a bit different.&lt;/p&gt;

&lt;h2 id=&quot;capital-gains-on-foreign-assets&quot;&gt;Capital gains on foreign assets&lt;/h2&gt;
&lt;p&gt;Any holding for more the 2 years (from vesting/ purchase date) qualifies for special tax treatment under long-term capital gains. These are taxed at 20% after indexation.&lt;/p&gt;

&lt;p&gt;Indexation means that you will only be taxed for the gains above inflation. So, if you sold your holding in 3 years making 50% profit, and assuming inflation to be 5% annually, the inflation will be 5 * 3 = 15% (well it is more than that as the number will be compounded). So, you actually pay only &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;20% of (50%–15%)&lt;/code&gt; as tax (plus cess and surcharge 🥲)&lt;/p&gt;

&lt;p&gt;The loss can also be adjusted with other profits as well (check the rules for that). Any charges directly linked to the transfer can also be claimed. Technically, the transfer of foreign currency-related charges should not be claimed under capital gains as it’s not linked to the transfer of assets. But it probably will not be questioned if we do.&lt;/p&gt;

&lt;p&gt;Divide the earnings into timeframes based on advanced tax periods similar to what we did in dividends.&lt;/p&gt;

&lt;hr /&gt;
&lt;p&gt;In addition, if your annual income exceeds 50 lakhs, you should also fill out Schedule Assets and Liabilities.&lt;/p&gt;

&lt;p&gt;Please comment below if you feel something is incorrect or if I missed something. This blog has been an effort to consolidate the data on the internet. I will be more than happy to modify the content.&lt;/p&gt;

&lt;h1 id=&quot;references&quot;&gt;References&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://indcdn.indmoney.com/public/images/itr_filling_video.mp4&quot;&gt;https://indcdn.indmoney.com/public/images/itr_filling_video.mp4&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://economictimes.indiatimes.com/wealth/tax/how-to-report-your-foreign-income-share-investment-while-filing-itr-form/articleshow/102070142.cms?source=post_page-----a98d77a5895e--------------------------------&quot;&gt;How to report your foreign income, share investment while filing ITR form?&lt;/a&gt;
    &lt;blockquote&gt;
      &lt;p&gt;Many individuals having investments in foreign shares, or having bank account in foreign country are required to report…&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://bemoneyaware.com/rsu-tax-perquisite-capital-gains/?source=post_page-----a98d77a5895e--------------------------------&quot;&gt;RSU of MNC, perquisite, tax, Capital gains, ITR&lt;/a&gt;
    &lt;blockquote&gt;
      &lt;p&gt;What are RSUs or Restricted Stock Units? What is vesting date? When are RSU taxed? What is the capital gain from…&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://medium.com/@chintanr97/e-filing-form-67-in-new-income-tax-portal-9449f1fa089c?source=post_page-----a98d77a5895e--------------------------------&quot;&gt;e-Filing Form 67 in New Income Tax Portal&lt;/a&gt;
    &lt;blockquote&gt;
      &lt;p&gt;DISCLAIMER: The following Medium Article is only for knowledge purpose and to allow taxpayers to gain more insight into…&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Jio vs TCP</title>
   <link href="https://dev-ritik.github.io/blog/2022/11/15/Jio-vs-TCP/"/>
   <updated>2022-11-15T00:00:00+00:00</updated>
   <id>https://dev-ritik.github.io/blog/2022/11/15/Jio-vs-TCP</id>
   <content type="html">&lt;p&gt;🚀 Diving into the Network Abyss: Unraveling Jio’s 64kbps Terminal Limit from a TCP Perspective 🌐💻&lt;/p&gt;

&lt;p&gt;Hold on to your virtual hats, tech enthusiasts! We’re about to embark on a journey that goes beyond the surface of India’s telecom giant, &lt;strong&gt;Reliance Jio&lt;/strong&gt;. We’re delving into the mysterious realm of Jio’s 64kbps terminal limit, not to dissect Jio but to understand the intricate dance it performs in the world of TCP.&lt;/p&gt;

&lt;p&gt;Sure, Jio is a &lt;a href=&quot;https://www.statista.com/statistics/258797/market-share-of-the-mobile-telecom-industry-in-india-by-company/&quot;&gt;behemoth&lt;/a&gt; in the telecom world, with its 5G plans and a game-changing impact on data costs that brought the nation online at lightning speed. But today, we’re not just talking about Jio; we’re on a mission to decode the enigma behind the 64kbps terminal limit, unravelling the threads that make TCP tick in this innovative landscape.&lt;/p&gt;

&lt;p&gt;Forget the usual chatter about DAU/MAU numbers; we’re here to explore the techy side of Jio’s prowess. So buckle up, tech explorers, as we venture into the heart of Jio’s network intricacies, where IPv6 adoption reigns supreme at a staggering 92.5%. Let’s push the boundaries of understanding and discover what makes Jio’s TCP perspective truly fascinating! 🚀🔍📡&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/max/720/1*F3PFKcgId4I1J7n2WhcqUw.png&quot; alt=&quot;&quot; /&gt;
&lt;!--break--&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;a href=&quot;https://stats.labs.apnic.net/ipv6/AS55836?a=55836&amp;amp;c=IN&amp;amp;x=1&amp;amp;s=0&amp;amp;p=0&amp;amp;w=30&amp;amp;s=1&quot;&gt;Src&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Transmission_Control_Protocol&quot;&gt;TCP&lt;/a&gt; is arguably the most used internet protocol for data movement from the user’s device to the cloud (HTTP/3 aside). At the moment, HTTP/3 adoption hasn’t been widespread. Even the support for that in Nginx hasn’t been merged.&lt;/p&gt;

&lt;p&gt;TCP is a reliable and connection-oriented protocol. It tries its best to get the data from one application on the internet to another. Being so important, it is supported by the whole public internet. TCP has essential features built into it. It takes care that the receiver can handle the data the sender will deliver. It also considers the network bandwidth in how it deals with congestion. During heavy load or artificial traffic shaping by on-route devices, TCP packets can be dropped. However, TCP employs various congestion protocols on either end of the connection to deal with them most efficiently while keeping the network congestion in mind. You can find more details &lt;a href=&quot;https://en.wikipedia.org/wiki/TCP_congestion_control&quot;&gt;here&lt;/a&gt;. The following experiment demonstrates TCP in action on a Jio ISP.&lt;/p&gt;

&lt;h1 id=&quot;the-experiment&quot;&gt;The Experiment&lt;/h1&gt;
&lt;p&gt;I have a target text file of 1.4 MB (14,45,257 bytes) on my remote server. I am fetching that file using &lt;a href=&quot;https://linux.die.net/man/1/scp&quot;&gt;SCP&lt;/a&gt; (which uses TCP at the transport layer).&lt;/p&gt;

&lt;p&gt;Jio continues to provide data at &lt;a href=&quot;https://www.jio.com/business/jio-4g-mobile-service#:~:text=Post%20100%25%20monthly%20data%20quota%20is%20exhausted%2C%20data%20services%20will%20continue%20at%20speeds%20up%20to%2064%20Kbps&quot;&gt;64Kbps&lt;/a&gt; speed after the unlimited daily usage.&lt;/p&gt;

&lt;p&gt;I am trying to Scp this file to and from the server post the daily usage at 64kbps. Note that 64Kbps is 8 KBps.&lt;/p&gt;

&lt;h1 id=&quot;results&quot;&gt;Results&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*p4eQlo2OEFFUQhYnS-vbWQ.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Time vs RTT for download test from the client&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;From the data above, the RTT usually is about 205 ms, which gives maximum in-flight bytes to be around 1640 bytes for that duration (barely more than the regular 1500 bytes limit for Ethernet frames)&lt;/p&gt;

&lt;p&gt;As expected, there will be packet drops somewhere.&lt;/p&gt;

&lt;p&gt;To understand the details below, do note that the server’s public IP is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;20.203.40.255&lt;/code&gt;, and the client’ Jio’s external IP is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;47.11.211.102&lt;/code&gt;. (&lt;em&gt;I don’t mind sharing these details! Go ahead!&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;From the server capture, just before the drops,&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*koN4TGecno5Sfjy7eJMF3A.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Server Packet logs&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;On receiving the ACKs from the client (number 1413), the server sends several data packets simultaneously (2782*5 in 1415–1418). This is the TCP congestion protocol in action, expanding the congestion window (&lt;a href=&quot;https://en.wikipedia.org/wiki/TCP_congestion_control#:~:text=In%20TCP%2C%20the%20congestion%20window,overloaded%20with%20too%20much%20traffic.&quot;&gt;CWND&lt;/a&gt;). &lt;em&gt;Notice that these individual packets are bigger than possible to pass undropped. However, the MTU for the immediate network on both ends is 1500 and looking at the jumps in the IP identity header, this is probably TCP sending more packets of at most MSS size because of the availability of a higher window&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;From the client side,&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*EPmb4fKiHHhFjEV0l5fK_g.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Client packet logs&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After sending the ACKs for earlier packets (49–50), we see that it is starting to receive those simultaneous packets. It sends an ACK on 56. And again on 59. Post that, there is no new packet till 3.21s (about 220ms). This indicates that some of the later simultaneously sent packets were dropped. It received packet 60 but not the immediate next ones it was expecting to receive. It sends an ACK back (61) acknowledging this packet but saying there was a packet in between that was not received. Subsequently, the server only sends single TCP frames with the client’s request packets.&lt;/p&gt;

&lt;p&gt;This is a duplicate ACK received as the 1428th packet for the server. Henceforth it sends the requested packet again. Notice that these duplicate ACK TCP packets would have dropped the server side CWND and hence must have slowed down in streaming the packets anticipating network congestion.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*EcfI9bijVawv2_NLhrRQSQ.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Server packet logs continued.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Notice the decrease of the bytes in flight. The server then only sends the requested packet segments (which Jio possibly has dropped).&lt;/p&gt;

&lt;p&gt;Post packet 1511, it started accelerating again (TCP congestion control at work) but stopped again at 1519.&lt;/p&gt;

&lt;p&gt;Checking the throughput on Wireshark. This is Jio not letting more than 64000bits pass in a second&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*EtUtz31fDwEGxaGlaDEIMA.png&quot; alt=&quot;&quot; /&gt;
Wireshark Window scaling graph:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*5GnRbZOflaQmvPyssU1BWA.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Server Packet capture TCP Window Scaling on Wireshark&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The green line representing the Receive window size stays around the initial negotiated 64128 throughout, while the blue line representing the bytes outstanding is forced to come down to MSS because that’s around what is possible to pass through at the permitted speeds.&lt;/p&gt;

&lt;p&gt;Interestingly, there is no ICMP packet recorded on either side notifying of packet drops in the network. It was all about duplicate TCP ACKs and TCP Out-of-Order packets and TCP Previous segment not being received.&lt;/p&gt;

&lt;p&gt;The upload traffic test results were similar.&lt;/p&gt;

&lt;p&gt;These cycles of increasing bytes in flight and retransmission drop occur continuously throughout the run. This is how TCP copes with packet drops on the network. This is TCP vs Jio in action.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Networking when you google</title>
   <link href="https://dev-ritik.github.io/blog/2022/05/16/Networking-when-you-google/"/>
   <updated>2022-05-16T00:00:00+00:00</updated>
   <id>https://dev-ritik.github.io/blog/2022/05/16/Networking-when-you-google</id>
   <content type="html">&lt;p&gt;I took a lecture aimed at explaining what happens when you google something. It was more like how a website is accessed from networking perspective. This lecture touches:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The Transport layer protocols
    &lt;ul&gt;
      &lt;li&gt;TCP&lt;/li&gt;
      &lt;li&gt;UDP&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Explains what happens when we search for a website on the browser
    &lt;ul&gt;
      &lt;li&gt;DNS&lt;/li&gt;
      &lt;li&gt;Packet exchange on the network&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Check this out &lt;a href=&quot;https://youtu.be/hB04NjDSqbk&quot;&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Realtime Results Livestream</title>
   <link href="https://dev-ritik.github.io/blog/2021/06/19/Realtime-Results-Livestream/"/>
   <updated>2021-06-19T00:00:00+00:00</updated>
   <id>https://dev-ritik.github.io/blog/2021/06/19/Realtime-Results-Livestream</id>
   <content type="html">&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/max/800/1*zZ1YTl0oQSK5ZGgOIB51Mw.png&quot; alt=&quot;&quot; /&gt;
Get ready for a quick tech thrill! Last month, we dove into a time-sensitive project for the West Bengal state elections - a 5+ hour YouTube Livestream featuring real-time data in a dazzling design. This blog spills the secrets behind the scenes, from coding marathons to unexpected triumphs. Fasten your seatbelts - it’s a tech spectacle you won’t want to miss! 💻🌐🎥&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Now, let’s get real. We had zero experience with a programmatically defined dynamic Livestream. None. Nada. Zilch. But hey, where’s the fun in sticking to the tried and tested?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;the-stream-design&quot;&gt;The Stream Design&lt;/h2&gt;
&lt;p&gt;I already had the idea to add a dynamically generated state map based on the party’s colour with a lead on the constituency. This is what we (I and &lt;a href=&quot;https://github.com/KarthikRIyer&quot;&gt;Karthik&lt;/a&gt;(&lt;a href=&quot;https://medium.com/u/ca54209c3d72?source=post_page-----e6d29add5e3d--------------------------------&quot;&gt;Karthik Iyer&lt;/a&gt;)) envisioned our final design to be:
&lt;!--break--&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;A state map dynamically generated. Maps for phases and district as well.&lt;/li&gt;
  &lt;li&gt;State-wise overall results of the 5 states on the poll&lt;/li&gt;
  &lt;li&gt;Constituency-wise leads. (Party-Coalition and candidate leads)&lt;/li&gt;
  &lt;li&gt;Comparison with the past result&lt;/li&gt;
  &lt;li&gt;Dot-semicircle pie chart (for visualizing majority)&lt;/li&gt;
  &lt;li&gt;Projected total seats&lt;/li&gt;
  &lt;li&gt;Notification panel (Recent flips in constituency leads)&lt;/li&gt;
  &lt;li&gt;Time, Name &amp;amp; Logo&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;~ Alas, we dropped some of these in favour of some of the important ones.&lt;/em&gt;&lt;/p&gt;

&lt;h1 id=&quot;the-pipeline-design&quot;&gt;The Pipeline Design&lt;/h1&gt;
&lt;p&gt;We designed individual components in this pipeline in parallel, using basic classes (to be subclassed later) in the backend. Every component was designed to reduce the coupling amongst them so that a crash on the scraping module (or even the backend in general) won’t affect the frontend logic. This was mainly done because of the uncertainty in the pipeline with respect to the scraper and the procured data. The main reason was that this script was to be developed on D-day only (for obvious reasons).&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:1100/format:webp/1*TaownoHSsOKDnYcU9JKxEQ.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Pipeline diagram&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Major components in the pipeline were:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Backend&lt;/strong&gt;: Actual scraping and database logic with map rendering logic exposed through Flask APIs&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Frontend&lt;/strong&gt;: React app with Material UI components for elegant and easy design.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Selenium Browser &amp;amp; pyvirtualdisplay&lt;/strong&gt;: A chrome instance with the frontend running in the background (to replace the need for a secondary display).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;OBS studio&lt;/strong&gt;: Tool to capture and stream the virtual display to YouTube.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This pipeline by design has got a number of resource-intensive services running. Henceforth, we focussed on reducing the back-end processing by always leveraging cached data for the API calls. We prefetched and stored all that we could, like candidate details, for example. We only scraped constituency-wise per candidate vote count on the go. The frontend periodically queries the backend to check for updates. And the backend independently updates the database and maps. A periodic refresh task triggered the scraper, which then updated the database’s state continuously. This essentially made the backend logic independent of the API calls.&lt;/p&gt;

&lt;p&gt;We developed events-based callbacks triggered by events, like when the leading candidate in a constituency changed or when the overall ranking changed.&lt;/p&gt;

&lt;h2 id=&quot;map-rendering&quot;&gt;Map Rendering&lt;/h2&gt;
&lt;p&gt;The map renderer registered itself with these callbacks, through which it received just the updates in data. We created metadata for rendering the maps beforehand. We were able to find a constituency level map of West Bengal in the MS Excel Map format through sheer luck. It contained all constituencies, paired with an integer value and a chart map highlighting individual constituencies based on these values. We wrote an &lt;strong&gt;Excel macro&lt;/strong&gt; that changed the value paired with each constituency, highlighted it yellow and took a screenshot. All automated. Generating metadata after this was simple. A simple python script that cropped the screenshots to the appropriate dimensions, found all the pixels coloured yellow and stored the pixel coordinates in a simple text file.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*Jd6Vbx_7uJWVGK0ndtdpPQ.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Map rendering individual constituency&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When the server starts, it loads all those pixel coordinates into an array. When the update callback is triggered, we fetch these coordinates only for those constituencies which actually changed and re-render just these pixels. We used &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Pillow&lt;/code&gt; to render the images. Once updated, the image is saved onto the filesystem. When the frontend requests for a map, it is fetched from that cached map from the filesystem. To ensure thread-safety for simultaneous read-update to the filesystem, we came up with this solution: to preload paths to all the map images in an array, use paths from this array while saving or reading an image use a thread lock on the path strings.&lt;/p&gt;

&lt;h2 id=&quot;results&quot;&gt;Results&lt;/h2&gt;
&lt;p&gt;All set and done, the live stream worked perfectly for more than 5 hours.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=AHXu84uznMc&quot;&gt;&lt;img src=&quot;https://img.youtube.com/vi/AHXu84uznMc/0.jpg&quot; alt=&quot;Youtube Livestream Url&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Running this heavy pipeline on a single device did take a toll on the performance. It was mostly around dropping frame rates, but it was unnoticeable on the stream for the most part. Below are the details for the environment running the pipeline:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Ubuntu 20.04 LTS Linux with 5.8.0 kernel on Predator Helios 300 with Intel corei7 9th gen processor, 16 GB RAM &amp;amp; 6 GB NVIDIA GeForce GTX 1660 Ti Graphics card.
Flask and React app was running on debug mode and OBS studio
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Before closing the stream, I recorded these system statistics.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The performance was getting increasingly poorer as we approached towards the end of the stream.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:1100/format:webp/1*CfY1AWJQgx2ckvGTzKEOyw.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;htop&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:1100/format:webp/1*dFlJL9OP25_5v2QwNKC8Pg.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;top&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*4evCODOrfxHjxlaMRZ8ixA.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;nvidia-smi&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Note that&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The backend was running through the Pycharm’s terminal.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python display.py&lt;/code&gt; is the process running &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pyvirtualdisplay&lt;/code&gt; + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;selenium process&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Google-Chrome was also running parallel.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Other processes are rather self-explanatory and/or mostly comes preinstalled with standard Ubuntu desktop installation.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>I scanned all my broadband peers</title>
   <link href="https://dev-ritik.github.io/blog/2021/04/22/Broadband-Scan/"/>
   <updated>2021-04-22T00:00:00+00:00</updated>
   <id>https://dev-ritik.github.io/blog/2021/04/22/Broadband-Scan</id>
   <content type="html">&lt;blockquote&gt;
  &lt;p&gt;Hold onto your internet connection because things are about to get interesting! I recently went on a scanning spree, unveiling the mysteries of my broadband peers and the results? Mind-blowing! 📡🔍 Ready to dive into the fascinating world of broadband revelations? Let’s roll! 🚀💻&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;My internet broadband provider is one of the popular Internet service providers in this region. I have been their customer for quite some time now. Though comments and reviews may point otherwise, I am satisfied by their service in my region with close to promised speeds mostly.&lt;/p&gt;

&lt;p&gt;They use NAT and provide static IPs under the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;10.0.0.0/8&lt;/code&gt; private block, and if I am not wrong, this same subdomain is used in West Bengal’s operational area. As of this moment, they don’t block any cross-customer communication. This makes it possible to scan the entire network. And as I have mentioned later, this may be a security concern.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://github.com/robertdavidgraham/masscan&quot;&gt;masscan&lt;/a&gt; configuration used for the scan was:
&lt;!--break--&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;masscan 10.0.0.0/8 -p80,23,443,21,22,25,3389,110,445,139,143,53,135,3306,8080,1723,111,995,993,5900,1025,587,8888,199,1720,465,548,113,81,6001,10000,514 -Pn -n - rate=1000 -oL 10.masscan&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This ensures the following:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Masscan helps find open IP:Port pairs faster&lt;/li&gt;
  &lt;li&gt;Scan the top few TCP ports (32 in this case)&lt;/li&gt;
  &lt;li&gt;Keep the scan slow, so it doesn’t cause any network issues, and I don’t wake up anyone at the ISP.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below, I have mentioned some interesting facts on this scan and related work.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Out of the ports mentioned, the distribution of count vs port number was&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Port count
80   194
443  138
22   75
23   59
8888 15
8080 10
135  9
81   3
5900 2
3389 1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;(excluding port 25 &amp;amp; 53)&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A lot of routers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*lKVNJkZxGziy0kPfhkMNng.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*Ms1sFu-Cvq6tJlXWs6CyvQ.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*LTUOPojn-0IroqReEznkvQ.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*2oUvMp38wmzO175WujqEJQ.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*bwoSMYwcE5bJOkrLAaJ4Ng.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*b1mwuyprHkGgbbXQHSuONw.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*8nngEOsTFppYSK-JGO2N8w.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*KYOrNvFj7IPeFxi7tkvyCQ.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*_dXFmJh3aPgSuBCBWP2PJA.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*WRO1tMWPDn2S38j8WIQq4Q.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*MW67GKdyGqVjqad2ZglpGg.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Quite fewer Ip cameras
&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*00OA_Dfp9_kYxnHNXzePfA.png&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*JtSha8HpXoWq5vl41thDew.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*cBv18EJdKZG7fyhqOYX6aQ.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;And other login pages of things I don’t know about
&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*GOwkn579V57y9izL_kBpZg.png&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*6LIcMNYknV_uL07ST94idA.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*FION4T1p8quaaTO58qIRuA.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;takeaways&quot;&gt;Takeaways&lt;/h2&gt;
&lt;p&gt;Vendors providing these routers &amp;amp; IP cameras should prompt the users to change the default password upon 1st login. A good number of people never care to change the default passwords of these devices after working installation. At the same time, default settings for these devices should restrict access to a select few IPs to prevent unauthorized access over the WAN.&lt;/p&gt;

&lt;p&gt;IP cameras should particularly actively provide patches to discovered vulnerabilities and prompt users to update their devices for the same. These vulnerabilities are regularly detected and patched, but it does take time for these consumer devices to get patched.&lt;/p&gt;

&lt;p&gt;Network operators should actively block cross-customer communication because consumers usually don’t care or don’t have the knowledge to be safe against it. Therefore some responsibility should be borned by the ISPs.&lt;/p&gt;

&lt;h2 id=&quot;actions&quot;&gt;Actions&lt;/h2&gt;
&lt;p&gt;I have raised a service ticket and mailed them explaining the issue. The support representative has promised to forward this to the senior authority.&lt;/p&gt;

&lt;h2 id=&quot;inspiration&quot;&gt;Inspiration&lt;/h2&gt;
&lt;p&gt;The following blog by &lt;a href=&quot;https://captnemo.in/&quot;&gt;captnemo&lt;/a&gt; was the inspiration for this blog:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://medium.com/@captn3m0/i-scanned-all-of-act-bangalore-customers-and-the-results-arent-surprising-fecf9d7fe775?source=post_page-----17febead6797--------------------------------&quot;&gt;I scanned all of ACT Bangalore customers, and the results aren’t surprising&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;I scanned all of ACT Bangalore customers, and the results aren’t surprising&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>DNS and Privacy</title>
   <link href="https://dev-ritik.github.io/blog/2021/02/15/DNS-and-Privacy/"/>
   <updated>2021-02-15T00:00:00+00:00</updated>
   <id>https://dev-ritik.github.io/blog/2021/02/15/DNS-and-Privacy</id>
   <content type="html">&lt;blockquote&gt;
  &lt;p&gt;Ever felt like your internet journey is a little too exposed? As you surf anonymously, websites slyly snatch your public IP address, and your ISP lurks, peering into your every click. It’s the perfect stage for unwanted surveillance, with the potential to tweak your routing behaviour and block access to your favourite sites. Enter the unsung hero: DNS.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this blog, we’re delving into the world of online invisibility. I’ll spill the beans on the latest tech tricks that can cloak your browsing habits from the prying eyes of ISPs, with a special focus on the wizardry of DNS. Ready to discover the secrets to a more private online experience? Let’s dive in!🚀🔍&lt;/p&gt;

&lt;h2 id=&quot;domain-name-system&quot;&gt;Domain Name System&lt;/h2&gt;
&lt;p&gt;DNS is the phonebook of the Internet. It’s a global database of information about domain names. In simple terms, it helps convert &lt;code class=&quot;markup--code markup--p-code&quot;&gt;medium.com&lt;/code&gt; into &lt;code class=&quot;markup--code markup--p-code&quot;&gt;104.17.31.52&lt;/code&gt; which computer networks actually understands and can route your request to.
&lt;!--break--&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*9JgtMCfm7996JW0Plqo8kg.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;a href=&quot;https://hacks.mozilla.org/2018/05/a-cartoon-intro-to-dns-over-https/&quot;&gt;Source&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A simple &lt;a href=&quot;https://en.wikipedia.org/wiki/Fully_qualified_domain_name&quot;&gt;fully qualified domain name&lt;/a&gt; looks like &lt;em&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;en.wikipedia.org.&lt;/code&gt;&lt;/em&gt;. DNS follows a hierarchical structure. A dot separates each level. At the top of this structure is the root servers which specifies details about these top-level domains (TLDs) for example, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;org&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;com&lt;/code&gt;. These also act as the trust anchors (as explained later) and the first level while querying DNS records. More on querying can be found &lt;a href=&quot;https://www.cloudflare.com/learning/dns/what-is-dns/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:520/format:webp/1*xtH12w1ZbWTuwU9zmSbQrw.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Dig: DNS lookup tool in Linux&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A&lt;/code&gt; is the most basic type of DNS record which contains IP addresses to which this domain should point to. There are a few other records too for other purposes. These records have a Time to Live &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TTL&lt;/code&gt; field associated with them describing how long to cache them before requesting a new one. Caching would improve response time for the subsequent queries and reduce load over DNS servers.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*1OP-hXfBbRXWTEjIVyKH8g.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For the uncached plain text query to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;8.8.8.8&lt;/code&gt; for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;medium.com&lt;/code&gt;, Wireshark recorded round trip time (RTT) of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;62.43 ms&lt;/code&gt; and chrome recorded &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;62.72 ms&lt;/code&gt;. That’s 4.8% of basic page load time. Subsequent queries were cached by chrome itself to reduce load time.&lt;/p&gt;

&lt;p&gt;DNS generally works on UDP over port 53. TCP over the same port can also be used, but UDP is the prime choice. UDP, if you know, is unreliable but it is fast. For a simple query, where TCP establishes a connection using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3-way handshake&lt;/code&gt; before the actual query, UDP could complete it in a single round trip. (DNS query is the first thing your browser does when visiting a website). Use of TCP also needs more resources on both sides and more header data compared to UDP.&lt;/p&gt;

&lt;p&gt;DNS clients generally switch to TCP when the DNS payload is more than 512 bytes. It may continue on UDP if the devices and the network supports larger DNS packets over UDP. The 512-byte UDP payload size is a dependency on IPv4. From &lt;a href=&quot;https://tools.ietf.org/html/rfc791#section-3.1&quot;&gt;RFC&lt;/a&gt;,&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;All hosts must be prepared to accept datagrams of up to 576 octets (whether they arrive whole or in fragments). It is recommended that hosts only send datagrams larger than 576 octets if they have assurance that the destination is prepared to accept the larger datagrams.&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;The number 576 is selected to allow a reasonable sized data block to be transmitted in addition to the required header information. For example, this size allows a data block of 512 octets plus 64 header octets to fit in a datagram. The maximal internet header is 60 octets, and a typical internet header is 20 octets, allowing a margin for headers of higher level protocols.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is why there are precisely 13 DNS root servers originally: 13 domain names and 13 IPv4 addresses fit nicely into a single UDP packet.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*dij5N9aw_iEAo9Jd3SJgkA.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;A plaintext UDP DNS response for medium.com&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The original DNS did not include any security details; instead, it was designed to be a scalable distributed key-value system. As you know, DNS query and response are transferred as plain text UDP packets and are susceptible to be forged and manipulated while on the wire. There were no checks on the authenticity of the data in the original implementation. Users could be easily redirected to a fake website using DNS spoofing.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*Nnw-IBHEwSty7HWdaTnJLw.jpeg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;DNS Spoofing &lt;a href=&quot;https://www.imperva.com/learn/application-security/dnssec/&quot;&gt;Source&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Keeping in mind how easy it is to manipulate and spy on DNS data, certain extensions and improvements have been specified and used. Some of them are:&lt;/p&gt;

&lt;h2 id=&quot;dns-security-extensions-dnssec&quot;&gt;DNS Security Extensions (DNSSEC)&lt;/h2&gt;
&lt;p&gt;The &lt;strong&gt;DNS Security Extensions&lt;/strong&gt; (DNSSEC) is specifications for securing the DNS data. It provides data integrity and authentication to security-aware resolvers and applications through cryptographic digital signatures while ensuring backward compatibility with insecure DNS. These digital signatures are included in those resource records. DNSSEC &lt;em&gt;does not&lt;/em&gt; provide data confidentiality; in particular, all DNSSEC responses are authenticated but not encrypted.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*6Rmb0oyGVV9YWH-hDRhC7w.jpeg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;DNS Validation &lt;a href=&quot;https://www.imperva.com/learn/application-security/dnssec/&quot;&gt;Source&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;DNSSEC creates a parent-child train of trust that travels all the way up to the root server. The root keeps the hash of DNSKEY for the authoritative top-level domain (e.g., &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.com&lt;/code&gt;) nameservers (in the DS record). These (e.g., &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.com&lt;/code&gt;) TLDs keep hash for DNSKEY for their subdomains (e.g., example.com). All the record sets are signed by their own DNSKEY and stored as a new record at each level. This is a lot like the chain of trust used to validate TLS/SSL certificates, except that, rather than many trusted root certificates; there is one trusted root key managed by the DNS root maintainer IANA.&lt;/p&gt;

&lt;p&gt;Formally published in 2005, it is still far from mainstream adoption - one of the reasons is network operators who prefer stability to complexity (for a good reason).&lt;/p&gt;

&lt;h2 id=&quot;dns-over-tls-dot&quot;&gt;DNS over TLS (DoT)&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*KelkcD1CPEFp_6afwwaOWA.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;a href=&quot;https://www.cloudflare.com/learning/dns/dns-over-tls/&quot;&gt;Source&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;DNS over TLS, or DoT, is described in &lt;a href=&quot;https://tools.ietf.org/html/rfc7858&quot;&gt;RFC 7858&lt;/a&gt;. The protocol uses port 853 (though port can depend on the implementation). It is based on TLS (also known as SSL). This is a standard to encrypt the communication between the user’s device and the DNS resolver. To an external device, only the targetted resolver will be known. This prevents spoofing and tracking of the DNS messages.&lt;/p&gt;

&lt;p&gt;DNS over TLS incurs additional latency at session startup. It also requires an additional state (memory) and increased processing (CPU). Compared to UDP, it requires an extra RTT of latency to establish a TCP connection. The TLS handshake adds another two RTTs of latency. Clients and servers should support connection &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keepalive&lt;/code&gt; (reuse) and out-of-order processing to amortize connection setup costs.&lt;/p&gt;

&lt;h2 id=&quot;dns-over-https-doh&quot;&gt;DNS over HTTPS (DoH)&lt;/h2&gt;
&lt;p&gt;DNS over HTTPS, or DoH, is described in &lt;a href=&quot;https://tools.ietf.org/html/rfc8484&quot;&gt;RFC 8484&lt;/a&gt;. The protocol uses the standard HTTPS port 443, thus making DNS traffic have the same semantics with regular Web HTTPS traffic from web browsers, for the external world. It is also based on TLS (as it is based on HTTPS), thus making things similar to DoT.&lt;/p&gt;

&lt;p&gt;Based on HTTP, the DNS request-response is replaced with HTTP request-response messages over &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GET&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;POST&lt;/code&gt; method. Templates can be defined for making these requests and responses, and the standard status codes can have similar meanings.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://medium.com/mobile-development-group/http-websockets-9c6704e44a2a&quot;&gt;HTTP/2&lt;/a&gt; is the minimum recommended version of HTTP for use with DoH. The messages in classic UDP-based DNS are inherently unordered and have low overhead. A competitive HTTP transport needs to support reordering, parallelism, priority, and header compression to achieve similar performance. Those features were introduced to HTTP in HTTP/2. Earlier versions of HTTP can convey the semantic requirements of DoH but may result in inferior performance. Even other HTTP/2 features like Server push is supported.&lt;/p&gt;

&lt;p&gt;DoT and DoH are very similar. But there a debate on what is better.&lt;/p&gt;

&lt;p&gt;From a network security standpoint, DoT is arguably better. It gives network administrators the ability to monitor and block DNS queries, based on port, which is important for identifying and stopping malicious traffic.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.dnsfilter.com/blog/dns-over-tls/&quot;&gt;DoH&lt;/a&gt; is applied at the application layer. In contrast, DoT is applied directly at the transport layer. As such, DoH wrt DoT has.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;More coding required&lt;/li&gt;
  &lt;li&gt;More libraries required&lt;/li&gt;
  &lt;li&gt;Packet sizes are more extensive than DoT.&lt;/li&gt;
  &lt;li&gt;Ever-so-slightly higher latency&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Neither DoT nor DoH is perfect DNS encryption solutions at this moment. More work still needs to be done, like enabling 0-RTT for all DNS-over-TLS and DNS-over-HTTPS implementations.&lt;/p&gt;

&lt;p&gt;There have been more number of DoT deployments than DoH. Support for DoT has been added to Android since Android Pie. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;systemd-resolved&lt;/code&gt; in Linux already has an option to &lt;a href=&quot;https://fedoramagazine.org/use-dns-over-tls/&quot;&gt;turn this on&lt;/a&gt;. Recently, Firefox has added an option to use DoH with its browser. Chrome has been catching up too. For browsers, it is easier to use DoH as they are already handling HTTPS traffic. Google and Cloudflare have provided their open DoH resolvers.&lt;/p&gt;

&lt;p&gt;Below is a beautiful and detailed explanation of encrypted DNS:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;a href=&quot;hacks.mozilla.org&quot;&gt;A cartoon intro to DNS over HTTPS - Mozilla Hacks - the Web developer blog&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;dns-sinkhole-and-pi-hole&quot;&gt;DNS sinkhole and Pi-hole&lt;/h2&gt;
&lt;p&gt;A sinkhole is a DNS provider that can provide a false result for particular DNS queries. This may be because of a compromised server or server being configured to block access to specific domains (for parental control, advertisement filtering, or preventing botnet attacks).&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*V4fPgKcewp6sOVCjLIe1AQ.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Pi-hole logo&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href=&quot;https://pi-hole.net/&quot;&gt;Pi-Hole&lt;/a&gt; is an excellent, free, and open-sourced DNS-Sinkhole with support on major platforms (from Pi as in &lt;em&gt;raspberry pi&lt;/em&gt; and hole in &lt;em&gt;DNS-Sinkhole&lt;/em&gt;). It comes with a standard list of websites (&lt;em&gt;including google analytics!&lt;/em&gt;) to block, to prevent DNS queries to harmful and unwanted domains, and block 3rd party advertisements, all together saving bandwidth. It has a pretty web interface for configuration. Domains can easily be added or removed from the blocklist. It provided faster DNS queries by optimizing DNS caching with respect to native DNS implementations. It comes with a configurable DHCP server to automatically allocate DNS servers to the clients. It can easily be installed on a home or corporate network.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*9rfjj7LDlseoQ7zbWWTMJQ.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Pi-hole admin panel&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As evident from this image, 21.5% of all my traffic was blocked (primarily advertisements).&lt;/p&gt;

&lt;p&gt;Check out my image for a container for Pi-hole based DNS Sinkhole with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cloudflared&lt;/code&gt; DoH setup. It has a handy bash function too.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/dev-ritik/Pihole-Docker?source=post_page-----d50c59428cb2--------------------------------&quot;&gt;dev-ritik/Pihole-Docker&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;This repo has the Docker environment for Pihole (DNS sinkhole and DHCP Server) + Cloudflared (DNS over HTTPS proxy). I…&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*J1FXVQX3c1seSLCdAk7OTQ.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For a locally uncached DNS request for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;medium.com&lt;/code&gt; in this setup, Wireshark recorded RTT of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;91.47 ms&lt;/code&gt; and Chrome recorded &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;91.85 ms&lt;/code&gt;. That’s 9.1% of basic page load time and a 46.4% increase in DNS query time in DNS over HTTPS with Pi-hole (as expected).&lt;/p&gt;

&lt;p&gt;At the same time, when the results were cached by Pi-hole locally (and not by Chrome),&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*pwfxRqjux2zXJmaZRCHIHw.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;it had an RTT of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.145 ms&lt;/code&gt; in Wireshark and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.39 ms&lt;/code&gt; on Chrome. This makes sense for having a DNS resolver on the local network.&lt;/p&gt;

&lt;h3 id=&quot;plain-text-server-name-indication&quot;&gt;Plain Text Server Name Indication&lt;/h3&gt;
&lt;p&gt;With the setup above, one can be sure that no on-path device can detect what website someone is visiting based on the DNS traffic. There are still few other exploitable methods to find that out. The easiest of them will be the &lt;strong&gt;Server Name Indication (SNI)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A web server can host multiple ‘virtual’ servers on a single IP. These servers may belong to different DNS domains. Reverse proxy technologies like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Nginx&lt;/code&gt; may be used to distribute incoming traffic to an appropriate server based on the domain it contains. This would be easy in the case of HTTP traffic (as it contains the requested domain in the URL), but for encrypted HTTPS traffic, things are quite different.&lt;/p&gt;

&lt;p&gt;TLS Handshake is performed before the actual HTTP(S) communication. For this, the client needs to validate the server’s certificate to establish trust (explained &lt;a href=&quot;https://medium.com/mobile-development-group/trust-tls-ssl-and-https-b925ac9d59&quot;&gt;here&lt;/a&gt;). In a TLS handshake, the server can send a common certificate of all the virtual hosted domains to the client, generating the session key if the requested domain was within the certificate. But this is not a scalable approach. The more widely used technique is where the client will specify what virtual domain it wants to talk to, with the request.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*rVS5rU_zP20In8DrwyAxpQ.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Client Hello (for example.com)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is sent in the &lt;a href=&quot;https://tools.ietf.org/html/rfc3546#section-3.1&quot;&gt;Server Name Indication&lt;/a&gt; field in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Client Hello&lt;/code&gt;. As you can see, the server name is sent in plain text and can easily be used to spy on a device. Anyone between you and the server can see this field. This is the first message of the TLS Handshake; hence, no key has been agreed upon yet to encrypt this field.&lt;/p&gt;

&lt;p&gt;One approach to encrypt this field is by encrypting Client Hello. &lt;strong&gt;Encrypted Server Name Indication&lt;/strong&gt;(ESNI) works by adding a Public Key to the DNS records. A client can easily fetch this key (while querying for the IP address) and use this to encrypt the SNI field. Since only the server will have the corresponding private key, only it can get the original field and no one else.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*Usrzr67aRRa3BNkQJik5dA.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Certificate as plaintext in TLS v1.1 Server Hello&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is added as an extension to TLS v1.3. &lt;em&gt;Older versions of TLS even expose the server’s certificates, so set the minimum acceptable version to v1.3&lt;/em&gt;. Details of this can be found &lt;a href=&quot;https://datatracker.ietf.org/doc/draft-ietf-tls-esni/?include_text=1&quot;&gt;here&lt;/a&gt;. As of now, there are very few deployments of ESNI. You can enable this feature in the configs (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;about:config&lt;/code&gt;) in Firefox. Check out this website and find out how secure are you against anyone spying on your online activity.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;www.cloudflare.com&quot;&gt;Cloudflare ESNI Checker | Cloudflare&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;When you browse websites, there are several points where your privacy could be compromised, such as by your ISP or the…&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Firefox v85 has recently stopped supporting ESNI towards an improved &lt;strong&gt;Encrypted Client Hello&lt;/strong&gt; (ECH) TLS extension. The basic idea is to encrypt the entire client rather than just the SNI field (Client Hello does contain other sensitive information). This would still be supported using DNS by adding keys and other metadata to DNS records. The draft RFC explains its working as&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;When a client wants to establish a TLS session with the backend server, it constructs its ClientHello as usual (we will refer to this as the ClientHelloInner message) and then encrypts this message using the public key of the ECH configuration.  It then constructs a new ClientHello (ClientHelloOuter) with innocuous values for sensitive extensions, e.g., SNI, ALPN, etc., and with an “encrypted_client_hello” extension, which this document defines. The extension’s payload carries the encrypted ClientHelloInner and specifies the ECH configuration used for encryption. Finally, it sends ClientHelloOuter to the server.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The backend server (for example, Cloudflare) could be serving multiple domains. It acts as a relay decrypting the Client Hello and forwarding that to the original server. Cloudflare has put up a really nice &lt;a href=&quot;https://blog.cloudflare.com/encrypted-client-hello/&quot;&gt;blog post&lt;/a&gt; on this.&lt;/p&gt;

&lt;p&gt;As Firefox explains &lt;a href=&quot;https://blog.mozilla.org/security/2021/01/07/encrypted-client-hello-the-future-of-esni-in-firefox/&quot;&gt;here&lt;/a&gt;, they have dropped the support for ESNI, and the support for ECH is under active development. As such, for now, downgrading Firefox to &lt;a href=&quot;https://www.mozilla.org/en-US/firefox/enterprise/&quot;&gt;Extended Support Release&lt;/a&gt; v78.7.1esr seems to be a good option.&lt;/p&gt;

&lt;p&gt;Even now, anyone can guess what website you are visiting based on the IP address of the server you are visiting. In most cases, results would be quite accurate as well. Fortunately, as more and more websites are hosted on services like Cloudflare, they share common IP addresses. This will then become more difficult to find out. For any other cases, it’s best to route your traffic through some other servers by using a VPN or using a Tor browser.&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>Network Access Control</title>
   <link href="https://dev-ritik.github.io/blog/2020/12/13/Network-Access-Control/"/>
   <updated>2020-12-13T00:00:00+00:00</updated>
   <id>https://dev-ritik.github.io/blog/2020/12/13/Network-Access-Control</id>
   <content type="html">&lt;blockquote&gt;
  &lt;p&gt;Dive into my &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CSN-502 presentation&lt;/code&gt; delivered on 31.10.2020, where we unravel the intricacies of Network Access Control, with a special focus on Wireless Protocols. If you’re keen to delve deeper, check out the references for more details. This serves as your quick intro to the topic; the ppt is attached below. 🚀💻&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;network-access-control&quot;&gt;Network Access Control&lt;/h2&gt;
&lt;p&gt;You must have heard that open and coffee shop wifis are insecure, and one must proceed with cautions. Now think about large corporates or campus networks. There’s a ton of stuff involved here which are private within the network and must be protected via access control and prevented from eavesdropping. Remember, a network is not just used for connecting to the internet. A single malicious device or some malicious programs in some innocent device can bring massive troubles to the network providers. All other stuff related to secure access management applies here as well.&lt;/p&gt;

&lt;p&gt;So broadly, it is the job of the Network Access Control System to proactively detect and authorize the devices and put certain access control in place. It should also provide a mechanism to deal with malicious programs and actors acting with bad faith from within or outside the network.
&lt;!--break--&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://1drv.ms/p/s!AnYk3B0CuVyGlg23VpXu-qX6eWtG?e=BtjrAL&amp;amp;source=post_page-----6e3b27b00830--------------------------------&quot;&gt;Network Access Control ppt&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Broadly any general NAC system should have at least these &lt;strong&gt;functionalities&lt;/strong&gt;:
&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*pzUn_9OvCGXoyjvgrR4pmg.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Node Detection&lt;/strong&gt;: This indeed is the first step to find out if there’s a new device connected to the network. The system can detect the traffic from protocols like ARP, which are essential when registering in a network or from explicit NAC register messages.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Authentication&lt;/strong&gt;: Authenticating the device or the user trying to access the network.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Assessment&lt;/strong&gt;: A secure network must assess a device before giving it access to the system’s resources for potential threats.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Authorization&lt;/strong&gt;: NAC must use some policy to provide the user with access to the network’s resources based on the user’s/device’s identification and assessment.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quarantine&lt;/strong&gt;: NAC can isolate non-compliant devices into a separate network where it doesn’t possess a threat to the network and can still access specific safe resources.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Remediation&lt;/strong&gt;: Quarantined devices should be allowed to join or get access to system resources upon undergoing remedies like downloading security patches or firewall setup.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Monitor&lt;/strong&gt;: The devices admitted to the network should be continuously monitored for some policy violation upon which it can be Quarantined, or the access can be dropped and actions can be taken.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An NAC sysem generally has these components:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Client&lt;/strong&gt;: These are the devices trying to access the network. These are of 2 types: &lt;strong&gt;Agent-based Client&lt;/strong&gt;, where an agent (a software) is already installed on the client. This client then communicates with the policy servers to make the client compliant with network security parameters like installing anti-virus software. &lt;strong&gt;Agent-less Clients&lt;/strong&gt; are made to install an agent for joining the network. If it cannot, its traffic is monitored for threat management.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Enforcement Points&lt;/strong&gt;: These are points in the network where action can be taken for a device. These are generally the points with which the client communicates to access the network. Example: Switches, Routers, VPN.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Policy Servers&lt;/strong&gt;: As the name suggests, these servers are responsible for policy enforcements like Access, Authorization, and Accounting. These servers are responsible for collecting assessment data and ensuring compliance.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quarantine Network&lt;/strong&gt;: This is a network (as defined earlier) for the non-compliant devices. They are allowed limited or no access to network resources and remediation servers.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Remediation Servers&lt;/strong&gt;: These servers are responsible for checking Quarantined devices for their compliances with network standards. These can provide with required security software to those devices for the purpose.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;extensible-authentication-protocol&quot;&gt;Extensible Authentication Protocol&lt;/h2&gt;
&lt;p&gt;EAP (RFC &lt;a href=&quot;https://tools.ietf.org/html/rfc3748&quot;&gt;3748&lt;/a&gt;, &lt;a href=&quot;https://tools.ietf.org/html/rfc5247&quot;&gt;5247&lt;/a&gt;) is an authentication framework, not a specific authentication mechanism, used in network and internet connection for providing the transport and negotiation of authentication methods via &lt;strong&gt;EAP methods&lt;/strong&gt;. EAP typically runs directly over data link layers without requiring IP. EAP is not a wire protocol; instead, it only defines the information from the interface and the formats. Each protocol that uses EAP defines a way to encapsulate by the user EAP messages within that protocol’s messages. It has been applied to a wide variety of networks and protocols like wired networks &lt;a href=&quot;https://tools.ietf.org/html/rfc5247#ref-IEEE-802.1X&quot;&gt;IEEE-802.1X&lt;/a&gt;, Internet Key Exchange Protocol version 2 (IKEv2) &lt;a href=&quot;https://tools.ietf.org/html/rfc4306&quot;&gt;RFC4306&lt;/a&gt;, and wireless networks such as [IEEE-802.11] and &lt;a href=&quot;https://tools.ietf.org/html/rfc5247#ref-IEEE-802.16e&quot;&gt;IEEE-802.16e&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;EAP defines 4 (generally 3) entities for authenticating a device. Some of these entities can be and are usually handled by the same device in a setup. These are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Supplicant&lt;/strong&gt;: This refers to the device seeking admission into the network.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Authenticator&lt;/strong&gt;: The entity which relays and initiates EAP authentication. It may not know specifics of the actual wire protocol used.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Authentication Server&lt;/strong&gt;: This is the place where the actual authentication takes place.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;EAP server&lt;/strong&gt;: Its job is to exchange EAP messages with the supplicant via authenticator. The authentication server then uses these messages. It is often handled by other entities.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;eap-authentication-process&quot;&gt;EAP Authentication Process&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*743swMTQM7eY9fQIR8qAPA.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;This image describes EAP over LAN (802.1X)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
  &lt;li&gt;The &lt;strong&gt;authenticator&lt;/strong&gt; sends a Request to authenticate the peer (code 1). The Request has a &lt;strong&gt;Type field&lt;/strong&gt; to indicate what is being requested.&lt;/li&gt;
  &lt;li&gt;The peer sends a Response packet (code 2) in reply to a valid Request. As with the Request packet, the Response packet contains a Type field, which corresponds to the Type field of the Request.&lt;/li&gt;
  &lt;li&gt;The authenticator sends an additional Request packet, and the peer replies with a Response. The sequence of Requests and Responses continues as long as needed.&lt;/li&gt;
  &lt;li&gt;The conversation continues until the authenticator cannot authenticate the peer in which case the authenticator implementation MUST transmit an &lt;strong&gt;EAP Failure&lt;/strong&gt; (Code 4). Alternatively, the authentication conversation can continue until the authenticator determines that successful authentication has occurred, in which case the authenticator MUST transmit an &lt;strong&gt;EAP Success&lt;/strong&gt; (Code 3).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;security-claims&quot;&gt;Security Claims&lt;/h2&gt;
&lt;p&gt;EAP is used in wireless and wired LANs. In these situations, an attacker can gain access to links over which EAP packets are transmitted. As an example, one can easily detect all the traffic going in a wireless network without even authenticating into the network. As such, there are several security concerns which EAP defines and the EAP methods should take care of. These can be found &lt;a href=&quot;https://tools.ietf.org/html/rfc3748#section-7.2.1&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;eap-methods-example&quot;&gt;EAP Methods Example&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;EAP-MD5&lt;/strong&gt;: Here, the server sends a random challenge to the client. The client forms an MD5 hash of the user’s password and the challenge and sends the result back to the server. The server then validates the MD5 hash using the known correct plaintext password from the user database. Hence, It offers minimal security, is vulnerable to dictionary attacks, it only provides authentication of the EAP peer to the EAP server but not mutual authentication, hence is vulnerable to MITM.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;EAP-TLS&lt;/strong&gt;: Transport Layer Security (TLS) provides for mutual authentication, integrity-protected cipher suite negotiation, and key exchange between two endpoints. EAP-TLS is still considered one of the most secure EAP standards available. This has also been used in NoAuth cases where only server authentication is done. This would allow for situations, much like HTTPS, where a wireless hotspot allows free access and does not authenticate clients. Still, clients wish to use encryption and potentially authenticate the wireless hotspot. With a client-side certificate, however, a compromised password is not enough to break into EAP-TLS enabled systems because the intruder still needs to have the client-side certificate.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;EAP-PSK&lt;/strong&gt;: EAP method for mutual authentication and session key derivation using a &lt;strong&gt;Pre-Shared Key&lt;/strong&gt; (PSK). The Pre-Shared Key refers to a key or secret that needs to be derived and shared by the parties by some mechanism before the EAP-PSK conversation takes place (Take this as a simple passphrase). EAP-PSK is designed for authentication over insecure networks such as &lt;strong&gt;IEEE 802.11&lt;/strong&gt;(standards for Wireless LAN (WLAN) &amp;amp; Mesh (Wi-Fi certification)). EAP-PSK is distinct from the Pre-shared Key authentication mode used in &lt;strong&gt;Wi-Fi Protected Access&lt;/strong&gt;(WPA) and should not be confused with it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;implementations&quot;&gt;Implementations&lt;/h1&gt;
&lt;h2 id=&quot;wi-fi-wireless-fidelity-history&quot;&gt;Wi-Fi (Wireless Fidelity) History&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Wired Equivalent Privacy&lt;/strong&gt; (WEP) is a security algorithm for IEEE 802.11 wireless networks. Introduced as part of the original 802.11 standard ratified in 1997, its intention was to provide data &lt;strong&gt;confidentiality comparable&lt;/strong&gt; to that of a traditional &lt;strong&gt;wired&lt;/strong&gt; network.&lt;/p&gt;

&lt;p&gt;Later, to address WEP security issues, the &lt;strong&gt;802.11 working group&lt;/strong&gt; adopted the &lt;strong&gt;802.1X&lt;/strong&gt; standard for &lt;strong&gt;authentication, authorization and key management. IEEE 802.1X&lt;/strong&gt; is an IEEE Standard for port-based Network Access Control (PNAC). It provides an authentication mechanism to devices wishing to attach to a LAN or WLAN. At the same time, IEEE formed a Task Group “I” to develop &lt;strong&gt;802.11i&lt;/strong&gt; standard, with a purpose to produce a detailed specification to enhance the security features for wireless LANs dramatically.&lt;/p&gt;

&lt;p&gt;In 2003 the &lt;strong&gt;Wi-Fi Alliance&lt;/strong&gt; announced that WEP had been superseded by &lt;strong&gt;Wi-Fi Protected Access&lt;/strong&gt; (WPA). They extracted the key features from 802.11i to establish WPA to satisfy the immediate needs of the wireless industry. WPA became available in 2003 based on a subset of a &lt;strong&gt;draft&lt;/strong&gt; of &lt;strong&gt;802.11i&lt;/strong&gt;. IEEE 802.11i describes EAP for wireless LANs.&lt;/p&gt;

&lt;p&gt;However, WPA has shown significant vulnerabilities and was later superseded by &lt;strong&gt;WPA2&lt;/strong&gt;, which is based on IEEE 802.11i standard ratified in June 2004.&lt;/p&gt;

&lt;p&gt;In January 2018, Wi-Fi Alliance announced the release of &lt;strong&gt;WPA3&lt;/strong&gt; with several security improvements over WPA2.&lt;/p&gt;

&lt;h2 id=&quot;wep&quot;&gt;WEP&lt;/h2&gt;
&lt;p&gt;WEP was ratified as a Wi-Fi security standard in September of 1999. WEP uses the &lt;a href=&quot;https://en.wikipedia.org/wiki/Stream_cipher&quot;&gt;stream cipher&lt;/a&gt; &lt;a href=&quot;https://en.wikipedia.org/wiki/RC4&quot;&gt;RC4&lt;/a&gt; for &lt;strong&gt;confidentiality&lt;/strong&gt; and the &lt;a href=&quot;https://en.wikipedia.org/wiki/CRC-32&quot;&gt;CRC-32&lt;/a&gt; checksum for &lt;strong&gt;integrity&lt;/strong&gt;. WEP generally uses Pre-Shared Key (PSK); however, it uses rudimentary variations of the same key to encrypt all packets . These weak encryption keys are based on the underlying RC4 crypto algorithm. This is not very safe, a large sample of encrypted packets using the same key tends to create an easy key recovery target for hackers. Furthermore, to change a WEP key requires an IT administrator to update each client machine manually. As a result, changing pre-shared keys regularly to safeguard against key recovery is a highly unfeasible task to scale for large deployments.&lt;/p&gt;

&lt;p&gt;Systems that rely on WEP should be upgraded or, if security upgrades are not an option, replaced.&lt;/p&gt;

&lt;h2 id=&quot;wpa&quot;&gt;WPA&lt;/h2&gt;
&lt;p&gt;As discussed above, WiFi Protected Access was formally adopted in 2003, a year before WEP was officially retired.&lt;/p&gt;

&lt;p&gt;WPA keys use 256-bit keys. Its most common configuration is called the &lt;strong&gt;WPA-PSK&lt;/strong&gt; or &lt;strong&gt;WiFi Protected Access Pre-Shared Key&lt;/strong&gt;. WPA included &lt;strong&gt;message integrity checks&lt;/strong&gt; (to determine if an attacker had captured or altered packets passed between the access point and client) and the &lt;strong&gt;Temporal Key Integrity Protocol&lt;/strong&gt; (TKIP). TKIP employs a per-packet key system that was radically more secure than the fixed key system used by WEP. Although TKIP uses the same base encryption algorithm, RC4 as WEP, the way it selects and changes keys resolves many of the issues surrounding WEP.&lt;/p&gt;

&lt;p&gt;The primary improvement in WPA is the per-session encryption key. Every time a station associates, a new encryption key is generated based on some per-session random numbers and the media access control (MAC) addresses of the station and the access point. WPA sounds like a major improvement, and it is — if it’s used correctly.&lt;/p&gt;

&lt;p&gt;WPA with pre-shared keys can be cracked if IT management unwisely uses straightforward passwords. However, this is not a weakness in WPA security, but rather a potential result of poor password management. An attacker grabs a few packets at the time a legitimate station joins the wireless network and then can take those packets and recover the PSK used.&lt;/p&gt;

&lt;p&gt;WPA used with 802.1X authentication (&lt;strong&gt;WPA-Enterprise&lt;/strong&gt;) offers a secure, per-session encryption key that is not vulnerable to any casual attack. This security comes with a cost because 802.1X authentication requires a significant infrastructure including 802.1X-compliant &lt;strong&gt;RADIUS&lt;/strong&gt; server with a digital certificate, and client software for every user that supports 802.1X and whichever authentication mode they use.&lt;/p&gt;

&lt;h2 id=&quot;wpa2&quot;&gt;WPA2&lt;/h2&gt;
&lt;p&gt;WiFi Protected Access II, as discussed above, was ratified in 2004, and replaced WPA. WPA2 implements the mandatory elements of IEEE 802.11i. In particular, it includes mandatory support for &lt;a href=&quot;https://en.wikipedia.org/wiki/CCMP_(cryptography)&quot;&gt;CCMP&lt;/a&gt;(&lt;strong&gt;Counter Cipher Mode with Block Chaining Message Authentication Code Protocol&lt;/strong&gt;), an &lt;a href=&quot;https://en.wikipedia.org/wiki/Advanced_Encryption_Standard&quot;&gt;AES&lt;/a&gt; based encryption mode as a replacement for TKIP.&lt;/p&gt;

&lt;h3 id=&quot;working&quot;&gt;Working&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*C1hd3PqmkFO-YdgoJGdrnw.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;four-way handshake&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The &lt;strong&gt;four-way handshake&lt;/strong&gt; is the process of exchanging 4 messages between an Access Point (AP) (&lt;strong&gt;authenticator&lt;/strong&gt;) and the client device (&lt;strong&gt;supplicant&lt;/strong&gt;) to generate some encryption keys which can be used to encrypt actual data sent over Wireless medium.&lt;/p&gt;

&lt;p&gt;While Enterprise version use 802.1x exchanges (as discussed above) before handshake, personal directly begins handshake using &lt;strong&gt;Pairwise Master key&lt;/strong&gt; (PMK) (generated from PSK).&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Master Session Key&lt;/strong&gt; (MSK) is the first key which is generated either from 802.1X/EAP (Enterprise) or derived from PSK authentication (Personal). Pairwise master is key generated from this master session key. In case of WPA2/PSK when device authenticates with access point the PMK is simply derived from PSK.&lt;/p&gt;

&lt;p&gt;Here, with the four way handshake, the client is able to generate a &lt;strong&gt;Pairwise Transit Key&lt;/strong&gt; (PTK) and &lt;strong&gt;Group Temporal Key&lt;/strong&gt; (GTK). All unicast traffic will be encrypted with PTK and all multicast and broadcast traffic will be encrypted via GTK.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PTK = PRF (PMK + Anonce + SNonce + Mac (AA)+ Mac (SA))&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For PTK, &lt;strong&gt;PRF&lt;/strong&gt; is a pseudo-random function, &lt;strong&gt;Anonce&lt;/strong&gt; is supplied by the AP in the 1st message. &lt;strong&gt;SNonce&lt;/strong&gt; is generated by the client. Mac address of the AP and supplicant is known already. Hence PTK can be generated. GTK is generated by the AP and shared with the client in the 3rd message of the handshake.&lt;/p&gt;

&lt;p&gt;For detailed explaination, follow this &lt;a href=&quot;https://www.wifi-professionals.com/2019/01/4-way-handshake&quot;&gt;post&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;issues&quot;&gt;Issues&lt;/h3&gt;

&lt;p&gt;The ability to crack the WPA2-Personal passphrase with brute-force attacks: basically guessing the password over and over until a match is found, is a critical vulnerability of WPA2. Making the problem worse, once hackers captured the right data from the airwaves, they could perform these password-guessing attempts off-site, making it more practical for them. Four-way handshake is susceptible to &lt;strong&gt;offline&lt;/strong&gt; dictionary-based attacks, especially when short passwords under 16 characters are employed. Once cracked, they could then decrypt any data they captured before or after the cracking.&lt;/p&gt;

&lt;p&gt;Another major vulnerability of WPA2-Personal, particularly on business networks, is that a user with the passphrase could snoop on another user’s network traffic and perform attacks. This is more evident in open networks. Although the enterprise mode of WPA/WPA2 protects against user-to-user snooping, it requires a RADIUS server or cloud service to deploy the enterprise mode.&lt;/p&gt;

&lt;h3 id=&quot;krack-attack&quot;&gt;KRACK attack&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;a href=&quot;https://www.krackattacks.com/?_ga=2.182670950.1957743772.1508163997-2044333671.1507156536&quot;&gt;Key Reinstallation Attack&lt;/a&gt;&lt;/strong&gt; (KRACK) is a direct attack on the WPA2 protocol and not in individual products or implementations.&lt;/p&gt;

&lt;p&gt;Essentially, KRACK undermines the four-way handshake, allowing a hacker to intercept and manipulate the creation of new encryption keys within the secure connection process. The adversary tricks a victim into reinstalling an already-in-use key. When the victim reinstalls the key, associated parameters such as nonce and receive packet number (i.e. replay counter) are reset to their initial value.&lt;/p&gt;

&lt;p&gt;During the four way handshake, if the 3rd message is received again, the client will reinstall the same encryption key, and thereby reset the incremental transmit packet number (nonce) and receive replay counter used by the encryption protocol. By forcing nonce reuse in this manner, the encryption protocol can be attacked, e.g., packets can be replayed, decrypted, and/or forged. Adversaries can use this attack to decrypt packets sent by clients. As a result, &lt;strong&gt;the same encryption key is used with nonce values that have already been used in the past&lt;/strong&gt;. In turn, this causes all encryption protocols of WPA2 to reuse &lt;a href=&quot;https://en.wikipedia.org/wiki/Keystream&quot;&gt;keystream&lt;/a&gt; when encrypting packets. In case a message that reuses keystream has known content, it becomes trivial to derive the used keystream. This keystream can then be used to decrypt messages with the same nonce. When there is no known content, it is harder to decrypt packets, although still possible in several cases. In practice, finding packets with known content is not a problem, so it should be assumed that any packet can be decrypted.&lt;/p&gt;

&lt;h2 id=&quot;wpa-3&quot;&gt;WPA 3&lt;/h2&gt;
&lt;p&gt;In 2018, the Wi-Fi Alliance announced the next iteration called WPA3 to replace the WPA2, adding several security enhancements and features while overcoming the security vulnerabilities of the WPA2. It takes security to the next level by making wireless networks future ready. It uses the more powerful and robust encryption by AES with the GCMP (&lt;strong&gt;Galois/Counter Mode Protocol&lt;/strong&gt;) and replaces the PSK with the more reliable and secure handshake mechanism called &lt;strong&gt;Simultaneous Authentication of Equals&lt;/strong&gt; (SAE). SAE, also known as the &lt;strong&gt;Dragonfly Key Exchange Protocol&lt;/strong&gt;, is a more secure method of key exchange that addresses the KRACK vulnerability. Specifically, it is resistant to offline decryption attacks through the provision of “&lt;strong&gt;forward secrecy.&lt;/strong&gt;” Forward secrecy stops an attacker decrypting a previously recorded internet connection, even if they know the WPA3 password.&lt;/p&gt;

&lt;p&gt;Have a look at this &lt;a href=&quot;https://medium.com/asecuritysite-when-bob-met-alice/hello-to-wpa-3-ae8b9c365b95&quot;&gt;post&lt;/a&gt; for details.&lt;/p&gt;

&lt;h1 id=&quot;references&quot;&gt;References&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.diva-portal.org/smash/get/diva2:23688/FULLTEXT01.pdf&quot;&gt;https://www.diva-portal.org/smash/get/diva2:23688/FULLTEXT01.pdf&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.615.3578&amp;amp;rep=rep1&amp;amp;type=pdf&quot;&gt;https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.615.3578&amp;amp;rep=rep1&amp;amp;type=pdf&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.computerworld.com/article/2544215/don-t-use-wep-for-wi-fi-security--researchers-say.html&quot;&gt;https://www.computerworld.com/article/2544215/don-t-use-wep-for-wi-fi-security–researchers-say.html&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.networkworld.com/article/2329740/how-can-wpa-be-more-secure-than-wep-.html&quot;&gt;https://www.networkworld.com/article/2329740/how-can-wpa-be-more-secure-than-wep-.html&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.networkworld.com/article/2325729/wpa---an-accident-waiting-to-happen.html&quot;&gt;https://www.networkworld.com/article/2325729/wpa—an-accident-waiting-to-happen.html&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.howtogeek.com/167783/htg-explains-the-difference-between-wep-wpa-and-wpa2-wireless-encryption-and-why-it-matters/&quot;&gt;https://www.howtogeek.com/167783/htg-explains-the-difference-between-wep-wpa-and-wpa2-wireless-encryption-and-why-it-matters/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.krackattacks.com/?_ga=2.182670950.1957743772.1508163997-2044333671.1507156536&quot;&gt;https://www.krackattacks.com/?_ga=2.182670950.1957743772.1508163997-2044333671.1507156536&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.differencebetween.net/technology/difference-between-wpa2-and-wpa3/&quot;&gt;http://www.differencebetween.net/technology/difference-between-wpa2-and-wpa3/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.makeuseof.com/tag/wep-wpa-wpa2-wpa3-explained/&quot;&gt;https://www.makeuseof.com/tag/wep-wpa-wpa2-wpa3-explained/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.networkworld.com/article/3316567/what-is-wpa3-wi-fi-security-protocol-strengthens-connections.html&quot;&gt;https://www.networkworld.com/article/3316567/what-is-wpa3-wi-fi-security-protocol-strengthens-connections.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Kishanganj-2020</title>
   <link href="https://dev-ritik.github.io/blog/2020/11/06/Kishanganj-2020/"/>
   <updated>2020-11-06T00:00:00+00:00</updated>
   <id>https://dev-ritik.github.io/blog/2020/11/06/Kishanganj-2020</id>
   <content type="html">&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/max/800/1*3mFmG08Vl8e96BRvn8M6bg.jpeg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Ever heard of the Kishanganj Vidhan Sabha seat? Probably not. But hey, let’s shed some light on the names vying for your vote in the Bihar Legislature election 2020. I get it; politics isn’t everyone’s cup of tea, but consider this your crash course in “Know Your Choice!” These nuggets are just bits and pieces from my internet scavenger hunt. I’m just here to spark your political curiosity! 🕵️‍♀️🗂️&lt;/p&gt;
&lt;/blockquote&gt;

&lt;!--break--&gt;
&lt;h1 id=&quot;bihar-election-2020&quot;&gt;Bihar Election 2020&lt;/h1&gt;
&lt;h2 id=&quot;political-parties&quot;&gt;Political parties&lt;/h2&gt;
&lt;p&gt;The main parties in Bihar relevant to Kishanganj (or at least those I will be considering here) are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Indian National Congress&lt;/strong&gt; (INC): is headed by Madan Mohan Jha in Bihar.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bharatiya Janta Party&lt;/strong&gt; (BJP) is headed by Sanjay Jaiswal in Bihar.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Janta Dal (United)&lt;/strong&gt; (JD(U)) is headed by CM Nitish Kumar.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;All India Majlis-e-Ittehadul Muslimeen&lt;/strong&gt; (AIMIM) Akhtarul Iman is said to be the president of AIMIM, which recently got its first seat in Bihar from Kishanganj.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;54-kishanganj-vidhan-sabha&quot;&gt;54 Kishanganj Vidhan Sabha&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*9bjx6tXak6nGoIg_2q1_AA.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;54 Kishanganj Vidhan Sabha&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;candidates&quot;&gt;Candidates&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;MD. Qamrul Hoda&lt;/strong&gt; (AIMIM). He won the constituency in 2019 bye-election when the sitting Congress MLA won the MP seat in 2019 Lok Sabha elections.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ijaharul Husain&lt;/strong&gt; (INC). After the backlash in 2019, when Congress decided to give its ticket to the candidate from the family and lost badly, the party has decided to give it to a new face, a party worker.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sweety Singh&lt;/strong&gt; (BJP): 3 times securing 2nd position, she has an ever-increasing vote per cent and has a good chance of being first this time.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tasiruddin&lt;/strong&gt; (Indp): One of the independent candidate with a relatively poor performance in the recent election.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below are the details of these major candidates. These data are largely taken from the affidavit submitted by them for contesting past state elections. These affidavit though is a good source of information but at times these are poorly filled.&lt;/p&gt;

&lt;p&gt;I couldn’t add a table here, so here’s their overall data&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*QaUC1i6IjZjVx8UWlbU-mg.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Candidates general details&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*3kleW4Vo-Cpf3f7cR2kv-w.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Immovable assets include the market value of all the assets inherited.
&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*uw0VNBQTLoZSFk1pUBEAzQ.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Candidates expenditure is recorded according to the Election Commission’s Guidelines. These are put in place to reduce the bias created because of the money power of the candidates. Candidates are required to maintain a register of the same and this register is compared with a shadow register maintained by the officials. This data is sourced from the same. Note that Qamrul Hoda was absent for the first term and presented a common report in the 2nd term. (However absent and not answering in a requested period is considered really bad). Third term’s report is yet to be uploaded.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*9QqwU4egP4VfZWv2E0pKbg.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;individual-profile&quot;&gt;Individual profile&lt;/h2&gt;
&lt;p&gt;Except for the new Congress face, the 3 of them have been contesting state elections. the data below is taken from the affidavit of the candidates from their past elections and the election results available in the Election Commission Website.
&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*6U5b0tRNCwUw3aBnCBKIkw.png&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*kjlsCkf7qRJXA7aFuzr58w.png&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*IWF8gfAB_o3H1SwoZflegg.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Note that all financial data here is the sum of self, spouse and dependents.
&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*B4fGmQSb1rq2W_ttnr3JVQ.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;past-elections-in-kishanganj&quot;&gt;Past elections in Kishanganj&lt;/h2&gt;
&lt;p&gt;Note that 0 indicates that the party did not have a candidate under its flags, probably because of a coalition.
&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*KTMHZZxb8X2wnCaSCwC9Tw.png&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*nNT3SEHa8BtjGuuFUIBD1A.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Below is the Turnout (the count of people who actually voted) and Electors (the total number of voters registered in the area).
&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*BL5iGJGmiurDNGFPQJhJIA.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Note that the dip in 2010 for Vidhan Sabha can be associated with the delimitation of Parliamentary and Assembly constituencies Order, 2008
&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*ZJMRcurfb7W1PxRupdf_XQ.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;source&quot;&gt;Source&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;The cover image is taken from Wikipedia.&lt;/li&gt;
  &lt;li&gt;Kishanganj Vidhan Sabha Map is taken from Election Commission’s records.&lt;/li&gt;
  &lt;li&gt;The tables are generated by me using the data made available by the Election Commission and Kishanganj’s page.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*ZJMRcurfb7W1PxRupdf_XQ.png&quot;&gt;https://eci.gov.in/statistical-report/statistical-reports/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://kishanganj.nic.in/election/?source=post_page-----ccee1ded4fb5--------------------------------&quot;&gt;Election&lt;/a&gt;
    &lt;blockquote&gt;
      &lt;p&gt;Bihar Assembly Election 2020-Nomination Paper Checklist Tender from District Election Office Kishanganj Bihar Assembly…&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;Some of the data is also sourced from various Wikipedia articles.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;~ Happy Voting!&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Trust-TLS-SSL &amp; HTTPS</title>
   <link href="https://dev-ritik.github.io/blog/2020/05/17/Trust-TLS-SSL-and-HTTPS/"/>
   <updated>2020-05-17T00:00:00+00:00</updated>
   <id>https://dev-ritik.github.io/blog/2020/05/17/Trust--TLS-SSL-and-HTTPS</id>
   <content type="html">&lt;p&gt;In our last rendezvous with &lt;a href=&quot;https://medium.com/@ritikk/http-websockets-9c6704e44a2a&quot;&gt;HTTP&lt;/a&gt;, we dove into its evolution for better performance. But here’s the plot twist — HTTP alone is about as secure as a paper umbrella in a storm. Yet, that little lock🔐 in the corner of your browser assures you of safety in the vast and sometimes treacherous realm of the internet. Trust me; my server’s access logs tell tales of the wild digital west!&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;So, what’s the secret sauce behind securing HTTP traffic? What’s the story behind that reassuring lock? How do we establish trust in this cyber jungle? And most importantly, is this Medium article genuinely what it claims to be?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Join me on this journey as we unravel the mysteries of HTTP security. I’ll be your guide, using real-world examples to break down complex concepts without drowning you in technical jargon. Let’s embark on a tech adventure where security meets simplicity! 🚀🔐🌐&lt;/p&gt;

&lt;!--break--&gt;

&lt;h2 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h2&gt;

&lt;p&gt;A bit of knowledge of network systems, particularly the TCP, and cryptography will be enough to understand the content. Though, an interest in the topic should suffice anyway!.&lt;/p&gt;

&lt;h1 id=&quot;https&quot;&gt;HTTPS??&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;Hypertext Transfer Protocol Secure (HTTPS)&lt;/strong&gt; is the secure version HTTP. HTTP, as the name suggests, sends data packets as hypertext. Anyone on the internet can easily read these, or hackers can impersonate your server upon using compromised routers like cafes and other public routers or easily tracked and modified by your ISPs. As such, critical information like banking details should not be handled without HTTPS. Even if you don’t host any sensitive data on your server, it’s pretty recommended shifting to HTTPS. (You don’t want an intermediary to modify your content like pushing their advertisements with it without your permission and your website down rated and marked insecure by popular browsers.)&lt;/p&gt;

&lt;p&gt;HTTPS helps keep these malicious elements out by using what is called &lt;strong&gt;TLS/SSL Handshake&lt;/strong&gt;, which happens before the actual data is transferred. The crux of this handshake is that your server and your client generate a shared session key using asymmetric cryptography, unique to the world, and then encrypt all the traffic to random data packets. Yes these packets can still be seen and modified by those sitting in the middle, or even the request can be forwarded to a malicious server, but your client software would know that something is wrong and alert the user to switch to a more secure network. How would they know you say? Well, that’s what this blog is all about.&lt;/p&gt;

&lt;h2 id=&quot;how-is-http-related-to-https&quot;&gt;How is HTTP related to HTTPS?&lt;/h2&gt;
&lt;p&gt;The actual messages are formatted and structured as determined by HTTP. It’s just that they are encrypted to garbage while transmitting and again decrypted by the intended recipient and none else. All HTTP data MUST be sent as TLS application data. By default, HTTP uses port 80 and HTTPS uses port 443. Using HTTPS, only the source &amp;amp; destination IP address, port and domain (SNI) are public. The URL, query parameters, headers, body, and cookies (which often contain identity information about the user) are all encrypted. The amount of data and the duration of communication can also be determined.&lt;/p&gt;

&lt;h2 id=&quot;making-https-calls-using-openssl&quot;&gt;Making HTTPS calls using OpenSSL&lt;/h2&gt;
&lt;p&gt;OpenSSL is a command-line cryptography tool relating to SSL/TLS protocols and related cryptographic functions. As such, it can be easily used for making HTTPS calls. On your terminal,&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;openssl s_client &lt;span class=&quot;nt&quot;&gt;-crlf&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-connect&lt;/span&gt; example.com:443
GET / HTTP/1.1
Host: example.com
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;simple-example&quot;&gt;Simple Example&lt;/h2&gt;
&lt;p&gt;Run the following code to fetch &lt;em&gt;example.com&lt;/em&gt; using python. Comments have been added for your help.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://gist.github.com/dev-ritik/99609f5282a7cad5d13f621cd80431fe#file-client-py&quot;&gt;Example of a simple HTTPS request&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;capturing-https-and-http-packets&quot;&gt;Capturing HTTPS and HTTP Packets&lt;/h2&gt;
&lt;p&gt;There are a handful of tools, particularly &lt;strong&gt;&lt;a href=&quot;https://www.wireshark.org/&quot;&gt;Wireshark&lt;/a&gt;&lt;/strong&gt;, which helps us analyse network packets actually exchanged. Let’s use a similar tool &lt;strong&gt;tcpdump&lt;/strong&gt; to sniff and analyse these packets going to example.com (93.184.216.34). It can sniff all the packets on the target interface and help in analysing the traffic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTTP&lt;/strong&gt;: Let’s use &lt;strong&gt;cURL&lt;/strong&gt; to make an HTTP request. Run this command on the terminal to capture packets:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;tcpdump &lt;span class=&quot;nt&quot;&gt;-A&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; 0 host 3.220.159.10 and port http
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now, make an HTTP cURL request from another&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl &lt;span class=&quot;nt&quot;&gt;--location&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;http://postman-echo.com/post&apos;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--data-raw&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;This is a client secret, not to be revealed!&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This would print the TCP packet in ASCII. If you like, you can get in hex as well. (You can interpret that packet using TCP segment structure as well). Anyways, here you can see among other things, src and dest address &amp;amp; port. What you can also see is the first three messages of the &lt;strong&gt;TCP handshake&lt;/strong&gt; (SYN, SYN+ACK, SYN). Following that you can see the entire HTTP request:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;E....B@.@.. ..+#...
.D.P..EQ.t.............
.U....[.POST /post HTTP/1.1
Host: postman-echo.com
User-Agent: curl/7.58.0
Accept: */*
Content-Length: 44
Content-Type: application/x-www-form-urlencoded

This is a client secret, not to be revealed!
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And after the server &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ack&lt;/code&gt;, the server reply as well:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;E.. .a@…{….
..+#.P.D.t….F….n…….
..]T.U..HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Tue, 28 Apr 2020 17:59:17 GMT
ETag: W/”189-BP2UptWJTIcEngOzrSrBUV1O57Y”
Server: nginx
set-cookie: sails.sid=s%3Anxu4rLgsmTVDxMM8s-9m8UvJ-RniOXlj.x4Jd80JEc2ldtbGd9KVKcnOP%2Bkspz0dYKduOgl4%2FXL0; Path=/; HttpOnly
Vary: Accept-Encoding
Content-Length: 393
Connection: keep-alive
{“args”:{},”data”:””,”files”:{},”form”:{“This is a client secret, not to be revealed!”:””},”headers”:{“x-forwarded-proto”:”https”,”host”:”postman-echo.com”,”content-length”:”44&quot;,”accept”:”*/*”,”content-type”:”application/x-www-form-urlencoded”,”user-agent”:”curl/7.58.0&quot;,”x-forwarded-port”:”80&quot;},”json”:{“This is a client secret, not to be revealed!”:””},”url”:”https://postman-echo.com/post&quot;}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Following an ack by the client, you can see &lt;strong&gt;TCP Connection Termination&lt;/strong&gt; as well.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;The dump has other interesting things as well for your interpretation.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Take away here is that a middleman can sniff your complete HTTP request-response easily.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTTPS&lt;/strong&gt;: Use Openssl for HTTPS and make the same request. Trace it using:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;tcpdump &lt;span class=&quot;nt&quot;&gt;-A&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; 0 host 3.220.159.10 and port https
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You will see a lot of messages exchanged, from both TCP Handshake and TLS Handshake. But you won’t find any more data than the TCP headers. HTTP data is encrypted to arbitrary bits.&lt;/p&gt;

&lt;h1 id=&quot;ssl&quot;&gt;SSL&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;Secure Sockets Layer (SSL)&lt;/strong&gt;, more commonly called &lt;strong&gt;Transport Layer Security (TLS)&lt;/strong&gt;, is a standard security protocol, commonly used by HTTPS, for securing the communication. Data is transferred over the public internet wherein it could easily be spoofed or sniffed if sent as plain text. SSL ensures that this transfer is encrypted using symmetric and asymmetric cryptography. Thus the data actually transferred is garbage to anyone else on the internet(planet) other than their intended recipient. (Even though they might never have met each other and are sitting on the other sides of the planet.)&lt;/p&gt;

&lt;p&gt;This is done by what is called &lt;strong&gt;SSL Handshake&lt;/strong&gt; and &lt;strong&gt;Certificate trust verification&lt;/strong&gt;. This SSL protocol dictates how both parties should interact to ensure trust and authentication. All this is carried using what is called an &lt;strong&gt;SSL Certificate&lt;/strong&gt;. This certificate packs a lot of data within it together with a &lt;strong&gt;public key&lt;/strong&gt;. Please note that SSL is not limited to HTTPS. Other protocols like SMTP (for sending emails) are secured as well like SMTPS.&lt;/p&gt;

&lt;h2 id=&quot;ssl-handshakes&quot;&gt;SSL Handshakes&lt;/h2&gt;
&lt;p&gt;To generate that unique session key for encryption, both parties need to agree on particulars of the conversation. So this Handshake is that pre-conversation agreement. During the Handshake, the following things happen:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Both parties agree on the protocol version.&lt;/li&gt;
  &lt;li&gt;Decide on the cypher suites to use&lt;/li&gt;
  &lt;li&gt;Prove the identity of the server (and the client if required)&lt;/li&gt;
  &lt;li&gt;Decide on the symmetric common session key for both parties&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*laui6VO02hZB1flJeggdHw.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;courtesy: &lt;a href=&quot;https://techcommunity.microsoft.com/&quot;&gt;https://techcommunity.microsoft.com/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Again, it all starts with a Socket based connection (A TCP handshake). The server is waiting on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;accept&lt;/code&gt;, i.e. waiting to accept a new TCP Socket connection and the client (browser) will &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;connect&lt;/code&gt; soon. What happens during a socket connection (TCP Connection) is handled at the transport layer level. During the SSL Handshake, this is generally what happens:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Client Hello&lt;/strong&gt;: The client sends a request for a secure connection with the server. It requests that the web server identify itself. It also includes other fields for initiating the agreement like supported versions and cyphers.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Server Hello&lt;/strong&gt;: The server replies with its SSL certificate proving it’s identity. Note that the certificate also contains its public key. It also replies with some of its fields like selected version and cypher. It may ask for a client certificate request.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Authentication &amp;amp; ClientKeyExchange&lt;/strong&gt;: The client verifies the certificate received, through which it confirms that the server is indeed who it claims to be and the public key does genuinely belong to the server and not forged by someone on the public internet. (Again it’s all Cryptography!) The client, upon trusting the certificate and the public key, generates an asymmetric &lt;strong&gt;pre-master secret&lt;/strong&gt; and sends it encrypted using the server’s public key. (Intelligent only that server can decrypt it using its Private key.)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Private key&lt;/strong&gt;: The server decrypts the pre-master secret using its private key.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Session keys&lt;/strong&gt;: Both client and server perform a series of steps depending upon the cypher and computes the &lt;strong&gt;session key&lt;/strong&gt;. Hence, by the laws of cryptographic algorithms, they have shared a symmetric key which only these 2 devices on the planet claim to have and no other on the public internet (sorry MITM).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Finish&lt;/strong&gt;: The server and the client acknowledge each other by sending a “finished” message that is encrypted with the session key!.
The secure connection is thus established, and their communication is encrypted now.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The exact steps may be slightly different based upon the cyphers and the version of the protocol used.&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Note that in this form of connection, the client certificate is not required. SSL verification of clients is also possible and required under some conditions wherein the server requires the client to verify as well! Well browsers don’t fit in those conditions.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;certificates&quot;&gt;Certificates&lt;/h2&gt;
&lt;p&gt;The SSL Certificate establishes the identity of an entity on the Internet. It is like a small document of trust wherein the entity records its public key and organisational details etc. The credibility of these certificates is established on the chain of trust anchored to the trusted authorities on the Internet using cryptographic wizardry!&lt;/p&gt;

&lt;p&gt;Let’s get our hands dirty on these certificates!. There’s a lot to grab in them and let’s try to pocket some of them. It’s effortless to get the certificates of a web service. Using &lt;strong&gt;openssl&lt;/strong&gt; is one such method. For &lt;em&gt;medium.com&lt;/em&gt;, you can see the certificate using this command:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;openssl s_client &lt;span class=&quot;nt&quot;&gt;-showcerts&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-connect&lt;/span&gt; medium.com:443 &amp;lt;/dev/null
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Most popular browsers let you get these certificates as well.&lt;/p&gt;

&lt;p&gt;Starting with a sample certificate!. In your browser, click on that lock symbol on the search bar and download Medium’s certificate, it used to negotiate an SSL connection with your browser. This is how it looks now:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-----BEGIN CERTIFICATE-----
MIIHOjCCBiKgAwIBAgIQCKfj9u8gdru4ZGLwtU+igTANBgkqhkiG9w0BAQsFADB1
&amp;lt;Base64 Encoded text&amp;gt;
4JrHEaQHgEi13M29EUMqB3azOqcov4m1QZH0ygih6UFPol0+InswHa84ZTDmPOpt
gSl68MrGmFqTfywSCfStLmMZJWjfW/3OHFzvGMX2
-----END CERTIFICATE-----
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This looks like a lot of base64 encoded gibberish but saves this in a file &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;medium.crt&lt;/code&gt; and run the command,&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;openssl x509 -in medium.crt -text -noout
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;You can see all the details it has within itself. Among other things, it contains,&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Issuer: C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert SHA2 Extended Validation Server CA&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Indicating that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DigiCert SHA2 Extended Validation Server CA&lt;/code&gt; issued medium this certificate and&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Subject: businessCategory = Private Organization, jurisdictionC = US, jurisdictionST = Delaware, serialNumber = 5010624, C = US, ST = California, L = San Francisco, O = A Medium Corporation, CN = medium.com&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;is the description of the entity(medium) it is issued to.
Now if you download &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DigiCert SHA2 Extended Validation Server CA&lt;/code&gt;‘s certificate and run similar command, this is what you get:
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Issuer: C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert High Assurance EV Root CA&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Indicating that this itself was issued by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DigiCert High Assurance EV Root CA&lt;/code&gt;. You can see a chain like trust-building! Upon downloading this one, you will see that issuer is the same as the one to whom it is issued to,&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Issuer: C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert High Assurance EV Root CA
Validity
Not Before: Nov 10 00:00:00 2006 GMT
Not After : Nov 10 00:00:00 2031 GMT
Subject: C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert High Assurance EV Root CA
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*L1wDi5EVmQHhWmQx6pu6tw.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Medium certificate chain&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So should we trust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DigiCert High Assurance EV Root CA&lt;/code&gt; and by extension medium!? Well yes! They are the trust anchors (&lt;strong&gt;Certifying Authorities&lt;/strong&gt;) of the internet trust network, and mostly every SSL software keeps a copy of these certificates or gets it through support libraries. They have to comply with the set of security guidelines established by these Softwares (like Browsers). As can be seen here, certificates are generally signed by other certificates forming the &lt;strong&gt;certificate chain&lt;/strong&gt;. This chain terminates at a self-signed authoritative certificate provided by these root &lt;strong&gt;Certifying Authorities&lt;/strong&gt; (CA)s like Digicert Root CA. There are cryptographic algorithms to ensure that if certificates are indeed signed by the issuer (discussed later).&lt;/p&gt;

&lt;p&gt;Also, if you are following along using openssl, you must have noted that medium doesn’t actually send this root certificate. The browser itself, in fact, adds it. The server may not send the root CA certificate if it wants to. (&lt;a href=&quot;https://tools.ietf.org/html/rfc5246#section-7.4.2&quot;&gt;RFC Reference&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;You can also verify the certificate chain using openssl. As explained in the picture above, Issuer (Digicert CA) signs the certificate containing the public key of the requester (Medium). It uses it’s own private key to generate a cryptographic signed hash of the data provided with the request and sends that in the certificate. Now cryptography says that only Digicert’s public key can decrypt it, which is available with its own certificate. So let’s get&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Digicert pubkey&lt;/strong&gt;: To get the included Digicert’s public key from its certificate use
    &lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;openssl x509 &lt;span class=&quot;nt&quot;&gt;-pubkey&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-noout&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-in&lt;/span&gt; DigiCert&lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;SHA2&lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;Extended&lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;Validation&lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;Server&lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;CA.crt &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; DigiCert.pub
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Medium signature from the certificate&lt;/strong&gt;: You can extract the Digicert signed hash in the medium’s certificate and convert it into binary:
    &lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;openssl x509 &lt;span class=&quot;nt&quot;&gt;-in&lt;/span&gt; medium.crt &lt;span class=&quot;nt&quot;&gt;-text&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-noout&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-certopt&lt;/span&gt; ca_default &lt;span class=&quot;nt&quot;&gt;-certopt&lt;/span&gt; no_validity &lt;span class=&quot;nt&quot;&gt;-certopt&lt;/span&gt; no_serial &lt;span class=&quot;nt&quot;&gt;-certopt&lt;/span&gt; no_subject &lt;span class=&quot;nt&quot;&gt;-certopt&lt;/span&gt; no_extensions &lt;span class=&quot;nt&quot;&gt;-certopt&lt;/span&gt; no_signame | &lt;span class=&quot;nb&quot;&gt;grep&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-v&lt;/span&gt; ‘Signature Algorithm’ | &lt;span class=&quot;nb&quot;&gt;tr&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; ‘[:space:]:’ | xxd &lt;span class=&quot;nt&quot;&gt;-r&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; medium_signature.bin
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cert body&lt;/strong&gt;: To get the body of the cert which was actually hashed,
    &lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;openssl asn1parse &lt;span class=&quot;nt&quot;&gt;-in&lt;/span&gt; medium.crt &lt;span class=&quot;nt&quot;&gt;-strparse&lt;/span&gt; 4 &lt;span class=&quot;nt&quot;&gt;-out&lt;/span&gt; cert-body.bin
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
    &lt;p&gt;Finally, run the command (sha256 in this case),&lt;/p&gt;
    &lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;openssl dgst &lt;span class=&quot;nt&quot;&gt;-sha256&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-verify&lt;/span&gt; DigiCert.pub &lt;span class=&quot;nt&quot;&gt;-signature&lt;/span&gt; medium_signature.bin cert-body.bin
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; Verified OK
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This shows that Digicert CA actually signed the medium’s cert and everything in medium’s cert (including medium’s public key) is actually genuine if Digicert’s certificate is genuine. This certificate chain of trust is the backbone of trust on the internet. More details on this can be found &lt;a href=&quot;https://kulkarniamit.github.io/whatwhyhow/howto/verify-ssl-tls-certificate-signature.html&quot;&gt;here&lt;/a&gt;. This was just signature verification, but other things like validity and revoking trust check also comes into play.&lt;/p&gt;

&lt;p&gt;Where to look for the certificates I trust? Softwares like your OS comes with its list of trusted anchors.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;For Linux, the file &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/ssl/certs/ca-certificates.crt&lt;/code&gt; contains the concatenated list of trusted CA’s certificates which defines the base trust for your OS and other software which use that file as default.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;requests&lt;/code&gt; library in python has &lt;a href=&quot;https://github.com/psf/requests/blob/master/requests/certs.py&quot;&gt;this&lt;/a&gt; file wherein it looks for the root CA certs. You can see that it depends on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;certifi&lt;/code&gt; package. This package contains updated root CA certificates for major trust anchors. (Like if you see their PyPI page, ‘&lt;em&gt;Python package for providing Mozilla’s CA Bundle&lt;/em&gt;’). Certifi comes with its list of certs when downloaded, available &lt;a href=&quot;https://github.com/certifi/python-certifi/blob/master/certifi/cacert.pem&quot;&gt;here&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;In python &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;urllib3&lt;/code&gt;, it says &lt;a href=&quot;https://urllib3.readthedocs.io/en/latest/user-guide.html#certificate-verification&quot;&gt;here&lt;/a&gt; that, ‘&lt;em&gt;Unless otherwise specified urllib3 will try to load the default system certificate stores. The most reliable cross-platform method is to use the &lt;a href=&quot;https://certifi.io/&quot;&gt;certifi&lt;/a&gt; package which provides Mozilla’s root certificate bundle&lt;/em&gt;’.&lt;/li&gt;
  &lt;li&gt;For chrome, go to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chrome://settings/certificates&lt;/code&gt; onto the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Authorities&lt;/code&gt; tab, and search for DigiCert, you will get &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DigiCert High Assurance EV Root CA&lt;/code&gt; there. If you compare these two, they are actually the same! Hence Chrome establishes trust for this certificate for you! And hence you see that green lock there on the search bar!. You can get it on the Firefox as well!.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Look how chrome complained when I denied chrome to use that certificate to verify medium! XD&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*w8N3NJj2mM7Pn04zl6rGOw.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Manually removing trust for Digicert Root CA.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:374/format:webp/1*k50HRAAfoECt7OiAFPDxDg.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Not Secure Warning on the search bar&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*iqCIxpXSNkgfjAw22I4Itw.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;NET::ERR_CERT_AUTHORITY_INVALID&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let me explain what just happened. During SSL handshake, Medium didn’t provide all the 3 certificates! It just provided its own certificate, cryptographically signed by DigiCert SHA2 Extended Validation Server CA bundled with the latter’s certificate signed by DigiCert High Assurance EV Root CA. But since Chrome now doesn’t trust this Root CA, it cannot guarantee the user if it is indeed medium. It may be any malicious website pretending to be medium and proceeding further is probably unsafe.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let me describe another case&lt;/strong&gt;. Consider that the server doesn’t send its certificate chain and rather send the leaf certificate (signed by an intermediate authority and not directly by your trusted root CA). What happens then!. Well, it all depends upon the implementation of the certificate verification program. Certificates contain fields (along with Issuer DN (Distinguished Name) mentioned above) which help the program to fetch that intermediate certificate from other sources. This may be utilised to fetch and build the chain and hence build trust. Chrome does this automatically for you, but firefox probably gives a warning. But for libraries like python request, this isn’t the case. You will certainly get verification errors in this case! Here, a temporary solution will be to add intermediate certificates yourself as trusted (for the time being).&lt;/p&gt;

&lt;h2 id=&quot;simple-example-1&quot;&gt;Simple Example&lt;/h2&gt;
&lt;p&gt;To get the simplest SSL based communication, you would need a certificate for the server, which can be verified by our demo client. This is explained beautifully &lt;a href=&quot;https://www.electricmonk.nl/log/2018/06/02/ssl-tls-client-certificate-verification-with-python-v3-4-sslcontext/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For experimenting with different types of certificates, have a look at &lt;a href=&quot;https://badssl.com/&quot;&gt;this website&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;how-to-get-a-certificate-for-my-website&quot;&gt;How to get a certificate for my website?&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*xiAYdN-ELzSMC3vfYZ3EgQ.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Self-Signed Certificates!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As you must have guessed by now, you can indeed generate your own &lt;strong&gt;self-signed certificate&lt;/strong&gt; and use that to establish yourself as the trust anchor for your closed testing environment. But that won’t work in production. Your users won’t trust your signed certificate. Instead, browsers and search engines will demote your website. Indeed your communication will be secure though! (&lt;em&gt;assuming that it is with your server and not any other impersonated server!&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;You would obviously try to get certificates from established trust anchors on the internet. Now there are tons of CA on the internet both paid and free ones. I personally use &lt;a href=&quot;https://letsencrypt.org/&quot;&gt;Let’s Encrypt&lt;/a&gt; for my websites (&lt;em&gt;not a paid promotion!&lt;/em&gt;). It’s free and easy to use. &lt;em&gt;To get a certificate for your website’s domain from Let’s Encrypt, you have to demonstrate control over the domain&lt;/em&gt;. Assuming that you are hosting your service on some virtual servers like AWS yourself, it basically boils down to your server listening to the IP address attached to your domain and you having SSH access into the system. It comes with a handy tool called &lt;a href=&quot;https://certbot.eff.org/&quot;&gt;certbot&lt;/a&gt;. &lt;em&gt;It can automate certificate issuance and installation with no downtime&lt;/em&gt;. For my website, I have automated the process using these shell commands:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;wget https://dl.eff.org/certbot-auto&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;chmod &lt;/span&gt;a+x certbot-auto
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo&lt;/span&gt; ./certbot-auto certonly &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt; non-interactive &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt; email &amp;lt;email&amp;gt; &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt; agree-tos &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt; standalone &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt; domains &amp;lt;domain&amp;gt; &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt; keep-until-expiring &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt; debug
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo ln&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-sf&lt;/span&gt; /etc/letsencrypt/live/&amp;lt;domain&amp;gt; /etc/letsencrypt/live/cert
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This generates a cert and private key for your website and stores the Let’s encrypt intermediate cert as well for the trust chain at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/letsencrypt/live/cert/&lt;/code&gt; . Now you could easily add their location to Nginx or Apache(httpd) server config file or use them with the simple HTTPS example mentioned above.&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;🎉 Phew! That was a content-packed ride! 🚀 Unraveled the mysteries of TLS, didn’t we? Dive into the intriguing world of cryptography and explore more with my examples. Play, learn, and enjoy the tech playground. Ready for hands-on fun? Check out the repository for a real-life implementation based on what we’ve explored! 💡💻&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/dev-ritik/Secure-file-transfer?source=post_page-----b925ac9d59--------------------------------&quot;&gt;dev-ritik/Secure-file-transfer&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;A demonstration for secure file transfer within an organization using key-chain validation. The files are secured using asymmetric encryption…&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>HTTP &amp; WebSockets</title>
   <link href="https://dev-ritik.github.io/blog/2020/05/17/HTTP-WebSockets/"/>
   <updated>2020-05-17T00:00:00+00:00</updated>
   <id>https://dev-ritik.github.io/blog/2020/05/17/HTTP---WebSockets</id>
   <content type="html">&lt;p&gt;In our last tech rendezvous, we delved into the realm of &lt;a href=&quot;https://medium.com/mobile-development-group/simple-servers-cc465f340658&quot;&gt;Simple Servers&lt;/a&gt; and got cosy with sockets-based communication - the unsung heroes behind the scenes. But let’s face it, when it comes to writing servers today, it’s the dynamic duo of &lt;strong&gt;HTTP&lt;/strong&gt; and &lt;strong&gt;HTTPS&lt;/strong&gt; taking centre stage!&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Picture this: the entire digital cosmos, with terabytes of data zipping around every second to the gadgets in our hands - it’s mostly all orchestrated by the magic of HTTP and WebSocket. But here’s the kicker - how do they tango with sockets? How is HTTP evolving, and is WebSocket just a fancy cousin of the classic socket?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hold on tight as we demystify these web wonders! I’ll be your guide, unravelling the tech tapestry with real-world examples and steering clear of unnecessary tech mumbo-jumbo. Let’s embark on a tech exploration where complexity meets simplicity! 🚀🌐💡&lt;/p&gt;

&lt;!--break--&gt;

&lt;h2 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h2&gt;

&lt;p&gt;A little knowledge of network systems with interest in the topic should be just excellent. Have a look at my &lt;a href=&quot;https://medium.com/mobile-development-group/simple-servers-cc465f340658&quot;&gt;last blog&lt;/a&gt; for some basic concepts.&lt;/p&gt;

&lt;h1 id=&quot;introduction-to-http-and-its-versions&quot;&gt;Introduction to HTTP and its versions&lt;/h1&gt;
&lt;p&gt;Once a socket-based connection is made, the client and the server can indeed communicate with each other. If it were for your inhouse application, any form of communication standards would suffice. But, when it comes to standardizing a protocol for communication between the browsers and the servers, &lt;em&gt;it ought to be simple and extensible&lt;/em&gt;. As you might know, &lt;strong&gt;HTTP&lt;/strong&gt; plays that role. It is the underlying application-level protocol which defines this communication.&lt;/p&gt;

&lt;p&gt;Whenever a browser wants a web page, it sends an HTTP request to get that page. The server responds according to this protocol and sends the page and an appropriate HTTP status code which can be interpreted by the browser as the standard server’s response. Its versatility and usefulness are reflected on its extensive use even now (since the 1990s). Today, a wide range of applications (&lt;em&gt;almost just about anything you can think of&lt;/em&gt;) are deployed over HTTP.&lt;/p&gt;

&lt;p&gt;HTTP is a request/response protocol. The client sends a request to the server in the form of a request method, URI, and protocol version, followed by a message containing request modifiers, client information, and possible body content over the connection. The server responds with a status line, including the message’s protocol version and a success or error code, followed by a message containing server information, entity metainformation, and possible entity-body content.&lt;/p&gt;

&lt;h2 id=&quot;features&quot;&gt;Features&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;HTTP by itself is &lt;strong&gt;stateless&lt;/strong&gt;. This means each request is executed independently, without any knowledge of the requests that were executed before it, i.e. the server does not keep any state between two requests. Even though servers use cookies today to store state, HTTP remains stateless&lt;/li&gt;
  &lt;li&gt;The applications can easily modify it by adding custom headers, which the client and the server agrees upon.&lt;/li&gt;
  &lt;li&gt;It is reliable (ensures the message is transferred or generates an error).&lt;/li&gt;
  &lt;li&gt;HTTP/1.x, it is pretty easy to implement, something which I demonstrated in my &lt;a href=&quot;https://medium.com/mobile-development-group/simple-servers-cc465f340658&quot;&gt;socket blog&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;versions&quot;&gt;Versions&lt;/h2&gt;
&lt;p&gt;Take the simplest example of &lt;strong&gt;HTML/0.9&lt;/strong&gt; (the initially proposed version). As simple as making a TCP Socket connection and sending one-line ASCII request&lt;/p&gt;

&lt;div class=&quot;language-http highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;err&quot;&gt;GET /index.html
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;to the socket will get you the response hypertext message from the server socket&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;HTML&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;Body&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;
     Hello from server!
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/Body&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/HTML&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;and the connection will be closed.&lt;/p&gt;

&lt;p&gt;HTTP has had several revisions since. &lt;strong&gt;HTTP/1.0&lt;/strong&gt; modified HTTP/0.9 and added features like status code headers, version (appended in the 1st line).&lt;/p&gt;

&lt;p&gt;Standardised in &lt;strong&gt;HTTP/1.1&lt;/strong&gt;, it is the most widely used version right now. It introduced connection reuse, among other things. Opening and closing a connection is a significant overhead in a TCP connection. With the introduction of SSL/TLS Handshake, the number of message exchanges for establishing a connection has gone significantly up, increasing the load on HTTP servers apart from causing congestion on the Internet and the apparent delay. By persisting a connection, memory &amp;amp; CPU time is conserved as well. These warm existing connections overcome &lt;strong&gt;TCP slow start&lt;/strong&gt; congestion control protocol as well. Hence, it’s wasteful if used for just a single request-response exchange connection.&lt;/p&gt;

&lt;p&gt;Using &lt;strong&gt;persistent connections&lt;/strong&gt;, multiple HTTP requests could be sent in the same connection (connection is ‘&lt;em&gt;keepalive&lt;/em&gt;’ by default). This allowed connection to be reused, but the problem remained that newer requests had to wait for the response of the existing one in a particular connection(a strict FIFO from the client-side).&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*5I7UTS1pOwlHwv_vAaLP3g.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;a href=&quot;http://developer.mozilla.org/&quot;&gt;Courtesy&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It introduced &lt;strong&gt;request pipelining&lt;/strong&gt; as well wherein, multiple requests could be sent instead of waiting for the response of the first one to arrive, on the same connection. Modern-day webpages request tons of other static assets as well upon loading. Pipelining them on the same connection makes sense as well. But this increases the load of buffering and processing on the server’s end. As you can see in the picture, the server can only send the response to a request in a FIFO manner. Multiplexing was still not introduced for helping with multiple parallel responses. This has some other severe implications in TCP based connection as well. Therefore pipelining is in marginal use today.&lt;/p&gt;

&lt;p&gt;In such a scenario, browsers have limited choice for handling tons of static resources put into displaying today’s web pages. They have to make a balance between the number of parallel connections and FIFO delay. (Throwing unlimited connection may lead to unintentional D-DoS). In practice, browsers tend to open around 6 connections per host, but there is a good discussion around &lt;a href=&quot;https://bugs.chromium.org/p/chromium/issues/detail?id=12066&quot;&gt;that&lt;/a&gt;. From &lt;a href=&quot;https://tools.ietf.org/html/rfc2616#section-8.1.4&quot;&gt;RFC 2616&lt;/a&gt;, “&lt;em&gt;Clients that use persistent connections SHOULD limit the number of simultaneous connections that they maintain to a given server. A single-user client SHOULD NOT maintain more than 2 connections with any server or proxy&lt;/em&gt;”.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*YJfWLxUhF9BvHYZUSQPp0w.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Waterfall for the same domain using HTTP/1.1&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can verify this using the &lt;em&gt;inspect-network&lt;/em&gt; tool in the (chrome) browser. Notice how only 6 parallel connections are made (to the same host) and other requests are waiting for the response to the earlier ones.&lt;/p&gt;

&lt;p&gt;There is yet another problem with HTTP/1.x. When considering tons of HTTP calls for a single page rendering, everything matters. If you notice, we are exchanging a bunch of metadata including headers and cookies(which by the stateless nature needs to be sent with all of your requests) which fundamentally increase the total payload for the transport layer. These are sent as plain text without compression. Run the command:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl &lt;span class=&quot;nt&quot;&gt;--trace-ascii&lt;/span&gt; - &lt;span class=&quot;s1&quot;&gt;&apos;http://postman-echo.com/get?foo1=bar1&amp;amp;foo2=bar2&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can see that the header to data byte ratio in the request is 103:0, whereas in response is 352:227. Headers clearly overshadow the actual HTTP payload.&lt;/p&gt;

&lt;p&gt;Come &lt;strong&gt;&lt;a href=&quot;https://tools.ietf.org/html/rfc7540&quot;&gt;HTTP/2.0&lt;/a&gt;&lt;/strong&gt;, many of these problems were addressed. Essentially it adds a new intermediate &lt;strong&gt;binary framing layer&lt;/strong&gt; between the HTTP/1.x syntax and the underlying transport protocol, without fundamentally modifying it. With the introduction of &lt;strong&gt;multiplexing&lt;/strong&gt; transfers, multiple requests could be sent simultaneously in the same TCP connection with each request being largely independent of others in the form of separate &lt;strong&gt;streams&lt;/strong&gt;. These streams are just a bidirectional flow of HTTP/2 &lt;strong&gt;frames&lt;/strong&gt;, identifiable by assigned integers. Multiple streams can be initiated and used at the same time within the same connection, thus establishing multiplexing.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*IOHUOmufilOT7nwpAAhnbA.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;a href=&quot;http://developers.google.com/&quot;&gt;Courtesy&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The basic protocol unit in HTTP/2 is a &lt;strong&gt;frame&lt;/strong&gt;. There are quite a few types of frame, including HEADERS and DATA frame. The format of frames is well defined in &lt;a href=&quot;https://tools.ietf.org/html/rfc7540#section-4.1&quot;&gt;RFC 7540&lt;/a&gt;. Along with other stuff, these frames carry a &lt;strong&gt;stream identifier&lt;/strong&gt;, necessary while multiplexing wherein these frames of different streams can be interleaved and then reassembled. In the HEADERS frame, headers are compressed and serialised into a header block using &lt;strong&gt;&lt;a href=&quot;https://tools.ietf.org/html/rfc7541&quot;&gt;HPACK&lt;/a&gt; compression&lt;/strong&gt;. Often these header names and values are the same or similar. It uses Huffman encoding and static and dynamic reference tables for this purpose. Same headers among consecutive frames can be simply referenced using the dynamic table and duplicates can be dropped. You can get a feeling of how this would be done and feel the compression gain as well. Header frames may also contain a weight field, assigning &lt;strong&gt;priority&lt;/strong&gt; to the requests. This prioritisation will help in getting crucial assets like CSS and blocking JS faster, thus improving performance.&lt;/p&gt;

&lt;p&gt;With the introduction of &lt;strong&gt;server push&lt;/strong&gt;, servers can push additional resources to the client which it knows the client would request for. The server can send these in additional multiple responses (in new push streams) for the single request. This indeed helps in saving request latencies in RTT (Round Trip Time). For example, the server may push all the relevant assets when it receives a request for the index page, which the client can cache.&lt;/p&gt;

&lt;p&gt;Standardised in 2015, HTTP/2 has seen wide adoption, particularly with high traffic servers. The protocol requires no change from the web application but only an upgrade to the browser and the server. The application side API remains the same with the same semantics. Because the data is transferred using binary instead of text, &lt;strong&gt;tcpdump&lt;/strong&gt; cannot be used to read the data directly. As such it can run with TLS or as cleartext TCP but is generally used with HTTPS.&lt;/p&gt;

&lt;p&gt;Check the latest implementations of HTTP/2 &lt;a href=&quot;https://github.com/http2/http2-spec/wiki/Implementations&quot;&gt;here&lt;/a&gt;. As a fact, Medium is using H2 as of now!&lt;/p&gt;

&lt;h2 id=&quot;implementation&quot;&gt;Implementation&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*eJTGH8nj-cCxdURQDa9OEA.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Waterfall for the same host using H2&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Clearly HTTP/2 is vastly different wrt HTTP/1.1 (from the image far up), you can see that the time for the first two items remained almost similar (owing to the way the page is loaded), but after that 15 more assets are requested at the same time. You can see that in HTTP/1.1, requests were queued in 6 parallel TCP connections waiting for their turn, but here, all of them are requested at once (with set priorities) without waiting. Notice how the only JS request (3rd one) took less (626 ms) to load from the HTTP/1.1 (734 ms). This can be attributed to high priority being assigned to the blocking JS assets by chrome. As for the increased size of the green bar (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;time to first byte&lt;/code&gt;) for others, it is because HTTP/2 prioritises critical JS assets for a better experience, so other requests have to wait for a while. Also, do note that the finish time is 2.30s in HTTP/1.1 vs 2.12s in H2&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*rPm-NkSfCdSaqFayQ_l0lg.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;With Server push&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For the image above, I pushed CSS and JS assets (2nd and 3rd, respectively) with the index page (1st request). Notice how it makes no network call for these resources as gets it from the cached files (pushed from server). This is a significant boost in performance and user experience wrt other images above.&lt;/p&gt;

&lt;p&gt;Let’s move to the more recent and under-development, &lt;strong&gt;HTTP/3&lt;/strong&gt; (HTTP over &lt;strong&gt;QUIC&lt;/strong&gt;(&lt;strong&gt;Quick UDP Internet Connections&lt;/strong&gt;)). Though much support is not available, popular browsers and servers are slowly adopting HTTP/3. QUIC, unlike other revisions, is somewhat radical. The whole concept is to shift the entire protocol from TCP to &lt;strong&gt;UDP&lt;/strong&gt;! Yes, you read it right.&lt;/p&gt;

&lt;p&gt;Owing to some of the limitations of the underlying TCP at the transport layer, it became crucial to think of modifying that protocol. But then modifying TCP would have required changes in the entire internet infrastructure. Therefore, this new transport layer protocol is built upon UDP and inherits properties from TCP with modifications as needed.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*sQflnyUcKVFaGmagZ7GJrg.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;a href=&quot;https://datatracker.ietf.org/meeting/98/materials/slides-98-edu-sessf-quic-tutorial-00.pdf&quot;&gt;Courtesy&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To count a few limitations of TCP, wrt HTTP/2.0:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Connection establishment latency&lt;/strong&gt;: For a general TCP secure connection, it requires 2–3 RTT in handshakes whereas it can be done in 0–1 RTT in QUIC. It merges connection and encryption into a single handshake. If the client has talked to a given server before, it can start sending data without any round trip!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/1*lfXH5BHQt_ltGCq-KEvlUQ.gif&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;a href=&quot;http://cloudplatform.googleblog.com/&quot;&gt;Courtesy&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Encryption&lt;/strong&gt;: QUIC comes with encryption built into it and negotiates the terms in its only Handshake (TLS 1.3). Connections are encrypted from the beginning.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stream control&lt;/strong&gt;: In HTTP/2, wherein multiple streams utilise a shared connection, the underlying TCP has no idea of these streams. Consequently, the transport layer values them as consecutive payload sent by the application layer. This can cause some limitation such as &lt;strong&gt;Head of Line Blocking&lt;/strong&gt; wherein all the streams can be blocked until a previously on flight stream frame has not been received. This is essentially handled by bringing the pre-stream control to the underlying QUIC protocol.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Connection migration&lt;/strong&gt;: Switching networks in HTTP/2 would mean inflight packets being dropped and the need to establish a new connection (because a socket is identified using IP address port pair). This would be handled in QUIC using a 64-bit connection ID. This will help a server identify a client even when the client changes its IP address (like switching to Wi-Fi from a cellular network).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;QUIC streams, like HTTP/2 streams, share the same connection. Additional control over independent streams provides additional advantages. Streams can now arrive out of order among each other and are not affected by network packet loss of another stream. However, this has to lead the HPACK algorithm to be modified into &lt;strong&gt;QPACK&lt;/strong&gt; for HTTP/3, because this out of order delivery can cause some additional issues. QPACK uses separate unidirectional streams to modify and track header table state. The new HTTP/3 is built over this protocol. HTTP/3 streams simply run over QUIC streams. The semantics has not changed and is yet transparent to the application.&lt;/p&gt;

&lt;p&gt;Much of the work is yet to be finalised, and various implementations spring up similar to the draft proposal. Check the latest implementations of QUIC HTTP/3 &lt;a href=&quot;https://github.com/quicwg/base-drafts/wiki/Implementations&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;is-websockets-the-same-as-sockets&quot;&gt;Is WebSockets the same as Sockets?&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://tools.ietf.org/html/rfc6455&quot;&gt;WebSocket&lt;/a&gt;&lt;/strong&gt; is a communication protocol that allows clients(like browsers) and servers to communicate on a full-duplex channel over a long time over TCP Sockets. Being based on a persistent TCP Socket connection, any of the client or the server can send data at any time until the connection is broken from either of the parties. Think about building a chat application. Pinging Server continuously for checking for new messages would be a waste of bandwidth and resources. The server should be able to respond by itself when it gets new data to send. This also differentiates WebSockets from HTTP persistent connections.&lt;/p&gt;

&lt;p&gt;WebSockets and Network Sockets may sound similar but are quite different. While the latter is just a generic file descriptor to the file where the network writes the received data packets the former is a protocol built upon TCP Sockets. Network Socket, in general, is independent of the transport protocol(TCP or UDP).&lt;/p&gt;

&lt;p&gt;This protocol requires a handshake over the established TCP Socket connection. The Handshake is based on simple HTTP request-response and an upgrade header and other related fields.&lt;/p&gt;

&lt;p&gt;The handshake from the client looks as follows:&lt;/p&gt;

&lt;div class=&quot;language-http highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nf&quot;&gt;GET&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;/chat&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;HTTP&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;1.1&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Host&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;server.example.com&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Upgrade&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;websocket&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Connection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Upgrade&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Sec-WebSocket-Key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;dGhlIHNhbXBsZSBub25jZQ==&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Origin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;http://example.com&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Sec-WebSocket-Protocol&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;chat, superchat&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Sec-WebSocket-Version&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;13&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The handshake from the server looks as follows:&lt;/p&gt;

&lt;div class=&quot;language-http highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;HTTP&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;1.1&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;101&lt;/span&gt; &lt;span class=&quot;ne&quot;&gt;Switching Protocols&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Upgrade&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;websocket&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Connection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Upgrade&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Sec-WebSocket-Accept&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;s3pPLMBiTxaQ9kYGzzhZRbK+xOo=&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Sec-WebSocket-Protocol&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;chat&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If everything is fine, the connection is upgraded to a WebSocket connection after which any party can send data as required. Thereafter, the same connection is used for exchanging any further message. Various other control frames like PING, PONG, CLOSE are used to check/ close the connection&lt;/p&gt;

&lt;p&gt;There are various libraries available to abstract the working of WebSockets.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;🌟 Nailed the Basics! 🚀 Now, brace yourself for the exciting part – the promise of HTTP. Curious about the security dance? Dive into my next blog on HTTPS and TLS-SSL. The adventure continues! 💻🔒&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://medium.com/mobile-development-group/trust-tls-ssl-and-https-b925ac9d59?source=post_page-----9c6704e44a2a--------------------------------&quot;&gt;Trust! TLS-SSL and HTTPS&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;How is the HTTP traffic secured? What does that lock indicate? How do we establish trust? How can I say that indeed medium.com…&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;See you there!&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Simple Servers</title>
   <link href="https://dev-ritik.github.io/blog/2019/12/25/Simple-Servers/"/>
   <updated>2019-12-25T00:00:00+00:00</updated>
   <id>https://dev-ritik.github.io/blog/2019/12/25/Simple-Servers</id>
   <content type="html">&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/1200/0*0rW_QpMizH-BiO_v&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Buckle up for a swift journey! This blog is your ticket to setting up the most basic server on your computer. We’ll blend theory with easy-to-follow code explanations, breaking down the magic of socket-based servers. Get ready to unravel the secrets of the simplest sockets in no time! 🌐💡
&lt;!--break--&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h3&gt;

&lt;p&gt;A little knowledge of computer systems and some programming would be enough to understand the content. This blog ought to be one of your first blogs on networking and its architecture. An interest in the topic will be sufficient to move forward.&lt;/p&gt;

&lt;h2 id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;

&lt;p&gt;In this information age, where most, if not all the devices around us are getting connected, the internet stands as the most revolutionising technology used in our daily life, providing room for a great many opportunities.&lt;/p&gt;

&lt;p&gt;The internet is a network of a large number of devices connected and sharing information, together forming the WWW. This technology lays down the path to various computer science areas and sub-disciplines like cloud computing, IoT, Cybersecurity, web development…&lt;/p&gt;

&lt;p&gt;It all comes down to the basic knowledge of servers and clients and how the network works. In this blog, I shall be describing the simplest server-client communication based on sockets and how to get that public. So, let’s begin!&lt;/p&gt;

&lt;h3 id=&quot;servers-and-clients&quot;&gt;Servers and Clients&lt;/h3&gt;

&lt;p&gt;For those who don’t know, in the simplest case, a network connection between 2 devices generally involves a machine (&lt;strong&gt;server&lt;/strong&gt;) which provides functionality (help) to the other device (&lt;strong&gt;client&lt;/strong&gt;) in its operation. Typically, they communicate using requests and response.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:720/format:webp/1*swCmuUB-qMDfK-3ENHWKQQ.jpeg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Before moving ahead, Let me introduce the following terms:&lt;/p&gt;

&lt;h2 id=&quot;network-interface&quot;&gt;Network Interface&lt;/h2&gt;
&lt;p&gt;Communication between your computer and the network is through a network interface. Generally present in the form of a network interface card(NIC), virtual interfaces can also be implemented using software. Loopback Interface (mentioned below) is an excellent example of this. Use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ifconfig&lt;/code&gt; in Linux and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ipconfig&lt;/code&gt; in Windows for getting the list and details of the interfaces on your device. Generally, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wl/wlan&lt;/code&gt; represent &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wlan&lt;/code&gt; interface, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;eth/en&lt;/code&gt; represent &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ethernet&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lo&lt;/code&gt; represent the loopback virtual interface.&lt;/p&gt;

&lt;h2 id=&quot;sockets-and-ports&quot;&gt;Sockets and ports&lt;/h2&gt;
&lt;p&gt;OK! So we are ready for a connection, aren’t we?
&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*8ZWO1X3kOYj9JsuqYCRwTA.jpeg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;socket-port&quot;&gt;Socket-port&lt;/h2&gt;
&lt;p&gt;Well, every connection has two ends. And in our case, one is with the client, and one is with the server. At both the end, network writes the received data packets to a file dedicated for that particular connection. Sockets are the file descriptor to the file, which is used to write the data.&lt;/p&gt;

&lt;p&gt;Any application may be up at any time to communicate on the connection or establish new ones. Every program should naturally keep an eye on separate file descriptor on the same device. How to handle making separate files for each? and how would new requests from the same device or other be handled, so that they communicate with the exact application they want to? For this, we add a &lt;strong&gt;Port&lt;/strong&gt; number to the network address of the device to identify them separately. Thus, we get a unique &lt;strong&gt;address:port&lt;/strong&gt; combination to reach a particular address. It is like a set of (non-physical) channels where a process can dock to wait for new connections. This combination is called Socket address and is then used to identify separate sockets to identify the file to write data to. Evidently, the targeted application will be listening on the same socket. There are some standard port numbers which various server process take to listen to new requests. Have a look on this &lt;a href=&quot;https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers&quot;&gt;wiki&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;localhost&quot;&gt;Localhost&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:640/format:webp/1*FgamLzZwvdMEHnRMHA6_lw.jpeg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Just Localhost things!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Yo! this is where things get interesting! hmm…&lt;/p&gt;

&lt;p&gt;Say your server is ready to be used. You got to check if it is working before deployment! Now Localhost is how you can do so.&lt;/p&gt;

&lt;p&gt;As the name suggests, it is used to access network services running on the same device (thus fit for our use). What actually happens is that any request to the localhost isn’t forwarded to the external network interface, but to the &lt;strong&gt;Loopback interface&lt;/strong&gt;. So, we can request any process listening to a socket on the loopback address from the same device itself! The addresses &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;127/8&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;127.0.0.0&lt;/code&gt; - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;127.255.255.255&lt;/code&gt;) are bound to the loopback interface.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The word ‘localhost’ is mapped to &lt;strong&gt;127.0.0.1&lt;/strong&gt; for you already! (Look at the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/hosts&lt;/code&gt; file in Linux). Just set up your server to listen to any port* on the localhost and try pinging it!!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Moving further, there’s another interesting address: &lt;strong&gt;0.0.0.0&lt;/strong&gt;. It is the joker IP address where we do not want to specify a particular IP address for our connection. If any data directed to the computer (by any IP address) through any interface (including loopback) is received, you can listen to it via the ‘joker’ address, on the particular port. Thus, it can be used as an IP address in the server instead of any particular IP address from any interface. This will enable you to connect to your server from any device in all the network the device is connected.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Ports 1–1024 are privileged so don’t use them (or get &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;root&lt;/code&gt; permission).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;lets-get-our-hand-dirty&quot;&gt;Let’s get our hand dirty!&lt;/h2&gt;
&lt;p&gt;So, after much of the concepts, finally, it’s time to get to some code. I planned to provide the steps with their explanation! But I found resources like &lt;a href=&quot;https://www.geeksforgeeks.org/socket-programming-cc/&quot;&gt;this&lt;/a&gt; helpful as well. Meanwhile, you can have a look at some code explanation here.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://medium.com/media/21e0e25ed1f4adfd3980b3575322091d#server&quot;&gt;Server code&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://medium.com/media/95cfd1a94027dba6fee0af48d34df162#client&quot;&gt;Client Code&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Run the Server code in a terminal. The server will start waiting for a client request. Next, run the client code in a different terminal. If you had done it right, the server and the client must have exchanged their messages.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But broadly, the steps are as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Make a socket object providing various options and types and protocols.&lt;/li&gt;
  &lt;li&gt;bind to an interface or all.&lt;/li&gt;
  &lt;li&gt;Start listening to the socket and respond to incoming requests.&lt;/li&gt;
  &lt;li&gt;Read and Write to the socket file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/vishwasmittal/bare-socket?source=post_page-----cc465f340658--------------------------------&quot;&gt;vishwasmittal/bare-socket&lt;/a&gt;
    &lt;blockquote&gt;
      &lt;p&gt;Simple server and corresponding client written in bare sockets in multiple languages. The server should be written in…&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Simple implementation of Socket based server-client programs in multiple languages.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/dev-ritik/files_share?source=post_page-----cc465f340658--------------------------------&quot;&gt;dev-ritik/files_share&lt;/a&gt;
    &lt;blockquote&gt;
      &lt;p&gt;Web development proficiency. Contribute to dev-ritik/files_share development by creating an account on GitHub.&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;File sharing web and command-line app in C++ based on sockets.&lt;/p&gt;

&lt;h2 id=&quot;frameworks&quot;&gt;Frameworks&lt;/h2&gt;
&lt;p&gt;Well, Socket level programming is not done generally in the production servers. These are abstracted and handled by various popular frameworks developers use to build and deploy a production-grade web application to handle real-time traffic from users. While developing simple web applications you may not even know what’s going at the socket level and how connections are handled. Having a framework comes with lots of benefits apart from abstraction. They may be fast, scalable, secure and tested, well documented, have good community support, etc. Some of the leading frameworks of 2020 can be found &lt;a href=&quot;https://medium.com/front-end-weekly/10-most-popular-web-frameworks-in-2020-167b9103e08a&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;going-public&quot;&gt;Going Public&lt;/h2&gt;
&lt;p&gt;It’s quite cool and sometimes important to be able to access the server on your device from some other device. As such, it’s easy to do so. If you are not on a public-facing device (connected directly to the internet with public IP), you need to use some tricks to be available to anyone on the internet.&lt;/p&gt;

&lt;p&gt;For the former case, directly use 0.0.0.0 or your public IP address as the IP address to host your server. For the latter case, we can achieve the same within the private network. Host the server on 0.0.0.0 or the assigned private IP address of the device on the network*. Now on the new device (on the same private network), use that same private IP:port to access the service.&lt;/p&gt;

&lt;p&gt;To make your server public from a private network, have a look on how to do it through &lt;a href=&quot;https://stevessmarthomeguide.com/understanding-port-forwarding/&quot;&gt;Port Forwarding&lt;/a&gt;. You may be required to take the help of your ISP here. If that looks complex, you can use services like &lt;a href=&quot;https://ngrok.com/&quot;&gt;ngrok&lt;/a&gt; or &lt;a href=&quot;http://serveo.net/&quot;&gt;Serveo&lt;/a&gt;. They help to directly and simply do the task for you.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;*Use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ifconfig&lt;/code&gt; in Linux and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ipconfig&lt;/code&gt; in Windows for getting the private IP address.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;cli-utilities&quot;&gt;CLI Utilities&lt;/h2&gt;
&lt;p&gt;There are a bunch of useful utilities to test and interact with servers on the network. These include &lt;strong&gt;Ping&lt;/strong&gt;, &lt;strong&gt;Curl&lt;/strong&gt;, &lt;strong&gt;Wget&lt;/strong&gt;, etc.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Curl&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;curl localhost:8000
&amp;lt;HTML&amp;gt;
&amp;lt;Head&amp;gt;
&amp;lt;Title&amp;gt;Title: Bare Socket&amp;lt;/Title&amp;gt;
&amp;lt;/Head&amp;gt;
&amp;lt;Body&amp;gt;
 &amp;lt;center&amp;gt;
 &amp;lt;h1&amp;gt;
 Hello from server!
 &amp;lt;/h1&amp;gt;
 &amp;lt;/center&amp;gt;
&amp;lt;/Body&amp;gt;
&amp;lt;/HTML&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Wget&lt;/strong&gt;: Save the received HTML text into a file.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;wget localhost:8000
 — 2019–12–23 17:44:16 — http://localhost:8000/
Resolving localhost &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;localhost&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;… 127.0.0.1
Connecting to localhost &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;localhost&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;|127.0.0.1|:8000... connected.
HTTP request sent, awaiting response… 200 OK
Length: unspecified
Saving to: ‘index.html’
index.html &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &amp;lt;&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; 139 — .-KB/s &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;0s
2019–12–23 17:44:16 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;5.31 MB/s&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; — ‘index.html’ saved &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;139]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Being pretty simple in use, it’s good to try them all once.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;🚀 Ready to Conquer the Digital Frontier? This glimpse is just the beginning of your journey into Computer Networking and Services. Dive into my next blog on ‘HTTP &amp;amp; WebSocket’ for an even more thrilling ride. The tech adventure continues! 🌐💻&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href=&quot;https://medium.com/mobile-development-group/http-websockets-9c6704e44a2a?source=post_page-----cc465f340658--------------------------------&quot;&gt;HTTP &amp;amp; WebSockets&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;How are they connected to sockets? How is HTTP evolving? HTTP/2? HTTP/3? QUIC? Is WebSockets the same as Sockets?…&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>NpChat</title>
   <link href="https://dev-ritik.github.io/blog/2019/12/07/NpChat/"/>
   <updated>2019-12-07T00:00:00+00:00</updated>
   <id>https://dev-ritik.github.io/blog/2019/12/07/NpChat</id>
   <content type="html">&lt;h2 id=&quot;npchat-a-multimedia-sharing-application-over-ndn&quot;&gt;NpChat, a Multimedia Sharing Application over NDN&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/600/1*3eqaaYNrVBHPO3XG-uW1HQ.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;an NDN based multimedia sharing app&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;In a cyber universe dominated by giants like Google and Facebook, our everyday internet travels often lead to their massive servers. From E-commerce to Social Media and Web Streaming, it’s a giant corporation’s world, and we’re just browsing in it. But here’s the catch - our precious user data gets stored and played by their rules, often buried in the terms of service we hastily agree to.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But what if there’s another way? NpChat steps in as a practical, experimental alternative - a decentralized, end-to-end encrypted social multimedia app. No glorification, just a straightforward exploration into the possibilities of a more secure, user-centric design. Are you ready for a digital shift that puts control back in your hands? Let’s delve into the practicalities. 🚀🌐💻&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NpChat&lt;/code&gt; (from &lt;a href=&quot;https://en.wikipedia.org/wiki/Named_data_networking&quot;&gt;NDN&lt;/a&gt;+ Snapchat) is an Android application that allows users to capture and share multimedia with friends in a secure and fully &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;decentralised&lt;/code&gt; way, while still giving users complete control over their data. It is based on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Named Data Network&lt;/code&gt;, a proposed evolution of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IP&lt;/code&gt; architecture that uses data-names(identifiers) as a kind of address and not just IP addresses. NDN aims to change the network fundamentally from end to end communication to content-based, wherein, not only IP address but also the data identifier and only the identifier can also be used to exchange information. More on &lt;a href=&quot;https://named-data.net/project/archoverview/&quot;&gt;NDN&lt;/a&gt;
&lt;!--break--&gt;&lt;/p&gt;
&lt;h2 id=&quot;npchat&quot;&gt;NpChat&lt;/h2&gt;
&lt;p&gt;As NpChat is based on NDN, many of its concepts are blended into the app. As such, it may require further clarification of the idea.&lt;/p&gt;

&lt;p&gt;As the Network layer is different in NDN and IP, it requires specially designed libraries and technologies to work with. NDN has a lot of support &lt;a href=&quot;https://github.com/named-data&quot;&gt;libraries&lt;/a&gt; written in different languages actively developed to support application development. As NpChat is developed for Android, it uses java library &lt;a href=&quot;https://github.com/named-data/jndn&quot;&gt;jNDN&lt;/a&gt; and some C++ libraries via the native interface. To connect to an NDN network, it uses &lt;a href=&quot;https://play.google.com/store/apps/details?id=net.named_data.nfd&quot;&gt;NFD&lt;/a&gt; (an android app to use NDN over IP network). This daemon is required for NpChat to work and send/receive messages.&lt;/p&gt;

&lt;p&gt;Let’s get into the working of the app&lt;/p&gt;

&lt;h3 id=&quot;initialising&quot;&gt;Initialising&lt;/h3&gt;
&lt;p&gt;The app on it’s initialising does the following stuff:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Ensure NFD is installed and running in the background&lt;/li&gt;
  &lt;li&gt;Initialize Psync library using JNI and native code. More on Psync (partial state synchronisation protocol for NDN can be found &lt;a href=&quot;https://named-data.net/wp-content/uploads/2017/05/scalable_name-based_data_synchronization.pdf&quot;&gt;here&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Initialise the Psync partial producer. Register syncPrefix in NFD and sets internal filters for “sync” and “hello” under Prefix. Also, provide the prefixes available to synchronise&lt;/li&gt;
  &lt;li&gt;Initialise consumer manager and add consumer for each friend. Send a hello interest according to the Psync protocol and wait for the hello reply to synchronise further.&lt;/li&gt;
  &lt;li&gt;Make a new NDN Face&lt;/li&gt;
  &lt;li&gt;Make new &lt;strong&gt;AndroidSqlite3Pib&lt;/strong&gt; object to help with SQLite for using &lt;a href=&quot;https://named-data.net/doc/ndn-ccl-api/security/pib.html&quot;&gt;PIB&lt;/a&gt; NDN to store public keys&lt;/li&gt;
  &lt;li&gt;Make new &lt;strong&gt;TpmBackEndFile&lt;/strong&gt; object to store and access private keys and provide its location to AndroidSqlite3Pib object&lt;/li&gt;
  &lt;li&gt;Make a new &lt;strong&gt;KeyChain&lt;/strong&gt; object to help provide a set of interfaces to the security library&lt;/li&gt;
  &lt;li&gt;Fetch/generate the pub key for the user namespace in the app using the keychain object and store the PIB key and related identity and certificates.&lt;/li&gt;
  &lt;li&gt;Set the signing information for the face using the keychain and the generated certificate for the name&lt;/li&gt;
  &lt;li&gt;Set up the custom &lt;strong&gt;memory cache&lt;/strong&gt; object to help serve data to interests after it’s not in the cache (like after app restart).&lt;/li&gt;
  &lt;li&gt;Register names to NFD for receiving and responding to incoming interests for data. Interests may be of data, file, cert, friends, network-discovery, discover, etc. While others are for the general exchange of data and certificates, network-discovery is used to find out other instances of NpChat and publish our namespace address to them.&lt;/li&gt;
  &lt;li&gt;Start network discovery using NFD multicast discovery, NSD (DNS-SD), and send network-discovery get and establish named routes to other users.&lt;/li&gt;
  &lt;li&gt;Call &lt;strong&gt;processEvents&lt;/strong&gt; on a separate network thread and loop it continuously.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With these things set up, the user can now interact with the app and send and receive media. But before doing that, he has to make friends.&lt;/p&gt;

&lt;h3 id=&quot;friends&quot;&gt;Friends&lt;/h3&gt;
&lt;p&gt;Akin to the real world, making friends on NpChat also requires trust among the two parties. Trust in this context is the acceptance and verification of the signed data from the other party. This means that we accept the public key to be of that particular user. The acceptance of this public key involves various trust models as proposed and implemented in the app.&lt;/p&gt;

&lt;p&gt;During the process of making friends (or building trust), they exchange their public keys. Once two users accept their friendship, they issue certificates to each other by signing the new friend’s key. The certificate is designed to certify the user to own a namespace (in this case, for the app).&lt;/p&gt;

&lt;p&gt;So the main problem in a non-centralised app like this is to get suggested potential friends-list so that we can add new friends. Without a central list of available users, this is a rather challenging job. So, to discover and trust new users to be a new friend, the app uses:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Physical&lt;/strong&gt; certificate exchange through QR exchange&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mutual Friend&lt;/strong&gt;’s friend list: User can share his list of trusted friends with their friends so a user can have a list of potential friends&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Domain&lt;/strong&gt;: A user can easily trust and find other users from the same organisation, part of their namespace&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;media-sharing&quot;&gt;Media Sharing&lt;/h3&gt;
&lt;p&gt;Taking another look in the feed based sharing, it is evident that a user subscribes to friends feed. Once a friend publishes a piece of information, it is published to all his friend (who has subscribed to his feed). NpChat uses partial sync mode in PSync to realise this pub-sub functionality. Psync is designed to inform the consumers of a new piece of data produced. The friend can then request the producer (in the form of interest) to get that data back. Also, while logging into the app, a user can sync his state with that of the producer. This will get the latest data from him.&lt;/p&gt;

&lt;h3 id=&quot;access-control&quot;&gt;Access Control&lt;/h3&gt;
&lt;p&gt;A user in NpChat may share a piece of data with a particular user or a group of user he wants to. Unless we encrypt the data, every user on NDN can access it, given he knows its unique name. This possesses a significant challenge to privacy. So to allow only a certain number of people to access a particular data, NpChat uses both Asymmetric and Symmetric key encryption.&lt;/p&gt;

&lt;p&gt;As mentioned above, NpChat user stores the public keys of his friend upon adding him as a friend. The data to be sent is encrypted using a symmetric key (content key). To send the data, NpChat sends SyncData (metadata) to all the friend through Psync. This SyncData is itself encrypted by the selected friend’s public key. Upon receiving this information, each recipient in the set of authorised friends fetches both the filename and the encrypted content key, decrypts the content key and then decrypts the data using the content key. Even if an unauthorised friend retrieves the encrypted data, he/she will not be able to decrypt the content key and thus cannot decrypt the data.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;For more and detailed description of the app, head over to the reference paper and the code repository.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;reference&quot;&gt;Reference&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://dl.acm.org/citation.cfm?doid=3357150.3357402&quot;&gt;http://dl.acm.org/citation.cfm?doid=3357150.3357402&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;way-ahead&quot;&gt;Way Ahead&lt;/h2&gt;
&lt;p&gt;As of now, NFD is available on the play store, and NpChat is almost ready to be released. The source code of the app is available under GNU GPL v3.0 &lt;a href=&quot;https://github.com/named-data-mobile/ndn-photo-app&quot;&gt;here&lt;/a&gt;. The primary work is done, and the app can be used to share data in a local network. Some of the considerable work left, for the app to be done effectively are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Improving the user interface&lt;/li&gt;
  &lt;li&gt;Connecting with the NDN Testbed&lt;/li&gt;
  &lt;li&gt;Managing Groups&lt;/li&gt;
  &lt;li&gt;Enhancing user discovery&lt;/li&gt;
  &lt;li&gt;Handling edge cases&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;among others. More information on this can be found &lt;a href=&quot;https://redmine.named-data.net/projects/npchat/issues&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>GSoC NDN 2019 Report</title>
   <link href="https://dev-ritik.github.io/blog/2019/08/25/GSoC-2019-Report/"/>
   <updated>2019-08-25T00:00:00+00:00</updated>
   <id>https://dev-ritik.github.io/blog/2019/08/25/GSoC-2019-Report</id>
   <content type="html">&lt;h1 id=&quot;android-app-improvement&quot;&gt;Android App Improvement&lt;/h1&gt;

&lt;h2 id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/named-data-mobile/ndn-photo-app&quot;&gt;NpChat&lt;/a&gt; is a photo and file-sharing application built on Android and is inspired by Snapchat. It runs over the Named Data Network (NDN) and focuses on decentralised information sharing architecture. It stands as one of the best examples of Android application developed on the new Internet architecture.&lt;/p&gt;

&lt;p&gt;The project description can be found &lt;a href=&quot;https://named-data.net/gsoc-2019/#npchat&quot;&gt;here&lt;/a&gt;. During Google Summer of Code 2019, I contributed to the project and developed several features to improve the NpChat app, its supporting library(&lt;a href=&quot;https://github.com/named-data/jndn&quot;&gt;Jndn&lt;/a&gt;) and the &lt;a href=&quot;https://github.com/zhtaoxiang/android-identity-manager&quot;&gt;Identity Manager&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;work&quot;&gt;Work&lt;/h2&gt;

&lt;p&gt;During the GSoC period, I worked on the following,
&lt;!--break--&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;b&gt;Replaces FaceProxy with Memorycache&lt;/b&gt; (&lt;a href=&quot;https://github.com/named-data-mobile/ndn-photo-app/pull/132&quot;&gt;#132&lt;/a&gt;) : Replaced &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FaceProxy&lt;/code&gt; (which used to store and serve data for interests) class with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Memorycache&lt;/code&gt; class which uses &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MemoryContentCache&lt;/code&gt; (from  the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jNDN&lt;/code&gt; library).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;b&gt;Aimd pipelining in Segment fetcher&lt;/b&gt; (&lt;a href=&quot;https://github.com/named-data/jndn/pull/24&quot;&gt;#24&lt;/a&gt;) : Updated &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SegmentFetcher.java&lt;/code&gt; from the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jndn&lt;/code&gt; library to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AIMD&lt;/code&gt; pipe-lining in place of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fixed&lt;/code&gt; window fetching. Ran some tests on &lt;a href=&quot;https://github.com/named-data/mini-ndn&quot;&gt;minindn&lt;/a&gt; to compare these strategies among the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jNDN&lt;/code&gt; and &lt;a href=&quot;https://github.com/named-data/ndn-cxx&quot;&gt;ndn-cxx&lt;/a&gt; libraries, the most recent of the results can be found &lt;a href=&quot;https://docs.google.com/spreadsheets/d/1I11AvNxdttPvftFzk0DF_G650LGNkjGsK21mcumsysU/edit?usp=sharing&quot;&gt;here&lt;/a&gt;. After a long review period and a list of changes, it was successfully merged.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;b&gt;Introduce MVVM architecture&lt;/b&gt; (&lt;a href=&quot;https://github.com/named-data-mobile/ndn-photo-app/pull/161&quot;&gt;#161&lt;/a&gt;) : The state of the code at that point was more or less ad-hoc with things like memory and network access specific code placed and used in the view itself against the encouraged application architecture patterns like MVVM. This Pull Request moved and reorganised the code to single Activity multiple Fragment MVVM architecture, with operation logics separated and organised into classes and packages.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;b&gt;Add location co-ordinates to pictures&lt;/b&gt; (&lt;a href=&quot;https://github.com/named-data-mobile/ndn-photo-app/pull/162&quot;&gt;#162&lt;/a&gt;) : Added a feature to let user geo-tag a picture. Once Geo-tagged, the location is shared by adding the co-ordinates into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Exif&lt;/code&gt; metadata and transformed to ground address using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Geocoder&lt;/code&gt; class.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;b&gt;File sharing&lt;/b&gt; (&lt;a href=&quot;https://github.com/named-data-mobile/ndn-photo-app/pull/163&quot;&gt;#163&lt;/a&gt;) : Improved the pictures sharing and file browsing experience and separated them into status and files, to be viewed differently.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;b&gt;NDNCert java client&lt;/b&gt; (&lt;a href=&quot;https://github.com/zhtaoxiang/android-identity-manager/pull/1&quot;&gt;#1&lt;/a&gt;): For the users to have a namespace, they must have a certificate for it. Previously, a self-signed certificate was used to verify the ownership. This PR updates the &lt;a href=&quot;https://github.com/zhtaoxiang/android-identity-manager&quot;&gt;Android Identity Manager&lt;/a&gt; to get signed certificates of the namespace using &lt;a href=&quot;https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.2&quot;&gt;NDNCERT&lt;/a&gt;. This will be used to prove the ownership using the trust agent.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;gsoc-contribution&quot;&gt;GSoC contribution&lt;/h2&gt;
&lt;p&gt;Here is a list of all contribution made during the GSoC period.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;(&lt;a href=&quot;https://github.com/named-data-mobile/ndn-photo-app/pull/132&quot;&gt;#132&lt;/a&gt;) Replaces FaceProxy with Memorycache&lt;/li&gt;
  &lt;li&gt;(&lt;a href=&quot;https://github.com/named-data-mobile/ndn-photo-app/pull/134&quot;&gt;#134&lt;/a&gt;) Removes publishData code from FilesActivity&lt;/li&gt;
  &lt;li&gt;(&lt;a href=&quot;https://github.com/named-data-mobile/ndn-photo-app/pull/154&quot;&gt;#154&lt;/a&gt;) Replace Log with Timber&lt;/li&gt;
  &lt;li&gt;(&lt;a href=&quot;https://github.com/named-data-mobile/ndn-photo-app/pull/155&quot;&gt;#155&lt;/a&gt;) Add AboutActivity&lt;/li&gt;
  &lt;li&gt;(&lt;a href=&quot;https://github.com/named-data-mobile/ndn-photo-app/pull/161&quot;&gt;#161&lt;/a&gt;) Introduce MVVM architecture&lt;/li&gt;
  &lt;li&gt;(&lt;a href=&quot;https://github.com/named-data-mobile/ndn-photo-app/pull/162&quot;&gt;#162&lt;/a&gt;) Add location co-ordinates to pictures&lt;/li&gt;
  &lt;li&gt;(&lt;a href=&quot;https://github.com/named-data-mobile/ndn-photo-app/pull/163&quot;&gt;#163&lt;/a&gt;) Picture selection&lt;/li&gt;
  &lt;li&gt;(&lt;a href=&quot;https://github.com/named-data/jndn/pull/24&quot;&gt;#24&lt;/a&gt;) Aimd pipelining in Segment fetcher&lt;/li&gt;
  &lt;li&gt;(&lt;a href=&quot;https://github.com/named-data/jndn/pull/25&quot;&gt;#25&lt;/a&gt;) Fix null object error in AIMD SegmentFetcher&lt;/li&gt;
  &lt;li&gt;(&lt;a href=&quot;https://github.com/zhtaoxiang/android-identity-manager/pull/1&quot;&gt;#1&lt;/a&gt;) Ndncert java&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These PRs spans accross &lt;a href=&quot;https://github.com/named-data-mobile/ndn-photo-app/pulls?q=is%3Apr+is%3Aclosed+author%3Adev-ritik+sort%3Acreated-asc&quot;&gt;NpChat&lt;/a&gt;, &lt;a href=&quot;https://github.com/named-data/jndn/pulls?q=is%3Apr+is%3Aclosed+author%3Adev-ritik&quot;&gt;jndn&lt;/a&gt; and &lt;a href=&quot;https://github.com/zhtaoxiang/android-identity-manager/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc+author%3Adev-ritik&quot;&gt;android-identity-manager&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;todo&quot;&gt;TODO&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Publishing the app to Play Store.&lt;/li&gt;
  &lt;li&gt;Adding ECDH key encryption to android-identity-manager.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;challenges&quot;&gt;Challenges&lt;/h2&gt;
&lt;p&gt;As a part of the project, I faced some challenges, which gave me experiences in new fields&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Moving to decentralised from the popular centralised server model.&lt;/li&gt;
  &lt;li&gt;The nature of the work (pretty much new and unprecedented).&lt;/li&gt;
  &lt;li&gt;Establishing and updating development environments and NDN dependencies.&lt;/li&gt;
  &lt;li&gt;Trying to establish ECDH key exchange.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;future-works&quot;&gt;Future Works&lt;/h2&gt;
&lt;p&gt;I plan to continue working on the NDN concept, developing and contributing to open-source application and utilities, in the days to come.&lt;/p&gt;
</content>
 </entry>
 

</feed>
