PageRenderTime 60ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/vendor/phpseclib/phpseclib/phpseclib/File/X509.php

https://bitbucket.org/openemr/openemr
PHP | 4614 lines | 3049 code | 460 blank | 1105 comment | 390 complexity | 39ea599ff0ad62f50c4d9d4e9f8691f9 MD5 | raw file
Possible License(s): Apache-2.0, AGPL-1.0, GPL-2.0, LGPL-3.0, BSD-3-Clause, Unlicense, MPL-2.0, GPL-3.0, LGPL-2.1

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

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

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