/opt/canhelp/node_modules/gel/dist
NameSizeModeActions
codecs/-0755rm
datatypes/-0755rm
errors/-0755rm
primitives/-0755rm
reflection/-0755rm
baseClient.d.ts58870644editdlrm
baseClient.js198870644editdlrm
baseConn.d.ts48900644editdlrm
baseConn.js315880644editdlrm
browserClient.d.ts2000644editdlrm
browserClient.js12120644editdlrm
browserCrypto.d.ts910644editdlrm
browserCrypto.js7240644editdlrm
cli.mjs74390755editdlrm
codecTypeRegistry.d.ts1950644editdlrm
codecTypeRegistry.js770644editdlrm
conUtils.d.ts55400644editdlrm
conUtils.js362590644editdlrm
conUtils.server.d.ts5550644editdlrm
conUtils.server.js32660644editdlrm
credentials.d.ts5610644editdlrm
credentials.js41580644editdlrm
cryptoUtils.d.ts1060644editdlrm
cryptoUtils.js8110644editdlrm
fetchConn.d.ts28000644editdlrm
fetchConn.js75450644editdlrm
httpScram.d.ts2290644editdlrm
httpScram.js39700644editdlrm
ifaces.d.ts25300644editdlrm
ifaces.js28470644editdlrm
index.browser.d.ts8670644editdlrm
index.browser.js19730644editdlrm
index.node.d.ts12750644editdlrm
index.node.js32660644editdlrm
index.shared.d.ts18960644editdlrm
index.shared.js54860644editdlrm
nodeClient.d.ts2400644editdlrm
nodeClient.js15290644editdlrm
nodeCrypto.d.ts910644editdlrm
nodeCrypto.js9170644editdlrm
options.d.ts42540644editdlrm
options.js112490644editdlrm
platform.d.ts1240644editdlrm
platform.js17310644editdlrm
rawConn.d.ts12180644editdlrm
rawConn.js173140644editdlrm
retry.d.ts11530644editdlrm
retry.js39250644editdlrm
scram.d.ts17230644editdlrm
scram.js60040644editdlrm
systemUtils.d.ts4830644editdlrm
systemUtils.js38400644editdlrm
transaction.d.ts17380644editdlrm
transaction.js81130644editdlrm
typeutil.d.ts2430644editdlrm
typeutil.js770644editdlrm
utils.d.ts19250644editdlrm
utils.js37270644editdlrm
Edit: /opt/canhelp/node_modules/gel/dist/scram.js (6004B)
"use strict"; /*! * This source file is part of the Gel open source project. * * Copyright 2019-present MagicStack Inc. and the Gel authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.saslprep = saslprep; exports.getSCRAM = getSCRAM; const buffer_1 = require("./primitives/buffer"); const errors_1 = require("./errors"); const RAW_NONCE_LENGTH = 18; function saslprep(str) { return str.normalize("NFKC"); } function getSCRAM({ randomBytes, H, HMAC, makeKey }) { function bufferEquals(a, b) { if (a.length !== b.length) { return false; } for (let i = 0, len = a.length; i < len; i++) { if (a[i] !== b[i]) { return false; } } return true; } function generateNonce(length = RAW_NONCE_LENGTH) { return randomBytes(length); } function buildClientFirstMessage(clientNonce, username) { const bare = `n=${saslprep(username)},r=${(0, buffer_1.encodeB64)(clientNonce)}`; return [`n,,${bare}`, bare]; } function parseServerFirstMessage(msg) { const attrs = msg.split(","); if (attrs.length < 3) { throw new errors_1.ProtocolError("malformed SCRAM message"); } const nonceAttr = attrs[0]; if (!nonceAttr || nonceAttr[0] !== "r") { throw new errors_1.ProtocolError("malformed SCRAM message"); } const nonceB64 = nonceAttr.split("=", 2)[1]; if (!nonceB64) { throw new errors_1.ProtocolError("malformed SCRAM message"); } const nonce = (0, buffer_1.decodeB64)(nonceB64); const saltAttr = attrs[1]; if (!saltAttr || saltAttr[0] !== "s") { throw new errors_1.ProtocolError("malformed SCRAM message"); } const saltB64 = saltAttr.split("=", 2)[1]; if (!saltB64) { throw new errors_1.ProtocolError("malformed SCRAM message"); } const salt = (0, buffer_1.decodeB64)(saltB64); const iterAttr = attrs[2]; if (!iterAttr || iterAttr[0] !== "i") { throw new errors_1.ProtocolError("malformed SCRAM message"); } const iter = iterAttr.split("=", 2)[1]; if (!iter || !iter.match(/^[0-9]*$/)) { throw new errors_1.ProtocolError("malformed SCRAM message"); } const iterCount = parseInt(iter, 10); if (iterCount <= 0) { throw new errors_1.ProtocolError("malformed SCRAM message"); } return [nonce, salt, iterCount]; } function parseServerFinalMessage(msg) { const attrs = msg.split(","); if (attrs.length < 1) { throw new errors_1.ProtocolError("malformed SCRAM message"); } const nonceAttr = attrs[0]; if (!nonceAttr || nonceAttr[0] !== "v") { throw new errors_1.ProtocolError("malformed SCRAM message"); } const signatureB64 = nonceAttr.split("=", 2)[1]; if (!signatureB64) { throw new errors_1.ProtocolError("malformed SCRAM message"); } return (0, buffer_1.decodeB64)(signatureB64); } async function buildClientFinalMessage(password, salt, iterations, clientFirstBare, serverFirst, serverNonce) { const clientFinal = `c=biws,r=${(0, buffer_1.encodeB64)(serverNonce)}`; const authMessage = buffer_1.utf8Encoder.encode(`${clientFirstBare},${serverFirst},${clientFinal}`); const saltedPassword = await _getSaltedPassword(buffer_1.utf8Encoder.encode(saslprep(password)), salt, iterations); const clientKey = await _getClientKey(saltedPassword); const storedKey = await H(clientKey); const clientSignature = await HMAC(storedKey, authMessage); const clientProof = _XOR(clientKey, clientSignature); const serverKey = await _getServerKey(saltedPassword); const serverProof = await HMAC(serverKey, authMessage); return [`${clientFinal},p=${(0, buffer_1.encodeB64)(clientProof)}`, serverProof]; } async function _getSaltedPassword(password, salt, iterations) { const msg = new Uint8Array(salt.length + 4); msg.set(salt); msg.set([0, 0, 0, 1], salt.length); const keyFromPassword = await makeKey(password); let Hi = await HMAC(keyFromPassword, msg); let Ui = Hi; for (let _ = 0; _ < iterations - 1; _++) { Ui = await HMAC(keyFromPassword, Ui); Hi = _XOR(Hi, Ui); } return Hi; } function _getClientKey(saltedPassword) { return HMAC(saltedPassword, buffer_1.utf8Encoder.encode("Client Key")); } function _getServerKey(saltedPassword) { return HMAC(saltedPassword, buffer_1.utf8Encoder.encode("Server Key")); } function _XOR(a, b) { const len = a.length; if (len !== b.length) { throw new errors_1.ProtocolError("scram.XOR: buffers are of different lengths"); } const res = new Uint8Array(len); for (let i = 0; i < len; i++) { res[i] = a[i] ^ b[i]; } return res; } return { bufferEquals, generateNonce, buildClientFirstMessage, parseServerFirstMessage, parseServerFinalMessage, buildClientFinalMessage, _getSaltedPassword, _getClientKey, _getServerKey, _XOR, }; }