openid.install 4.83 KB
Newer Older
1 2 3
<?php
// $Id$

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

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

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 83
  $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'),
    ),
  );

84 85
  return $schema;
}
86 87

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

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

  return $requirements;
}
120 121

/**
122
 * @addtogroup updates-6.x-to-7.x
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
 * @{
 */

/**
 * Add a table to store nonces.
 */
function openid_update_6000() {
  $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'),
    ),
  );

  db_create_table('openid_nonce', $schema['openid_nonce']);
}

/**
160
 * @} End of "addtogroup updates-6.x-to-7.x"
161
 */