Recently, I participated in the Ethereum-hackathon, and today I want to tell you about the EtherAuth project, with which the MixBytes team took third place. EtherAuth is an attempt to make a decentralized version of the entrance to the site using an external account. Like button to enter through Facebook, only without Facebook.
If you want to make a closed area for users on your site, you have to choose: to develop your own system of identification, authentication and authorization of users, or use a ready-made solution. A ready solution means that your user already has an account on some system (Facebook, Google, Yahoo, Outlook, or even just an email). And you use the appropriate mechanism (most often the OAuth 2.0 protocol) to make sure that someone who tries to login to your site using an external user ID is this user.
The latter option is easier to implement, but a risk arises for the user: if something happens to his main account (for example, Facebook blocks the account without explaining the reasons), he will also lose access to his information on your site.
In addition, if I, as a user, want to enter a site that I don’t trust, I’m faced with the need to give this site access to my personal information, such as email or age. If the site only supports logging in with an external account, I have to literally make a choice: refuse to use the site or sacrifice my anonymity.
Most users end up sacrificing anonymity with the words "yes, that the worst can happen, I have nothing to hide." Unfortunately, the majority of attacks targeted at an unprepared user and ending with monetary losses begin with similar words. "What terrible can happen if I send a code from an SMS to a bank employee?" “What terrible can happen if I send a request header to a tech support employee?” The answer to this question is most often learned when nothing can be done.
How can Ethereum help here? We already understood that there are three main problems:
We can use the Ethereum network instead of the external system and store in it only the necessary data set. Care must be taken not to keep publicly available secret information, but since every wallet on the Ethereum network is actually a pair of cryptographically secure keys, in which the public key determines the wallet address, and the private key is never transmitted over the network and is known only to the owner, we we can use asymmetric encryption to authenticate users.
In the simplest case, you can use the address of the Ethereum wallet as a user ID. But here a problem arises: in the event of a key leak, the user loses access to the system forever. More precisely, from the moment when the user's secret key became known to an attacker or simply accidentally got into public access, we cannot use such a key for authentication.
In our solution, I wrote a simple EtherAuth smart contract to store user IDs and their associated wallet addresses. The user ID is simply a UTF-8 string between 2 and 32 bytes in size. It comes up with once the user himself and later uses to enter any site that supports EtherAuth. Today I would add another restriction on the possible characters included in the string, leaving the possibility of using Latin characters and Arabic numerals (subsets of 7-bit ASCII encoding) to limit the possibility of creating externally similar logins.
When creating an account in EtherAuth, a key pair is defined: an authorization key (authAddr) and a key to restore access (recoveryKey). The recoveryKey name is not entirely successful, since this address is used to manage your account, and not just to recover. When creating, both addresses are equal to the address of the wallet on whose behalf the transaction was sent. But a user who cares about their security should create a separate control key and store it in a place inaccessible over the network. I would even keep it on paper in a safe in the form of 12 mnemonic words, allowing, if necessary, to recreate a pair of keys.
It is also wise to use a separate wallet address for authentication, separating it from the wallet address, which stores all your Ether. The authKey connection with the address of the wallet that created the account can still be traced by analyzing the sequence of transactions of the smart contract. Now you can not set a separate authKey and recoveryKey when creating an account. However, if you refine the smart contract in this direction, the address that created the account will not necessarily be associated with the account owner, which will allow everyone to protect their anonymity.
For user interaction with a smart contract, we created a separate web page. You can create an account on it, change its keys or delete it. To work, the user will need to install the browser plugin MetaMask. If you are already actively using the Ethereum network, most likely you have already installed this plugin, that is, the majority of users who want to access the site through Ethereum will not encounter an additional obstacle in their path.
The overall user authentication process using EtherAuth looks like this:
In our solution for the hackathon, for simplicity, we combined the backend- and frontend-parts, we got one big frontend. In real life, it is important that authentication checks take place in a user-uncontrolled environment, that is, not in a browser, but on a server.
Of the problems we encountered, we can note the signature verification in the frontend part. The browser did not support elliptic curves, so I had to add a function to the smart contract that returns the ecrecover result from the message and learn how to pass parameters to it (get them from the signed MetaMask message).
As a result, in two days we received proof-of-concept decentralized authentication using the Ethereum network and the MetaMask plugin. We understand how to modify this system in order to add anonymity to the user. The user has the opportunity to restore access in case of a leak of his primary key (but not in the case of a recovery key leak). The decentralized system is not subject to censorship of large structures, such as Google or Facebook. If it is necessary to censor, the site should implement it independently, but it can do it only within its own system, without affecting the user's access to other systems. The Ethereum network does not conduct transactions very quickly (when creating an account, the user may have to wait a few minutes), but you can get the data and verify the user’s authentication very quickly. This solution scales well, since there are a lot of data nodes, and anyone can add another one at any time. The complexity of implementing such a solution for site owners is not higher than the complexity of implementing support for OAuth 2.0.
Of course, today users using the Ethereum network are negligible compared to the number of Facebook users. However, the popularity of blockchain technologies is growing, and I believe that in the foreseeable future, such users will become more and more, which means that it will be possible to use decentralized authentication in industrial systems.
Source: https://habr.com/ru/post/423039/
All Articles