| 184 | } |
| 185 | |
| 186 | function buildAuthHandler( |
| 187 | username: string, |
| 188 | privateKeys: readonly (Buffer | string)[], |
| 189 | password?: string, |
| 190 | ): ConnectConfig['authHandler'] { |
| 191 | const authQueue: AnyAuthMethod[] = privateKeys.map((key) => ({ |
| 192 | key, |
| 193 | type: 'publickey', |
| 194 | username, |
| 195 | })); |
| 196 | if (password !== undefined) { |
| 197 | authQueue.push({ |
| 198 | password, |
| 199 | type: 'password', |
| 200 | username, |
| 201 | }); |
| 202 | } |
| 203 | |
| 204 | let index = 0; |
| 205 | return (_authsLeft, _partialSuccess, next) => { |
| 206 | const nextAuth = authQueue[index]; |
| 207 | index += 1; |
| 208 | const nextWithFalse = next as (auth: AnyAuthMethod | false) => void; |
| 209 | nextWithFalse(nextAuth ?? false); |
| 210 | }; |
| 211 | } |
| 212 | |
| 213 | // ── SSH process ──────────────────────────────────────────────────────── |
| 214 | |