samlesa 2.12.3 → 2.12.6
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.
Potentially problematic release.
This version of samlesa might be problematic. Click here for more details.
- package/build/index.js +54 -64
- package/build/index.js.map +1 -1
- package/build/src/api.js +24 -23
- package/build/src/api.js.map +1 -1
- package/build/src/binding-post.js +358 -368
- package/build/src/binding-post.js.map +1 -1
- package/build/src/binding-redirect.js +333 -332
- package/build/src/binding-redirect.js.map +1 -1
- package/build/src/binding-simplesign.js +222 -232
- package/build/src/binding-simplesign.js.map +1 -1
- package/build/src/entity-idp.js +132 -130
- package/build/src/entity-idp.js.map +1 -1
- package/build/src/entity-sp.js +96 -96
- package/build/src/entity-sp.js.map +1 -1
- package/build/src/entity.js +225 -235
- package/build/src/entity.js.map +1 -1
- package/build/src/extractor.js +369 -369
- package/build/src/extractor.js.map +1 -1
- package/build/src/flow.js +320 -319
- package/build/src/flow.js.map +1 -1
- package/build/src/libsaml.js +660 -641
- package/build/src/libsaml.js.map +1 -1
- package/build/src/metadata-idp.js +127 -127
- package/build/src/metadata-idp.js.map +1 -1
- package/build/src/metadata-sp.js +231 -231
- package/build/src/metadata-sp.js.map +1 -1
- package/build/src/metadata.js +166 -176
- package/build/src/metadata.js.map +1 -1
- package/build/src/types.js +11 -11
- package/build/src/urn.js +212 -212
- package/build/src/urn.js.map +1 -1
- package/build/src/utility.js +292 -248
- package/build/src/utility.js.map +1 -1
- package/build/src/validator.js +27 -26
- package/build/src/validator.js.map +1 -1
- package/index.d.ts +10 -10
- package/index.js +18 -18
- package/package.json +1 -5
- package/qodana.yaml +29 -29
- package/src/binding-post.ts +1 -1
- package/src/binding-redirect.ts +83 -64
- package/src/entity-idp.ts +26 -20
- package/src/libsaml.ts +79 -48
- package/src/utility.ts +147 -76
- package/types/index.d.ts +10 -10
- package/types/src/api.d.ts +13 -13
- package/types/src/binding-post.d.ts +46 -46
- package/types/src/binding-redirect.d.ts +52 -52
- package/types/src/binding-simplesign.d.ts +39 -39
- package/types/src/entity-idp.d.ts +35 -42
- package/types/src/entity-sp.d.ts +36 -36
- package/types/src/entity.d.ts +101 -99
- package/types/src/extractor.d.ts +25 -25
- package/types/src/flow.d.ts +6 -6
- package/types/src/libsaml.d.ts +200 -210
- package/types/src/metadata-idp.d.ts +24 -24
- package/types/src/metadata-sp.d.ts +36 -36
- package/types/src/metadata.d.ts +59 -57
- package/types/src/types.d.ts +129 -127
- package/types/src/urn.d.ts +194 -194
- package/types/src/utility.d.ts +134 -134
- package/types/src/validator.d.ts +3 -3
- package/.idea/compiler.xml +0 -6
- package/.idea/deployment.xml +0 -14
- package/.idea/jsLibraryMappings.xml +0 -6
- package/build/.idea/workspace.xml +0 -58
|
@@ -1,369 +1,359 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @file binding-post.ts
|
|
4
|
-
* @author tngan
|
|
5
|
-
* @desc Binding-level API, declare the functions using POST binding
|
|
6
|
-
*/
|
|
7
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
-
if (k2 === undefined) k2 = k;
|
|
9
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
-
}
|
|
13
|
-
Object.defineProperty(o, k2, desc);
|
|
14
|
-
}) : (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
o[k2] = m[k];
|
|
17
|
-
}));
|
|
18
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
-
}) : function(o, v) {
|
|
21
|
-
o["default"] = v;
|
|
22
|
-
});
|
|
23
|
-
var __importStar = (this && this.__importStar) ||
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
rawSamlResponse
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
throw new Error('ERR_GENERATE_POST_LOGOUT_RESPONSE_MISSING_METADATA');
|
|
361
|
-
}
|
|
362
|
-
const postBinding = {
|
|
363
|
-
base64LoginRequest,
|
|
364
|
-
base64LoginResponse,
|
|
365
|
-
base64LogoutRequest,
|
|
366
|
-
base64LogoutResponse,
|
|
367
|
-
};
|
|
368
|
-
exports.default = postBinding;
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file binding-post.ts
|
|
4
|
+
* @author tngan
|
|
5
|
+
* @desc Binding-level API, declare the functions using POST binding
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
24
|
+
if (mod && mod.__esModule) return mod;
|
|
25
|
+
var result = {};
|
|
26
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
27
|
+
__setModuleDefault(result, mod);
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
30
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
const urn_js_1 = require("./urn.js");
|
|
35
|
+
const libsaml_js_1 = __importDefault(require("./libsaml.js"));
|
|
36
|
+
const utility_js_1 = __importStar(require("./utility.js"));
|
|
37
|
+
const binding = urn_js_1.wording.binding;
|
|
38
|
+
/**
|
|
39
|
+
* @desc Generate a base64 encoded login request
|
|
40
|
+
* @param {string} referenceTagXPath reference uri
|
|
41
|
+
* @param {object} entity object includes both idp and sp
|
|
42
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
43
|
+
*/
|
|
44
|
+
function base64LoginRequest(referenceTagXPath, entity, customTagReplacement) {
|
|
45
|
+
const metadata = { idp: entity.idp.entityMeta, sp: entity.sp.entityMeta };
|
|
46
|
+
const spSetting = entity.sp.entitySetting;
|
|
47
|
+
let id = '';
|
|
48
|
+
if (metadata && metadata.idp && metadata.sp) {
|
|
49
|
+
const base = metadata.idp.getSingleSignOnService(binding.post);
|
|
50
|
+
let rawSamlRequest;
|
|
51
|
+
if (spSetting.loginRequestTemplate && customTagReplacement) {
|
|
52
|
+
const info = customTagReplacement(spSetting.loginRequestTemplate.context);
|
|
53
|
+
id = (0, utility_js_1.get)(info, 'id', null);
|
|
54
|
+
rawSamlRequest = (0, utility_js_1.get)(info, 'context', null);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const nameIDFormat = spSetting.nameIDFormat;
|
|
58
|
+
const selectedNameIDFormat = Array.isArray(nameIDFormat) ? nameIDFormat[0] : nameIDFormat;
|
|
59
|
+
id = spSetting.generateID();
|
|
60
|
+
rawSamlRequest = libsaml_js_1.default.replaceTagsByValue(libsaml_js_1.default.defaultLoginRequestTemplate.context, {
|
|
61
|
+
ID: id,
|
|
62
|
+
Destination: base,
|
|
63
|
+
Issuer: metadata.sp.getEntityID(),
|
|
64
|
+
IssueInstant: new Date().toISOString(),
|
|
65
|
+
AssertionConsumerServiceURL: metadata.sp.getAssertionConsumerService(binding.post),
|
|
66
|
+
EntityID: metadata.sp.getEntityID(),
|
|
67
|
+
AllowCreate: spSetting.allowCreate,
|
|
68
|
+
NameIDFormat: selectedNameIDFormat
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (metadata.idp.isWantAuthnRequestsSigned()) {
|
|
72
|
+
const { privateKey, privateKeyPass, requestSignatureAlgorithm: signatureAlgorithm, transformationAlgorithms } = spSetting;
|
|
73
|
+
return {
|
|
74
|
+
id,
|
|
75
|
+
context: libsaml_js_1.default.constructSAMLSignature({
|
|
76
|
+
referenceTagXPath,
|
|
77
|
+
privateKey,
|
|
78
|
+
privateKeyPass,
|
|
79
|
+
signatureAlgorithm,
|
|
80
|
+
transformationAlgorithms,
|
|
81
|
+
rawSamlMessage: rawSamlRequest,
|
|
82
|
+
signingCert: metadata.sp.getX509Certificate('signing'),
|
|
83
|
+
signatureConfig: spSetting.signatureConfig || {
|
|
84
|
+
prefix: 'ds',
|
|
85
|
+
location: { reference: "/*[local-name(.)='AuthnRequest']/*[local-name(.)='Issuer']", action: 'after' },
|
|
86
|
+
}
|
|
87
|
+
}),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// No need to embeded XML signature
|
|
91
|
+
return {
|
|
92
|
+
id,
|
|
93
|
+
context: utility_js_1.default.base64Encode(rawSamlRequest),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
throw new Error('ERR_GENERATE_POST_LOGIN_REQUEST_MISSING_METADATA');
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* @desc Generate a base64 encoded login response
|
|
100
|
+
* @param {object} requestInfo corresponding request, used to obtain the id
|
|
101
|
+
* @param {object} entity object includes both idp and sp
|
|
102
|
+
* @param {object} user current logged user (e.g. req.user)
|
|
103
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
104
|
+
* @param {boolean} encryptThenSign whether or not to encrypt then sign first (if signing). Defaults to sign-then-encrypt
|
|
105
|
+
*/
|
|
106
|
+
async function base64LoginResponse(requestInfo = {}, entity, user = {}, customTagReplacement, encryptThenSign = false) {
|
|
107
|
+
const idpSetting = entity.idp.entitySetting;
|
|
108
|
+
const spSetting = entity.sp.entitySetting;
|
|
109
|
+
const id = idpSetting.generateID();
|
|
110
|
+
const metadata = {
|
|
111
|
+
idp: entity.idp.entityMeta,
|
|
112
|
+
sp: entity.sp.entityMeta,
|
|
113
|
+
};
|
|
114
|
+
const nameIDFormat = idpSetting.nameIDFormat;
|
|
115
|
+
const selectedNameIDFormat = Array.isArray(nameIDFormat) ? nameIDFormat[0] : nameIDFormat;
|
|
116
|
+
if (metadata && metadata.idp && metadata.sp) {
|
|
117
|
+
const base = metadata.sp.getAssertionConsumerService(binding.post);
|
|
118
|
+
let rawSamlResponse;
|
|
119
|
+
const nowTime = new Date();
|
|
120
|
+
const spEntityID = metadata.sp.getEntityID();
|
|
121
|
+
const fiveMinutesLaterTime = new Date(nowTime.getTime());
|
|
122
|
+
fiveMinutesLaterTime.setMinutes(fiveMinutesLaterTime.getMinutes() + 5);
|
|
123
|
+
const fiveMinutesLater = fiveMinutesLaterTime.toISOString();
|
|
124
|
+
const now = nowTime.toISOString();
|
|
125
|
+
const acl = metadata.sp.getAssertionConsumerService(binding.post);
|
|
126
|
+
const tvalue = {
|
|
127
|
+
ID: id,
|
|
128
|
+
AssertionID: idpSetting.generateID(),
|
|
129
|
+
Destination: base,
|
|
130
|
+
Audience: spEntityID,
|
|
131
|
+
EntityID: spEntityID,
|
|
132
|
+
SubjectRecipient: acl,
|
|
133
|
+
Issuer: metadata.idp.getEntityID(),
|
|
134
|
+
IssueInstant: now,
|
|
135
|
+
AssertionConsumerServiceURL: acl,
|
|
136
|
+
StatusCode: urn_js_1.StatusCode.Success,
|
|
137
|
+
// can be customized
|
|
138
|
+
ConditionsNotBefore: now,
|
|
139
|
+
ConditionsNotOnOrAfter: fiveMinutesLater,
|
|
140
|
+
SubjectConfirmationDataNotOnOrAfter: fiveMinutesLater,
|
|
141
|
+
NameIDFormat: selectedNameIDFormat,
|
|
142
|
+
NameID: user.email || '',
|
|
143
|
+
InResponseTo: (0, utility_js_1.get)(requestInfo, 'extract.request.id', ''),
|
|
144
|
+
AuthnStatement: '',
|
|
145
|
+
AttributeStatement: '',
|
|
146
|
+
};
|
|
147
|
+
if (idpSetting.loginResponseTemplate && customTagReplacement) {
|
|
148
|
+
const template = customTagReplacement(idpSetting.loginResponseTemplate.context);
|
|
149
|
+
rawSamlResponse = (0, utility_js_1.get)(template, 'context', null);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
if (requestInfo !== null) {
|
|
153
|
+
tvalue.InResponseTo = requestInfo.extract.request.id;
|
|
154
|
+
}
|
|
155
|
+
rawSamlResponse = libsaml_js_1.default.replaceTagsByValue(libsaml_js_1.default.defaultLoginResponseTemplate.context, tvalue);
|
|
156
|
+
}
|
|
157
|
+
const { privateKey, privateKeyPass, requestSignatureAlgorithm: signatureAlgorithm } = idpSetting;
|
|
158
|
+
const config = {
|
|
159
|
+
privateKey,
|
|
160
|
+
privateKeyPass,
|
|
161
|
+
signatureAlgorithm,
|
|
162
|
+
signingCert: metadata.idp.getX509Certificate('signing'),
|
|
163
|
+
isBase64Output: false,
|
|
164
|
+
};
|
|
165
|
+
// step: sign assertion ? -> encrypted ? -> sign message ?
|
|
166
|
+
if (metadata.sp.isWantAssertionsSigned()) {
|
|
167
|
+
// console.debug('sp wants assertion signed');
|
|
168
|
+
rawSamlResponse = libsaml_js_1.default.constructSAMLSignature({
|
|
169
|
+
...config,
|
|
170
|
+
rawSamlMessage: rawSamlResponse,
|
|
171
|
+
transformationAlgorithms: spSetting.transformationAlgorithms,
|
|
172
|
+
referenceTagXPath: "/*[local-name(.)='Response']/*[local-name(.)='Assertion']",
|
|
173
|
+
signatureConfig: {
|
|
174
|
+
prefix: 'ds',
|
|
175
|
+
location: { reference: "/*[local-name(.)='Response']/*[local-name(.)='Assertion']/*[local-name(.)='Issuer']", action: 'after' },
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
// console.debug('after assertion signed', rawSamlResponse);
|
|
180
|
+
// SAML response must be signed sign message first, then encrypt
|
|
181
|
+
if (!encryptThenSign && (spSetting.wantMessageSigned || !metadata.sp.isWantAssertionsSigned())) {
|
|
182
|
+
// console.debug('sign then encrypt and sign entire message');
|
|
183
|
+
rawSamlResponse = libsaml_js_1.default.constructSAMLSignature({
|
|
184
|
+
...config,
|
|
185
|
+
rawSamlMessage: rawSamlResponse,
|
|
186
|
+
isMessageSigned: true,
|
|
187
|
+
transformationAlgorithms: spSetting.transformationAlgorithms,
|
|
188
|
+
signatureConfig: spSetting.signatureConfig || {
|
|
189
|
+
prefix: 'ds',
|
|
190
|
+
location: { reference: "/*[local-name(.)='Response']/*[local-name(.)='Issuer']", action: 'after' },
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
console.log(rawSamlResponse);
|
|
194
|
+
console.log('这他妈是什么------------------');
|
|
195
|
+
}
|
|
196
|
+
// console.debug('after message signed', rawSamlResponse);
|
|
197
|
+
if (idpSetting.isAssertionEncrypted) {
|
|
198
|
+
// console.debug('idp is configured to do encryption');
|
|
199
|
+
const context = await libsaml_js_1.default.encryptAssertion(entity.idp, entity.sp, rawSamlResponse);
|
|
200
|
+
if (encryptThenSign) {
|
|
201
|
+
//need to decode it
|
|
202
|
+
rawSamlResponse = utility_js_1.default.base64Decode(context);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
return Promise.resolve({ id, context });
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
//sign after encrypting
|
|
209
|
+
if (encryptThenSign && (spSetting.wantMessageSigned || !metadata.sp.isWantAssertionsSigned())) {
|
|
210
|
+
rawSamlResponse = libsaml_js_1.default.constructSAMLSignature({
|
|
211
|
+
...config,
|
|
212
|
+
rawSamlMessage: rawSamlResponse,
|
|
213
|
+
isMessageSigned: true,
|
|
214
|
+
transformationAlgorithms: spSetting.transformationAlgorithms,
|
|
215
|
+
signatureConfig: spSetting.signatureConfig || {
|
|
216
|
+
prefix: 'ds',
|
|
217
|
+
location: { reference: "/*[local-name(.)='Response']/*[local-name(.)='Issuer']", action: 'after' },
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return Promise.resolve({
|
|
222
|
+
id,
|
|
223
|
+
context: utility_js_1.default.base64Encode(rawSamlResponse),
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
throw new Error('ERR_GENERATE_POST_LOGIN_RESPONSE_MISSING_METADATA');
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* @desc Generate a base64 encoded logout request
|
|
230
|
+
* @param {object} user current logged user (e.g. req.user)
|
|
231
|
+
* @param {string} referenceTagXPath reference uri
|
|
232
|
+
* @param {object} entity object includes both idp and sp
|
|
233
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
234
|
+
* @return {string} base64 encoded request
|
|
235
|
+
*/
|
|
236
|
+
function base64LogoutRequest(user, referenceTagXPath, entity, customTagReplacement) {
|
|
237
|
+
const metadata = { init: entity.init.entityMeta, target: entity.target.entityMeta };
|
|
238
|
+
const initSetting = entity.init.entitySetting;
|
|
239
|
+
const nameIDFormat = initSetting.nameIDFormat;
|
|
240
|
+
const selectedNameIDFormat = Array.isArray(nameIDFormat) ? nameIDFormat[0] : nameIDFormat;
|
|
241
|
+
let id = '';
|
|
242
|
+
if (metadata && metadata.init && metadata.target) {
|
|
243
|
+
let rawSamlRequest;
|
|
244
|
+
if (initSetting.logoutRequestTemplate && customTagReplacement) {
|
|
245
|
+
const template = customTagReplacement(initSetting.logoutRequestTemplate.context);
|
|
246
|
+
id = (0, utility_js_1.get)(template, 'id', null);
|
|
247
|
+
rawSamlRequest = (0, utility_js_1.get)(template, 'context', null);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
id = initSetting.generateID();
|
|
251
|
+
const tvalue = {
|
|
252
|
+
ID: id,
|
|
253
|
+
Destination: metadata.target.getSingleLogoutService(binding.post),
|
|
254
|
+
Issuer: metadata.init.getEntityID(),
|
|
255
|
+
IssueInstant: new Date().toISOString(),
|
|
256
|
+
EntityID: metadata.init.getEntityID(),
|
|
257
|
+
NameIDFormat: selectedNameIDFormat,
|
|
258
|
+
NameID: user.logoutNameID,
|
|
259
|
+
};
|
|
260
|
+
rawSamlRequest = libsaml_js_1.default.replaceTagsByValue(libsaml_js_1.default.defaultLogoutRequestTemplate.context, tvalue);
|
|
261
|
+
}
|
|
262
|
+
if (entity.target.entitySetting.wantLogoutRequestSigned) {
|
|
263
|
+
// Need to embeded XML signature
|
|
264
|
+
const { privateKey, privateKeyPass, requestSignatureAlgorithm: signatureAlgorithm, transformationAlgorithms } = initSetting;
|
|
265
|
+
return {
|
|
266
|
+
id,
|
|
267
|
+
context: libsaml_js_1.default.constructSAMLSignature({
|
|
268
|
+
referenceTagXPath,
|
|
269
|
+
privateKey,
|
|
270
|
+
privateKeyPass,
|
|
271
|
+
signatureAlgorithm,
|
|
272
|
+
transformationAlgorithms,
|
|
273
|
+
rawSamlMessage: rawSamlRequest,
|
|
274
|
+
signingCert: metadata.init.getX509Certificate('signing'),
|
|
275
|
+
signatureConfig: initSetting.signatureConfig || {
|
|
276
|
+
prefix: 'ds',
|
|
277
|
+
location: { reference: "/*[local-name(.)='LogoutRequest']/*[local-name(.)='Issuer']", action: 'after' },
|
|
278
|
+
}
|
|
279
|
+
}),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
id,
|
|
284
|
+
context: utility_js_1.default.base64Encode(rawSamlRequest),
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
throw new Error('ERR_GENERATE_POST_LOGOUT_REQUEST_MISSING_METADATA');
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* @desc Generate a base64 encoded logout response
|
|
291
|
+
* @param {object} requestInfo corresponding request, used to obtain the id
|
|
292
|
+
* @param {string} referenceTagXPath reference uri
|
|
293
|
+
* @param {object} entity object includes both idp and sp
|
|
294
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
295
|
+
*/
|
|
296
|
+
function base64LogoutResponse(requestInfo, entity, customTagReplacement) {
|
|
297
|
+
const metadata = {
|
|
298
|
+
init: entity.init.entityMeta,
|
|
299
|
+
target: entity.target.entityMeta,
|
|
300
|
+
};
|
|
301
|
+
let id = '';
|
|
302
|
+
const initSetting = entity.init.entitySetting;
|
|
303
|
+
if (metadata && metadata.init && metadata.target) {
|
|
304
|
+
let rawSamlResponse;
|
|
305
|
+
if (initSetting.logoutResponseTemplate) {
|
|
306
|
+
const template = customTagReplacement(initSetting.logoutResponseTemplate.context);
|
|
307
|
+
id = template.id;
|
|
308
|
+
rawSamlResponse = template.context;
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
id = initSetting.generateID();
|
|
312
|
+
const tvalue = {
|
|
313
|
+
ID: id,
|
|
314
|
+
Destination: metadata.target.getSingleLogoutService(binding.post),
|
|
315
|
+
EntityID: metadata.init.getEntityID(),
|
|
316
|
+
Issuer: metadata.init.getEntityID(),
|
|
317
|
+
IssueInstant: new Date().toISOString(),
|
|
318
|
+
StatusCode: urn_js_1.StatusCode.Success,
|
|
319
|
+
InResponseTo: (0, utility_js_1.get)(requestInfo, 'extract.request.id', null)
|
|
320
|
+
};
|
|
321
|
+
rawSamlResponse = libsaml_js_1.default.replaceTagsByValue(libsaml_js_1.default.defaultLogoutResponseTemplate.context, tvalue);
|
|
322
|
+
}
|
|
323
|
+
if (entity.target.entitySetting.wantLogoutResponseSigned) {
|
|
324
|
+
const { privateKey, privateKeyPass, requestSignatureAlgorithm: signatureAlgorithm, transformationAlgorithms } = initSetting;
|
|
325
|
+
return {
|
|
326
|
+
id,
|
|
327
|
+
context: libsaml_js_1.default.constructSAMLSignature({
|
|
328
|
+
isMessageSigned: true,
|
|
329
|
+
transformationAlgorithms: transformationAlgorithms,
|
|
330
|
+
privateKey,
|
|
331
|
+
privateKeyPass,
|
|
332
|
+
signatureAlgorithm,
|
|
333
|
+
rawSamlMessage: rawSamlResponse,
|
|
334
|
+
signingCert: metadata.init.getX509Certificate('signing'),
|
|
335
|
+
signatureConfig: {
|
|
336
|
+
prefix: 'ds',
|
|
337
|
+
location: {
|
|
338
|
+
reference: "/*[local-name(.)='LogoutResponse']/*[local-name(.)='Issuer']",
|
|
339
|
+
action: 'after'
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}),
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
id,
|
|
347
|
+
context: utility_js_1.default.base64Encode(rawSamlResponse),
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
throw new Error('ERR_GENERATE_POST_LOGOUT_RESPONSE_MISSING_METADATA');
|
|
351
|
+
}
|
|
352
|
+
const postBinding = {
|
|
353
|
+
base64LoginRequest,
|
|
354
|
+
base64LoginResponse,
|
|
355
|
+
base64LogoutRequest,
|
|
356
|
+
base64LogoutResponse,
|
|
357
|
+
};
|
|
358
|
+
exports.default = postBinding;
|
|
369
359
|
//# sourceMappingURL=binding-post.js.map
|