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,1379 @@
1
+ import { __module as asn1 } from '../../../_virtual/asn1.js';
2
+ import { __require as requireForge } from './forge.js';
3
+ import { __require as requireUtil } from './util.js';
4
+ import { __require as requireOids } from './oids.js';
5
+
6
+ /**
7
+ * Javascript implementation of Abstract Syntax Notation Number One.
8
+ *
9
+ * @author Dave Longley
10
+ *
11
+ * Copyright (c) 2010-2015 Digital Bazaar, Inc.
12
+ *
13
+ * An API for storing data using the Abstract Syntax Notation Number One
14
+ * format using DER (Distinguished Encoding Rules) encoding. This encoding is
15
+ * commonly used to store data for PKI, i.e. X.509 Certificates, and this
16
+ * implementation exists for that purpose.
17
+ *
18
+ * Abstract Syntax Notation Number One (ASN.1) is used to define the abstract
19
+ * syntax of information without restricting the way the information is encoded
20
+ * for transmission. It provides a standard that allows for open systems
21
+ * communication. ASN.1 defines the syntax of information data and a number of
22
+ * simple data types as well as a notation for describing them and specifying
23
+ * values for them.
24
+ *
25
+ * The RSA algorithm creates public and private keys that are often stored in
26
+ * X.509 or PKCS#X formats -- which use ASN.1 (encoded in DER format). This
27
+ * class provides the most basic functionality required to store and load DSA
28
+ * keys that are encoded according to ASN.1.
29
+ *
30
+ * The most common binary encodings for ASN.1 are BER (Basic Encoding Rules)
31
+ * and DER (Distinguished Encoding Rules). DER is just a subset of BER that
32
+ * has stricter requirements for how data must be encoded.
33
+ *
34
+ * Each ASN.1 structure has a tag (a byte identifying the ASN.1 structure type)
35
+ * and a byte array for the value of this ASN1 structure which may be data or a
36
+ * list of ASN.1 structures.
37
+ *
38
+ * Each ASN.1 structure using BER is (Tag-Length-Value):
39
+ *
40
+ * | byte 0 | bytes X | bytes Y |
41
+ * |--------|---------|----------
42
+ * | tag | length | value |
43
+ *
44
+ * ASN.1 allows for tags to be of "High-tag-number form" which allows a tag to
45
+ * be two or more octets, but that is not supported by this class. A tag is
46
+ * only 1 byte. Bits 1-5 give the tag number (ie the data type within a
47
+ * particular 'class'), 6 indicates whether or not the ASN.1 value is
48
+ * constructed from other ASN.1 values, and bits 7 and 8 give the 'class'. If
49
+ * bits 7 and 8 are both zero, the class is UNIVERSAL. If only bit 7 is set,
50
+ * then the class is APPLICATION. If only bit 8 is set, then the class is
51
+ * CONTEXT_SPECIFIC. If both bits 7 and 8 are set, then the class is PRIVATE.
52
+ * The tag numbers for the data types for the class UNIVERSAL are listed below:
53
+ *
54
+ * UNIVERSAL 0 Reserved for use by the encoding rules
55
+ * UNIVERSAL 1 Boolean type
56
+ * UNIVERSAL 2 Integer type
57
+ * UNIVERSAL 3 Bitstring type
58
+ * UNIVERSAL 4 Octetstring type
59
+ * UNIVERSAL 5 Null type
60
+ * UNIVERSAL 6 Object identifier type
61
+ * UNIVERSAL 7 Object descriptor type
62
+ * UNIVERSAL 8 External type and Instance-of type
63
+ * UNIVERSAL 9 Real type
64
+ * UNIVERSAL 10 Enumerated type
65
+ * UNIVERSAL 11 Embedded-pdv type
66
+ * UNIVERSAL 12 UTF8String type
67
+ * UNIVERSAL 13 Relative object identifier type
68
+ * UNIVERSAL 14-15 Reserved for future editions
69
+ * UNIVERSAL 16 Sequence and Sequence-of types
70
+ * UNIVERSAL 17 Set and Set-of types
71
+ * UNIVERSAL 18-22, 25-30 Character string types
72
+ * UNIVERSAL 23-24 Time types
73
+ *
74
+ * The length of an ASN.1 structure is specified after the tag identifier.
75
+ * There is a definite form and an indefinite form. The indefinite form may
76
+ * be used if the encoding is constructed and not all immediately available.
77
+ * The indefinite form is encoded using a length byte with only the 8th bit
78
+ * set. The end of the constructed object is marked using end-of-contents
79
+ * octets (two zero bytes).
80
+ *
81
+ * The definite form looks like this:
82
+ *
83
+ * The length may take up 1 or more bytes, it depends on the length of the
84
+ * value of the ASN.1 structure. DER encoding requires that if the ASN.1
85
+ * structure has a value that has a length greater than 127, more than 1 byte
86
+ * will be used to store its length, otherwise just one byte will be used.
87
+ * This is strict.
88
+ *
89
+ * In the case that the length of the ASN.1 value is less than 127, 1 octet
90
+ * (byte) is used to store the "short form" length. The 8th bit has a value of
91
+ * 0 indicating the length is "short form" and not "long form" and bits 7-1
92
+ * give the length of the data. (The 8th bit is the left-most, most significant
93
+ * bit: also known as big endian or network format).
94
+ *
95
+ * In the case that the length of the ASN.1 value is greater than 127, 2 to
96
+ * 127 octets (bytes) are used to store the "long form" length. The first
97
+ * byte's 8th bit is set to 1 to indicate the length is "long form." Bits 7-1
98
+ * give the number of additional octets. All following octets are in base 256
99
+ * with the most significant digit first (typical big-endian binary unsigned
100
+ * integer storage). So, for instance, if the length of a value was 257, the
101
+ * first byte would be set to:
102
+ *
103
+ * 10000010 = 130 = 0x82.
104
+ *
105
+ * This indicates there are 2 octets (base 256) for the length. The second and
106
+ * third bytes (the octets just mentioned) would store the length in base 256:
107
+ *
108
+ * octet 2: 00000001 = 1 * 256^1 = 256
109
+ * octet 3: 00000001 = 1 * 256^0 = 1
110
+ * total = 257
111
+ *
112
+ * The algorithm for converting a js integer value of 257 to base-256 is:
113
+ *
114
+ * var value = 257;
115
+ * var bytes = [];
116
+ * bytes[0] = (value >>> 8) & 0xFF; // most significant byte first
117
+ * bytes[1] = value & 0xFF; // least significant byte last
118
+ *
119
+ * On the ASN.1 UNIVERSAL Object Identifier (OID) type:
120
+ *
121
+ * An OID can be written like: "value1.value2.value3...valueN"
122
+ *
123
+ * The DER encoding rules:
124
+ *
125
+ * The first byte has the value 40 * value1 + value2.
126
+ * The following bytes, if any, encode the remaining values. Each value is
127
+ * encoded in base 128, most significant digit first (big endian), with as
128
+ * few digits as possible, and the most significant bit of each byte set
129
+ * to 1 except the last in each value's encoding. For example: Given the
130
+ * OID "1.2.840.113549", its DER encoding is (remember each byte except the
131
+ * last one in each encoding is OR'd with 0x80):
132
+ *
133
+ * byte 1: 40 * 1 + 2 = 42 = 0x2A.
134
+ * bytes 2-3: 128 * 6 + 72 = 840 = 6 72 = 6 72 = 0x0648 = 0x8648
135
+ * bytes 4-6: 16384 * 6 + 128 * 119 + 13 = 6 119 13 = 0x06770D = 0x86F70D
136
+ *
137
+ * The final value is: 0x2A864886F70D.
138
+ * The full OID (including ASN.1 tag and length of 6 bytes) is:
139
+ * 0x06062A864886F70D
140
+ */
141
+ var hasRequiredAsn1;
142
+ function requireAsn1() {
143
+ if (hasRequiredAsn1) return asn1.exports;
144
+ hasRequiredAsn1 = 1;
145
+ var forge = requireForge();
146
+ requireUtil();
147
+ requireOids();
148
+
149
+ /* ASN.1 API */
150
+ var asn1$1 = asn1.exports = forge.asn1 = forge.asn1 || {};
151
+
152
+ /**
153
+ * ASN.1 classes.
154
+ */
155
+ asn1$1.Class = {
156
+ UNIVERSAL: 0x00,
157
+ APPLICATION: 0x40,
158
+ CONTEXT_SPECIFIC: 0x80,
159
+ PRIVATE: 0xC0
160
+ };
161
+
162
+ /**
163
+ * ASN.1 types. Not all types are supported by this implementation, only
164
+ * those necessary to implement a simple PKI are implemented.
165
+ */
166
+ asn1$1.Type = {
167
+ NONE: 0,
168
+ BOOLEAN: 1,
169
+ INTEGER: 2,
170
+ BITSTRING: 3,
171
+ OCTETSTRING: 4,
172
+ NULL: 5,
173
+ OID: 6,
174
+ ODESC: 7,
175
+ EXTERNAL: 8,
176
+ REAL: 9,
177
+ ENUMERATED: 10,
178
+ EMBEDDED: 11,
179
+ UTF8: 12,
180
+ ROID: 13,
181
+ SEQUENCE: 16,
182
+ SET: 17,
183
+ PRINTABLESTRING: 19,
184
+ IA5STRING: 22,
185
+ UTCTIME: 23,
186
+ GENERALIZEDTIME: 24,
187
+ BMPSTRING: 30
188
+ };
189
+
190
+ /**
191
+ * Creates a new asn1 object.
192
+ *
193
+ * @param tagClass the tag class for the object.
194
+ * @param type the data type (tag number) for the object.
195
+ * @param constructed true if the asn1 object is in constructed form.
196
+ * @param value the value for the object, if it is not constructed.
197
+ * @param [options] the options to use:
198
+ * [bitStringContents] the plain BIT STRING content including padding
199
+ * byte.
200
+ *
201
+ * @return the asn1 object.
202
+ */
203
+ asn1$1.create = function (tagClass, type, constructed, value, options) {
204
+ /* An asn1 object has a tagClass, a type, a constructed flag, and a
205
+ value. The value's type depends on the constructed flag. If
206
+ constructed, it will contain a list of other asn1 objects. If not,
207
+ it will contain the ASN.1 value as an array of bytes formatted
208
+ according to the ASN.1 data type. */
209
+
210
+ // remove undefined values
211
+ if (forge.util.isArray(value)) {
212
+ var tmp = [];
213
+ for (var i = 0; i < value.length; ++i) {
214
+ if (value[i] !== undefined) {
215
+ tmp.push(value[i]);
216
+ }
217
+ }
218
+ value = tmp;
219
+ }
220
+ var obj = {
221
+ tagClass: tagClass,
222
+ type: type,
223
+ constructed: constructed,
224
+ composed: constructed || forge.util.isArray(value),
225
+ value: value
226
+ };
227
+ if (options && 'bitStringContents' in options) {
228
+ // TODO: copy byte buffer if it's a buffer not a string
229
+ obj.bitStringContents = options.bitStringContents;
230
+ // TODO: add readonly flag to avoid this overhead
231
+ // save copy to detect changes
232
+ obj.original = asn1$1.copy(obj);
233
+ }
234
+ return obj;
235
+ };
236
+
237
+ /**
238
+ * Copies an asn1 object.
239
+ *
240
+ * @param obj the asn1 object.
241
+ * @param [options] copy options:
242
+ * [excludeBitStringContents] true to not copy bitStringContents
243
+ *
244
+ * @return the a copy of the asn1 object.
245
+ */
246
+ asn1$1.copy = function (obj, options) {
247
+ var copy;
248
+ if (forge.util.isArray(obj)) {
249
+ copy = [];
250
+ for (var i = 0; i < obj.length; ++i) {
251
+ copy.push(asn1$1.copy(obj[i], options));
252
+ }
253
+ return copy;
254
+ }
255
+ if (typeof obj === 'string') {
256
+ // TODO: copy byte buffer if it's a buffer not a string
257
+ return obj;
258
+ }
259
+ copy = {
260
+ tagClass: obj.tagClass,
261
+ type: obj.type,
262
+ constructed: obj.constructed,
263
+ composed: obj.composed,
264
+ value: asn1$1.copy(obj.value, options)
265
+ };
266
+ if (options && !options.excludeBitStringContents) {
267
+ // TODO: copy byte buffer if it's a buffer not a string
268
+ copy.bitStringContents = obj.bitStringContents;
269
+ }
270
+ return copy;
271
+ };
272
+
273
+ /**
274
+ * Compares asn1 objects for equality.
275
+ *
276
+ * Note this function does not run in constant time.
277
+ *
278
+ * @param obj1 the first asn1 object.
279
+ * @param obj2 the second asn1 object.
280
+ * @param [options] compare options:
281
+ * [includeBitStringContents] true to compare bitStringContents
282
+ *
283
+ * @return true if the asn1 objects are equal.
284
+ */
285
+ asn1$1.equals = function (obj1, obj2, options) {
286
+ if (forge.util.isArray(obj1)) {
287
+ if (!forge.util.isArray(obj2)) {
288
+ return false;
289
+ }
290
+ if (obj1.length !== obj2.length) {
291
+ return false;
292
+ }
293
+ for (var i = 0; i < obj1.length; ++i) {
294
+ if (!asn1$1.equals(obj1[i], obj2[i])) {
295
+ return false;
296
+ }
297
+ }
298
+ return true;
299
+ }
300
+ if (typeof obj1 !== typeof obj2) {
301
+ return false;
302
+ }
303
+ if (typeof obj1 === 'string') {
304
+ return obj1 === obj2;
305
+ }
306
+ var equal = obj1.tagClass === obj2.tagClass && obj1.type === obj2.type && obj1.constructed === obj2.constructed && obj1.composed === obj2.composed && asn1$1.equals(obj1.value, obj2.value);
307
+ if (options && options.includeBitStringContents) {
308
+ equal = equal && obj1.bitStringContents === obj2.bitStringContents;
309
+ }
310
+ return equal;
311
+ };
312
+
313
+ /**
314
+ * Gets the length of a BER-encoded ASN.1 value.
315
+ *
316
+ * In case the length is not specified, undefined is returned.
317
+ *
318
+ * @param b the BER-encoded ASN.1 byte buffer, starting with the first
319
+ * length byte.
320
+ *
321
+ * @return the length of the BER-encoded ASN.1 value or undefined.
322
+ */
323
+ asn1$1.getBerValueLength = function (b) {
324
+ // TODO: move this function and related DER/BER functions to a der.js
325
+ // file; better abstract ASN.1 away from der/ber.
326
+ var b2 = b.getByte();
327
+ if (b2 === 0x80) {
328
+ return undefined;
329
+ }
330
+
331
+ // see if the length is "short form" or "long form" (bit 8 set)
332
+ var length;
333
+ var longForm = b2 & 0x80;
334
+ if (!longForm) {
335
+ // length is just the first byte
336
+ length = b2;
337
+ } else {
338
+ // the number of bytes the length is specified in bits 7 through 1
339
+ // and each length byte is in big-endian base-256
340
+ length = b.getInt((b2 & 0x7F) << 3);
341
+ }
342
+ return length;
343
+ };
344
+
345
+ /**
346
+ * Check if the byte buffer has enough bytes. Throws an Error if not.
347
+ *
348
+ * @param bytes the byte buffer to parse from.
349
+ * @param remaining the bytes remaining in the current parsing state.
350
+ * @param n the number of bytes the buffer must have.
351
+ */
352
+ function _checkBufferLength(bytes, remaining, n) {
353
+ if (n > remaining) {
354
+ var error = new Error('Too few bytes to parse DER.');
355
+ error.available = bytes.length();
356
+ error.remaining = remaining;
357
+ error.requested = n;
358
+ throw error;
359
+ }
360
+ }
361
+
362
+ /**
363
+ * Gets the length of a BER-encoded ASN.1 value.
364
+ *
365
+ * In case the length is not specified, undefined is returned.
366
+ *
367
+ * @param bytes the byte buffer to parse from.
368
+ * @param remaining the bytes remaining in the current parsing state.
369
+ *
370
+ * @return the length of the BER-encoded ASN.1 value or undefined.
371
+ */
372
+ var _getValueLength = function (bytes, remaining) {
373
+ // TODO: move this function and related DER/BER functions to a der.js
374
+ // file; better abstract ASN.1 away from der/ber.
375
+ // fromDer already checked that this byte exists
376
+ var b2 = bytes.getByte();
377
+ remaining--;
378
+ if (b2 === 0x80) {
379
+ return undefined;
380
+ }
381
+
382
+ // see if the length is "short form" or "long form" (bit 8 set)
383
+ var length;
384
+ var longForm = b2 & 0x80;
385
+ if (!longForm) {
386
+ // length is just the first byte
387
+ length = b2;
388
+ } else {
389
+ // the number of bytes the length is specified in bits 7 through 1
390
+ // and each length byte is in big-endian base-256
391
+ var longFormBytes = b2 & 0x7F;
392
+ _checkBufferLength(bytes, remaining, longFormBytes);
393
+ length = bytes.getInt(longFormBytes << 3);
394
+ }
395
+ // FIXME: this will only happen for 32 bit getInt with high bit set
396
+ if (length < 0) {
397
+ throw new Error('Negative length: ' + length);
398
+ }
399
+ return length;
400
+ };
401
+
402
+ /**
403
+ * Parses an asn1 object from a byte buffer in DER format.
404
+ *
405
+ * @param bytes the byte buffer to parse from.
406
+ * @param [strict] true to be strict when checking value lengths, false to
407
+ * allow truncated values (default: true).
408
+ * @param [options] object with options or boolean strict flag
409
+ * [strict] true to be strict when checking value lengths, false to
410
+ * allow truncated values (default: true).
411
+ * [parseAllBytes] true to ensure all bytes are parsed
412
+ * (default: true)
413
+ * [decodeBitStrings] true to attempt to decode the content of
414
+ * BIT STRINGs (not OCTET STRINGs) using strict mode. Note that
415
+ * without schema support to understand the data context this can
416
+ * erroneously decode values that happen to be valid ASN.1. This
417
+ * flag will be deprecated or removed as soon as schema support is
418
+ * available. (default: true)
419
+ *
420
+ * @throws Will throw an error for various malformed input conditions.
421
+ *
422
+ * @return the parsed asn1 object.
423
+ */
424
+ asn1$1.fromDer = function (bytes, options) {
425
+ if (options === undefined) {
426
+ options = {
427
+ strict: true,
428
+ parseAllBytes: true,
429
+ decodeBitStrings: true
430
+ };
431
+ }
432
+ if (typeof options === 'boolean') {
433
+ options = {
434
+ strict: options,
435
+ parseAllBytes: true,
436
+ decodeBitStrings: true
437
+ };
438
+ }
439
+ if (!('strict' in options)) {
440
+ options.strict = true;
441
+ }
442
+ if (!('parseAllBytes' in options)) {
443
+ options.parseAllBytes = true;
444
+ }
445
+ if (!('decodeBitStrings' in options)) {
446
+ options.decodeBitStrings = true;
447
+ }
448
+
449
+ // wrap in buffer if needed
450
+ if (typeof bytes === 'string') {
451
+ bytes = forge.util.createBuffer(bytes);
452
+ }
453
+ var byteCount = bytes.length();
454
+ var value = _fromDer(bytes, bytes.length(), 0, options);
455
+ if (options.parseAllBytes && bytes.length() !== 0) {
456
+ var error = new Error('Unparsed DER bytes remain after ASN.1 parsing.');
457
+ error.byteCount = byteCount;
458
+ error.remaining = bytes.length();
459
+ throw error;
460
+ }
461
+ return value;
462
+ };
463
+
464
+ /**
465
+ * Internal function to parse an asn1 object from a byte buffer in DER format.
466
+ *
467
+ * @param bytes the byte buffer to parse from.
468
+ * @param remaining the number of bytes remaining for this chunk.
469
+ * @param depth the current parsing depth.
470
+ * @param options object with same options as fromDer().
471
+ *
472
+ * @return the parsed asn1 object.
473
+ */
474
+ function _fromDer(bytes, remaining, depth, options) {
475
+ // temporary storage for consumption calculations
476
+ var start;
477
+
478
+ // minimum length for ASN.1 DER structure is 2
479
+ _checkBufferLength(bytes, remaining, 2);
480
+
481
+ // get the first byte
482
+ var b1 = bytes.getByte();
483
+ // consumed one byte
484
+ remaining--;
485
+
486
+ // get the tag class
487
+ var tagClass = b1 & 0xC0;
488
+
489
+ // get the type (bits 1-5)
490
+ var type = b1 & 0x1F;
491
+
492
+ // get the variable value length and adjust remaining bytes
493
+ start = bytes.length();
494
+ var length = _getValueLength(bytes, remaining);
495
+ remaining -= start - bytes.length();
496
+
497
+ // ensure there are enough bytes to get the value
498
+ if (length !== undefined && length > remaining) {
499
+ if (options.strict) {
500
+ var error = new Error('Too few bytes to read ASN.1 value.');
501
+ error.available = bytes.length();
502
+ error.remaining = remaining;
503
+ error.requested = length;
504
+ throw error;
505
+ }
506
+ // Note: be lenient with truncated values and use remaining state bytes
507
+ length = remaining;
508
+ }
509
+
510
+ // value storage
511
+ var value;
512
+ // possible BIT STRING contents storage
513
+ var bitStringContents;
514
+
515
+ // constructed flag is bit 6 (32 = 0x20) of the first byte
516
+ var constructed = (b1 & 0x20) === 0x20;
517
+ if (constructed) {
518
+ // parse child asn1 objects from the value
519
+ value = [];
520
+ if (length === undefined) {
521
+ // asn1 object of indefinite length, read until end tag
522
+ for (;;) {
523
+ _checkBufferLength(bytes, remaining, 2);
524
+ if (bytes.bytes(2) === String.fromCharCode(0, 0)) {
525
+ bytes.getBytes(2);
526
+ remaining -= 2;
527
+ break;
528
+ }
529
+ start = bytes.length();
530
+ value.push(_fromDer(bytes, remaining, depth + 1, options));
531
+ remaining -= start - bytes.length();
532
+ }
533
+ } else {
534
+ // parsing asn1 object of definite length
535
+ while (length > 0) {
536
+ start = bytes.length();
537
+ value.push(_fromDer(bytes, length, depth + 1, options));
538
+ remaining -= start - bytes.length();
539
+ length -= start - bytes.length();
540
+ }
541
+ }
542
+ }
543
+
544
+ // if a BIT STRING, save the contents including padding
545
+ if (value === undefined && tagClass === asn1$1.Class.UNIVERSAL && type === asn1$1.Type.BITSTRING) {
546
+ bitStringContents = bytes.bytes(length);
547
+ }
548
+
549
+ // determine if a non-constructed value should be decoded as a composed
550
+ // value that contains other ASN.1 objects. BIT STRINGs (and OCTET STRINGs)
551
+ // can be used this way.
552
+ if (value === undefined && options.decodeBitStrings && tagClass === asn1$1.Class.UNIVERSAL &&
553
+ // FIXME: OCTET STRINGs not yet supported here
554
+ // .. other parts of forge expect to decode OCTET STRINGs manually
555
+ type === asn1$1.Type.BITSTRING /*|| type === asn1.Type.OCTETSTRING*/ && length > 1) {
556
+ // save read position
557
+ var savedRead = bytes.read;
558
+ var savedRemaining = remaining;
559
+ var unused = 0;
560
+ if (type === asn1$1.Type.BITSTRING) {
561
+ /* The first octet gives the number of bits by which the length of the
562
+ bit string is less than the next multiple of eight (this is called
563
+ the "number of unused bits").
564
+ The second and following octets give the value of the bit string
565
+ converted to an octet string. */
566
+ _checkBufferLength(bytes, remaining, 1);
567
+ unused = bytes.getByte();
568
+ remaining--;
569
+ }
570
+ // if all bits are used, maybe the BIT/OCTET STRING holds ASN.1 objs
571
+ if (unused === 0) {
572
+ try {
573
+ // attempt to parse child asn1 object from the value
574
+ // (stored in array to signal composed value)
575
+ start = bytes.length();
576
+ var subOptions = {
577
+ // enforce strict mode to avoid parsing ASN.1 from plain data
578
+ strict: true,
579
+ decodeBitStrings: true
580
+ };
581
+ var composed = _fromDer(bytes, remaining, depth + 1, subOptions);
582
+ var used = start - bytes.length();
583
+ remaining -= used;
584
+ if (type == asn1$1.Type.BITSTRING) {
585
+ used++;
586
+ }
587
+
588
+ // if the data all decoded and the class indicates UNIVERSAL or
589
+ // CONTEXT_SPECIFIC then assume we've got an encapsulated ASN.1 object
590
+ var tc = composed.tagClass;
591
+ if (used === length && (tc === asn1$1.Class.UNIVERSAL || tc === asn1$1.Class.CONTEXT_SPECIFIC)) {
592
+ value = [composed];
593
+ }
594
+ } catch (ex) {}
595
+ }
596
+ if (value === undefined) {
597
+ // restore read position
598
+ bytes.read = savedRead;
599
+ remaining = savedRemaining;
600
+ }
601
+ }
602
+ if (value === undefined) {
603
+ // asn1 not constructed or composed, get raw value
604
+ // TODO: do DER to OID conversion and vice-versa in .toDer?
605
+
606
+ if (length === undefined) {
607
+ if (options.strict) {
608
+ throw new Error('Non-constructed ASN.1 object of indefinite length.');
609
+ }
610
+ // be lenient and use remaining state bytes
611
+ length = remaining;
612
+ }
613
+ if (type === asn1$1.Type.BMPSTRING) {
614
+ value = '';
615
+ for (; length > 0; length -= 2) {
616
+ _checkBufferLength(bytes, remaining, 2);
617
+ value += String.fromCharCode(bytes.getInt16());
618
+ remaining -= 2;
619
+ }
620
+ } else {
621
+ value = bytes.getBytes(length);
622
+ remaining -= length;
623
+ }
624
+ }
625
+
626
+ // add BIT STRING contents if available
627
+ var asn1Options = bitStringContents === undefined ? null : {
628
+ bitStringContents: bitStringContents
629
+ };
630
+
631
+ // create and return asn1 object
632
+ return asn1$1.create(tagClass, type, constructed, value, asn1Options);
633
+ }
634
+
635
+ /**
636
+ * Converts the given asn1 object to a buffer of bytes in DER format.
637
+ *
638
+ * @param asn1 the asn1 object to convert to bytes.
639
+ *
640
+ * @return the buffer of bytes.
641
+ */
642
+ asn1$1.toDer = function (obj) {
643
+ var bytes = forge.util.createBuffer();
644
+
645
+ // build the first byte
646
+ var b1 = obj.tagClass | obj.type;
647
+
648
+ // for storing the ASN.1 value
649
+ var value = forge.util.createBuffer();
650
+
651
+ // use BIT STRING contents if available and data not changed
652
+ var useBitStringContents = false;
653
+ if ('bitStringContents' in obj) {
654
+ useBitStringContents = true;
655
+ if (obj.original) {
656
+ useBitStringContents = asn1$1.equals(obj, obj.original);
657
+ }
658
+ }
659
+ if (useBitStringContents) {
660
+ value.putBytes(obj.bitStringContents);
661
+ } else if (obj.composed) {
662
+ // if composed, use each child asn1 object's DER bytes as value
663
+ // turn on 6th bit (0x20 = 32) to indicate asn1 is constructed
664
+ // from other asn1 objects
665
+ if (obj.constructed) {
666
+ b1 |= 0x20;
667
+ } else {
668
+ // type is a bit string, add unused bits of 0x00
669
+ value.putByte(0x00);
670
+ }
671
+
672
+ // add all of the child DER bytes together
673
+ for (var i = 0; i < obj.value.length; ++i) {
674
+ if (obj.value[i] !== undefined) {
675
+ value.putBuffer(asn1$1.toDer(obj.value[i]));
676
+ }
677
+ }
678
+ } else {
679
+ // use asn1.value directly
680
+ if (obj.type === asn1$1.Type.BMPSTRING) {
681
+ for (var i = 0; i < obj.value.length; ++i) {
682
+ value.putInt16(obj.value.charCodeAt(i));
683
+ }
684
+ } else {
685
+ // ensure integer is minimally-encoded
686
+ // TODO: should all leading bytes be stripped vs just one?
687
+ // .. ex '00 00 01' => '01'?
688
+ if (obj.type === asn1$1.Type.INTEGER && obj.value.length > 1 && (
689
+ // leading 0x00 for positive integer
690
+ obj.value.charCodeAt(0) === 0 && (obj.value.charCodeAt(1) & 0x80) === 0 ||
691
+ // leading 0xFF for negative integer
692
+ obj.value.charCodeAt(0) === 0xFF && (obj.value.charCodeAt(1) & 0x80) === 0x80)) {
693
+ value.putBytes(obj.value.substr(1));
694
+ } else {
695
+ value.putBytes(obj.value);
696
+ }
697
+ }
698
+ }
699
+
700
+ // add tag byte
701
+ bytes.putByte(b1);
702
+
703
+ // use "short form" encoding
704
+ if (value.length() <= 127) {
705
+ // one byte describes the length
706
+ // bit 8 = 0 and bits 7-1 = length
707
+ bytes.putByte(value.length() & 0x7F);
708
+ } else {
709
+ // use "long form" encoding
710
+ // 2 to 127 bytes describe the length
711
+ // first byte: bit 8 = 1 and bits 7-1 = # of additional bytes
712
+ // other bytes: length in base 256, big-endian
713
+ var len = value.length();
714
+ var lenBytes = '';
715
+ do {
716
+ lenBytes += String.fromCharCode(len & 0xFF);
717
+ len = len >>> 8;
718
+ } while (len > 0);
719
+
720
+ // set first byte to # bytes used to store the length and turn on
721
+ // bit 8 to indicate long-form length is used
722
+ bytes.putByte(lenBytes.length | 0x80);
723
+
724
+ // concatenate length bytes in reverse since they were generated
725
+ // little endian and we need big endian
726
+ for (var i = lenBytes.length - 1; i >= 0; --i) {
727
+ bytes.putByte(lenBytes.charCodeAt(i));
728
+ }
729
+ }
730
+
731
+ // concatenate value bytes
732
+ bytes.putBuffer(value);
733
+ return bytes;
734
+ };
735
+
736
+ /**
737
+ * Converts an OID dot-separated string to a byte buffer. The byte buffer
738
+ * contains only the DER-encoded value, not any tag or length bytes.
739
+ *
740
+ * @param oid the OID dot-separated string.
741
+ *
742
+ * @return the byte buffer.
743
+ */
744
+ asn1$1.oidToDer = function (oid) {
745
+ // split OID into individual values
746
+ var values = oid.split('.');
747
+ var bytes = forge.util.createBuffer();
748
+
749
+ // first byte is 40 * value1 + value2
750
+ bytes.putByte(40 * parseInt(values[0], 10) + parseInt(values[1], 10));
751
+ // other bytes are each value in base 128 with 8th bit set except for
752
+ // the last byte for each value
753
+ var last, valueBytes, value, b;
754
+ for (var i = 2; i < values.length; ++i) {
755
+ // produce value bytes in reverse because we don't know how many
756
+ // bytes it will take to store the value
757
+ last = true;
758
+ valueBytes = [];
759
+ value = parseInt(values[i], 10);
760
+ do {
761
+ b = value & 0x7F;
762
+ value = value >>> 7;
763
+ // if value is not last, then turn on 8th bit
764
+ if (!last) {
765
+ b |= 0x80;
766
+ }
767
+ valueBytes.push(b);
768
+ last = false;
769
+ } while (value > 0);
770
+
771
+ // add value bytes in reverse (needs to be in big endian)
772
+ for (var n = valueBytes.length - 1; n >= 0; --n) {
773
+ bytes.putByte(valueBytes[n]);
774
+ }
775
+ }
776
+ return bytes;
777
+ };
778
+
779
+ /**
780
+ * Converts a DER-encoded byte buffer to an OID dot-separated string. The
781
+ * byte buffer should contain only the DER-encoded value, not any tag or
782
+ * length bytes.
783
+ *
784
+ * @param bytes the byte buffer.
785
+ *
786
+ * @return the OID dot-separated string.
787
+ */
788
+ asn1$1.derToOid = function (bytes) {
789
+ var oid;
790
+
791
+ // wrap in buffer if needed
792
+ if (typeof bytes === 'string') {
793
+ bytes = forge.util.createBuffer(bytes);
794
+ }
795
+
796
+ // first byte is 40 * value1 + value2
797
+ var b = bytes.getByte();
798
+ oid = Math.floor(b / 40) + '.' + b % 40;
799
+
800
+ // other bytes are each value in base 128 with 8th bit set except for
801
+ // the last byte for each value
802
+ var value = 0;
803
+ while (bytes.length() > 0) {
804
+ b = bytes.getByte();
805
+ value = value << 7;
806
+ // not the last byte for the value
807
+ if (b & 0x80) {
808
+ value += b & 0x7F;
809
+ } else {
810
+ // last byte
811
+ oid += '.' + (value + b);
812
+ value = 0;
813
+ }
814
+ }
815
+ return oid;
816
+ };
817
+
818
+ /**
819
+ * Converts a UTCTime value to a date.
820
+ *
821
+ * Note: GeneralizedTime has 4 digits for the year and is used for X.509
822
+ * dates past 2049. Parsing that structure hasn't been implemented yet.
823
+ *
824
+ * @param utc the UTCTime value to convert.
825
+ *
826
+ * @return the date.
827
+ */
828
+ asn1$1.utcTimeToDate = function (utc) {
829
+ /* The following formats can be used:
830
+ YYMMDDhhmmZ
831
+ YYMMDDhhmm+hh'mm'
832
+ YYMMDDhhmm-hh'mm'
833
+ YYMMDDhhmmssZ
834
+ YYMMDDhhmmss+hh'mm'
835
+ YYMMDDhhmmss-hh'mm'
836
+ Where:
837
+ YY is the least significant two digits of the year
838
+ MM is the month (01 to 12)
839
+ DD is the day (01 to 31)
840
+ hh is the hour (00 to 23)
841
+ mm are the minutes (00 to 59)
842
+ ss are the seconds (00 to 59)
843
+ Z indicates that local time is GMT, + indicates that local time is
844
+ later than GMT, and - indicates that local time is earlier than GMT
845
+ hh' is the absolute value of the offset from GMT in hours
846
+ mm' is the absolute value of the offset from GMT in minutes */
847
+ var date = new Date();
848
+
849
+ // if YY >= 50 use 19xx, if YY < 50 use 20xx
850
+ var year = parseInt(utc.substr(0, 2), 10);
851
+ year = year >= 50 ? 1900 + year : 2000 + year;
852
+ var MM = parseInt(utc.substr(2, 2), 10) - 1; // use 0-11 for month
853
+ var DD = parseInt(utc.substr(4, 2), 10);
854
+ var hh = parseInt(utc.substr(6, 2), 10);
855
+ var mm = parseInt(utc.substr(8, 2), 10);
856
+ var ss = 0;
857
+
858
+ // not just YYMMDDhhmmZ
859
+ if (utc.length > 11) {
860
+ // get character after minutes
861
+ var c = utc.charAt(10);
862
+ var end = 10;
863
+
864
+ // see if seconds are present
865
+ if (c !== '+' && c !== '-') {
866
+ // get seconds
867
+ ss = parseInt(utc.substr(10, 2), 10);
868
+ end += 2;
869
+ }
870
+ }
871
+
872
+ // update date
873
+ date.setUTCFullYear(year, MM, DD);
874
+ date.setUTCHours(hh, mm, ss, 0);
875
+ if (end) {
876
+ // get +/- after end of time
877
+ c = utc.charAt(end);
878
+ if (c === '+' || c === '-') {
879
+ // get hours+minutes offset
880
+ var hhoffset = parseInt(utc.substr(end + 1, 2), 10);
881
+ var mmoffset = parseInt(utc.substr(end + 4, 2), 10);
882
+
883
+ // calculate offset in milliseconds
884
+ var offset = hhoffset * 60 + mmoffset;
885
+ offset *= 60000;
886
+
887
+ // apply offset
888
+ if (c === '+') {
889
+ date.setTime(+date - offset);
890
+ } else {
891
+ date.setTime(+date + offset);
892
+ }
893
+ }
894
+ }
895
+ return date;
896
+ };
897
+
898
+ /**
899
+ * Converts a GeneralizedTime value to a date.
900
+ *
901
+ * @param gentime the GeneralizedTime value to convert.
902
+ *
903
+ * @return the date.
904
+ */
905
+ asn1$1.generalizedTimeToDate = function (gentime) {
906
+ /* The following formats can be used:
907
+ YYYYMMDDHHMMSS
908
+ YYYYMMDDHHMMSS.fff
909
+ YYYYMMDDHHMMSSZ
910
+ YYYYMMDDHHMMSS.fffZ
911
+ YYYYMMDDHHMMSS+hh'mm'
912
+ YYYYMMDDHHMMSS.fff+hh'mm'
913
+ YYYYMMDDHHMMSS-hh'mm'
914
+ YYYYMMDDHHMMSS.fff-hh'mm'
915
+ Where:
916
+ YYYY is the year
917
+ MM is the month (01 to 12)
918
+ DD is the day (01 to 31)
919
+ hh is the hour (00 to 23)
920
+ mm are the minutes (00 to 59)
921
+ ss are the seconds (00 to 59)
922
+ .fff is the second fraction, accurate to three decimal places
923
+ Z indicates that local time is GMT, + indicates that local time is
924
+ later than GMT, and - indicates that local time is earlier than GMT
925
+ hh' is the absolute value of the offset from GMT in hours
926
+ mm' is the absolute value of the offset from GMT in minutes */
927
+ var date = new Date();
928
+ var YYYY = parseInt(gentime.substr(0, 4), 10);
929
+ var MM = parseInt(gentime.substr(4, 2), 10) - 1; // use 0-11 for month
930
+ var DD = parseInt(gentime.substr(6, 2), 10);
931
+ var hh = parseInt(gentime.substr(8, 2), 10);
932
+ var mm = parseInt(gentime.substr(10, 2), 10);
933
+ var ss = parseInt(gentime.substr(12, 2), 10);
934
+ var fff = 0;
935
+ var offset = 0;
936
+ var isUTC = false;
937
+ if (gentime.charAt(gentime.length - 1) === 'Z') {
938
+ isUTC = true;
939
+ }
940
+ var end = gentime.length - 5,
941
+ c = gentime.charAt(end);
942
+ if (c === '+' || c === '-') {
943
+ // get hours+minutes offset
944
+ var hhoffset = parseInt(gentime.substr(end + 1, 2), 10);
945
+ var mmoffset = parseInt(gentime.substr(end + 4, 2), 10);
946
+
947
+ // calculate offset in milliseconds
948
+ offset = hhoffset * 60 + mmoffset;
949
+ offset *= 60000;
950
+
951
+ // apply offset
952
+ if (c === '+') {
953
+ offset *= -1;
954
+ }
955
+ isUTC = true;
956
+ }
957
+
958
+ // check for second fraction
959
+ if (gentime.charAt(14) === '.') {
960
+ fff = parseFloat(gentime.substr(14), 10) * 1000;
961
+ }
962
+ if (isUTC) {
963
+ date.setUTCFullYear(YYYY, MM, DD);
964
+ date.setUTCHours(hh, mm, ss, fff);
965
+
966
+ // apply offset
967
+ date.setTime(+date + offset);
968
+ } else {
969
+ date.setFullYear(YYYY, MM, DD);
970
+ date.setHours(hh, mm, ss, fff);
971
+ }
972
+ return date;
973
+ };
974
+
975
+ /**
976
+ * Converts a date to a UTCTime value.
977
+ *
978
+ * Note: GeneralizedTime has 4 digits for the year and is used for X.509
979
+ * dates past 2049. Converting to a GeneralizedTime hasn't been
980
+ * implemented yet.
981
+ *
982
+ * @param date the date to convert.
983
+ *
984
+ * @return the UTCTime value.
985
+ */
986
+ asn1$1.dateToUtcTime = function (date) {
987
+ // TODO: validate; currently assumes proper format
988
+ if (typeof date === 'string') {
989
+ return date;
990
+ }
991
+ var rval = '';
992
+
993
+ // create format YYMMDDhhmmssZ
994
+ var format = [];
995
+ format.push(('' + date.getUTCFullYear()).substr(2));
996
+ format.push('' + (date.getUTCMonth() + 1));
997
+ format.push('' + date.getUTCDate());
998
+ format.push('' + date.getUTCHours());
999
+ format.push('' + date.getUTCMinutes());
1000
+ format.push('' + date.getUTCSeconds());
1001
+
1002
+ // ensure 2 digits are used for each format entry
1003
+ for (var i = 0; i < format.length; ++i) {
1004
+ if (format[i].length < 2) {
1005
+ rval += '0';
1006
+ }
1007
+ rval += format[i];
1008
+ }
1009
+ rval += 'Z';
1010
+ return rval;
1011
+ };
1012
+
1013
+ /**
1014
+ * Converts a date to a GeneralizedTime value.
1015
+ *
1016
+ * @param date the date to convert.
1017
+ *
1018
+ * @return the GeneralizedTime value as a string.
1019
+ */
1020
+ asn1$1.dateToGeneralizedTime = function (date) {
1021
+ // TODO: validate; currently assumes proper format
1022
+ if (typeof date === 'string') {
1023
+ return date;
1024
+ }
1025
+ var rval = '';
1026
+
1027
+ // create format YYYYMMDDHHMMSSZ
1028
+ var format = [];
1029
+ format.push('' + date.getUTCFullYear());
1030
+ format.push('' + (date.getUTCMonth() + 1));
1031
+ format.push('' + date.getUTCDate());
1032
+ format.push('' + date.getUTCHours());
1033
+ format.push('' + date.getUTCMinutes());
1034
+ format.push('' + date.getUTCSeconds());
1035
+
1036
+ // ensure 2 digits are used for each format entry
1037
+ for (var i = 0; i < format.length; ++i) {
1038
+ if (format[i].length < 2) {
1039
+ rval += '0';
1040
+ }
1041
+ rval += format[i];
1042
+ }
1043
+ rval += 'Z';
1044
+ return rval;
1045
+ };
1046
+
1047
+ /**
1048
+ * Converts a javascript integer to a DER-encoded byte buffer to be used
1049
+ * as the value for an INTEGER type.
1050
+ *
1051
+ * @param x the integer.
1052
+ *
1053
+ * @return the byte buffer.
1054
+ */
1055
+ asn1$1.integerToDer = function (x) {
1056
+ var rval = forge.util.createBuffer();
1057
+ if (x >= -128 && x < 0x80) {
1058
+ return rval.putSignedInt(x, 8);
1059
+ }
1060
+ if (x >= -32768 && x < 0x8000) {
1061
+ return rval.putSignedInt(x, 16);
1062
+ }
1063
+ if (x >= -8388608 && x < 0x800000) {
1064
+ return rval.putSignedInt(x, 24);
1065
+ }
1066
+ if (x >= -2147483648 && x < 0x80000000) {
1067
+ return rval.putSignedInt(x, 32);
1068
+ }
1069
+ var error = new Error('Integer too large; max is 32-bits.');
1070
+ error.integer = x;
1071
+ throw error;
1072
+ };
1073
+
1074
+ /**
1075
+ * Converts a DER-encoded byte buffer to a javascript integer. This is
1076
+ * typically used to decode the value of an INTEGER type.
1077
+ *
1078
+ * @param bytes the byte buffer.
1079
+ *
1080
+ * @return the integer.
1081
+ */
1082
+ asn1$1.derToInteger = function (bytes) {
1083
+ // wrap in buffer if needed
1084
+ if (typeof bytes === 'string') {
1085
+ bytes = forge.util.createBuffer(bytes);
1086
+ }
1087
+ var n = bytes.length() * 8;
1088
+ if (n > 32) {
1089
+ throw new Error('Integer too large; max is 32-bits.');
1090
+ }
1091
+ return bytes.getSignedInt(n);
1092
+ };
1093
+
1094
+ /**
1095
+ * Validates that the given ASN.1 object is at least a super set of the
1096
+ * given ASN.1 structure. Only tag classes and types are checked. An
1097
+ * optional map may also be provided to capture ASN.1 values while the
1098
+ * structure is checked.
1099
+ *
1100
+ * To capture an ASN.1 value, set an object in the validator's 'capture'
1101
+ * parameter to the key to use in the capture map. To capture the full
1102
+ * ASN.1 object, specify 'captureAsn1'. To capture BIT STRING bytes, including
1103
+ * the leading unused bits counter byte, specify 'captureBitStringContents'.
1104
+ * To capture BIT STRING bytes, without the leading unused bits counter byte,
1105
+ * specify 'captureBitStringValue'.
1106
+ *
1107
+ * Objects in the validator may set a field 'optional' to true to indicate
1108
+ * that it isn't necessary to pass validation.
1109
+ *
1110
+ * @param obj the ASN.1 object to validate.
1111
+ * @param v the ASN.1 structure validator.
1112
+ * @param capture an optional map to capture values in.
1113
+ * @param errors an optional array for storing validation errors.
1114
+ *
1115
+ * @return true on success, false on failure.
1116
+ */
1117
+ asn1$1.validate = function (obj, v, capture, errors) {
1118
+ var rval = false;
1119
+
1120
+ // ensure tag class and type are the same if specified
1121
+ if ((obj.tagClass === v.tagClass || typeof v.tagClass === 'undefined') && (obj.type === v.type || typeof v.type === 'undefined')) {
1122
+ // ensure constructed flag is the same if specified
1123
+ if (obj.constructed === v.constructed || typeof v.constructed === 'undefined') {
1124
+ rval = true;
1125
+
1126
+ // handle sub values
1127
+ if (v.value && forge.util.isArray(v.value)) {
1128
+ var j = 0;
1129
+ for (var i = 0; rval && i < v.value.length; ++i) {
1130
+ rval = v.value[i].optional || false;
1131
+ if (obj.value[j]) {
1132
+ rval = asn1$1.validate(obj.value[j], v.value[i], capture, errors);
1133
+ if (rval) {
1134
+ ++j;
1135
+ } else if (v.value[i].optional) {
1136
+ rval = true;
1137
+ }
1138
+ }
1139
+ if (!rval && errors) {
1140
+ errors.push('[' + v.name + '] ' + 'Tag class "' + v.tagClass + '", type "' + v.type + '" expected value length "' + v.value.length + '", got "' + obj.value.length + '"');
1141
+ }
1142
+ }
1143
+ }
1144
+ if (rval && capture) {
1145
+ if (v.capture) {
1146
+ capture[v.capture] = obj.value;
1147
+ }
1148
+ if (v.captureAsn1) {
1149
+ capture[v.captureAsn1] = obj;
1150
+ }
1151
+ if (v.captureBitStringContents && 'bitStringContents' in obj) {
1152
+ capture[v.captureBitStringContents] = obj.bitStringContents;
1153
+ }
1154
+ if (v.captureBitStringValue && 'bitStringContents' in obj) {
1155
+ if (obj.bitStringContents.length < 2) {
1156
+ capture[v.captureBitStringValue] = '';
1157
+ } else {
1158
+ // FIXME: support unused bits with data shifting
1159
+ var unused = obj.bitStringContents.charCodeAt(0);
1160
+ if (unused !== 0) {
1161
+ throw new Error('captureBitStringValue only supported for zero unused bits');
1162
+ }
1163
+ capture[v.captureBitStringValue] = obj.bitStringContents.slice(1);
1164
+ }
1165
+ }
1166
+ }
1167
+ } else if (errors) {
1168
+ errors.push('[' + v.name + '] ' + 'Expected constructed "' + v.constructed + '", got "' + obj.constructed + '"');
1169
+ }
1170
+ } else if (errors) {
1171
+ if (obj.tagClass !== v.tagClass) {
1172
+ errors.push('[' + v.name + '] ' + 'Expected tag class "' + v.tagClass + '", got "' + obj.tagClass + '"');
1173
+ }
1174
+ if (obj.type !== v.type) {
1175
+ errors.push('[' + v.name + '] ' + 'Expected type "' + v.type + '", got "' + obj.type + '"');
1176
+ }
1177
+ }
1178
+ return rval;
1179
+ };
1180
+
1181
+ // regex for testing for non-latin characters
1182
+ var _nonLatinRegex = /[^\\u0000-\\u00ff]/;
1183
+
1184
+ /**
1185
+ * Pretty prints an ASN.1 object to a string.
1186
+ *
1187
+ * @param obj the object to write out.
1188
+ * @param level the level in the tree.
1189
+ * @param indentation the indentation to use.
1190
+ *
1191
+ * @return the string.
1192
+ */
1193
+ asn1$1.prettyPrint = function (obj, level, indentation) {
1194
+ var rval = '';
1195
+
1196
+ // set default level and indentation
1197
+ level = level || 0;
1198
+ indentation = indentation || 2;
1199
+
1200
+ // start new line for deep levels
1201
+ if (level > 0) {
1202
+ rval += '\n';
1203
+ }
1204
+
1205
+ // create indent
1206
+ var indent = '';
1207
+ for (var i = 0; i < level * indentation; ++i) {
1208
+ indent += ' ';
1209
+ }
1210
+
1211
+ // print class:type
1212
+ rval += indent + 'Tag: ';
1213
+ switch (obj.tagClass) {
1214
+ case asn1$1.Class.UNIVERSAL:
1215
+ rval += 'Universal:';
1216
+ break;
1217
+ case asn1$1.Class.APPLICATION:
1218
+ rval += 'Application:';
1219
+ break;
1220
+ case asn1$1.Class.CONTEXT_SPECIFIC:
1221
+ rval += 'Context-Specific:';
1222
+ break;
1223
+ case asn1$1.Class.PRIVATE:
1224
+ rval += 'Private:';
1225
+ break;
1226
+ }
1227
+ if (obj.tagClass === asn1$1.Class.UNIVERSAL) {
1228
+ rval += obj.type;
1229
+
1230
+ // known types
1231
+ switch (obj.type) {
1232
+ case asn1$1.Type.NONE:
1233
+ rval += ' (None)';
1234
+ break;
1235
+ case asn1$1.Type.BOOLEAN:
1236
+ rval += ' (Boolean)';
1237
+ break;
1238
+ case asn1$1.Type.INTEGER:
1239
+ rval += ' (Integer)';
1240
+ break;
1241
+ case asn1$1.Type.BITSTRING:
1242
+ rval += ' (Bit string)';
1243
+ break;
1244
+ case asn1$1.Type.OCTETSTRING:
1245
+ rval += ' (Octet string)';
1246
+ break;
1247
+ case asn1$1.Type.NULL:
1248
+ rval += ' (Null)';
1249
+ break;
1250
+ case asn1$1.Type.OID:
1251
+ rval += ' (Object Identifier)';
1252
+ break;
1253
+ case asn1$1.Type.ODESC:
1254
+ rval += ' (Object Descriptor)';
1255
+ break;
1256
+ case asn1$1.Type.EXTERNAL:
1257
+ rval += ' (External or Instance of)';
1258
+ break;
1259
+ case asn1$1.Type.REAL:
1260
+ rval += ' (Real)';
1261
+ break;
1262
+ case asn1$1.Type.ENUMERATED:
1263
+ rval += ' (Enumerated)';
1264
+ break;
1265
+ case asn1$1.Type.EMBEDDED:
1266
+ rval += ' (Embedded PDV)';
1267
+ break;
1268
+ case asn1$1.Type.UTF8:
1269
+ rval += ' (UTF8)';
1270
+ break;
1271
+ case asn1$1.Type.ROID:
1272
+ rval += ' (Relative Object Identifier)';
1273
+ break;
1274
+ case asn1$1.Type.SEQUENCE:
1275
+ rval += ' (Sequence)';
1276
+ break;
1277
+ case asn1$1.Type.SET:
1278
+ rval += ' (Set)';
1279
+ break;
1280
+ case asn1$1.Type.PRINTABLESTRING:
1281
+ rval += ' (Printable String)';
1282
+ break;
1283
+ case asn1$1.Type.IA5String:
1284
+ rval += ' (IA5String (ASCII))';
1285
+ break;
1286
+ case asn1$1.Type.UTCTIME:
1287
+ rval += ' (UTC time)';
1288
+ break;
1289
+ case asn1$1.Type.GENERALIZEDTIME:
1290
+ rval += ' (Generalized time)';
1291
+ break;
1292
+ case asn1$1.Type.BMPSTRING:
1293
+ rval += ' (BMP String)';
1294
+ break;
1295
+ }
1296
+ } else {
1297
+ rval += obj.type;
1298
+ }
1299
+ rval += '\n';
1300
+ rval += indent + 'Constructed: ' + obj.constructed + '\n';
1301
+ if (obj.composed) {
1302
+ var subvalues = 0;
1303
+ var sub = '';
1304
+ for (var i = 0; i < obj.value.length; ++i) {
1305
+ if (obj.value[i] !== undefined) {
1306
+ subvalues += 1;
1307
+ sub += asn1$1.prettyPrint(obj.value[i], level + 1, indentation);
1308
+ if (i + 1 < obj.value.length) {
1309
+ sub += ',';
1310
+ }
1311
+ }
1312
+ }
1313
+ rval += indent + 'Sub values: ' + subvalues + sub;
1314
+ } else {
1315
+ rval += indent + 'Value: ';
1316
+ if (obj.type === asn1$1.Type.OID) {
1317
+ var oid = asn1$1.derToOid(obj.value);
1318
+ rval += oid;
1319
+ if (forge.pki && forge.pki.oids) {
1320
+ if (oid in forge.pki.oids) {
1321
+ rval += ' (' + forge.pki.oids[oid] + ') ';
1322
+ }
1323
+ }
1324
+ }
1325
+ if (obj.type === asn1$1.Type.INTEGER) {
1326
+ try {
1327
+ rval += asn1$1.derToInteger(obj.value);
1328
+ } catch (ex) {
1329
+ rval += '0x' + forge.util.bytesToHex(obj.value);
1330
+ }
1331
+ } else if (obj.type === asn1$1.Type.BITSTRING) {
1332
+ // TODO: shift bits as needed to display without padding
1333
+ if (obj.value.length > 1) {
1334
+ // remove unused bits field
1335
+ rval += '0x' + forge.util.bytesToHex(obj.value.slice(1));
1336
+ } else {
1337
+ rval += '(none)';
1338
+ }
1339
+ // show unused bit count
1340
+ if (obj.value.length > 0) {
1341
+ var unused = obj.value.charCodeAt(0);
1342
+ if (unused == 1) {
1343
+ rval += ' (1 unused bit shown)';
1344
+ } else if (unused > 1) {
1345
+ rval += ' (' + unused + ' unused bits shown)';
1346
+ }
1347
+ }
1348
+ } else if (obj.type === asn1$1.Type.OCTETSTRING) {
1349
+ if (!_nonLatinRegex.test(obj.value)) {
1350
+ rval += '(' + obj.value + ') ';
1351
+ }
1352
+ rval += '0x' + forge.util.bytesToHex(obj.value);
1353
+ } else if (obj.type === asn1$1.Type.UTF8) {
1354
+ try {
1355
+ rval += forge.util.decodeUtf8(obj.value);
1356
+ } catch (e) {
1357
+ if (e.message === 'URI malformed') {
1358
+ rval += '0x' + forge.util.bytesToHex(obj.value) + ' (malformed UTF8)';
1359
+ } else {
1360
+ throw e;
1361
+ }
1362
+ }
1363
+ } else if (obj.type === asn1$1.Type.PRINTABLESTRING || obj.type === asn1$1.Type.IA5String) {
1364
+ rval += obj.value;
1365
+ } else if (_nonLatinRegex.test(obj.value)) {
1366
+ rval += '0x' + forge.util.bytesToHex(obj.value);
1367
+ } else if (obj.value.length === 0) {
1368
+ rval += '[null]';
1369
+ } else {
1370
+ rval += obj.value;
1371
+ }
1372
+ }
1373
+ return rval;
1374
+ };
1375
+ return asn1.exports;
1376
+ }
1377
+
1378
+ export { requireAsn1 as __require };
1379
+ //# sourceMappingURL=asn1.js.map