<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Victor Basumatary on Medium]]></title>
        <description><![CDATA[Stories by Victor Basumatary on Medium]]></description>
        <link>https://medium.com/@vlence?source=rss-57fbea1a3896------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ypmdK2JBsIvNcQOnQaY4qQ.png</url>
            <title>Stories by Victor Basumatary on Medium</title>
            <link>https://medium.com/@vlence?source=rss-57fbea1a3896------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 14:22:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vlence/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Today I Completed Our Cloud Infrastructure — 1 — Network]]></title>
            <link>https://medium.com/@vlence/today-i-completed-our-cloud-infrastructure-1-network-741ae80f38c6?source=rss-57fbea1a3896------2</link>
            <guid isPermaLink="false">https://medium.com/p/741ae80f38c6</guid>
            <category><![CDATA[high-availability]]></category>
            <category><![CDATA[redundancy]]></category>
            <category><![CDATA[vpc]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Victor Basumatary]]></dc:creator>
            <pubDate>Thu, 12 Sep 2019 11:37:07 GMT</pubDate>
            <atom:updated>2020-07-26T09:15:10.261Z</atom:updated>
            <content:encoded><![CDATA[<h3>Today I Completed Our Cloud Infrastructure — 1 — Network</h3><blockquote>No network no infra.</blockquote><p><em>This is a multi-part blog post which will be discussing how I built the first version of our cloud infrastructure. The articles have been split up into the following topics:</em></p><ol><li><em>Network (you are here)</em></li><li><em>Compute/Storage/Delivery</em></li><li><em>Tooling</em></li></ol><p><em>I will be taking the liberty to explain the different concepts and terms that we come across along the way. If you already understand these terms and concepts feel free to skim them over.</em></p><p>Date: 11 September, 2019<br>Location: Mumbai<br>Weather: Doom and gloom</p><p>I work for <a href="https://www.intown-solutions.com/">InTown Solutions</a>. We’re a small company based in Shillong, India, and came into existence about five years ago. I’ve been working here for 3 years now as I’m writing this. We primarily serve our customers by building websites for them.</p><h3>How it began</h3><p>My primary role here is R&amp;D, as in I experiment with technologies, but I’m also responsible for a lot of our backend development, both for client projects and internal projects. When our company started my Boss bought a VPS in GoDaddy and we have been using it since. GoDaddy is great as a DNS provider but I wouldn’t recommend them if you want compute capacity.</p><p>For those who don’t know, a VPS is basically a virtual machine. Virtual machines allow you to run multiple instances of an operating system on a single computer/server simultaneously, and so it’s a great way for service providers like GoDaddy to share their compute capacity (CPU cores and RAM) among their clients.</p><figure><img alt="A picture comparison of a home computer running one operating system and a server running multiple virtual machines." src="https://cdn-images-1.medium.com/max/741/1*ykHY3jRfEmD5G2C9Wl7-9g.png" /><figcaption>You’re one of the green Linux boxes</figcaption></figure><p>Over time we had so many websites in our VPS that it started to run slow. 10–20 seconds blank white screen slow. My Boss approached me earlier this year with this problem and asked what we should do.</p><p>Now this is a very well known and well studied problem. The two most used solutions are:</p><ol><li>Vertical scaling— buy more CPU cores and RAM</li><li>Horizontal scaling— buy another VPS and load balance between them</li></ol><p>Both solutions work and are very easy to implement but are they worth our money? In their simple forms, no.</p><p>Our problem, like any other problem, was multi-faceted.</p><ol><li>It was a VPS. You had to manage everything yourself. OS patches, security updates, firewalls, database, etc.</li><li>Our VPS had been hacked before and visitors to our sites were redirected to spurious websites. This eroded our trust in GoDaddy’s security.</li><li>We don’t have many backend developers and sysadmins and so cost of management and troubleshooting, if something goes wrong in the backend, is VERY high.</li><li>What happens when we have too many sites again? Buy another VPS? Buy more RAM and CPU cores? How many moving parts can we manage?</li></ol><h3>The Cloud</h3><p>Two years ago I read about AWS. I didn’t really understand what it was but it seemed interesting. Over time, after reading its documentation and actually using it, I began to understand what it was and what it could mean to us. It was genius.</p><p>AWS stands for Amazon Web Services. Yes, the same Amazon where you shop online. Turns out it isn’t easy to run amazon.com and so they had to hire a lot of genius engineers who worked tirelessly to optimize their data centers and the applications that run in them. They soon realized that the software they had built could be sold as services to other people and organizations who had similar needs. And thus AWS was born. Fun fact — Amazon makes about half, or more, of its profits from AWS.</p><p>What is AWS? AWS offers what they like to call “AWS Services”. These services are web applications which allow you to build, deploy and manage your applications and their infrastructure without worrying about provisioning servers, storage capacity, etc. All in all you can think of AWS as your very own virtual data center. You can have this virtual data center in one place or several places across the globe. They can all be the same or all be very different, it’s up to you.</p><p>I decided that we should use AWS. In this article we will discuss one of the key components in our cloud infrastructure — the network. We will discuss the different AWS services and their features that I used while building the network and why I made certain choices.</p><h3>The Network</h3><p>If you are going to build a data center, or a virtual one, the first thing you need to think about is the network. The network is what allows your applications and the internet to talk with each other. This makes it one of the most important, and dangerous, pieces of your infrastructure.</p><figure><img alt="A rectangle with a dashed border representing a VPC. This VPC uses a CIDR range of 10.0.0.0/16" src="https://cdn-images-1.medium.com/max/474/1*vNWK32_LSB20nefamJpchQ.png" /><figcaption>Your VPC</figcaption></figure><p>Designing networks is difficult but AWS removes some of the pain by allowing you to create virtual networks, which behave almost the same as physical networks. This is possible through their service called VPC — Virtual Private Cloud. Using VPC you can launch a virtual network with your own private IP space.</p><p>The number at the bottom right is the private IP range of the VPC. This style of describing a range of IP addresses is called CIDR (Classless Inter-Domain Routing) notation, where you write an IP address followed by a slash and a number from 0 to 32.</p><h4>CIDR</h4><p>An IP address consists of 4 numbers separated by dots. Each number uses 8 bits, so an IP address uses a total of 32 bits. If all the bits were 0 your IP address would be 0.0.0.0, and if all the bits were 1 your IP address would be 255.255.255.255. From this it is clear that any of the four numbers can be 0 at the least or 255 at the most. That’s a little more than 4 billion unique IP addresses.</p><p>Our example VPC above is using all IP addresses from 10.0.0.0 to 10.0.255.255. Notice that the first two numbers are the same — 10.0. We have two numbers, so that’s 16 bits. 16 is the number to the right of the slash. I think you can see the connection. The CIDR notation above can be read as follows:</p><blockquote>I want all IP addresses, starting from 10.0.0.0, keeping the leftmost 16 bits fixed.</blockquote><h4>Private and public IP ranges</h4><p>Did I randomly decide to use 10.0.0.0/16? No.</p><p>We know that IP addresses can be anywhere from 0.0.0.0 to 255.255.255.255 so how do we decide who uses what IP address? Do we have the liberty to randomly select any IP address we like and everyone just agrees? No.</p><p>The IANA is the organization which decides what different IP addresses can be used for. And it has decided to label some ranges of IP addresses as private, and others as public. A private IP range is one whose addresses CANNOT be used to access resources over the internet and a public IP range is one whose addresses MUST be used to access resources over the internet. Let’s look at the private IP ranges:</p><ol><li>10.0.0.0/8</li><li>172.16.0.0/12</li><li>192.168.0.0./16</li></ol><p>In simple terms you can be sure that websites on the internet will not be using any IP address that fall within any of the ranges above. Similarly, within your own home or office network you can be sure that all devices will be assigned an IP address from one of the ranges above.</p><h4>Subnets</h4><p>A VPC by itself is not very useful. What makes it useful are subnets. A subnet is a smaller range of IP addresses within your VPC’s range of IP addresses. It is inside a subnet that you can launch your applications and other resources like virtual machines and databases.</p><figure><img alt="Our VPC diagram now has 6 subnets inside it. The first two subnets are green, the next two are blue and the last two are red." src="https://cdn-images-1.medium.com/max/614/1*DkKmYVkzXEj59EXjBLJBwQ.png" /><figcaption>6 subnets. Wow.</figcaption></figure><p>I need to deviate a little bit and explain to you how exactly AWS lays out its data centers. AWS data centers are located in “regions”. A region is a geographic location, like Mumbai and Sydney. Within a region there are at least two Availability Zones (AZ). Each AZ has at least one data center.</p><p>Each AZ has its own compute, storage and networking infrastructure, along with backup power. All AZs within a region are interconnected via a proprietary low latency network. AZs are highly available because each AZ has a different power and internet connectivity supplier. You can read more about AWS’ global infrastructure <a href="https://aws.amazon.com/about-aws/global-infrastructure/">here</a>.</p><p>So what has all this got to do with our network? Our network can span an entire AWS region. This is made possible by launching our subnets into different AZs.</p><figure><img alt="Our VPC diagram now depicts AZs as rectangles within them. Within each AZ are three subnets — public, private and isolated." src="https://cdn-images-1.medium.com/max/627/1*yB1kLCjONetZo2rhQtTh7A.png" /><figcaption>Each AZ has one of each type of subnet</figcaption></figure><p>This effectively means we can have multiple instances of our applications and resources running in separate physical locations which are completely isolated from each other — the essence of high availability. If an AZ goes down your application can still keep chugging along, required that you designed your application with high availability in mind.</p><p>You will have noticed that I colored the subnets with different colors. This is for a reason. A subnet can be thought of as a logical unit of our network — it has a purpose and an intended use. Subnets usually fall into three main categories:</p><ol><li><strong>Public subnets (green)<br></strong>Applications and resources launched in public subnets can reach the internet and the internet can reach them.</li><li><strong>Private subnets (blue)<br></strong>Applications and resources launched in private subnets can reach the internet but the internet cannot reach them.</li><li><strong>Isolated subnets (red)<br></strong>Applications and resources launched in isolated subnets cannot reach the internet and the internet cannot reach them.</li></ol><h4>Public subnets</h4><p>When a resource is placed within a subnet that resource receives a private IP address — it is taken from the subnet’s CIDR range. Applications within a network speak with each other by sending each other packets. Packets, in general, consist of the source IP address, the destination IP address and some data. Subnets know where to send packets by looking up the destination IP address in their route table. A route table is kinda like an address book — name and address.</p><p>By default all subnets within the same network know how to route among themselves. This means that they all have each other in their route tables. What does that route look like?</p><blockquote><strong>10.0.0.0/16 </strong>→local</blockquote><p>This reads as follows:</p><blockquote>If the destination IP address is within 10.0.0.0/16 then forward the packets to the resource with the same IP address as the destination IP address within our network.</blockquote><p>The CIDR range on the left is called the destination and the text on the right is called the target. Public subnets allow applications within it to reach the internet. But the internet has many IP addresses… How do you route packets to their correct targets on the internet? You only need one route.</p><blockquote><strong>0.0.0.0/0</strong> →igw</blockquote><p>How 0.0.0.0/0 translates to all internet IP addresses is an exercise I leave to you.</p><p>The <em>igw</em> here is an Internet Gateway. An Internet Gateway knows how to route packets to their correct destination on the internet, so to route packets from within our subnets to the internet it is sufficient to route it to the Internet Gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*AWggL254nu4WY_FtvFbaPw.png" /></figure><p>Therefore, a public subnet in AWS is one which routes 0.0.0.0/0 to an Internet Gateway.</p><p>Our public subnets are doing half their job now. Next, the resources within the public subnets must themselves be reachable by the internet. Recall that resources within a subnet always receive a private IP address. Likewise resources can also receive a public IP address. If a resource within a public subnet receives a public IP address it automatically becomes reachable by the internet.</p><h4>Private subnets</h4><p>Private subnets allow applications and resources within it to reach the internet but doesn’t allow the internet to reach them. From our discussion above it seems that all we need to do is simply route 0.0.0.0/0 from our private subnets to the IGW and not give the resources within it a public IP address, right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*201kxwd9wp39B8Tn20wrxA.png" /><figcaption>Is this correct?</figcaption></figure><p>This does not work. Let’s wind back a bit and look at packets again. Packets contain some data, the source IP address and the destination IP address. The source IP address is where the data is coming from and the destination IP address is where the data should be delivered.</p><figure><img alt="A packet consisting of the header and the data. The header has the source and destination IP addresses." src="https://cdn-images-1.medium.com/max/364/1*LCk_auIIJzKLb1u0MNGusw.png" /><figcaption>Packets, oversimplified</figcaption></figure><p>When you search for something in google.com the results come back to you. How does google.com know it needs to send back the response to you? The answer lies in the source IP address that is being sent in the packets going to google.com.</p><p>Now consider this, your application is within a private subnet so all it has is a private IP address. What will the source IP be? A private IP address. Can then the responding application send back a response? No, because private IP addresses are never accessible over the internet.</p><p>So what we need then is a public IP address so that our applications within the private subnet can correctly work. Do we then assign public IP addresses to the resources within our private subnet? No, because that would defeat the purpose of a private subnet and also, it wouldn’t be a private subnet anymore.</p><h4>NAT</h4><p>Network Address Translator (NAT) devices can change the source IP address of outgoing packets and the destination IP address of incoming packets. Your router at home is also a NAT device. What makes such devices very useful is that these devices can take packets whose source IP address is a private IP address, replace it with a public IP address and send it on its way.</p><p>NAT devices provide us with the one-way connection to the internet that we want in private subnets. The reason this is possible is because NAT devices rely on information in outgoing packets to correctly route incoming packets to the correct destination.</p><p>Consider your web browser and the router in your home. Your router has assigned your computer a private IP address but because your router is connected to the internet, your router has a public IP address. This public IP address is shared with all devices connected to your router.</p><p>When you visit google.com your router identifies the device and application the request is being sent from and establishes a unique connection with the intended destination — google.com. Before sending the packets your router will overwrite the source IP address with the public IP address assigned to it — that’s how devices “share” the same public IP address as your router. To google.com the connection is coming from your router, NOT your device. When google.com sends back the response your router knows where to redirect it because it established a unique connection.</p><p>Because NAT devices need at least two pieces of information — the device and application — to correctly route packets to hosts within your network, it is impossible for hosts outside your network to directly reach applications behind a NAT by using a public IP address because there just isn’t enough information in the incoming requests.</p><p>AWS offers such virtual devices, called NAT Gateways. NAT Gateways are deployed into public subnets, which give them a public IP, and private subnets route their internet traffic to these NAT Gateways.</p><blockquote><strong>0.0.0.0/0</strong> →nat</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*pqe01ZlXtqYCJnDYv5EZyw.png" /><figcaption>This will work</figcaption></figure><h4>Security</h4><p>One great thing about AWS is their state of the art security measures and how much they give their customers for free. For example, all AWS customers receive free DDoS protection against the most common DDoS attacks. And wherever AWS doesn’t offer something themselves, they make it easy for you add the security measures yourself.</p><p>The network architecture we built is an industry standard best practice. Not all your resources and applications need to be accessible by the internet or even need to access the internet.</p><p>Let’s discuss isolated subnets first. Isolated subnets are unique in that there is no connection with the internet, whatsoever. This makes them very suitable for hosting databases and other storage devices/applications. By keeping your data disconnected from the internet you immediately make it very difficult for it to be stolen. Notice I said difficult, not impossible.</p><p>What about applications like websites? Public subnets? They need to be accessible by the internet right? No. You keep such applications in private subnets. We know that in our architecture above it will be impossible for anyone on the internet to access a website in a private subnet directly, so how does this work?</p><p>Just like how a NAT device sits between private subnets and the internet, a reverse proxy or load balancer sits between your website and the internet. Consider google.com again. When you visit google.com what are you actually connecting to? The google.com website or a load balancer sitting in front of it? The load balancer. Load balancers are a necessity when you serve high traffic applications.</p><figure><img alt="An example multi-tier application. Applications are hosted in private subnets while databases are hosted in isolated subnets." src="https://cdn-images-1.medium.com/max/606/1*7XMbQhmN1bWRLLqtgsRcbQ.png" /><figcaption>A typical modern multi-tier application</figcaption></figure><p>The diagram above may look messy but that’s really a simplified version of how many modern applications are designed.</p><p>So far we have discussed how we have limited access from the internet to our internal resources but what about access among internal resources? Surely you can trust them all because you control them all, right? No.</p><p>Looking at the diagram above we can see that the database instances are being accessed by the application through a load balancer. Suppose the load balancer sitting in front of the application was compromised. Does it immediately have access to our database instances? In our current setup, yes. Recall that subnets within the same VPC can speak to each other.</p><p>One of the simplest ways to mitigate such attacks is to use firewalls. In our example that would mean that the database instances will only accept connections coming from the load balancer in front of them, and the load balancer will only accept connections coming from the application. Likewise, the application instances too will only accept connections coming from the load balancer in front of them.</p><p>Using firewalls is recommended but it is also manual and must be repeated for every application that we deploy. There are, however, several conveniences available that enable us to do that painlessly. We can, additionally, use a VPC feature called Network Access Control Lists (Network ACLs).</p><figure><img alt="Using Network ACLs to control traffic as follows: internet ↔ public ↔ private ↔ isolated" src="https://cdn-images-1.medium.com/max/638/1*h_OEZmWfZ7H0AgEKOsN8dQ.png" /><figcaption>Example Network ACL setup</figcaption></figure><p>Network ACLs are attached to subnets and decide which packets are allowed to enter or leave the subnet. In the example above there are three Network ACLs associated with the three different types of subnets.</p><ol><li>The Network ACL associated with the public subnets allow incoming packets from the internet and allow all outgoing packets to the internet and private subnets.</li><li>The Network ACL associated with the private subnets allow incoming packets from the public subnets and allow all outgoing packets to the public subnets and isolated subnets</li><li>The Network ACL associated with the isolated subnets allow incoming packets from private subnets and allow outgoing packets to the private subnets.</li></ol><p>You should use Network ACLs and firewalls together. Network ACLs decide which traffic is allowed and firewalls decide which applications can speak with each other and how.</p><p>Networks and their security are one time investments. You do not need to build a separate network for each application that you build. By using the same network across all applications</p><h3>Conclusion</h3><p>We have discussed terms and concepts involved in building a virtual network in AWS and how to secure it. The network I built was built in a very similar manner. The security measures I talked about are only some of the things you should be doing — you can never have too much security.</p><p>In the next article we will be discussing how we’re using this network to launch WordPress websites as Docker containers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=741ae80f38c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Today I Learnt Myself An Async/Await]]></title>
            <link>https://medium.com/@vlence/today-i-learnt-myself-an-async-await-c03188fd2db0?source=rss-57fbea1a3896------2</link>
            <guid isPermaLink="false">https://medium.com/p/c03188fd2db0</guid>
            <dc:creator><![CDATA[Victor Basumatary]]></dc:creator>
            <pubDate>Sun, 08 Sep 2019 18:58:18 GMT</pubDate>
            <atom:updated>2019-09-09T02:02:15.295Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>It’s 2019… What took you so long?!</blockquote><p>Yeah yeah yeah… Whatever. I’m lazy.</p><p>Date: 8 September 2019<br>Location: Mumbai, India<br>Weather: Rainy</p><p><strong>WARNING</strong>: Not a tutorial</p><p>Some time earlier this year my Boss™ asked me to give him something better than the VPS we had running on GoDaddy. We have many WordPress sites running on that thing and it hasn’t aged very well.</p><p>I found AWS a few years ago and fell in love with it. Ever since then I’ve been dreaming about building a cloud infrastructure for our company, one which was robust and easy enough for everyone to use. And now’s my chance, to begin at least.</p><p>I thought and thought and thought and decided that we needed:</p><ol><li>A virtual network which would have public, private and isolated subnets</li><li>Autoscaling compute capacity for WordPress containers</li><li>Traefik</li><li>CloudFront</li></ol><p>I built a clunky prototype in about two months’ time. It was functional but I wasn’t happy with it so it was back to the drawing board. There were several flaws with my design and the most glaring one was that you had to wait about 15–30 mins when deploying a WordPress site because a CloudFront distribution was being deployed alongside the website. Also you had no temporary domain for the site besides the distribution’s domain. A temporary domain is needed because our clients don’t always know what domain they want at the very beginning of projects.</p><p>Fast forward to the present (September 2019) and we have a way to deploy WordPress sites and their CloudFront distributions separately, and also provide a temporary domain to the websites. This made deployments much faster and immediately interactive.</p><p>What made this possible was my work on the load balancer layer. Our load balancer layer has an AutoScaling Group running Traefik containers, managed by ECS. We’re using Traefik to load balance, reverse proxy and provision SSL certificates.</p><p>So how do I give new websites a temporary domain? Assume that we use <em>example.com</em> for the load balancer layer and that Traefik container instances are reachable at <em>traefik.example.com</em>. For each new site all I need to do then is create a new CNAME record, let’s say <em>website.example.com</em>, and point it to the Traefik container instances. Because we are routing by host this is a pretty effective and simple way to provide temporary domains to our websites.</p><p>Notice that the title of this article is about async/await but we haven’t even begun talking about it. We’re getting there. Patience, child.</p><p>I said that the load balancer layer includes an AutoScaling Group running an ECS service. How do I route traffic from <em>traefik.example.com</em> to our fleet? Network Load Balancer? No, of course not. I use weighted A records in Route53. I have a tight budget.</p><p>Each weighted A record needs to point to a unique instance in our fleet. Because I’m using an AutoScaling Group I can attach Lifecycle Hooks. Lifecycle Hooks allow you to run arbitrary code when instances are launched or terminated. I needed to create weighted A records when instances were launched and delete them when instances were terminated.</p><p>So here’s the initial version of the handler code of the Lambda function that creates weighted A records when new instances are launched.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/599a0e458ee84ff1cdec8d164df569fd/href">https://medium.com/media/599a0e458ee84ff1cdec8d164df569fd/href</a></iframe><p>As you can see there’s lots of callbacks which makes the code very ugly. One or two is fine I guess but three? No.</p><p>For some time now I have only been an observer of async/await from a distance. I didn’t really know how it worked but I knew it had something to do with promises. So today I decided to spend some time reading about it.</p><p>After one Google search and five minutes reading about async/await I rewrote my code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ea14874adb2e70cc3dd20bb98b5a635/href">https://medium.com/media/1ea14874adb2e70cc3dd20bb98b5a635/href</a></iframe><p>It didn’t reduce my lines of code very much BUT it did make my code a lot more readable. Just what I wanted.</p><p>So how does async/await work? Well I’m probably not the person to ask this but:</p><ol><li>They’re keywords</li><li><em>async</em> functions ALWAYS return a promise. This means that if you return something that is not a promise, it is automatically wrapped into a resolved promise.</li><li>The <em>await</em> keyword is allowed inside <em>async</em> functions only</li><li>The value of an <em>await</em> expression is the resolved value of the promise</li><li>You need to use try/catch/finally</li><li>JavaScript will wait until all <em>await</em>ed promises resolve or reject</li></ol><p>The last point is a bit of a gotcha — JavaScript runs each <em>await</em>ed promise sequentially.</p><p>Also I am using <a href="https://docs.aws.amazon.com/cdk/latest/guide/home.html">AWS CDK</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c03188fd2db0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Today I Was Confused — AES/CBC/PKCS5PADDING]]></title>
            <link>https://medium.com/@vlence/today-i-was-confused-aes-cbc-pkcs5padding-eaa506124987?source=rss-57fbea1a3896------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaa506124987</guid>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[encryption]]></category>
            <dc:creator><![CDATA[Victor Basumatary]]></dc:creator>
            <pubDate>Fri, 06 Sep 2019 18:13:22 GMT</pubDate>
            <atom:updated>2019-09-07T02:51:11.331Z</atom:updated>
            <content:encoded><![CDATA[<h3>Today I Was Confused — AES/CBC/PKCS5PADDING</h3><p>Date: 6 September 2019<br>Location: Mumbai, India<br>Weather: Rainy</p><p>I do not intend for this article to be educational in any capacity. But hey thanks for reading.</p><p>One of our clients has a website and wants to use a third part API — I can’t say which — and so I’m given charge of the project. Sweet.</p><p>I get my hands on some example PHP code, the API docs and test credentials. Our story begins here, about how I got to a working implementation and how the innards of this implementation confused me.</p><p>Let’s start with the fact that I know jack about encryption. All I know is that you plug in some text and a key, and get gibberish text out the other end. That’s about all I know about encryption.</p><p>And today I had to write code that would encrypt some text. Using AES/CBC/PKCS5PADDING.</p><p>I started by reading the example code and the API docs in tandem. They were pretty short so it didn’t take too long to understand how the code worked.</p><p>Essentially you had a JSON object, serialized the JSON to string, encrypted that string, and base64 encoded the ciphertext. Easy.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17b6c3d0b7ead367737eb77b98d7ac5e/href">https://medium.com/media/17b6c3d0b7ead367737eb77b98d7ac5e/href</a></iframe><p>I proceeded to test my code and it worked — the API accepted my request and promptly sent me an error saying one of the fields was incorrect. In other words the API could correctly decrypt the encrypted data and tell me something was wrong with it. Noice.</p><p>Life would be simple if you could just fix that field and call it a day. Well I couldn’t call it a day. Because I couldn’t fix that field. Because that field is supposed to be already correct…</p><p>Now the API docs say that this field expects only one, very specific, default value. Of course I was using that one, very specific, default value. And the API told me it was invalid. You wot m8?!</p><p>After taking a deep breath and a 30 minute break I decided it was time to binge on YouTube. During my binge a thought crossed my mind, “Maybe it’s my code. Maybe I should run the PHP code and see what’s what.” And so I ran the PHP code. And it ran just like mine — The API returned the same error for the same input. OK yay it’s not my code.</p><p>Along the way I got curious about what the encrypted text looked like. And what do you know, my code and the PHP code produced different ciphertext. Time to play detective.</p><p>First rule to playing detective is that you don’t play detective with production code. Or staging code. Or dev code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/523cd7afdd60824914d5cbdc7313c44f/href">https://medium.com/media/523cd7afdd60824914d5cbdc7313c44f/href</a></iframe><p>A quick glance™ and it’s obvious both tests do basically the same thing. But completely different results. How? Why? We need a second quick glance™.</p><p>Notice that in the JavaScript test file the <em>data</em> object has <em>field1</em> defined before <em>field2</em> and the opposite is true in the PHP test file. At this point I remembered something I had once read about chaos theory— A small change in the input brings about a large change in the output. So I made sure that in both test files the fields appeared in the same order.</p><p>The outputs were still different. But they were very similar. We’re getting closer to the truth. The inputs were the same, right? Both fields were in the exact same order and had the same values. Time to play detective v2. Let’s log the JSON encoding.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/daa3351a1ccb50dc262b19d7e44e2d8f/href">https://medium.com/media/daa3351a1ccb50dc262b19d7e44e2d8f/href</a></iframe><p>And there we have it. An extra backslash. Looks very similar to… Wait. Is <em>json_encode</em> <strong>escaping a forward slash?</strong> Yes. Yes it is. 🤯</p><p>You can disable this behavior by passing <em>JSON_UNESCAPED_SLASHES</em> to <em>json_encode</em>. Peace has returned to the valley. But here’s the thing — why is this default behavior? JSON doesn’t even require you to escape a forward slash AFAIK.</p><p>Why did I waste 5 hours on this?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaa506124987" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Learn ANY Programming Language]]></title>
            <link>https://medium.com/@vlence/how-to-learn-any-programming-language-7deae6e79d07?source=rss-57fbea1a3896------2</link>
            <guid isPermaLink="false">https://medium.com/p/7deae6e79d07</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Victor Basumatary]]></dc:creator>
            <pubDate>Sun, 07 Jan 2018 15:34:33 GMT</pubDate>
            <atom:updated>2018-01-07T16:00:25.872Z</atom:updated>
            <content:encoded><![CDATA[<p>What I am going to write here is what worked and still works for me. Tastes and opinions may (probably will) differ.</p><p>The following steps assume you are most comfortable learning through videos. If you aren’t then replace the notion of videos with whatever medium you are most comfortable with (books, online articles, etc).</p><h3>I’ve Never Programmed In My Life</h3><ol><li>Go to <a href="https://www.youtube.com/">YouTube.com</a>.</li><li>Search for “THE_LANGUAGE beginner tutorials”. Replace “THE_LANGUAGE” with the name of the programming language.</li><li>Filter for a recent playlist.</li><li>Take your time and see which playlist you connect with most. It is important that you feel comfortable listening to and watching the videos.</li><li>Take it slow. Make sure you understand everything you watch. Try to mix and match examples. Try out your own ideas.</li><li>These are the basic concepts you MUST know — variables, functions, loops, conditional statements, data types.</li><li>Start reading the documentation of the language. You should find this in the website of the language.</li></ol><h3>I Know How To Code</h3><ol><li>Learn how to set up your environment (install compilers, interpreters, just do whatever you need to) and get a basic program running.</li><li>Speed run it. You might think you should take it slow but you most probably won’t need to. What’s important is you get the ABSOLUTE BASICS down first — variables, functions, data types, loops, conditional statements.</li><li>Hit the docs. Get even more familiar with the basics and their intricacies.</li><li>Start using simple libraries and make a few dummy ones of your own to get a taste of how it all works.</li><li>You’re probably good to go now.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7deae6e79d07" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>