scimgateway 6.2.6 → 6.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,104 @@
1
+ const utils = require('../utils');
2
+ const SignedXml = require('xml-crypto').SignedXml;
3
+
4
+ const algorithms = {
5
+ signature: {
6
+ 'rsa-sha256': 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256',
7
+ 'rsa-sha1': 'http://www.w3.org/2000/09/xmldsig#rsa-sha1'
8
+ },
9
+ digest: {
10
+ 'sha256': 'http://www.w3.org/2001/04/xmlenc#sha256',
11
+ 'sha1': 'http://www.w3.org/2000/09/xmldsig#sha1'
12
+ }
13
+ };
14
+
15
+ exports.fromSignXmlOptions = function (options) {
16
+ if (!options.key)
17
+ throw new Error('Expect a private key in pem format');
18
+
19
+ if (!options.cert)
20
+ throw new Error('Expect a public key cert in pem format');
21
+
22
+ if (!options.xpathToNodeBeforeSignature)
23
+ throw new Error('xpathToNodeBeforeSignature is required')
24
+
25
+ const key = options.key;
26
+ const pem = options.cert;
27
+ const signatureAlgorithm = options.signatureAlgorithm || 'rsa-sha256';
28
+ const digestAlgorithm = options.digestAlgorithm || 'sha256';
29
+ const signatureNamespacePrefix = (function (prefix) {
30
+ // 0.10.1 added prefix, but we want to name it signatureNamespacePrefix - This is just to keep supporting prefix
31
+ return typeof prefix === 'string' ? prefix : '';
32
+ })(options.signatureNamespacePrefix || options.prefix);
33
+ const xpathToNodeBeforeSignature = options.xpathToNodeBeforeSignature;
34
+ const idAttribute = options.signatureIdAttribute;
35
+
36
+ /**
37
+ * @param {Document} doc
38
+ * @param {Function} [callback]
39
+ * @return {string}
40
+ */
41
+ return function signXmlDocument(doc, callback) {
42
+ function sign(key) {
43
+ const unsigned = exports.unsigned(doc);
44
+ const cert = utils.pemToCert(pem);
45
+
46
+ const sig = new SignedXml(null, {
47
+ signatureAlgorithm: algorithms.signature[signatureAlgorithm],
48
+ idAttribute: idAttribute
49
+ });
50
+ sig.addReference("//*[local-name(.)='Assertion']",
51
+ ["http://www.w3.org/2000/09/xmldsig#enveloped-signature", "http://www.w3.org/2001/10/xml-exc-c14n#"],
52
+ algorithms.digest[digestAlgorithm]);
53
+
54
+ sig.signingKey = key;
55
+
56
+ sig.keyInfoProvider = {
57
+ getKeyInfo: function (key, prefix) {
58
+ prefix = prefix ? prefix + ':' : prefix;
59
+ return "<" + prefix + "X509Data><" + prefix + "X509Certificate>" + cert + "</" + prefix + "X509Certificate></" + prefix + "X509Data>";
60
+ }
61
+ };
62
+
63
+ sig.computeSignature(unsigned, {
64
+ location: {reference: xpathToNodeBeforeSignature, action: 'after'},
65
+ prefix: signatureNamespacePrefix
66
+ });
67
+
68
+ return sig.getSignedXml();
69
+ }
70
+
71
+ let signed
72
+ try {
73
+ try {
74
+ signed = sign(key)
75
+ } catch (err) {
76
+ signed = sign(utils.fixPemFormatting(key))
77
+ }
78
+
79
+ if (callback) {
80
+ setImmediate(callback, null, signed);
81
+ } else {
82
+ return signed;
83
+ }
84
+ } catch (e) {
85
+ if (callback) {
86
+ setImmediate(callback, e)
87
+ }
88
+ throw e
89
+ }
90
+ };
91
+ };
92
+ /**
93
+ * @param {Document} doc
94
+ * @param {Function} [callback]
95
+ * @return {string}
96
+ */
97
+ exports.unsigned = function (doc, callback) {
98
+ const xml = utils.removeWhitespace(doc.toString());
99
+ if (callback) {
100
+ setImmediate(callback, null, xml)
101
+ } else {
102
+ return xml;
103
+ }
104
+ }
@@ -26,8 +26,7 @@
26
26
  // SOFTWARE.
27
27
  //
28
28
 
29
- // @ts-expect-error type declaration file not found
30
- import { Saml20 as saml } from 'saml'
29
+ import { Saml20 as saml } from './saml/index.js' // The `saml` entry in `package.json` must be kept — it provides the sub-dependencies (@xmldom/xmldom, moment, xml-crypto, etc.) that this local copy requires.
31
30
  import crypto from 'node:crypto'
32
31
 
33
32
  export const samlAssertionUtils = {
@@ -25,6 +25,8 @@ import * as utils from './utils.ts'
25
25
  import * as utilsScim from './utils-scim.ts'
26
26
  import * as stream from './scim-stream.js'
27
27
  export * from './helper-rest.ts'
28
+ import LicenseData from './azure-license-mapping.json'
29
+ export { LicenseData }
28
30
  // @ts-expect-error: cannot find declaration
29
31
  import hycoPkg from 'hyco-https'
30
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scimgateway",
3
- "version": "6.2.6",
3
+ "version": "6.2.7",
4
4
  "type": "module",
5
5
  "description": "Using SCIM protocol as a gateway for user provisioning to other endpoints",
6
6
  "author": "Jarle Elshaug <jarle.elshaug@gmail.com> (https://elshaug.xyz)",