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

Function parseDER

lib/protocol/keyParser.js:1312–1391  ·  view source on GitHub ↗
(data, baseType, comment, fullType)

Source from the content-addressed store, hash-verified

1310
1311
1312function parseDER(data, baseType, comment, fullType) {
1313 if (!isSupportedKeyType(baseType))
1314 return new Error(`Unsupported OpenSSH public key type: ${baseType}`);
1315
1316 let algo;
1317 let oid;
1318 let pubPEM = null;
1319 let pubSSH = null;
1320
1321 switch (baseType) {
1322 case 'ssh-rsa': {
1323 const e = readString(data, data._pos || 0);
1324 if (e === undefined)
1325 return new Error('Malformed OpenSSH public key');
1326 const n = readString(data, data._pos);
1327 if (n === undefined)
1328 return new Error('Malformed OpenSSH public key');
1329 pubPEM = genOpenSSLRSAPub(n, e);
1330 pubSSH = genOpenSSHRSAPub(n, e);
1331 algo = 'sha1';
1332 break;
1333 }
1334 case 'ssh-dss': {
1335 const p = readString(data, data._pos || 0);
1336 if (p === undefined)
1337 return new Error('Malformed OpenSSH public key');
1338 const q = readString(data, data._pos);
1339 if (q === undefined)
1340 return new Error('Malformed OpenSSH public key');
1341 const g = readString(data, data._pos);
1342 if (g === undefined)
1343 return new Error('Malformed OpenSSH public key');
1344 const y = readString(data, data._pos);
1345 if (y === undefined)
1346 return new Error('Malformed OpenSSH public key');
1347 pubPEM = genOpenSSLDSAPub(p, q, g, y);
1348 pubSSH = genOpenSSHDSAPub(p, q, g, y);
1349 algo = 'sha1';
1350 break;
1351 }
1352 case 'ssh-ed25519': {
1353 const edpub = readString(data, data._pos || 0);
1354 if (edpub === undefined || edpub.length !== 32)
1355 return new Error('Malformed OpenSSH public key');
1356 pubPEM = genOpenSSLEdPub(edpub);
1357 pubSSH = genOpenSSHEdPub(edpub);
1358 algo = null;
1359 break;
1360 }
1361 case 'ecdsa-sha2-nistp256':
1362 algo = 'sha256';
1363 oid = '1.2.840.10045.3.1.7';
1364 // FALLTHROUGH
1365 case 'ecdsa-sha2-nistp384':
1366 if (algo === undefined) {
1367 algo = 'sha384';
1368 oid = '1.3.132.0.34';
1369 }

Callers 2

keyParser.jsFile · 0.85
parseKeyFunction · 0.85

Calls 10

isSupportedKeyTypeFunction · 0.85
genOpenSSLRSAPubFunction · 0.85
genOpenSSHRSAPubFunction · 0.85
genOpenSSLDSAPubFunction · 0.85
genOpenSSHDSAPubFunction · 0.85
genOpenSSLEdPubFunction · 0.85
genOpenSSHEdPubFunction · 0.85
skipFieldsFunction · 0.85
genOpenSSLECDSAPubFunction · 0.85
genOpenSSHECDSAPubFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…