samlesa 2.12.113 → 2.14.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.

Potentially problematic release.


This version of samlesa might be problematic. Click here for more details.

Files changed (145) hide show
  1. package/build/index.js +18 -54
  2. package/build/index.js.map +1 -1
  3. package/build/src/api.js +18 -24
  4. package/build/src/api.js.map +1 -1
  5. package/build/src/binding-post.js +337 -365
  6. package/build/src/binding-post.js.map +1 -1
  7. package/build/src/binding-redirect.js +312 -340
  8. package/build/src/binding-redirect.js.map +1 -1
  9. package/build/src/binding-simplesign.js +201 -229
  10. package/build/src/binding-simplesign.js.map +1 -1
  11. package/build/src/entity-idp.js +119 -127
  12. package/build/src/entity-idp.js.map +1 -1
  13. package/build/src/entity-sp.js +88 -96
  14. package/build/src/entity-sp.js.map +1 -1
  15. package/build/src/entity.js +193 -225
  16. package/build/src/entity.js.map +1 -1
  17. package/build/src/extractor.js +361 -369
  18. package/build/src/extractor.js.map +1 -1
  19. package/build/src/flow.js +313 -320
  20. package/build/src/flow.js.map +1 -1
  21. package/build/src/libsaml.js +693 -721
  22. package/build/src/libsaml.js.map +1 -1
  23. package/build/src/metadata-idp.js +119 -127
  24. package/build/src/metadata-idp.js.map +1 -1
  25. package/build/src/metadata-sp.js +223 -231
  26. package/build/src/metadata-sp.js.map +1 -1
  27. package/build/src/metadata.js +138 -166
  28. package/build/src/metadata.js.map +1 -1
  29. package/build/src/types.js +4 -11
  30. package/build/src/types.js.map +1 -1
  31. package/build/src/urn.js +204 -212
  32. package/build/src/urn.js.map +1 -1
  33. package/build/src/utility.js +277 -292
  34. package/build/src/utility.js.map +1 -1
  35. package/build/src/validator.js +24 -27
  36. package/build/src/validator.js.map +1 -1
  37. package/package.json +13 -7
  38. package/types/api.d.ts +15 -0
  39. package/types/api.d.ts.map +1 -0
  40. package/types/binding-post.d.ts +48 -0
  41. package/types/binding-post.d.ts.map +1 -0
  42. package/types/binding-redirect.d.ts +54 -0
  43. package/types/binding-redirect.d.ts.map +1 -0
  44. package/types/binding-simplesign.d.ts +41 -0
  45. package/types/binding-simplesign.d.ts.map +1 -0
  46. package/types/entity-idp.d.ts +38 -0
  47. package/types/entity-idp.d.ts.map +1 -0
  48. package/types/entity-sp.d.ts +38 -0
  49. package/types/entity-sp.d.ts.map +1 -0
  50. package/types/entity.d.ts +100 -0
  51. package/types/entity.d.ts.map +1 -0
  52. package/types/extractor.d.ts +26 -0
  53. package/types/extractor.d.ts.map +1 -0
  54. package/types/flow.d.ts +7 -0
  55. package/types/flow.d.ts.map +1 -0
  56. package/types/index.d.ts +11 -10
  57. package/types/index.d.ts.map +1 -0
  58. package/types/libsaml.d.ts +208 -0
  59. package/types/libsaml.d.ts.map +1 -0
  60. package/types/metadata-idp.d.ts +25 -0
  61. package/types/metadata-idp.d.ts.map +1 -0
  62. package/types/metadata-sp.d.ts +37 -0
  63. package/types/metadata-sp.d.ts.map +1 -0
  64. package/types/metadata.d.ts +58 -0
  65. package/types/metadata.d.ts.map +1 -0
  66. package/types/src/api.d.ts +15 -13
  67. package/types/src/api.d.ts.map +1 -0
  68. package/types/src/binding-post.d.ts +48 -47
  69. package/types/src/binding-post.d.ts.map +1 -0
  70. package/types/src/binding-redirect.d.ts +54 -53
  71. package/types/src/binding-redirect.d.ts.map +1 -0
  72. package/types/src/binding-simplesign.d.ts +41 -40
  73. package/types/src/binding-simplesign.d.ts.map +1 -0
  74. package/types/src/entity-idp.d.ts +38 -37
  75. package/types/src/entity-idp.d.ts.map +1 -0
  76. package/types/src/entity-sp.d.ts +38 -36
  77. package/types/src/entity-sp.d.ts.map +1 -0
  78. package/types/src/entity.d.ts +100 -101
  79. package/types/src/entity.d.ts.map +1 -0
  80. package/types/src/extractor.d.ts +26 -25
  81. package/types/src/extractor.d.ts.map +1 -0
  82. package/types/src/flow.d.ts +7 -6
  83. package/types/src/flow.d.ts.map +1 -0
  84. package/types/src/libsaml.d.ts +208 -209
  85. package/types/src/libsaml.d.ts.map +1 -0
  86. package/types/src/metadata-idp.d.ts +25 -24
  87. package/types/src/metadata-idp.d.ts.map +1 -0
  88. package/types/src/metadata-sp.d.ts +37 -36
  89. package/types/src/metadata-sp.d.ts.map +1 -0
  90. package/types/src/metadata.d.ts +58 -59
  91. package/types/src/metadata.d.ts.map +1 -0
  92. package/types/src/types.d.ts +128 -129
  93. package/types/src/types.d.ts.map +1 -0
  94. package/types/src/urn.d.ts +195 -194
  95. package/types/src/urn.d.ts.map +1 -0
  96. package/types/src/utility.d.ts +133 -134
  97. package/types/src/utility.d.ts.map +1 -0
  98. package/types/src/validator.d.ts +4 -3
  99. package/types/src/validator.d.ts.map +1 -0
  100. package/types/types.d.ts +128 -0
  101. package/types/types.d.ts.map +1 -0
  102. package/types/urn.d.ts +195 -0
  103. package/types/urn.d.ts.map +1 -0
  104. package/types/utility.d.ts +133 -0
  105. package/types/utility.d.ts.map +1 -0
  106. package/types/validator.d.ts +4 -0
  107. package/types/validator.d.ts.map +1 -0
  108. package/.editorconfig +0 -19
  109. package/.github/FUNDING.yml +0 -1
  110. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  111. package/.idea/modules.xml +0 -8
  112. package/.idea/samlify.iml +0 -12
  113. package/.idea/vcs.xml +0 -6
  114. package/.pre-commit.sh +0 -15
  115. package/.snyk +0 -8
  116. package/.travis.yml +0 -29
  117. package/Makefile +0 -25
  118. package/index.d.ts +0 -10
  119. package/index.js +0 -19
  120. package/index.js.map +0 -1
  121. package/index.ts +0 -28
  122. package/qodana.yaml +0 -29
  123. package/src/.idea/modules.xml +0 -8
  124. package/src/.idea/src.iml +0 -12
  125. package/src/.idea/vcs.xml +0 -6
  126. package/src/api.ts +0 -36
  127. package/src/binding-post.ts +0 -348
  128. package/src/binding-redirect.ts +0 -356
  129. package/src/binding-simplesign.ts +0 -238
  130. package/src/entity-idp.ts +0 -153
  131. package/src/entity-sp.ts +0 -114
  132. package/src/entity.ts +0 -243
  133. package/src/extractor.ts +0 -392
  134. package/src/flow.ts +0 -467
  135. package/src/libsaml.ts +0 -895
  136. package/src/metadata-idp.ts +0 -146
  137. package/src/metadata-sp.ts +0 -268
  138. package/src/metadata.ts +0 -166
  139. package/src/types.ts +0 -153
  140. package/src/urn.ts +0 -211
  141. package/src/utility.ts +0 -319
  142. package/src/validator.ts +0 -39
  143. package/tsconfig.json +0 -38
  144. package/tslint.json +0 -35
  145. package/types.d.ts +0 -2
