(username, pubKey, hostname, userlocal, keyAlgo, cbSign)
| 748 | }); |
| 749 | } |
| 750 | authHostbased(username, pubKey, hostname, userlocal, keyAlgo, cbSign) { |
| 751 | // TODO: Make DRY by sharing similar code with authPK() |
| 752 | if (this._server) |
| 753 | throw new Error('Client-only method called in server mode'); |
| 754 | |
| 755 | pubKey = parseKey(pubKey); |
| 756 | if (pubKey instanceof Error) |
| 757 | throw new Error('Invalid key'); |
| 758 | |
| 759 | const keyType = pubKey.type; |
| 760 | pubKey = pubKey.getPublicSSH(); |
| 761 | |
| 762 | if (typeof keyAlgo === 'function') { |
| 763 | cbSign = keyAlgo; |
| 764 | keyAlgo = undefined; |
| 765 | } |
| 766 | if (!keyAlgo) |
| 767 | keyAlgo = keyType; |
| 768 | |
| 769 | const userLen = Buffer.byteLength(username); |
| 770 | const algoLen = Buffer.byteLength(keyAlgo); |
| 771 | const pubKeyLen = pubKey.length; |
| 772 | const sessionID = this._kex.sessionID; |
| 773 | const sesLen = sessionID.length; |
| 774 | const hostnameLen = Buffer.byteLength(hostname); |
| 775 | const userlocalLen = Buffer.byteLength(userlocal); |
| 776 | const data = Buffer.allocUnsafe( |
| 777 | 4 + sesLen + 1 + 4 + userLen + 4 + 14 + 4 + 9 + 4 + algoLen |
| 778 | + 4 + pubKeyLen + 4 + hostnameLen + 4 + userlocalLen |
| 779 | ); |
| 780 | let p = 0; |
| 781 | |
| 782 | writeUInt32BE(data, sesLen, p); |
| 783 | data.set(sessionID, p += 4); |
| 784 | |
| 785 | data[p += sesLen] = MESSAGE.USERAUTH_REQUEST; |
| 786 | |
| 787 | writeUInt32BE(data, userLen, ++p); |
| 788 | data.utf8Write(username, p += 4, userLen); |
| 789 | |
| 790 | writeUInt32BE(data, 14, p += userLen); |
| 791 | data.utf8Write('ssh-connection', p += 4, 14); |
| 792 | |
| 793 | writeUInt32BE(data, 9, p += 14); |
| 794 | data.utf8Write('hostbased', p += 4, 9); |
| 795 | |
| 796 | writeUInt32BE(data, algoLen, p += 9); |
| 797 | data.utf8Write(keyAlgo, p += 4, algoLen); |
| 798 | |
| 799 | writeUInt32BE(data, pubKeyLen, p += algoLen); |
| 800 | data.set(pubKey, p += 4); |
| 801 | |
| 802 | writeUInt32BE(data, hostnameLen, p += pubKeyLen); |
| 803 | data.utf8Write(hostname, p += 4, hostnameLen); |
| 804 | |
| 805 | writeUInt32BE(data, userlocalLen, p += hostnameLen); |
| 806 | data.utf8Write(userlocal, p += 4, userlocalLen); |
| 807 |
no test coverage detected