public static function authenticateAgent($sourceId) { $agent = new Agent($sourceId); $xmlStr = REC_XML; $db = Zend_Registry::get('my_db'); //if authentication type is username and password if (Zone::getZoneAuthenticationType() == 1) { if (!isset($_SERVER['PHP_AUTH_USER'])) { GeneralError::invalidUserError($xmlStr); exit; } else { $username = $_SERVER['PHP_AUTH_USER']; $password = $_SERVER['PHP_AUTH_PW']; if ($agent->username == $username && $agent->password == $password) { $_SESSION['username'] = $username; return; } else { ZitLog::writeToErrorLog('[Invalid User] User does not exist', 'User in agent request does not exist in the system', 'Authenticate Agent', $_SESSION['ZONE_ID'], $agent->agentId); GeneralError::invalidUserError($xmlStr); exit; } } } else { if (Zone::getZoneAuthenticationType() == 2) { if (!isset($_SERVER['SSL_CLIENT_CERT'])) { ZitLog::writeToErrorLog('[Missing Certificate] Certificate is missing for agent', 'Agent request does not contain a certificate. Zone is set to certificate authentication', 'Verify Certificate', $_SESSION['ZONE_ID'], $agent->agentId); GeneralError::missingSenderCertificate($xmlStr); exit; } else { $cert = $_SERVER['SSL_CLIENT_CERT']; $dn = "C: " || $_SERVER['SSL_CLIENT_S_DN_S'] || '<br/>' || "O: " || $_SERVER['SSL_CLIENT_S_DN_O'] || '<br/>' || "OU: " || $_SERVER['SSL_CLIENT_S_DN_OU'] || '<br/>' || "CN: " || $_SERVER['SSL_CLIENT_S_DN_CN'] || '<br/>' || "End Date: " || $_SERVER['SSL_CLIENT_V_END'] || '<br/>'; } if ($agent->certCommonName == null || $agent->certCommonName == '' || $agent->certCommonName == ' ') { $agents = new Agents($db); $row = $agents->fetchRow("agent_id = " . $agent->agentId); $row->cert_common_name = $cert; $row->cert_common_dn = $dn; $row->save(); $agent->certCommonName = $cert; } if ($agent->certCommonName != $cert) { ZitLog::writeToErrorLog('[CN is not valid] CN of certificate is invalid', 'CN of request certificate does not match the CN setup with the agent', 'Verify Certificate', $_SESSION['ZONE_ID'], $agent->agentId); GeneralError::agentCommonNameDoesNoMatch($xmlStr); exit; } } } /* if($agent->isRegistered()) { //$remoteAddress = SifProcessRequest::getIpAddress(); $cn = $_SERVER['SSL_CLIENT_S_DN_CN']; $result = $_SERVER['SSL_CLIENT_VERIFY']; switch($agent->getAgentRegistrationSifAuthenticationLevel()) { case 1: if($cn == null || $cn == '' || $cn == ' '){ ZitLog::writeToErrorLog('[Missing Certificate] Certificate is missing for agent', 'Agent request does not contain a certificate. Zone is set to certificate authentication', 'Verify Certificate', $_SESSION['ZONE_ID'], $agent->agentId); GeneralError::missingSenderCertificate(REC_XML); exit; } break; case 3: if($agent->certCommonName != $cn){ ZitLog::writeToErrorLog('[CN is not valid] CN of certificate is invalid', 'CN of request certificate does not match the CN setup with the agent', 'Verify Certificate', $_SESSION['ZONE_ID'], $agent->agentId); GeneralError::agentCommonNameDoesNoMatch(REC_XML); exit; } break; } } */ // }//end authentication type check }