openid.install 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. 'not null' => TRUE,
  17. 'description' => 'Primary Key: URI of the OpenID Provider endpoint.',
  18. ),
  19. 'assoc_handle' => array(
  20. 'type' => 'varchar',
  21. 'length' => 255,
  22. 'not null' => TRUE,
  23. 'description' => 'Used to refer to this association in subsequent messages.',
  24. ),
  25. 'assoc_type' => array(
  26. 'type' => 'varchar',
  27. 'length' => 32,
  28. 'description' => 'The signature algorithm used: one of HMAC-SHA1 or HMAC-SHA256.',
  29. ),
  30. 'session_type' => array(
  31. 'type' => 'varchar',
  32. 'length' => 32,
  33. 'description' => 'Valid association session types: "no-encryption", "DH-SHA1", and "DH-SHA256".',
  34. ),
  35. 'mac_key' => array(
  36. 'type' => 'varchar',
  37. 'length' => 255,
  38. 'description' => 'The MAC key (shared secret) for this association.',
  39. ),
  40. 'created' => array(
  41. 'type' => 'int',
  42. 'not null' => TRUE,
  43. 'default' => 0,
  44. 'description' => 'UNIX timestamp for when the association was created.',
  45. ),
  46. 'expires_in' => array(
  47. 'type' => 'int',
  48. 'not null' => TRUE,
  49. 'default' => 0,
  50. 'description' => 'The lifetime, in seconds, of this association.',
  51. ),
  52. ),
  53. 'primary key' => array('idp_endpoint_uri'),
  54. 'unique keys' => array(
  55. 'assoc_handle' => array('assoc_handle'),
  56. ),
  57. );
  58. $schema['openid_nonce'] = array(
  59. 'description' => 'Stores received openid.response_nonce per OpenID endpoint URL to prevent replay attacks.',
  60. 'fields' => array(
  61. 'idp_endpoint_uri' => array(
  62. 'type' => 'varchar',
  63. 'length' => 255,
  64. 'description' => 'URI of the OpenID Provider endpoint.',
  65. ),
  66. 'nonce' => array(
  67. 'type' => 'varchar',
  68. 'length' => 255,
  69. 'description' => 'The value of openid.response_nonce.',
  70. ),
  71. 'expires' => array(
  72. 'type' => 'int',
  73. 'not null' => TRUE,
  74. 'default' => 0,
  75. 'description' => 'A Unix timestamp indicating when the entry should expire.',
  76. ),
  77. ),
  78. 'indexes' => array(
  79. 'nonce' => array('nonce'),
  80. 'expires' => array('expires'),
  81. ),
  82. );
  83. return $schema;
  84. }
  85. /**
  86. * Implements hook_requirements().
  87. */
  88. function openid_requirements($phase) {
  89. $requirements = array();
  90. if ($phase == 'runtime') {
  91. // Check for the PHP BC Math library.
  92. if (!function_exists('bcadd') && !function_exists('gmp_add')) {
  93. $requirements['openid_math'] = array(
  94. 'value' => t('Not installed'),
  95. 'severity' => REQUIREMENT_ERROR,
  96. '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')),
  97. );
  98. }
  99. elseif (!function_exists('gmp_add')) {
  100. $requirements['openid_math'] = array(
  101. 'value' => t('Not optimized'),
  102. 'severity' => REQUIREMENT_WARNING,
  103. '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')),
  104. );
  105. }
  106. else {
  107. $requirements['openid_math'] = array(
  108. 'value' => t('Installed'),
  109. 'severity' => REQUIREMENT_OK,
  110. );
  111. }
  112. $requirements['openid_math']['title'] = t('OpenID Math library');
  113. }
  114. return $requirements;
  115. }
  116. /**
  117. * @addtogroup updates-6.x-to-7.x
  118. * @{
  119. */
  120. /**
  121. * Add a table to store nonces.
  122. */
  123. function openid_update_6000() {
  124. $schema['openid_nonce'] = array(
  125. 'description' => 'Stores received openid.response_nonce per OpenID endpoint URL to prevent replay attacks.',
  126. 'fields' => array(
  127. 'idp_endpoint_uri' => array(
  128. 'type' => 'varchar',
  129. 'length' => 255,
  130. 'description' => 'URI of the OpenID Provider endpoint.',
  131. ),
  132. 'nonce' => array(
  133. 'type' => 'varchar',
  134. 'length' => 255,
  135. 'description' => 'The value of openid.response_nonce'
  136. ),
  137. 'expires' => array(
  138. 'type' => 'int',
  139. 'not null' => TRUE,
  140. 'default' => 0,
  141. 'description' => 'A Unix timestamp indicating when the entry should expire.',
  142. ),
  143. ),
  144. 'indexes' => array(
  145. 'nonce' => array('nonce'),
  146. 'expires' => array('expires'),
  147. ),
  148. );
  149. db_create_table('openid_nonce', $schema['openid_nonce']);
  150. }
  151. /**
  152. * @} End of "addtogroup updates-6.x-to-7.x".
  153. */
  154. /**
  155. * @addtogroup updates-7.x-extra
  156. * @{
  157. */
  158. /**
  159. * Bind associations to their providers.
  160. */
  161. function openid_update_7000() {
  162. db_drop_table('openid_association');
  163. $schema = array(
  164. 'description' => 'Stores temporary shared key association information for OpenID authentication.',
  165. 'fields' => array(
  166. 'idp_endpoint_uri' => array(
  167. 'type' => 'varchar',
  168. 'length' => 255,
  169. 'not null' => TRUE,
  170. 'description' => 'Primary Key: URI of the OpenID Provider endpoint.',
  171. ),
  172. 'assoc_handle' => array(
  173. 'type' => 'varchar',
  174. 'length' => 255,
  175. 'not null' => TRUE,
  176. 'description' => 'Used to refer to this association in subsequent messages.',
  177. ),
  178. 'assoc_type' => array(
  179. 'type' => 'varchar',
  180. 'length' => 32,
  181. 'description' => 'The signature algorithm used: one of HMAC-SHA1 or HMAC-SHA256.',
  182. ),
  183. 'session_type' => array(
  184. 'type' => 'varchar',
  185. 'length' => 32,
  186. 'description' => 'Valid association session types: "no-encryption", "DH-SHA1", and "DH-SHA256".',
  187. ),
  188. 'mac_key' => array(
  189. 'type' => 'varchar',
  190. 'length' => 255,
  191. 'description' => 'The MAC key (shared secret) for this association.',
  192. ),
  193. 'created' => array(
  194. 'type' => 'int',
  195. 'not null' => TRUE,
  196. 'default' => 0,
  197. 'description' => 'UNIX timestamp for when the association was created.',
  198. ),
  199. 'expires_in' => array(
  200. 'type' => 'int',
  201. 'not null' => TRUE,
  202. 'default' => 0,
  203. 'description' => 'The lifetime, in seconds, of this association.',
  204. ),
  205. ),
  206. 'primary key' => array('idp_endpoint_uri'),
  207. 'unique keys' => array(
  208. 'assoc_handle' => array('assoc_handle'),
  209. ),
  210. );
  211. db_create_table('openid_association', $schema);
  212. }
  213. /**
  214. * @} End of "addtogroup updates-7.x-extra".
  215. */