| 712 | } |
| 713 | |
| 714 | async function SASLContinue(x) { |
| 715 | const res = x.toString('utf8', 9).split(',').reduce((acc, x) => (acc[x[0]] = x.slice(2), acc), {}) |
| 716 | |
| 717 | const saltedPassword = await crypto.pbkdf2Sync( |
| 718 | await Pass(), |
| 719 | Buffer.from(res.s, 'base64'), |
| 720 | parseInt(res.i), 32, |
| 721 | 'sha256' |
| 722 | ) |
| 723 | |
| 724 | const clientKey = await hmac(saltedPassword, 'Client Key') |
| 725 | |
| 726 | const auth = 'n=*,r=' + nonce + ',' |
| 727 | + 'r=' + res.r + ',s=' + res.s + ',i=' + res.i |
| 728 | + ',c=biws,r=' + res.r |
| 729 | |
| 730 | serverSignature = (await hmac(await hmac(saltedPassword, 'Server Key'), auth)).toString('base64') |
| 731 | |
| 732 | const payload = 'c=biws,r=' + res.r + ',p=' + xor( |
| 733 | clientKey, Buffer.from(await hmac(await sha256(clientKey), auth)) |
| 734 | ).toString('base64') |
| 735 | |
| 736 | write( |
| 737 | b().p().str(payload).end() |
| 738 | ) |
| 739 | } |
| 740 | |
| 741 | function SASLFinal(x) { |
| 742 | if (x.toString('utf8', 9).split(b.N, 1)[0].slice(2) === serverSignature) |