<?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 Miyuru Dayarathna on Medium]]></title>
        <description><![CDATA[Stories by Miyuru Dayarathna on Medium]]></description>
        <link>https://medium.com/@miyurud?source=rss-bcc575267bb7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*lxsOoZuxKpqdff_qp8C-sA.jpeg</url>
            <title>Stories by Miyuru Dayarathna on Medium</title>
            <link>https://medium.com/@miyurud?source=rss-bcc575267bb7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 17:48:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@miyurud/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[Challenge Response Protocol Based Authentication with Blockchains]]></title>
            <link>https://medium.com/@miyurud/challenge-response-protocol-based-authentication-with-blockchains-2935bf6c53d4?source=rss-bcc575267bb7------2</link>
            <guid isPermaLink="false">https://medium.com/p/2935bf6c53d4</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[ballerinalang]]></category>
            <dc:creator><![CDATA[Miyuru Dayarathna]]></dc:creator>
            <pubDate>Wed, 17 Apr 2019 09:55:22 GMT</pubDate>
            <atom:updated>2019-04-17T09:55:22.945Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. Introduction</h3><p>Challenge-response protocol (also known as Zero-Knowledge Proof) is a fundamental operation for block chain based applications which enables the external parties to gain access to the application. This approach is based on asymmetric key encryption. This article explains our experience of implementing Challenge-response protocol based authentication for a <a href="https://ballerina.io/">Ballerina</a> application based on Blockchain technology.</p><h3>2. Challenge-response Protocol</h3><p>Challenge-response protocol is based on the concept of challenging an entity which is trying to access the services of a system to prove itself first using a known fact about that entity. Here we use the symmetric key encryption technique as a means of implementing the challenge-response protocol. The entity which requires to access the services first needs to generate a public/private key pair and register the public key with the service in advance. The service leverages the fact that any information encrypted by using a public key can only be decrypted by using the corresponding private key. Hence whenever an entity tries to gain access to the service, it gets challenged to decrypt some encrypted text using entity’s private key to verify its identity. Next, we will provide brief overviews to Ballerina and Blockchain technologies which are the key underlying technologies of our application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_fi-xsfqDgTQCivURGd3Ow.jpeg" /></figure><h3>3. Technology Overview</h3><p>We developed the challenge-response protocol application with Ballerina and Blockchain technologies.</p><h3>3.1 Ballerina</h3><p><a href="https://ballerina.io/">Ballerina</a> is a compiled, transactional, statically and strongly typed programming language with textual and graphical syntaxes. Ballerina embeds fundamental concepts of distributed system integration into the programming language. Ballerina offers a type safe, concurrent environment to implement microservices with distributed transactions, reliable messaging, stream processing, and workflows. The use case scenario described in this article can be considered as a software integration scenario hence Ballerina matches well for this application.</p><h3>3.2 Blockchain</h3><p><a href="https://dl.acm.org/citation.cfm?id=3006358">Blockchain</a> is a distributed ledger technology with some special features. Blockchain is a linked list (i.e., a chain) of blocks. A block is a group of ordered transactions. Blockchain is the technology which enables moving digital assets/coins from one individual to another. Blockchain was intended to solve the problem of money transfer. It is based on three concepts,</p><ul><li>Everyone on the network can see and validate the transactions.</li><li>Distributed ledger (exists in many nodes)</li><li>Consists of Miners which are special nodes in the network for validating the transactions and adding them to the ledger hence synchronizing the ledger</li></ul><p>Although blockchains has become popular due to its association with digital currencies, in recent times multiple different applications of blockchain has emerged in the IT industry. Applications that run on custom built Blockchains are called smart contracts and they run exactly as programmed without any possibility of downtime, censorship, fraud or third-party interference. <a href="https://www.ethereum.org/">Ethereum</a> is a decentralized platform that runs smart contracts.</p><p>Next, we will describe an example use case where Challenge-response protocol has been applied.</p><h3>4. Application Use Case</h3><p>Challenge-response protocol has versatile applications. The scenario which we implement and present in this article is a group chat application. The chat application is accessible by a group of users who have registered their public key with the blockchain. If a user gains access to the chat application, the user is able to post messages to the group chat interface. The messages get broadcasted to all the subscribed users in the group chat. User could post any amount of messages to the chat application and logout from the system anytime he/she wishes. However, their conversions will be left in the group chat. Hence, if the user logs back in few moments after logout he/she will be able to see the messages that got posted in the earlier session. If the authentication attempt was not successful, the user will get directed to an error message page.</p><h3>5. Implementation</h3><p>The processing flow associated with the application can be shown as shown in Figure 1. We designed the application as an interaction between a web browser, Ballerina service, and Ethereum Blockchain. Ballerina service functions as a web server. Whenever the user tries to access the chat application, he gets directed to the user login page of the Ballerina chat application (See Figure 1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/0*kdeaiQ3I_rw8PFUX" /><figcaption>Figure 1: Blockchain based chat application’s login page</figcaption></figure><p><strong>Figure 1: Blockchain based chat application’s login page</strong></p><p>Once the User Login page gets loaded,the user who wants to login to the chat application submits his/her email address and the private key to the browser which does the communication with the Ballerina service. The sequence diagram for this process is shown in Figure 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/0*TgBJcMNAQM5arbx7" /></figure><p><strong>Figure 2: Process flow of challenge-response protocol of the chat application</strong></p><p>Note that even though the user submits his/her private key to the browser the private key is not sent outside from the browser and it is used only within the Javascript based encryption algorithms that are running within the browser.</p><p>User’s email address is sent to Ballerina service which looks up the corresponding hash of the public key from the blockchain. We use the Smart Contract shown in Listing 1 for storing the hash of the user’s public key within the blockchain.</p><p><strong>Listing 1: Smart contract for storing and retrieving the hash codes of the public keys of the users</strong></p><pre>pragma solidity ^0.4.22;</pre><pre>contract registry {</pre><pre>string private miyurudatwso2dotcomHash;</pre><pre>string private isurupatwso2dotcomHash;</pre><pre>string private nadheeshatwso2dotcomHash;</pre><pre>function setmiyurudatwso2dotcom(string x) public {</pre><pre>miyurudatwso2dotcomHash = x;</pre><pre>}</pre><pre>function getmiyurudatwso2dotcom() public view returns (string) {</pre><pre>return miyurudatwso2dotcomHash;</pre><pre>}</pre><pre>function setisurupatwso2dotcom(string x) public {</pre><pre>isurupatwso2dotcomHash = x;</pre><pre>}</pre><pre>function getisurupatwso2dotcom() public view returns (string) {</pre><pre>return isurupatwso2dotcomHash;</pre><pre>}</pre><pre>function setnadheeshatwso2dotcom(string x) public {</pre><pre>nadheeshatwso2dotcomHash = x;</pre><pre>}</pre><pre>function getnadheeshatwso2dotcom() public view returns (string) {</pre><pre>return nadheeshatwso2dotcomHash;</pre><pre>}</pre><pre>}</pre><p>We compiled the smart contract using <a href="https://remix.ethereum.org/">remix</a> IDE, obtained the Javascript version of the application, and deployed it in an Ethereum blockchain. Next, we set the SHA-1 hash codes of the public keys in the blockchain using the setter operations of the smart contract. These hash values are accessed via the getter operations. Note that we assume the SHA-1 behaves like a “random oracle” which basically returns random values, with the condition that once it has returned output A on input B, it must always thereafter return A on input B.</p><p>When the user clicks on the submit button of the login page, the user’s email address is transferred to the Ballerina service which uses that value for executing the corresponding getter operation for obtaining the hash values of the public key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/0*E3qYheKDuI-5cbBd" /></figure><p><strong>Figure 3: The group chat interface</strong></p><p>The hash value is used to fetch the public key which is stored on the local disk of the computer where the Ballerina service is running. The public keys of each user are stored in text files which are named using the SHA-1 hash codes generated using them. Next, Ballerina service generates a random string and encrypts it with the public key of the user and sends it back to the browser. If the browser was able to decrypt the encrypted text, Ballerina service directs the browser to the homepage of the chat group (shown in Figure 3). Ballerina service also maintains the user session in a map until when the user logs out from the application by clicking the Logout button.</p><p>The complete <a href="https://github.com/miyurud/group-chat-blockchain">source code</a> of our application is accessible from GitHub.</p><h3>6. Summary</h3><p>In this article we described how we implemented a challenge-response protocol on top of a Ballerina application using blockchain technology. The application we developed is a group chat application and it demonstrates how such challenge-response protocol be implemented with smart contracts. This application demonstrates “login” which is one of the core operations of decentralized applications. We currently investigate on the implementation of other similar core operations of decentralized applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2935bf6c53d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>