Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: auth0/node-xml-encryption
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 887c7a3091bc926b53a90b5c57ca6f98022860e1
Choose a base ref
...
head repository: auth0/node-xml-encryption
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3571b587847fb8e0867870d2c2bfcaa0521b45dc
Choose a head ref
  • 9 commits
  • 3 files changed
  • 3 contributors

Commits on Dec 26, 2019

  1. Remove async as a dep.

    joseluisdiaz committed Dec 26, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    78a61f0 View commit details
  2. remove async 🤦

    joseluisdiaz committed Dec 26, 2019
    Copy the full SHA
    bf830bc View commit details
  3. remove node 0.10 from ci

    joseluisdiaz committed Dec 26, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ca78d6b View commit details
  4. update supported engines

    joseluisdiaz committed Dec 26, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4adc00e View commit details
  5. Update package.json

    Co-Authored-By: Leonardo Zanivan <pangalz@gmail.com>
    joseluisdiaz and panga authored Dec 26, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    afe0fd0 View commit details

Commits on Dec 27, 2019

  1. add node 10 and 12

    joseluisdiaz committed Dec 27, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    44d182d View commit details
  2. 0.12.0

    joseluisdiaz committed Dec 27, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5568139 View commit details
  3. remove package-lock

    joseluisdiaz committed Dec 27, 2019
    Copy the full SHA
    9a879ae View commit details
  4. Merge pull request #56 from joseluisdiaz/fix-async-dep

    Remove async as a dep.
    esarafianou authored Dec 27, 2019
    Copy the full SHA
    3571b58 View commit details
Showing with 77 additions and 55 deletions.
  1. +2 −1 .travis.yml
  2. +73 −51 lib/xmlenc.js
  3. +2 −3 package.json
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: node_js
node_js:
- 0.10
- 4
- 6
- 8
- 10
- 12
124 changes: 73 additions & 51 deletions lib/xmlenc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var crypto = require('crypto');
var async = require('async');
var xmldom = require('xmldom');
var xpath = require('xpath');
var utils = require('./utils');
@@ -59,60 +58,83 @@ function encrypt(content, options, callback) {

options.input_encoding = options.input_encoding || 'utf8';

async.waterfall([
function generate_symmetric_key(cb) {
switch (options.encryptionAlgorithm) {
case 'http://www.w3.org/2001/04/xmlenc#aes128-cbc':
crypto.randomBytes(16, cb); // generate a symmetric random key 16 bytes length
break;
case 'http://www.w3.org/2001/04/xmlenc#aes256-cbc':
crypto.randomBytes(32, cb); // generate a symmetric random key 32 bytes length
break;
case 'http://www.w3.org/2001/04/xmlenc#tripledes-cbc':
crypto.randomBytes(24, cb); // generate a symmetric random key 24 bytes (192 bits) length
break;
default:
crypto.randomBytes(32, cb); // generate a symmetric random key 32 bytes length
}
},
function encrypt_content(symmetricKey, cb) {
switch (options.encryptionAlgorithm) {
case 'http://www.w3.org/2001/04/xmlenc#aes128-cbc':
encryptWithAlgorithm('aes-128-cbc', symmetricKey, 16, content, options.input_encoding, function (err, encryptedContent) {
if (err) return cb(err);
cb(null, symmetricKey, encryptedContent);
});
break;
case 'http://www.w3.org/2001/04/xmlenc#aes256-cbc':
encryptWithAlgorithm('aes-256-cbc', symmetricKey, 16, content, options.input_encoding, function (err, encryptedContent) {
if (err) return cb(err);
cb(null, symmetricKey, encryptedContent);
});
break;
case 'http://www.w3.org/2001/04/xmlenc#tripledes-cbc':
encryptWithAlgorithm('des-ede3-cbc', symmetricKey, 8, content, options.input_encoding, function (err, encryptedContent) {
if (err) return cb(err);
cb(null, symmetricKey, encryptedContent);
});
break;
default:
cb(new Error('encryption algorithm not supported'));
}
},
function encrypt_key(symmetricKey, encryptedContent, cb) {
encryptKeyInfo(symmetricKey, options, function(err, keyInfo) {
if (err) return cb(err);

var result = utils.renderTemplate('encrypted-key', {
encryptedContent: encryptedContent.toString('base64'),
keyInfo: keyInfo,
contentEncryptionMethod: options.encryptionAlgorithm
function generate_symmetric_key(cb) {
switch (options.encryptionAlgorithm) {
case 'http://www.w3.org/2001/04/xmlenc#aes128-cbc':
crypto.randomBytes(16, cb); // generate a symmetric random key 16 bytes length
break;
case 'http://www.w3.org/2001/04/xmlenc#aes256-cbc':
crypto.randomBytes(32, cb); // generate a symmetric random key 32 bytes length
break;
case 'http://www.w3.org/2001/04/xmlenc#tripledes-cbc':
crypto.randomBytes(24, cb); // generate a symmetric random key 24 bytes (192 bits) length
break;
default:
crypto.randomBytes(32, cb); // generate a symmetric random key 32 bytes length
}
}

function encrypt_content(symmetricKey, cb) {
switch (options.encryptionAlgorithm) {
case 'http://www.w3.org/2001/04/xmlenc#aes128-cbc':
encryptWithAlgorithm('aes-128-cbc', symmetricKey, 16, content, options.input_encoding, function (err, encryptedContent) {
if (err) return cb(err);
cb(null, encryptedContent);
});
break;
case 'http://www.w3.org/2001/04/xmlenc#aes256-cbc':
encryptWithAlgorithm('aes-256-cbc', symmetricKey, 16, content, options.input_encoding, function (err, encryptedContent) {
if (err) return cb(err);
cb(null, encryptedContent);
});
break;
case 'http://www.w3.org/2001/04/xmlenc#tripledes-cbc':
encryptWithAlgorithm('des-ede3-cbc', symmetricKey, 8, content, options.input_encoding, function (err, encryptedContent) {
if (err) return cb(err);
cb(null, encryptedContent);
});
break;
default:
cb(new Error('encryption algorithm not supported'));
}
}

cb(null, result);
function encrypt_key(symmetricKey, encryptedContent, cb) {
encryptKeyInfo(symmetricKey, options, function(err, keyInfo) {
if (err) return cb(err);

var result = utils.renderTemplate('encrypted-key', {
encryptedContent: encryptedContent.toString('base64'),
keyInfo: keyInfo,
contentEncryptionMethod: options.encryptionAlgorithm
});

cb(null, result);
});
}


generate_symmetric_key(function (genKeyError, symmetricKey) {
if (genKeyError) {
return callback(genKeyError);
}
], callback);

encrypt_content(symmetricKey, function(encryptContentError, encryptedContent) {
if (encryptContentError) {
return callback(encryptContentError);
}

encrypt_key(symmetricKey, encryptedContent, function (encryptKeyError, result) {
if (encryptKeyError) {
return callback(encryptKeyError);
}

callback(null, result);
});

});

});
}

function decrypt(xml, options, callback) {
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xml-encryption",
"version": "0.11.2",
"version": "0.12.0",
"devDependencies": {
"mocha": "3.3.0",
"should": "^11.2.1"
@@ -19,7 +19,6 @@
],
"license": "MIT",
"dependencies": {
"async": "^2.1.5",
"ejs": "^2.5.6",
"node-forge": "^0.7.0",
"xmldom": "~0.1.15",
@@ -29,6 +28,6 @@
"test": "mocha"
},
"engines": {
"node": ">=0.10"
"node": ">=4"
}
}