Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions lib/cam.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,23 +387,37 @@ Cam.prototype.updateNC = function() {
return String(this._nc).padStart(8, '0');
};

/**
* Get the hash algorithm to use for digest authentication.
* If Node.js is running in FIPS mode, returns sha256, otherwise returns md5.
* @returns {md5 | sha256} hash algorithm
* @private
*/
Cam.prototype._getHashAlgorithm = function() {
if (crypto.getFips() === 1) {
return 'sha256';
} else {
return 'md5';
}
};

Cam.prototype.digestAuth = function(wwwAuthenticate, reqOptions) {
const challenge = this._parseChallenge(wwwAuthenticate);
const ha1 = crypto.createHash('md5');
const ha1 = crypto.createHash(this._getHashAlgorithm());
ha1.update([this.username, challenge.realm, this.password].join(':'));
const ha2 = crypto.createHash('md5');
const ha2 = crypto.createHash(this._getHashAlgorithm());
ha2.update([reqOptions.method, reqOptions.path].join(':'));

let cnonce = null;
let nc = null;
if (typeof challenge.qop === 'string') {
const cnonceHash = crypto.createHash('md5');
const cnonceHash = crypto.createHash(this._getHashAlgorithm());
cnonceHash.update(Math.random().toString(36));
cnonce = cnonceHash.digest('hex').substring(0, 8);
nc = this.updateNC();
}

const response = crypto.createHash('md5');
const response = crypto.createHash(this._getHashAlgorithm());
const responseParams = [
ha1.digest('hex'),
challenge.nonce
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "onvif",
"version": "0.8.1",
"version": "0.9.0",
"author": "Andrew D.Laptev <[email protected]>",
"description": "Client to ONVIF NVT devices Profile S: cameras",
"main": "lib/onvif.js",
"scripts": {
"jsdoc": "jsdoc ./lib/*.js --readme ./README.md --destination ./docs",
"gh-pages": "jsdoc ./lib/*.js --readme ./README.md --destination ./",
"lint": "eslint lib/*.js",
"lint:fix": "eslint --fix lib/*.js",
"pretest": "npm run lint",
"test": "nyc mocha",
"mockserver": "node startServerMockup.js"
Expand Down