1.0.1 • Published 6 years ago

client-creds v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

client-creds

Simple Node.js application using MongoDB to store and query FTP/WebDAV credentials with encrypted passwords.

Build Status

Installation and Configuration

npm install client-creds

After running npm install, a .env file (or your existing .env file) will be populated with MONGO_URI and CRYPTO_KEY. CRYPTO_KEY is a random 32 character string generated via the Node crypto module. You may replace it with your own random 32 character string. These environment variables must be present in your deployed application in order to use this module. Also, your CRYPTO_KEY value must be identical across environments in order to decrypt credentials across environments.

Documentation

There are two accessible methods in the module right now.

addCredentialAndGetIV(ftpObject)

addCredentialAndGetIV(ftpObject) - This method stores an encrypted Credential object in a MongoDB instance and returns passIV. passIV is a key generated each time you call addCredentialAndGetIV(ftpObject) to store a set of FTP credentials. It, along with your application-level CRYPTO_KEY, will be used for encryption and decryption. encryptedPass is the resulting encrypted password for your set of FTP credentials.

ftpObject (method parameter):

  {
    host: "exchange-test.si.net",
    port: 4321,
    username: "test-client",
    pass: "test-password",
    path: "/"
  }

Credential object (stored in MongoDB):

  {
    host: "exchange-test.si.net",
    port: 4321,
    username: "test-client",
    encryptedPass: "dcc0887374e5ff18ed3c36de4d99e10b",
    passIV: "14d89b043c89fb38",
    path: "/"
  }

It is suggested to store passIV on an associated object in your application so it may be used for decryption later.


decryptCredsFromIV(passIV)

decryptCredsFromIV(passIV) - expects a passIV from a set of encrypted FTP credentials generated with addCredentialAndGetIV(ftpObject) and returns a decrypted set of FTP credentials in the format of the ftpObject shown above. It is not recommended to pass these credentials over a query string or as a parameter in a HTTP request. Only use them to connect to the associated FTP server.

Example

const clientcredentials = require('clientcredentials');

// Expected object from form input
let ftpObject = {
  host: "exchange-test.si.net",
  port: 4321,
  username: "test-client",
  pass: "test-password",
  path: "/"
};

async function processClientRegistration(clientRegistrationObject, ftpObject) {
  let await passIV = clientcredentials.addCredentialAndGetIV(ftpObject);

  //sudo code
  let await clientModel = ProcessClientRegistrationObject(clientRegistrationObject);
  clientModel.passIV = passIV;
  await clientModel.save();
}

async function connectToFTPWithClientModel(clientModel) {
  let passIV = clientModel.passIV;

  let ftpObject = await clientcredentials.decryptCredsFromIV(passIV);

  //sudo code
  authenticateFTPCredentials(ftpObject).then((result) => {
    doAThing();
  });
}