pixel-react 1.15.21 → 1.15.23

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.
Files changed (208) hide show
  1. package/lib/_virtual/aesCipherSuites.js +4 -0
  2. package/lib/_virtual/aesCipherSuites.js.map +1 -0
  3. package/lib/_virtual/asn1-validator.js +4 -0
  4. package/lib/_virtual/asn1-validator.js.map +1 -0
  5. package/lib/_virtual/asn1.js +4 -0
  6. package/lib/_virtual/asn1.js.map +1 -0
  7. package/lib/_virtual/cipherModes.js +4 -0
  8. package/lib/_virtual/cipherModes.js.map +1 -0
  9. package/lib/_virtual/hmac.js +4 -0
  10. package/lib/_virtual/hmac.js.map +1 -0
  11. package/lib/_virtual/index11.js +2 -2
  12. package/lib/_virtual/index12.js +2 -2
  13. package/lib/_virtual/index13.js +2 -2
  14. package/lib/_virtual/index14.js +4 -0
  15. package/lib/_virtual/index14.js.map +1 -0
  16. package/lib/_virtual/index2.js +5 -3
  17. package/lib/_virtual/index2.js.map +1 -1
  18. package/lib/_virtual/index3.js +4 -2
  19. package/lib/_virtual/index3.js.map +1 -1
  20. package/lib/_virtual/index4.js +2 -4
  21. package/lib/_virtual/index4.js.map +1 -1
  22. package/lib/_virtual/index5.js +4 -2
  23. package/lib/_virtual/index5.js.map +1 -1
  24. package/lib/_virtual/index6.js +2 -2
  25. package/lib/_virtual/index7.js +2 -6
  26. package/lib/_virtual/index7.js.map +1 -1
  27. package/lib/_virtual/index8.js +6 -2
  28. package/lib/_virtual/index8.js.map +1 -1
  29. package/lib/_virtual/index9.js +2 -2
  30. package/lib/_virtual/md5.js +4 -0
  31. package/lib/_virtual/md5.js.map +1 -0
  32. package/lib/_virtual/mgf1.js +4 -0
  33. package/lib/_virtual/mgf1.js.map +1 -0
  34. package/lib/_virtual/oids.js +4 -0
  35. package/lib/_virtual/oids.js.map +1 -0
  36. package/lib/_virtual/pem.js +4 -0
  37. package/lib/_virtual/pem.js.map +1 -0
  38. package/lib/_virtual/pkcs1.js +4 -0
  39. package/lib/_virtual/pkcs1.js.map +1 -0
  40. package/lib/_virtual/pkcs12.js +4 -0
  41. package/lib/_virtual/pkcs12.js.map +1 -0
  42. package/lib/_virtual/pkcs7.js +4 -0
  43. package/lib/_virtual/pkcs7.js.map +1 -0
  44. package/lib/_virtual/pkcs7asn1.js +4 -0
  45. package/lib/_virtual/pkcs7asn1.js.map +1 -0
  46. package/lib/_virtual/pki.js +4 -0
  47. package/lib/_virtual/pki.js.map +1 -0
  48. package/lib/_virtual/prime.js +4 -0
  49. package/lib/_virtual/prime.js.map +1 -0
  50. package/lib/_virtual/prng.js +4 -0
  51. package/lib/_virtual/prng.js.map +1 -0
  52. package/lib/_virtual/pss.js +4 -0
  53. package/lib/_virtual/pss.js.map +1 -0
  54. package/lib/_virtual/random.js +4 -0
  55. package/lib/_virtual/random.js.map +1 -0
  56. package/lib/_virtual/sha1.js +4 -0
  57. package/lib/_virtual/sha1.js.map +1 -0
  58. package/lib/_virtual/sha256.js +4 -0
  59. package/lib/_virtual/sha256.js.map +1 -0
  60. package/lib/_virtual/sha512.js +4 -0
  61. package/lib/_virtual/sha512.js.map +1 -0
  62. package/lib/_virtual/ssh.js +4 -0
  63. package/lib/_virtual/ssh.js.map +1 -0
  64. package/lib/_virtual/util.js +4 -0
  65. package/lib/_virtual/util.js.map +1 -0
  66. package/lib/_virtual/x509.js +4 -0
  67. package/lib/_virtual/x509.js.map +1 -0
  68. package/lib/assets/icons/testify_icon.svg.js +6 -0
  69. package/lib/assets/icons/testify_icon.svg.js.map +1 -0
  70. package/lib/assets/icons/testify_loader.svg.js +6 -0
  71. package/lib/assets/icons/testify_loader.svg.js.map +1 -0
  72. package/lib/assets/icons/testify_logo_name.svg.js +6 -0
  73. package/lib/assets/icons/testify_logo_name.svg.js.map +1 -0
  74. package/lib/components/AllProjectsDropdown/AllProjectsDropdown.js +3 -1
  75. package/lib/components/AllProjectsDropdown/AllProjectsDropdown.js.map +1 -1
  76. package/lib/components/Charts/DashboardDonutChart/DashboardDonutChart.js +2 -9
  77. package/lib/components/Charts/DashboardDonutChart/DashboardDonutChart.js.map +1 -1
  78. package/lib/components/Charts/DashboardDonutChart/types.d.ts +1 -1
  79. package/lib/components/ConditionalDropdown/ConditionalDropdown.js +2 -9
  80. package/lib/components/ConditionalDropdown/ConditionalDropdown.js.map +1 -1
  81. package/lib/components/Editor/Editor.js +37 -17
  82. package/lib/components/Editor/Editor.js.map +1 -1
  83. package/lib/components/Icon/iconList.js +6 -0
  84. package/lib/components/Icon/iconList.js.map +1 -1
  85. package/lib/components/MultiSelect/MultiSelect.js +9 -10
  86. package/lib/components/MultiSelect/MultiSelect.js.map +1 -1
  87. package/lib/components/PhoneInput/PhoneInput.js +1 -0
  88. package/lib/components/PhoneInput/PhoneInput.js.map +1 -1
  89. package/lib/components/SessionDropdown/SessionDropdown.js +4 -2
  90. package/lib/components/SessionDropdown/SessionDropdown.js.map +1 -1
  91. package/lib/index.cjs +27423 -379
  92. package/lib/index.cjs.map +1 -1
  93. package/lib/index.d.ts +1 -1
  94. package/lib/node_modules/classnames/index.js +1 -1
  95. package/lib/node_modules/input-format/modules/react/Input.js +1 -1
  96. package/lib/node_modules/js-beautify/js/index.js +1 -1
  97. package/lib/node_modules/js-beautify/js/src/html/beautifier.js +1 -1
  98. package/lib/node_modules/js-beautify/js/src/html/index.js +1 -1
  99. package/lib/node_modules/js-beautify/js/src/html/options.js +1 -1
  100. package/lib/node_modules/js-beautify/js/src/html/tokenizer.js +1 -1
  101. package/lib/node_modules/js-beautify/js/src/index.js +1 -1
  102. package/lib/node_modules/js-beautify/js/src/javascript/beautifier.js +1 -1
  103. package/lib/node_modules/js-beautify/js/src/javascript/index.js +1 -1
  104. package/lib/node_modules/js-beautify/js/src/javascript/options.js +1 -1
  105. package/lib/node_modules/js-beautify/js/src/javascript/tokenizer.js +1 -1
  106. package/lib/node_modules/node-forge/lib/aes.js +1014 -0
  107. package/lib/node_modules/node-forge/lib/aes.js.map +1 -0
  108. package/lib/node_modules/node-forge/lib/aesCipherSuites.js +286 -0
  109. package/lib/node_modules/node-forge/lib/aesCipherSuites.js.map +1 -0
  110. package/lib/node_modules/node-forge/lib/asn1-validator.js +100 -0
  111. package/lib/node_modules/node-forge/lib/asn1-validator.js.map +1 -0
  112. package/lib/node_modules/node-forge/lib/asn1.js +1379 -0
  113. package/lib/node_modules/node-forge/lib/asn1.js.map +1 -0
  114. package/lib/node_modules/node-forge/lib/baseN.js +181 -0
  115. package/lib/node_modules/node-forge/lib/baseN.js.map +1 -0
  116. package/lib/node_modules/node-forge/lib/cipher.js +236 -0
  117. package/lib/node_modules/node-forge/lib/cipher.js.map +1 -0
  118. package/lib/node_modules/node-forge/lib/cipherModes.js +936 -0
  119. package/lib/node_modules/node-forge/lib/cipherModes.js.map +1 -0
  120. package/lib/node_modules/node-forge/lib/des.js +467 -0
  121. package/lib/node_modules/node-forge/lib/des.js.map +1 -0
  122. package/lib/node_modules/node-forge/lib/ed25519.js +1108 -0
  123. package/lib/node_modules/node-forge/lib/ed25519.js.map +1 -0
  124. package/lib/node_modules/node-forge/lib/forge.js +23 -0
  125. package/lib/node_modules/node-forge/lib/forge.js.map +1 -0
  126. package/lib/node_modules/node-forge/lib/hmac.js +158 -0
  127. package/lib/node_modules/node-forge/lib/hmac.js.map +1 -0
  128. package/lib/node_modules/node-forge/lib/index.js +70 -0
  129. package/lib/node_modules/node-forge/lib/index.js.map +1 -0
  130. package/lib/node_modules/node-forge/lib/jsbn.js +1481 -0
  131. package/lib/node_modules/node-forge/lib/jsbn.js.map +1 -0
  132. package/lib/node_modules/node-forge/lib/kem.js +178 -0
  133. package/lib/node_modules/node-forge/lib/kem.js.map +1 -0
  134. package/lib/node_modules/node-forge/lib/log.js +325 -0
  135. package/lib/node_modules/node-forge/lib/log.js.map +1 -0
  136. package/lib/node_modules/node-forge/lib/md.all.js +28 -0
  137. package/lib/node_modules/node-forge/lib/md.all.js.map +1 -0
  138. package/lib/node_modules/node-forge/lib/md.js +22 -0
  139. package/lib/node_modules/node-forge/lib/md.js.map +1 -0
  140. package/lib/node_modules/node-forge/lib/md5.js +288 -0
  141. package/lib/node_modules/node-forge/lib/md5.js.map +1 -0
  142. package/lib/node_modules/node-forge/lib/mgf.js +24 -0
  143. package/lib/node_modules/node-forge/lib/mgf.js.map +1 -0
  144. package/lib/node_modules/node-forge/lib/mgf1.js +68 -0
  145. package/lib/node_modules/node-forge/lib/mgf1.js.map +1 -0
  146. package/lib/node_modules/node-forge/lib/oids.js +185 -0
  147. package/lib/node_modules/node-forge/lib/oids.js.map +1 -0
  148. package/lib/node_modules/node-forge/lib/pbe.js +966 -0
  149. package/lib/node_modules/node-forge/lib/pbe.js.map +1 -0
  150. package/lib/node_modules/node-forge/lib/pbkdf2.js +209 -0
  151. package/lib/node_modules/node-forge/lib/pbkdf2.js.map +1 -0
  152. package/lib/node_modules/node-forge/lib/pem.js +250 -0
  153. package/lib/node_modules/node-forge/lib/pem.js.map +1 -0
  154. package/lib/node_modules/node-forge/lib/pkcs1.js +273 -0
  155. package/lib/node_modules/node-forge/lib/pkcs1.js.map +1 -0
  156. package/lib/node_modules/node-forge/lib/pkcs12.js +980 -0
  157. package/lib/node_modules/node-forge/lib/pkcs12.js.map +1 -0
  158. package/lib/node_modules/node-forge/lib/pkcs7.js +1073 -0
  159. package/lib/node_modules/node-forge/lib/pkcs7.js.map +1 -0
  160. package/lib/node_modules/node-forge/lib/pkcs7asn1.js +415 -0
  161. package/lib/node_modules/node-forge/lib/pkcs7asn1.js.map +1 -0
  162. package/lib/node_modules/node-forge/lib/pki.js +125 -0
  163. package/lib/node_modules/node-forge/lib/pki.js.map +1 -0
  164. package/lib/node_modules/node-forge/lib/prime.js +297 -0
  165. package/lib/node_modules/node-forge/lib/prime.js.map +1 -0
  166. package/lib/node_modules/node-forge/lib/prng.js +433 -0
  167. package/lib/node_modules/node-forge/lib/prng.js.map +1 -0
  168. package/lib/node_modules/node-forge/lib/pss.js +246 -0
  169. package/lib/node_modules/node-forge/lib/pss.js.map +1 -0
  170. package/lib/node_modules/node-forge/lib/random.js +191 -0
  171. package/lib/node_modules/node-forge/lib/random.js.map +1 -0
  172. package/lib/node_modules/node-forge/lib/rc2.js +382 -0
  173. package/lib/node_modules/node-forge/lib/rc2.js.map +1 -0
  174. package/lib/node_modules/node-forge/lib/rsa.js +1815 -0
  175. package/lib/node_modules/node-forge/lib/rsa.js.map +1 -0
  176. package/lib/node_modules/node-forge/lib/sha1.js +325 -0
  177. package/lib/node_modules/node-forge/lib/sha1.js.map +1 -0
  178. package/lib/node_modules/node-forge/lib/sha256.js +306 -0
  179. package/lib/node_modules/node-forge/lib/sha256.js.map +1 -0
  180. package/lib/node_modules/node-forge/lib/sha512.js +479 -0
  181. package/lib/node_modules/node-forge/lib/sha512.js.map +1 -0
  182. package/lib/node_modules/node-forge/lib/ssh.js +244 -0
  183. package/lib/node_modules/node-forge/lib/ssh.js.map +1 -0
  184. package/lib/node_modules/node-forge/lib/tls.js +4207 -0
  185. package/lib/node_modules/node-forge/lib/tls.js.map +1 -0
  186. package/lib/node_modules/node-forge/lib/util.js +2565 -0
  187. package/lib/node_modules/node-forge/lib/util.js.map +1 -0
  188. package/lib/node_modules/node-forge/lib/x509.js +2986 -0
  189. package/lib/node_modules/node-forge/lib/x509.js.map +1 -0
  190. package/lib/node_modules/prop-types/index.js +1 -1
  191. package/lib/node_modules/react-async-script/lib/esm/async-script-loader.js +1 -1
  192. package/lib/node_modules/react-google-recaptcha/lib/esm/recaptcha.js +1 -1
  193. package/lib/node_modules/react-is/index.js +1 -1
  194. package/lib/node_modules/react-phone-number-input/modules/CountryIcon.js +1 -1
  195. package/lib/node_modules/react-phone-number-input/modules/CountrySelect.js +1 -1
  196. package/lib/node_modules/react-phone-number-input/modules/Flag.js +1 -1
  197. package/lib/node_modules/react-phone-number-input/modules/InputBasic.js +1 -1
  198. package/lib/node_modules/react-phone-number-input/modules/InputSmart.js +1 -1
  199. package/lib/node_modules/react-phone-number-input/modules/InternationalIcon.js +1 -1
  200. package/lib/node_modules/react-phone-number-input/modules/PhoneInputWithCountry.js +1 -1
  201. package/lib/node_modules/react-phone-number-input/modules/PropTypes.js +1 -1
  202. package/lib/node_modules/scheduler/index.js +1 -1
  203. package/lib/node_modules/use-context-selector/dist/index.js +1 -1
  204. package/lib/styles.css +1 -1
  205. package/lib/styles.css.map +1 -1
  206. package/lib/utils/getEncryptedData/getEncryptedData.js +10 -13
  207. package/lib/utils/getEncryptedData/getEncryptedData.js.map +1 -1
  208. package/package.json +3 -1