package/src/types.ts DELETED
@@ -1,153 +0,0 @@
1
- import { LoginResponseTemplate } from './libsaml.js';
2
-
3
- export { IdentityProvider as IdentityProviderConstructor } from './entity-idp.js';
4
- export { IdpMetadata as IdentityProviderMetadata } from './metadata-idp.js';
5
-
6
- export { ServiceProvider as ServiceProviderConstructor } from './entity-sp.js';
7
- export { SpMetadata as ServiceProviderMetadata } from './metadata-sp.js';
8
-
9
- export type MetadataFile = string | Buffer;
10
-
11
- type SSOService = {
12
- isDefault?: boolean;
13
- Binding: string;
14
- Location: string;
15
- };
16
- // 1. 定义服务名称类型
17
- export type ServiceName = {
18
- value: string;
19
- /** @description 语言标识符(如 en/zh-CN) */
20
- lang?: string;
21
- };
22
-
23
- // 2. 定义请求属性类型
24
- export type RequestedAttribute = {
25
- name: string;
26
- friendlyName?: string;
27
- isRequired?: boolean;
28
- nameFormat?: string;
29
- attributeValue?: string[];
30
- };
31
-
32
- // 3. 定义属性消费服务类型
33
- export type AttributeConsumingService = {
34
- isDefault: boolean;
35
- serviceName: ServiceName[]; // 修复点:确保属性名为 serviceName(驼峰命名)
36
- serviceDescription: ServiceName[]; // 修复点:确保属性名为 serviceName(驼峰命名)
37
- requestedAttributes: RequestedAttribute[];
38
- };
39
-
40
- // 4. 定义顶层服务配置类型
41
- export type AttrService = AttributeConsumingService[];
42
- export interface MetadataIdpOptions {
43
- entityID?: string;
44
- signingCert?: string | Buffer | (string | Buffer)[];
45
- encryptCert?: string | Buffer | (string | Buffer)[];
46
- wantAuthnRequestsSigned?: boolean;
47
- nameIDFormat?: string[];
48
- singleSignOnService?: SSOService[];
49
- singleLogoutService?: SSOService[];
50
- requestSignatureAlgorithm?: string;
51
- }
52
-
53
- export type MetadataIdpConstructor =
54
- | MetadataIdpOptions
55
- | MetadataFile;
56
-
57
- export interface MetadataSpOptions {
58
- entityID?: string;
59
- signingCert?: string | Buffer | (string | Buffer)[];
60
- encryptCert?: string | Buffer | (string | Buffer)[];
61
- authnRequestsSigned?: boolean;
62
- wantAssertionsSigned?: boolean;
63
- wantMessageSigned?: boolean;
64
- signatureConfig?: { [key: string]: any };
65
- nameIDFormat?: string[];
66
- singleSignOnService?: SSOService[];
67
- singleLogoutService?: SSOService[];
68
- assertionConsumerService?: SSOService[];
69
- attributeConsumingService?: AttributeConsumingService[];
70
- elementsOrder?: string[];
71
- }
72
-
73
- export type MetadataSpConstructor =
74
- | MetadataSpOptions
75
- | MetadataFile;
76
-
77
- export type EntitySetting = ServiceProviderSettings & IdentityProviderSettings;
78
-
79
- export interface SignatureConfig {
80
- prefix?: string;
81
- location?: {
82
- reference?: string;
83
- action?: 'append' | 'prepend' | 'before' | 'after';
84
- };
85
- }
86
-
87
- export interface SAMLDocumentTemplate {
88
- context?: string;
89
- }
90
-
91
- export type ServiceProviderSettings = {
92
- metadata?: string | Buffer;
93
- entityID?: string;
94
- authnRequestsSigned?: boolean;
95
- wantAssertionsSigned?: boolean;
96
- wantMessageSigned?: boolean;
97
- wantLogoutResponseSigned?: boolean;
98
- wantLogoutRequestSigned?: boolean;
99
- privateKey?: string | Buffer;
100
- privateKeyPass?: string;
101
- isAssertionEncrypted?: boolean;
102
- requestSignatureAlgorithm?: string;
103
- encPrivateKey?: string | Buffer;
104
- encPrivateKeyPass?: string | Buffer;
105
- assertionConsumerService?: SSOService[];
106
- singleLogoutService?: SSOService[];
107
- signatureConfig?: SignatureConfig;
108
- loginRequestTemplate?: SAMLDocumentTemplate;
109
- logoutRequestTemplate?: SAMLDocumentTemplate;
110
- signingCert?: string | Buffer | (string | Buffer)[];
111
- encryptCert?: string | Buffer | (string | Buffer)[];
112
- transformationAlgorithms?: string[];
113
- nameIDFormat?: string[];
114
- allowCreate?: boolean;
115
- // will be deprecated soon
116
- relayState?: string;
117
- // https://github.com/tngan/samlify/issues/337
118
- clockDrifts?: [number, number];
119
- };
120
-
121
- export type IdentityProviderSettings = {
122
- metadata?: string | Buffer;
123
-
124
- /** signature algorithm */
125
- requestSignatureAlgorithm?: string;
126
-
127
- /** template of login response */
128
- loginResponseTemplate?: LoginResponseTemplate;
129
-
130
- /** template of logout request */
131
- logoutRequestTemplate?: SAMLDocumentTemplate;
132
-
133
- /** customized function used for generating request ID */
134
- generateID?: () => string;
135
-
136
- entityID?: string;
137
- privateKey?: string | Buffer;
138
- privateKeyPass?: string;
139
- signingCert?: string | Buffer | (string | Buffer)[];
140
- encryptCert?: string | Buffer | (string | Buffer)[];
141
- nameIDFormat?: string[];
142
- singleSignOnService?: SSOService[];
143
- singleLogoutService?: SSOService[];
144
- isAssertionEncrypted?: boolean;
145
- encPrivateKey?: string | Buffer;
146
- encPrivateKeyPass?: string;
147
- messageSigningOrder?: string;
148
- wantLogoutRequestSigned?: boolean;
149
- wantLogoutResponseSigned?: boolean;
150
- wantAuthnRequestsSigned?: boolean;
151
- wantLogoutRequestSignedResponseSigned?: boolean;
152
- tagPrefix?: { [key: string]: string };
153
- };
package/src/urn.ts DELETED
@@ -1,211 +0,0 @@
1
- /**
2
- * @file urn.ts
3
- * @author tngan
4
- * @desc Includes all keywords need in samlify
5
- */
6
-
7
- export enum BindingNamespace {
8
- Redirect = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
9
- Post = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
10
- SimpleSign = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST-SimpleSign',
11
- Artifact = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact'
12
- }
13
-
14
- export enum MessageSignatureOrder {
15
- STE = 'sign-then-encrypt',
16
- ETS = 'encrypt-then-sign'
17
- }
18
-
19
- export enum StatusCode {
20
- // top-tier
21
- Success = 'urn:oasis:names:tc:SAML:2.0:status:Success',
22
- Requester = 'urn:oasis:names:tc:SAML:2.0:status:Requester',
23
- Responder = 'urn:oasis:names:tc:SAML:2.0:status:Responder',
24
- VersionMismatch = 'urn:oasis:names:tc:SAML:2.0:status:VersionMismatch',
25
- // second-tier to provide more information
26
- AuthFailed = 'urn:oasis:names:tc:SAML:2.0:status:AuthnFailed',
27
- InvalidAttrNameOrValue = 'urn:oasis:names:tc:SAML:2.0:status:InvalidAttrNameOrValue',
28
- InvalidNameIDPolicy = 'urn:oasis:names:tc:SAML:2.0:status:InvalidNameIDPolicy',
29
- NoAuthnContext = 'urn:oasis:names:tc:SAML:2.0:status:NoAuthnContext',
30
- NoAvailableIDP = 'urn:oasis:names:tc:SAML:2.0:status:NoAvailableIDP',
31
- NoPassive = 'urn:oasis:names:tc:SAML:2.0:status:NoPassive',
32
- NoSupportedIDP = 'urn:oasis:names:tc:SAML:2.0:status:NoSupportedIDP',
33
- PartialLogout = 'urn:oasis:names:tc:SAML:2.0:status:PartialLogout',
34
- ProxyCountExceeded = 'urn:oasis:names:tc:SAML:2.0:status:ProxyCountExceeded',
35
- RequestDenied = 'urn:oasis:names:tc:SAML:2.0:status:RequestDenied',
36
- RequestUnsupported = 'urn:oasis:names:tc:SAML:2.0:status:RequestUnsupported',
37
- RequestVersionDeprecated = 'urn:oasis:names:tc:SAML:2.0:status:RequestVersionDeprecated',
38
- RequestVersionTooHigh = 'urn:oasis:names:tc:SAML:2.0:status:RequestVersionTooHigh',
39
- RequestVersionTooLow = 'urn:oasis:names:tc:SAML:2.0:status:RequestVersionTooLow',
40
- ResourceNotRecognized = 'urn:oasis:names:tc:SAML:2.0:status:ResourceNotRecognized',
41
- TooManyResponses = 'urn:oasis:names:tc:SAML:2.0:status:TooManyResponses',
42
- UnknownAttrProfile = 'urn:oasis:names:tc:SAML:2.0:status:UnknownAttrProfile',
43
- UnknownPrincipal = 'urn:oasis:names:tc:SAML:2.0:status:UnknownPrincipal',
44
- UnsupportedBinding = 'urn:oasis:names:tc:SAML:2.0:status:UnsupportedBinding',
45
- }
46
-
47
- const namespace = {
48
- binding: {
49
- redirect: 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
50
- post: 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
51
- simpleSign: 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST-SimpleSign',
52
- artifact: 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact',
53
- },
54
- names: {
55
- protocol: 'urn:oasis:names:tc:SAML:2.0:protocol',
56
- assertion: 'urn:oasis:names:tc:SAML:2.0:assertion',
57
- metadata: 'urn:oasis:names:tc:SAML:2.0:metadata',
58
- userLogout: 'urn:oasis:names:tc:SAML:2.0:logout:user',
59
- adminLogout: 'urn:oasis:names:tc:SAML:2.0:logout:admin',
60
- },
61
- authnContextClassRef: {
62
- password: 'urn:oasis:names:tc:SAML:2.0:ac:classes:Password',
63
- passwordProtectedTransport: 'urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport',
64
- },
65
- format: {
66
- emailAddress: 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress',
67
- persistent: 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent',
68
- transient: 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient',
69
- entity: 'urn:oasis:names:tc:SAML:2.0:nameid-format:entity',
70
- unspecified: 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
71
- kerberos: 'urn:oasis:names:tc:SAML:2.0:nameid-format:kerberos',
72
- windowsDomainQualifiedName: 'urn:oasis:names:tc:SAML:1.1:nameid-format:WindowsDomainQualifiedName',
73
- x509SubjectName: 'urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName',
74
- },
75
- statusCode: {
76
- // permissible top-level status codes
77
- success: 'urn:oasis:names:tc:SAML:2.0:status:Success',
78
- requester: 'urn:oasis:names:tc:SAML:2.0:status:Requester',
79
- responder: 'urn:oasis:names:tc:SAML:2.0:status:Responder',
80
- versionMismatch: 'urn:oasis:names:tc:SAML:2.0:status:VersionMismatch',
81
- // second-level status codes
82
- authFailed: 'urn:oasis:names:tc:SAML:2.0:status:AuthnFailed',
83
- invalidAttrNameOrValue: 'urn:oasis:names:tc:SAML:2.0:status:InvalidAttrNameOrValue',
84
- invalidNameIDPolicy: 'urn:oasis:names:tc:SAML:2.0:status:InvalidNameIDPolicy',
85
- noAuthnContext: 'urn:oasis:names:tc:SAML:2.0:status:NoAuthnContext',
86
- noAvailableIDP: 'urn:oasis:names:tc:SAML:2.0:status:NoAvailableIDP',
87
- noPassive: 'urn:oasis:names:tc:SAML:2.0:status:NoPassive',
88
- noSupportedIDP: 'urn:oasis:names:tc:SAML:2.0:status:NoSupportedIDP',
89
- partialLogout: 'urn:oasis:names:tc:SAML:2.0:status:PartialLogout',
90
- proxyCountExceeded: 'urn:oasis:names:tc:SAML:2.0:status:ProxyCountExceeded',
91
- requestDenied: 'urn:oasis:names:tc:SAML:2.0:status:RequestDenied',
92
- requestUnsupported: 'urn:oasis:names:tc:SAML:2.0:status:RequestUnsupported',
93
- requestVersionDeprecated: 'urn:oasis:names:tc:SAML:2.0:status:RequestVersionDeprecated',
94
- requestVersionTooHigh: 'urn:oasis:names:tc:SAML:2.0:status:RequestVersionTooHigh',
95
- requestVersionTooLow: 'urn:oasis:names:tc:SAML:2.0:status:RequestVersionTooLow',
96
- resourceNotRecognized: 'urn:oasis:names:tc:SAML:2.0:status:ResourceNotRecognized',
97
- tooManyResponses: 'urn:oasis:names:tc:SAML:2.0:status:TooManyResponses',
98
- unknownAttrProfile: 'urn:oasis:names:tc:SAML:2.0:status:UnknownAttrProfile',
99
- unknownPrincipal: 'urn:oasis:names:tc:SAML:2.0:status:UnknownPrincipal',
100
- unsupportedBinding: 'urn:oasis:names:tc:SAML:2.0:status:UnsupportedBinding',
101
- },
102
- };
103
-
104
- const tags = {
105
- request: {
106
- AllowCreate: '{AllowCreate}',
107
- AssertionConsumerServiceURL: '{AssertionConsumerServiceURL}',
108
- AuthnContextClassRef: '{AuthnContextClassRef}',
109
- AssertionID: '{AssertionID}',
110
- Audience: '{Audience}',
111
- AuthnStatement: '{AuthnStatement}',
112
- AttributeStatement: '{AttributeStatement}',
113
- ConditionsNotBefore: '{ConditionsNotBefore}',
114
- ConditionsNotOnOrAfter: '{ConditionsNotOnOrAfter}',
115
- Destination: '{Destination}',
116
- EntityID: '{EntityID}',
117
- ID: '{ID}',
118
- Issuer: '{Issuer}',
119
- IssueInstant: '{IssueInstant}',
120
- InResponseTo: '{InResponseTo}',
121
- NameID: '{NameID}',
122
- NameIDFormat: '{NameIDFormat}',
123
- ProtocolBinding: '{ProtocolBinding}',
124
- SessionIndex: '{SessionIndex}',
125
- SubjectRecipient: '{SubjectRecipient}',
126
- SubjectConfirmationDataNotOnOrAfter: '{SubjectConfirmationDataNotOnOrAfter}',
127
- StatusCode: '{StatusCode}',
128
- },
129
- xmlTag: {
130
- loginRequest: 'AuthnRequest',
131
- logoutRequest: 'LogoutRequest',
132
- loginResponse: 'Response',
133
- logoutResponse: 'LogoutResponse',
134
- },
135
- };
136
-
137
- const messageConfigurations = {
138
- signingOrder: {
139
- SIGN_THEN_ENCRYPT: 'sign-then-encrypt',
140
- ENCRYPT_THEN_SIGN: 'encrypt-then-sign',
141
- },
142
- };
143
-
144
- const algorithms = {
145
- signature: {
146
- RSA_SHA1: 'http://www.w3.org/2000/09/xmldsig#rsa-sha1',
147
- RSA_SHA256: 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256',
148
- RSA_SHA512: 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512',
149
- },
150
- encryption: {
151
- data: {
152
- AES_128: 'http://www.w3.org/2001/04/xmlenc#aes128-cbc',
153
- AES_256: 'http://www.w3.org/2001/04/xmlenc#aes256-cbc',
154
- AES_256_GCM: 'http://www.w3.org/2009/xmlenc11#aes256-gcm',
155
- TRI_DEC: 'http://www.w3.org/2001/04/xmlenc#tripledes-cbc',
156
- AES_128_GCM: 'http://www.w3.org/2009/xmlenc11#aes128-gcm'
157
- },
158
- key: {
159
- RSA_OAEP_MGF1P: 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p',
160
- RSA_1_5: 'http://www.w3.org/2001/04/xmlenc#rsa-1_5',
161
- },
162
- },
163
- digest: {
164
- 'http://www.w3.org/2000/09/xmldsig#rsa-sha1': 'http://www.w3.org/2000/09/xmldsig#sha1',
165
- 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256': 'http://www.w3.org/2001/04/xmlenc#sha256',
166
- 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512': 'http://www.w3.org/2001/04/xmlenc#sha512', // support hashing algorithm sha512 in xml-crypto after 0.8.0
167
- },
168
- };
169
-
170
- export enum ParserType {
171
- SAMLRequest = 'SAMLRequest',
172
- SAMLResponse = 'SAMLResponse',
173
- LogoutRequest = 'LogoutRequest',
174
- LogoutResponse = 'LogoutResponse'
175
- }
176
-
177
- const wording = {
178
- urlParams: {
179
- samlRequest: 'SAMLRequest',
180
- samlResponse: 'SAMLResponse',
181
- logoutRequest: 'LogoutRequest',
182
- logoutResponse: 'LogoutResponse',
183
- sigAlg: 'SigAlg',
184
- signature: 'Signature',
185
- relayState: 'RelayState',
186
- },
187
- binding: {
188
- redirect: 'redirect',
189
- post: 'post',
190
- simpleSign: 'simpleSign',
191
- artifact: 'artifact',
192
- },
193
- certUse: {
194
- signing: 'signing',
195
- encrypt: 'encryption',
196
- },
197
- metadata: {
198
- sp: 'metadata-sp',
199
- idp: 'metadata-idp',
200
- },
201
- };
202
-
203
- // https://wiki.shibboleth.net/confluence/display/CONCEPT/MetadataForSP
204
- // some idps restrict the order of elements in entity descriptors
205
- const elementsOrder = {
206
- default: ['KeyDescriptor', 'NameIDFormat', 'SingleLogoutService', 'AssertionConsumerService','AttributeConsumingService'],
207
- onelogin: ['KeyDescriptor', 'NameIDFormat', 'SingleLogoutService', 'AssertionConsumerService','AttributeConsumingService'],
208
- shibboleth: ['KeyDescriptor', 'SingleLogoutService', 'NameIDFormat', 'AssertionConsumerService', 'AttributeConsumingService'],
209
- };
210
-
211
- export { namespace, tags, algorithms, wording, elementsOrder, messageConfigurations };
package/src/utility.ts DELETED
@@ -1,319 +0,0 @@
1
- /**
2
- * @file utility.ts
3
- * @author tngan
4
- * @desc Library for some common functions (e.g. de/inflation, en/decoding)
5
- */
6
-
7
- import {X509Certificate,createPrivateKey } from 'node:crypto';
8
-
9
-
10
- import {inflate, deflate} from 'pako';
11
-
12
- const BASE64_STR = 'base64';
13
-
14
- /**
15
- * @desc Mimic lodash.zipObject
16
- * @param arr1 {string[]}
17
- * @param arr2 {[]}
18
- */
19
- export function zipObject(arr1: string[], arr2: any[], skipDuplicated = true) {
20
- return arr1.reduce((res, l, i) => {
21
-
22
- if (skipDuplicated) {
23
- res[l] = arr2[i];
24
- return res;
25
- }
26
- // if key exists, aggregate with array in order to get rid of duplicate key
27
- if (res[l] !== undefined) {
28
- res[l] = Array.isArray(res[l])
29
- ? res[l].concat(arr2[i])
30
- : [res[l]].concat(arr2[i]);
31
- return res;
32
- }
33
-
34
- res[l] = arr2[i];
35
- return res;
36
-
37
- }, {});
38
- }
39
-
40
- /**
41
- * @desc Alternative to lodash.flattenDeep
42
- * @reference https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_flattendeep
43
- * @param input {[]}
44
- */
45
- export function flattenDeep(input: any[]) {
46
- return Array.isArray(input)
47
- ? input.reduce((a, b) => a.concat(flattenDeep(b)), [])
48
- : [input];
49
- }
50
-
51
- /**
52
- * @desc Alternative to lodash.last
53
- * @reference https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_last
54
- * @param input {[]}
55
- */
56
- export function last(input: any[]) {
57
- return input.slice(-1)[0];
58
- }
59
-
60
- /**
61
- * @desc Alternative to lodash.uniq
62
- * @reference https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_uniq
63
- * @param input {string[]}
64
- */
65
- export function uniq(input: string[]) {
66
- const set = new Set(input);
67
- return [...set];
68
- }
69
-
70
- /**
71
- * @desc Alternative to lodash.get
72
- * @reference https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_get
73
- * @param obj
74
- * @param path
75
- * @param defaultValue
76
- */
77
- export function get(obj, path, defaultValue) {
78
- return path.split('.')
79
- .reduce((a, c) => (a && a[c] ? a[c] : (defaultValue || null)), obj);
80
- }
81
-
82
- /**
83
- * @desc Check if the input is string
84
- * @param {any} input
85
- */
86
- export function isString(input: any) {
87
- return typeof input === 'string';
88
- }
89
-
90
- /**
91
- * @desc Encode string with base64 format
92
- * @param {string} message plain-text message
93
- * @return {string} base64 encoded string
94
- */
95
- function base64Encode(message: string | number[]) {
96
- return Buffer.from(message as string).toString(BASE64_STR);
97
- }
98
-
99
- /**
100
- * @desc Decode string from base64 format
101
- * @param {string} base64Message encoded string
102
- * @param {boolean} isBytes determine the return value type (True: bytes False: string)
103
- * @return {bytes/string} decoded bytes/string depends on isBytes, default is {string}
104
- */
105
- export function base64Decode(base64Message: string, isBytes?: boolean): string | Buffer {
106
- const bytes = Buffer.from(base64Message, BASE64_STR);
107
- return Boolean(isBytes) ? bytes : bytes.toString();
108
- }
109
-
110
- /**
111
- * @desc Compress the string
112
- * @param {string} message
113
- * @return {string} compressed string
114
- */
115
- function deflateString(message: string): number[] {
116
- const input = Array.prototype.map.call(message, char => char.charCodeAt(0));
117
- return Array.from(deflate(input, {raw: true}));
118
- }
119
-
120
- /**
121
- * @desc Decompress the compressed string
122
- * @param {string} compressedString
123
- * @return {string} decompressed string
124
- */
125
- export function inflateString(compressedString: string): string {
126
- const inputBuffer = Buffer.from(compressedString, BASE64_STR);
127
- const input = Array.prototype.map.call(inputBuffer.toString('binary'), char => char.charCodeAt(0));
128
- return Array.from(inflate(input, {raw: true}))
129
- .map((byte: number) => String.fromCharCode(byte))
130
- .join('');
131
- }
132
-
133
- /**
134
- * @desc Abstract the normalizeCerString and normalizePemString
135
- * @param {buffer} File stream or string
136
- * @param {string} String for header and tail
137
- * @return {string} A formatted certificate string
138
- */
139
- function _normalizeCerString(bin: string | Buffer, format: string) {
140
- return bin.toString().replace(/\n/g, '').replace(/\r/g, '').replace(`-----BEGIN ${format}-----`, '').replace(`-----END ${format}-----`, '').replace(/ /g, '').replace(/\t/g, '');
141
- }
142
-
143
- /**
144
- * @desc Parse the .cer to string format without line break, header and footer
145
- * @param {string} certString declares the certificate contents
146
- * @return {string} certificiate in string format
147
- */
148
- function normalizeCerString(certString: string | Buffer) {
149
- return _normalizeCerString(certString, 'CERTIFICATE');
150
- }
151
-
152
- /**
153
- * @desc Normalize the string in .pem format without line break, header and footer
154
- * @param {string} pemString
155
- * @return {string} private key in string format
156
- */
157
- function normalizePemString(pemString: string | Buffer) {
158
- return _normalizeCerString(pemString.toString(), 'RSA PRIVATE KEY');
159
- }
160
-
161
- /**
162
- * @desc Return the complete URL
163
- * @param {object} req HTTP request
164
- * @return {string} URL
165
- */
166
- function getFullURL(req) {
167
- return `${req.protocol}://${req.get('host')}${req.originalUrl}`;
168
- }
169
-
170
- /**
171
- * @desc Parse input string, return default value if it is undefined
172
- * @param {string/boolean}
173
- * @return {boolean}
174
- */
175
- function parseString(str, defaultValue = '') {
176
- return str || defaultValue;
177
- }
178
-
179
- /**
180
- * @desc Override the object by another object (rtl)
181
- * @param {object} default object
182
- * @param {object} object applied to the default object
183
- * @return {object} result object
184
- */
185
- function applyDefault(obj1, obj2) {
186
- return Object.assign({}, obj1, obj2);
187
- }
188
-
189
- /**
190
- * @desc Get public key in pem format from the certificate included in the metadata
191
- * @param {string} x509 certificate
192
- * @return {string} public key fetched from the certificate
193
- */
194
- function getPublicKeyPemFromCertificate(x509CertificateString: string) {
195
- const derBuffer = Buffer.from(x509CertificateString, 'base64');
196
- // 解析 X.509 证书
197
- const cert2 = new X509Certificate(derBuffer);
198
- const publicKeyObject = cert2.publicKey
199
- // 3. 导出为 PEM 格式
200
- return publicKeyObject.export({
201
- type: 'spki', // 使用 Subject Public Key Info 结构
202
- format: 'pem' // 输出 PEM 格式
203
- });
204
-
205
- }
206
-
207
-
208
- /*function getPublicKeyPemFromCertificate(x509Certificate: string): string {
209
- // 将 Base64 字符串转为 Buffer(DER 编码)
210
- const derBuffer = Buffer.from(x509Certificate, 'base64');
211
-
212
- // 解析 X.509 证书
213
- const cert = new X509Certificate(derBuffer);
214
-
215
- // 直接获取公钥的 PEM 格式
216
- console.log(cert.publicKey?.toString())
217
- console.log("这就是我的打印")
218
- return cert.publicKey?.toString();
219
- }*/
220
- /**
221
- * @desc Read private key from pem-formatted string
222
- * @param {string | Buffer} keyString pem-formatted string
223
- * @param {string} protected passphrase of the key
224
- * @return {string} string in pem format
225
- * If passphrase is used to protect the .pem content (recommend)
226
- */
227
-
228
- /**
229
- * PEM 头尾格式校验与修复
230
- */
231
- function validatePEMHeaders(pem: string, keyType: string): string {
232
- const expectedHeader = `-----BEGIN ${keyType}-----`;
233
- const expectedFooter = `-----END ${keyType}-----`;
234
-
235
- // 自动修复不规范的 PEM 头尾
236
- return pem
237
- .replace(/-{5}.*PRIVATE KEY-{5}/g, '') // 清除已有头尾
238
- .replace(/(\r\n|\n|\r)/gm, '\n') // 统一换行符
239
- .trim() + // 清理空白
240
- `\n${expectedHeader}\n${pem}\n${expectedFooter}\n`;
241
- }
242
- export function readPrivateKey(
243
- keyString: string | Buffer,
244
- passphrase?: string,
245
- isOutputString: boolean = true
246
- ): string | Buffer {
247
- try {
248
- // 统一转换为字符串格式处理
249
- const pemKey = Buffer.isBuffer(keyString)
250
- ? keyString.toString('utf8')
251
- : keyString;
252
-
253
- // 创建私钥对象 (自动处理加密)
254
- const keyObject = createPrivateKey({
255
- key: pemKey,
256
- format: 'pem',
257
- passphrase: isString(passphrase) ? passphrase : undefined,
258
- encoding: 'utf8'
259
- });
260
-
261
- // 验证密钥类型为 RSA
262
- if (keyObject.asymmetricKeyType !== 'rsa') {
263
- throw new Error('仅支持 RSA 私钥类型');
264
- }
265
-
266
- // 强制转换为 PKCS#1 格式
267
- const exported = keyObject.export({
268
- type: 'pkcs1', // 明确指定 RSA 传统格式
269
- format: 'pem' // 输出为 PEM 格式
270
- }) as string;
271
-
272
- return isOutputString ? String(exported) : Buffer.from(exported, 'utf8');
273
- } catch (error) {
274
- throw new Error(`私钥读取失败: ${error.message}`);
275
- }
276
- }
277
-
278
-
279
- /**
280
- * @desc Inline syntax sugar
281
- */
282
- function convertToString(input, isOutputString) {
283
- return Boolean(isOutputString) ? String(input) : input;
284
- }
285
-
286
- /**
287
- * @desc Check if the input is an array with non-zero size
288
- */
289
- export function isNonEmptyArray(a: any) {
290
- return Array.isArray(a) && a.length > 0;
291
- }
292
-
293
- export function castArrayOpt<T>(a?: T | T[]): T[] {
294
- if (a === undefined) return []
295
- return Array.isArray(a) ? a : [a]
296
- }
297
-
298
- export function notEmpty<TValue>(value: TValue | null | undefined): value is TValue {
299
- return value !== null && value !== undefined;
300
- }
301
-
302
- const utility = {
303
- isString,
304
- base64Encode,
305
- base64Decode,
306
- deflateString,
307
- inflateString,
308
- normalizeCerString,
309
- normalizePemString,
310
- getFullURL,
311
- parseString,
312
- applyDefault,
313
- getPublicKeyPemFromCertificate,
314
- readPrivateKey,
315
- convertToString,
316
- isNonEmptyArray,
317
- };
318
-
319
- export default utility;