Skip to content

Commit 9c2e9bd

Browse files
committed
use sha256 if using a fips provider
1 parent e03355c commit 9c2e9bd

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/cam.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,23 +387,31 @@ Cam.prototype.updateNC = function() {
387387
return String(this._nc).padStart(8, '0');
388388
};
389389

390+
Cam.prototype._getHashAlgorithm = function() {
391+
if (crypto.getFips() === 1) {
392+
return 'sha256';
393+
} else {
394+
return 'md5';
395+
}
396+
}
397+
390398
Cam.prototype.digestAuth = function(wwwAuthenticate, reqOptions) {
391399
const challenge = this._parseChallenge(wwwAuthenticate);
392-
const ha1 = crypto.createHash('md5');
400+
const ha1 = crypto.createHash(this._getHashAlgorithm());
393401
ha1.update([this.username, challenge.realm, this.password].join(':'));
394-
const ha2 = crypto.createHash('md5');
402+
const ha2 = crypto.createHash(this._getHashAlgorithm());
395403
ha2.update([reqOptions.method, reqOptions.path].join(':'));
396404

397405
let cnonce = null;
398406
let nc = null;
399407
if (typeof challenge.qop === 'string') {
400-
const cnonceHash = crypto.createHash('md5');
408+
const cnonceHash = crypto.createHash(this._getHashAlgorithm());
401409
cnonceHash.update(Math.random().toString(36));
402410
cnonce = cnonceHash.digest('hex').substring(0, 8);
403411
nc = this.updateNC();
404412
}
405413

406-
const response = crypto.createHash('md5');
414+
const response = crypto.createHash(this._getHashAlgorithm());
407415
const responseParams = [
408416
ha1.digest('hex'),
409417
challenge.nonce

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "onvif",
3-
"version": "0.8.1",
3+
"version": "0.9.0",
44
"author": "Andrew D.Laptev <[email protected]>",
55
"description": "Client to ONVIF NVT devices Profile S: cameras",
66
"main": "lib/onvif.js",

0 commit comments

Comments
 (0)