How to use the sshpk.parseKey function in sshpk

To help you get started, we’ve selected a few sshpk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tessel / t2-cli / lib / tessel / provision.js View on Github external
return new Promise(function(resolve, reject) {

    if (Tessel.isProvisioned()) {
      return resolve();
    }

    log.info('Creating public and private keys for Tessel authentication...');

    // Generate SSH key
    var key = new RSA({
      b: 2048
    });
    var privateKey = key.exportKey('private');
    var publicKey = sshpk.parseKey(key.exportKey('public'), 'pem').toString('ssh') + '\n';

    // Make sure dir exists
    fs.ensureDir(path.dirname(keyFile), function(err) {
      if (err) {
        return reject(err);
      }

      // Put SSH keys for Tessel in that folder
      // Set the permission to 0600 (decimal 384)
      // owner can read and write
      var fileOptions = {
        encoding: 'utf8',
        mode: 0o600,
      };
      async.parallel([
          (cb) => fs.writeFile(keyFile + '.pub', publicKey, fileOptions, cb), (cb) => fs.writeFile(keyFile, privateKey, fileOptions, cb),
github Soluto / tweek / services / authoring / src / server.ts View on Github external
async function startServer() {
  await appsRepository.refresh();
  const app = express();
  const publicKey = sshpk
    .parseKey(await fs.readFile(gitRepositoryConfig.publicKey), 'auto')
    .toBuffer('pem');
  app.use(requestLogger);
  app.use(configurePassport(publicKey, appsRepository));
  app.use(express.json()); // for parsing application/json
  app.use(express.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
  app.get('/version', (req, res) => res.send(process.env.npm_package_version));
  app.get('/health', (req, res) => res.status(200).json({}));
  app.use(
    '/api',
    auth,
    routes({
      tagsRepository,
      keysRepository,
      appsRepository,
      policyRepository,
github replicatedhq / kots / kotsadm / api / src / apps / resolvers / apps_mutations.ts View on Github external
const { gitOpsInput } = args;

      const { publicKey, privateKey } = generateKeyPairSync("rsa", {
        modulusLength: 4096,
        publicKeyEncoding: {
          type: "pkcs1",
          format: "pem",
        },
        privateKeyEncoding: {
          type: "pkcs1",
          format: "pem",
        },
      });

      const params = await Params.getParams();
      const parsedPublic = sshpk.parseKey(publicKey, "pem");
      const sshPublishKey = parsedPublic.toString("ssh");

      const encryptedPrivateKey = await kotsEncryptString(params.apiEncryptionKey, privateKey);
      await stores.kotsAppStore.createGitOpsRepo(gitOpsInput.provider, gitOpsInput.uri, gitOpsInput.hostname, encryptedPrivateKey, sshPublishKey);

      return true;
    },
github charlielin99 / Jobalytics / node_modules / http-signature / lib / utils.js View on Github external
sshKeyToPEM: function sshKeyToPEM(key) {
    assert.string(key, 'ssh_key');

    var k = sshpk.parseKey(key, 'ssh');
    return (k.toString('pem'));
  },
github amazeeio / lagoon / services / api / src / routes / keys.js View on Github external
const toFingerprint = sshKey => {
  try {
    return sshpk
      .parseKey(sshKey, 'ssh')
      .fingerprint()
      .toString();
  } catch (e) {
    logger.error(`Invalid ssh key: ${sshKey}`);
  }
};
github joyent / sdc-docker / lib / auth.js View on Github external
function verifyKey(_, cb) {
        var key;
        try {
            key = sshpk.parseKey(ufdsKey.pkcs);
        } catch (err) {
            log.error({err: err, login: login, key: ufdsKey.fingerprint},
                'failed to parse pkcs key from UFDS');
            cb(new errors.UnauthorizedError());
            return;
        }
        /*
         * Check the actual signature on the certificate -- this will prevent
         * MD5 collisions from authing the key in the self-signed case,
         * and will do the actual validation in the account-key-signed case.
         */
        if (cert.isSignedByKey(key)) {
            authCache.set(login, peerKeyFp);
            cb();
        } else {
            log.info({login: login, authn: true},
github Strider-CD / strider / lib / ssh.js View on Github external
exports.generateKeyPair = function (comment, callback) {
  debug('Generating SSH key pair...');
  try {
    var key = new NodeRSA();
    key.generateKeyPair();
    var privateKeyPem = key.exportKey('pkcs1-private-pem');
    var publicKeyPem = key.exportKey('pkcs1-public-pem');
    var publicKey = sshpk.parseKey(publicKeyPem, 'pem');
    publicKey.comment = comment;

    callback(null, privateKeyPem, publicKey.toString());

  } catch (error) {
    callback(error);
  }
};
github joyent / node-http-signature / lib / utils.js View on Github external
pemToRsaSSHKey: function pemToRsaSSHKey(pem, comment) {
    assert.equal('string', typeof (pem), 'typeof pem');

    var k = sshpk.parseKey(pem, 'pem');
    k.comment = comment;
    return (k.toString('ssh'));
  }
};
github joyent / node-http-signature / lib / utils.js View on Github external
sshKeyToPEM: function sshKeyToPEM(key) {
    assert.string(key, 'ssh_key');

    var k = sshpk.parseKey(key, 'ssh');
    return (k.toString('pem'));
  },
github charlielin99 / Jobalytics / node_modules / http-signature / lib / utils.js View on Github external
pemToRsaSSHKey: function pemToRsaSSHKey(pem, comment) {
    assert.equal('string', typeof (pem), 'typeof pem');

    var k = sshpk.parseKey(pem, 'pem');
    k.comment = comment;
    return (k.toString('ssh'));
  }
};

sshpk

A library for finding and using SSH public keys

MIT
Latest version published 1 year ago

Package Health Score

74 / 100
Full package analysis