npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

netid-ni-tls

v0.4.2

Published

netid-ni-tls ============

Downloads

12

Readme

netid-ni-tls

Nodejs module implementing a variant of the WebID-TLS authentication protocol based on using Named Information URIs to identify X509 certificates.

Useful reading

Why NI URIs?

The current WebID spec mandates the use of RSA due to the focus on (modulus,exponent) comparison. I'd like something more flexible that would allow me to use other kinds of keys without breaking the semantics of the existing vocabularies.

RDF example

Assume the identity https://example.com/me. In order for this module to be able to authenticate a user with this identity, such a user has to provide a TLS client certificate with the following `Subject Alternative Name:

URI:https://example.com

Dereferencing this identity must lead to a RDF document in one of the following formats: application/ld+json, text/turtle, text/n3, text/html (HTML5+RDFa).

The RDF document should contain triples equivalent to those shown in the following RDFa snippet:

<div about="ni:///sha-256;Mub5jcxUlUz6SG0oWKmHtIYGNgATBmPdRdlXiKxRBWw" typeof="cert:X509Certificate" prefix="cert:http://www.w3.org/ns/auth/cert#">
    <div rel="cert:identity" href="https://example.com/me"></div>
</div>

The certificate's URI must follow the Named Information URI format. Use the following command to generate the required base64-encoded SHA256 certificate fingerprint:

$ openssl x509 -in example.crt -inform pem -outform der | openssl dgst -sha256 -binary | openssl base64

Remove all padding = characters at the end of the fingerprint, as per the Named Information RFC.

API

var netid = require('netid-ni-tls');

Authenticator class

var authenticator = netid.createAuthenticator([opts]);

Authenticator.prototype.authenticate(clientCertInfo)

var clientCertInfo = req.connection.getPeerCertificate();

authenticator.authenticate(clientCertInfo)
    .then(function (auth) { ... });
    

This method expects the client TLS certificate of the user being authenticated in the form of the native nodejs object obtained through req.connection.getPeerCertificate().

This method returns an authentication object with the following properties:

{
    "success": true,                        // Whether the authentication has succeeded
    "netId": "https://example.com/john",    // The NetID that has been authenticated
    "clientCertInfo": { ... },              // Native getPeerCertificate() for the client used by the NetID
    "serverCertInfo": { ... },              // Native getPeerCertificate() for the server hosting the NetID
    "error": { ...}                         // The error that prevented a succeessful authentication, if any
    "createdAt": 1481458587406              // Operation timestamp
}

Authenticator.prototype.getMiddleware()

app.use(authenticator.getMiddleware());

This method returns an express-compatible authentication middleware which stores the resulting authentication object in req.auth .

Caching

On its own, an authenticator goes through the authentication process every time the authenticate(clientCertInfo) method is called (every request if using the middleware).

However, implementors can opt to override the authenticator._retrieve(netId, clientCertInfo) to return a previously cached authentication object to be used by the authenticator.

Every authenticator also emits an authentication event on every authentication, regardless of success or caching. This event can be used in conjunction with the _retrieve() method to implement caching.

authenticator._retrieve = function (netId, clientCertInfo) {
    return getCachedAuthenticationObject(netId, clientCertInfo)
        .then(function (auth) {
            return (auth.cachedAt > Date.now() - 1000 * 10)
                ? auth
                : null;
        });
};

authenticator.on('authentication', function (auth) {
      if (auth.success && !auth.cachedAt) {
        auth.cachedAt = Date.now();
        cacheAuthenticationObject(auth);
      }
});

Tests

A test server that echoes the authentication object to the client can be fired up using the following:

$ node test/server.js

The test server caches authentications for 10 seconds based on the client certificate's fingerprint.

License

MIT

Acknowledgements

Big thanks to the awesome folks at the public-webid mailing list for their wonderful suggestions.

Todo

  1. Automated tests