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,1073 @@
1
+ import { __module as pkcs7 } from '../../../_virtual/pkcs7.js';
2
+ import { __require as requireForge } from './forge.js';
3
+ import { __require as requireAes } from './aes.js';
4
+ import { __require as requireAsn1 } from './asn1.js';
5
+ import { __require as requireDes } from './des.js';
6
+ import { __require as requireOids } from './oids.js';
7
+ import { __require as requirePem } from './pem.js';
8
+ import { __require as requirePkcs7asn1 } from './pkcs7asn1.js';
9
+ import { __require as requireRandom } from './random.js';
10
+ import { __require as requireUtil } from './util.js';
11
+ import { __require as requireX509 } from './x509.js';
12
+
13
+ /**
14
+ * Javascript implementation of PKCS#7 v1.5.
15
+ *
16
+ * @author Stefan Siegl
17
+ * @author Dave Longley
18
+ *
19
+ * Copyright (c) 2012 Stefan Siegl <stesie@brokenpipe.de>
20
+ * Copyright (c) 2012-2015 Digital Bazaar, Inc.
21
+ *
22
+ * Currently this implementation only supports ContentType of EnvelopedData,
23
+ * EncryptedData, or SignedData at the root level. The top level elements may
24
+ * contain only a ContentInfo of ContentType Data, i.e. plain data. Further
25
+ * nesting is not (yet) supported.
26
+ *
27
+ * The Forge validators for PKCS #7's ASN.1 structures are available from
28
+ * a separate file pkcs7asn1.js, since those are referenced from other
29
+ * PKCS standards like PKCS #12.
30
+ */
31
+ var hasRequiredPkcs7;
32
+ function requirePkcs7() {
33
+ if (hasRequiredPkcs7) return pkcs7.exports;
34
+ hasRequiredPkcs7 = 1;
35
+ var forge = requireForge();
36
+ requireAes();
37
+ requireAsn1();
38
+ requireDes();
39
+ requireOids();
40
+ requirePem();
41
+ requirePkcs7asn1();
42
+ requireRandom();
43
+ requireUtil();
44
+ requireX509();
45
+
46
+ // shortcut for ASN.1 API
47
+ var asn1 = forge.asn1;
48
+
49
+ // shortcut for PKCS#7 API
50
+ var p7 = pkcs7.exports = forge.pkcs7 = forge.pkcs7 || {};
51
+
52
+ /**
53
+ * Converts a PKCS#7 message from PEM format.
54
+ *
55
+ * @param pem the PEM-formatted PKCS#7 message.
56
+ *
57
+ * @return the PKCS#7 message.
58
+ */
59
+ p7.messageFromPem = function (pem) {
60
+ var msg = forge.pem.decode(pem)[0];
61
+ if (msg.type !== 'PKCS7') {
62
+ var error = new Error('Could not convert PKCS#7 message from PEM; PEM ' + 'header type is not "PKCS#7".');
63
+ error.headerType = msg.type;
64
+ throw error;
65
+ }
66
+ if (msg.procType && msg.procType.type === 'ENCRYPTED') {
67
+ throw new Error('Could not convert PKCS#7 message from PEM; PEM is encrypted.');
68
+ }
69
+
70
+ // convert DER to ASN.1 object
71
+ var obj = asn1.fromDer(msg.body);
72
+ return p7.messageFromAsn1(obj);
73
+ };
74
+
75
+ /**
76
+ * Converts a PKCS#7 message to PEM format.
77
+ *
78
+ * @param msg The PKCS#7 message object
79
+ * @param maxline The maximum characters per line, defaults to 64.
80
+ *
81
+ * @return The PEM-formatted PKCS#7 message.
82
+ */
83
+ p7.messageToPem = function (msg, maxline) {
84
+ // convert to ASN.1, then DER, then PEM-encode
85
+ var pemObj = {
86
+ type: 'PKCS7',
87
+ body: asn1.toDer(msg.toAsn1()).getBytes()
88
+ };
89
+ return forge.pem.encode(pemObj, {
90
+ maxline: maxline
91
+ });
92
+ };
93
+
94
+ /**
95
+ * Converts a PKCS#7 message from an ASN.1 object.
96
+ *
97
+ * @param obj the ASN.1 representation of a ContentInfo.
98
+ *
99
+ * @return the PKCS#7 message.
100
+ */
101
+ p7.messageFromAsn1 = function (obj) {
102
+ // validate root level ContentInfo and capture data
103
+ var capture = {};
104
+ var errors = [];
105
+ if (!asn1.validate(obj, p7.asn1.contentInfoValidator, capture, errors)) {
106
+ var error = new Error('Cannot read PKCS#7 message. ' + 'ASN.1 object is not an PKCS#7 ContentInfo.');
107
+ error.errors = errors;
108
+ throw error;
109
+ }
110
+ var contentType = asn1.derToOid(capture.contentType);
111
+ var msg;
112
+ switch (contentType) {
113
+ case forge.pki.oids.envelopedData:
114
+ msg = p7.createEnvelopedData();
115
+ break;
116
+ case forge.pki.oids.encryptedData:
117
+ msg = p7.createEncryptedData();
118
+ break;
119
+ case forge.pki.oids.signedData:
120
+ msg = p7.createSignedData();
121
+ break;
122
+ default:
123
+ throw new Error('Cannot read PKCS#7 message. ContentType with OID ' + contentType + ' is not (yet) supported.');
124
+ }
125
+ msg.fromAsn1(capture.content.value[0]);
126
+ return msg;
127
+ };
128
+ p7.createSignedData = function () {
129
+ var msg = null;
130
+ msg = {
131
+ type: forge.pki.oids.signedData,
132
+ version: 1,
133
+ certificates: [],
134
+ crls: [],
135
+ // TODO: add json-formatted signer stuff here?
136
+ signers: [],
137
+ // populated during sign()
138
+ digestAlgorithmIdentifiers: [],
139
+ contentInfo: null,
140
+ signerInfos: [],
141
+ fromAsn1: function (obj) {
142
+ // validate SignedData content block and capture data.
143
+ _fromAsn1(msg, obj, p7.asn1.signedDataValidator);
144
+ msg.certificates = [];
145
+ msg.crls = [];
146
+ msg.digestAlgorithmIdentifiers = [];
147
+ msg.contentInfo = null;
148
+ msg.signerInfos = [];
149
+ if (msg.rawCapture.certificates) {
150
+ var certs = msg.rawCapture.certificates.value;
151
+ for (var i = 0; i < certs.length; ++i) {
152
+ msg.certificates.push(forge.pki.certificateFromAsn1(certs[i]));
153
+ }
154
+ }
155
+
156
+ // TODO: parse crls
157
+ },
158
+ toAsn1: function () {
159
+ // degenerate case with no content
160
+ if (!msg.contentInfo) {
161
+ msg.sign();
162
+ }
163
+ var certs = [];
164
+ for (var i = 0; i < msg.certificates.length; ++i) {
165
+ certs.push(forge.pki.certificateToAsn1(msg.certificates[i]));
166
+ }
167
+ var crls = [];
168
+ // TODO: implement CRLs
169
+
170
+ // [0] SignedData
171
+ var signedData = asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
172
+ // Version
173
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false, asn1.integerToDer(msg.version).getBytes()),
174
+ // DigestAlgorithmIdentifiers
175
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, msg.digestAlgorithmIdentifiers),
176
+ // ContentInfo
177
+ msg.contentInfo])]);
178
+ if (certs.length > 0) {
179
+ // [0] IMPLICIT ExtendedCertificatesAndCertificates OPTIONAL
180
+ signedData.value[0].value.push(asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, certs));
181
+ }
182
+ if (crls.length > 0) {
183
+ // [1] IMPLICIT CertificateRevocationLists OPTIONAL
184
+ signedData.value[0].value.push(asn1.create(asn1.Class.CONTEXT_SPECIFIC, 1, true, crls));
185
+ }
186
+ // SignerInfos
187
+ signedData.value[0].value.push(asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, msg.signerInfos));
188
+
189
+ // ContentInfo
190
+ return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
191
+ // ContentType
192
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(msg.type).getBytes()),
193
+ // [0] SignedData
194
+ signedData]);
195
+ },
196
+ /**
197
+ * Add (another) entity to list of signers.
198
+ *
199
+ * Note: If authenticatedAttributes are provided, then, per RFC 2315,
200
+ * they must include at least two attributes: content type and
201
+ * message digest. The message digest attribute value will be
202
+ * auto-calculated during signing and will be ignored if provided.
203
+ *
204
+ * Here's an example of providing these two attributes:
205
+ *
206
+ * forge.pkcs7.createSignedData();
207
+ * p7.addSigner({
208
+ * issuer: cert.issuer.attributes,
209
+ * serialNumber: cert.serialNumber,
210
+ * key: privateKey,
211
+ * digestAlgorithm: forge.pki.oids.sha1,
212
+ * authenticatedAttributes: [{
213
+ * type: forge.pki.oids.contentType,
214
+ * value: forge.pki.oids.data
215
+ * }, {
216
+ * type: forge.pki.oids.messageDigest
217
+ * }]
218
+ * });
219
+ *
220
+ * TODO: Support [subjectKeyIdentifier] as signer's ID.
221
+ *
222
+ * @param signer the signer information:
223
+ * key the signer's private key.
224
+ * [certificate] a certificate containing the public key
225
+ * associated with the signer's private key; use this option as
226
+ * an alternative to specifying signer.issuer and
227
+ * signer.serialNumber.
228
+ * [issuer] the issuer attributes (eg: cert.issuer.attributes).
229
+ * [serialNumber] the signer's certificate's serial number in
230
+ * hexadecimal (eg: cert.serialNumber).
231
+ * [digestAlgorithm] the message digest OID, as a string, to use
232
+ * (eg: forge.pki.oids.sha1).
233
+ * [authenticatedAttributes] an optional array of attributes
234
+ * to also sign along with the content.
235
+ */
236
+ addSigner: function (signer) {
237
+ var issuer = signer.issuer;
238
+ var serialNumber = signer.serialNumber;
239
+ if (signer.certificate) {
240
+ var cert = signer.certificate;
241
+ if (typeof cert === 'string') {
242
+ cert = forge.pki.certificateFromPem(cert);
243
+ }
244
+ issuer = cert.issuer.attributes;
245
+ serialNumber = cert.serialNumber;
246
+ }
247
+ var key = signer.key;
248
+ if (!key) {
249
+ throw new Error('Could not add PKCS#7 signer; no private key specified.');
250
+ }
251
+ if (typeof key === 'string') {
252
+ key = forge.pki.privateKeyFromPem(key);
253
+ }
254
+
255
+ // ensure OID known for digest algorithm
256
+ var digestAlgorithm = signer.digestAlgorithm || forge.pki.oids.sha1;
257
+ switch (digestAlgorithm) {
258
+ case forge.pki.oids.sha1:
259
+ case forge.pki.oids.sha256:
260
+ case forge.pki.oids.sha384:
261
+ case forge.pki.oids.sha512:
262
+ case forge.pki.oids.md5:
263
+ break;
264
+ default:
265
+ throw new Error('Could not add PKCS#7 signer; unknown message digest algorithm: ' + digestAlgorithm);
266
+ }
267
+
268
+ // if authenticatedAttributes is present, then the attributes
269
+ // must contain at least PKCS #9 content-type and message-digest
270
+ var authenticatedAttributes = signer.authenticatedAttributes || [];
271
+ if (authenticatedAttributes.length > 0) {
272
+ var contentType = false;
273
+ var messageDigest = false;
274
+ for (var i = 0; i < authenticatedAttributes.length; ++i) {
275
+ var attr = authenticatedAttributes[i];
276
+ if (!contentType && attr.type === forge.pki.oids.contentType) {
277
+ contentType = true;
278
+ if (messageDigest) {
279
+ break;
280
+ }
281
+ continue;
282
+ }
283
+ if (!messageDigest && attr.type === forge.pki.oids.messageDigest) {
284
+ messageDigest = true;
285
+ if (contentType) {
286
+ break;
287
+ }
288
+ continue;
289
+ }
290
+ }
291
+ if (!contentType || !messageDigest) {
292
+ throw new Error('Invalid signer.authenticatedAttributes. If ' + 'signer.authenticatedAttributes is specified, then it must ' + 'contain at least two attributes, PKCS #9 content-type and ' + 'PKCS #9 message-digest.');
293
+ }
294
+ }
295
+ msg.signers.push({
296
+ key: key,
297
+ version: 1,
298
+ issuer: issuer,
299
+ serialNumber: serialNumber,
300
+ digestAlgorithm: digestAlgorithm,
301
+ signatureAlgorithm: forge.pki.oids.rsaEncryption,
302
+ signature: null,
303
+ authenticatedAttributes: authenticatedAttributes,
304
+ unauthenticatedAttributes: []
305
+ });
306
+ },
307
+ /**
308
+ * Signs the content.
309
+ * @param options Options to apply when signing:
310
+ * [detached] boolean. If signing should be done in detached mode. Defaults to false.
311
+ */
312
+ sign: function (options) {
313
+ options = options || {};
314
+ // auto-generate content info
315
+ if (typeof msg.content !== 'object' || msg.contentInfo === null) {
316
+ // use Data ContentInfo
317
+ msg.contentInfo = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
318
+ // ContentType
319
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(forge.pki.oids.data).getBytes())]);
320
+
321
+ // add actual content, if present
322
+ if ('content' in msg) {
323
+ var content;
324
+ if (msg.content instanceof forge.util.ByteBuffer) {
325
+ content = msg.content.bytes();
326
+ } else if (typeof msg.content === 'string') {
327
+ content = forge.util.encodeUtf8(msg.content);
328
+ }
329
+ if (options.detached) {
330
+ msg.detachedContent = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, content);
331
+ } else {
332
+ msg.contentInfo.value.push(
333
+ // [0] EXPLICIT content
334
+ asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, content)]));
335
+ }
336
+ }
337
+ }
338
+
339
+ // no signers, return early (degenerate case for certificate container)
340
+ if (msg.signers.length === 0) {
341
+ return;
342
+ }
343
+
344
+ // generate digest algorithm identifiers
345
+ var mds = addDigestAlgorithmIds();
346
+
347
+ // generate signerInfos
348
+ addSignerInfos(mds);
349
+ },
350
+ verify: function () {
351
+ throw new Error('PKCS#7 signature verification not yet implemented.');
352
+ },
353
+ /**
354
+ * Add a certificate.
355
+ *
356
+ * @param cert the certificate to add.
357
+ */
358
+ addCertificate: function (cert) {
359
+ // convert from PEM
360
+ if (typeof cert === 'string') {
361
+ cert = forge.pki.certificateFromPem(cert);
362
+ }
363
+ msg.certificates.push(cert);
364
+ },
365
+ /**
366
+ * Add a certificate revokation list.
367
+ *
368
+ * @param crl the certificate revokation list to add.
369
+ */
370
+ addCertificateRevokationList: function (crl) {
371
+ throw new Error('PKCS#7 CRL support not yet implemented.');
372
+ }
373
+ };
374
+ return msg;
375
+ function addDigestAlgorithmIds() {
376
+ var mds = {};
377
+ for (var i = 0; i < msg.signers.length; ++i) {
378
+ var signer = msg.signers[i];
379
+ var oid = signer.digestAlgorithm;
380
+ if (!(oid in mds)) {
381
+ // content digest
382
+ mds[oid] = forge.md[forge.pki.oids[oid]].create();
383
+ }
384
+ if (signer.authenticatedAttributes.length === 0) {
385
+ // no custom attributes to digest; use content message digest
386
+ signer.md = mds[oid];
387
+ } else {
388
+ // custom attributes to be digested; use own message digest
389
+ // TODO: optimize to just copy message digest state if that
390
+ // feature is ever supported with message digests
391
+ signer.md = forge.md[forge.pki.oids[oid]].create();
392
+ }
393
+ }
394
+
395
+ // add unique digest algorithm identifiers
396
+ msg.digestAlgorithmIdentifiers = [];
397
+ for (var oid in mds) {
398
+ msg.digestAlgorithmIdentifiers.push(
399
+ // AlgorithmIdentifier
400
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
401
+ // algorithm
402
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(oid).getBytes()),
403
+ // parameters (null)
404
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')]));
405
+ }
406
+ return mds;
407
+ }
408
+ function addSignerInfos(mds) {
409
+ var content;
410
+ if (msg.detachedContent) {
411
+ // Signature has been made in detached mode.
412
+ content = msg.detachedContent;
413
+ } else {
414
+ // Note: ContentInfo is a SEQUENCE with 2 values, second value is
415
+ // the content field and is optional for a ContentInfo but required here
416
+ // since signers are present
417
+ // get ContentInfo content
418
+ content = msg.contentInfo.value[1];
419
+ // skip [0] EXPLICIT content wrapper
420
+ content = content.value[0];
421
+ }
422
+ if (!content) {
423
+ throw new Error('Could not sign PKCS#7 message; there is no content to sign.');
424
+ }
425
+
426
+ // get ContentInfo content type
427
+ var contentType = asn1.derToOid(msg.contentInfo.value[0].value);
428
+
429
+ // serialize content
430
+ var bytes = asn1.toDer(content);
431
+
432
+ // skip identifier and length per RFC 2315 9.3
433
+ // skip identifier (1 byte)
434
+ bytes.getByte();
435
+ // read and discard length bytes
436
+ asn1.getBerValueLength(bytes);
437
+ bytes = bytes.getBytes();
438
+
439
+ // digest content DER value bytes
440
+ for (var oid in mds) {
441
+ mds[oid].start().update(bytes);
442
+ }
443
+
444
+ // sign content
445
+ var signingTime = new Date();
446
+ for (var i = 0; i < msg.signers.length; ++i) {
447
+ var signer = msg.signers[i];
448
+ if (signer.authenticatedAttributes.length === 0) {
449
+ // if ContentInfo content type is not "Data", then
450
+ // authenticatedAttributes must be present per RFC 2315
451
+ if (contentType !== forge.pki.oids.data) {
452
+ throw new Error('Invalid signer; authenticatedAttributes must be present ' + 'when the ContentInfo content type is not PKCS#7 Data.');
453
+ }
454
+ } else {
455
+ // process authenticated attributes
456
+ // [0] IMPLICIT
457
+ signer.authenticatedAttributesAsn1 = asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, []);
458
+
459
+ // per RFC 2315, attributes are to be digested using a SET container
460
+ // not the above [0] IMPLICIT container
461
+ var attrsAsn1 = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, []);
462
+ for (var ai = 0; ai < signer.authenticatedAttributes.length; ++ai) {
463
+ var attr = signer.authenticatedAttributes[ai];
464
+ if (attr.type === forge.pki.oids.messageDigest) {
465
+ // use content message digest as value
466
+ attr.value = mds[signer.digestAlgorithm].digest();
467
+ } else if (attr.type === forge.pki.oids.signingTime) {
468
+ // auto-populate signing time if not already set
469
+ if (!attr.value) {
470
+ attr.value = signingTime;
471
+ }
472
+ }
473
+
474
+ // convert to ASN.1 and push onto Attributes SET (for signing) and
475
+ // onto authenticatedAttributesAsn1 to complete SignedData ASN.1
476
+ // TODO: optimize away duplication
477
+ attrsAsn1.value.push(_attributeToAsn1(attr));
478
+ signer.authenticatedAttributesAsn1.value.push(_attributeToAsn1(attr));
479
+ }
480
+
481
+ // DER-serialize and digest SET OF attributes only
482
+ bytes = asn1.toDer(attrsAsn1).getBytes();
483
+ signer.md.start().update(bytes);
484
+ }
485
+
486
+ // sign digest
487
+ signer.signature = signer.key.sign(signer.md, 'RSASSA-PKCS1-V1_5');
488
+ }
489
+
490
+ // add signer info
491
+ msg.signerInfos = _signersToAsn1(msg.signers);
492
+ }
493
+ };
494
+
495
+ /**
496
+ * Creates an empty PKCS#7 message of type EncryptedData.
497
+ *
498
+ * @return the message.
499
+ */
500
+ p7.createEncryptedData = function () {
501
+ var msg = null;
502
+ msg = {
503
+ type: forge.pki.oids.encryptedData,
504
+ version: 0,
505
+ encryptedContent: {
506
+ algorithm: forge.pki.oids['aes256-CBC']
507
+ },
508
+ /**
509
+ * Reads an EncryptedData content block (in ASN.1 format)
510
+ *
511
+ * @param obj The ASN.1 representation of the EncryptedData content block
512
+ */
513
+ fromAsn1: function (obj) {
514
+ // Validate EncryptedData content block and capture data.
515
+ _fromAsn1(msg, obj, p7.asn1.encryptedDataValidator);
516
+ },
517
+ /**
518
+ * Decrypt encrypted content
519
+ *
520
+ * @param key The (symmetric) key as a byte buffer
521
+ */
522
+ decrypt: function (key) {
523
+ if (key !== undefined) {
524
+ msg.encryptedContent.key = key;
525
+ }
526
+ _decryptContent(msg);
527
+ }
528
+ };
529
+ return msg;
530
+ };
531
+
532
+ /**
533
+ * Creates an empty PKCS#7 message of type EnvelopedData.
534
+ *
535
+ * @return the message.
536
+ */
537
+ p7.createEnvelopedData = function () {
538
+ var msg = null;
539
+ msg = {
540
+ type: forge.pki.oids.envelopedData,
541
+ version: 0,
542
+ recipients: [],
543
+ encryptedContent: {
544
+ algorithm: forge.pki.oids['aes256-CBC']
545
+ },
546
+ /**
547
+ * Reads an EnvelopedData content block (in ASN.1 format)
548
+ *
549
+ * @param obj the ASN.1 representation of the EnvelopedData content block.
550
+ */
551
+ fromAsn1: function (obj) {
552
+ // validate EnvelopedData content block and capture data
553
+ var capture = _fromAsn1(msg, obj, p7.asn1.envelopedDataValidator);
554
+ msg.recipients = _recipientsFromAsn1(capture.recipientInfos.value);
555
+ },
556
+ toAsn1: function () {
557
+ // ContentInfo
558
+ return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
559
+ // ContentType
560
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(msg.type).getBytes()),
561
+ // [0] EnvelopedData
562
+ asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
563
+ // Version
564
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false, asn1.integerToDer(msg.version).getBytes()),
565
+ // RecipientInfos
566
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, _recipientsToAsn1(msg.recipients)),
567
+ // EncryptedContentInfo
568
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, _encryptedContentToAsn1(msg.encryptedContent))])])]);
569
+ },
570
+ /**
571
+ * Find recipient by X.509 certificate's issuer.
572
+ *
573
+ * @param cert the certificate with the issuer to look for.
574
+ *
575
+ * @return the recipient object.
576
+ */
577
+ findRecipient: function (cert) {
578
+ var sAttr = cert.issuer.attributes;
579
+ for (var i = 0; i < msg.recipients.length; ++i) {
580
+ var r = msg.recipients[i];
581
+ var rAttr = r.issuer;
582
+ if (r.serialNumber !== cert.serialNumber) {
583
+ continue;
584
+ }
585
+ if (rAttr.length !== sAttr.length) {
586
+ continue;
587
+ }
588
+ var match = true;
589
+ for (var j = 0; j < sAttr.length; ++j) {
590
+ if (rAttr[j].type !== sAttr[j].type || rAttr[j].value !== sAttr[j].value) {
591
+ match = false;
592
+ break;
593
+ }
594
+ }
595
+ if (match) {
596
+ return r;
597
+ }
598
+ }
599
+ return null;
600
+ },
601
+ /**
602
+ * Decrypt enveloped content
603
+ *
604
+ * @param recipient The recipient object related to the private key
605
+ * @param privKey The (RSA) private key object
606
+ */
607
+ decrypt: function (recipient, privKey) {
608
+ if (msg.encryptedContent.key === undefined && recipient !== undefined && privKey !== undefined) {
609
+ switch (recipient.encryptedContent.algorithm) {
610
+ case forge.pki.oids.rsaEncryption:
611
+ case forge.pki.oids.desCBC:
612
+ var key = privKey.decrypt(recipient.encryptedContent.content);
613
+ msg.encryptedContent.key = forge.util.createBuffer(key);
614
+ break;
615
+ default:
616
+ throw new Error('Unsupported asymmetric cipher, ' + 'OID ' + recipient.encryptedContent.algorithm);
617
+ }
618
+ }
619
+ _decryptContent(msg);
620
+ },
621
+ /**
622
+ * Add (another) entity to list of recipients.
623
+ *
624
+ * @param cert The certificate of the entity to add.
625
+ */
626
+ addRecipient: function (cert) {
627
+ msg.recipients.push({
628
+ version: 0,
629
+ issuer: cert.issuer.attributes,
630
+ serialNumber: cert.serialNumber,
631
+ encryptedContent: {
632
+ // We simply assume rsaEncryption here, since forge.pki only
633
+ // supports RSA so far. If the PKI module supports other
634
+ // ciphers one day, we need to modify this one as well.
635
+ algorithm: forge.pki.oids.rsaEncryption,
636
+ key: cert.publicKey
637
+ }
638
+ });
639
+ },
640
+ /**
641
+ * Encrypt enveloped content.
642
+ *
643
+ * This function supports two optional arguments, cipher and key, which
644
+ * can be used to influence symmetric encryption. Unless cipher is
645
+ * provided, the cipher specified in encryptedContent.algorithm is used
646
+ * (defaults to AES-256-CBC). If no key is provided, encryptedContent.key
647
+ * is (re-)used. If that one's not set, a random key will be generated
648
+ * automatically.
649
+ *
650
+ * @param [key] The key to be used for symmetric encryption.
651
+ * @param [cipher] The OID of the symmetric cipher to use.
652
+ */
653
+ encrypt: function (key, cipher) {
654
+ // Part 1: Symmetric encryption
655
+ if (msg.encryptedContent.content === undefined) {
656
+ cipher = cipher || msg.encryptedContent.algorithm;
657
+ key = key || msg.encryptedContent.key;
658
+ var keyLen, ivLen, ciphFn;
659
+ switch (cipher) {
660
+ case forge.pki.oids['aes128-CBC']:
661
+ keyLen = 16;
662
+ ivLen = 16;
663
+ ciphFn = forge.aes.createEncryptionCipher;
664
+ break;
665
+ case forge.pki.oids['aes192-CBC']:
666
+ keyLen = 24;
667
+ ivLen = 16;
668
+ ciphFn = forge.aes.createEncryptionCipher;
669
+ break;
670
+ case forge.pki.oids['aes256-CBC']:
671
+ keyLen = 32;
672
+ ivLen = 16;
673
+ ciphFn = forge.aes.createEncryptionCipher;
674
+ break;
675
+ case forge.pki.oids['des-EDE3-CBC']:
676
+ keyLen = 24;
677
+ ivLen = 8;
678
+ ciphFn = forge.des.createEncryptionCipher;
679
+ break;
680
+ default:
681
+ throw new Error('Unsupported symmetric cipher, OID ' + cipher);
682
+ }
683
+ if (key === undefined) {
684
+ key = forge.util.createBuffer(forge.random.getBytes(keyLen));
685
+ } else if (key.length() != keyLen) {
686
+ throw new Error('Symmetric key has wrong length; ' + 'got ' + key.length() + ' bytes, expected ' + keyLen + '.');
687
+ }
688
+
689
+ // Keep a copy of the key & IV in the object, so the caller can
690
+ // use it for whatever reason.
691
+ msg.encryptedContent.algorithm = cipher;
692
+ msg.encryptedContent.key = key;
693
+ msg.encryptedContent.parameter = forge.util.createBuffer(forge.random.getBytes(ivLen));
694
+ var ciph = ciphFn(key);
695
+ ciph.start(msg.encryptedContent.parameter.copy());
696
+ ciph.update(msg.content);
697
+
698
+ // The finish function does PKCS#7 padding by default, therefore
699
+ // no action required by us.
700
+ if (!ciph.finish()) {
701
+ throw new Error('Symmetric encryption failed.');
702
+ }
703
+ msg.encryptedContent.content = ciph.output;
704
+ }
705
+
706
+ // Part 2: asymmetric encryption for each recipient
707
+ for (var i = 0; i < msg.recipients.length; ++i) {
708
+ var recipient = msg.recipients[i];
709
+
710
+ // Nothing to do, encryption already done.
711
+ if (recipient.encryptedContent.content !== undefined) {
712
+ continue;
713
+ }
714
+ switch (recipient.encryptedContent.algorithm) {
715
+ case forge.pki.oids.rsaEncryption:
716
+ recipient.encryptedContent.content = recipient.encryptedContent.key.encrypt(msg.encryptedContent.key.data);
717
+ break;
718
+ default:
719
+ throw new Error('Unsupported asymmetric cipher, OID ' + recipient.encryptedContent.algorithm);
720
+ }
721
+ }
722
+ }
723
+ };
724
+ return msg;
725
+ };
726
+
727
+ /**
728
+ * Converts a single recipient from an ASN.1 object.
729
+ *
730
+ * @param obj the ASN.1 RecipientInfo.
731
+ *
732
+ * @return the recipient object.
733
+ */
734
+ function _recipientFromAsn1(obj) {
735
+ // validate EnvelopedData content block and capture data
736
+ var capture = {};
737
+ var errors = [];
738
+ if (!asn1.validate(obj, p7.asn1.recipientInfoValidator, capture, errors)) {
739
+ var error = new Error('Cannot read PKCS#7 RecipientInfo. ' + 'ASN.1 object is not an PKCS#7 RecipientInfo.');
740
+ error.errors = errors;
741
+ throw error;
742
+ }
743
+ return {
744
+ version: capture.version.charCodeAt(0),
745
+ issuer: forge.pki.RDNAttributesAsArray(capture.issuer),
746
+ serialNumber: forge.util.createBuffer(capture.serial).toHex(),
747
+ encryptedContent: {
748
+ algorithm: asn1.derToOid(capture.encAlgorithm),
749
+ parameter: capture.encParameter ? capture.encParameter.value : undefined,
750
+ content: capture.encKey
751
+ }
752
+ };
753
+ }
754
+
755
+ /**
756
+ * Converts a single recipient object to an ASN.1 object.
757
+ *
758
+ * @param obj the recipient object.
759
+ *
760
+ * @return the ASN.1 RecipientInfo.
761
+ */
762
+ function _recipientToAsn1(obj) {
763
+ return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
764
+ // Version
765
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false, asn1.integerToDer(obj.version).getBytes()),
766
+ // IssuerAndSerialNumber
767
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
768
+ // Name
769
+ forge.pki.distinguishedNameToAsn1({
770
+ attributes: obj.issuer
771
+ }),
772
+ // Serial
773
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false, forge.util.hexToBytes(obj.serialNumber))]),
774
+ // KeyEncryptionAlgorithmIdentifier
775
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
776
+ // Algorithm
777
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(obj.encryptedContent.algorithm).getBytes()),
778
+ // Parameter, force NULL, only RSA supported for now.
779
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')]),
780
+ // EncryptedKey
781
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, obj.encryptedContent.content)]);
782
+ }
783
+
784
+ /**
785
+ * Map a set of RecipientInfo ASN.1 objects to recipient objects.
786
+ *
787
+ * @param infos an array of ASN.1 representations RecipientInfo (i.e. SET OF).
788
+ *
789
+ * @return an array of recipient objects.
790
+ */
791
+ function _recipientsFromAsn1(infos) {
792
+ var ret = [];
793
+ for (var i = 0; i < infos.length; ++i) {
794
+ ret.push(_recipientFromAsn1(infos[i]));
795
+ }
796
+ return ret;
797
+ }
798
+
799
+ /**
800
+ * Map an array of recipient objects to ASN.1 RecipientInfo objects.
801
+ *
802
+ * @param recipients an array of recipientInfo objects.
803
+ *
804
+ * @return an array of ASN.1 RecipientInfos.
805
+ */
806
+ function _recipientsToAsn1(recipients) {
807
+ var ret = [];
808
+ for (var i = 0; i < recipients.length; ++i) {
809
+ ret.push(_recipientToAsn1(recipients[i]));
810
+ }
811
+ return ret;
812
+ }
813
+
814
+ /**
815
+ * Converts a single signerInfo object to an ASN.1 object.
816
+ *
817
+ * @param obj the signerInfo object.
818
+ *
819
+ * @return the ASN.1 representation of a SignerInfo.
820
+ */
821
+ function _signerToAsn1(obj) {
822
+ // SignerInfo
823
+ var rval = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
824
+ // version
825
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false, asn1.integerToDer(obj.version).getBytes()),
826
+ // issuerAndSerialNumber
827
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
828
+ // name
829
+ forge.pki.distinguishedNameToAsn1({
830
+ attributes: obj.issuer
831
+ }),
832
+ // serial
833
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false, forge.util.hexToBytes(obj.serialNumber))]),
834
+ // digestAlgorithm
835
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
836
+ // algorithm
837
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(obj.digestAlgorithm).getBytes()),
838
+ // parameters (null)
839
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')])]);
840
+
841
+ // authenticatedAttributes (OPTIONAL)
842
+ if (obj.authenticatedAttributesAsn1) {
843
+ // add ASN.1 previously generated during signing
844
+ rval.value.push(obj.authenticatedAttributesAsn1);
845
+ }
846
+
847
+ // digestEncryptionAlgorithm
848
+ rval.value.push(asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
849
+ // algorithm
850
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(obj.signatureAlgorithm).getBytes()),
851
+ // parameters (null)
852
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')]));
853
+
854
+ // encryptedDigest
855
+ rval.value.push(asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, obj.signature));
856
+
857
+ // unauthenticatedAttributes (OPTIONAL)
858
+ if (obj.unauthenticatedAttributes.length > 0) {
859
+ // [1] IMPLICIT
860
+ var attrsAsn1 = asn1.create(asn1.Class.CONTEXT_SPECIFIC, 1, true, []);
861
+ for (var i = 0; i < obj.unauthenticatedAttributes.length; ++i) {
862
+ var attr = obj.unauthenticatedAttributes[i];
863
+ attrsAsn1.values.push(_attributeToAsn1(attr));
864
+ }
865
+ rval.value.push(attrsAsn1);
866
+ }
867
+ return rval;
868
+ }
869
+
870
+ /**
871
+ * Map an array of signer objects to ASN.1 objects.
872
+ *
873
+ * @param signers an array of signer objects.
874
+ *
875
+ * @return an array of ASN.1 SignerInfos.
876
+ */
877
+ function _signersToAsn1(signers) {
878
+ var ret = [];
879
+ for (var i = 0; i < signers.length; ++i) {
880
+ ret.push(_signerToAsn1(signers[i]));
881
+ }
882
+ return ret;
883
+ }
884
+
885
+ /**
886
+ * Convert an attribute object to an ASN.1 Attribute.
887
+ *
888
+ * @param attr the attribute object.
889
+ *
890
+ * @return the ASN.1 Attribute.
891
+ */
892
+ function _attributeToAsn1(attr) {
893
+ var value;
894
+
895
+ // TODO: generalize to support more attributes
896
+ if (attr.type === forge.pki.oids.contentType) {
897
+ value = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(attr.value).getBytes());
898
+ } else if (attr.type === forge.pki.oids.messageDigest) {
899
+ value = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, attr.value.bytes());
900
+ } else if (attr.type === forge.pki.oids.signingTime) {
901
+ /* Note per RFC 2985: Dates between 1 January 1950 and 31 December 2049
902
+ (inclusive) MUST be encoded as UTCTime. Any dates with year values
903
+ before 1950 or after 2049 MUST be encoded as GeneralizedTime. [Further,]
904
+ UTCTime values MUST be expressed in Greenwich Mean Time (Zulu) and MUST
905
+ include seconds (i.e., times are YYMMDDHHMMSSZ), even where the
906
+ number of seconds is zero. Midnight (GMT) must be represented as
907
+ "YYMMDD000000Z". */
908
+ // TODO: make these module-level constants
909
+ var jan_1_1950 = new Date('1950-01-01T00:00:00Z');
910
+ var jan_1_2050 = new Date('2050-01-01T00:00:00Z');
911
+ var date = attr.value;
912
+ if (typeof date === 'string') {
913
+ // try to parse date
914
+ var timestamp = Date.parse(date);
915
+ if (!isNaN(timestamp)) {
916
+ date = new Date(timestamp);
917
+ } else if (date.length === 13) {
918
+ // YYMMDDHHMMSSZ (13 chars for UTCTime)
919
+ date = asn1.utcTimeToDate(date);
920
+ } else {
921
+ // assume generalized time
922
+ date = asn1.generalizedTimeToDate(date);
923
+ }
924
+ }
925
+ if (date >= jan_1_1950 && date < jan_1_2050) {
926
+ value = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.UTCTIME, false, asn1.dateToUtcTime(date));
927
+ } else {
928
+ value = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.GENERALIZEDTIME, false, asn1.dateToGeneralizedTime(date));
929
+ }
930
+ }
931
+
932
+ // TODO: expose as common API call
933
+ // create a RelativeDistinguishedName set
934
+ // each value in the set is an AttributeTypeAndValue first
935
+ // containing the type (an OID) and second the value
936
+ return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
937
+ // AttributeType
938
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(attr.type).getBytes()), asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, [
939
+ // AttributeValue
940
+ value])]);
941
+ }
942
+
943
+ /**
944
+ * Map messages encrypted content to ASN.1 objects.
945
+ *
946
+ * @param ec The encryptedContent object of the message.
947
+ *
948
+ * @return ASN.1 representation of the encryptedContent object (SEQUENCE).
949
+ */
950
+ function _encryptedContentToAsn1(ec) {
951
+ return [
952
+ // ContentType, always Data for the moment
953
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(forge.pki.oids.data).getBytes()),
954
+ // ContentEncryptionAlgorithmIdentifier
955
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
956
+ // Algorithm
957
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(ec.algorithm).getBytes()),
958
+ // Parameters (IV)
959
+ !ec.parameter ? undefined : asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, ec.parameter.getBytes())]),
960
+ // [0] EncryptedContent
961
+ asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, ec.content.getBytes())])];
962
+ }
963
+
964
+ /**
965
+ * Reads the "common part" of an PKCS#7 content block (in ASN.1 format)
966
+ *
967
+ * This function reads the "common part" of the PKCS#7 content blocks
968
+ * EncryptedData and EnvelopedData, i.e. version number and symmetrically
969
+ * encrypted content block.
970
+ *
971
+ * The result of the ASN.1 validate and capture process is returned
972
+ * to allow the caller to extract further data, e.g. the list of recipients
973
+ * in case of a EnvelopedData object.
974
+ *
975
+ * @param msg the PKCS#7 object to read the data to.
976
+ * @param obj the ASN.1 representation of the content block.
977
+ * @param validator the ASN.1 structure validator object to use.
978
+ *
979
+ * @return the value map captured by validator object.
980
+ */
981
+ function _fromAsn1(msg, obj, validator) {
982
+ var capture = {};
983
+ var errors = [];
984
+ if (!asn1.validate(obj, validator, capture, errors)) {
985
+ var error = new Error('Cannot read PKCS#7 message. ' + 'ASN.1 object is not a supported PKCS#7 message.');
986
+ error.errors = error;
987
+ throw error;
988
+ }
989
+
990
+ // Check contentType, so far we only support (raw) Data.
991
+ var contentType = asn1.derToOid(capture.contentType);
992
+ if (contentType !== forge.pki.oids.data) {
993
+ throw new Error('Unsupported PKCS#7 message. ' + 'Only wrapped ContentType Data supported.');
994
+ }
995
+ if (capture.encryptedContent) {
996
+ var content = '';
997
+ if (forge.util.isArray(capture.encryptedContent)) {
998
+ for (var i = 0; i < capture.encryptedContent.length; ++i) {
999
+ if (capture.encryptedContent[i].type !== asn1.Type.OCTETSTRING) {
1000
+ throw new Error('Malformed PKCS#7 message, expecting encrypted ' + 'content constructed of only OCTET STRING objects.');
1001
+ }
1002
+ content += capture.encryptedContent[i].value;
1003
+ }
1004
+ } else {
1005
+ content = capture.encryptedContent;
1006
+ }
1007
+ msg.encryptedContent = {
1008
+ algorithm: asn1.derToOid(capture.encAlgorithm),
1009
+ parameter: forge.util.createBuffer(capture.encParameter.value),
1010
+ content: forge.util.createBuffer(content)
1011
+ };
1012
+ }
1013
+ if (capture.content) {
1014
+ var content = '';
1015
+ if (forge.util.isArray(capture.content)) {
1016
+ for (var i = 0; i < capture.content.length; ++i) {
1017
+ if (capture.content[i].type !== asn1.Type.OCTETSTRING) {
1018
+ throw new Error('Malformed PKCS#7 message, expecting ' + 'content constructed of only OCTET STRING objects.');
1019
+ }
1020
+ content += capture.content[i].value;
1021
+ }
1022
+ } else {
1023
+ content = capture.content;
1024
+ }
1025
+ msg.content = forge.util.createBuffer(content);
1026
+ }
1027
+ msg.version = capture.version.charCodeAt(0);
1028
+ msg.rawCapture = capture;
1029
+ return capture;
1030
+ }
1031
+
1032
+ /**
1033
+ * Decrypt the symmetrically encrypted content block of the PKCS#7 message.
1034
+ *
1035
+ * Decryption is skipped in case the PKCS#7 message object already has a
1036
+ * (decrypted) content attribute. The algorithm, key and cipher parameters
1037
+ * (probably the iv) are taken from the encryptedContent attribute of the
1038
+ * message object.
1039
+ *
1040
+ * @param The PKCS#7 message object.
1041
+ */
1042
+ function _decryptContent(msg) {
1043
+ if (msg.encryptedContent.key === undefined) {
1044
+ throw new Error('Symmetric key not available.');
1045
+ }
1046
+ if (msg.content === undefined) {
1047
+ var ciph;
1048
+ switch (msg.encryptedContent.algorithm) {
1049
+ case forge.pki.oids['aes128-CBC']:
1050
+ case forge.pki.oids['aes192-CBC']:
1051
+ case forge.pki.oids['aes256-CBC']:
1052
+ ciph = forge.aes.createDecryptionCipher(msg.encryptedContent.key);
1053
+ break;
1054
+ case forge.pki.oids['desCBC']:
1055
+ case forge.pki.oids['des-EDE3-CBC']:
1056
+ ciph = forge.des.createDecryptionCipher(msg.encryptedContent.key);
1057
+ break;
1058
+ default:
1059
+ throw new Error('Unsupported symmetric cipher, OID ' + msg.encryptedContent.algorithm);
1060
+ }
1061
+ ciph.start(msg.encryptedContent.parameter);
1062
+ ciph.update(msg.encryptedContent.content);
1063
+ if (!ciph.finish()) {
1064
+ throw new Error('Symmetric decryption failed.');
1065
+ }
1066
+ msg.content = ciph.output;
1067
+ }
1068
+ }
1069
+ return pkcs7.exports;
1070
+ }
1071
+
1072
+ export { requirePkcs7 as __require };
1073
+ //# sourceMappingURL=pkcs7.js.map