GithubHelp home page GithubHelp logo

peculiarventures / webcrypto-local Goto Github PK

View Code? Open in Web Editor NEW
18.0 8.0 13.0 6.47 MB

webcrypto-local is a cross platform service that provides access to PKCS#11 implementations over a protocol we call webcrypto-socket.

Home Page: https://peculiarventures.github.io/webcrypto-local/

License: MIT License

JavaScript 2.58% TypeScript 96.94% HTML 0.49%

webcrypto-local's Introduction

webcrypto-local

Coverage Status Test

webcrypto-local is a cross platform service that provides access to PKCS#11 implementations over a ProtoBuf based protocol we call webcrypto-socket. It provides for message confidentiality and integrity via 2key-ratchet and implements a security policy mechanism that allows the user to approve which peers can interact with it.

webcrypto-socket

Build

npm run build

Tests

npm test

C++ Node.js Addons

This project uses C++ Node.js addons. When building on Node.js 20, you may encounter issues with node-gyp. It is recommended to use node-gyp version 10 or higher to avoid these issues.

If you're using nvm to manage Node.js versions, you can switch to Node.js 10 by running nvm use 10. If you don't have Node.js 10 installed, you can install it by running nvm install 10.

Please ensure that you have the necessary build tools installed on your system to compile C++ code. On Windows, you can install the necessary build tools by running npm install --global --production windows-build-tools. On Unix-based systems, you'll need to have gcc and make installed. You can install these by using your system's package manager.

Related

webcrypto-local's People

Contributors

aetherc0r3 avatar donskov avatar kharya1337 avatar microshine avatar ottunger avatar rmhrisk avatar

Stargazers

 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

webcrypto-local's Issues

Need to determine how we will enable pin/password prompts for key usage.

This is a complicated one, right now our server is running in the current user context because we are doing development. As such it is interactive and can display user interface.

When we switch to it running as a service it will no longer be able to do that.

The various PKCS#11 implementations we will have will want the ability to present pin/password prompts. For them to do so there will need to be an interactive component that invokes the provider.

One way to do this is to use webcrypto-local on the service and have it invoke a session to a user mode "server" that invokes node-webcrypto-p11. We would want to automate the establishment of the pairing between the two components if we did this approach.

We will also need to consider how to handle multi-user systems with this also.

Though solving this problem will require some refactoring, I suggest we continue on the current path and come back to it.

Need to design a certificate selection dialog

We will need an API to select certificates that match an application's criteria, we are tracking that here: #4

This bug is to track designing a dialog for that API to use, here are some mocks to seed that process:
image

image

image

It would also make sense to have a confirm prompt:
image

We may also want to have basic smart card support:
image

These dialogs are inspired by: https://blogs.technet.microsoft.com/dodeitte/2015/05/31/how-to-change-the-certificate-store-used-for-lync-client-certificates/

Multi sessions for pkcs11 modules

@rmhrisk

I've got some problems with opening multi sessions for one PKCS#11 token.

SoftHSM module throws error Error: CKR_USER_ALREADY_LOGGED_IN:256
Yubico module throws error Error: CKR_SESSION_COUNT:177

node-webcrypto-p11 uses

const mod = graphene.Module.load()
mod.initialize()

I can't use initialize twice for one module, even I use Module.load for each time. Because JS load native module only once.

To fix it we have to load native in its own thread for each new Module.load

if we use current version of node-webcrypto-p11, then user can enter PIN only once and use this PKCS11 session for each 2key session.

Unable to import CSR

When I go to import a CSR in PEM encoding I get an error in the console:

image

But the UI displays no error, I would have expected a message like:

An error occurred while importing a certificate. 
Please make sure the certificate is well formed and try again.

But I also would have expected this import to actually work, I tried again with the same certificate encoded as DER though the certificate did not get imported it also did not get an error.

