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,966 @@
1
+ import { __require as requireForge } from './forge.js';
2
+ import { __require as requireAes } from './aes.js';
3
+ import { __require as requireAsn1 } from './asn1.js';
4
+ import { __require as requireDes } from './des.js';
5
+ import { __require as requireMd } from './md.js';
6
+ import { __require as requireOids } from './oids.js';
7
+ import { __require as requirePbkdf2 } from './pbkdf2.js';
8
+ import { __require as requirePem } from './pem.js';
9
+ import { __require as requireRandom } from './random.js';
10
+ import { __require as requireRc2 } from './rc2.js';
11
+ import { __require as requireRsa } from './rsa.js';
12
+ import { __require as requireUtil } from './util.js';
13
+
14
+ /**
15
+ * Password-based encryption functions.
16
+ *
17
+ * @author Dave Longley
18
+ * @author Stefan Siegl <stesie@brokenpipe.de>
19
+ *
20
+ * Copyright (c) 2010-2013 Digital Bazaar, Inc.
21
+ * Copyright (c) 2012 Stefan Siegl <stesie@brokenpipe.de>
22
+ *
23
+ * An EncryptedPrivateKeyInfo:
24
+ *
25
+ * EncryptedPrivateKeyInfo ::= SEQUENCE {
26
+ * encryptionAlgorithm EncryptionAlgorithmIdentifier,
27
+ * encryptedData EncryptedData }
28
+ *
29
+ * EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
30
+ *
31
+ * EncryptedData ::= OCTET STRING
32
+ */
33
+ var pbe;
34
+ var hasRequiredPbe;
35
+ function requirePbe() {
36
+ if (hasRequiredPbe) return pbe;
37
+ hasRequiredPbe = 1;
38
+ var forge = requireForge();
39
+ requireAes();
40
+ requireAsn1();
41
+ requireDes();
42
+ requireMd();
43
+ requireOids();
44
+ requirePbkdf2();
45
+ requirePem();
46
+ requireRandom();
47
+ requireRc2();
48
+ requireRsa();
49
+ requireUtil();
50
+ if (typeof BigInteger === 'undefined') {
51
+ var BigInteger = forge.jsbn.BigInteger;
52
+ }
53
+
54
+ // shortcut for asn.1 API
55
+ var asn1 = forge.asn1;
56
+
57
+ /* Password-based encryption implementation. */
58
+ var pki = forge.pki = forge.pki || {};
59
+ pbe = pki.pbe = forge.pbe = forge.pbe || {};
60
+ var oids = pki.oids;
61
+
62
+ // validator for an EncryptedPrivateKeyInfo structure
63
+ // Note: Currently only works w/algorithm params
64
+ var encryptedPrivateKeyValidator = {
65
+ name: 'EncryptedPrivateKeyInfo',
66
+ tagClass: asn1.Class.UNIVERSAL,
67
+ type: asn1.Type.SEQUENCE,
68
+ constructed: true,
69
+ value: [{
70
+ name: 'EncryptedPrivateKeyInfo.encryptionAlgorithm',
71
+ tagClass: asn1.Class.UNIVERSAL,
72
+ type: asn1.Type.SEQUENCE,
73
+ constructed: true,
74
+ value: [{
75
+ name: 'AlgorithmIdentifier.algorithm',
76
+ tagClass: asn1.Class.UNIVERSAL,
77
+ type: asn1.Type.OID,
78
+ constructed: false,
79
+ capture: 'encryptionOid'
80
+ }, {
81
+ name: 'AlgorithmIdentifier.parameters',
82
+ tagClass: asn1.Class.UNIVERSAL,
83
+ type: asn1.Type.SEQUENCE,
84
+ constructed: true,
85
+ captureAsn1: 'encryptionParams'
86
+ }]
87
+ }, {
88
+ // encryptedData
89
+ name: 'EncryptedPrivateKeyInfo.encryptedData',
90
+ tagClass: asn1.Class.UNIVERSAL,
91
+ type: asn1.Type.OCTETSTRING,
92
+ constructed: false,
93
+ capture: 'encryptedData'
94
+ }]
95
+ };
96
+
97
+ // validator for a PBES2Algorithms structure
98
+ // Note: Currently only works w/PBKDF2 + AES encryption schemes
99
+ var PBES2AlgorithmsValidator = {
100
+ name: 'PBES2Algorithms',
101
+ tagClass: asn1.Class.UNIVERSAL,
102
+ type: asn1.Type.SEQUENCE,
103
+ constructed: true,
104
+ value: [{
105
+ name: 'PBES2Algorithms.keyDerivationFunc',
106
+ tagClass: asn1.Class.UNIVERSAL,
107
+ type: asn1.Type.SEQUENCE,
108
+ constructed: true,
109
+ value: [{
110
+ name: 'PBES2Algorithms.keyDerivationFunc.oid',
111
+ tagClass: asn1.Class.UNIVERSAL,
112
+ type: asn1.Type.OID,
113
+ constructed: false,
114
+ capture: 'kdfOid'
115
+ }, {
116
+ name: 'PBES2Algorithms.params',
117
+ tagClass: asn1.Class.UNIVERSAL,
118
+ type: asn1.Type.SEQUENCE,
119
+ constructed: true,
120
+ value: [{
121
+ name: 'PBES2Algorithms.params.salt',
122
+ tagClass: asn1.Class.UNIVERSAL,
123
+ type: asn1.Type.OCTETSTRING,
124
+ constructed: false,
125
+ capture: 'kdfSalt'
126
+ }, {
127
+ name: 'PBES2Algorithms.params.iterationCount',
128
+ tagClass: asn1.Class.UNIVERSAL,
129
+ type: asn1.Type.INTEGER,
130
+ constructed: false,
131
+ capture: 'kdfIterationCount'
132
+ }, {
133
+ name: 'PBES2Algorithms.params.keyLength',
134
+ tagClass: asn1.Class.UNIVERSAL,
135
+ type: asn1.Type.INTEGER,
136
+ constructed: false,
137
+ optional: true,
138
+ capture: 'keyLength'
139
+ }, {
140
+ // prf
141
+ name: 'PBES2Algorithms.params.prf',
142
+ tagClass: asn1.Class.UNIVERSAL,
143
+ type: asn1.Type.SEQUENCE,
144
+ constructed: true,
145
+ optional: true,
146
+ value: [{
147
+ name: 'PBES2Algorithms.params.prf.algorithm',
148
+ tagClass: asn1.Class.UNIVERSAL,
149
+ type: asn1.Type.OID,
150
+ constructed: false,
151
+ capture: 'prfOid'
152
+ }]
153
+ }]
154
+ }]
155
+ }, {
156
+ name: 'PBES2Algorithms.encryptionScheme',
157
+ tagClass: asn1.Class.UNIVERSAL,
158
+ type: asn1.Type.SEQUENCE,
159
+ constructed: true,
160
+ value: [{
161
+ name: 'PBES2Algorithms.encryptionScheme.oid',
162
+ tagClass: asn1.Class.UNIVERSAL,
163
+ type: asn1.Type.OID,
164
+ constructed: false,
165
+ capture: 'encOid'
166
+ }, {
167
+ name: 'PBES2Algorithms.encryptionScheme.iv',
168
+ tagClass: asn1.Class.UNIVERSAL,
169
+ type: asn1.Type.OCTETSTRING,
170
+ constructed: false,
171
+ capture: 'encIv'
172
+ }]
173
+ }]
174
+ };
175
+ var pkcs12PbeParamsValidator = {
176
+ name: 'pkcs-12PbeParams',
177
+ tagClass: asn1.Class.UNIVERSAL,
178
+ type: asn1.Type.SEQUENCE,
179
+ constructed: true,
180
+ value: [{
181
+ name: 'pkcs-12PbeParams.salt',
182
+ tagClass: asn1.Class.UNIVERSAL,
183
+ type: asn1.Type.OCTETSTRING,
184
+ constructed: false,
185
+ capture: 'salt'
186
+ }, {
187
+ name: 'pkcs-12PbeParams.iterations',
188
+ tagClass: asn1.Class.UNIVERSAL,
189
+ type: asn1.Type.INTEGER,
190
+ constructed: false,
191
+ capture: 'iterations'
192
+ }]
193
+ };
194
+
195
+ /**
196
+ * Encrypts a ASN.1 PrivateKeyInfo object, producing an EncryptedPrivateKeyInfo.
197
+ *
198
+ * PBES2Algorithms ALGORITHM-IDENTIFIER ::=
199
+ * { {PBES2-params IDENTIFIED BY id-PBES2}, ...}
200
+ *
201
+ * id-PBES2 OBJECT IDENTIFIER ::= {pkcs-5 13}
202
+ *
203
+ * PBES2-params ::= SEQUENCE {
204
+ * keyDerivationFunc AlgorithmIdentifier {{PBES2-KDFs}},
205
+ * encryptionScheme AlgorithmIdentifier {{PBES2-Encs}}
206
+ * }
207
+ *
208
+ * PBES2-KDFs ALGORITHM-IDENTIFIER ::=
209
+ * { {PBKDF2-params IDENTIFIED BY id-PBKDF2}, ... }
210
+ *
211
+ * PBES2-Encs ALGORITHM-IDENTIFIER ::= { ... }
212
+ *
213
+ * PBKDF2-params ::= SEQUENCE {
214
+ * salt CHOICE {
215
+ * specified OCTET STRING,
216
+ * otherSource AlgorithmIdentifier {{PBKDF2-SaltSources}}
217
+ * },
218
+ * iterationCount INTEGER (1..MAX),
219
+ * keyLength INTEGER (1..MAX) OPTIONAL,
220
+ * prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT algid-hmacWithSHA1
221
+ * }
222
+ *
223
+ * @param obj the ASN.1 PrivateKeyInfo object.
224
+ * @param password the password to encrypt with.
225
+ * @param options:
226
+ * algorithm the encryption algorithm to use
227
+ * ('aes128', 'aes192', 'aes256', '3des'), defaults to 'aes128'.
228
+ * count the iteration count to use.
229
+ * saltSize the salt size to use.
230
+ * prfAlgorithm the PRF message digest algorithm to use
231
+ * ('sha1', 'sha224', 'sha256', 'sha384', 'sha512')
232
+ *
233
+ * @return the ASN.1 EncryptedPrivateKeyInfo.
234
+ */
235
+ pki.encryptPrivateKeyInfo = function (obj, password, options) {
236
+ // set default options
237
+ options = options || {};
238
+ options.saltSize = options.saltSize || 8;
239
+ options.count = options.count || 2048;
240
+ options.algorithm = options.algorithm || 'aes128';
241
+ options.prfAlgorithm = options.prfAlgorithm || 'sha1';
242
+
243
+ // generate PBE params
244
+ var salt = forge.random.getBytesSync(options.saltSize);
245
+ var count = options.count;
246
+ var countBytes = asn1.integerToDer(count);
247
+ var dkLen;
248
+ var encryptionAlgorithm;
249
+ var encryptedData;
250
+ if (options.algorithm.indexOf('aes') === 0 || options.algorithm === 'des') {
251
+ // do PBES2
252
+ var ivLen, encOid, cipherFn;
253
+ switch (options.algorithm) {
254
+ case 'aes128':
255
+ dkLen = 16;
256
+ ivLen = 16;
257
+ encOid = oids['aes128-CBC'];
258
+ cipherFn = forge.aes.createEncryptionCipher;
259
+ break;
260
+ case 'aes192':
261
+ dkLen = 24;
262
+ ivLen = 16;
263
+ encOid = oids['aes192-CBC'];
264
+ cipherFn = forge.aes.createEncryptionCipher;
265
+ break;
266
+ case 'aes256':
267
+ dkLen = 32;
268
+ ivLen = 16;
269
+ encOid = oids['aes256-CBC'];
270
+ cipherFn = forge.aes.createEncryptionCipher;
271
+ break;
272
+ case 'des':
273
+ dkLen = 8;
274
+ ivLen = 8;
275
+ encOid = oids['desCBC'];
276
+ cipherFn = forge.des.createEncryptionCipher;
277
+ break;
278
+ default:
279
+ var error = new Error('Cannot encrypt private key. Unknown encryption algorithm.');
280
+ error.algorithm = options.algorithm;
281
+ throw error;
282
+ }
283
+
284
+ // get PRF message digest
285
+ var prfAlgorithm = 'hmacWith' + options.prfAlgorithm.toUpperCase();
286
+ var md = prfAlgorithmToMessageDigest(prfAlgorithm);
287
+
288
+ // encrypt private key using pbe SHA-1 and AES/DES
289
+ var dk = forge.pkcs5.pbkdf2(password, salt, count, dkLen, md);
290
+ var iv = forge.random.getBytesSync(ivLen);
291
+ var cipher = cipherFn(dk);
292
+ cipher.start(iv);
293
+ cipher.update(asn1.toDer(obj));
294
+ cipher.finish();
295
+ encryptedData = cipher.output.getBytes();
296
+
297
+ // get PBKDF2-params
298
+ var params = createPbkdf2Params(salt, countBytes, dkLen, prfAlgorithm);
299
+ encryptionAlgorithm = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(oids['pkcs5PBES2']).getBytes()), asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
300
+ // keyDerivationFunc
301
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(oids['pkcs5PBKDF2']).getBytes()),
302
+ // PBKDF2-params
303
+ params]),
304
+ // encryptionScheme
305
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(encOid).getBytes()),
306
+ // iv
307
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, iv)])])]);
308
+ } else if (options.algorithm === '3des') {
309
+ // Do PKCS12 PBE
310
+ dkLen = 24;
311
+ var saltBytes = new forge.util.ByteBuffer(salt);
312
+ var dk = pki.pbe.generatePkcs12Key(password, saltBytes, 1, count, dkLen);
313
+ var iv = pki.pbe.generatePkcs12Key(password, saltBytes, 2, count, dkLen);
314
+ var cipher = forge.des.createEncryptionCipher(dk);
315
+ cipher.start(iv);
316
+ cipher.update(asn1.toDer(obj));
317
+ cipher.finish();
318
+ encryptedData = cipher.output.getBytes();
319
+ encryptionAlgorithm = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(oids['pbeWithSHAAnd3-KeyTripleDES-CBC']).getBytes()),
320
+ // pkcs-12PbeParams
321
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
322
+ // salt
323
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, salt),
324
+ // iteration count
325
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false, countBytes.getBytes())])]);
326
+ } else {
327
+ var error = new Error('Cannot encrypt private key. Unknown encryption algorithm.');
328
+ error.algorithm = options.algorithm;
329
+ throw error;
330
+ }
331
+
332
+ // EncryptedPrivateKeyInfo
333
+ var rval = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
334
+ // encryptionAlgorithm
335
+ encryptionAlgorithm,
336
+ // encryptedData
337
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, encryptedData)]);
338
+ return rval;
339
+ };
340
+
341
+ /**
342
+ * Decrypts a ASN.1 PrivateKeyInfo object.
343
+ *
344
+ * @param obj the ASN.1 EncryptedPrivateKeyInfo object.
345
+ * @param password the password to decrypt with.
346
+ *
347
+ * @return the ASN.1 PrivateKeyInfo on success, null on failure.
348
+ */
349
+ pki.decryptPrivateKeyInfo = function (obj, password) {
350
+ var rval = null;
351
+
352
+ // get PBE params
353
+ var capture = {};
354
+ var errors = [];
355
+ if (!asn1.validate(obj, encryptedPrivateKeyValidator, capture, errors)) {
356
+ var error = new Error('Cannot read encrypted private key. ' + 'ASN.1 object is not a supported EncryptedPrivateKeyInfo.');
357
+ error.errors = errors;
358
+ throw error;
359
+ }
360
+
361
+ // get cipher
362
+ var oid = asn1.derToOid(capture.encryptionOid);
363
+ var cipher = pki.pbe.getCipher(oid, capture.encryptionParams, password);
364
+
365
+ // get encrypted data
366
+ var encrypted = forge.util.createBuffer(capture.encryptedData);
367
+ cipher.update(encrypted);
368
+ if (cipher.finish()) {
369
+ rval = asn1.fromDer(cipher.output);
370
+ }
371
+ return rval;
372
+ };
373
+
374
+ /**
375
+ * Converts a EncryptedPrivateKeyInfo to PEM format.
376
+ *
377
+ * @param epki the EncryptedPrivateKeyInfo.
378
+ * @param maxline the maximum characters per line, defaults to 64.
379
+ *
380
+ * @return the PEM-formatted encrypted private key.
381
+ */
382
+ pki.encryptedPrivateKeyToPem = function (epki, maxline) {
383
+ // convert to DER, then PEM-encode
384
+ var msg = {
385
+ type: 'ENCRYPTED PRIVATE KEY',
386
+ body: asn1.toDer(epki).getBytes()
387
+ };
388
+ return forge.pem.encode(msg, {
389
+ maxline: maxline
390
+ });
391
+ };
392
+
393
+ /**
394
+ * Converts a PEM-encoded EncryptedPrivateKeyInfo to ASN.1 format. Decryption
395
+ * is not performed.
396
+ *
397
+ * @param pem the EncryptedPrivateKeyInfo in PEM-format.
398
+ *
399
+ * @return the ASN.1 EncryptedPrivateKeyInfo.
400
+ */
401
+ pki.encryptedPrivateKeyFromPem = function (pem) {
402
+ var msg = forge.pem.decode(pem)[0];
403
+ if (msg.type !== 'ENCRYPTED PRIVATE KEY') {
404
+ var error = new Error('Could not convert encrypted private key from PEM; ' + 'PEM header type is "ENCRYPTED PRIVATE KEY".');
405
+ error.headerType = msg.type;
406
+ throw error;
407
+ }
408
+ if (msg.procType && msg.procType.type === 'ENCRYPTED') {
409
+ throw new Error('Could not convert encrypted private key from PEM; ' + 'PEM is encrypted.');
410
+ }
411
+
412
+ // convert DER to ASN.1 object
413
+ return asn1.fromDer(msg.body);
414
+ };
415
+
416
+ /**
417
+ * Encrypts an RSA private key. By default, the key will be wrapped in
418
+ * a PrivateKeyInfo and encrypted to produce a PKCS#8 EncryptedPrivateKeyInfo.
419
+ * This is the standard, preferred way to encrypt a private key.
420
+ *
421
+ * To produce a non-standard PEM-encrypted private key that uses encapsulated
422
+ * headers to indicate the encryption algorithm (old-style non-PKCS#8 OpenSSL
423
+ * private key encryption), set the 'legacy' option to true. Note: Using this
424
+ * option will cause the iteration count to be forced to 1.
425
+ *
426
+ * Note: The 'des' algorithm is supported, but it is not considered to be
427
+ * secure because it only uses a single 56-bit key. If possible, it is highly
428
+ * recommended that a different algorithm be used.
429
+ *
430
+ * @param rsaKey the RSA key to encrypt.
431
+ * @param password the password to use.
432
+ * @param options:
433
+ * algorithm: the encryption algorithm to use
434
+ * ('aes128', 'aes192', 'aes256', '3des', 'des').
435
+ * count: the iteration count to use.
436
+ * saltSize: the salt size to use.
437
+ * legacy: output an old non-PKCS#8 PEM-encrypted+encapsulated
438
+ * headers (DEK-Info) private key.
439
+ *
440
+ * @return the PEM-encoded ASN.1 EncryptedPrivateKeyInfo.
441
+ */
442
+ pki.encryptRsaPrivateKey = function (rsaKey, password, options) {
443
+ // standard PKCS#8
444
+ options = options || {};
445
+ if (!options.legacy) {
446
+ // encrypt PrivateKeyInfo
447
+ var rval = pki.wrapRsaPrivateKey(pki.privateKeyToAsn1(rsaKey));
448
+ rval = pki.encryptPrivateKeyInfo(rval, password, options);
449
+ return pki.encryptedPrivateKeyToPem(rval);
450
+ }
451
+
452
+ // legacy non-PKCS#8
453
+ var algorithm;
454
+ var iv;
455
+ var dkLen;
456
+ var cipherFn;
457
+ switch (options.algorithm) {
458
+ case 'aes128':
459
+ algorithm = 'AES-128-CBC';
460
+ dkLen = 16;
461
+ iv = forge.random.getBytesSync(16);
462
+ cipherFn = forge.aes.createEncryptionCipher;
463
+ break;
464
+ case 'aes192':
465
+ algorithm = 'AES-192-CBC';
466
+ dkLen = 24;
467
+ iv = forge.random.getBytesSync(16);
468
+ cipherFn = forge.aes.createEncryptionCipher;
469
+ break;
470
+ case 'aes256':
471
+ algorithm = 'AES-256-CBC';
472
+ dkLen = 32;
473
+ iv = forge.random.getBytesSync(16);
474
+ cipherFn = forge.aes.createEncryptionCipher;
475
+ break;
476
+ case '3des':
477
+ algorithm = 'DES-EDE3-CBC';
478
+ dkLen = 24;
479
+ iv = forge.random.getBytesSync(8);
480
+ cipherFn = forge.des.createEncryptionCipher;
481
+ break;
482
+ case 'des':
483
+ algorithm = 'DES-CBC';
484
+ dkLen = 8;
485
+ iv = forge.random.getBytesSync(8);
486
+ cipherFn = forge.des.createEncryptionCipher;
487
+ break;
488
+ default:
489
+ var error = new Error('Could not encrypt RSA private key; unsupported ' + 'encryption algorithm "' + options.algorithm + '".');
490
+ error.algorithm = options.algorithm;
491
+ throw error;
492
+ }
493
+
494
+ // encrypt private key using OpenSSL legacy key derivation
495
+ var dk = forge.pbe.opensslDeriveBytes(password, iv.substr(0, 8), dkLen);
496
+ var cipher = cipherFn(dk);
497
+ cipher.start(iv);
498
+ cipher.update(asn1.toDer(pki.privateKeyToAsn1(rsaKey)));
499
+ cipher.finish();
500
+ var msg = {
501
+ type: 'RSA PRIVATE KEY',
502
+ procType: {
503
+ version: '4',
504
+ type: 'ENCRYPTED'
505
+ },
506
+ dekInfo: {
507
+ algorithm: algorithm,
508
+ parameters: forge.util.bytesToHex(iv).toUpperCase()
509
+ },
510
+ body: cipher.output.getBytes()
511
+ };
512
+ return forge.pem.encode(msg);
513
+ };
514
+
515
+ /**
516
+ * Decrypts an RSA private key.
517
+ *
518
+ * @param pem the PEM-formatted EncryptedPrivateKeyInfo to decrypt.
519
+ * @param password the password to use.
520
+ *
521
+ * @return the RSA key on success, null on failure.
522
+ */
523
+ pki.decryptRsaPrivateKey = function (pem, password) {
524
+ var rval = null;
525
+ var msg = forge.pem.decode(pem)[0];
526
+ if (msg.type !== 'ENCRYPTED PRIVATE KEY' && msg.type !== 'PRIVATE KEY' && msg.type !== 'RSA PRIVATE KEY') {
527
+ var error = new Error('Could not convert private key from PEM; PEM header type ' + 'is not "ENCRYPTED PRIVATE KEY", "PRIVATE KEY", or "RSA PRIVATE KEY".');
528
+ error.headerType = error;
529
+ throw error;
530
+ }
531
+ if (msg.procType && msg.procType.type === 'ENCRYPTED') {
532
+ var dkLen;
533
+ var cipherFn;
534
+ switch (msg.dekInfo.algorithm) {
535
+ case 'DES-CBC':
536
+ dkLen = 8;
537
+ cipherFn = forge.des.createDecryptionCipher;
538
+ break;
539
+ case 'DES-EDE3-CBC':
540
+ dkLen = 24;
541
+ cipherFn = forge.des.createDecryptionCipher;
542
+ break;
543
+ case 'AES-128-CBC':
544
+ dkLen = 16;
545
+ cipherFn = forge.aes.createDecryptionCipher;
546
+ break;
547
+ case 'AES-192-CBC':
548
+ dkLen = 24;
549
+ cipherFn = forge.aes.createDecryptionCipher;
550
+ break;
551
+ case 'AES-256-CBC':
552
+ dkLen = 32;
553
+ cipherFn = forge.aes.createDecryptionCipher;
554
+ break;
555
+ case 'RC2-40-CBC':
556
+ dkLen = 5;
557
+ cipherFn = function (key) {
558
+ return forge.rc2.createDecryptionCipher(key, 40);
559
+ };
560
+ break;
561
+ case 'RC2-64-CBC':
562
+ dkLen = 8;
563
+ cipherFn = function (key) {
564
+ return forge.rc2.createDecryptionCipher(key, 64);
565
+ };
566
+ break;
567
+ case 'RC2-128-CBC':
568
+ dkLen = 16;
569
+ cipherFn = function (key) {
570
+ return forge.rc2.createDecryptionCipher(key, 128);
571
+ };
572
+ break;
573
+ default:
574
+ var error = new Error('Could not decrypt private key; unsupported ' + 'encryption algorithm "' + msg.dekInfo.algorithm + '".');
575
+ error.algorithm = msg.dekInfo.algorithm;
576
+ throw error;
577
+ }
578
+
579
+ // use OpenSSL legacy key derivation
580
+ var iv = forge.util.hexToBytes(msg.dekInfo.parameters);
581
+ var dk = forge.pbe.opensslDeriveBytes(password, iv.substr(0, 8), dkLen);
582
+ var cipher = cipherFn(dk);
583
+ cipher.start(iv);
584
+ cipher.update(forge.util.createBuffer(msg.body));
585
+ if (cipher.finish()) {
586
+ rval = cipher.output.getBytes();
587
+ } else {
588
+ return rval;
589
+ }
590
+ } else {
591
+ rval = msg.body;
592
+ }
593
+ if (msg.type === 'ENCRYPTED PRIVATE KEY') {
594
+ rval = pki.decryptPrivateKeyInfo(asn1.fromDer(rval), password);
595
+ } else {
596
+ // decryption already performed above
597
+ rval = asn1.fromDer(rval);
598
+ }
599
+ if (rval !== null) {
600
+ rval = pki.privateKeyFromAsn1(rval);
601
+ }
602
+ return rval;
603
+ };
604
+
605
+ /**
606
+ * Derives a PKCS#12 key.
607
+ *
608
+ * @param password the password to derive the key material from, null or
609
+ * undefined for none.
610
+ * @param salt the salt, as a ByteBuffer, to use.
611
+ * @param id the PKCS#12 ID byte (1 = key material, 2 = IV, 3 = MAC).
612
+ * @param iter the iteration count.
613
+ * @param n the number of bytes to derive from the password.
614
+ * @param md the message digest to use, defaults to SHA-1.
615
+ *
616
+ * @return a ByteBuffer with the bytes derived from the password.
617
+ */
618
+ pki.pbe.generatePkcs12Key = function (password, salt, id, iter, n, md) {
619
+ var j, l;
620
+ if (typeof md === 'undefined' || md === null) {
621
+ if (!('sha1' in forge.md)) {
622
+ throw new Error('"sha1" hash algorithm unavailable.');
623
+ }
624
+ md = forge.md.sha1.create();
625
+ }
626
+ var u = md.digestLength;
627
+ var v = md.blockLength;
628
+ var result = new forge.util.ByteBuffer();
629
+
630
+ /* Convert password to Unicode byte buffer + trailing 0-byte. */
631
+ var passBuf = new forge.util.ByteBuffer();
632
+ if (password !== null && password !== undefined) {
633
+ for (l = 0; l < password.length; l++) {
634
+ passBuf.putInt16(password.charCodeAt(l));
635
+ }
636
+ passBuf.putInt16(0);
637
+ }
638
+
639
+ /* Length of salt and password in BYTES. */
640
+ var p = passBuf.length();
641
+ var s = salt.length();
642
+
643
+ /* 1. Construct a string, D (the "diversifier"), by concatenating
644
+ v copies of ID. */
645
+ var D = new forge.util.ByteBuffer();
646
+ D.fillWithByte(id, v);
647
+
648
+ /* 2. Concatenate copies of the salt together to create a string S of length
649
+ v * ceil(s / v) bytes (the final copy of the salt may be trunacted
650
+ to create S).
651
+ Note that if the salt is the empty string, then so is S. */
652
+ var Slen = v * Math.ceil(s / v);
653
+ var S = new forge.util.ByteBuffer();
654
+ for (l = 0; l < Slen; l++) {
655
+ S.putByte(salt.at(l % s));
656
+ }
657
+
658
+ /* 3. Concatenate copies of the password together to create a string P of
659
+ length v * ceil(p / v) bytes (the final copy of the password may be
660
+ truncated to create P).
661
+ Note that if the password is the empty string, then so is P. */
662
+ var Plen = v * Math.ceil(p / v);
663
+ var P = new forge.util.ByteBuffer();
664
+ for (l = 0; l < Plen; l++) {
665
+ P.putByte(passBuf.at(l % p));
666
+ }
667
+
668
+ /* 4. Set I=S||P to be the concatenation of S and P. */
669
+ var I = S;
670
+ I.putBuffer(P);
671
+
672
+ /* 5. Set c=ceil(n / u). */
673
+ var c = Math.ceil(n / u);
674
+
675
+ /* 6. For i=1, 2, ..., c, do the following: */
676
+ for (var i = 1; i <= c; i++) {
677
+ /* a) Set Ai=H^r(D||I). (l.e. the rth hash of D||I, H(H(H(...H(D||I)))) */
678
+ var buf = new forge.util.ByteBuffer();
679
+ buf.putBytes(D.bytes());
680
+ buf.putBytes(I.bytes());
681
+ for (var round = 0; round < iter; round++) {
682
+ md.start();
683
+ md.update(buf.getBytes());
684
+ buf = md.digest();
685
+ }
686
+
687
+ /* b) Concatenate copies of Ai to create a string B of length v bytes (the
688
+ final copy of Ai may be truncated to create B). */
689
+ var B = new forge.util.ByteBuffer();
690
+ for (l = 0; l < v; l++) {
691
+ B.putByte(buf.at(l % u));
692
+ }
693
+
694
+ /* c) Treating I as a concatenation I0, I1, ..., Ik-1 of v-byte blocks,
695
+ where k=ceil(s / v) + ceil(p / v), modify I by setting
696
+ Ij=(Ij+B+1) mod 2v for each j. */
697
+ var k = Math.ceil(s / v) + Math.ceil(p / v);
698
+ var Inew = new forge.util.ByteBuffer();
699
+ for (j = 0; j < k; j++) {
700
+ var chunk = new forge.util.ByteBuffer(I.getBytes(v));
701
+ var x = 0x1ff;
702
+ for (l = B.length() - 1; l >= 0; l--) {
703
+ x = x >> 8;
704
+ x += B.at(l) + chunk.at(l);
705
+ chunk.setAt(l, x & 0xff);
706
+ }
707
+ Inew.putBuffer(chunk);
708
+ }
709
+ I = Inew;
710
+
711
+ /* Add Ai to A. */
712
+ result.putBuffer(buf);
713
+ }
714
+ result.truncate(result.length() - n);
715
+ return result;
716
+ };
717
+
718
+ /**
719
+ * Get new Forge cipher object instance.
720
+ *
721
+ * @param oid the OID (in string notation).
722
+ * @param params the ASN.1 params object.
723
+ * @param password the password to decrypt with.
724
+ *
725
+ * @return new cipher object instance.
726
+ */
727
+ pki.pbe.getCipher = function (oid, params, password) {
728
+ switch (oid) {
729
+ case pki.oids['pkcs5PBES2']:
730
+ return pki.pbe.getCipherForPBES2(oid, params, password);
731
+ case pki.oids['pbeWithSHAAnd3-KeyTripleDES-CBC']:
732
+ case pki.oids['pbewithSHAAnd40BitRC2-CBC']:
733
+ return pki.pbe.getCipherForPKCS12PBE(oid, params, password);
734
+ default:
735
+ var error = new Error('Cannot read encrypted PBE data block. Unsupported OID.');
736
+ error.oid = oid;
737
+ error.supportedOids = ['pkcs5PBES2', 'pbeWithSHAAnd3-KeyTripleDES-CBC', 'pbewithSHAAnd40BitRC2-CBC'];
738
+ throw error;
739
+ }
740
+ };
741
+
742
+ /**
743
+ * Get new Forge cipher object instance according to PBES2 params block.
744
+ *
745
+ * The returned cipher instance is already started using the IV
746
+ * from PBES2 parameter block.
747
+ *
748
+ * @param oid the PKCS#5 PBKDF2 OID (in string notation).
749
+ * @param params the ASN.1 PBES2-params object.
750
+ * @param password the password to decrypt with.
751
+ *
752
+ * @return new cipher object instance.
753
+ */
754
+ pki.pbe.getCipherForPBES2 = function (oid, params, password) {
755
+ // get PBE params
756
+ var capture = {};
757
+ var errors = [];
758
+ if (!asn1.validate(params, PBES2AlgorithmsValidator, capture, errors)) {
759
+ var error = new Error('Cannot read password-based-encryption algorithm ' + 'parameters. ASN.1 object is not a supported EncryptedPrivateKeyInfo.');
760
+ error.errors = errors;
761
+ throw error;
762
+ }
763
+
764
+ // check oids
765
+ oid = asn1.derToOid(capture.kdfOid);
766
+ if (oid !== pki.oids['pkcs5PBKDF2']) {
767
+ var error = new Error('Cannot read encrypted private key. ' + 'Unsupported key derivation function OID.');
768
+ error.oid = oid;
769
+ error.supportedOids = ['pkcs5PBKDF2'];
770
+ throw error;
771
+ }
772
+ oid = asn1.derToOid(capture.encOid);
773
+ if (oid !== pki.oids['aes128-CBC'] && oid !== pki.oids['aes192-CBC'] && oid !== pki.oids['aes256-CBC'] && oid !== pki.oids['des-EDE3-CBC'] && oid !== pki.oids['desCBC']) {
774
+ var error = new Error('Cannot read encrypted private key. ' + 'Unsupported encryption scheme OID.');
775
+ error.oid = oid;
776
+ error.supportedOids = ['aes128-CBC', 'aes192-CBC', 'aes256-CBC', 'des-EDE3-CBC', 'desCBC'];
777
+ throw error;
778
+ }
779
+
780
+ // set PBE params
781
+ var salt = capture.kdfSalt;
782
+ var count = forge.util.createBuffer(capture.kdfIterationCount);
783
+ count = count.getInt(count.length() << 3);
784
+ var dkLen;
785
+ var cipherFn;
786
+ switch (pki.oids[oid]) {
787
+ case 'aes128-CBC':
788
+ dkLen = 16;
789
+ cipherFn = forge.aes.createDecryptionCipher;
790
+ break;
791
+ case 'aes192-CBC':
792
+ dkLen = 24;
793
+ cipherFn = forge.aes.createDecryptionCipher;
794
+ break;
795
+ case 'aes256-CBC':
796
+ dkLen = 32;
797
+ cipherFn = forge.aes.createDecryptionCipher;
798
+ break;
799
+ case 'des-EDE3-CBC':
800
+ dkLen = 24;
801
+ cipherFn = forge.des.createDecryptionCipher;
802
+ break;
803
+ case 'desCBC':
804
+ dkLen = 8;
805
+ cipherFn = forge.des.createDecryptionCipher;
806
+ break;
807
+ }
808
+
809
+ // get PRF message digest
810
+ var md = prfOidToMessageDigest(capture.prfOid);
811
+
812
+ // decrypt private key using pbe with chosen PRF and AES/DES
813
+ var dk = forge.pkcs5.pbkdf2(password, salt, count, dkLen, md);
814
+ var iv = capture.encIv;
815
+ var cipher = cipherFn(dk);
816
+ cipher.start(iv);
817
+ return cipher;
818
+ };
819
+
820
+ /**
821
+ * Get new Forge cipher object instance for PKCS#12 PBE.
822
+ *
823
+ * The returned cipher instance is already started using the key & IV
824
+ * derived from the provided password and PKCS#12 PBE salt.
825
+ *
826
+ * @param oid The PKCS#12 PBE OID (in string notation).
827
+ * @param params The ASN.1 PKCS#12 PBE-params object.
828
+ * @param password The password to decrypt with.
829
+ *
830
+ * @return the new cipher object instance.
831
+ */
832
+ pki.pbe.getCipherForPKCS12PBE = function (oid, params, password) {
833
+ // get PBE params
834
+ var capture = {};
835
+ var errors = [];
836
+ if (!asn1.validate(params, pkcs12PbeParamsValidator, capture, errors)) {
837
+ var error = new Error('Cannot read password-based-encryption algorithm ' + 'parameters. ASN.1 object is not a supported EncryptedPrivateKeyInfo.');
838
+ error.errors = errors;
839
+ throw error;
840
+ }
841
+ var salt = forge.util.createBuffer(capture.salt);
842
+ var count = forge.util.createBuffer(capture.iterations);
843
+ count = count.getInt(count.length() << 3);
844
+ var dkLen, dIvLen, cipherFn;
845
+ switch (oid) {
846
+ case pki.oids['pbeWithSHAAnd3-KeyTripleDES-CBC']:
847
+ dkLen = 24;
848
+ dIvLen = 8;
849
+ cipherFn = forge.des.startDecrypting;
850
+ break;
851
+ case pki.oids['pbewithSHAAnd40BitRC2-CBC']:
852
+ dkLen = 5;
853
+ dIvLen = 8;
854
+ cipherFn = function (key, iv) {
855
+ var cipher = forge.rc2.createDecryptionCipher(key, 40);
856
+ cipher.start(iv, null);
857
+ return cipher;
858
+ };
859
+ break;
860
+ default:
861
+ var error = new Error('Cannot read PKCS #12 PBE data block. Unsupported OID.');
862
+ error.oid = oid;
863
+ throw error;
864
+ }
865
+
866
+ // get PRF message digest
867
+ var md = prfOidToMessageDigest(capture.prfOid);
868
+ var key = pki.pbe.generatePkcs12Key(password, salt, 1, count, dkLen, md);
869
+ md.start();
870
+ var iv = pki.pbe.generatePkcs12Key(password, salt, 2, count, dIvLen, md);
871
+ return cipherFn(key, iv);
872
+ };
873
+
874
+ /**
875
+ * OpenSSL's legacy key derivation function.
876
+ *
877
+ * See: http://www.openssl.org/docs/crypto/EVP_BytesToKey.html
878
+ *
879
+ * @param password the password to derive the key from.
880
+ * @param salt the salt to use, null for none.
881
+ * @param dkLen the number of bytes needed for the derived key.
882
+ * @param [options] the options to use:
883
+ * [md] an optional message digest object to use.
884
+ */
885
+ pki.pbe.opensslDeriveBytes = function (password, salt, dkLen, md) {
886
+ if (typeof md === 'undefined' || md === null) {
887
+ if (!('md5' in forge.md)) {
888
+ throw new Error('"md5" hash algorithm unavailable.');
889
+ }
890
+ md = forge.md.md5.create();
891
+ }
892
+ if (salt === null) {
893
+ salt = '';
894
+ }
895
+ var digests = [hash(md, password + salt)];
896
+ for (var length = 16, i = 1; length < dkLen; ++i, length += 16) {
897
+ digests.push(hash(md, digests[i - 1] + password + salt));
898
+ }
899
+ return digests.join('').substr(0, dkLen);
900
+ };
901
+ function hash(md, bytes) {
902
+ return md.start().update(bytes).digest().getBytes();
903
+ }
904
+ function prfOidToMessageDigest(prfOid) {
905
+ // get PRF algorithm, default to SHA-1
906
+ var prfAlgorithm;
907
+ if (!prfOid) {
908
+ prfAlgorithm = 'hmacWithSHA1';
909
+ } else {
910
+ prfAlgorithm = pki.oids[asn1.derToOid(prfOid)];
911
+ if (!prfAlgorithm) {
912
+ var error = new Error('Unsupported PRF OID.');
913
+ error.oid = prfOid;
914
+ error.supported = ['hmacWithSHA1', 'hmacWithSHA224', 'hmacWithSHA256', 'hmacWithSHA384', 'hmacWithSHA512'];
915
+ throw error;
916
+ }
917
+ }
918
+ return prfAlgorithmToMessageDigest(prfAlgorithm);
919
+ }
920
+ function prfAlgorithmToMessageDigest(prfAlgorithm) {
921
+ var factory = forge.md;
922
+ switch (prfAlgorithm) {
923
+ case 'hmacWithSHA224':
924
+ factory = forge.md.sha512;
925
+ case 'hmacWithSHA1':
926
+ case 'hmacWithSHA256':
927
+ case 'hmacWithSHA384':
928
+ case 'hmacWithSHA512':
929
+ prfAlgorithm = prfAlgorithm.substr(8).toLowerCase();
930
+ break;
931
+ default:
932
+ var error = new Error('Unsupported PRF algorithm.');
933
+ error.algorithm = prfAlgorithm;
934
+ error.supported = ['hmacWithSHA1', 'hmacWithSHA224', 'hmacWithSHA256', 'hmacWithSHA384', 'hmacWithSHA512'];
935
+ throw error;
936
+ }
937
+ if (!factory || !(prfAlgorithm in factory)) {
938
+ throw new Error('Unknown hash algorithm: ' + prfAlgorithm);
939
+ }
940
+ return factory[prfAlgorithm].create();
941
+ }
942
+ function createPbkdf2Params(salt, countBytes, dkLen, prfAlgorithm) {
943
+ var params = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
944
+ // salt
945
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, salt),
946
+ // iteration count
947
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false, countBytes.getBytes())]);
948
+ // when PRF algorithm is not SHA-1 default, add key length and PRF algorithm
949
+ if (prfAlgorithm !== 'hmacWithSHA1') {
950
+ params.value.push(
951
+ // key length
952
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false, forge.util.hexToBytes(dkLen.toString(16))),
953
+ // AlgorithmIdentifier
954
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
955
+ // algorithm
956
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(pki.oids[prfAlgorithm]).getBytes()),
957
+ // parameters (null)
958
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')]));
959
+ }
960
+ return params;
961
+ }
962
+ return pbe;
963
+ }
964
+
965
+ export { requirePbe as __require };
966
+ //# sourceMappingURL=pbe.js.map