openid.install 4.11 KB
Newer Older
1 2
<?php

3 4 5 6 7
/**
 * @file
 * Install, update and uninstall functions for the openid module.
 */

8
/**
9
 * Implements hook_schema().
10 11 12
 */
function openid_schema() {
  $schema['openid_association'] = array(
13
    'description' => 'Stores temporary shared key association information for OpenID authentication.',
14
    'fields' => array(
15 16 17
      'idp_endpoint_uri' => array(
        'type' => 'varchar',
        'length' => 255,
18
        'description' => 'URI of the OpenID Provider endpoint.',
19 20 21 22 23
      ),
      'assoc_handle' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
24
        'description' => 'Primary Key: Used to refer to this association in subsequent messages.',
25 26 27 28
      ),
      'assoc_type' => array(
        'type' => 'varchar',
        'length' => 32,
29
        'description' => 'The signature algorithm used: one of HMAC-SHA1 or HMAC-SHA256.',
30 31 32 33
      ),
      'session_type' => array(
        'type' => 'varchar',
        'length' => 32,
34
        'description' => 'Valid association session types: "no-encryption", "DH-SHA1", and "DH-SHA256".',
35 36 37 38
      ),
      'mac_key' => array(
        'type' => 'varchar',
        'length' => 255,
39
        'description' => 'The MAC key (shared secret) for this association.',
40 41 42 43 44
      ),
      'created' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
45
        'description' => 'UNIX timestamp for when the association was created.',
46 47 48 49 50
      ),
      'expires_in' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
51
        'description' => 'The lifetime, in seconds, of this association.',
52
      ),
53 54 55 56
    ),
    'primary key' => array('assoc_handle'),
  );

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
  $schema['openid_nonce'] = array(
    'description' => 'Stores received openid.response_nonce per OpenID endpoint URL to prevent replay attacks.',
    'fields' => array(
      'idp_endpoint_uri' => array(
        'type' => 'varchar',
        'length' => 255,
        'description' => 'URI of the OpenID Provider endpoint.',
      ),
      'nonce' => array(
        'type' => 'varchar',
        'length' => 255,
        'description' => 'The value of openid.response_nonce.',
      ),
      'expires' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'A Unix timestamp indicating when the entry should expire.',
      ),
    ),
    'indexes' => array(
      'nonce' => array('nonce'),
      'expires' => array('expires'),
    ),
  );

83 84
  return $schema;
}
85 86

/**
87
 * Implements hook_requirements().
88 89 90 91 92 93
 */
function openid_requirements($phase) {
  $requirements = array();

  if ($phase == 'runtime') {
    // Check for the PHP BC Math library.
94 95
    if (!function_exists('bcadd') && !function_exists('gmp_add')) {
      $requirements['openid_math'] = array(
96 97
        'value' => t('Not installed'),
        'severity' => REQUIREMENT_ERROR,
98
        '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/book.gmp.php', '@bc' => 'http://www.php.net/manual/book.bc.php')),
99 100 101 102 103 104
      );
    }
    elseif (!function_exists('gmp_add')) {
      $requirements['openid_math'] = array(
        'value' => t('Not optimized'),
        'severity' => REQUIREMENT_WARNING,
105
        '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/book.gmp.php')),
106 107 108
      );
    }
    else {
109
      $requirements['openid_math'] = array(
110 111 112
        'value' => t('Installed'),
      );
    }
113
    $requirements['openid_math']['title'] = t('OpenID Math library');
114 115 116 117
  }

  return $requirements;
}
118 119

/**
120
 * Implements hook_update_last_removed().
121
 */
122 123
function openid_update_last_removed() {
  return 6000;
124
}
125 126 127 128 129 130 131 132 133 134 135

/**
 * Moves xri_proxy_resolver settings from variable to config.
 *
 * @ingroup config_upgrade
 */
function openid_update_8001() {
  update_variables_to_config('openid.settings', array(
    'xri_proxy_resolver' => 'xri_proxy_resolver',
  ));
}