openid.install 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the openid module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function openid_schema() {
  10. $schema['openid_association'] = array(
  11. 'description' => 'Stores temporary shared key association information for OpenID authentication.',
  12. 'fields' => array(
  13. 'idp_endpoint_uri' => array(
  14. 'type' => 'varchar',
  15. 'length' => 255,
  16. 'description' => 'URI of the OpenID Provider endpoint.',
  17. ),
  18. 'assoc_handle' => array(
  19. 'type' => 'varchar',
  20. 'length' => 255,
  21. 'not null' => TRUE,
  22. 'description' => 'Primary Key: Used to refer to this association in subsequent messages.',
  23. ),
  24. 'assoc_type' => array(
  25. 'type' => 'varchar',
  26. 'length' => 32,
  27. 'description' => 'The signature algorithm used: one of HMAC-SHA1 or HMAC-SHA256.',
  28. ),
  29. 'session_type' => array(
  30. 'type' => 'varchar',
  31. 'length' => 32,
  32. 'description' => 'Valid association session types: "no-encryption", "DH-SHA1", and "DH-SHA256".',
  33. ),
  34. 'mac_key' => array(
  35. 'type' => 'varchar',
  36. 'length' => 255,
  37. 'description' => 'The MAC key (shared secret) for this association.',
  38. ),
  39. 'created' => array(
  40. 'type' => 'int',
  41. 'not null' => TRUE,
  42. 'default' => 0,
  43. 'description' => 'UNIX timestamp for when the association was created.',
  44. ),
  45. 'expires_in' => array(
  46. 'type' => 'int',
  47. 'not null' => TRUE,
  48. 'default' => 0,
  49. 'description' => 'The lifetime, in seconds, of this association.',
  50. ),
  51. ),
  52. 'primary key' => array('assoc_handle'),
  53. );
  54. $schema['openid_nonce'] = array(
  55. 'description' => 'Stores received openid.response_nonce per OpenID endpoint URL to prevent replay attacks.',
  56. 'fields' => array(
  57. 'idp_endpoint_uri' => array(
  58. 'type' => 'varchar',
  59. 'length' => 255,
  60. 'description' => 'URI of the OpenID Provider endpoint.',
  61. ),
  62. 'nonce' => array(
  63. 'type' => 'varchar',
  64. 'length' => 255,
  65. 'description' => 'The value of openid.response_nonce.',
  66. ),
  67. 'expires' => array(
  68. 'type' => 'int',
  69. 'not null' => TRUE,
  70. 'default' => 0,
  71. 'description' => 'A Unix timestamp indicating when the entry should expire.',
  72. ),
  73. ),
  74. 'indexes' => array(
  75. 'nonce' => array('nonce'),
  76. 'expires' => array('expires'),
  77. ),
  78. );
  79. return $schema;
  80. }
  81. /**
  82. * Implements hook_requirements().
  83. */
  84. function openid_requirements($phase) {
  85. $requirements = array();
  86. if ($phase == 'runtime') {
  87. // Check for the PHP BC Math library.
  88. if (!function_exists('bcadd') && !function_exists('gmp_add')) {
  89. $requirements['openid_math'] = array(
  90. 'value' => t('Not installed'),
  91. 'severity' => REQUIREMENT_ERROR,
  92. 'description' => t('OpenID suggests the use of either the <a href="@gmp">GMP Math</a> (recommended for performance) or <a href="@bc">BC Math</a> libraries to enable OpenID associations.', array('@gmp' => 'http://php.net/manual/en/book.gmp.php', '@bc' => 'http://www.php.net/manual/en/book.bc.php')),
  93. );
  94. }
  95. elseif (!function_exists('gmp_add')) {
  96. $requirements['openid_math'] = array(
  97. 'value' => t('Not optimized'),
  98. 'severity' => REQUIREMENT_WARNING,
  99. 'description' => t('OpenID suggests the use of the GMP Math library for PHP for optimal performance. Check the <a href="@url">GMP Math Library documentation</a> for installation instructions.', array('@url' => 'http://www.php.net/manual/en/book.gmp.php')),
  100. );
  101. }
  102. else {
  103. $requirements['openid_math'] = array(
  104. 'value' => t('Installed'),
  105. 'severity' => REQUIREMENT_OK,
  106. );
  107. }
  108. $requirements['openid_math']['title'] = t('OpenID Math library');
  109. }
  110. return $requirements;
  111. }
  112. /**
  113. * @addtogroup updates-6.x-to-7.x
  114. * @{
  115. */
  116. /**
  117. * Add a table to store nonces.
  118. */
  119. function openid_update_6000() {
  120. $schema['openid_nonce'] = array(
  121. 'description' => 'Stores received openid.response_nonce per OpenID endpoint URL to prevent replay attacks.',
  122. 'fields' => array(
  123. 'idp_endpoint_uri' => array(
  124. 'type' => 'varchar',
  125. 'length' => 255,
  126. 'description' => 'URI of the OpenID Provider endpoint.',
  127. ),
  128. 'nonce' => array(
  129. 'type' => 'varchar',
  130. 'length' => 255,
  131. 'description' => 'The value of openid.response_nonce'
  132. ),
  133. 'expires' => array(
  134. 'type' => 'int',
  135. 'not null' => TRUE,
  136. 'default' => 0,
  137. 'description' => 'A Unix timestamp indicating when the entry should expire.',
  138. ),
  139. ),
  140. 'indexes' => array(
  141. 'nonce' => array('nonce'),
  142. 'expires' => array('expires'),
  143. ),
  144. );
  145. db_create_table('openid_nonce', $schema['openid_nonce']);
  146. }
  147. /**
  148. * @} End of "addtogroup updates-6.x-to-7.x".
  149. */