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

Method getIdentitiesReply

lib/agent.js:871–957  ·  view source on GitHub ↗
(req, keys)

Source from the content-addressed store, hash-verified

869 return respond(this, req, buf);
870 }
871 getIdentitiesReply(req, keys) {
872 if (this[SYM_MODE] !== ROLE_SERVER)
873 throw new Error('Server-only method called with client role');
874
875 if (!(req instanceof AgentInboundRequest))
876 throw new Error('Wrong request argument');
877
878 if (req.hasResponded())
879 return true;
880
881 /*
882 byte SSH_AGENT_IDENTITIES_ANSWER
883 uint32 nkeys
884
885 where `nkeys` is 0 or more of:
886 string key blob
887 string comment
888 */
889
890 if (req.getType() !== SSH_AGENTC_REQUEST_IDENTITIES)
891 throw new Error('Invalid response to request');
892
893 if (!Array.isArray(keys))
894 throw new Error('Keys argument must be an array');
895
896 let totalKeysLen = 4; // Include `nkeys` size
897
898 const newKeys = [];
899 for (let i = 0; i < keys.length; ++i) {
900 const entry = keys[i];
901 if (typeof entry !== 'object' || entry === null)
902 throw new Error(`Invalid key entry: ${entry}`);
903
904 let pubKey;
905 let comment;
906 if (isParsedKey(entry)) {
907 pubKey = entry;
908 } else if (isParsedKey(entry.pubKey)) {
909 pubKey = entry.pubKey;
910 } else {
911 if (typeof entry.pubKey !== 'object' || entry.pubKey === null)
912 continue;
913 ({ pubKey, comment } = entry.pubKey);
914 pubKey = parseKey(pubKey);
915 if (pubKey instanceof Error)
916 continue; // TODO: add debug output
917 }
918 comment = pubKey.comment || comment;
919 pubKey = pubKey.getPublicSSH();
920
921 totalKeysLen += 4 + pubKey.length;
922
923 if (comment && typeof comment === 'string')
924 comment = Buffer.from(comment);
925 else if (!Buffer.isBuffer(comment))
926 comment = EMPTY_BUF;
927
928 totalKeysLen += 4 + comment.length;

Callers 1

Calls 7

isParsedKeyFunction · 0.85
parseKeyFunction · 0.85
writeUInt32BEFunction · 0.85
respondFunction · 0.85
hasRespondedMethod · 0.80
getTypeMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected