( cryptoMethod: CryptoMethod, credentials: MongoCredentials, nonce: Uint8Array )
| 76 | } |
| 77 | |
| 78 | function makeFirstMessage( |
| 79 | cryptoMethod: CryptoMethod, |
| 80 | credentials: MongoCredentials, |
| 81 | nonce: Uint8Array |
| 82 | ) { |
| 83 | const username = cleanUsername(credentials.username); |
| 84 | const mechanism = |
| 85 | cryptoMethod === 'sha1' ? AuthMechanism.MONGODB_SCRAM_SHA1 : AuthMechanism.MONGODB_SCRAM_SHA256; |
| 86 | |
| 87 | // NOTE: This is done b/c Javascript uses UTF-16, but the server is hashing in UTF-8. |
| 88 | // Since the username is not sasl-prep-d, we need to do this here. |
| 89 | return { |
| 90 | saslStart: 1, |
| 91 | mechanism, |
| 92 | payload: new Binary( |
| 93 | ByteUtils.concat([ByteUtils.fromUTF8('n,,'), clientFirstMessageBare(username, nonce)]) |
| 94 | ), |
| 95 | autoAuthorize: 1, |
| 96 | options: { skipEmptyExchange: true } |
| 97 | }; |
| 98 | } |
| 99 | |
| 100 | async function executeScram(cryptoMethod: CryptoMethod, authContext: AuthContext): Promise<void> { |
| 101 | const { connection, credentials } = authContext; |
no test coverage detected