PageRenderTime 166ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 1ms

/apps/files_external/3rdparty/phpseclib/phpseclib/File/X509.php

https://github.com/sezuan/core
PHP | 4323 lines | 2916 code | 432 blank | 975 comment | 366 complexity | 0a2e60d206aa742c914ca7100f0ce0b6 MD5 | raw file
Possible License(s): AGPL-3.0, AGPL-1.0, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * Pure-PHP X.509 Parser
  5. *
  6. * PHP versions 4 and 5
  7. *
  8. * Encode and decode X.509 certificates.
  9. *
  10. * The extensions are from {@link http://tools.ietf.org/html/rfc5280 RFC5280} and
  11. * {@link http://web.archive.org/web/19961027104704/http://www3.netscape.com/eng/security/cert-exts.html Netscape Certificate Extensions}.
  12. *
  13. * Note that loading an X.509 certificate and resaving it may invalidate the signature. The reason being that the signature is based on a
  14. * portion of the certificate that contains optional parameters with default values. ie. if the parameter isn't there the default value is
  15. * used. Problem is, if the parameter is there and it just so happens to have the default value there are two ways that that parameter can
  16. * be encoded. It can be encoded explicitly or left out all together. This would effect the signature value and thus may invalidate the
  17. * the certificate all together unless the certificate is re-signed.
  18. *
  19. * LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
  20. * of this software and associated documentation files (the "Software"), to deal
  21. * in the Software without restriction, including without limitation the rights
  22. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  23. * copies of the Software, and to permit persons to whom the Software is
  24. * furnished to do so, subject to the following conditions:
  25. *
  26. * The above copyright notice and this permission notice shall be included in
  27. * all copies or substantial portions of the Software.
  28. *
  29. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  30. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  31. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  32. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  33. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  34. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  35. * THE SOFTWARE.
  36. *
  37. * @category File
  38. * @package File_X509
  39. * @author Jim Wigginton <terrafrost@php.net>
  40. * @copyright MMXII Jim Wigginton
  41. * @license http://www.opensource.org/licenses/mit-license.html MIT License
  42. * @version $Id$
  43. * @link htp://phpseclib.sourceforge.net
  44. */
  45. /**
  46. * Include File_ASN1
  47. */
  48. if (!class_exists('File_ASN1')) {
  49. require_once('File/ASN1.php');
  50. }
  51. /**
  52. * Flag to only accept signatures signed by certificate authorities
  53. *
  54. * @access public
  55. * @see File_X509::validateSignature()
  56. */
  57. define('FILE_X509_VALIDATE_SIGNATURE_BY_CA', 1);
  58. /**#@+
  59. * @access public
  60. * @see File_X509::getDN()
  61. */
  62. /**
  63. * Return internal array representation
  64. */
  65. define('FILE_X509_DN_ARRAY', 0);
  66. /**
  67. * Return string
  68. */
  69. define('FILE_X509_DN_STRING', 1);
  70. /**
  71. * Return ASN.1 name string
  72. */
  73. define('FILE_X509_DN_ASN1', 2);
  74. /**
  75. * Return OpenSSL compatible array
  76. */
  77. define('FILE_X509_DN_OPENSSL', 3);
  78. /**
  79. * Return canonical ASN.1 RDNs string
  80. */
  81. define('FILE_X509_DN_CANON', 4);
  82. /**
  83. * Return name hash for file indexing
  84. */
  85. define('FILE_X509_DN_HASH', 5);
  86. /**#@-*/
  87. /**#@+
  88. * @access public
  89. * @see File_X509::saveX509()
  90. * @see File_X509::saveCSR()
  91. * @see File_X509::saveCRL()
  92. */
  93. /**
  94. * Save as PEM
  95. *
  96. * ie. a base64-encoded PEM with a header and a footer
  97. */
  98. define('FILE_X509_FORMAT_PEM', 0);
  99. /**
  100. * Save as DER
  101. */
  102. define('FILE_X509_FORMAT_DER', 1);
  103. /**
  104. * Save as a SPKAC
  105. *
  106. * Only works on CSRs. Not currently supported.
  107. */
  108. define('FILE_X509_FORMAT_SPKAC', 2);
  109. /**#@-*/
  110. /**
  111. * Attribute value disposition.
  112. * If disposition is >= 0, this is the index of the target value.
  113. */
  114. define('FILE_X509_ATTR_ALL', -1); // All attribute values (array).
  115. define('FILE_X509_ATTR_APPEND', -2); // Add a value.
  116. define('FILE_X509_ATTR_REPLACE', -3); // Clear first, then add a value.
  117. /**
  118. * Pure-PHP X.509 Parser
  119. *
  120. * @author Jim Wigginton <terrafrost@php.net>
  121. * @version 0.3.1
  122. * @access public
  123. * @package File_X509
  124. */
  125. class File_X509 {
  126. /**
  127. * ASN.1 syntax for X.509 certificates
  128. *
  129. * @var Array
  130. * @access private
  131. */
  132. var $Certificate;
  133. /**#@+
  134. * ASN.1 syntax for various extensions
  135. *
  136. * @access private
  137. */
  138. var $DirectoryString;
  139. var $PKCS9String;
  140. var $AttributeValue;
  141. var $Extensions;
  142. var $KeyUsage;
  143. var $ExtKeyUsageSyntax;
  144. var $BasicConstraints;
  145. var $KeyIdentifier;
  146. var $CRLDistributionPoints;
  147. var $AuthorityKeyIdentifier;
  148. var $CertificatePolicies;
  149. var $AuthorityInfoAccessSyntax;
  150. var $SubjectAltName;
  151. var $PrivateKeyUsagePeriod;
  152. var $IssuerAltName;
  153. var $PolicyMappings;
  154. var $NameConstraints;
  155. var $CPSuri;
  156. var $UserNotice;
  157. var $netscape_cert_type;
  158. var $netscape_comment;
  159. var $netscape_ca_policy_url;
  160. var $Name;
  161. var $RelativeDistinguishedName;
  162. var $CRLNumber;
  163. var $CRLReason;
  164. var $IssuingDistributionPoint;
  165. var $InvalidityDate;
  166. var $CertificateIssuer;
  167. var $HoldInstructionCode;
  168. var $SignedPublicKeyAndChallenge;
  169. /**#@-*/
  170. /**
  171. * ASN.1 syntax for Certificate Signing Requests (RFC2986)
  172. *
  173. * @var Array
  174. * @access private
  175. */
  176. var $CertificationRequest;
  177. /**
  178. * ASN.1 syntax for Certificate Revocation Lists (RFC5280)
  179. *
  180. * @var Array
  181. * @access private
  182. */
  183. var $CertificateList;
  184. /**
  185. * Distinguished Name
  186. *
  187. * @var Array
  188. * @access private
  189. */
  190. var $dn;
  191. /**
  192. * Public key
  193. *
  194. * @var String
  195. * @access private
  196. */
  197. var $publicKey;
  198. /**
  199. * Private key
  200. *
  201. * @var String
  202. * @access private
  203. */
  204. var $privateKey;
  205. /**
  206. * Object identifiers for X.509 certificates
  207. *
  208. * @var Array
  209. * @access private
  210. * @link http://en.wikipedia.org/wiki/Object_identifier
  211. */
  212. var $oids;
  213. /**
  214. * The certificate authorities
  215. *
  216. * @var Array
  217. * @access private
  218. */
  219. var $CAs;
  220. /**
  221. * The currently loaded certificate
  222. *
  223. * @var Array
  224. * @access private
  225. */
  226. var $currentCert;
  227. /**
  228. * The signature subject
  229. *
  230. * There's no guarantee File_X509 is going to reencode an X.509 cert in the same way it was originally
  231. * encoded so we take save the portion of the original cert that the signature would have made for.
  232. *
  233. * @var String
  234. * @access private
  235. */
  236. var $signatureSubject;
  237. /**
  238. * Certificate Start Date
  239. *
  240. * @var String
  241. * @access private
  242. */
  243. var $startDate;
  244. /**
  245. * Certificate End Date
  246. *
  247. * @var String
  248. * @access private
  249. */
  250. var $endDate;
  251. /**
  252. * Serial Number
  253. *
  254. * @var String
  255. * @access private
  256. */
  257. var $serialNumber;
  258. /**
  259. * Key Identifier
  260. *
  261. * See {@link http://tools.ietf.org/html/rfc5280#section-4.2.1.1 RFC5280#section-4.2.1.1} and
  262. * {@link http://tools.ietf.org/html/rfc5280#section-4.2.1.2 RFC5280#section-4.2.1.2}.
  263. *
  264. * @var String
  265. * @access private
  266. */
  267. var $currentKeyIdentifier;
  268. /**
  269. * CA Flag
  270. *
  271. * @var Boolean
  272. * @access private
  273. */
  274. var $caFlag = false;
  275. /**
  276. * Default Constructor.
  277. *
  278. * @return File_X509
  279. * @access public
  280. */
  281. function File_X509()
  282. {
  283. // Explicitly Tagged Module, 1988 Syntax
  284. // http://tools.ietf.org/html/rfc5280#appendix-A.1
  285. $this->DirectoryString = array(
  286. 'type' => FILE_ASN1_TYPE_CHOICE,
  287. 'children' => array(
  288. 'teletexString' => array('type' => FILE_ASN1_TYPE_TELETEX_STRING),
  289. 'printableString' => array('type' => FILE_ASN1_TYPE_PRINTABLE_STRING),
  290. 'universalString' => array('type' => FILE_ASN1_TYPE_UNIVERSAL_STRING),
  291. 'utf8String' => array('type' => FILE_ASN1_TYPE_UTF8_STRING),
  292. 'bmpString' => array('type' => FILE_ASN1_TYPE_BMP_STRING)
  293. )
  294. );
  295. $this->PKCS9String = array(
  296. 'type' => FILE_ASN1_TYPE_CHOICE,
  297. 'children' => array(
  298. 'ia5String' => array('type' => FILE_ASN1_TYPE_IA5_STRING),
  299. 'directoryString' => $this->DirectoryString
  300. )
  301. );
  302. $this->AttributeValue = array('type' => FILE_ASN1_TYPE_ANY);
  303. $AttributeType = array('type' => FILE_ASN1_TYPE_OBJECT_IDENTIFIER);
  304. $AttributeTypeAndValue = array(
  305. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  306. 'children' => array(
  307. 'type' => $AttributeType,
  308. 'value'=> $this->AttributeValue
  309. )
  310. );
  311. /*
  312. In practice, RDNs containing multiple name-value pairs (called "multivalued RDNs") are rare,
  313. but they can be useful at times when either there is no unique attribute in the entry or you
  314. want to ensure that the entry's DN contains some useful identifying information.
  315. - https://www.opends.org/wiki/page/DefinitionRelativeDistinguishedName
  316. */
  317. $this->RelativeDistinguishedName = array(
  318. 'type' => FILE_ASN1_TYPE_SET,
  319. 'min' => 1,
  320. 'max' => -1,
  321. 'children' => $AttributeTypeAndValue
  322. );
  323. // http://tools.ietf.org/html/rfc5280#section-4.1.2.4
  324. $RDNSequence = array(
  325. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  326. // RDNSequence does not define a min or a max, which means it doesn't have one
  327. 'min' => 0,
  328. 'max' => -1,
  329. 'children' => $this->RelativeDistinguishedName
  330. );
  331. $this->Name = array(
  332. 'type' => FILE_ASN1_TYPE_CHOICE,
  333. 'children' => array(
  334. 'rdnSequence' => $RDNSequence
  335. )
  336. );
  337. // http://tools.ietf.org/html/rfc5280#section-4.1.1.2
  338. $AlgorithmIdentifier = array(
  339. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  340. 'children' => array(
  341. 'algorithm' => array('type' => FILE_ASN1_TYPE_OBJECT_IDENTIFIER),
  342. 'parameters' => array(
  343. 'type' => FILE_ASN1_TYPE_ANY,
  344. 'optional' => true
  345. )
  346. )
  347. );
  348. /*
  349. A certificate using system MUST reject the certificate if it encounters
  350. a critical extension it does not recognize; however, a non-critical
  351. extension may be ignored if it is not recognized.
  352. http://tools.ietf.org/html/rfc5280#section-4.2
  353. */
  354. $Extension = array(
  355. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  356. 'children' => array(
  357. 'extnId' => array('type' => FILE_ASN1_TYPE_OBJECT_IDENTIFIER),
  358. 'critical' => array(
  359. 'type' => FILE_ASN1_TYPE_BOOLEAN,
  360. 'optional' => true,
  361. 'default' => false
  362. ),
  363. 'extnValue' => array('type' => FILE_ASN1_TYPE_OCTET_STRING)
  364. )
  365. );
  366. $this->Extensions = array(
  367. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  368. 'min' => 1,
  369. // technically, it's MAX, but we'll assume anything < 0 is MAX
  370. 'max' => -1,
  371. // if 'children' isn't an array then 'min' and 'max' must be defined
  372. 'children' => $Extension
  373. );
  374. $SubjectPublicKeyInfo = array(
  375. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  376. 'children' => array(
  377. 'algorithm' => $AlgorithmIdentifier,
  378. 'subjectPublicKey' => array('type' => FILE_ASN1_TYPE_BIT_STRING)
  379. )
  380. );
  381. $UniqueIdentifier = array('type' => FILE_ASN1_TYPE_BIT_STRING);
  382. $Time = array(
  383. 'type' => FILE_ASN1_TYPE_CHOICE,
  384. 'children' => array(
  385. 'utcTime' => array('type' => FILE_ASN1_TYPE_UTC_TIME),
  386. 'generalTime' => array('type' => FILE_ASN1_TYPE_GENERALIZED_TIME)
  387. )
  388. );
  389. // http://tools.ietf.org/html/rfc5280#section-4.1.2.5
  390. $Validity = array(
  391. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  392. 'children' => array(
  393. 'notBefore' => $Time,
  394. 'notAfter' => $Time
  395. )
  396. );
  397. $CertificateSerialNumber = array('type' => FILE_ASN1_TYPE_INTEGER);
  398. $Version = array(
  399. 'type' => FILE_ASN1_TYPE_INTEGER,
  400. 'mapping' => array('v1', 'v2', 'v3')
  401. );
  402. // assert($TBSCertificate['children']['signature'] == $Certificate['children']['signatureAlgorithm'])
  403. $TBSCertificate = array(
  404. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  405. 'children' => array(
  406. // technically, default implies optional, but we'll define it as being optional, none-the-less, just to
  407. // reenforce that fact
  408. 'version' => array(
  409. 'constant' => 0,
  410. 'optional' => true,
  411. 'explicit' => true,
  412. 'default' => 'v1'
  413. ) + $Version,
  414. 'serialNumber' => $CertificateSerialNumber,
  415. 'signature' => $AlgorithmIdentifier,
  416. 'issuer' => $this->Name,
  417. 'validity' => $Validity,
  418. 'subject' => $this->Name,
  419. 'subjectPublicKeyInfo' => $SubjectPublicKeyInfo,
  420. // implicit means that the T in the TLV structure is to be rewritten, regardless of the type
  421. 'issuerUniqueID' => array(
  422. 'constant' => 1,
  423. 'optional' => true,
  424. 'implicit' => true
  425. ) + $UniqueIdentifier,
  426. 'subjectUniqueID' => array(
  427. 'constant' => 2,
  428. 'optional' => true,
  429. 'implicit' => true
  430. ) + $UniqueIdentifier,
  431. // <http://tools.ietf.org/html/rfc2459#page-74> doesn't use the EXPLICIT keyword but if
  432. // it's not IMPLICIT, it's EXPLICIT
  433. 'extensions' => array(
  434. 'constant' => 3,
  435. 'optional' => true,
  436. 'explicit' => true
  437. ) + $this->Extensions
  438. )
  439. );
  440. $this->Certificate = array(
  441. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  442. 'children' => array(
  443. 'tbsCertificate' => $TBSCertificate,
  444. 'signatureAlgorithm' => $AlgorithmIdentifier,
  445. 'signature' => array('type' => FILE_ASN1_TYPE_BIT_STRING)
  446. )
  447. );
  448. $this->KeyUsage = array(
  449. 'type' => FILE_ASN1_TYPE_BIT_STRING,
  450. 'mapping' => array(
  451. 'digitalSignature',
  452. 'nonRepudiation',
  453. 'keyEncipherment',
  454. 'dataEncipherment',
  455. 'keyAgreement',
  456. 'keyCertSign',
  457. 'cRLSign',
  458. 'encipherOnly',
  459. 'decipherOnly'
  460. )
  461. );
  462. $this->BasicConstraints = array(
  463. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  464. 'children' => array(
  465. 'cA' => array(
  466. 'type' => FILE_ASN1_TYPE_BOOLEAN,
  467. 'optional' => true,
  468. 'default' => false
  469. ),
  470. 'pathLenConstraint' => array(
  471. 'type' => FILE_ASN1_TYPE_INTEGER,
  472. 'optional' => true
  473. )
  474. )
  475. );
  476. $this->KeyIdentifier = array('type' => FILE_ASN1_TYPE_OCTET_STRING);
  477. $OrganizationalUnitNames = array(
  478. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  479. 'min' => 1,
  480. 'max' => 4, // ub-organizational-units
  481. 'children' => array('type' => FILE_ASN1_TYPE_PRINTABLE_STRING)
  482. );
  483. $PersonalName = array(
  484. 'type' => FILE_ASN1_TYPE_SET,
  485. 'children' => array(
  486. 'surname' => array(
  487. 'type' => FILE_ASN1_TYPE_PRINTABLE_STRING,
  488. 'constant' => 0,
  489. 'optional' => true,
  490. 'implicit' => true
  491. ),
  492. 'given-name' => array(
  493. 'type' => FILE_ASN1_TYPE_PRINTABLE_STRING,
  494. 'constant' => 1,
  495. 'optional' => true,
  496. 'implicit' => true
  497. ),
  498. 'initials' => array(
  499. 'type' => FILE_ASN1_TYPE_PRINTABLE_STRING,
  500. 'constant' => 2,
  501. 'optional' => true,
  502. 'implicit' => true
  503. ),
  504. 'generation-qualifier' => array(
  505. 'type' => FILE_ASN1_TYPE_PRINTABLE_STRING,
  506. 'constant' => 3,
  507. 'optional' => true,
  508. 'implicit' => true
  509. )
  510. )
  511. );
  512. $NumericUserIdentifier = array('type' => FILE_ASN1_TYPE_NUMERIC_STRING);
  513. $OrganizationName = array('type' => FILE_ASN1_TYPE_PRINTABLE_STRING);
  514. $PrivateDomainName = array(
  515. 'type' => FILE_ASN1_TYPE_CHOICE,
  516. 'children' => array(
  517. 'numeric' => array('type' => FILE_ASN1_TYPE_NUMERIC_STRING),
  518. 'printable' => array('type' => FILE_ASN1_TYPE_PRINTABLE_STRING)
  519. )
  520. );
  521. $TerminalIdentifier = array('type' => FILE_ASN1_TYPE_PRINTABLE_STRING);
  522. $NetworkAddress = array('type' => FILE_ASN1_TYPE_NUMERIC_STRING);
  523. $AdministrationDomainName = array(
  524. 'type' => FILE_ASN1_TYPE_CHOICE,
  525. // if class isn't present it's assumed to be FILE_ASN1_CLASS_UNIVERSAL or
  526. // (if constant is present) FILE_ASN1_CLASS_CONTEXT_SPECIFIC
  527. 'class' => FILE_ASN1_CLASS_APPLICATION,
  528. 'cast' => 2,
  529. 'children' => array(
  530. 'numeric' => array('type' => FILE_ASN1_TYPE_NUMERIC_STRING),
  531. 'printable' => array('type' => FILE_ASN1_TYPE_PRINTABLE_STRING)
  532. )
  533. );
  534. $CountryName = array(
  535. 'type' => FILE_ASN1_TYPE_CHOICE,
  536. // if class isn't present it's assumed to be FILE_ASN1_CLASS_UNIVERSAL or
  537. // (if constant is present) FILE_ASN1_CLASS_CONTEXT_SPECIFIC
  538. 'class' => FILE_ASN1_CLASS_APPLICATION,
  539. 'cast' => 1,
  540. 'children' => array(
  541. 'x121-dcc-code' => array('type' => FILE_ASN1_TYPE_NUMERIC_STRING),
  542. 'iso-3166-alpha2-code' => array('type' => FILE_ASN1_TYPE_PRINTABLE_STRING)
  543. )
  544. );
  545. $AnotherName = array(
  546. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  547. 'children' => array(
  548. 'type-id' => array('type' => FILE_ASN1_TYPE_OBJECT_IDENTIFIER),
  549. 'value' => array(
  550. 'type' => FILE_ASN1_TYPE_ANY,
  551. 'constant' => 0,
  552. 'optional' => true,
  553. 'explicit' => true
  554. )
  555. )
  556. );
  557. $ExtensionAttribute = array(
  558. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  559. 'children' => array(
  560. 'extension-attribute-type' => array(
  561. 'type' => FILE_ASN1_TYPE_PRINTABLE_STRING,
  562. 'constant' => 0,
  563. 'optional' => true,
  564. 'implicit' => true
  565. ),
  566. 'extension-attribute-value' => array(
  567. 'type' => FILE_ASN1_TYPE_ANY,
  568. 'constant' => 1,
  569. 'optional' => true,
  570. 'explicit' => true
  571. )
  572. )
  573. );
  574. $ExtensionAttributes = array(
  575. 'type' => FILE_ASN1_TYPE_SET,
  576. 'min' => 1,
  577. 'max' => 256, // ub-extension-attributes
  578. 'children' => $ExtensionAttribute
  579. );
  580. $BuiltInDomainDefinedAttribute = array(
  581. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  582. 'children' => array(
  583. 'type' => array('type' => FILE_ASN1_TYPE_PRINTABLE_STRING),
  584. 'value' => array('type' => FILE_ASN1_TYPE_PRINTABLE_STRING)
  585. )
  586. );
  587. $BuiltInDomainDefinedAttributes = array(
  588. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  589. 'min' => 1,
  590. 'max' => 4, // ub-domain-defined-attributes
  591. 'children' => $BuiltInDomainDefinedAttribute
  592. );
  593. $BuiltInStandardAttributes = array(
  594. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  595. 'children' => array(
  596. 'country-name' => array('optional' => true) + $CountryName,
  597. 'administration-domain-name' => array('optional' => true) + $AdministrationDomainName,
  598. 'network-address' => array(
  599. 'constant' => 0,
  600. 'optional' => true,
  601. 'implicit' => true
  602. ) + $NetworkAddress,
  603. 'terminal-identifier' => array(
  604. 'constant' => 1,
  605. 'optional' => true,
  606. 'implicit' => true
  607. ) + $TerminalIdentifier,
  608. 'private-domain-name' => array(
  609. 'constant' => 2,
  610. 'optional' => true,
  611. 'explicit' => true
  612. ) + $PrivateDomainName,
  613. 'organization-name' => array(
  614. 'constant' => 3,
  615. 'optional' => true,
  616. 'implicit' => true
  617. ) + $OrganizationName,
  618. 'numeric-user-identifier' => array(
  619. 'constant' => 4,
  620. 'optional' => true,
  621. 'implicit' => true
  622. ) + $NumericUserIdentifier,
  623. 'personal-name' => array(
  624. 'constant' => 5,
  625. 'optional' => true,
  626. 'implicit' => true
  627. ) + $PersonalName,
  628. 'organizational-unit-names' => array(
  629. 'constant' => 6,
  630. 'optional' => true,
  631. 'implicit' => true
  632. ) + $OrganizationalUnitNames
  633. )
  634. );
  635. $ORAddress = array(
  636. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  637. 'children' => array(
  638. 'built-in-standard-attributes' => $BuiltInStandardAttributes,
  639. 'built-in-domain-defined-attributes' => array('optional' => true) + $BuiltInDomainDefinedAttributes,
  640. 'extension-attributes' => array('optional' => true) + $ExtensionAttributes
  641. )
  642. );
  643. $EDIPartyName = array(
  644. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  645. 'children' => array(
  646. 'nameAssigner' => array(
  647. 'constant' => 0,
  648. 'optional' => true,
  649. 'implicit' => true
  650. ) + $this->DirectoryString,
  651. // partyName is technically required but File_ASN1 doesn't currently support non-optional constants and
  652. // setting it to optional gets the job done in any event.
  653. 'partyName' => array(
  654. 'constant' => 1,
  655. 'optional' => true,
  656. 'implicit' => true
  657. ) + $this->DirectoryString
  658. )
  659. );
  660. $GeneralName = array(
  661. 'type' => FILE_ASN1_TYPE_CHOICE,
  662. 'children' => array(
  663. 'otherName' => array(
  664. 'constant' => 0,
  665. 'optional' => true,
  666. 'implicit' => true
  667. ) + $AnotherName,
  668. 'rfc822Name' => array(
  669. 'type' => FILE_ASN1_TYPE_IA5_STRING,
  670. 'constant' => 1,
  671. 'optional' => true,
  672. 'implicit' => true
  673. ),
  674. 'dNSName' => array(
  675. 'type' => FILE_ASN1_TYPE_IA5_STRING,
  676. 'constant' => 2,
  677. 'optional' => true,
  678. 'implicit' => true
  679. ),
  680. 'x400Address' => array(
  681. 'constant' => 3,
  682. 'optional' => true,
  683. 'implicit' => true
  684. ) + $ORAddress,
  685. 'directoryName' => array(
  686. 'constant' => 4,
  687. 'optional' => true,
  688. 'explicit' => true
  689. ) + $this->Name,
  690. 'ediPartyName' => array(
  691. 'constant' => 5,
  692. 'optional' => true,
  693. 'implicit' => true
  694. ) + $EDIPartyName,
  695. 'uniformResourceIdentifier' => array(
  696. 'type' => FILE_ASN1_TYPE_IA5_STRING,
  697. 'constant' => 6,
  698. 'optional' => true,
  699. 'implicit' => true
  700. ),
  701. 'iPAddress' => array(
  702. 'type' => FILE_ASN1_TYPE_OCTET_STRING,
  703. 'constant' => 7,
  704. 'optional' => true,
  705. 'implicit' => true
  706. ),
  707. 'registeredID' => array(
  708. 'type' => FILE_ASN1_TYPE_OBJECT_IDENTIFIER,
  709. 'constant' => 8,
  710. 'optional' => true,
  711. 'implicit' => true
  712. )
  713. )
  714. );
  715. $GeneralNames = array(
  716. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  717. 'min' => 1,
  718. 'max' => -1,
  719. 'children' => $GeneralName
  720. );
  721. $this->IssuerAltName = $GeneralNames;
  722. $ReasonFlags = array(
  723. 'type' => FILE_ASN1_TYPE_BIT_STRING,
  724. 'mapping' => array(
  725. 'unused',
  726. 'keyCompromise',
  727. 'cACompromise',
  728. 'affiliationChanged',
  729. 'superseded',
  730. 'cessationOfOperation',
  731. 'certificateHold',
  732. 'privilegeWithdrawn',
  733. 'aACompromise'
  734. )
  735. );
  736. $DistributionPointName = array(
  737. 'type' => FILE_ASN1_TYPE_CHOICE,
  738. 'children' => array(
  739. 'fullName' => array(
  740. 'constant' => 0,
  741. 'optional' => true,
  742. 'implicit' => true
  743. ) + $GeneralNames,
  744. 'nameRelativeToCRLIssuer' => array(
  745. 'constant' => 1,
  746. 'optional' => true,
  747. 'implicit' => true
  748. ) + $this->RelativeDistinguishedName
  749. )
  750. );
  751. $DistributionPoint = array(
  752. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  753. 'children' => array(
  754. 'distributionPoint' => array(
  755. 'constant' => 0,
  756. 'optional' => true,
  757. 'explicit' => true
  758. ) + $DistributionPointName,
  759. 'reasons' => array(
  760. 'constant' => 1,
  761. 'optional' => true,
  762. 'implicit' => true
  763. ) + $ReasonFlags,
  764. 'cRLIssuer' => array(
  765. 'constant' => 2,
  766. 'optional' => true,
  767. 'implicit' => true
  768. ) + $GeneralNames
  769. )
  770. );
  771. $this->CRLDistributionPoints = array(
  772. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  773. 'min' => 1,
  774. 'max' => -1,
  775. 'children' => $DistributionPoint
  776. );
  777. $this->AuthorityKeyIdentifier = array(
  778. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  779. 'children' => array(
  780. 'keyIdentifier' => array(
  781. 'constant' => 0,
  782. 'optional' => true,
  783. 'implicit' => true
  784. ) + $this->KeyIdentifier,
  785. 'authorityCertIssuer' => array(
  786. 'constant' => 1,
  787. 'optional' => true,
  788. 'implicit' => true
  789. ) + $GeneralNames,
  790. 'authorityCertSerialNumber' => array(
  791. 'constant' => 2,
  792. 'optional' => true,
  793. 'implicit' => true
  794. ) + $CertificateSerialNumber
  795. )
  796. );
  797. $PolicyQualifierId = array('type' => FILE_ASN1_TYPE_OBJECT_IDENTIFIER);
  798. $PolicyQualifierInfo = array(
  799. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  800. 'children' => array(
  801. 'policyQualifierId' => $PolicyQualifierId,
  802. 'qualifier' => array('type' => FILE_ASN1_TYPE_ANY)
  803. )
  804. );
  805. $CertPolicyId = array('type' => FILE_ASN1_TYPE_OBJECT_IDENTIFIER);
  806. $PolicyInformation = array(
  807. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  808. 'children' => array(
  809. 'policyIdentifier' => $CertPolicyId,
  810. 'policyQualifiers' => array(
  811. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  812. 'min' => 0,
  813. 'max' => -1,
  814. 'optional' => true,
  815. 'children' => $PolicyQualifierInfo
  816. )
  817. )
  818. );
  819. $this->CertificatePolicies = array(
  820. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  821. 'min' => 1,
  822. 'max' => -1,
  823. 'children' => $PolicyInformation
  824. );
  825. $this->PolicyMappings = array(
  826. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  827. 'min' => 1,
  828. 'max' => -1,
  829. 'children' => array(
  830. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  831. 'children' => array(
  832. 'issuerDomainPolicy' => $CertPolicyId,
  833. 'subjectDomainPolicy' => $CertPolicyId
  834. )
  835. )
  836. );
  837. $KeyPurposeId = array('type' => FILE_ASN1_TYPE_OBJECT_IDENTIFIER);
  838. $this->ExtKeyUsageSyntax = array(
  839. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  840. 'min' => 1,
  841. 'max' => -1,
  842. 'children' => $KeyPurposeId
  843. );
  844. $AccessDescription = array(
  845. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  846. 'children' => array(
  847. 'accessMethod' => array('type' => FILE_ASN1_TYPE_OBJECT_IDENTIFIER),
  848. 'accessLocation' => $GeneralName
  849. )
  850. );
  851. $this->AuthorityInfoAccessSyntax = array(
  852. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  853. 'min' => 1,
  854. 'max' => -1,
  855. 'children' => $AccessDescription
  856. );
  857. $this->SubjectAltName = $GeneralNames;
  858. $this->PrivateKeyUsagePeriod = array(
  859. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  860. 'children' => array(
  861. 'notBefore' => array(
  862. 'constant' => 0,
  863. 'optional' => true,
  864. 'implicit' => true,
  865. 'type' => FILE_ASN1_TYPE_GENERALIZED_TIME),
  866. 'notAfter' => array(
  867. 'constant' => 1,
  868. 'optional' => true,
  869. 'implicit' => true,
  870. 'type' => FILE_ASN1_TYPE_GENERALIZED_TIME)
  871. )
  872. );
  873. $BaseDistance = array('type' => FILE_ASN1_TYPE_INTEGER);
  874. $GeneralSubtree = array(
  875. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  876. 'children' => array(
  877. 'base' => $GeneralName,
  878. 'minimum' => array(
  879. 'constant' => 0,
  880. 'optional' => true,
  881. 'implicit' => true,
  882. 'default' => new Math_BigInteger(0)
  883. ) + $BaseDistance,
  884. 'maximum' => array(
  885. 'constant' => 1,
  886. 'optional' => true,
  887. 'implicit' => true,
  888. ) + $BaseDistance
  889. )
  890. );
  891. $GeneralSubtrees = array(
  892. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  893. 'min' => 1,
  894. 'max' => -1,
  895. 'children' => $GeneralSubtree
  896. );
  897. $this->NameConstraints = array(
  898. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  899. 'children' => array(
  900. 'permittedSubtrees' => array(
  901. 'constant' => 0,
  902. 'optional' => true,
  903. 'implicit' => true
  904. ) + $GeneralSubtrees,
  905. 'excludedSubtrees' => array(
  906. 'constant' => 1,
  907. 'optional' => true,
  908. 'implicit' => true
  909. ) + $GeneralSubtrees
  910. )
  911. );
  912. $this->CPSuri = array('type' => FILE_ASN1_TYPE_IA5_STRING);
  913. $DisplayText = array(
  914. 'type' => FILE_ASN1_TYPE_CHOICE,
  915. 'children' => array(
  916. 'ia5String' => array('type' => FILE_ASN1_TYPE_IA5_STRING),
  917. 'visibleString' => array('type' => FILE_ASN1_TYPE_VISIBLE_STRING),
  918. 'bmpString' => array('type' => FILE_ASN1_TYPE_BMP_STRING),
  919. 'utf8String' => array('type' => FILE_ASN1_TYPE_UTF8_STRING)
  920. )
  921. );
  922. $NoticeReference = array(
  923. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  924. 'children' => array(
  925. 'organization' => $DisplayText,
  926. 'noticeNumbers' => array(
  927. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  928. 'min' => 1,
  929. 'max' => 200,
  930. 'children' => array('type' => FILE_ASN1_TYPE_INTEGER)
  931. )
  932. )
  933. );
  934. $this->UserNotice = array(
  935. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  936. 'children' => array(
  937. 'noticeRef' => array(
  938. 'optional' => true,
  939. 'implicit' => true
  940. ) + $NoticeReference,
  941. 'explicitText' => array(
  942. 'optional' => true,
  943. 'implicit' => true
  944. ) + $DisplayText
  945. )
  946. );
  947. // mapping is from <http://www.mozilla.org/projects/security/pki/nss/tech-notes/tn3.html>
  948. $this->netscape_cert_type = array(
  949. 'type' => FILE_ASN1_TYPE_BIT_STRING,
  950. 'mapping' => array(
  951. 'SSLClient',
  952. 'SSLServer',
  953. 'Email',
  954. 'ObjectSigning',
  955. 'Reserved',
  956. 'SSLCA',
  957. 'EmailCA',
  958. 'ObjectSigningCA'
  959. )
  960. );
  961. $this->netscape_comment = array('type' => FILE_ASN1_TYPE_IA5_STRING);
  962. $this->netscape_ca_policy_url = array('type' => FILE_ASN1_TYPE_IA5_STRING);
  963. // attribute is used in RFC2986 but we're using the RFC5280 definition
  964. $Attribute = array(
  965. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  966. 'children' => array(
  967. 'type' => $AttributeType,
  968. 'value'=> array(
  969. 'type' => FILE_ASN1_TYPE_SET,
  970. 'min' => 1,
  971. 'max' => -1,
  972. 'children' => $this->AttributeValue
  973. )
  974. )
  975. );
  976. // adapted from <http://tools.ietf.org/html/rfc2986>
  977. $Attributes = array(
  978. 'type' => FILE_ASN1_TYPE_SET,
  979. 'min' => 1,
  980. 'max' => -1,
  981. 'children' => $Attribute
  982. );
  983. $CertificationRequestInfo = array(
  984. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  985. 'children' => array(
  986. 'version' => array(
  987. 'type' => FILE_ASN1_TYPE_INTEGER,
  988. 'mapping' => array('v1')
  989. ),
  990. 'subject' => $this->Name,
  991. 'subjectPKInfo' => $SubjectPublicKeyInfo,
  992. 'attributes' => array(
  993. 'constant' => 0,
  994. 'optional' => true,
  995. 'implicit' => true
  996. ) + $Attributes,
  997. )
  998. );
  999. $this->CertificationRequest = array(
  1000. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  1001. 'children' => array(
  1002. 'certificationRequestInfo' => $CertificationRequestInfo,
  1003. 'signatureAlgorithm' => $AlgorithmIdentifier,
  1004. 'signature' => array('type' => FILE_ASN1_TYPE_BIT_STRING)
  1005. )
  1006. );
  1007. $RevokedCertificate = array(
  1008. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  1009. 'children' => array(
  1010. 'userCertificate' => $CertificateSerialNumber,
  1011. 'revocationDate' => $Time,
  1012. 'crlEntryExtensions' => array(
  1013. 'optional' => true
  1014. ) + $this->Extensions
  1015. )
  1016. );
  1017. $TBSCertList = array(
  1018. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  1019. 'children' => array(
  1020. 'version' => array(
  1021. 'optional' => true,
  1022. 'default' => 'v1'
  1023. ) + $Version,
  1024. 'signature' => $AlgorithmIdentifier,
  1025. 'issuer' => $this->Name,
  1026. 'thisUpdate' => $Time,
  1027. 'nextUpdate' => array(
  1028. 'optional' => true
  1029. ) + $Time,
  1030. 'revokedCertificates' => array(
  1031. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  1032. 'optional' => true,
  1033. 'min' => 0,
  1034. 'max' => -1,
  1035. 'children' => $RevokedCertificate
  1036. ),
  1037. 'crlExtensions' => array(
  1038. 'constant' => 0,
  1039. 'optional' => true,
  1040. 'explicit' => true
  1041. ) + $this->Extensions
  1042. )
  1043. );
  1044. $this->CertificateList = array(
  1045. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  1046. 'children' => array(
  1047. 'tbsCertList' => $TBSCertList,
  1048. 'signatureAlgorithm' => $AlgorithmIdentifier,
  1049. 'signature' => array('type' => FILE_ASN1_TYPE_BIT_STRING)
  1050. )
  1051. );
  1052. $this->CRLNumber = array('type' => FILE_ASN1_TYPE_INTEGER);
  1053. $this->CRLReason = array('type' => FILE_ASN1_TYPE_ENUMERATED,
  1054. 'mapping' => array(
  1055. 'unspecified',
  1056. 'keyCompromise',
  1057. 'cACompromise',
  1058. 'affiliationChanged',
  1059. 'superseded',
  1060. 'cessationOfOperation',
  1061. 'certificateHold',
  1062. // Value 7 is not used.
  1063. 8 => 'removeFromCRL',
  1064. 'privilegeWithdrawn',
  1065. 'aACompromise'
  1066. )
  1067. );
  1068. $this->IssuingDistributionPoint = array('type' => FILE_ASN1_TYPE_SEQUENCE,
  1069. 'children' => array(
  1070. 'distributionPoint' => array(
  1071. 'constant' => 0,
  1072. 'optional' => true,
  1073. 'explicit' => true
  1074. ) + $DistributionPointName,
  1075. 'onlyContainsUserCerts' => array(
  1076. 'type' => FILE_ASN1_TYPE_BOOLEAN,
  1077. 'constant' => 1,
  1078. 'optional' => true,
  1079. 'default' => false,
  1080. 'implicit' => true
  1081. ),
  1082. 'onlyContainsCACerts' => array(
  1083. 'type' => FILE_ASN1_TYPE_BOOLEAN,
  1084. 'constant' => 2,
  1085. 'optional' => true,
  1086. 'default' => false,
  1087. 'implicit' => true
  1088. ),
  1089. 'onlySomeReasons' => array(
  1090. 'constant' => 3,
  1091. 'optional' => true,
  1092. 'implicit' => true
  1093. ) + $ReasonFlags,
  1094. 'indirectCRL' => array(
  1095. 'type' => FILE_ASN1_TYPE_BOOLEAN,
  1096. 'constant' => 4,
  1097. 'optional' => true,
  1098. 'default' => false,
  1099. 'implicit' => true
  1100. ),
  1101. 'onlyContainsAttributeCerts' => array(
  1102. 'type' => FILE_ASN1_TYPE_BOOLEAN,
  1103. 'constant' => 5,
  1104. 'optional' => true,
  1105. 'default' => false,
  1106. 'implicit' => true
  1107. )
  1108. )
  1109. );
  1110. $this->InvalidityDate = array('type' => FILE_ASN1_TYPE_GENERALIZED_TIME);
  1111. $this->CertificateIssuer = $GeneralNames;
  1112. $this->HoldInstructionCode = array('type' => FILE_ASN1_TYPE_OBJECT_IDENTIFIER);
  1113. $PublicKeyAndChallenge = array(
  1114. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  1115. 'children' => array(
  1116. 'spki' => $SubjectPublicKeyInfo,
  1117. 'challenge' => array('type' => FILE_ASN1_TYPE_IA5_STRING)
  1118. )
  1119. );
  1120. $this->SignedPublicKeyAndChallenge = array(
  1121. 'type' => FILE_ASN1_TYPE_SEQUENCE,
  1122. 'children' => array(
  1123. 'publicKeyAndChallenge' => $PublicKeyAndChallenge,
  1124. 'signatureAlgorithm' => $AlgorithmIdentifier,
  1125. 'signature' => array('type' => FILE_ASN1_TYPE_BIT_STRING)
  1126. )
  1127. );
  1128. // OIDs from RFC5280 and those RFCs mentioned in RFC5280#section-4.1.1.2
  1129. $this->oids = array(
  1130. '1.3.6.1.5.5.7' =>

Large files files are truncated, but you can click here to view the full file