Exemplo n.º 1
0
function get_csr_details($person, $auth_key)
{
    $csr = get_csr_from_db_raw($person->getX509ValidCN(), $auth_key);
    $subj = openssl_csr_get_subject($csr['csr'], false);
    $result = array('auth_token' => $csr['auth_key'], 'length' => csr_pubkey_length($csr['csr']), 'uploaded' => $csr['uploaded_date'], 'from_ip' => Output::formatIP($csr['from_ip'], true));
    foreach ($subj as $key => $value) {
        $result[$key] = $value;
    }
    return $result;
}
Exemplo n.º 2
0
 /**
  * getFromDB() find one (or all) CSR(s) for a person in the database.
  *
  * @param	uid		$person limit the query to the person's common-name
  * @param	String|null	$pubHash the hash of the public key
  * @return	CSR|False	The CSR for the person
  * @access	public
  */
 static function getFromDB($uid, $pubHash)
 {
     $res = false;
     if (!isset($uid) || !isset($pubHash)) {
         return false;
     }
     $query = "SELECT * FROM csr_cache WHERE ";
     $query .= "auth_key=:auth_key AND ";
     $query .= "common_name=:common_name";
     $data = array();
     $data['auth_key'] = $pubHash;
     $data['common_name'] = $uid;
     try {
         $csr_res = MDB2Wrapper::execute($query, null, $data);
         if (count($csr_res) != 1) {
             return false;
         }
     } catch (DBStatementException $dbse) {
         Logger::log_event(LOG_WARNING, __FILE__ . ":" . __LINE__ . "cannot retrieve CSR from DB. Server said: " . $dbse->getMessage());
         return false;
     } catch (DBQueryException $dbqe) {
         Logger::log_event(LOG_WARNING, __FILE__ . ":" . __LINE__ . "cannot retrieve CSR from DB. Server said: " . $dbse->getMessage());
         return false;
     }
     $csr_type = $csr_res[0]['type'];
     if ($csr_type == CSR_PKCS10::getCSRType()) {
         $csr = new CSR_PKCS10($csr_res[0]['csr']);
     } else {
         if ($csr_type == CSR_SPKAC::getCSRType()) {
             $csr = new CSR_SPKAC($csr_res[0]['csr']);
         } else {
             throw new CryptoElementException("Unsupported CSR type " . $csr_type . "!");
         }
     }
     $csr->setUploadedDate($csr_res[0]['uploaded_date']);
     $csr->setUploadedFromIP(Output::formatIP($csr_res[0]['from_ip'], true));
     if ($csr->getAuthToken() !== $pubHash) {
         Logger::log_event(LOG_ALERT, "Found CSR in database with hash {$pubHash} but " . "this does not correspond to pubkey. Corrupted db?");
         return false;
     }
     return $csr;
 }