samlify 2.12.0 → 2.13.0
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.
- package/README.md +1 -1
- package/build/src/api.js +41 -3
- package/build/src/api.js.map +1 -1
- package/build/src/binding-post.js +236 -182
- package/build/src/binding-post.js.map +1 -1
- package/build/src/binding-redirect.js +303 -215
- package/build/src/binding-redirect.js.map +1 -1
- package/build/src/binding-simplesign.js +285 -137
- package/build/src/binding-simplesign.js.map +1 -1
- package/build/src/entity-idp.js +130 -47
- package/build/src/entity-idp.js.map +1 -1
- package/build/src/entity-sp.js +81 -39
- package/build/src/entity-sp.js.map +1 -1
- package/build/src/entity.js +100 -62
- package/build/src/entity.js.map +1 -1
- package/build/src/extractor.js +118 -151
- package/build/src/extractor.js.map +1 -1
- package/build/src/flow.js +100 -96
- package/build/src/flow.js.map +1 -1
- package/build/src/libsaml.js +315 -259
- package/build/src/libsaml.js.map +1 -1
- package/build/src/metadata-idp.js +60 -30
- package/build/src/metadata-idp.js.map +1 -1
- package/build/src/metadata-sp.js +51 -41
- package/build/src/metadata-sp.js.map +1 -1
- package/build/src/metadata.js +47 -43
- package/build/src/metadata.js.map +1 -1
- package/build/src/options.js +73 -0
- package/build/src/options.js.map +1 -0
- package/build/src/urn.js +28 -1
- package/build/src/urn.js.map +1 -1
- package/build/src/utility.js +140 -85
- package/build/src/utility.js.map +1 -1
- package/build/src/validator.js +27 -10
- package/build/src/validator.js.map +1 -1
- package/package.json +16 -5
- package/types/src/api.d.ts +33 -3
- package/types/src/binding-post.d.ts +67 -34
- package/types/src/binding-redirect.d.ts +58 -31
- package/types/src/binding-simplesign.d.ts +77 -21
- package/types/src/entity-idp.d.ts +40 -31
- package/types/src/entity-sp.d.ts +37 -27
- package/types/src/entity.d.ts +71 -77
- package/types/src/extractor.d.ts +31 -22
- package/types/src/flow.d.ts +24 -2
- package/types/src/libsaml.d.ts +172 -118
- package/types/src/metadata-idp.d.ts +27 -11
- package/types/src/metadata-sp.d.ts +29 -19
- package/types/src/metadata.d.ts +59 -34
- package/types/src/options.d.ts +37 -0
- package/types/src/types.d.ts +250 -24
- package/types/src/urn.d.ts +7 -0
- package/types/src/utility.d.ts +139 -90
- package/types/src/validator.d.ts +21 -0
- package/.circleci/config.yml +0 -98
- package/.editorconfig +0 -19
- package/.github/FUNDING.yml +0 -1
- package/.github/workflows/deploy-docs.yml +0 -56
- package/.pre-commit.sh +0 -15
- package/.snyk +0 -4
- package/Makefile +0 -25
- package/index.ts +0 -28
- package/samlify-2.11.0.tgz +0 -0
- package/src/api.ts +0 -48
- package/src/binding-post.ts +0 -336
- package/src/binding-redirect.ts +0 -335
- package/src/binding-simplesign.ts +0 -231
- package/src/entity-idp.ts +0 -145
- package/src/entity-sp.ts +0 -114
- package/src/entity.ts +0 -243
- package/src/extractor.ts +0 -399
- package/src/flow.ts +0 -469
- package/src/libsaml.ts +0 -779
- package/src/metadata-idp.ts +0 -146
- package/src/metadata-sp.ts +0 -203
- package/src/metadata.ts +0 -166
- package/src/types.ts +0 -127
- package/src/urn.ts +0 -210
- package/src/utility.ts +0 -259
- package/src/validator.ts +0 -44
- package/tsconfig.json +0 -41
- package/tslint.json +0 -35
- package/types.d.ts +0 -2
- package/vitest.config.ts +0 -12
package/types/src/entity.d.ts
CHANGED
|
@@ -1,35 +1,8 @@
|
|
|
1
1
|
import { IdpMetadata as IdpMetadataConstructor } from './metadata-idp';
|
|
2
2
|
import { SpMetadata as SpMetadataConstructor } from './metadata-sp';
|
|
3
|
-
import { MetadataIdpConstructor, MetadataSpConstructor, EntitySetting } from './types';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
query?: any;
|
|
7
|
-
body?: any;
|
|
8
|
-
octetString?: string;
|
|
9
|
-
}
|
|
10
|
-
export interface BindingContext {
|
|
11
|
-
context: string;
|
|
12
|
-
id: string;
|
|
13
|
-
}
|
|
14
|
-
export interface PostBindingContext extends BindingContext {
|
|
15
|
-
relayState?: string;
|
|
16
|
-
entityEndpoint: string;
|
|
17
|
-
type: string;
|
|
18
|
-
}
|
|
19
|
-
export interface SimpleSignBindingContext extends PostBindingContext {
|
|
20
|
-
sigAlg?: string;
|
|
21
|
-
signature?: string;
|
|
22
|
-
keyInfo?: string;
|
|
23
|
-
}
|
|
24
|
-
export interface SimpleSignComputedContext extends BindingContext {
|
|
25
|
-
sigAlg?: string;
|
|
26
|
-
signature?: string;
|
|
27
|
-
}
|
|
28
|
-
export interface ParseResult {
|
|
29
|
-
samlContent: string;
|
|
30
|
-
extract: any;
|
|
31
|
-
sigAlg: string;
|
|
32
|
-
}
|
|
3
|
+
import type { MetadataIdpConstructor, MetadataSpConstructor, EntitySetting, ESamlHttpRequest, BindingContext, PostBindingContext, SimpleSignBindingContext, RequestInfo, SAMLUser, CreateLogoutRequestOptions, CreateLogoutResponseOptions, CustomTagReplacement } from './types';
|
|
4
|
+
export type { ESamlHttpRequest, BindingContext, PostBindingContext, SimpleSignBindingContext, SimpleSignComputedContext, ParseResult, } from './types';
|
|
5
|
+
/** Constructor argument shared by both SP and IdP factories. */
|
|
33
6
|
export type EntityConstructor = (MetadataIdpConstructor | MetadataSpConstructor) & {
|
|
34
7
|
metadata?: string | Buffer;
|
|
35
8
|
};
|
|
@@ -38,62 +11,83 @@ export default class Entity {
|
|
|
38
11
|
entityType: string;
|
|
39
12
|
entityMeta: IdpMetadataConstructor | SpMetadataConstructor;
|
|
40
13
|
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
14
|
+
* Build an entity, merging the provided configuration with defaults and
|
|
15
|
+
* hydrating the metadata abstraction for its role.
|
|
16
|
+
*
|
|
17
|
+
* @param entitySetting IdP or SP settings (metadata XML or options)
|
|
18
|
+
* @param entityType `idp` or `sp`
|
|
19
|
+
*/
|
|
44
20
|
constructor(entitySetting: EntityConstructor, entityType: 'idp' | 'sp');
|
|
45
21
|
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*/
|
|
22
|
+
* Return the effective entity settings (defaults merged with overrides).
|
|
23
|
+
*/
|
|
49
24
|
getEntitySetting(): EntitySetting;
|
|
50
25
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
*/
|
|
26
|
+
* Return the serialized metadata XML for this entity.
|
|
27
|
+
*/
|
|
54
28
|
getMetadata(): string;
|
|
55
29
|
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
30
|
+
* Persist the metadata XML to disk.
|
|
31
|
+
*
|
|
32
|
+
* @param exportFile absolute file path
|
|
33
|
+
*/
|
|
59
34
|
exportMetadata(exportFile: string): void;
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Equality check between a field value extracted from a SAML message and
|
|
37
|
+
* the value declared in the peer's metadata. Arrays must match on every
|
|
38
|
+
* entry.
|
|
39
|
+
*
|
|
40
|
+
* @param field value(s) from the inbound SAML message
|
|
41
|
+
* @param metaField value from peer metadata
|
|
42
|
+
* @returns true when every provided value equals `metaField`
|
|
43
|
+
*/
|
|
65
44
|
verifyFields(field: string | string[], metaField: string): boolean;
|
|
66
|
-
/** @desc Generates the logout request for developers to design their own method
|
|
67
|
-
* @param {ServiceProvider} sp object of service provider
|
|
68
|
-
* @param {string} binding protocol binding
|
|
69
|
-
* @param {object} user current logged user (e.g. user)
|
|
70
|
-
* @param {string} relayState the URL to which to redirect the user when logout is complete
|
|
71
|
-
* @param {function} customTagReplacement used when developers have their own login response template
|
|
72
|
-
*/
|
|
73
|
-
createLogoutRequest(targetEntity: any, binding: any, user: any, relayState?: string, customTagReplacement?: any): BindingContext | PostBindingContext;
|
|
74
45
|
/**
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
46
|
+
* Build a logout request targeting `targetEntity`. The return type depends
|
|
47
|
+
* on the binding: `redirect` produces a URL; `post` and `simpleSign`
|
|
48
|
+
* produce a base64 envelope (the latter with a detached signature).
|
|
49
|
+
*
|
|
50
|
+
* The fourth parameter accepts either a string (legacy `relayState`
|
|
51
|
+
* positional shape) or an options bag `{ relayState?, customTagReplacement? }`.
|
|
52
|
+
* Per `saml-bindings §3.4.3 / §3.5.3`, RelayState is request-scoped — pass
|
|
53
|
+
* it via the options bag instead of `entitySetting.relayState`.
|
|
54
|
+
*
|
|
55
|
+
* @param targetEntity peer to receive the logout request
|
|
56
|
+
* @param binding `redirect`, `post`, or `simpleSign`
|
|
57
|
+
* @param user currently authenticated user
|
|
58
|
+
* @param optionsOrRelayState per-request options or legacy RelayState string
|
|
59
|
+
* @param legacyCustomTagReplacement optional custom template transformer (legacy positional form)
|
|
60
|
+
*/
|
|
61
|
+
createLogoutRequest(targetEntity: Entity, binding: string, user: SAMLUser, optionsOrRelayState?: CreateLogoutRequestOptions | string, legacyCustomTagReplacement?: CustomTagReplacement): BindingContext | PostBindingContext | SimpleSignBindingContext;
|
|
62
|
+
/**
|
|
63
|
+
* Build a logout response to the peer that initiated logout.
|
|
64
|
+
*
|
|
65
|
+
* The fourth parameter accepts either a string (legacy `relayState`
|
|
66
|
+
* positional shape) or an options bag `{ relayState?, customTagReplacement? }`.
|
|
67
|
+
* Per `saml-bindings §3.4.3 / §3.5.3`, RelayState is request-scoped — pass
|
|
68
|
+
* it via the options bag instead of `entitySetting.relayState`.
|
|
69
|
+
*
|
|
70
|
+
* @param target peer that sent the corresponding logout request
|
|
71
|
+
* @param requestInfo parsed request used to link `InResponseTo`
|
|
72
|
+
* @param binding `redirect`, `post`, or `simpleSign`
|
|
73
|
+
* @param optionsOrRelayState per-request options or legacy RelayState string
|
|
74
|
+
* @param legacyCustomTagReplacement optional custom template transformer (legacy positional form)
|
|
75
|
+
*/
|
|
76
|
+
createLogoutResponse(target: Entity, requestInfo: RequestInfo, binding: string, optionsOrRelayState?: CreateLogoutResponseOptions | string, legacyCustomTagReplacement?: CustomTagReplacement): BindingContext | PostBindingContext | SimpleSignBindingContext;
|
|
83
77
|
/**
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
parseLogoutRequest(from:
|
|
78
|
+
* Parse, validate and verify an inbound logout request.
|
|
79
|
+
*
|
|
80
|
+
* @param from peer entity that produced the request
|
|
81
|
+
* @param binding `redirect`, `post`, or `simpleSign`
|
|
82
|
+
* @param request HTTP request envelope
|
|
83
|
+
*/
|
|
84
|
+
parseLogoutRequest(from: Entity, binding: string, request: ESamlHttpRequest): Promise<import("./flow").FlowResult>;
|
|
91
85
|
/**
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
parseLogoutResponse(from:
|
|
86
|
+
* Parse, validate and verify an inbound logout response.
|
|
87
|
+
*
|
|
88
|
+
* @param from peer entity that produced the response
|
|
89
|
+
* @param binding `redirect`, `post`, or `simpleSign`
|
|
90
|
+
* @param request HTTP request envelope
|
|
91
|
+
*/
|
|
92
|
+
parseLogoutResponse(from: Entity, binding: string, request: ESamlHttpRequest): Promise<import("./flow").FlowResult>;
|
|
99
93
|
}
|
package/types/src/extractor.d.ts
CHANGED
|
@@ -1,25 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
attributes: string[];
|
|
5
|
-
index?: string[];
|
|
6
|
-
attributePath?: string[];
|
|
7
|
-
context?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export type ExtractorFields = ExtractorField[];
|
|
1
|
+
import type { ExtractorField, ExtractorFields, ExtractorResult } from './types';
|
|
2
|
+
export type { ExtractorField, ExtractorFields, ExtractorResult } from './types';
|
|
3
|
+
/** Default extractor fields for an inbound `AuthnRequest` (login request). */
|
|
10
4
|
export declare const loginRequestFields: ExtractorFields;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
5
|
+
/** Two-tier status code extractor for login responses. */
|
|
6
|
+
export declare const loginResponseStatusFields: ExtractorFields;
|
|
7
|
+
/** Two-tier status code extractor for logout responses. */
|
|
8
|
+
export declare const logoutResponseStatusFields: ExtractorFields;
|
|
9
|
+
/**
|
|
10
|
+
* Build the login-response extractor bound to a particular assertion XML.
|
|
11
|
+
* Assertion-scoped fields are re-rooted at the assertion fragment via the
|
|
12
|
+
* `shortcut` mechanism so that wrapping attacks can't redirect extraction.
|
|
13
|
+
*
|
|
14
|
+
* @param assertion XML string of the (verified) assertion node
|
|
15
|
+
* @returns extractor fields ready for `extract`
|
|
16
|
+
*/
|
|
17
|
+
export declare const loginResponseFields: (assertion: string) => ExtractorFields;
|
|
18
|
+
/** Default extractor fields for an inbound `LogoutRequest`. */
|
|
22
19
|
export declare const logoutRequestFields: ExtractorFields;
|
|
20
|
+
/** Default extractor fields for an inbound `LogoutResponse`. */
|
|
23
21
|
export declare const logoutResponseFields: ExtractorFields;
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Evaluate the given extractor fields against an XML document and return
|
|
24
|
+
* a flat object keyed by `field.key`. Handles:
|
|
25
|
+
* - multi-path localPaths (`string[][]`) collected with `|`
|
|
26
|
+
* - parent/child attribute aggregation (`index` + `attributePath`)
|
|
27
|
+
* - whole-subtree extraction (`context: true`)
|
|
28
|
+
* - single/multiple/zero-attribute text extraction
|
|
29
|
+
*
|
|
30
|
+
* @param context XML string to parse
|
|
31
|
+
* @param fields extractor field definitions
|
|
32
|
+
* @returns extracted SAML values keyed by field name
|
|
33
|
+
*/
|
|
34
|
+
export declare function extract(context: string, fields: ExtractorField[]): ExtractorResult;
|
package/types/src/flow.d.ts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
|
+
import type { ESamlHttpRequest, ExtractorResult } from './types';
|
|
2
|
+
import type Entity from './entity';
|
|
3
|
+
import { ParserType } from './urn';
|
|
4
|
+
/** Result emitted by the flow dispatcher for successful inbound messages. */
|
|
1
5
|
export interface FlowResult {
|
|
2
6
|
samlContent: string;
|
|
3
|
-
extract:
|
|
7
|
+
extract: ExtractorResult;
|
|
4
8
|
sigAlg?: string | null;
|
|
5
9
|
}
|
|
6
|
-
|
|
10
|
+
/** Options consumed by {@link flow} and its internal dispatch helpers. */
|
|
11
|
+
export interface FlowOptions {
|
|
12
|
+
request: ESamlHttpRequest;
|
|
13
|
+
parserType: ParserType | string;
|
|
14
|
+
self: Entity;
|
|
15
|
+
from: Entity;
|
|
16
|
+
checkSignature?: boolean;
|
|
17
|
+
type: 'login' | 'logout';
|
|
18
|
+
binding: string;
|
|
19
|
+
supportBindings?: string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Entry point: dispatch an inbound SAML message to the matching binding
|
|
23
|
+
* handler based on `options.binding`.
|
|
24
|
+
*
|
|
25
|
+
* @param options flow inputs (request, parserType, entities, binding)
|
|
26
|
+
* @returns resolved {@link FlowResult} on success
|
|
27
|
+
*/
|
|
28
|
+
export declare function flow(options: FlowOptions): Promise<FlowResult>;
|
package/types/src/libsaml.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file
|
|
3
|
-
* @author tngan
|
|
4
|
-
* @desc
|
|
5
|
-
|
|
2
|
+
* @file libsaml.ts
|
|
3
|
+
* @author tngan
|
|
4
|
+
* @desc SAML primitives: templates, XML signing/verification, assertion
|
|
5
|
+
* encryption/decryption, and XPath helpers used by the higher-level flows.
|
|
6
|
+
*/
|
|
6
7
|
import { MetadataInterface } from './metadata';
|
|
8
|
+
import { SigningSchemeHash } from 'node-rsa';
|
|
9
|
+
import type { EntitySetting, SignatureConfig, TagReplacementMap, XmlElementArray } from './types';
|
|
10
|
+
/** Options accepted by {@link LibSamlInterface.constructSAMLSignature}. */
|
|
7
11
|
export interface SignatureConstructor {
|
|
8
12
|
rawSamlMessage: string;
|
|
9
13
|
referenceTagXPath?: string;
|
|
@@ -12,22 +16,28 @@ export interface SignatureConstructor {
|
|
|
12
16
|
signatureAlgorithm: string;
|
|
13
17
|
signingCert: string | Buffer;
|
|
14
18
|
isBase64Output?: boolean;
|
|
15
|
-
signatureConfig?:
|
|
19
|
+
signatureConfig?: SignatureConfig;
|
|
16
20
|
isMessageSigned?: boolean;
|
|
17
21
|
transformationAlgorithms?: string[];
|
|
18
22
|
}
|
|
23
|
+
/** Options accepted by {@link LibSamlInterface.verifySignature}. */
|
|
19
24
|
export interface SignatureVerifierOptions {
|
|
20
25
|
metadata?: MetadataInterface;
|
|
21
26
|
keyFile?: string;
|
|
22
27
|
signatureAlgorithm?: string;
|
|
23
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Generic extracted SAML result shape retained for backwards compatibility.
|
|
31
|
+
* Prefer {@link import('./types').ExtractorResult} in new code.
|
|
32
|
+
*/
|
|
24
33
|
export interface ExtractorResult {
|
|
25
|
-
[key: string]:
|
|
34
|
+
[key: string]: unknown;
|
|
26
35
|
signature?: string | string[];
|
|
27
36
|
issuer?: string | string[];
|
|
28
37
|
nameID?: string;
|
|
29
38
|
notexist?: boolean;
|
|
30
39
|
}
|
|
40
|
+
/** Attribute configuration used when building an AttributeStatement. */
|
|
31
41
|
export interface LoginResponseAttribute {
|
|
32
42
|
name: string;
|
|
33
43
|
nameFormat: string;
|
|
@@ -36,10 +46,12 @@ export interface LoginResponseAttribute {
|
|
|
36
46
|
valueXmlnsXs?: string;
|
|
37
47
|
valueXmlnsXsi?: string;
|
|
38
48
|
}
|
|
49
|
+
/** Overridable templates used when building a LoginResponse. */
|
|
39
50
|
export interface LoginResponseAdditionalTemplates {
|
|
40
51
|
attributeStatementTemplate?: AttributeStatementTemplate;
|
|
41
52
|
attributeTemplate?: AttributeTemplate;
|
|
42
53
|
}
|
|
54
|
+
/** Shared shape for all SAML document templates. */
|
|
43
55
|
export interface BaseSamlTemplate {
|
|
44
56
|
context: string;
|
|
45
57
|
}
|
|
@@ -57,26 +69,53 @@ export interface LogoutRequestTemplate extends BaseSamlTemplate {
|
|
|
57
69
|
}
|
|
58
70
|
export interface LogoutResponseTemplate extends BaseSamlTemplate {
|
|
59
71
|
}
|
|
72
|
+
/** Valid certificate `use` attribute values in metadata KeyDescriptor. */
|
|
60
73
|
export type KeyUse = 'signing' | 'encryption';
|
|
74
|
+
/** Shape of a KeyDescriptor element assembled by `createKeySection`. */
|
|
61
75
|
export interface KeyComponent {
|
|
62
|
-
[key: string]:
|
|
76
|
+
[key: string]: unknown;
|
|
77
|
+
KeyDescriptor: XmlElementArray;
|
|
78
|
+
}
|
|
79
|
+
/** Structural shape of an Entity (IdP or SP) consumed by libsaml. */
|
|
80
|
+
export interface EntityLike {
|
|
81
|
+
entitySetting: EntitySetting & {
|
|
82
|
+
isAssertionEncrypted?: boolean;
|
|
83
|
+
dataEncryptionAlgorithm?: string;
|
|
84
|
+
keyEncryptionAlgorithm?: string;
|
|
85
|
+
tagPrefix?: {
|
|
86
|
+
protocol?: string;
|
|
87
|
+
assertion?: string;
|
|
88
|
+
encryptedAssertion?: string;
|
|
89
|
+
[key: string]: string | undefined;
|
|
90
|
+
};
|
|
91
|
+
encPrivateKey?: string | Buffer;
|
|
92
|
+
encPrivateKeyPass?: string | Buffer;
|
|
93
|
+
};
|
|
94
|
+
entityMeta: MetadataInterface;
|
|
63
95
|
}
|
|
96
|
+
/** Public surface exposed by the libsaml singleton. */
|
|
64
97
|
export interface LibSamlInterface {
|
|
65
98
|
getQueryParamByType: (type: string) => string;
|
|
66
|
-
createXPath: (local:
|
|
67
|
-
|
|
99
|
+
createXPath: (local: string | {
|
|
100
|
+
name: string;
|
|
101
|
+
attr: string;
|
|
102
|
+
}, isExtractAll?: boolean) => string;
|
|
103
|
+
replaceTagsByValue: (rawXML: string, tagValues: TagReplacementMap) => string;
|
|
68
104
|
attributeStatementBuilder: (attributes: LoginResponseAttribute[], attributeTemplate: AttributeTemplate, attributeStatementTemplate: AttributeStatementTemplate) => string;
|
|
69
105
|
constructSAMLSignature: (opts: SignatureConstructor) => string;
|
|
70
|
-
verifySignature: (xml: string, opts: SignatureVerifierOptions) => [boolean,
|
|
71
|
-
createKeySection: (use: KeyUse, cert: string | Buffer) =>
|
|
72
|
-
constructMessageSignature: (octetString: string, key: string, passphrase?: string, isBase64?: boolean, signingAlgorithm?: string) => string;
|
|
73
|
-
verifyMessageSignature: (metadata:
|
|
74
|
-
getKeyInfo: (x509Certificate: string, signatureConfig?:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
106
|
+
verifySignature: (xml: string, opts: SignatureVerifierOptions) => [boolean, string | null];
|
|
107
|
+
createKeySection: (use: KeyUse, cert: string | Buffer) => KeyComponent;
|
|
108
|
+
constructMessageSignature: (octetString: string, key: string, passphrase?: string, isBase64?: boolean, signingAlgorithm?: string) => string | Buffer;
|
|
109
|
+
verifyMessageSignature: (metadata: MetadataInterface, octetString: string, signature: string | Buffer, verifyAlgorithm?: string) => boolean;
|
|
110
|
+
getKeyInfo: (x509Certificate: string, signatureConfig?: SignatureConfig) => {
|
|
111
|
+
getKeyInfo: () => string;
|
|
112
|
+
getKey: () => string;
|
|
113
|
+
};
|
|
114
|
+
encryptAssertion: (sourceEntity: EntityLike, targetEntity: EntityLike, entireXML: string) => Promise<string>;
|
|
115
|
+
decryptAssertion: (here: EntityLike, entireXML: string) => Promise<[string, string]>;
|
|
116
|
+
getSigningScheme: (sigAlg: string) => SigningSchemeHash | null;
|
|
78
117
|
getDigestMethod: (sigAlg: string) => string | null;
|
|
79
|
-
nrsaAliasMapping:
|
|
118
|
+
nrsaAliasMapping: Record<string, SigningSchemeHash>;
|
|
80
119
|
defaultLoginRequestTemplate: LoginRequestTemplate;
|
|
81
120
|
defaultLoginResponseTemplate: LoginResponseTemplate;
|
|
82
121
|
defaultAttributeStatementTemplate: AttributeStatementTemplate;
|
|
@@ -85,125 +124,140 @@ export interface LibSamlInterface {
|
|
|
85
124
|
defaultLogoutResponseTemplate: LogoutResponseTemplate;
|
|
86
125
|
}
|
|
87
126
|
declare const _default: {
|
|
88
|
-
createXPath: (local:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
};
|
|
100
|
-
attributeTemplate: {
|
|
101
|
-
context: string;
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
defaultAttributeStatementTemplate: {
|
|
106
|
-
context: string;
|
|
107
|
-
};
|
|
108
|
-
defaultAttributeTemplate: {
|
|
109
|
-
context: string;
|
|
110
|
-
};
|
|
111
|
-
defaultLogoutRequestTemplate: {
|
|
112
|
-
context: string;
|
|
113
|
-
};
|
|
114
|
-
defaultLogoutResponseTemplate: {
|
|
115
|
-
context: string;
|
|
116
|
-
};
|
|
127
|
+
createXPath: (local: string | {
|
|
128
|
+
name: string;
|
|
129
|
+
attr: string;
|
|
130
|
+
}, isExtractAll?: boolean) => string;
|
|
131
|
+
getQueryParamByType: (type: string) => string;
|
|
132
|
+
defaultLoginRequestTemplate: LoginRequestTemplate;
|
|
133
|
+
defaultLoginResponseTemplate: LoginResponseTemplate;
|
|
134
|
+
defaultAttributeStatementTemplate: AttributeStatementTemplate;
|
|
135
|
+
defaultAttributeTemplate: AttributeTemplate;
|
|
136
|
+
defaultLogoutRequestTemplate: LogoutRequestTemplate;
|
|
137
|
+
defaultLogoutResponseTemplate: LogoutResponseTemplate;
|
|
117
138
|
/**
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
139
|
+
* Substitute `{Tag}` placeholders inside an XML template with the given
|
|
140
|
+
* replacement map. Replacement text is XML-escaped in both attribute and
|
|
141
|
+
* element-text positions to prevent SAML element/attribute injection.
|
|
142
|
+
*
|
|
143
|
+
* When a tag's value is `null` or `undefined`:
|
|
144
|
+
* - in **attribute position** (`name="{Tag}"`) the entire attribute is
|
|
145
|
+
* omitted from the rendered XML, per `saml-core §3.4.1` (every
|
|
146
|
+
* `<AuthnRequest>` attribute is `use="optional"`); previously samlify
|
|
147
|
+
* emitted `name=""` or the literal `name="undefined"`, which is
|
|
148
|
+
* invalid for typed attributes (e.g. `AssertionConsumerServiceURL`
|
|
149
|
+
* declared as `xs:anyURI`).
|
|
150
|
+
* - in **element-only-body position** (`<X>{Tag}</X>` or
|
|
151
|
+
* `<X attr="...">{Tag}</X>`) the entire element is dropped — per
|
|
152
|
+
* `saml-core §3.7.1` for `<samlp:SessionIndex>` and any other
|
|
153
|
+
* `minOccurs="0"` element where the body is solely a placeholder.
|
|
154
|
+
* - in **mixed-text position** (`<X>prefix{Tag}suffix</X>`) the
|
|
155
|
+
* placeholder is replaced with the empty string (legacy behaviour).
|
|
156
|
+
*
|
|
157
|
+
* @param rawXML template with `{Tag}` placeholders
|
|
158
|
+
* @param tagValues replacement map keyed by tag name
|
|
159
|
+
* @returns XML with placeholders resolved
|
|
160
|
+
*/
|
|
161
|
+
replaceTagsByValue(rawXML: string, tagValues: TagReplacementMap): string;
|
|
124
162
|
/**
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
163
|
+
* Build a serialized `<AttributeStatement>` from attribute descriptors
|
|
164
|
+
* by applying the attribute and statement templates.
|
|
165
|
+
*
|
|
166
|
+
* @param attributes attribute descriptors (name, format, value)
|
|
167
|
+
* @param attributeTemplate per-attribute template
|
|
168
|
+
* @param attributeStatementTemplate wrapping statement template
|
|
169
|
+
* @returns serialized XML fragment
|
|
170
|
+
*/
|
|
131
171
|
attributeStatementBuilder(attributes: LoginResponseAttribute[], attributeTemplate?: AttributeTemplate, attributeStatementTemplate?: AttributeStatementTemplate): string;
|
|
132
172
|
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
* @param {string[]} transformationAlgorithms canonicalization and transformation Algorithms
|
|
141
|
-
* @return {string} base64 encoded string
|
|
142
|
-
*/
|
|
173
|
+
* Compute an XML-DSig signature over the supplied SAML message. Can
|
|
174
|
+
* sign the message root (`isMessageSigned`), a referenced subtree
|
|
175
|
+
* (`referenceTagXPath`), or both.
|
|
176
|
+
*
|
|
177
|
+
* @param opts signature inputs and layout options
|
|
178
|
+
* @returns base64 (default) or raw signed XML string
|
|
179
|
+
*/
|
|
143
180
|
constructSAMLSignature(opts: SignatureConstructor): string;
|
|
144
181
|
/**
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
182
|
+
* Verify an XML-DSig signature on a SAML payload and, on success, return
|
|
183
|
+
* the cryptographically authenticated assertion node.
|
|
184
|
+
*
|
|
185
|
+
* Defends against classic wrapping attacks by rejecting assertions that
|
|
186
|
+
* appear inside a `SubjectConfirmationData` subtree.
|
|
187
|
+
*
|
|
188
|
+
* @param xml SAML message XML
|
|
189
|
+
* @param opts metadata or key file plus signature algorithm
|
|
190
|
+
* @returns tuple `[verified, authenticatedAssertion | null]`
|
|
151
191
|
*/
|
|
152
192
|
verifySignature(xml: string, opts: SignatureVerifierOptions): [boolean, string | null];
|
|
153
193
|
/**
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
194
|
+
* Build the metadata `<KeyDescriptor>` fragment for a certificate use.
|
|
195
|
+
*
|
|
196
|
+
* @param use `signing` or `encryption`
|
|
197
|
+
* @param certString PEM certificate body or Buffer
|
|
198
|
+
* @returns element tree consumable by the `xml` module
|
|
199
|
+
*/
|
|
159
200
|
createKeySection(use: KeyUse, certString: string | Buffer): KeyComponent;
|
|
160
201
|
/**
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
202
|
+
* Produce a detached RSA signature over a SAML redirect-binding octet
|
|
203
|
+
* string. See SAML bindings spec §3.4.4.1.
|
|
204
|
+
*
|
|
205
|
+
* @param octetString canonical query-string to sign
|
|
206
|
+
* @param key PEM private key
|
|
207
|
+
* @param passphrase optional passphrase for the key
|
|
208
|
+
* @param isBase64 when true (default), base64-encode the signature
|
|
209
|
+
* @param signingAlgorithm signature algorithm URI
|
|
210
|
+
* @returns base64 string (default) or raw Buffer signature
|
|
211
|
+
*/
|
|
212
|
+
constructMessageSignature(octetString: string, key: string, passphrase?: string, isBase64?: boolean, signingAlgorithm?: string): string | Buffer;
|
|
169
213
|
/**
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
214
|
+
* Verify a detached RSA signature over a redirect-binding octet string.
|
|
215
|
+
*
|
|
216
|
+
* @param metadata peer metadata carrying the signing certificate
|
|
217
|
+
* @param octetString canonical query-string that was signed
|
|
218
|
+
* @param signature signature bytes
|
|
219
|
+
* @param verifyAlgorithm signature algorithm URI (optional)
|
|
220
|
+
* @returns true when the signature verifies
|
|
221
|
+
*/
|
|
222
|
+
verifyMessageSignature(metadata: MetadataInterface, octetString: string, signature: string | Buffer, verifyAlgorithm?: string): boolean;
|
|
178
223
|
/**
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
224
|
+
* Build the KeyInfo XML fragment and PEM public key for a certificate.
|
|
225
|
+
*
|
|
226
|
+
* @param x509Certificate certificate body (no PEM wrappers)
|
|
227
|
+
* @param signatureConfig optional prefix/location for the KeyInfo element
|
|
228
|
+
*/
|
|
229
|
+
getKeyInfo(x509Certificate: string, signatureConfig?: SignatureConfig): {
|
|
184
230
|
getKeyInfo: () => string;
|
|
185
231
|
getKey: () => string;
|
|
186
232
|
};
|
|
187
233
|
/**
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
234
|
+
* Encrypt the `<Assertion>` inside a SAML response using the target
|
|
235
|
+
* entity's encryption certificate. Returns the base64-encoded XML
|
|
236
|
+
* containing the `<EncryptedAssertion>` element in place of the plaintext.
|
|
237
|
+
*
|
|
238
|
+
* @param sourceEntity entity initiating the encryption (its settings drive the algorithms)
|
|
239
|
+
* @param targetEntity entity whose certificate is used
|
|
240
|
+
* @param xml response XML containing a single `<Assertion>`
|
|
241
|
+
* @returns promise resolving to base64-encoded XML
|
|
242
|
+
*/
|
|
243
|
+
encryptAssertion(sourceEntity: EntityLike, targetEntity: EntityLike, xml?: string): Promise<string>;
|
|
195
244
|
/**
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
245
|
+
* Decrypt the `<EncryptedAssertion>` inside a SAML response using the
|
|
246
|
+
* local entity's private key. Returns both the decrypted document XML
|
|
247
|
+
* and the raw assertion fragment for downstream extraction.
|
|
248
|
+
*
|
|
249
|
+
* @param here local entity performing decryption
|
|
250
|
+
* @param entireXML SAML response XML containing `<EncryptedAssertion>`
|
|
251
|
+
* @returns tuple `[decryptedDocumentXml, rawAssertionXml]`
|
|
252
|
+
*/
|
|
253
|
+
decryptAssertion(here: EntityLike, entireXML: string): Promise<[string, string]>;
|
|
204
254
|
/**
|
|
205
|
-
*
|
|
255
|
+
* Validate the SAML XML against the registered schema validator. Throws
|
|
256
|
+
* when no validator has been configured via {@link setSchemaValidator}
|
|
257
|
+
* so consumers can't silently ship without schema checks.
|
|
258
|
+
*
|
|
259
|
+
* @param input SAML XML string
|
|
206
260
|
*/
|
|
207
|
-
isValidXml(input: string): Promise<
|
|
261
|
+
isValidXml(input: string): Promise<unknown>;
|
|
208
262
|
};
|
|
209
263
|
export default _default;
|