Code Monkey home page Code Monkey logo

relaynet-core-js's Introduction

relaynet-core-js

This library implements the core of Awala and is meant to be used by anyone using the network from a Node.js application. Read the docs online.

Please note that this documentation is mostly incomplete because the interface exposed by this library is changing rapidly as of this writing.

Install

@relaycorp/relaynet-core requires Node.js v12 or newer, and the latest stable release can be installed as follows:

npm install --save @relaycorp/relaynet-core

Specs supported

This library supports the following Awala specs:

Updates

Releases are automatically published on GitHub and NPM, and the changelog can be found on GitHub. This project uses semantic versioning.

relaynet-core-js's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar gnarea avatar microshine avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

relaynet-core-js's Issues

Use either Buffer or ArrayBuffer exclusively

For consistency. Public interfaces use both interchangeably.

ArrayBuffer is used extensively because PKI.js requires it, but everything else uses Buffer.

As of early 2022, I'm using ArrayBuffer in new interfaces to avoid conversions before/after use with PKI.js and for forward-compatibility with web browsers.

Avoid re-deserialising ASN.1 values to work around bugs in PKI.js

I've been doing that to avoid burning more time on that bug, but we need to address the underlying issue and open a PR for PKI.js after debugging it.

The main reason to do this is performance.

We can find the instances where this is done by searching for "redeserialize".

Implement abstract certificate store

Analogous to the PrivateKeyStore, but values need not be encrypted at rest or in transit. It would hold two sets of certificates along with their corresponding chains:

  • Those belonging to the current node.
  • Channel session certificates for the nodes with which there are active sessions.

For example, a concrete store could be backed by MongoDB (in the case of a server-side app) or the file system (in the case of a desktop app).

Check that SignedData operations work when AKI/SKI extensions are missing/invalid

Note to self: I think I discovered a bug in PKI.js but haven't got the time right now to create a small reproducible snippet.

It seems like when the Authority Key Identifier or Subject Key Identifier extensions are missing, signature generation/verification operations never complete when using a certificate chain (which leads to timeouts).

Ephemeral key ids shouldn't be represented as JS numbers

The channel session spec used to require 32-bit integers: AwalaNetwork/specs@e759f9d

But representing such ids as JS numbers makes things more complicated because we'd have to ensure they're valid 32-bit unsigned integers. Also, the 32-bit constraint was only introduced to make it possible to represent such ids as numbers across platforms.

So we should just treat the serial number as an ArrayBuffer.

Serialising a SignedData value with a large, embedded content takes seconds to complete

Generating a DER-encoded SignedData value with a content of 8 MiB takes 6-9 seconds on my computer, which could make the public gateway susceptible to severe availability issues.

Nearly all that time is spent serialising the ContentInfo/SignedData object to a DER ByteArray (constructing those objects and calling SignedData.sign() takes 60ms and 5ms, respectively). Roughly 66% of the serialisation time is spent encoding the SignedData value and the remainder serialising the ContentInfo wrapper.

Verifying such large values takes just over 300ms on the same computer after some optimisations.

The culprit has to be the ASN1.js and/or PKI.js libraries, although having the plaintext embedded in the CMS SignedData certainly doesn't help. So broadly speaking, our options are:

Can't upgrade to PKI.js 2.1.85 or newer

I'm experiencing a really bizarre issue when upgrading from v2.1.84 to any of the newer versions (up to 2.1.88): I'm using getAlgorithmParameters() but it fails because getEngine() returns the default engine even though I'd previously called setEngine() with an instance from node-webcrypto-ossl.

I've altered the code for PKI.js' common.js file in node_modules to log each call to setEngine() and getEngine(), and I can confirm that my call to setEngine() is done before getEngine(). I've also checked that the engine gets placed in the right key under global, and the pid is always the same (which isn't surprising, since I'm only running one process).

This only happens when I integrate relaynet-core in the public gateway. That server doesn't use PKI.js directly at all, so index.js registers the crypto engine there. The server only imports stuff from index.js, so imports are only available after the PKI.js engine is registered. (Note that the debugging I mentioned was done on the server where the issue manifests)

I've tried downgrading to 2.1.83 and older versions, and the server works absolutely fine. It's only when I upgrade to 2.1.85-2.1.88 that it breaks. Here's an example: If I upgrade my library to use PKI.js 2.1.85+, the server tests fail with TypeError: Cannot read property 'getAlgorithmParameters' of null, but the issue goes away if I use a different version of my library that requires PKI.js 2.1.84.

See downgrade in #72

Move SessionEnvelopedData.getRecipientKeyId() method to EnvelopedData

So it can be used on SessionlessEnvelopedData instances (e.g., for key rotation purposes).

We may have to make it abstract because the session-based implementation looks at recipientInfos[0].value.keyInfo.recipientEncryptedKeys.encryptedKeys[0].rid.value.serialNumber, but I think recipientInfos[0].value.keyInfo.recipientEncryptedKeys is specific to key agreement protocols.

Make RAMFMesssage.validate() check type of recipient address

There should be an enum for the types of recipient addresses (private, public), which should be passed to validate() as the first parameter. It may also be set to null to allow any type.

Authorization should be skipped if and only if recipientType == public && requiredRecipientType != private.

Write documentation

  • Document install instructions.
  • API documentation.
  • Verbose documentation.
  • README.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.