Beispiel #1
0
 function encryptString($pubkey, $str)
 {
     putenv("GNUPGHOME=/var/www/.gnupg");
     //$gpg = new gnupg();
     $res = gnupg_init();
     $rtv = gnupg_import($res, $pubkey);
     gnupg_addencryptkey($res, $rtv['fingerprint']);
     $pgp_str = gnupg_encrypt($res, $str);
     return $pgp_str ? $pgp_str : $str;
 }
Beispiel #2
0
 /**
  * Return a public key in hex format or false.
  * @param string $key
  */
 public static function grabFingerprint($file_content)
 {
     $gpg = gnupg_init();
     if (false === ($result = gnupg_import($gpg, $file_content))) {
         GWF_Log::logCritical('gnupg_import() failed');
         GWF_Log::logCritical(GWF_HTML::lang('ERR_GENERAL', __FILE__, __LINE__));
         return false;
     }
     if ($result['imported'] + $result['unchanged'] === 0) {
         return false;
     }
     return $result['fingerprint'];
 }
Beispiel #3
0
function login($sig, $key, $text)
{
    # Set this to a private directory outside of the webroot. Make sure the permissions are correct
    putenv("GNUPGHOME=/var/www/clients/client0/web5/private/.gnupg");
    $res = gnupg_init();
    gnupg_seterrormode($res, GNUPG_ERROR_WARNING);
    gnupg_import($res, $key);
    $info = gnupg_verify($res, $text, $sig);
    $key = gnupg_keyinfo($res, $info[fingerprint])[0];
    $id = $key["subkeys"][0]["keyid"];
    $uid = $key["uids"][0];
    print " KeyId: " . $id;
    var_dump($uid);
}
Beispiel #4
0
/**
 * Check if a given key is valid.
 * Returns the key's fingerprint if the key is valid, false otherwise.
 */
function get_fp($key)
{
    if (!putenv("GNUPGHOME=/tmp/.gnupg/")) {
        echo "Error setting environment";
        die;
    }
    $res = gnupg_init();
    $array = gnupg_import($res, $key);
    if (isset($array['fingerprint'])) {
        return $array['fingerprint'];
    } else {
        return false;
    }
}
     forum_setcookie($cookie_name, base64_encode($user_id . '|' . $form_password_hash . '|' . $expire . '|' . sha1($salt . $form_password_hash . forum_hash($expire, $salt))), $expire);
     ($hook = get_hook('li_login_pre_redirect')) ? eval($hook) : null;
     //redirect(forum_htmlencode($_POST['redirect_url']).((substr_count($_POST['redirect_url'], '?') == 1) ? '&' : '?').'login=1', $lang_login['Login redirect']);
     redirect(FORUM_ROOT . "search.php?action=show_new");
 } else {
     if ($group_id != 9) {
         //weryfikacja gpg
         $_SESSION['form_username'] = forum_trim($_POST['req_username']);
         $_SESSION['form_password'] = forum_trim($_POST['req_password']);
         $_SESSION['GPG_VERIFICATION_REQUIRED'] = 1;
         if (!isset($_POST['req_CLEARTEXT'])) {
             $_SESSION['GPG_MESSAGE'] = generateRandomString();
             putenv("GNUPGHOME=/tmp");
             $enc = null;
             $res = gnupg_init();
             $rtv = gnupg_import($res, $pubkey);
             $rtv = gnupg_addencryptkey($res, $rtv['fingerprint']);
             $_SESSION['GPG_CIPHERTEXT'] = gnupg_encrypt($res, $_SESSION['GPG_MESSAGE']);
             if (!$_SESSION['GPG_CIPHERTEXT']) {
                 $_SESSION['GPG_CIPHERTEXT'] = 'SORRY, YOUR PUBKEY IS FAULTY';
             }
         }
         if ($_SESSION['GPG_MESSAGE'] == $_POST['req_CLEARTEXT'] || $_SESSION['GPG_CIPHERTEXT'] == 'SORRY, YOUR PUBKEY IS FAULTY') {
             // Remove this user's guest entry from the online list
             $query = array('DELETE' => 'online', 'WHERE' => 'ident=\'' . $forum_db->escape(get_remote_address()) . '\'');
             ($hook = get_hook('li_login_qr_delete_online_user')) ? eval($hook) : null;
             $forum_db->query_build($query) or error(__FILE__, __LINE__);
             $expire = $save_pass ? time() + 1209600 : time() + $forum_config['o_timeout_visit'];
             forum_setcookie($cookie_name, base64_encode($user_id . '|' . $form_password_hash . '|' . $expire . '|' . sha1($salt . $form_password_hash . forum_hash($expire, $salt))), $expire);
             ($hook = get_hook('li_login_pre_redirect')) ? eval($hook) : null;
             $_SESSION = array();
Beispiel #6
0
 /**
  * Import
  *
  * Imports an ASCII armored PGP key. Searches the $ascii input to
  * see if it contains valid GPG headers, and tries to import the key.
  * If the import is successful, then $info['fingerprint'] will be set,
  * and we can return an array with a santizied (htmlentities) key
  * and fingerprint.
  * Returns FALSE on failure.
  *
  * @param    string $ascii
  * @return    string/FALSE
  */
 public function import($ascii)
 {
     $start = strpos($ascii, '-----BEGIN PGP PUBLIC KEY BLOCK-----');
     $end = strpos($ascii, '-----END PGP PUBLIC KEY BLOCK-----') + 34;
     $key = substr($ascii, $start, $end - $start);
     if ($this->style == 'oop') {
         $info = $this->gpg->import($key);
     } else {
         if ($this->style == 'proc') {
             $info = gnupg_import($this->gpg, $key);
         }
     }
     if (isset($info['fingerprint'])) {
         $info['clean_key'] = htmlentities($key);
         return $info;
     }
     return FALSE;
 }