Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
User.findOne({username: ctx.username}, function(err, doc){
if (doc) {
if (ctx.method === 'publickey'
&& ctx.username!=undefined
&& doc.publicKey
&& doc.publicKey.length !== 0) {
console.log(' ** trying key auth');
//load publickey by username
if(doc.publicKey && doc.publicKey.length) {
var publicKey = utils.genPublicKey(utils.parseKey(doc.publicKey));
var successfulKeyAuth = ctx.key.algo === publicKey.fulltype
&& buffersEqual(ctx.key.data, publicKey.public);
if (successfulKeyAuth) {
// user logged in via key, serve interface
console.log('[ok] key auth');
userMeta.next = 'auth';
userMeta.user = doc;
ctx.accept();
} else {
console.log('[no] key auth');
return ctx.reject();
}
} else {
constructor(options) {
super();
this._options = options || {};
var clientPublicKeyPath = _.get(options, 'client_public_key');
if (clientPublicKeyPath) {
this.clientPublicKey = ssh_utils.genPublicKey(ssh_utils.parseKey(fs.readFileSync(clientPublicKeyPath)));
}
}