in src/accountImporter.js [167:261]
var _validateRequiredParameters = function (options) {
if (!options.hashAlgo) {
utils.logWarning("No hash algorithm specified. Password users cannot be imported.");
return { valid: true };
}
var hashAlgo = options.hashAlgo.toUpperCase();
let roundsNum;
switch (hashAlgo) {
case "HMAC_SHA512":
case "HMAC_SHA256":
case "HMAC_SHA1":
case "HMAC_MD5":
if (!options.hashKey || options.hashKey === "") {
throw new FirebaseError(
"Must provide hash key(base64 encoded) for hash algorithm " + options.hashAlgo,
{ exit: 1 }
);
}
return { hashAlgo: hashAlgo, hashKey: options.hashKey, valid: true };
case "MD5":
case "SHA1":
case "SHA256":
case "SHA512":
// MD5 is [0,8192] but SHA1, SHA256, and SHA512 are [1,8192]
roundsNum = parseInt(options.rounds, 10);
var minRounds = hashAlgo === "MD5" ? 0 : 1;
if (isNaN(roundsNum) || roundsNum < minRounds || roundsNum > 8192) {
throw new FirebaseError(
`Must provide valid rounds(${minRounds}..8192) for hash algorithm ${options.hashAlgo}`,
{ exit: 1 }
);
}
return { hashAlgo: hashAlgo, rounds: options.rounds, valid: true };
case "PBKDF_SHA1":
case "PBKDF2_SHA256":
roundsNum = parseInt(options.rounds, 10);
if (isNaN(roundsNum) || roundsNum < 0 || roundsNum > 120000) {
throw new FirebaseError(
"Must provide valid rounds(0..120000) for hash algorithm " + options.hashAlgo,
{ exit: 1 }
);
}
return { hashAlgo: hashAlgo, rounds: options.rounds, valid: true };
case "SCRYPT":
if (!options.hashKey || options.hashKey === "") {
throw new FirebaseError(
"Must provide hash key(base64 encoded) for hash algorithm " + options.hashAlgo,
{ exit: 1 }
);
}
roundsNum = parseInt(options.rounds, 10);
if (isNaN(roundsNum) || roundsNum <= 0 || roundsNum > 8) {
throw new FirebaseError(
"Must provide valid rounds(1..8) for hash algorithm " + options.hashAlgo,
{ exit: 1 }
);
}
var memCost = parseInt(options.memCost, 10);
if (isNaN(memCost) || memCost <= 0 || memCost > 14) {
throw new FirebaseError(
"Must provide valid memory cost(1..14) for hash algorithm " + options.hashAlgo,
{ exit: 1 }
);
}
var saltSeparator = "";
if (options.saltSeparator) {
saltSeparator = options.saltSeparator;
}
return {
hashAlgo: hashAlgo,
hashKey: options.hashKey,
saltSeparator: saltSeparator,
rounds: options.rounds,
memCost: options.memCost,
valid: true,
};
case "BCRYPT":
return { hashAlgo: hashAlgo, valid: true };
case "STANDARD_SCRYPT":
var cpuMemCost = parseInt(options.memCost, 10);
var parallelization = parseInt(options.parallelization, 10);
var blockSize = parseInt(options.blockSize, 10);
var dkLen = parseInt(options.dkLen, 10);
return {
hashAlgo: hashAlgo,
valid: true,
cpuMemCost: cpuMemCost,
parallelization: parallelization,
blockSize: blockSize,
dkLen: dkLen,
};
default:
throw new FirebaseError("Unsupported hash algorithm " + clc.bold(options.hashAlgo));
}
};