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

pepper-keychain

v0.1.1

Published

Simple API to create, query and delete passphrase peppers from the OS Keychain

Downloads

9

Readme

🌶 pepper-keychain

In cryptography, a pepper is a secret added to an input such as a passphrase during hashing with a cryptographic hash function. This value differs from a salt in that it is not stored alongside a passphrase hash, but rather the pepper is kept separate in some other medium, such as a Hardware Security Module

https://en.wikipedia.org/wiki/Pepper_(cryptography)

In Essence a passphrase plus random data is stronger than a passphrase alone. Most Apps and Databases can be dumped in one form or another, and if a KeyLogger is able to track the users input, your susceptible to getting your data stolen.

Enter Pepper-Keychain

Pepper-Keychain leverages the power of modern operating system keychains to supplement traditional master passphrase approach of "What you know" with a followup "What you have"

In an ideal world we could have a physical device separate to the machine generating peppers and maintaining a database for them, serving them up as required. We can get close to this with an OS Keychain API.

We use the Operating System Keychain to act a vault, your app calls createPepper with the users' passphrase, we create and store a random pepper in the keychain, map it to the passphrase hash (SHA3) and return it, where it can then be used to compliment the passphrase for encrypting.

Using this approach even if the encrypted data is lifted, and the passphrase is known the attacker then needs to penetrate the OS Keychain to access the accompanying peppers.

Word of Caution

This approach does not come without cost, only the device with those Peppers can be used to decrypt the content, this is somewhat inconvenient, depending on the use case. There will be additional overhead to create a migration package secure backup, or re-encrypt without the peppers on demand, but for some applications this additional layer is useful, hence this library 🙂

Usage

The Library exports simple functions createPepper and getPepper and deletePepper allowing crud operations on the peppers.

See API.md for additional information on usage.

Example

In this Example we take a Secret Message and wrap it in AES-256 Encryption, but rather than simply using the passphrase which is pretty useless against a lookup attack, we combine it with the randomly generated pepper which only the OS Keychain knows about.

const {AES, enc} = require("crypto-js");
const {getPepper, createPepper, deletePepper} = require("./src/pepper");

const SERVICE = "MyApp";
const ACCOUNT = "[email protected]";
const PASSPHRASE = "passphrase123!";
const SECRET_MESSAGE = "Launch Codes!!";

const main = async () => {
    // Create a New Pepper
    const savedPepper = await createPepper({
        service: SERVICE,
        account: ACCOUNT,
        passphrase: PASSPHRASE,
    }); // 4a4e16fcdefa26e3db2c4116f13659d6

    const pepperyPassphrase = PASSPHRASE + ":" + savedPepper; // passphrase123!:4a4e16fcdefa26e3db2c4116f13659d6

    // Apply AES-256 using PBKDF2 to derive Key from Known Passphrase and Pepper from KeyChain
    const encryptedContent = AES.encrypt(SECRET_MESSAGE, pepperyPassphrase);

    console.log(encryptedContent.toString()); // U2FsdGVkX1+G4C2ZTt6CkyTB36xyKEK+z9f084pIJy0=

    // --------- Do Something With Encrypted Content

    // Fetch Existing Pepper
    const queriedPepper = await getPepper({
        service: SERVICE,
        account: ACCOUNT,
        passphrase: PASSPHRASE,
    }); // 4a4e16fcdefa26e3db2c4116f13659d6

    const queriedPepperyPassphrase = PASSPHRASE + ":" + savedPepper; // passphrase123!:4a4e16fcdefa26e3db2c4116f13659d6

    const content = AES.decrypt(encryptedContent, queriedPepperyPassphrase);

    console.log(enc.Utf8.stringify(content)); //Launch Codes!!

    const result = await deletePepper({
        service: SERVICE,
        account: ACCOUNT,
        passphrase: PASSPHRASE,
    });
    console.log(result); // true
};

main();

Inside the Keychain

Peering Inside the Keychain the above example would produce the following KeyChain Entry

keychain.png pepper.png

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT