58 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| function fulcrm_crypto_permission() {
 | |
|   return array( 'administer fulcrm crypto' => array( 'title' => t('Administer fulcrm cryptography'),
 | |
|                                                     'description' => t('Perform main installation/administration tasks for fulcrm cryptography.'),
 | |
|                                                     ),                          
 | |
|                 );
 | |
| }
 | |
| 
 | |
| function fulcrm_crypto_menu() {
 | |
|     /*
 | |
|     $items[ 'admin/config/services/fulcrm' ] = array( 'page callback' => 'system_admin_menu_block_page',
 | |
|                                                       'file' => 'system.admin.inc',
 | |
|                                                       'file path' => drupal_get_path('module', 'system'),
 | |
|                                                       'title' => 'fulcrm',
 | |
|                                                       'description' => 'Configuration integration with fulcrm.org.',
 | |
|                                                       'position' => 'right',
 | |
|                                                       'access callback' => 'user_access',
 | |
|                                                       'access arguments' => array('access administration pages'),
 | |
|                                                       );
 | |
|    */
 | |
|     $items[ 'admin/config/services/fulcrm/crypto' ] = array( 'page callback' => 'fulcrm_crypto_admin',
 | |
|                                                              'file' => 'fulcrm_crypto.admin.inc',
 | |
|                                                              'title' => 'fulcrm cryptography',
 | |
|                                                              'description' => 'Settings for fulcrm.org cryptography.',
 | |
|                                                              'access callback' => 'user_access',
 | |
|                                                              'access arguments' => array('administer fulcrm crypto'),
 | |
|                                                              );
 | |
| 
 | |
|     return $items;
 | |
| }
 | |
| 
 | |
| function fulcrm_crypto_object_id_hmac( $object_type, $object_id ) {
 | |
|     return drupal_hmac_base64( 'fulcrm:' . strval( $object_id ) . ':' . $object_type, session_id() . drupal_get_hash_salt() );
 | |
| }
 | |
| 
 | |
| function fulcrm_crypto_check_object_id_hmac( $object_type, $object_id, $hmac ) {
 | |
|     $real_hmac = fulcrm_crypto_object_id_hmac( $object_type, $object_id );
 | |
|     return hash_equals( $real_hmac, $hmac );
 | |
| }
 | |
| 
 | |
| function fulcrm_crypto_object_id_form_value( $object_type, $object_id ) {
 | |
|     return $object_id . ':' . fulcrm_crypto_object_id_hmac( $object_type, $object_id );
 | |
| }
 | |
| 
 | |
| function fulcrm_crypto_get_object_id_form_value( $object_type, $form_value ) {
 | |
|     $bits = explode( ':', $form_value );
 | |
|     if ( count( $bits ) == 2 ) {
 | |
|         $object_id = $bits[ 0 ];
 | |
|         $hmac = $bits[ 1 ];
 | |
|         $real_hmac = fulcrm_crypto_object_id_hmac( $object_type, $object_id );
 | |
| 
 | |
|         if ( hash_equals( $real_hmac, $hmac ) )
 | |
|             return $object_id;
 | |
|     }
 | |
|     return NULL;
 | |
| }
 |