Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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),
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,
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;
},
sshKeyToPEM: function sshKeyToPEM(key) {
assert.string(key, 'ssh_key');
var k = sshpk.parseKey(key, 'ssh');
return (k.toString('pem'));
},
const toFingerprint = sshKey => {
try {
return sshpk
.parseKey(sshKey, 'ssh')
.fingerprint()
.toString();
} catch (e) {
logger.error(`Invalid ssh key: ${sshKey}`);
}
};
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},
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);
}
};
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'));
}
};
sshKeyToPEM: function sshKeyToPEM(key) {
assert.string(key, 'ssh_key');
var k = sshpk.parseKey(key, 'ssh');
return (k.toString('pem'));
},
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'));
}
};