We can do a basic check on the provided certificate to see if it is ASCII to determin if we should DER encode before passing to PKIjs. One simple way is via a regular expression:

/^[ -~\t\n\r]+$/;

You could also check for the PEM Armour?

http://stackoverflow.com/questions/30322774/how-do-we-validate-the-format-of-the-csr-using-regex

And based on that decide what is needed to be done.

Either way we need error handling in the UI for errors.

User interface needs to handle errors from the server

There will be cases where the server fails for unexpected reasons, right now we have such a case because a smart card is not supported, for example:

image

In this case, the UI made a call and the server complained:

image

The UI should catch such cases and display a generic error, something like:

An error occurred trying to access the remote cryptographic implementation.

Please try again.

We could maybe include the stack in a text box so people could copy it and paste it into a support forum.

Need to design a certificate selection API

In Windows they have an API called CertSelectCertificate(), it takes a set of criteria and filters certificate to those that match that set.

We will want to have a similar API to make it easy to pick the certificates that match an applications criteria.

In theory, this API would take in a CertificateStorage array and return a certificate, things it might also take as input include:

OID
title A string that contains the text for the title of the dialog.
subTitle A string that contains the text for the subtitle of the dialog.
EKU A string representation of an object identifier (OID) for an enhanced key usage (EKU). If an OID is provided, only certificates that include this EKU will be displayed.
KU An array of desired key usages. If a value is provided, only certificates that include all of the values will be displayed.

These values would be used by something like the dialog proposed in #5

We should also consider how we can make this a re-usable component, maybe do it as a WebCompontent?

Mozilla 2key-ratchet

2key-ratchet works for Mozilla, but IndexedDB storage doesn't keep Identity keys for next connection. User has approve each new connection.

Improve pin generation algorithms

Currently, the project combines two public keys together, hashes them, HEX's that hash, and takes the numbers.

It is better to take the last n bits or first n bits, and convert them into decimal.

parseInt(binary, 2);

This is because HEX will have a bias in its output, this change will make the pins far more random.

We will need to update SECURITY.md.

Need to design a pairing pin prompt

Our pairing mechanism requires the application to present the user a pin it compares to a pin displayed by the operating system for the webcrypto-local service.

Here is a rough prototype we can use as an input to this process:

image

We will want this to display as a DIV dialog so it can automatically be dismissed when the pairing is complete.

We may end up needing a user mode component to perform cryptographic operations, if so we may also want a pairing confirmation dialog:

image

UI: Need UI for errors

We have several error cases:

  • The requested operation is not supported by the cryptographic provider.
  • The requested operation was denied by the cryptographic provider.
  • The token or smart card was removed.
  • An unknown error occurred.

Need to determine how to handle sign and encrypt certificates

WebCrypto does not allow the same key to be used for both signing and encryption, certificates sometimes are used for both.

We have to choose to have webcrypto-local enforce this restriction or to accommodate the certificate usage pattern.

Initially, I suggest we honor the more restrictive WebCrypto approach and change if it becomes a problem.

The reason WebCrypto enforces this rule is to prevent accidental cryptographic mistakes, some algorithms will leak key details if used in the way certs allow.

Need to scrub data returned to client to minimize leakage

Right now we leak a bunch of data to the browser session, we may want to have a debug mode where an admin user can enable this detail or an explicit message to request it that must be approved by the user but by default we want to return only what is minimally needed to perform task.

image

Move communication to the service into a ServiceWorker

Any application running in the context of the application will have the ability to directly use the IdentityKey.

I believe, if we put the IdentityKey (and other keys) in a service worker, then only whatever API that is exposed by the service worker will be able to interact with those keys.

Since we utilize non-exportable keys, even if we do not do this they can not steal the key but they could create their own pre-keys (or other keys) and get them signed then use them elsewhere.

My moving these keys to the ServiceWorker and using PostMessage to communicate with it we mitigate this risk.

We should add this to our SECURITY.md also.

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.