--- /var/simplesamlphp/modules/core/lib/Auth/Process/old_TargetedID.php 2012-01-12 17:42:16.000000000 +0900 +++ /var/simplesamlphp/modules/core/lib/Auth/Process/TargetedID.php 2012-01-15 21:23:03.000000000 +0900 @@ -82,46 +82,114 @@ public function process(&$state) { assert('is_array($state)'); assert('array_key_exists("Attributes", $state)'); - if ($this->attribute === NULL) { - if (!array_key_exists('UserID', $state)) { - throw new Exception('core:TargetedID: Missing UserID for this user. Please' . - ' check the \'userid.attribute\' option in the metadata against the' . - ' attributes provided by the authentication source.'); - } + /*custom by oogami*/ + if ($this->generateNameId) { + if($state['Attributes']['eduPersonTargetedID'][0] != NULL){ + /** + * Paramater for bridge and transform ePTID + * $Bridge: TRUE -> bridge only : FALSE -> bridge and transform + * $Transient: If you want to transform from ePTID to transientID (format is ePTID), this paramater is TRUE. + * $LOG_mode: '1' -> log only ePTID before transforming (this is recommend) + * : '2' -> log ePTID before transforming and IV (if $Transient is 'TRUE', this option MUST be required) + * : '3' -> log ePTID before and after transforming + */ + $Bridge = FALSE; + $Transient = FALSE; + $LOG_mode = '1'; + + $data_in = $state['Attributes']['eduPersonTargetedID'][0]; + $base64_data = base64_encode($data_in); + //key + $key = 'the_key_value_for_crypting'; + //IV + $key2 = 'the_key_value_for_iv'; + if($Transient){ + $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CBC), MCRYPT_DEV_URANDOM); + }else{ + $ivData = $data_in . $key2; + $iv = hash('sha1' , $ivData); + } + //$iv_enc = base64_encode($iv); //for debug + //$output = print_r($iv_enc,true); + //error_log($output, 3, "/var/log/php/debug.log"); + //Preprocessing + $resource = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, ''); + //Encryption + mcrypt_generic_init($resource, $key, $iv); + $encrypted_data = mcrypt_generic($resource, $base64_data); + mcrypt_generic_deinit($resource); + $encrypt_data = base64_encode($encrypted_data); + //$output = print_r($encrypt_data,true);//for debug + //error_log($output, 3, "/var/log/php/debug.log"); + //Decryption + mcrypt_generic_init($resource, $key, $iv); + $base64_decrypted_data = mdecrypt_generic($resource, $encrypted_data); + mcrypt_generic_deinit($resource); + $decrypted_data = base64_decode($base64_decrypted_data); + //$output = print_r($decrypted_data,true);//for debug + //error_log($output, 3, "/var/log/php/debug.log"); + //End encrypt module + mcrypt_module_close($resource); + $output1 = print_r("Transformation at : " . date('Y-m-d H:i:s') . "\n" , true); + $output2 = print_r("Remote host is = " . $_SERVER["REMOTE_ADDR"] . ",Port = " . $_SERVER['REMOTE_PORT'] . "\n" , true); + $output3 = print_r("Input ePTID : ". $data_in . "\n" ,true); + $output4 = print_r("IV : ". base64_encode($iv) . "\n" ,true); + $output5 = print_r("Validate : " . ($data_in == $decrypted_data ? 'true' : 'false') . "\n" , true); + $output6 = print_r("Output ePTID : " . $encrypt_data . "\n" , true); + if($LOG_mode == '3'){ + $output = $output1 . $output2 . $output3 . $output5 . $output6; + }elseif($LOG_mode == '2'){ + $output = $output1 . $output2 . $output3 . $output4 . $output5; + }else{//default + $output = $output1 . $output2 . $output3 . $output5; + } + error_log($output, 3, "/var/log/php/trans_process.log"); + if($Bridge){ + $uid = $data_in; + }else{ + $uid = $encrypt_data; + } + }else{ + if ($this->attribute === NULL) { + if (!array_key_exists('UserID', $state)) { + throw new Exception('core:TargetedID: Missing UserID for this user. Please' . + ' check the \'userid.attribute\' option in the metadata against the' . + ' attributes provided by the authentication source.'); + } + + $userID = $state['UserID']; + } else { + if (!array_key_exists($this->attribute, $state['Attributes'])) { + throw new Exception('core:TargetedID: Missing attribute \'' . $this->attribute . + '\', which is needed to generate the targeted ID.'); + } + + $userID = $state['Attributes'][$this->attribute][0]; + } + + + $secretSalt = SimpleSAML_Utilities::getSecretSalt(); + + if (array_key_exists('Source', $state)) { + $srcID = self::getEntityId($state['Source']); + } else { + $srcID = ''; + } + + if (array_key_exists('Destination', $state)) { + $dstID = self::getEntityId($state['Destination']); + } else { + $dstID = ''; + } + + $uidData = 'uidhashbase' . $secretSalt; + $uidData .= strlen($srcID) . ':' . $srcID; + $uidData .= strlen($dstID) . ':' . $dstID; + $uidData .= strlen($userID) . ':' . $userID; + $uidData .= $secretSalt; - $userID = $state['UserID']; - } else { - if (!array_key_exists($this->attribute, $state['Attributes'])) { - throw new Exception('core:TargetedID: Missing attribute \'' . $this->attribute . - '\', which is needed to generate the targeted ID.'); + $uid = hash('sha1', $uidData); } - - $userID = $state['Attributes'][$this->attribute][0]; - } - - - $secretSalt = SimpleSAML_Utilities::getSecretSalt(); - - if (array_key_exists('Source', $state)) { - $srcID = self::getEntityId($state['Source']); - } else { - $srcID = ''; - } - - if (array_key_exists('Destination', $state)) { - $dstID = self::getEntityId($state['Destination']); - } else { - $dstID = ''; - } - - $uidData = 'uidhashbase' . $secretSalt; - $uidData .= strlen($srcID) . ':' . $srcID; - $uidData .= strlen($dstID) . ':' . $dstID; - $uidData .= strlen($userID) . ':' . $userID; - $uidData .= $secretSalt; - - $uid = hash('sha1', $uidData); - if ($this->generateNameId) { /* Convert the targeted ID to a SAML 2.0 name identifier element. */ $nameId = array( 'Format' => SAML2_Const::NAMEID_PERSISTENT,