Code Monkey home page Code Monkey logo

cloak's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar franky47 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

Watchers

 avatar  avatar  avatar  avatar

cloak's Issues

Use SHA-512 for key fingerprint

It's faster to calculate on 64 bit systems, and we're only keeping the first 16 characters anyway, so length does not matter much.

CLI command decrypt fails with 'Key is not available'

Example:

❯ node -v
v16.18.0

❯ npm install -g @47ng/cloak

❯ cloak generate
Key:          k1.aesgcm256.xDQ816copHeT8jWCNGHinlashyfB5hOXR8wcvXbReeM=
Fingerprint:  d5fff283

# Generated new empty keychain:
export CLOAK_MASTER_KEY=k1.aesgcm256.xDQ816copHeT8jWCNGHinlashyfB5hOXR8wcvXbReeM=
export CLOAK_KEYCHAIN=v1.aesgcm256.d5fff283.RJPDSOWSrJubssj7.CHTk4XNSpHFKMISv3_hwdMev

❯ echo 'test' | cloak encrypt 'k1.aesgcm256.xDQ816copHeT8jWCNGHinlashyfB5hOXR8wcvXbReeM='
v1.aesgcm256.d5fff283.RWkS6dy0bZRfe8jn.KJ2CN-QinTiQhnFFFa9qNk9sgMrs

❯ export CLOAK_MASTER_KEY=k1.aesgcm256.xDQ816copHeT8jWCNGHinlashyfB5hOXR8wcvXbReeM=

❯ export CLOAK_KEYCHAIN=v1.aesgcm256.d5fff283.RJPDSOWSrJubssj7.CHTk4XNSpHFKMISv3_hwdMev

❯ echo 'v1.aesgcm256.d5fff283.RWkS6dy0bZRfe8jn.KJ2CN-QinTiQhnFFFa9qNk9sgMrs' | cloak decrypt
Error: Error: Key is not available

As best as I can tell, the root cause of this is that decrypt calls getEnvKeychain which calls importKeychain which itself calls decryptString and then decryptAesGcm which passes to decryptAesGcmSync. It is here, in decryptAesGcmSync that the Node's Decipher returns an empty array after the final update + final, which is unexpected.

I tried writing a failing test, but got blocked on being able to pass stdin to Commander in jest. Something like this is the foundation though:

import program from './cli';

const OLD_ENV = process.env;

beforeEach(() => {
  jest.resetModules();
  
  process.env = {
    ...OLD_ENV,
    CLOAK_MASTER_KEY: 'k1.aesgcm256.2itF7YmMYIP4b9NNtKMhIx2axGi6aI50RcwGBiFq-VA=',
  };
});

afterAll(() => {
  process.env = OLD_ENV;
});

test('decrypt', () => {
  const cipher = 'v1.aesgcm256.710bb0e2.F5wkSytfdVv4xvtN.8uNajc7ufhVmMFpDdzWgKMKhOY4ZR2OSv1DFjvnm'
  const expected = 'Hello, World !'
  expect(() => {
    program.parse(['decrypt', cipher]);
  }).toReturnWith(expected)
})

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.