includes/sessions.php
changeset 1242 9aa09b0a7544
parent 1240 2b6cdff92b09
child 1252 e34c23a35dc9
equal deleted inserted replaced
1241:99b749da5149 1242:9aa09b0a7544
  3703 	 * @param reference Optional variable to fill with the server's public and private key. If IN_ENANO_INSTALL is defined, storing and retrieving the key
  3703 	 * @param reference Optional variable to fill with the server's public and private key. If IN_ENANO_INSTALL is defined, storing and retrieving the key
  3704 	 *                  is YOUR responsibility.
  3704 	 *                  is YOUR responsibility.
  3705 	 * @return string
  3705 	 * @return string
  3706 	 */
  3706 	 */
  3707 	
  3707 	
  3708 	static function generate_aes_form(&$dh_store = array())
  3708 	function generate_aes_form(&$dh_store = array())
  3709 	{
  3709 	{
  3710 		$is_static = !( isset($this) && get_class($this) === __CLASS__ );
  3710 		$aes_key = self::rijndael_genkey();
  3711 		if ( $is_static )
       
  3712 		{
       
  3713 			$aes = AESCrypt::singleton(AES_BITS, AES_BLOCKSIZE);
       
  3714 			$aes_key = $aes->gen_readymade_key();
       
  3715 		}
       
  3716 		else
       
  3717 		{
       
  3718 			$aes_key = self::rijndael_genkey();
       
  3719 		}
       
  3720 		$dh_store = array('aes' => $aes_key, 'public' => '', 'private' => '');
  3711 		$dh_store = array('aes' => $aes_key, 'public' => '', 'private' => '');
  3721 		
  3712 		
  3722 		$return = '<input type="hidden" name="use_crypt" value="no" />';
  3713 		$return = '<input type="hidden" name="use_crypt" value="no" />';
  3723 		$return .= '<input type="hidden" name="crypt_key" value="' . $aes_key . '" />';
  3714 		$return .= '<input type="hidden" name="crypt_key" value="' . $aes_key . '" />';
  3724 		$return .= '<input type="hidden" name="crypt_data" value="" />';
  3715 		$return .= '<input type="hidden" name="crypt_data" value="" />';
  3733 			$dh_key_priv = dh_gen_private();
  3724 			$dh_key_priv = dh_gen_private();
  3734 			$dh_key_pub = dh_gen_public($dh_key_priv);
  3725 			$dh_key_pub = dh_gen_public($dh_key_priv);
  3735 			$dh_key_priv = $_math->str($dh_key_priv);
  3726 			$dh_key_priv = $_math->str($dh_key_priv);
  3736 			$dh_key_pub = $_math->str($dh_key_pub);
  3727 			$dh_key_pub = $_math->str($dh_key_pub);
  3737 			// store the keys in the DB
  3728 			// store the keys in the DB
  3738 			// this is doing a static call check to avoid using $this in a static call
  3729 			$this->sql('INSERT INTO ' . table_prefix . "diffiehellman( public_key, private_key ) VALUES ( '$dh_key_pub', '$dh_key_priv' );");
  3739 			if ( !defined('IN_ENANO_INSTALL') && isset($this) && get_class($this) === __CLASS__ )
  3730 			// also give the key to the calling function
  3740 				$this->sql('INSERT INTO ' . table_prefix . "diffiehellman( public_key, private_key ) VALUES ( '$dh_key_pub', '$dh_key_priv' );");
  3731 			$dh_store['public'] = $dh_key_pub;
       
  3732 			$dh_store['private'] = $dh_key_priv;
       
  3733 			
       
  3734 			$return .=  "<input type=\"hidden\" name=\"dh_supported\" value=\"true\" />
       
  3735 						<input type=\"hidden\" name=\"dh_public_key\" value=\"$dh_key_pub\" />
       
  3736 						<input type=\"hidden\" name=\"dh_client_public_key\" value=\"\" />";
       
  3737 		}
       
  3738 		else
       
  3739 		{
       
  3740 			$return .=  "<input type=\"hidden\" name=\"dh_supported\" value=\"false\" />";
       
  3741 		}
       
  3742 		return $return;
       
  3743 	}
       
  3744 	
       
  3745 	/**
       
  3746 	 * Static version of generate_aes_form().
       
  3747 	 * @see sessionManager::generate_aes_form()
       
  3748 	 * @param reference
       
  3749 	 * @return string
       
  3750 	 */
       
  3751 	
       
  3752 	static function generate_aes_form_static(&$dh_store = array())
       
  3753 	{
       
  3754 		$aes = AESCrypt::singleton(AES_BITS, AES_BLOCKSIZE);
       
  3755 		$aes_key = $aes->gen_readymade_key();
       
  3756 		$dh_store = array('aes' => $aes_key, 'public' => '', 'private' => '');
       
  3757 		
       
  3758 		$return = '<input type="hidden" name="use_crypt" value="no" />';
       
  3759 		$return .= '<input type="hidden" name="crypt_key" value="' . $aes_key . '" />';
       
  3760 		$return .= '<input type="hidden" name="crypt_data" value="" />';
       
  3761 		$return .= '<input type="hidden" name="challenge_data" value="' . self::dss_rand() . '" />';
       
  3762 		
       
  3763 		require_once(ENANO_ROOT . '/includes/math.php');
       
  3764 		require_once(ENANO_ROOT . '/includes/diffiehellman.php');
       
  3765 		
       
  3766 		global $dh_supported, $_math;
       
  3767 		if ( $dh_supported )
       
  3768 		{
       
  3769 			$dh_key_priv = dh_gen_private();
       
  3770 			$dh_key_pub = dh_gen_public($dh_key_priv);
       
  3771 			$dh_key_priv = $_math->str($dh_key_priv);
       
  3772 			$dh_key_pub = $_math->str($dh_key_pub);
  3741 			// also give the key to the calling function
  3773 			// also give the key to the calling function
  3742 			$dh_store['public'] = $dh_key_pub;
  3774 			$dh_store['public'] = $dh_key_pub;
  3743 			$dh_store['private'] = $dh_key_priv;
  3775 			$dh_store['private'] = $dh_key_priv;
  3744 			
  3776 			
  3745 			$return .=  "<input type=\"hidden\" name=\"dh_supported\" value=\"true\" />
  3777 			$return .=  "<input type=\"hidden\" name=\"dh_supported\" value=\"true\" />