(client, keys_, cb)
| 2057 | } |
| 2058 | |
| 2059 | function hostKeysProve(client, keys_, cb) { |
| 2060 | if (!client._sock || !isWritable(client._sock)) |
| 2061 | return; |
| 2062 | |
| 2063 | if (typeof cb !== 'function') |
| 2064 | cb = noop; |
| 2065 | |
| 2066 | if (!Array.isArray(keys_)) |
| 2067 | throw new TypeError('Invalid keys argument type'); |
| 2068 | |
| 2069 | const keys = []; |
| 2070 | for (const key of keys_) { |
| 2071 | const parsed = parseKey(key); |
| 2072 | if (parsed instanceof Error) |
| 2073 | throw parsed; |
| 2074 | keys.push(parsed); |
| 2075 | } |
| 2076 | |
| 2077 | if (!client.config.strictVendor |
| 2078 | || (client.config.strictVendor && RE_OPENSSH.test(client._remoteVer))) { |
| 2079 | client._callbacks.push((had_err, data) => { |
| 2080 | if (had_err) { |
| 2081 | cb(had_err !== true |
| 2082 | ? had_err |
| 2083 | : new Error('Server failed to prove supplied keys')); |
| 2084 | return; |
| 2085 | } |
| 2086 | |
| 2087 | // TODO: move all of this parsing/verifying logic out of the client? |
| 2088 | const ret = []; |
| 2089 | let keyIdx = 0; |
| 2090 | bufferParser.init(data, 0); |
| 2091 | while (bufferParser.avail()) { |
| 2092 | if (keyIdx === keys.length) |
| 2093 | break; |
| 2094 | const key = keys[keyIdx++]; |
| 2095 | const keyPublic = key.getPublicSSH(); |
| 2096 | |
| 2097 | const sigEntry = bufferParser.readString(); |
| 2098 | sigParser.init(sigEntry, 0); |
| 2099 | const type = sigParser.readString(true); |
| 2100 | let value = sigParser.readString(); |
| 2101 | |
| 2102 | let algo; |
| 2103 | if (type !== key.type) { |
| 2104 | if (key.type === 'ssh-rsa') { |
| 2105 | switch (type) { |
| 2106 | case 'rsa-sha2-256': |
| 2107 | algo = 'sha256'; |
| 2108 | break; |
| 2109 | case 'rsa-sha2-512': |
| 2110 | algo = 'sha512'; |
| 2111 | break; |
| 2112 | default: |
| 2113 | continue; |
| 2114 | } |
| 2115 | } else { |
| 2116 | continue; |
no test coverage detected
searching dependent graphs…