MCPcopy Create free account
hub / github.com/mscdex/ssh2 / parseOpenSSHPrivKeys

Function parseOpenSSHPrivKeys

lib/protocol/keyParser.js:607–794  ·  view source on GitHub ↗
(data, nkeys, decrypted)

Source from the content-addressed store, hash-verified

605 };
606
607 function parseOpenSSHPrivKeys(data, nkeys, decrypted) {
608 const keys = [];
609 /*
610 uint32 checkint
611 uint32 checkint
612 string privatekey1
613 string comment1
614 string privatekey2
615 string comment2
616 ...
617 string privatekeyN
618 string commentN
619 char 1
620 char 2
621 char 3
622 ...
623 char padlen % 255
624 */
625 if (data.length < 8)
626 return new Error('Malformed OpenSSH private key');
627 const check1 = readUInt32BE(data, 0);
628 const check2 = readUInt32BE(data, 4);
629 if (check1 !== check2) {
630 if (decrypted) {
631 return new Error(
632 'OpenSSH key integrity check failed -- bad passphrase?'
633 );
634 }
635 return new Error('OpenSSH key integrity check failed');
636 }
637 data._pos = 8;
638 let i;
639 let oid;
640 for (i = 0; i < nkeys; ++i) {
641 let algo;
642 let privPEM;
643 let pubPEM;
644 let pubSSH;
645 // The OpenSSH documentation for the key format actually lies, the
646 // entirety of the private key content is not contained with a string
647 // field, it's actually the literal contents of the private key, so to be
648 // able to find the end of the key data you need to know the layout/format
649 // of each key type ...
650 const type = readString(data, data._pos, true);
651 if (type === undefined)
652 return new Error('Malformed OpenSSH private key');
653
654 switch (type) {
655 case 'ssh-rsa': {
656 /*
657 string n -- public
658 string e -- public
659 string d -- private
660 string iqmp -- private
661 string p -- private
662 string q -- private
663 */
664 const n = readString(data, data._pos);

Callers 1

keyParser.jsFile · 0.85

Calls 15

readUInt32BEFunction · 0.85
genOpenSSLRSAPubFunction · 0.85
genOpenSSHRSAPubFunction · 0.85
genOpenSSLDSAPubFunction · 0.85
genOpenSSHDSAPubFunction · 0.85
genOpenSSLDSAPrivFunction · 0.85
genOpenSSLEdPubFunction · 0.85
genOpenSSHEdPubFunction · 0.85
genOpenSSLEdPrivFunction · 0.85
bufferSliceFunction · 0.85
skipFieldsFunction · 0.85
genOpenSSLECDSAPubFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…