Skip to content

Testing Milestone 2

Isaac Adams edited this page Feb 24, 2022 · 31 revisions

Verifying Features

First, run Fennel Protocol as a dev node:

$ ./scripts/setup.sh
$ ./scripts/build-run.sh

Extrinsics are available by navigating to Polkadot.js and entering the Developer > Extrinsics menu.

The following represent the features outlined as the deliverables outlined for Milestone 2:

Keypair Creation

Fennel supports the generation of AES and RSA keys. In part, these tools are used for some specific uses cases within Fennel. Primarily, however, the support for these key types exist to supply a native key management system that benefits Fennel users directly and the ecosystem as a whole.

AES

Fennel provides support in our integration libraries for AES encryption and the generation of AES keys (source). A light wrapper around the OpenSSL implementation of AES is used for both key generation and encryption/decryption. An AES key will be generated based on the shared secret for each communication channel established and be used for encrypting the messages exchanged within it.

  • AESCipher::new generates an AES cipher instance based on a randomly generated secret
  • AESCipher::from_file generates an AES cipher instance based on a secret stored in a file
  • AESCipher::new_from_shared_secret generates an AES cipher instance based on a given secret
  • generate_keys using a given secret, this method will return an AES encryption and decryption keys for the OpenSSL implementation
  • aes_encrypt encrypts the given plain text using the given AES Key and a randomly generated IV. It returns the cipher text appended to the randomly generated IV
  • aes_decrypt decrypts the given cipher text using the given AES Key and the appended random IV that was generated for it, returning the original plain text

RSA

Fennel provides support in our integration libraries for RSA encryption and the generation of RSA keys (source).

  • hash
  • generate_keypair
  • encrypt
  • decrypt
  • sign
  • verify
  • import_keypair_from_file
  • export_keypair_to_file
  • import_public_key_from_binary
  • export_public_key_to_binary

Public Key Transmission

Having the capability to map public keys to accounts is critical to creating a secure, predictable, and reliable web-of-trust. By storing the public keys on-chain in connection with user accounts, blockchain level security is achieved for the connection between the public key and the account that claims it. It also ensures that when an account retires a public key, it occurs on-chain so that others are made aware it is no longer active.

You can announce a new RSA public key to the network by calling the issue_key extrinsic (source) with a key fingerprint and a link to a public key storage location.

Any existing RSA public key on-chain can also be revoked by calling the revoke_key extrinsic (source) by supplying the fingerprint.

A Diffie-Hellman encryption key can be announced through the issue_encryption_key extrinsic (source) by simply providing the public key data.

Public Key Retrieval

Public Key Retrieval is implemented as a storage handler around a StorageDoubleMap, mapping accounts to key fingerprints to storage locations. By virtue of storing public keys on-chain, the keys can be retrieved from the public chain by querying it.

In our integration library, subxt (an API for querying storage objects on a substrate blockchain) is utilized to query all the public keys available on the Fennel chain. You can find an example of a Rust function to call against this storage endpoint in fennel-lib.

Encrypted Communication Channel Negotiation

The changes in this milestone include both a library used to integrate key management and encryption negotiation features into Rust-based applications through a new fennel-lib implementation, and a Fennel Protocol pallet used to announce both Diffie-Hellman public keys and RSA public keys to the network. In the next milestone, we'll complete a client/server pair targeting easy deployment with this library integrated.

Diffie-Hellman

Fennel utilizes the Diffie-Hellman (DH) algorithm for establishing secure communication channels. A light wrapper around the x25519_dalek crate provides the functions Fennel will use for the communication channel handshake between two accounts (source).

  • get_session_secret this function generates a secret for a user to be used for DH
  • get_session_public_key this function returns the public key derived from the given DH secret, which is exchanged with another user's public key for DH
  • get_shared_secret when a user receives another user's public key, they can combine it with their DH secret to create the DH shared secret

Clone this wiki locally