MCPcopy
hub / github.com/mongodb/node-mongodb-native / makeFirstMessage

Function makeFirstMessage

src/cmap/auth/scram.ts:78–98  ·  view source on GitHub ↗
(
  cryptoMethod: CryptoMethod,
  credentials: MongoCredentials,
  nonce: Uint8Array
)

Source from the content-addressed store, hash-verified

76}
77
78function 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
100async function executeScram(cryptoMethod: CryptoMethod, authContext: AuthContext): Promise<void> {
101 const { connection, credentials } = authContext;

Callers 2

prepareMethod · 0.85
executeScramFunction · 0.85

Calls 2

cleanUsernameFunction · 0.85
clientFirstMessageBareFunction · 0.85

Tested by

no test coverage detected