joyent/node — pull request #6380 by arthurtsang (2013-10-20 06:06:22+00:00)
Title: enable fips support

FIPS 140-2 support for enterprise, especially government is very important. OpenSSL supported FIPS with OpenSSL FIPS Object Module. To enable NodeJS to support FIPS, all we need to do is to compile with OpenSSL shared library which built with OpenSSL FIPS Object Module and call FIPS_mode_set() to enable FIPS mode.

to test if NodeJS has turned on FIPS mode, we can use the script below. since bf is an unsupported algorithm, node will core dumped.

#!/usr/bin/env node

'use strict';

var crypto = require('crypto');

var cipher = crypto.createCipher('bf','12345');
var encrypted = cipher.update('encrypt this very long string' , 'utf8', 'base64');
encrypted = encrypted + cipher.final('base64');

var decipher = crypto.createDecipher('bf','12345');
var decrypted = decipher.update(encrypted, 'base64', 'utf8');
decrypted = decrypted + decipher.final('utf8');

console.log( 'encrypted: ' + encrypted );
console.log( 'decrypted: ' + decrypted );

configure is modified to add --shared-openssl-fips to turn on FIPS mode.