$endtime)) return false; //Incorrect time return $parsed_data; } else { return false; //Could not read the file } } /* * Check if the user is in the connected table * Update the row with the created Infocard card_ID */ function DB_update_connected_user ($username, $DB_params){ $card_id = sspmod_InfoCard_UserFunctions::generate_card_ID($username);; $dbconn = pg_connect('host='.$DB_params['DB_host'].' port='.$DB_params['DB_port'].' dbname='.$DB_params['DB_dbname'].' user='.$DB_params['DB_user'].' password='.$DB_params['DB_password']); $result = pg_fetch_all(pg_query_params($dbconn, 'SELECT * FROM connected_users WHERE name = $1', array("$username"))); if ($result[0]){ pg_update($dbconn, 'connected_users', array('card_id'=>$card_id), array('name'=>$username)); return true; } else { return false; } } $config = SimpleSAML_Configuration::getInstance(); $autoconfig = $config->copyFromBase('logininfocard', 'config-login-infocard.php'); $configuredIP = $autoconfig->getValue('configuredIP'); //RADIUS Request - Send One Time URL if ( (strcmp($_GET['ident'],'RADIUS')==0) && (($configuredIP == null) || ($_SERVER['REMOTE_ADDR'] == $configuredIP)) ){ /* Load the configuration. */ $key = $autoconfig->getValue('symmetric_key'); $internalkey = hash('sha256', $autoconfig->getValue('internal_key')); $encrequest = urlsafe_b64decode($_GET['data']); if (!$encrequest) throw new SimpleSAML_Error_NotFound('The URL wasn\'t found in the module.'); // Encryption if ($key!=null) { $iv = urlsafe_b64decode($_GET['iv']); if (!$iv) throw new SimpleSAML_Error_NotFound('The URL wasn\'t found in the module.'); $enckey = hash('sha256', $key); $request = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, pack("H*",$enckey), $encrequest, MCRYPT_MODE_CBC, $iv); } else { $request = $encrequest; } //Parse Attributes (username lenght + username + cardid length + cardid) $parsed_request = parse_attributes($request, 2); //Enable card for downloading (username+cardid+time) $response = enable_download($parsed_request[0],$parsed_request[1]); if(!$response) throw new SimpleSAML_Error_NotFound('FUNCTION enable_download, error accessing directory'); // Encrypt response for myself $response = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, pack("H*",$internalkey), $response, MCRYPT_MODE_CBC, $iv); $response = preg_replace('/\?.*/','',curPageURL()).'?data='.urlsafe_b64encode($response).'&iv='.urlsafe_b64encode($iv); // Encrypt response for RADIUS if ($key!=null){ $encresponse = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, pack("H*",$enckey), $response, MCRYPT_MODE_CBC, $iv); } else { $encresponse = $response; } // Send URL print base64_encode($encresponse); } else { //Client Resquest- Send InfoCard //Get Attributes $encrequest = urlsafe_b64decode($_GET['data']); $iv = urlsafe_b64decode($_GET['iv']); if ((!$encrequest)||(!$iv)) throw new SimpleSAML_Error_NotFound('The URL wasn\'t found in the module.'); /* Load the configuration. */ $internalkey = hash('sha256', $autoconfig->getValue('internal_key')); $certificates = $autoconfig->getValue('certificates'); $ICconfig['InfoCard'] = $autoconfig->getValue('InfoCard'); $ICconfig['InfoCard']['issuer'] = $autoconfig->getValue('tokenserviceurl');//sspmod_InfoCard_Utils::getIssuer($sts_crt); $ICconfig['tokenserviceurl'] = $autoconfig->getValue('tokenserviceurl'); $ICconfig['mexurl'] = $autoconfig->getValue('mexurl'); $ICconfig['sts_key'] = $autoconfig->getValue('sts_key'); $ICconfig['certificates'] = $autoconfig->getValue('certificates'); $ICconfig['UserCredential'] = $autoconfig->getValue('UserCredential'); $IC_lifetime_delivery = $autoconfig->getValue('IC_lifetime_delivery'); $DB_params = $autoconfig->getValue('DB_params'); // Encryption $request = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, pack("H*",$internalkey), $encrequest, MCRYPT_MODE_CBC, $iv); $parsed_request = is_card_enabled($request, $IC_lifetime_delivery); if ($parsed_request && DB_update_connected_user($parsed_request[0], $DB_params)) { // Calculate PPID $ppid = base64_encode(calculate_PPID($parsed_request[1], $certificates)); // Create InfoCard $ICdata = sspmod_InfoCard_UserFunctions::fillICdata($parsed_request[0],$ICconfig['UserCredential'],$ppid); $IC = sspmod_InfoCard_STS::createCard($ICdata,$ICconfig); disable_download($request); //Send Infocard print ($IC); } else { throw new SimpleSAML_Error_NotFound('The URL wasn\'t found in the module.'); } } ?>