OID.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /*
  3. * This file is part of the PHPASN1 library.
  4. *
  5. * Copyright © Friedrich Große <friedrich.grosse@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace FG\ASN1;
  11. class OID
  12. {
  13. const RSA_ENCRYPTION = '1.2.840.113549.1.1.1';
  14. const MD5_WITH_RSA_ENCRYPTION = '1.2.840.113549.1.1.4';
  15. const SHA1_WITH_RSA_SIGNATURE = '1.2.840.113549.1.1.5';
  16. const SHA256_WITH_RSA_SIGNATURE = '1.2.840.113549.1.1.11';
  17. const PKCS9_EMAIL = '1.2.840.113549.1.9.1';
  18. const PKCS9_UNSTRUCTURED_NAME = '1.2.840.113549.1.9.2';
  19. const PKCS9_CONTENT_TYPE = '1.2.840.113549.1.9.3';
  20. const PKCS9_MESSAGE_DIGEST = '1.2.840.113549.1.9.4';
  21. const PKCS9_SIGNING_TIME = '1.2.840.113549.1.9.5';
  22. const PKCS9_EXTENSION_REQUEST = '1.2.840.113549.1.9.14';
  23. // certificate extension identifier
  24. const CERT_EXT_SUBJECT_DIRECTORY_ATTR = '2.5.29.9';
  25. const CERT_EXT_SUBJECT_KEY_IDENTIFIER = '2.5.29.14';
  26. const CERT_EXT_KEY_USAGE = '2.5.29.15';
  27. const CERT_EXT_PRIVATE_KEY_USAGE_PERIOD = '2.5.29.16';
  28. const CERT_EXT_SUBJECT_ALT_NAME = '2.5.29.17';
  29. const CERT_EXT_ISSUER_ALT_NAME = '2.5.29.18';
  30. const CERT_EXT_BASIC_CONSTRAINTS = '2.5.29.19';
  31. const CERT_EXT_CRL_NUMBER = '2.5.29.20';
  32. const CERT_EXT_REASON_CODE = '2.5.29.21';
  33. const CERT_EXT_INVALIDITY_DATE = '2.5.29.24';
  34. const CERT_EXT_DELTA_CRL_INDICATOR = '2.5.29.27';
  35. const CERT_EXT_ISSUING_DIST_POINT = '2.5.29.28';
  36. const CERT_EXT_CERT_ISSUER = '2.5.29.29';
  37. const CERT_EXT_NAME_CONSTRAINTS = '2.5.29.30';
  38. const CERT_EXT_CRL_DISTRIBUTION_POINTS = '2.5.29.31';
  39. const CERT_EXT_CERT_POLICIES = '2.5.29.32';
  40. const CERT_EXT_AUTHORITY_KEY_IDENTIFIER = '2.5.29.35';
  41. const CERT_EXT_EXTENDED_KEY_USAGE = '2.5.29.37';
  42. // standard certificate files
  43. const COMMON_NAME = '2.5.4.3';
  44. const SURNAME = '2.5.4.4';
  45. const SERIAL_NUMBER = '2.5.4.5';
  46. const COUNTRY_NAME = '2.5.4.6';
  47. const LOCALITY_NAME = '2.5.4.7';
  48. const STATE_OR_PROVINCE_NAME = '2.5.4.8';
  49. const STREET_ADDRESS = '2.5.4.9';
  50. const ORGANIZATION_NAME = '2.5.4.10';
  51. const OU_NAME = '2.5.4.11';
  52. const TITLE = '2.5.4.12';
  53. const DESCRIPTION = '2.5.4.13';
  54. const POSTAL_ADDRESS = '2.5.4.16';
  55. const POSTAL_CODE = '2.5.4.17';
  56. const AUTHORITY_REVOCATION_LIST = '2.5.4.38';
  57. const AUTHORITY_INFORMATION_ACCESS = '1.3.6.1.5.5.7.1.1';
  58. /**
  59. * Returns the name of the given object identifier.
  60. *
  61. * Some OIDs are saved as class constants in this class.
  62. * If the wanted oidString is not among them, this method will
  63. * query http://oid-info.com for the right name.
  64. * This behavior can be suppressed by setting the second method parameter to false.
  65. *
  66. * @param string $oidString
  67. * @param bool $loadFromWeb
  68. *
  69. * @see self::loadFromWeb($oidString)
  70. *
  71. * @return string
  72. */
  73. public static function getName($oidString, $loadFromWeb = true)
  74. {
  75. switch ($oidString) {
  76. case self::RSA_ENCRYPTION:
  77. return 'RSA Encryption';
  78. case self::MD5_WITH_RSA_ENCRYPTION:
  79. return 'MD5 with RSA Encryption';
  80. case self::SHA1_WITH_RSA_SIGNATURE:
  81. return 'SHA-1 with RSA Signature';
  82. case self::PKCS9_EMAIL:
  83. return 'PKCS #9 Email Address';
  84. case self::PKCS9_UNSTRUCTURED_NAME:
  85. return 'PKCS #9 Unstructured Name';
  86. case self::PKCS9_CONTENT_TYPE:
  87. return 'PKCS #9 Content Type';
  88. case self::PKCS9_MESSAGE_DIGEST:
  89. return 'PKCS #9 Message Digest';
  90. case self::PKCS9_SIGNING_TIME:
  91. return 'PKCS #9 Signing Time';
  92. case self::COMMON_NAME:
  93. return 'Common Name';
  94. case self::SURNAME:
  95. return 'Surname';
  96. case self::SERIAL_NUMBER:
  97. return 'Serial Number';
  98. case self::COUNTRY_NAME:
  99. return 'Country Name';
  100. case self::LOCALITY_NAME:
  101. return 'Locality Name';
  102. case self::STATE_OR_PROVINCE_NAME:
  103. return 'State or Province Name';
  104. case self::STREET_ADDRESS:
  105. return 'Street Address';
  106. case self::ORGANIZATION_NAME:
  107. return 'Organization Name';
  108. case self::OU_NAME:
  109. return 'Organization Unit Name';
  110. case self::TITLE:
  111. return 'Title';
  112. case self::DESCRIPTION:
  113. return 'Description';
  114. case self::POSTAL_ADDRESS:
  115. return 'Postal Address';
  116. case self::POSTAL_CODE:
  117. return 'Postal Code';
  118. case self::AUTHORITY_REVOCATION_LIST:
  119. return 'Authority Revocation List';
  120. case self::CERT_EXT_SUBJECT_DIRECTORY_ATTR:
  121. return 'Subject directory attributes';
  122. case self::CERT_EXT_SUBJECT_KEY_IDENTIFIER:
  123. return 'Subject key identifier';
  124. case self::CERT_EXT_KEY_USAGE:
  125. return 'Key usage certificate extension';
  126. case self::CERT_EXT_PRIVATE_KEY_USAGE_PERIOD:
  127. return 'Private key usage';
  128. case self::CERT_EXT_SUBJECT_ALT_NAME:
  129. return 'Subject alternative name (SAN)';
  130. case self::CERT_EXT_ISSUER_ALT_NAME:
  131. return 'Issuer alternative name';
  132. case self::CERT_EXT_BASIC_CONSTRAINTS:
  133. return 'Basic constraints';
  134. case self::CERT_EXT_CRL_NUMBER:
  135. return 'CRL number';
  136. case self::CERT_EXT_REASON_CODE:
  137. return 'Reason code';
  138. case self::CERT_EXT_INVALIDITY_DATE:
  139. return 'Invalidity code';
  140. case self::CERT_EXT_DELTA_CRL_INDICATOR:
  141. return 'Delta CRL indicator';
  142. case self::CERT_EXT_ISSUING_DIST_POINT:
  143. return 'Issuing distribution point';
  144. case self::CERT_EXT_CERT_ISSUER:
  145. return 'Certificate issuer';
  146. case self::CERT_EXT_NAME_CONSTRAINTS:
  147. return 'Name constraints';
  148. case self::CERT_EXT_CRL_DISTRIBUTION_POINTS:
  149. return 'CRL distribution points';
  150. case self::CERT_EXT_CERT_POLICIES:
  151. return 'Certificate policies ';
  152. case self::CERT_EXT_AUTHORITY_KEY_IDENTIFIER:
  153. return 'Authority key identifier';
  154. case self::CERT_EXT_EXTENDED_KEY_USAGE:
  155. return 'Extended key usage';
  156. case self::AUTHORITY_INFORMATION_ACCESS:
  157. return 'Certificate Authority Information Access (AIA)';
  158. default:
  159. if ($loadFromWeb) {
  160. return self::loadFromWeb($oidString);
  161. } else {
  162. return $oidString;
  163. }
  164. }
  165. }
  166. public static function loadFromWeb($oidString)
  167. {
  168. $ch = curl_init("http://oid-info.com/get/{$oidString}");
  169. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  170. curl_setopt($ch, CURLOPT_HEADER, 0);
  171. $contents = curl_exec($ch);
  172. curl_close($ch);
  173. // This pattern needs to be updated as soon as the website layout of oid-info.com changes
  174. preg_match_all('#<tt>(.+)\(\d+\)</tt>#si', $contents, $oidName);
  175. if (empty($oidName[1])) {
  176. return "{$oidString} (unknown)";
  177. }
  178. $oidName = ucfirst(strtolower(preg_replace('/([A-Z][a-z])/', ' $1', $oidName[1][0])));
  179. $oidName = str_replace('-', ' ', $oidName);
  180. return "{$oidName} ({$oidString})";
  181. }
  182. }