file-stream-rotator icon indicating copy to clipboard operation
file-stream-rotator copied to clipboard

Error : Digest method not supported while using winston.transports.DailyRotate

Open patilms16 opened this issue 2 years ago • 3 comments

Environment :

OS : SUSE Linux Enterprise Server 15 SP2 Node: 14.16.0 Express: 4.17.1, winston: 3.2.1, winston-daily-rotate-file: 4.4.2

I am using following code :

 var transport = new (winston.transports.DailyRotateFile)({
        filename: 'log/server-%DATE%.log',
        datePattern: 'YYYY-MM-DD-HH',
        maxSize: '100m', //100MB
        zippedArchive: true,
        maxFiles: '10',
        frequency: '24h'
    });

and getting error as "Digest method not supported" from FileStreamRotator ( which usage crypto submodule of nodejs)

Below is actual line which was throwing error from File "FileStreamRotator.js" under node_modules : crypto.createHash('md5').update(logfile + "LOG_FILE" + time).digest("hex")

I posted similar question on winston-daily-rotate-file repo (https://github.com/winstonjs/winston-daily-rotate-file/issues/340) , but as this issue seems related to FileStreamRotator and dependent crypto submodule of node, posting the question here.

Also raised same question on stack-overflow : https://stackoverflow.com/questions/71552510/error-digest-method-not-supported-while-using-winston-transports-dailyrotate

Please check below screenshot for openssl version and algorithm list for the platforms where I am using the function ( Please note : for Helios platform function is working fine without any error but for SLES platform it does throw error )

159362257-eb9ee77b-4b12-4882-b975-edaeb66bfd87

Can someone please help to identify the issue here and probable solution?

patilms16 avatar Mar 22 '22 22:03 patilms16

@patilms16 try modifying the Winston module to include the option audit_hash_type when getting the stream https://github.com/winstonjs/winston-daily-rotate-file/blob/a4401b7277353e3375669dae35c0da866cb34e4a/daily-rotate-file.js#L94

If that works, please update the Winston issue you've raised to ask to include that as an option. The line below is from the README

audit_hash_type Use specified hashing algorithm for audit. Defaults to 'md5'. Use 'sha256' for FIPS compliance.

rogerc avatar Mar 24 '22 19:03 rogerc

@rogerc Thanks for the Suggestion. First of all, I could determine the root cause of my problem being openssl version used on my platform ( 1.1.1d 10 Sep 2019 ) doesn't support md5. when I try this command "openssl md5 'fileName'" , It throws error : md5 is not a known digest I verified openssl version changelog : Default digest algorithm is changed from md5 to Sha256 Ref: https://www.openssl.org/docs/man1.1.1/man1/dgst.html https://www.openssl.org/news/changelog.html#openssl-111 ( Section : Changes between 1.0.2h and 1.1.0 )

Next, I verified that version of file-stream-rotator being used in my node_modules is 0.5.7. In this version we don't have audit_hash_type, instead it directly uses 'md5'. However If I change it use different hash type say 'sha256' , I don't get error and it works fine.

Hence Winston module needs to be updated to include audit_hash_type as an option. Then I can use the latest versions.

patilms16 avatar Apr 07 '22 21:04 patilms16

Created a PR in winston-daily-rotate-file to pass audit_hash_type Created pull request : https://github.com/winstonjs/winston-daily-rotate-file/pull/344

patilms16 avatar Apr 08 '22 15:04 patilms16