# KeySpace: End-to-End Encryption using Ethereum and IPFS by Samuel Walker (Devcon5)

- Channel: [Devcon](https://streameth.org/devcon)
- Date: 2020-10-09
- Duration: 33:36
- Topics: blockchain, smart contracts, distributed ledger, ethereum
- Watch: https://streameth.org/watch/yt-jmE9RXBquJQ
- YouTube: https://www.youtube.com/watch?v=jmE9RXBquJQ

## Description

Visit the https://archive.devcon.org/ to gain access to the entire library of Devcon talks with the ease of filtering, playlists, personalized suggestions, decentralized access on IPFS and more.
https://archive.devcon.org/archive/watch/5/keyspace-end-to-end-encryption-using-ethereum-and-ipfs

One of the interesting side effects of the number of developers coming into the blockchain space is that as more engineers come to understand & play with cryptographic tools, they are more likely to come up with solutions to new user experience issues by creatively applying these cryptographic primitives. At AirSwap we wanted to enable conversational, messaged-based trading for users, and support dependable message delivery, without compromising their privacy. Since we knew that all dApp users have access to a persisted public-private key-pair through their wallet, we built a system that allowed them to derive secondary PGP keys which were deterministically tied to their address, and allowed for encryption & decryption of messages, and also signatures and signature verifications. (more detail here: https://medium.com/fluidity/keyspace-end-to-end-encryption-using-ethereum-and-ipfs-87b04b18156b).

Speaker(s): Samuel Walker
Skill level: Intermediate
Track: Privacy
Keywords: technical

Follow us: https://twitter.com/efdevcon, https://twitter.com/ethereum
Learn more about devcon: https://www.devcon.org/
Learn more about ethereum: https://ethereum.org/ 

Devcon is the Ethereum conference for developers, researchers, thinkers, and makers. 
Devcon 5 was held in Osaka, Japan on Oct 8 - 11, 2019.
Devcon is organized and presented by the Ethereum Foundation, with the support of our sponsors. To find out more, please visit https://ethereum.foundation/

## Transcript

[Applause] hi everybody my name is Anne Walker I'm an animator at eros watch this is a workshop about keyspace which is a protocol for end-to-end encryption amusing and aetherium and IBSS before I get started I wanted to give a bit of a prologue for prettiest piece of technology in kind of a larger context of what I see of kind of emerging technologies so that inspiration for key space first came to me about a year ago I was listening to a podcast by Arthur Falls called the third one he was interviewing a developer named Dominic Tarr he's the who develops a distributed social media network called secure Scotland of end-of-year familiar with that but the thing I really liked in the in an interview was he talked about this concept called cyberspace so cyberspace is what he sees as kind of an emerging style of application development on the net or on the web has a kind of a proper abstraction between the networking layer and the application layer and that proper abstraction is enabled the first time really by use of different cryptographic premises I think having your application logic divorced from your network network in logic looks kind of like a graph QL in that you know you can kind of specify what your application needs but you don't have to worry about how it gets to you so I think some more concrete examples of like what cyberspace is and how this kind of development methodology in the future it's going to be made clear and some later examples but just to have that context at you is you kind of watch this presentation so this is the agenda we're gonna start out pile high level and just answer what is this bit so why was the build similar its core dependence then we're gonna zoom in a little bit more with the in-depth technical description there's kind of three main stages and the user life cycle within the protocol we're gonna work through each of those after that is the fun part the interactive examples it is kind of a donut app that you all can load up on either desktop to your fans and we can kind of do some cute adhere encrypted group messaging amongst each other and then after that we'll have some time for questions or exploration on just meeting you know what we can do with this kind of protocol so free study definitions what is key space I think the simplest way to sum it up is the key space is at restless token PGP implementation developed on top of theorems existing cryptographic key to winning so some obvious questions come up from this definition first of all for those unfamiliar with cryptographic protocols ways open PGP and secondly why we need open PGP on there so teaching these stands for freedom privacy it's an encryption program that provided to cryptographic privacy and authentication for data communication PGP is used for signing encrypting and decrypting text emails files directories and holy disk partitions and to increase the security of the email communication so if legislation um so BGP a little background myth it was developed by a photographer named Phil Zimmerman in the nineties it was first of all to zEnterprise software but it was first developed as enterprise software and 1991 around 97 Phil decided that this would only work if it was open source so he started the open PGP initiative then around 2014 is when elliptic Kirk ography was added to the particular spec which is much lighter weight than the older form it's an encryption at the protocol used like RSA this kind of lighter footprint a lot to be more realistically used in the browser so open PGP j/s was about the same time um kind of opening the door for an encryption screen to screen encryption so there's no you know it's it's kind of the the standard of encryption that we'd like to have today which is what I like telegram for signal or other things like that so why do I need to bring PGP Aman Atheneum so a little background this came to be because of specific kind of business needs that Harris had um so in kind of the history like Dex development the first popular Dex is like ether Delta all the information was held on like in a smart contract so that order posting order matching and order settlement all happened on chain um kind of second generation Dex is had some improvements upon this to save gas so um protocols like pair Swasey rho x 8x DX is hydra protocol and do i where is all kind of used a similar approach for a gas saving where an order is signed off chain its first in somewhere matched off chain and then settled on chain on so on Harris off in particular but the way that the protocol works is that order posting happens peered up here so makers sent orders directly to takers matching happens when the taker decides that they want to fill the order and then the actual settlement happens when the word is filled on chain but since all of this is being moved off chain into messaging that messaging has to happen somewhere um so okay there's a possible information asymmetry that arises because like for example a Tarasov is hosting the messaging platform then we kind of have a global view into all the messaging that's happening that could potentially give us like an unfair advantage of like you know seeing this trade that's gonna happen before it happens or you know more a G C style interaction we can see people negotiating a table name text so so you kind of eliminate this kind of unfair angle or this unfair of you we need encryption so if all messages between makers and takers are encrypted then they are the only ones who are able to see it and there isn't a kind of global view to exploit from the angle of being a more technical party or kind of having a global access to the system um so we need both encryption for that reason and then we need an authentication to basically tie the messages that are created to a particular thing address um so that if somebody is being abusive messages they send for example trying to ddos the network we can say okay these messages are cryptographically verifiable as having come from this address um we're gonna like disable you know how to does can't send messages anymore and then we can kind of see if assets transferred between that addressed and another address we can you know basically figure out Q's using the network or how some standard where we can have economic incentives for behaving correctly um so obviously uh if my authentication I just mean a signature verification of messages um so there's a lot of different cryptographic protocols that you can use for your authentication and encryption of messaging but a PGP seems like the right choice for multiple reasons one of the main ones is that it's the right age and what I mean by that is that it's been around long enough that it's it's fairly safe it is um you know very robust it's used all over the world and it's been around long enough that it has a great tool you can associated with it which kind of like helps on the developer lived events my hair vertical like this but then it's also simultaneously new enough that you know it uses cryptographic algorithms like you know with elliptic curve cryptography which is like wait enough to use in the browser without negatively impacting and user screens okay so that's kind of like the high-level view of why we needed to implement this trustless version of PGP on ethereum so we're going to zoom you zoom in a little bit and talk about kind of a specific implementation and how it how it looks and feels for you um so the first step in that is a key generation in recovery so what this means is that we're trying to deterministic lead generate the PGP keep it from an Athenian key pairs such that we can verify that this is pyramid rest generated this PGP key and that if the PGP key is lost for whatever reason we can't regenerate it as long as you have control of the wallet so kind of a practical example of this is if I have my ledger and I generate my keys on one computer and I use those keys to read my encrypted messages I can then terminate that session wipe out that information plug my ledger into another computer to regenerate my PGP keys and use them to decrypt the same messages so it's kind of a stateless in a way it's deterministic and so that's just kind of one of the properties we wanted to have in the system on the the next step after keys are generated is a key distribution and lookup so if I want to send a encrypted message to you by knowing your theum address I have to have some way to you know look up that at 3:00 in the dress and find here PGP key and I need to be able to cryptographically verify that that is indeed your PGP key which I can then use that public key to encrypt a message and send it to so there needs to be some sort of directory basically the initial implement implementation of this actually for us was a smart contract so you basically stored your PGP key on I give us took that ifs hash of that key and sorry the smart contract and then when I wanted to find the key associated with your address look it up in a smart contract um pretty soon then we discovered that there is like a whole swath of users Hugh didn't want he wanted to basically try an application without paying gas upfront um you know as soon as like you have to pay for a transaction they weren't you know as interested in in using that application so um there's another alternative way of storing these keys where instead of storing a contract you sign it so that you can verify it as yours and then the signature together with the key can just be served in any database and since that signature always exists next with it you can just pull it and look it up it doesn't have the same guarantee you availability to smart contracts so currently that database is hosted by as well and you know if the Paris walking away then that database wouldn't be hosted but for those user is like you know they would just have to regenerate their keys and they can begin using the system again so there's kind of different options of like you know based on like the longevity the dependability that you need um and you know the level of trust lessness to be desired and you need to pay more for that or kind of have more of a low investment alternatives um so the the threat stuff in this is a passive authentication and privacy um so after everything's set up basically you know keys are generated they're distributed and they can be looked up then we can use them at the application level without really having to understand anything about the you know the underlying cryptography so just all messages between computers or how the simultaneous guarantee you if you receive a message you know for sure that the etherium address that sent you that message um is who they claim to be and when you send a message you know that nobody other than the etherium address that you intend to read it will read it so that's kind of like high-level on boarding um so zooming in on a key generation um so there's actually some you know we're not the first people to kind again some of these problems and a lot of the many of the cryptographic libraries of wallets like madam asked for example depend on like provide methods of deriving secondary keys from primary keys but unfortunately the zero on there's an RPC static for kind of exposing these methods to like the end user ended up but on so the way that we get around that is a key generation happens by taking a pass phrase which is just the plaintext word or set of words and then sign it and then using that pet string that's generated as kind of the encryption key for that encrypts your private PG PG basically so open PGP is when you generate a new key pair you have the option to pass in the passphrase that's kind of the encryption password so that sign message becomes eviction password for your key pair basically so that's kind of a low level of others to were associated and then once that key is created ipfs provides kind of cheap reliable storage um so the way that works for us is that we store the ipfs we swear the keeper and i give us and like basically a redundant set of layers so using the pin set so you know they go from pure a to pinata at or on I give us node onto a cloud fire and some others so we kind of use that that pen sets are like replicate across all of his nose so that kind of makes these keep areas reliably available without having to store them like on a certain contract basically so key distribution so this is kind of like the directory or the index that I talked about before um I think I actually covered missed this already but one thing I wanted to touch on was this idea of multiplexing which is an idea that kind of comes from lip d2d basically so if you if there's basically like it's kind of like function overriding but like on a network level so if I want for example to request some information and I shouldn't have to care about how that information is stored long or how it's fetched I should just be able to you know ask it ask for it and have some guarantee about you know how it gets to me so kind of the multiplex here in this case if we have keys that can be certain on our contract or keys that can be stored in a database and when you look up you kind of do that lookup of both the smart contract and the database in parallel um and on the application level you know you don't really care about where the key is stored you can just use it and this also allows for the addition of other types that data stores for mystery and the keys one of which we we use in our demo which is kind of tricky so often privacy so this is kind of the last step that needs your lifecycle said this is like after everything is generated and distributed we can just enjoy the benefits of everything that the open bgp library offers on so on key space on a key space class there is four function types that are pretty much everything they're going to use other than encrypt which takes a message the plaintext message and the address that you're going to send an encrypted message to decrypt which tasted encrypted message in the from address so you can verify you know that it was sent by the address you find us on it and you know that you can just get that's meant for you and then we also in isolation provide a sign and validate as well so that's all for the high-level review now is the fun part which is the demo so this demo will work on both your laptops and phones as long as they get connected to the internet on so you can go to the the top link there where the light of that is on the airsoft github that hyeri / keyspace / that's common sorry that link is not sure originally this is a mystery on kind of a lot of cloning repos and interactive recruiting depend kind of I saw like all the network limitations we seem too happy so I just kind of spun up this app quickly which I think should we're gonna play tested on tree throttle Internet consideration report all right um but I think this kind of will give us a view to kind of like the inner workings of the protocol without having too much of a bandwidth limitation so I'll let her be pull out and then I will pull it up on mine and kind of walk everybody through how it's working so the it's basically just it's a react front-end application that uses ipfs pub/sub to kind of have your messaging so the one of the cool things about this since up days it's a group chat app that doesn't have any central surgery to it so basically everybody's fairing and laptop kind of in the room is kind of going to be networked together and it's kind of form a two-tiered chat application um oh yeah and also sorry I should have mentioned when you first look the application and I'm not connected and then I'm asked which that also working like a little bit trust you can also say just generate a wallet inside the app generator temporary wallet which will you can still you know use that to communicate since it doesn't currently use any gas um so you do miss people that are gonna put up habit of anybody still typing forget it okay alright so I'm gonna get these tips myself I'll generate a temporary wallet so I'm the only tear that I found so far hopefully over time I'm gonna find all of you it's our other people at this screen after generating the wallet okay hey everybody okay so nice I hope the mobile was placed over expelling these addresses that I wasn't able to test without these people okay so I'm gonna be Sammy okay so okay so this is everybody sharing their PGP keys with each other okay it does that not has to do with this much scale yet but it's a seems like it's working okay yeah okay second I can get into a little bit of I can go into a little little bit of what's going on um so basically this this font tab I think it says Peter on your fan on the desktop that says peer discovery protocol so basically this is a instead of using a database on a contract to distribute keys on we all connect achieve the same I give us a pub set of topics so there's basically one idea that's a server that we reach out to you and say hey I'm listening to this topic then when other people connect they also reach out to that same server and say I'm listening to this topic and we kind of find each other all to that way and then appeared directly with each other then after we're all clear we'd broadcast we broadcast our key and then we send a message which is what we call it requests introduction which basically is like a we send a message to the pub sub topic that is asking other people for the keys and then everybody else responds to that person with their keys basically so it's kind of like a many many messaging system for kind of Italy in this dynamic database of keys and like so as you can see the more people that are having the more messaging or more people requesting that everyone's keys than where messages are sent so that's just kind of good crazy probably right now um so then down here on the no imperius screen um oh yeah I definitely did not design this for this many people TV news I bought this like this um so you can basically choose the keys or the identities that you actually want to send encrypted messages to and then when you on and then every but in example um answer then basically everybody that I selected will get a copy of that message that they can decrypt but everybody gets everybody's message so but the thing is that only the people if you buy encrypted that message specifically for will be able to decrypt it I'm going to refresh this page because all the people joined have a pair of mine with you um so to take it kind of back to the original prologue of the top and the idea of cyberspace um that's kind of what I built this of an example of so the actual data transport like layer of this application is completely public and then anybody can read it it just it takes place on a public ID FS topic but there actually is a complex application logic of you know a permission group chat happening in this public forum so this is kind of the idea of cyberspace that we can kind of divorce application logic from transport network logic and even database storage logic but we shouldn't have to care about where the data for this application lives all we have to care about is availability that product still hasn't really been solved yet but and then just write our own application logic using you know these different cryptographic primitives to kind of enforce our rules of our applications so this application you know it's certainly pretty peer just exists on all of our friends and our laptops in this room and you know we're basically sending each other plain text messages but then all these different cryptographic tools kind of allow us to have a you know a structured application built in this really simple context so oh and for those of you on desktop it's gonna really fit in the mobile view but you can actually look at the Mickey space parameters that I kind of talked through Annie and the first portion so you have like your unassigned seat so this is like what do you sign to generate your password this is the the password that basically encrypts your Keep Calm then this is the gtp public key and the encrypted PTV private key so these are kind of the you know the building blocks that were using to build this application I think if there's anything else about this one oh yeah the nickname I can't get to it because there's too many people but as those of you have said it you know the nickname is just exists as one other type of specialized message on the network so you can kind of announce your nickname when you announce your your your teacher um yeah that said that's it for the oh yeah I'm sorry I have a thing so if you have this loaded and you actually want to look at some of the code for the application um you can click the question mark in the top right and it'll open up to github um kind of talks a little bit about what it is to the application links to the slides in the slideshow and then links to key space which is ondol this part over here swatc I guess you can look at the code of the application even though I wrote it really fast so it's not very good alright it spits nasty but uh I would instead suggest they actually look at the key space and then your soft jazz library which actually has some better examples of documentation and his interviews um so yeah after when I include a key space in your application um this is where you would go to figure out you know um yeah I think is that's it for my demo um I think yeah so my head blog was about putting it in the context of cyberspace and you know this this kind of application right now it's turning in public by DFS but it could be running on any kind of transport you know you any like messaging system you could have an encrypted messaging system built inside of it and you know the stories can happen anywhere so I think that um the initial Eris walk trading network was built on RabbitMQ and it's easily portable now that ipfs because of like separation of concerns that we were talking about so I think that's at least what I believe is that like I think that if we follow a kind of this paradigm I think that like applications that we build in the future that are intrinsically tied to a certain type of what transport layer like for example fetching data over HTTP fetching something from WebSocket it's going to start to feel like spaghetti code is gonna start to feel like expensive influx debt because it's hard to port it's hard to you have all these functions in your code about like how the data comes to you how its available within the kind of areas are laughs when you fetch it and I think that with this kind of approach to building applications you have the separation of concerns such that you can like actually port your application to different types of transports without having you know a lot of tech tip that you have to resolve so yeah that's a that's it for my presentation time for some questions yeah why do you choose certain particular using a password rather than using the diffie-hellman to listen with the elliptic curve that you already have from hearing address huh I think it's because it's not available to deaf users over like json-rpc like Messick it's not part of like this standard JSON RPC message a format for like interaction with a private key basically say like the only like cryptographic functioning that we have available to us as people who build applications that work on top of wallets are basically like you know personal sign sent trans actually and is we don't there's a lot of cryptographic primitives that would be useful like when I was first building this thing that I needed for encryption I wanted to actually you know I was like well why can't I use the you know the etherion private key to encrypt data you know reticular data but it's possible like theoretically it's possible those functions are in the underlying cryptographic libraries that you know a wallet like ledger or meta mask uses but it's just like the respect for making those functions available like is you know it's far away it's gonna be a long time tell anything like that is so this is kind of like a way of working around that limitation do you have to assign the same message every time to get the password yeah so basically on kind of what I was talking about earlier like is there's a bunch of different types of users who want to use an application like this some are more hardcore about like their privacy and some people want something that's more convenient that they don't have to think very much so if you want to for those users who want something that's very convenient and they're not as like worried about privacy basically you can just kind of sign a you know a default phrase that we choose you know kind of provide to you every time son um so then it's kind of like you don't have to remember the passphrase and you can kind of determine its to be regenerated um if you want another layer of privacy you know you can on choose your own that's pretty sadistic your teeth and they'll be able snails but then if you lose that passphrase and you know you lose access to your messages so but that's available to users who want a better layer of privacy yep think of any practical use cases to employ uses exactly just um so it's one thing that did the initial implementation of PGP like functions is this concept called the web of trust the function which is basically like people can trust PGP keys if other keys that they already trust also trust that those PGP keys so like when the critical was first developed you know like all the academic nerds would have signing parties and get together and you know trachy GT keys in person so they could kind of have that base level of trust and build this like kind of trusted network and then off of that they like you know builds a larger network and it was kind of like if that was how Trust was like built like initially um like which is kind of actually now a sighted as kind of a it's more of a critique of PGP that that's kind of like a limitation of the protocol key space is more limited in scope since it's only about instead of finding identities to real person you're binding identities to you know an ethereal address basically but you don't have to worry about that same kind of web of trust which has seems kind of scalability issues but I think there are some some interesting opportunities but with like connecting to systems like he's he not keyspace Keita's um where like a identity and a cryptographic key are already bound by other means so then it kind of like philosophy use PGP more you know more modular you know where you can kind of strap it on to other existing networks that specifically as long as they have cryptographic capabilities all right all right that's it thank you [Applause]