@@ -0,0 +1,980 @@
1
+ import { __module as pkcs12 } from '../../../_virtual/pkcs12.js';
2
+ import { __require as requireForge } from './forge.js';
3
+ import { __require as requireAsn1 } from './asn1.js';
4
+ import { __require as requireHmac } from './hmac.js';
5
+ import { __require as requireOids } from './oids.js';
6
+ import { __require as requirePkcs7asn1 } from './pkcs7asn1.js';
7
+ import { __require as requirePbe } from './pbe.js';
8
+ import { __require as requireRandom } from './random.js';
9
+ import { __require as requireRsa } from './rsa.js';
10
+ import { __require as requireSha1 } from './sha1.js';
11
+ import { __require as requireUtil } from './util.js';
12
+ import { __require as requireX509 } from './x509.js';
13
+
14
+ /**
15
+ * Javascript implementation of PKCS#12.
16
+ *
17
+ * @author Dave Longley
18
+ * @author Stefan Siegl <stesie@brokenpipe.de>
19
+ *
20
+ * Copyright (c) 2010-2014 Digital Bazaar, Inc.
21
+ * Copyright (c) 2012 Stefan Siegl <stesie@brokenpipe.de>
22
+ *
23
+ * The ASN.1 representation of PKCS#12 is as follows
24
+ * (see ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-12/pkcs-12-tc1.pdf for details)
25
+ *
26
+ * PFX ::= SEQUENCE {
27
+ * version INTEGER {v3(3)}(v3,...),
28
+ * authSafe ContentInfo,
29
+ * macData MacData OPTIONAL
30
+ * }
31
+ *
32
+ * MacData ::= SEQUENCE {
33
+ * mac DigestInfo,
34
+ * macSalt OCTET STRING,
35
+ * iterations INTEGER DEFAULT 1
36
+ * }
37
+ * Note: The iterations default is for historical reasons and its use is
38
+ * deprecated. A higher value, like 1024, is recommended.
39
+ *
40
+ * DigestInfo is defined in PKCS#7 as follows:
41
+ *
42
+ * DigestInfo ::= SEQUENCE {
43
+ * digestAlgorithm DigestAlgorithmIdentifier,
44
+ * digest Digest
45
+ * }
46
+ *
47
+ * DigestAlgorithmIdentifier ::= AlgorithmIdentifier
48
+ *
49
+ * The AlgorithmIdentifier contains an Object Identifier (OID) and parameters
50
+ * for the algorithm, if any. In the case of SHA1 there is none.
51
+ *
52
+ * AlgorithmIdentifer ::= SEQUENCE {
53
+ * algorithm OBJECT IDENTIFIER,
54
+ * parameters ANY DEFINED BY algorithm OPTIONAL
55
+ * }
56
+ *
57
+ * Digest ::= OCTET STRING
58
+ *
59
+ *
60
+ * ContentInfo ::= SEQUENCE {
61
+ * contentType ContentType,
62
+ * content [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL
63
+ * }
64
+ *
65
+ * ContentType ::= OBJECT IDENTIFIER
66
+ *
67
+ * AuthenticatedSafe ::= SEQUENCE OF ContentInfo
68
+ * -- Data if unencrypted
69
+ * -- EncryptedData if password-encrypted
70
+ * -- EnvelopedData if public key-encrypted
71
+ *
72
+ *
73
+ * SafeContents ::= SEQUENCE OF SafeBag
74
+ *
75
+ * SafeBag ::= SEQUENCE {
76
+ * bagId BAG-TYPE.&id ({PKCS12BagSet})
77
+ * bagValue [0] EXPLICIT BAG-TYPE.&Type({PKCS12BagSet}{@bagId}),
78
+ * bagAttributes SET OF PKCS12Attribute OPTIONAL
79
+ * }
80
+ *
81
+ * PKCS12Attribute ::= SEQUENCE {
82
+ * attrId ATTRIBUTE.&id ({PKCS12AttrSet}),
83
+ * attrValues SET OF ATTRIBUTE.&Type ({PKCS12AttrSet}{@attrId})
84
+ * } -- This type is compatible with the X.500 type 'Attribute'
85
+ *
86
+ * PKCS12AttrSet ATTRIBUTE ::= {
87
+ * friendlyName | -- from PKCS #9
88
+ * localKeyId, -- from PKCS #9
89
+ * ... -- Other attributes are allowed
90
+ * }
91
+ *
92
+ * CertBag ::= SEQUENCE {
93
+ * certId BAG-TYPE.&id ({CertTypes}),
94
+ * certValue [0] EXPLICIT BAG-TYPE.&Type ({CertTypes}{@certId})
95
+ * }
96
+ *
97
+ * x509Certificate BAG-TYPE ::= {OCTET STRING IDENTIFIED BY {certTypes 1}}
98
+ * -- DER-encoded X.509 certificate stored in OCTET STRING
99
+ *
100
+ * sdsiCertificate BAG-TYPE ::= {IA5String IDENTIFIED BY {certTypes 2}}
101
+ * -- Base64-encoded SDSI certificate stored in IA5String
102
+ *
103
+ * CertTypes BAG-TYPE ::= {
104
+ * x509Certificate |
105
+ * sdsiCertificate,
106
+ * ... -- For future extensions
107
+ * }
108
+ */
109
+ var hasRequiredPkcs12;
110
+ function requirePkcs12() {
111
+ if (hasRequiredPkcs12) return pkcs12.exports;
112
+ hasRequiredPkcs12 = 1;
113
+ var forge = requireForge();
114
+ requireAsn1();
115
+ requireHmac();
116
+ requireOids();
117
+ requirePkcs7asn1();
118
+ requirePbe();
119
+ requireRandom();
120
+ requireRsa();
121
+ requireSha1();
122
+ requireUtil();
123
+ requireX509();
124
+
125
+ // shortcut for asn.1 & PKI API
126
+ var asn1 = forge.asn1;
127
+ var pki = forge.pki;
128
+
129
+ // shortcut for PKCS#12 API
130
+ var p12 = pkcs12.exports = forge.pkcs12 = forge.pkcs12 || {};
131
+ var contentInfoValidator = {
132
+ name: 'ContentInfo',
133
+ tagClass: asn1.Class.UNIVERSAL,
134
+ type: asn1.Type.SEQUENCE,
135
+ // a ContentInfo
136
+ constructed: true,
137
+ value: [{
138
+ name: 'ContentInfo.contentType',
139
+ tagClass: asn1.Class.UNIVERSAL,
140
+ type: asn1.Type.OID,
141
+ constructed: false,
142
+ capture: 'contentType'
143
+ }, {
144
+ name: 'ContentInfo.content',
145
+ tagClass: asn1.Class.CONTEXT_SPECIFIC,
146
+ constructed: true,
147
+ captureAsn1: 'content'
148
+ }]
149
+ };
150
+ var pfxValidator = {
151
+ name: 'PFX',
152
+ tagClass: asn1.Class.UNIVERSAL,
153
+ type: asn1.Type.SEQUENCE,
154
+ constructed: true,
155
+ value: [{
156
+ name: 'PFX.version',
157
+ tagClass: asn1.Class.UNIVERSAL,
158
+ type: asn1.Type.INTEGER,
159
+ constructed: false,
160
+ capture: 'version'
161
+ }, contentInfoValidator, {
162
+ name: 'PFX.macData',
163
+ tagClass: asn1.Class.UNIVERSAL,
164
+ type: asn1.Type.SEQUENCE,
165
+ constructed: true,
166
+ optional: true,
167
+ captureAsn1: 'mac',
168
+ value: [{
169
+ name: 'PFX.macData.mac',
170
+ tagClass: asn1.Class.UNIVERSAL,
171
+ type: asn1.Type.SEQUENCE,
172
+ // DigestInfo
173
+ constructed: true,
174
+ value: [{
175
+ name: 'PFX.macData.mac.digestAlgorithm',
176
+ tagClass: asn1.Class.UNIVERSAL,
177
+ type: asn1.Type.SEQUENCE,
178
+ // DigestAlgorithmIdentifier
179
+ constructed: true,
180
+ value: [{
181
+ name: 'PFX.macData.mac.digestAlgorithm.algorithm',
182
+ tagClass: asn1.Class.UNIVERSAL,
183
+ type: asn1.Type.OID,
184
+ constructed: false,
185
+ capture: 'macAlgorithm'
186
+ }, {
187
+ name: 'PFX.macData.mac.digestAlgorithm.parameters',
188
+ tagClass: asn1.Class.UNIVERSAL,
189
+ captureAsn1: 'macAlgorithmParameters'
190
+ }]
191
+ }, {
192
+ name: 'PFX.macData.mac.digest',
193
+ tagClass: asn1.Class.UNIVERSAL,
194
+ type: asn1.Type.OCTETSTRING,
195
+ constructed: false,
196
+ capture: 'macDigest'
197
+ }]
198
+ }, {
199
+ name: 'PFX.macData.macSalt',
200
+ tagClass: asn1.Class.UNIVERSAL,
201
+ type: asn1.Type.OCTETSTRING,
202
+ constructed: false,
203
+ capture: 'macSalt'
204
+ }, {
205
+ name: 'PFX.macData.iterations',
206
+ tagClass: asn1.Class.UNIVERSAL,
207
+ type: asn1.Type.INTEGER,
208
+ constructed: false,
209
+ optional: true,
210
+ capture: 'macIterations'
211
+ }]
212
+ }]
213
+ };
214
+ var safeBagValidator = {
215
+ name: 'SafeBag',
216
+ tagClass: asn1.Class.UNIVERSAL,
217
+ type: asn1.Type.SEQUENCE,
218
+ constructed: true,
219
+ value: [{
220
+ name: 'SafeBag.bagId',
221
+ tagClass: asn1.Class.UNIVERSAL,
222
+ type: asn1.Type.OID,
223
+ constructed: false,
224
+ capture: 'bagId'
225
+ }, {
226
+ name: 'SafeBag.bagValue',
227
+ tagClass: asn1.Class.CONTEXT_SPECIFIC,
228
+ constructed: true,
229
+ captureAsn1: 'bagValue'
230
+ }, {
231
+ name: 'SafeBag.bagAttributes',
232
+ tagClass: asn1.Class.UNIVERSAL,
233
+ type: asn1.Type.SET,
234
+ constructed: true,
235
+ optional: true,
236
+ capture: 'bagAttributes'
237
+ }]
238
+ };
239
+ var attributeValidator = {
240
+ name: 'Attribute',
241
+ tagClass: asn1.Class.UNIVERSAL,
242
+ type: asn1.Type.SEQUENCE,
243
+ constructed: true,
244
+ value: [{
245
+ name: 'Attribute.attrId',
246
+ tagClass: asn1.Class.UNIVERSAL,
247
+ type: asn1.Type.OID,
248
+ constructed: false,
249
+ capture: 'oid'
250
+ }, {
251
+ name: 'Attribute.attrValues',
252
+ tagClass: asn1.Class.UNIVERSAL,
253
+ type: asn1.Type.SET,
254
+ constructed: true,
255
+ capture: 'values'
256
+ }]
257
+ };
258
+ var certBagValidator = {
259
+ name: 'CertBag',
260
+ tagClass: asn1.Class.UNIVERSAL,
261
+ type: asn1.Type.SEQUENCE,
262
+ constructed: true,
263
+ value: [{
264
+ name: 'CertBag.certId',
265
+ tagClass: asn1.Class.UNIVERSAL,
266
+ type: asn1.Type.OID,
267
+ constructed: false,
268
+ capture: 'certId'
269
+ }, {
270
+ name: 'CertBag.certValue',
271
+ tagClass: asn1.Class.CONTEXT_SPECIFIC,
272
+ constructed: true,
273
+ /* So far we only support X.509 certificates (which are wrapped in
274
+ an OCTET STRING, hence hard code that here). */
275
+ value: [{
276
+ name: 'CertBag.certValue[0]',
277
+ tagClass: asn1.Class.UNIVERSAL,
278
+ type: asn1.Class.OCTETSTRING,
279
+ constructed: false,
280
+ capture: 'cert'
281
+ }]
282
+ }]
283
+ };
284
+
285
+ /**
286
+ * Search SafeContents structure for bags with matching attributes.
287
+ *
288
+ * The search can optionally be narrowed by a certain bag type.
289
+ *
290
+ * @param safeContents the SafeContents structure to search in.
291
+ * @param attrName the name of the attribute to compare against.
292
+ * @param attrValue the attribute value to search for.
293
+ * @param [bagType] bag type to narrow search by.
294
+ *
295
+ * @return an array of matching bags.
296
+ */
297
+ function _getBagsByAttribute(safeContents, attrName, attrValue, bagType) {
298
+ var result = [];
299
+ for (var i = 0; i < safeContents.length; i++) {
300
+ for (var j = 0; j < safeContents[i].safeBags.length; j++) {
301
+ var bag = safeContents[i].safeBags[j];
302
+ if (bagType !== undefined && bag.type !== bagType) {
303
+ continue;
304
+ }
305
+ // only filter by bag type, no attribute specified
306
+ if (attrName === null) {
307
+ result.push(bag);
308
+ continue;
309
+ }
310
+ if (bag.attributes[attrName] !== undefined && bag.attributes[attrName].indexOf(attrValue) >= 0) {
311
+ result.push(bag);
312
+ }
313
+ }
314
+ }
315
+ return result;
316
+ }
317
+
318
+ /**
319
+ * Converts a PKCS#12 PFX in ASN.1 notation into a PFX object.
320
+ *
321
+ * @param obj The PKCS#12 PFX in ASN.1 notation.
322
+ * @param strict true to use strict DER decoding, false not to (default: true).
323
+ * @param {String} password Password to decrypt with (optional).
324
+ *
325
+ * @return PKCS#12 PFX object.
326
+ */
327
+ p12.pkcs12FromAsn1 = function (obj, strict, password) {
328
+ // handle args
329
+ if (typeof strict === 'string') {
330
+ password = strict;
331
+ strict = true;
332
+ } else if (strict === undefined) {
333
+ strict = true;
334
+ }
335
+
336
+ // validate PFX and capture data
337
+ var capture = {};
338
+ var errors = [];
339
+ if (!asn1.validate(obj, pfxValidator, capture, errors)) {
340
+ var error = new Error('Cannot read PKCS#12 PFX. ' + 'ASN.1 object is not an PKCS#12 PFX.');
341
+ error.errors = error;
342
+ throw error;
343
+ }
344
+ var pfx = {
345
+ version: capture.version.charCodeAt(0),
346
+ safeContents: [],
347
+ /**
348
+ * Gets bags with matching attributes.
349
+ *
350
+ * @param filter the attributes to filter by:
351
+ * [localKeyId] the localKeyId to search for.
352
+ * [localKeyIdHex] the localKeyId in hex to search for.
353
+ * [friendlyName] the friendly name to search for.
354
+ * [bagType] bag type to narrow each attribute search by.
355
+ *
356
+ * @return a map of attribute type to an array of matching bags or, if no
357
+ * attribute was given but a bag type, the map key will be the
358
+ * bag type.
359
+ */
360
+ getBags: function (filter) {
361
+ var rval = {};
362
+ var localKeyId;
363
+ if ('localKeyId' in filter) {
364
+ localKeyId = filter.localKeyId;
365
+ } else if ('localKeyIdHex' in filter) {
366
+ localKeyId = forge.util.hexToBytes(filter.localKeyIdHex);
367
+ }
368
+
369
+ // filter on bagType only
370
+ if (localKeyId === undefined && !('friendlyName' in filter) && 'bagType' in filter) {
371
+ rval[filter.bagType] = _getBagsByAttribute(pfx.safeContents, null, null, filter.bagType);
372
+ }
373
+ if (localKeyId !== undefined) {
374
+ rval.localKeyId = _getBagsByAttribute(pfx.safeContents, 'localKeyId', localKeyId, filter.bagType);
375
+ }
376
+ if ('friendlyName' in filter) {
377
+ rval.friendlyName = _getBagsByAttribute(pfx.safeContents, 'friendlyName', filter.friendlyName, filter.bagType);
378
+ }
379
+ return rval;
380
+ },
381
+ /**
382
+ * DEPRECATED: use getBags() instead.
383
+ *
384
+ * Get bags with matching friendlyName attribute.
385
+ *
386
+ * @param friendlyName the friendly name to search for.
387
+ * @param [bagType] bag type to narrow search by.
388
+ *
389
+ * @return an array of bags with matching friendlyName attribute.
390
+ */
391
+ getBagsByFriendlyName: function (friendlyName, bagType) {
392
+ return _getBagsByAttribute(pfx.safeContents, 'friendlyName', friendlyName, bagType);
393
+ },
394
+ /**
395
+ * DEPRECATED: use getBags() instead.
396
+ *
397
+ * Get bags with matching localKeyId attribute.
398
+ *
399
+ * @param localKeyId the localKeyId to search for.
400
+ * @param [bagType] bag type to narrow search by.
401
+ *
402
+ * @return an array of bags with matching localKeyId attribute.
403
+ */
404
+ getBagsByLocalKeyId: function (localKeyId, bagType) {
405
+ return _getBagsByAttribute(pfx.safeContents, 'localKeyId', localKeyId, bagType);
406
+ }
407
+ };
408
+ if (capture.version.charCodeAt(0) !== 3) {
409
+ var error = new Error('PKCS#12 PFX of version other than 3 not supported.');
410
+ error.version = capture.version.charCodeAt(0);
411
+ throw error;
412
+ }
413
+ if (asn1.derToOid(capture.contentType) !== pki.oids.data) {
414
+ var error = new Error('Only PKCS#12 PFX in password integrity mode supported.');
415
+ error.oid = asn1.derToOid(capture.contentType);
416
+ throw error;
417
+ }
418
+ var data = capture.content.value[0];
419
+ if (data.tagClass !== asn1.Class.UNIVERSAL || data.type !== asn1.Type.OCTETSTRING) {
420
+ throw new Error('PKCS#12 authSafe content data is not an OCTET STRING.');
421
+ }
422
+ data = _decodePkcs7Data(data);
423
+
424
+ // check for MAC
425
+ if (capture.mac) {
426
+ var md = null;
427
+ var macKeyBytes = 0;
428
+ var macAlgorithm = asn1.derToOid(capture.macAlgorithm);
429
+ switch (macAlgorithm) {
430
+ case pki.oids.sha1:
431
+ md = forge.md.sha1.create();
432
+ macKeyBytes = 20;
433
+ break;
434
+ case pki.oids.sha256:
435
+ md = forge.md.sha256.create();
436
+ macKeyBytes = 32;
437
+ break;
438
+ case pki.oids.sha384:
439
+ md = forge.md.sha384.create();
440
+ macKeyBytes = 48;
441
+ break;
442
+ case pki.oids.sha512:
443
+ md = forge.md.sha512.create();
444
+ macKeyBytes = 64;
445
+ break;
446
+ case pki.oids.md5:
447
+ md = forge.md.md5.create();
448
+ macKeyBytes = 16;
449
+ break;
450
+ }
451
+ if (md === null) {
452
+ throw new Error('PKCS#12 uses unsupported MAC algorithm: ' + macAlgorithm);
453
+ }
454
+
455
+ // verify MAC (iterations default to 1)
456
+ var macSalt = new forge.util.ByteBuffer(capture.macSalt);
457
+ var macIterations = 'macIterations' in capture ? parseInt(forge.util.bytesToHex(capture.macIterations), 16) : 1;
458
+ var macKey = p12.generateKey(password, macSalt, 3, macIterations, macKeyBytes, md);
459
+ var mac = forge.hmac.create();
460
+ mac.start(md, macKey);
461
+ mac.update(data.value);
462
+ var macValue = mac.getMac();
463
+ if (macValue.getBytes() !== capture.macDigest) {
464
+ throw new Error('PKCS#12 MAC could not be verified. Invalid password?');
465
+ }
466
+ }
467
+ _decodeAuthenticatedSafe(pfx, data.value, strict, password);
468
+ return pfx;
469
+ };
470
+
471
+ /**
472
+ * Decodes PKCS#7 Data. PKCS#7 (RFC 2315) defines "Data" as an OCTET STRING,
473
+ * but it is sometimes an OCTET STRING that is composed/constructed of chunks,
474
+ * each its own OCTET STRING. This is BER-encoding vs. DER-encoding. This
475
+ * function transforms this corner-case into the usual simple,
476
+ * non-composed/constructed OCTET STRING.
477
+ *
478
+ * This function may be moved to ASN.1 at some point to better deal with
479
+ * more BER-encoding issues, should they arise.
480
+ *
481
+ * @param data the ASN.1 Data object to transform.
482
+ */
483
+ function _decodePkcs7Data(data) {
484
+ // handle special case of "chunked" data content: an octet string composed
485
+ // of other octet strings
486
+ if (data.composed || data.constructed) {
487
+ var value = forge.util.createBuffer();
488
+ for (var i = 0; i < data.value.length; ++i) {
489
+ value.putBytes(data.value[i].value);
490
+ }
491
+ data.composed = data.constructed = false;
492
+ data.value = value.getBytes();
493
+ }
494
+ return data;
495
+ }
496
+
497
+ /**
498
+ * Decode PKCS#12 AuthenticatedSafe (BER encoded) into PFX object.
499
+ *
500
+ * The AuthenticatedSafe is a BER-encoded SEQUENCE OF ContentInfo.
501
+ *
502
+ * @param pfx The PKCS#12 PFX object to fill.
503
+ * @param {String} authSafe BER-encoded AuthenticatedSafe.
504
+ * @param strict true to use strict DER decoding, false not to.
505
+ * @param {String} password Password to decrypt with (optional).
506
+ */
507
+ function _decodeAuthenticatedSafe(pfx, authSafe, strict, password) {
508
+ authSafe = asn1.fromDer(authSafe, strict); /* actually it's BER encoded */
509
+
510
+ if (authSafe.tagClass !== asn1.Class.UNIVERSAL || authSafe.type !== asn1.Type.SEQUENCE || authSafe.constructed !== true) {
511
+ throw new Error('PKCS#12 AuthenticatedSafe expected to be a ' + 'SEQUENCE OF ContentInfo');
512
+ }
513
+ for (var i = 0; i < authSafe.value.length; i++) {
514
+ var contentInfo = authSafe.value[i];
515
+
516
+ // validate contentInfo and capture data
517
+ var capture = {};
518
+ var errors = [];
519
+ if (!asn1.validate(contentInfo, contentInfoValidator, capture, errors)) {
520
+ var error = new Error('Cannot read ContentInfo.');
521
+ error.errors = errors;
522
+ throw error;
523
+ }
524
+ var obj = {
525
+ encrypted: false
526
+ };
527
+ var safeContents = null;
528
+ var data = capture.content.value[0];
529
+ switch (asn1.derToOid(capture.contentType)) {
530
+ case pki.oids.data:
531
+ if (data.tagClass !== asn1.Class.UNIVERSAL || data.type !== asn1.Type.OCTETSTRING) {
532
+ throw new Error('PKCS#12 SafeContents Data is not an OCTET STRING.');
533
+ }
534
+ safeContents = _decodePkcs7Data(data).value;
535
+ break;
536
+ case pki.oids.encryptedData:
537
+ safeContents = _decryptSafeContents(data, password);
538
+ obj.encrypted = true;
539
+ break;
540
+ default:
541
+ var error = new Error('Unsupported PKCS#12 contentType.');
542
+ error.contentType = asn1.derToOid(capture.contentType);
543
+ throw error;
544
+ }
545
+ obj.safeBags = _decodeSafeContents(safeContents, strict, password);
546
+ pfx.safeContents.push(obj);
547
+ }
548
+ }
549
+
550
+ /**
551
+ * Decrypt PKCS#7 EncryptedData structure.
552
+ *
553
+ * @param data ASN.1 encoded EncryptedContentInfo object.
554
+ * @param password The user-provided password.
555
+ *
556
+ * @return The decrypted SafeContents (ASN.1 object).
557
+ */
558
+ function _decryptSafeContents(data, password) {
559
+ var capture = {};
560
+ var errors = [];
561
+ if (!asn1.validate(data, forge.pkcs7.asn1.encryptedDataValidator, capture, errors)) {
562
+ var error = new Error('Cannot read EncryptedContentInfo.');
563
+ error.errors = errors;
564
+ throw error;
565
+ }
566
+ var oid = asn1.derToOid(capture.contentType);
567
+ if (oid !== pki.oids.data) {
568
+ var error = new Error('PKCS#12 EncryptedContentInfo ContentType is not Data.');
569
+ error.oid = oid;
570
+ throw error;
571
+ }
572
+
573
+ // get cipher
574
+ oid = asn1.derToOid(capture.encAlgorithm);
575
+ var cipher = pki.pbe.getCipher(oid, capture.encParameter, password);
576
+
577
+ // get encrypted data
578
+ var encryptedContentAsn1 = _decodePkcs7Data(capture.encryptedContentAsn1);
579
+ var encrypted = forge.util.createBuffer(encryptedContentAsn1.value);
580
+ cipher.update(encrypted);
581
+ if (!cipher.finish()) {
582
+ throw new Error('Failed to decrypt PKCS#12 SafeContents.');
583
+ }
584
+ return cipher.output.getBytes();
585
+ }
586
+
587
+ /**
588
+ * Decode PKCS#12 SafeContents (BER-encoded) into array of Bag objects.
589
+ *
590
+ * The safeContents is a BER-encoded SEQUENCE OF SafeBag.
591
+ *
592
+ * @param {String} safeContents BER-encoded safeContents.
593
+ * @param strict true to use strict DER decoding, false not to.
594
+ * @param {String} password Password to decrypt with (optional).
595
+ *
596
+ * @return {Array} Array of Bag objects.
597
+ */
598
+ function _decodeSafeContents(safeContents, strict, password) {
599
+ // if strict and no safe contents, return empty safes
600
+ if (!strict && safeContents.length === 0) {
601
+ return [];
602
+ }
603
+
604
+ // actually it's BER-encoded
605
+ safeContents = asn1.fromDer(safeContents, strict);
606
+ if (safeContents.tagClass !== asn1.Class.UNIVERSAL || safeContents.type !== asn1.Type.SEQUENCE || safeContents.constructed !== true) {
607
+ throw new Error('PKCS#12 SafeContents expected to be a SEQUENCE OF SafeBag.');
608
+ }
609
+ var res = [];
610
+ for (var i = 0; i < safeContents.value.length; i++) {
611
+ var safeBag = safeContents.value[i];
612
+
613
+ // validate SafeBag and capture data
614
+ var capture = {};
615
+ var errors = [];
616
+ if (!asn1.validate(safeBag, safeBagValidator, capture, errors)) {
617
+ var error = new Error('Cannot read SafeBag.');
618
+ error.errors = errors;
619
+ throw error;
620
+ }
621
+
622
+ /* Create bag object and push to result array. */
623
+ var bag = {
624
+ type: asn1.derToOid(capture.bagId),
625
+ attributes: _decodeBagAttributes(capture.bagAttributes)
626
+ };
627
+ res.push(bag);
628
+ var validator, decoder;
629
+ var bagAsn1 = capture.bagValue.value[0];
630
+ switch (bag.type) {
631
+ case pki.oids.pkcs8ShroudedKeyBag:
632
+ /* bagAsn1 has a EncryptedPrivateKeyInfo, which we need to decrypt.
633
+ Afterwards we can handle it like a keyBag,
634
+ which is a PrivateKeyInfo. */
635
+ bagAsn1 = pki.decryptPrivateKeyInfo(bagAsn1, password);
636
+ if (bagAsn1 === null) {
637
+ throw new Error('Unable to decrypt PKCS#8 ShroudedKeyBag, wrong password?');
638
+ }
639
+
640
+ /* fall through */
641
+ case pki.oids.keyBag:
642
+ /* A PKCS#12 keyBag is a simple PrivateKeyInfo as understood by our
643
+ PKI module, hence we don't have to do validation/capturing here,
644
+ just pass what we already got. */
645
+ try {
646
+ bag.key = pki.privateKeyFromAsn1(bagAsn1);
647
+ } catch (e) {
648
+ // ignore unknown key type, pass asn1 value
649
+ bag.key = null;
650
+ bag.asn1 = bagAsn1;
651
+ }
652
+ continue;
653
+ /* Nothing more to do. */
654
+
655
+ case pki.oids.certBag:
656
+ /* A PKCS#12 certBag can wrap both X.509 and sdsi certificates.
657
+ Therefore put the SafeBag content through another validator to
658
+ capture the fields. Afterwards check & store the results. */
659
+ validator = certBagValidator;
660
+ decoder = function () {
661
+ if (asn1.derToOid(capture.certId) !== pki.oids.x509Certificate) {
662
+ var error = new Error('Unsupported certificate type, only X.509 supported.');
663
+ error.oid = asn1.derToOid(capture.certId);
664
+ throw error;
665
+ }
666
+
667
+ // true=produce cert hash
668
+ var certAsn1 = asn1.fromDer(capture.cert, strict);
669
+ try {
670
+ bag.cert = pki.certificateFromAsn1(certAsn1, true);
671
+ } catch (e) {
672
+ // ignore unknown cert type, pass asn1 value
673
+ bag.cert = null;
674
+ bag.asn1 = certAsn1;
675
+ }
676
+ };
677
+ break;
678
+ default:
679
+ var error = new Error('Unsupported PKCS#12 SafeBag type.');
680
+ error.oid = bag.type;
681
+ throw error;
682
+ }
683
+
684
+ /* Validate SafeBag value (i.e. CertBag, etc.) and capture data if needed. */
685
+ if (validator !== undefined && !asn1.validate(bagAsn1, validator, capture, errors)) {
686
+ var error = new Error('Cannot read PKCS#12 ' + validator.name);
687
+ error.errors = errors;
688
+ throw error;
689
+ }
690
+
691
+ /* Call decoder function from above to store the results. */
692
+ decoder();
693
+ }
694
+ return res;
695
+ }
696
+
697
+ /**
698
+ * Decode PKCS#12 SET OF PKCS12Attribute into JavaScript object.
699
+ *
700
+ * @param attributes SET OF PKCS12Attribute (ASN.1 object).
701
+ *
702
+ * @return the decoded attributes.
703
+ */
704
+ function _decodeBagAttributes(attributes) {
705
+ var decodedAttrs = {};
706
+ if (attributes !== undefined) {
707
+ for (var i = 0; i < attributes.length; ++i) {
708
+ var capture = {};
709
+ var errors = [];
710
+ if (!asn1.validate(attributes[i], attributeValidator, capture, errors)) {
711
+ var error = new Error('Cannot read PKCS#12 BagAttribute.');
712
+ error.errors = errors;
713
+ throw error;
714
+ }
715
+ var oid = asn1.derToOid(capture.oid);
716
+ if (pki.oids[oid] === undefined) {
717
+ // unsupported attribute type, ignore.
718
+ continue;
719
+ }
720
+ decodedAttrs[pki.oids[oid]] = [];
721
+ for (var j = 0; j < capture.values.length; ++j) {
722
+ decodedAttrs[pki.oids[oid]].push(capture.values[j].value);
723
+ }
724
+ }
725
+ }
726
+ return decodedAttrs;
727
+ }
728
+
729
+ /**
730
+ * Wraps a private key and certificate in a PKCS#12 PFX wrapper. If a
731
+ * password is provided then the private key will be encrypted.
732
+ *
733
+ * An entire certificate chain may also be included. To do this, pass
734
+ * an array for the "cert" parameter where the first certificate is
735
+ * the one that is paired with the private key and each subsequent one
736
+ * verifies the previous one. The certificates may be in PEM format or
737
+ * have been already parsed by Forge.
738
+ *
739
+ * @todo implement password-based-encryption for the whole package
740
+ *
741
+ * @param key the private key.
742
+ * @param cert the certificate (may be an array of certificates in order
743
+ * to specify a certificate chain).
744
+ * @param password the password to use, null for none.
745
+ * @param options:
746
+ * algorithm the encryption algorithm to use
747
+ * ('aes128', 'aes192', 'aes256', '3des'), defaults to 'aes128'.
748
+ * count the iteration count to use.
749
+ * saltSize the salt size to use.
750
+ * useMac true to include a MAC, false not to, defaults to true.
751
+ * localKeyId the local key ID to use, in hex.
752
+ * friendlyName the friendly name to use.
753
+ * generateLocalKeyId true to generate a random local key ID,
754
+ * false not to, defaults to true.
755
+ *
756
+ * @return the PKCS#12 PFX ASN.1 object.
757
+ */
758
+ p12.toPkcs12Asn1 = function (key, cert, password, options) {
759
+ // set default options
760
+ options = options || {};
761
+ options.saltSize = options.saltSize || 8;
762
+ options.count = options.count || 2048;
763
+ options.algorithm = options.algorithm || options.encAlgorithm || 'aes128';
764
+ if (!('useMac' in options)) {
765
+ options.useMac = true;
766
+ }
767
+ if (!('localKeyId' in options)) {
768
+ options.localKeyId = null;
769
+ }
770
+ if (!('generateLocalKeyId' in options)) {
771
+ options.generateLocalKeyId = true;
772
+ }
773
+ var localKeyId = options.localKeyId;
774
+ var bagAttrs;
775
+ if (localKeyId !== null) {
776
+ localKeyId = forge.util.hexToBytes(localKeyId);
777
+ } else if (options.generateLocalKeyId) {
778
+ // use SHA-1 of paired cert, if available
779
+ if (cert) {
780
+ var pairedCert = forge.util.isArray(cert) ? cert[0] : cert;
781
+ if (typeof pairedCert === 'string') {
782
+ pairedCert = pki.certificateFromPem(pairedCert);
783
+ }
784
+ var sha1 = forge.md.sha1.create();
785
+ sha1.update(asn1.toDer(pki.certificateToAsn1(pairedCert)).getBytes());
786
+ localKeyId = sha1.digest().getBytes();
787
+ } else {
788
+ // FIXME: consider using SHA-1 of public key (which can be generated
789
+ // from private key components), see: cert.generateSubjectKeyIdentifier
790
+ // generate random bytes
791
+ localKeyId = forge.random.getBytes(20);
792
+ }
793
+ }
794
+ var attrs = [];
795
+ if (localKeyId !== null) {
796
+ attrs.push(
797
+ // localKeyID
798
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
799
+ // attrId
800
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(pki.oids.localKeyId).getBytes()),
801
+ // attrValues
802
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, localKeyId)])]));
803
+ }
804
+ if ('friendlyName' in options) {
805
+ attrs.push(
806
+ // friendlyName
807
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
808
+ // attrId
809
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(pki.oids.friendlyName).getBytes()),
810
+ // attrValues
811
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.BMPSTRING, false, options.friendlyName)])]));
812
+ }
813
+ if (attrs.length > 0) {
814
+ bagAttrs = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, attrs);
815
+ }
816
+
817
+ // collect contents for AuthenticatedSafe
818
+ var contents = [];
819
+
820
+ // create safe bag(s) for certificate chain
821
+ var chain = [];
822
+ if (cert !== null) {
823
+ if (forge.util.isArray(cert)) {
824
+ chain = cert;
825
+ } else {
826
+ chain = [cert];
827
+ }
828
+ }
829
+ var certSafeBags = [];
830
+ for (var i = 0; i < chain.length; ++i) {
831
+ // convert cert from PEM as necessary
832
+ cert = chain[i];
833
+ if (typeof cert === 'string') {
834
+ cert = pki.certificateFromPem(cert);
835
+ }
836
+
837
+ // SafeBag
838
+ var certBagAttrs = i === 0 ? bagAttrs : undefined;
839
+ var certAsn1 = pki.certificateToAsn1(cert);
840
+ var certSafeBag = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
841
+ // bagId
842
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(pki.oids.certBag).getBytes()),
843
+ // bagValue
844
+ asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [
845
+ // CertBag
846
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
847
+ // certId
848
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(pki.oids.x509Certificate).getBytes()),
849
+ // certValue (x509Certificate)
850
+ asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, asn1.toDer(certAsn1).getBytes())])])]),
851
+ // bagAttributes (OPTIONAL)
852
+ certBagAttrs]);
853
+ certSafeBags.push(certSafeBag);
854
+ }
855
+ if (certSafeBags.length > 0) {
856
+ // SafeContents
857
+ var certSafeContents = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, certSafeBags);
858
+
859
+ // ContentInfo
860
+ var certCI =
861
+ // PKCS#7 ContentInfo
862
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
863
+ // contentType
864
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
865
+ // OID for the content type is 'data'
866
+ asn1.oidToDer(pki.oids.data).getBytes()),
867
+ // content
868
+ asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, asn1.toDer(certSafeContents).getBytes())])]);
869
+ contents.push(certCI);
870
+ }
871
+
872
+ // create safe contents for private key
873
+ var keyBag = null;
874
+ if (key !== null) {
875
+ // SafeBag
876
+ var pkAsn1 = pki.wrapRsaPrivateKey(pki.privateKeyToAsn1(key));
877
+ if (password === null) {
878
+ // no encryption
879
+ keyBag = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
880
+ // bagId
881
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(pki.oids.keyBag).getBytes()),
882
+ // bagValue
883
+ asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [
884
+ // PrivateKeyInfo
885
+ pkAsn1]),
886
+ // bagAttributes (OPTIONAL)
887
+ bagAttrs]);
888
+ } else {
889
+ // encrypted PrivateKeyInfo
890
+ keyBag = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
891
+ // bagId
892
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(pki.oids.pkcs8ShroudedKeyBag).getBytes()),
893
+ // bagValue
894
+ asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [
895
+ // EncryptedPrivateKeyInfo
896
+ pki.encryptPrivateKeyInfo(pkAsn1, password, options)]),
897
+ // bagAttributes (OPTIONAL)
898
+ bagAttrs]);
899
+ }
900
+
901
+ // SafeContents
902
+ var keySafeContents = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [keyBag]);
903
+
904
+ // ContentInfo
905
+ var keyCI =
906
+ // PKCS#7 ContentInfo
907
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
908
+ // contentType
909
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
910
+ // OID for the content type is 'data'
911
+ asn1.oidToDer(pki.oids.data).getBytes()),
912
+ // content
913
+ asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, asn1.toDer(keySafeContents).getBytes())])]);
914
+ contents.push(keyCI);
915
+ }
916
+
917
+ // create AuthenticatedSafe by stringing together the contents
918
+ var safe = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, contents);
919
+ var macData;
920
+ if (options.useMac) {
921
+ // MacData
922
+ var sha1 = forge.md.sha1.create();
923
+ var macSalt = new forge.util.ByteBuffer(forge.random.getBytes(options.saltSize));
924
+ var count = options.count;
925
+ // 160-bit key
926
+ var key = p12.generateKey(password, macSalt, 3, count, 20);
927
+ var mac = forge.hmac.create();
928
+ mac.start(sha1, key);
929
+ mac.update(asn1.toDer(safe).getBytes());
930
+ var macValue = mac.getMac();
931
+ macData = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
932
+ // mac DigestInfo
933
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
934
+ // digestAlgorithm
935
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
936
+ // algorithm = SHA-1
937
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(pki.oids.sha1).getBytes()),
938
+ // parameters = Null
939
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')]),
940
+ // digest
941
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, macValue.getBytes())]),
942
+ // macSalt OCTET STRING
943
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, macSalt.getBytes()),
944
+ // iterations INTEGER (XXX: Only support count < 65536)
945
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false, asn1.integerToDer(count).getBytes())]);
946
+ }
947
+
948
+ // PFX
949
+ return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
950
+ // version (3)
951
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false, asn1.integerToDer(3).getBytes()),
952
+ // PKCS#7 ContentInfo
953
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
954
+ // contentType
955
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
956
+ // OID for the content type is 'data'
957
+ asn1.oidToDer(pki.oids.data).getBytes()),
958
+ // content
959
+ asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, asn1.toDer(safe).getBytes())])]), macData]);
960
+ };
961
+
962
+ /**
963
+ * Derives a PKCS#12 key.
964
+ *
965
+ * @param password the password to derive the key material from, null or
966
+ * undefined for none.
967
+ * @param salt the salt, as a ByteBuffer, to use.
968
+ * @param id the PKCS#12 ID byte (1 = key material, 2 = IV, 3 = MAC).
969
+ * @param iter the iteration count.
970
+ * @param n the number of bytes to derive from the password.
971
+ * @param md the message digest to use, defaults to SHA-1.
972
+ *
973
+ * @return a ByteBuffer with the bytes derived from the password.
974
+ */
975
+ p12.generateKey = forge.pbe.generatePkcs12Key;
976
+ return pkcs12.exports;
977
+ }
978
+
979
+ export { requirePkcs12 as __require };
980
+ //# sourceMappingURL=pkcs12.js.map