GithubHelp home page GithubHelp logo

nodejs / webcrypto Goto Github PK

View Code? Open in Web Editor NEW
68.0 64.0 20.0 98 KB

This repository has been archived. The WebCrypto API has been implemented in recent versions of Node.js and does not require additional packages.

JavaScript 100.00%

webcrypto's Introduction

WebCrypto Prototype for Node.js

This is a partial and experimental WebCrypto implementation for the Node.js platform.

Asynchonicity

The WebCrypto specification requires almost all operations to be completed asynchronously, however, Node.js implements very few operations asynchronously. Usually, this is not a problem, since most cryptographic functions are incredibly fast compared to the overhead that comes with asynchronicity, and because Node.js implements most cryptographic features through efficient streaming interfaces. WebCrypto has no streaming interfaces but only one-shot APIs. Encrypting, hashing, signing or verifying large amounts of data is thus difficult in WebCrypto without underlying asynchronous APIs.

Development

Structure

The main export of this package is implemented in lib/index.js and represents the Crypto interface as defined in section 10 of the WebCrypto specification. It contains two members:

  • The subtle attribute is implemented in lib/subtle.js, including all methods described in section 14.3 of the WebCrypto specification. These methods usually delegate work to one or more cryptographic operations that are listed in section 18.2.2 and implemented in lib/algorithms/.
  • The getRandomValues function is implemented in lib/random.js.

Tests

The test directory contains a small number of unit tests. All of these tests are required to pass after each commit. You can run unit tests using npm test.

A coverage report can be generated using the command npm run coverage.

A subset of web-platform-tests can also be used for testing. The test/wpt/wpt submodule must be initialized in order to use them. You can run the WPTs using npm run wpt. Proposed changes do not need to pass all WPTs, but they should not break tests that passed without the changes.

Linting

This repository uses ESLint. Use npm run lint to check the code.

webcrypto's People

Contributors

panva avatar tniessen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webcrypto's Issues

feature request: exposing crypto interface directly

I wrote a simple test that erred:

const crypto = require("webcrypto");
var iv = crypto.getRandomValues(new Uint8Array(16))
console.log(iv)

turns out I should do this:

const crypto = require("webcrypto");
var iv = crypto.crypto.getRandomValues(new Uint8Array(16))
console.log(iv)

compared to the straightforward interface provided by trust-webcrypto

const crypto = require("@trust/webcrypto");
var iv = crypto.getRandomValues(new Uint8Array(16))
console.log(iv)

I think it's more intuitive to provide crypto object directly.

Tracking issue: Bugs in web-platform-tests

List of web-platform-tests that seem to fail due to bugs in web-platform-tests:

  • derive_bits_keys/hkdf.js: Tests that illegal hash function names throw a NotSupportedError, but seems to miss the required BufferSource info, leading to a TypeError instead of a NotSupportedError according to WebIDL.
  • derive_bits_keys/hkdf.js: Tests that passing null as the length throws a TypeError, but WebIDL allows passing null and interprets it as 0, so it should likely be an OperationError instead.

How to install this package?

It seems like this package doesn't publish on the npm. When I try to install via git, yarn add git://github.com/nodejs/webcrypto --ignore-scripts -D, it reports error Can't add undefined: invalid package version undefined.

JWK support for ecdsa

In ecdsa.js, it seems like importKey is ignoring the JWK parameter and import the key as a buffer therefore throw an error
image

Add JWK support to RSA

This won't be possible (without manually parsing DER) as long as node does not provide an API to extract relevant fields from keys and to construct keys from said fields.

Previous discussion in nodejs/node#26854.

RSA needs to distinguish between RSA keys with different OIDs and parameters

WebCrypto requires implementations to be able to distinguish between the OIDs rsaEncryption, sha1WithRSAEncryption, sha256WithRSAEncryption, sha384WithRSAEncryption, sha512WithRSAEncryption, id-RSAES-OAEP and id-RSASSA-PSS, and for the last two, we even need access to the ASN.1 parameters.

This is currently not possible using the KeyObject API.

Remove .travis.yml?

I was going through various .travis.ymls in the org, and I spotted that the one here does not include v14 - but I can also see that this repo is now using Github Actions - shall I open a PR to remove .travis.yml?

Or should the .travis.yml be updated to include v14?

Storing keys in a non-extractable way

In the browser the developer may choose to generate a key pair and store these object instances in Indexed DB and recall these at any point in the future. Like so there's no way to retrieve the private key value, ever.

What are the extractable: false options for the node implementation?

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.