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

rpki-validator

v2.13.13

Published

An RPKI validator that works also in the browser.

Downloads

290

Readme

rpki-validator

This is a JavaScript tool which provides RPKI lookup/validation functionalities.
This tool is designed to be used for data analysis and visualization, and it is able to check more than 20k prefixes per second. It works both server side with node.js or in the browser.

This tool is not designed for routing security implementation. There is no cryptography involved in this tool, the validation is based on Validated ROA Payloads files (VRPs)

VRP files are provided by:

Install

Run: npm install rpki-validator

Place in your code: import RpkiValidator from "rpki-validator";

Validate

To validate the a <prefix, origin> pair:

const prefix = "165.254.225.0/24";
const origin = 15562;
const verbose = true;

const rpki = new RpkiValidator();

rpki.validate(prefix, origin, verbose)
    .then((result) => {
        // Do something with "result"
    })

The parameter verbose defines the amount of information provided as a result.

If verbose is false or missing, the result will be one of:

  • true - if rpki valid
  • false - if rpki invalid
  • null - if no ROA was found for this prefix

If verbose is true, the result will be an object like:

{
    valid: true|false|null,
    reason: "A string describing the reason",
    covering: [{
        asn: 15562,
        prefix: "165.254.225.0/21",
        maxLength: 24,
        expires: 1633702845
    }]
}

Possible reason values are:

  • Not valid origin
  • Not valid prefix length
  • No ROA available for this prefix
  • null (when valid is true)

The covering array is the list of ROAs covering the queried prefix.

IMPORTANT: In this case you are not using a VRP file, but an online API. Please, read the section below to understand how to load a VRP file and do more frequent validations.

Multiple validations

If you are planning to validate many <prefix, origin> pairs, use preCache as shown below:

rpki.preCache()
    .then(() => {
        // The cache is loaded, do here your validations

        rpki.validate(prefix, origin, verbose)
            .then((result) => {
                // Do something with "result"
            })
    })

The preCache method downloads a complete VRP list, this may take some seconds. Do your validations inside the .then if you want to be sure all validations are happening in cache. If you instead do validations outside the .then, these will be executed online up to when the cache is ready. When the cache is ready, all validations will happen based on the cache.

The .preCache() method can take an optional parameter indicating after how many minutes the cache will be automatically refreshed (see below for more info). E.g., prki.preCache(60) to refresh the cache every hour.

IMPORTANT: preCache uses a good amount of memory (at the moment ~40Mb, but this will grow in the future) to store the cache. This may be less suitable for running in a browser.

Options

It is possible to specify options while creating the validator. In the following way:

const options = {
    httpsAgent, // an http(s) agent, e.g., to use a proxy https://www.npmjs.com/package/https-proxy-agent
    connector //one of "rpkiclient", "ntt", "cloudflare", "ripe", "external", "api" (default: "rpkiclient")
};

const rpki = new RpkiValidator(options);

Example, to change the VRP provider to NTT:

const rpki = new RpkiValidator({ connector: "ntt" });

The VRP provider can also be changed at runtime

rpki.setConnector("ripe");

RPKI auto-refresh limits

Each connector has limits on how much time can be specified for the auto-refresh option:

  • rpkiclient, 5 min
  • ntt, 15 min
  • ripe, 10 min
  • cloudflare, 20 min
  • external, not available (based on when new data is applied)
  • api, 5 min

External VRPs

You can load your VRPs in the following way:

const rpki = new rpkiValidator({ connector: "external" });

rpki.setVRPs([{
    prefix: "123.4.5.0/24",
    maxLength: 24,
    asn: 1234
}, {
    prefix: "321.4.5.0/22",
    maxLength: 22,
    asn: 9876
}
]);

rpki.preCache()
    .then(() => {
        // External VRPs loaded

        rpki.validate(prefix, origin, verbose)
            .then((result) => {
                // Do something with "result"
            })
    })

VRPs on custom API

Also, you can load your VRPs by providing a URL of an API.

const rpki = new rpkiValidator({ connector: "api", url: "https://my-api.api.com/vrps/" });

rpki.preCache()
    .then(() => {
        // VRPs from API loaded

        rpki.validate(prefix, origin, verbose)
            .then((result) => {
                // Do something with "result"
            })
    })

The API must produce a JSON output like:

{
  "roas": [{
    "prefix": "123.4.5.0/24",
    "maxLength": 24,
    "asn": 1234
  }, {
    "prefix": "321.4.5.0/22",
    "maxLength": 22,
    "asn": 9876
  }]
}