forked from vrk-kpa/suomifi-passport-saml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request vrk-kpa#15 from vrk-kpa/upstream-v1.3.3_merge
Upstream v1.3.3 merge
- Loading branch information
Showing
13 changed files
with
1,653 additions
and
700 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
indent_size = 4 | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
language: node_js | ||
node_js: | ||
- "6.0" | ||
- "8.10" | ||
- "stable" | ||
|
||
script: | ||
- npm test | ||
- ./node_modules/.bin/jshint lib | ||
- ./node_modules/.bin/eslint lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var crypto = require('crypto'); | ||
|
||
exports.getSigningAlgorithm = function getSigningAlgorithm (shortName) { | ||
switch(shortName) { | ||
case 'sha256': | ||
return 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256'; | ||
case 'sha512': | ||
return 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512'; | ||
default: | ||
return 'http://www.w3.org/2000/09/xmldsig#rsa-sha1'; | ||
} | ||
}; | ||
|
||
exports.getDigestAlgorithm = function getDigestAlgorithm (shortName) { | ||
switch(shortName) { | ||
case 'sha256': | ||
return 'http://www.w3.org/2001/04/xmlenc#sha256'; | ||
case 'sha512': | ||
return 'http://www.w3.org/2001/04/xmlenc#sha512'; | ||
default: | ||
return 'http://www.w3.org/2000/09/xmldsig#sha1'; | ||
} | ||
}; | ||
|
||
exports.getSigner = function getSigner (shortName) { | ||
switch(shortName) { | ||
case 'sha256': | ||
return crypto.createSign('RSA-SHA256'); | ||
case 'sha512': | ||
return crypto.createSign('RSA-SHA512'); | ||
default: | ||
return crypto.createSign('RSA-SHA1'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var SignedXml = require('xml-crypto').SignedXml; | ||
var algorithms = require('./algorithms'); | ||
|
||
var authnRequestXPath = '/*[local-name(.)="AuthnRequest" and namespace-uri(.)="urn:oasis:names:tc:SAML:2.0:protocol"]'; | ||
var issuerXPath = '/*[local-name(.)="Issuer" and namespace-uri(.)="urn:oasis:names:tc:SAML:2.0:assertion"]'; | ||
var defaultTransforms = [ 'http://www.w3.org/2000/09/xmldsig#enveloped-signature', 'http://www.w3.org/2001/10/xml-exc-c14n#' ]; | ||
|
||
function signSamlPost(samlMessage, xpath, options) { | ||
if (!samlMessage) throw new Error('samlMessage is required'); | ||
if (!xpath) throw new Error('xpath is required'); | ||
if (!options || !options.privateCert) throw new Error('options.privateCert is required'); | ||
|
||
var transforms = options.xmlSignatureTransforms || defaultTransforms; | ||
var sig = new SignedXml(); | ||
if (options.signatureAlgorithm) { | ||
sig.signatureAlgorithm = algorithms.getSigningAlgorithm(options.signatureAlgorithm); | ||
} | ||
sig.addReference(xpath, transforms, algorithms.getDigestAlgorithm(options.digestAlgorithm)); | ||
sig.signingKey = options.privateCert; | ||
sig.computeSignature(samlMessage, { location: { reference: xpath + issuerXPath, action: 'after' }}); | ||
return sig.getSignedXml(); | ||
} | ||
|
||
function signAuthnRequestPost(authnRequest, options) { | ||
return signSamlPost(authnRequest, authnRequestXPath, options); | ||
} | ||
|
||
exports.signSamlPost = signSamlPost; | ||
exports.signAuthnRequestPost = signAuthnRequestPost; |
Oops, something went wrong.