예제 #1
1
<?php

$plaintext_body = 'Some sensitive order data';
$recipient = '*****@*****.**';
$g = gnupg_init();
gnupg_seterrormode($g, GNUPG_ERROR_WARNING);
// Fingerprint of the recipient's key
$a = gnupg_addencryptkey($g, "5495F0CA9C8F30A9274C2259D7EBE8584CEF302B");
// Fingerprint of the sender's key
$b = gnupg_addsignkey($g, "520D5FC5C85EF4F4F9D94E1C1AF1F7C5916FC221", "passphrase");
$encrypted_body = gnupg_encryptsign($g, $plaintext_body);
mail($recipient, 'Web Site Order', $encrypted_body);
예제 #2
0
/**
 * @param string $enc_data
 * @param string $salt
 * @return bool|mixed
 */
function decrypt_gpg($enc_data, $salt)
{
    if (!function_exists("gnupg_init") || !function_exists("gnupg_adddecryptkey") || !function_exists("gnupg_decrypt") || !function_exists("gnupg_geterror")) {
        error_log("Required GnuPG functions not available. Bypassing password RSA decryption...");
        return $enc_data;
    }
    if (!defined('SYNAPP_GPG_KEY_FINGERPRINT')) {
        error_log("Missing required GnuPG settings. Bypassing password RSA decryption...");
        return $enc_data;
    }
    if (defined('CRYPT_BYPASS') && (CRYPT_BYPASS === true || strtolower(CRYPT_BYPASS) === "1" || strtolower(CRYPT_BYPASS) === "true" || strtolower(CRYPT_BYPASS) === "on")) {
        return $enc_data;
    }
    $res = gnupg_init();
    $env = getenv('GNUPGHOME');
    if (!gnupg_adddecryptkey($res, SYNAPP_GPG_KEY_FINGERPRINT, "")) {
        $error = gnupg_geterror($res);
        error_log("Error trying to add decryption key on " . $env);
        error_log($error);
    }
    if (($dec_data = gnupg_decrypt($res, $enc_data)) === false) {
        $error = gnupg_geterror($res);
        error_log("Error trying to use decryption key on " . $env);
        error_log($error);
    }
    $dec_data_saltless = preg_replace('/' . preg_quote($salt, '/') . '$/', '', $dec_data);
    if ($dec_data_saltless === $dec_data) {
        return false;
    }
    $dec_out = preg_replace('/' . preg_quote(strpbrk($dec_data_saltless, '@'), '/') . '$/', '', $dec_data_saltless);
    return $dec_out;
}
예제 #3
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;
 }
예제 #4
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'];
 }
예제 #5
0
파일: server.php 프로젝트: GnuPG-Auth/docs
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);
}
예제 #6
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;
    }
}
예제 #7
0
 /**
  * Construct
  *
  * In constructing this class we check if the gnupg OOP class is
  * available, or if the procedural functions are there instead.
  * Loads the current version of the GPG extension if it's available.
  */
 public function __construct()
 {
     $home = dirname(__FILE__) . '/../storage/.gnupg';
     if (!file_exists($home)) {
         mkdir($home, 0700);
     }
     putenv("GNUPGHOME={$home}");
     if (class_exists('gnupg')) {
         $this->gpg = new gnupg();
         $this->style = 'oop';
         $this->version = phpversion('gnupg');
     }
     if (function_exists('gnupg_init')) {
         $this->gpg = gnupg_init();
         // Detect whether functions are procedural or object-oriented.
         $this->style = 'proc';
         $this->version = phpversion('gnupg');
     }
 }
예제 #8
0
     $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;
     //redirect(forum_htmlencode($_POST['redirect_url']).((substr_count($_POST['redirect_url'], '?') == 1) ? '&amp;' : '?').'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;
예제 #9
0
파일: GWF_Mail.php 프로젝트: sinfocol/gwf3
 private function encrypt($message)
 {
     if ($this->gpgKey === '' && self::GPG_FINGERPRINT === '') {
         return $message;
     }
     if (false === function_exists('gnupg_init')) {
         return $message . PHP_EOL . 'GnuPG Error: gnupg extension is missing.';
     }
     if (false === ($gpg = gnupg_init())) {
         return $message . PHP_EOL . 'GnuPG Error: gnupg_init() failed.';
     }
     if ($this->gpgKey !== '') {
         if (false === gnupg_addencryptkey($gpg, $this->gpgKey)) {
             return $message . PHP_EOL . 'GnuPG Error: gnupg_addencryptkey() failed.';
         }
     }
     $signed = false;
     //		if (self::GPG_FINGERPRINT !== '') {
     //			$sign_key = preg_replace('/[^a-z0-9]/i', '', self::GPG_FINGERPRINT);
     //
     //			if (self::GPG_PASSPHRASE==='')
     //			{
     //				if (false === gnupg_addsignkey($gpg, $sign_key)) {
     //					$message .= PHP_EOL.'GnuPG Error: gnupg_addsignkey1() failed.';
     //				}
     //				else {
     //					$signed = true;
     //				}
     //			}
     //			else
     //			{
     //				if (false === gnupg_addsignkey($gpg, $sign_key, self::GPG_PASSPHRASE)) {
     //					$message .= PHP_EOL.'GnuPG Error: gnupg_addsignkey2() failed.';
     //				}
     //				else {
     //					$signed = true;
     //				}
     //			}
     //
     //		}
     if ($signed === true) {
         if (false === ($back = gnupg_encryptsign($gpg, $message))) {
             return $message . PHP_EOL . 'GnuPG Error: gnupg_encryptsign() failed.';
         }
     } else {
         if (false === ($back = gnupg_encrypt($gpg, $message))) {
             return 'GnuPG Error: gnupg_encrypt() failed.' . PHP_EOL . 'Message has been removed!';
         }
     }
     return $back;
 }
예제 #10
0
파일: gnupg.php 프로젝트: noccy80/lepton-ng
 function __construct($match = '')
 {
     $this->gpg = gnupg_init();
     $this->keys = gnupg_keyinfo($this->gpg, $match);
 }
예제 #11
0
 private function getDORSubmission($CompanyInfo, $ProceedsInfo, $CharitiesInfo)
 {
     $fullxml = "";
     $XmlBody = "";
     $XmlCompanyInfo = "";
     $XmlProcedesBody = "";
     $XmlCharitiesBody = "";
     $XmlMiscInfo = "";
     $XmlBodyClose = "";
     //---------Header Info-------------
     $XmlBody += "<?xml version='1.0' encoding='UTF-8'?>";
     $XmlBody += "<SGOC_Report xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='SGOC_Report.xsd'>";
     $XmlBody += "<Reports>";
     //---------Company Info------------
     $XmlCompanyInfo += "<OrgDetailSec1>";
     $XmlCompanyInfo += "<RptYear>" + $CompanyInfo[0] . rptYear + "</RptYear>";
     $XmlCompanyInfo += "<LicenseNo>" + $CompanyInfo[0] . LicenseNo + "</LicenseNo>";
     $XmlCompanyInfo += "<OrgName>" + $CompanyInfo[0] . CompanyName + "</OrgName>";
     $XmlCompanyInfo += "<CountyCode>" + $CompanyInfo[0] . CountyCode + "</CountyCode>";
     $XmlCompanyInfo += "<MunCode>" + $CompanyInfo[0] . MunCode + "</MunCode>";
     $XmlCompanyInfo += "<AddressLine1>" + $CompanyInfo[0] . CompanyAddress1 + "</AddressLine1>";
     $XmlCompanyInfo += "<City>" + $CompanyInfo[0] . CompanyCity + "</City>";
     $XmlCompanyInfo += "<Zip>" + $CompanyInfo[0] . CompanyZip + "</Zip>";
     $XmlCompanyInfo += "<ContactPhone>" + $CompanyInfo[0] . CompanyPhone + "</ContactPhone>";
     $XmlCompanyInfo += "<ContactName>" + $CompanyInfo[0] . ContactName + "</ContactName>";
     $XmlCompanyInfo += "<LicenseExpDate>" + FormatDateSTD($CompanyInfo[0] . LicenseExpDate) + "</LicenseExpDate>";
     $XmlCompanyInfo += "<LidNo>" + $CompanyInfo[0] . LidNo + "</LidNo>";
     $XmlCompanyInfo += "<FeinSsn>" + $CompanyInfo[0] . FeinSsn + "</FeinSsn>";
     $XmlCompanyInfo += "<IdentityType>" + $CompanyInfo[0] . IdentityType + "</IdentityType>";
     $XmlCompanyInfo += "<FilerName>" + $CompanyInfo[0] . FilerName + "</FilerName>";
     $XmlCompanyInfo += "<FilerTitle>" + $CompanyInfo[0] . FilerTitle + "</FilerTitle>";
     $XmlCompanyInfo += "<FilerPhone>" + $CompanyInfo[0] . FilerPhone + "</FilerPhone>";
     ${$XmlCompanyInfo} += "<NoW2GForms>" + $CompanyInfo[0] . NoW2GForms + "</NoW2GForms>";
     $XmlCompanyInfo += "<TotW2GPrizeAmt>" + $CompanyInfo[0] . TotW2GPrizeAmt + "</TotW2GPrizeAmt>";
     $XmlCompanyInfo += "</OrgDetailSec1>";
     //---------Proceeds----------------
     $i = 0;
     /* for illustrative purposes only */
     foreach ($ProceedsInfo as $ProceedsFeed) {
         //echo "\$a[$i] => $v.\n";
         $XmlProcedesBody += "<ProceedsReportingSec2>";
         $XmlProcedesBody += "<WkBeginDate>" + FormatDateSTD($ProceedsFeed[$i] . wkBegin) + "</WkBeginDate>";
         $XmlProcedesBody += "<WkEndDate>" + FormatDateSTD($ProceedsFeed[$i] . wkEnd) + "</WkEndDate>";
         $XmlProcedesBody += "<GameCode>" + $ProceedsFeed[$i] . GameCode + "</GameCode>";
         $XmlProcedesBody += "<GrossRevenue>" + $ProceedsFeed[$i] . Gross + "</GrossRevenue>";
         $XmlProcedesBody += "<TotalExpenses>" + $ProceedsFeed[$i] . Expenses + "</TotalExpenses>";
         $XmlProcedesBody += "<TotalPrizes>" + $ProceedsFeed[$i] . Prizes + "</TotalPrizes>";
         $XmlProcedesBody += "<Proceeds>" + $ProceedsFeed[$i] . Proceeds + "</Proceeds>";
         $XmlProcedesBody += "</ProceedsReportingSec2>";
         $i++;
     }
     //---------Charities---------------
     $i = 0;
     /* for illustrative purposes only */
     foreach ($CharitiesInfo as $CharitiesFeed) {
         //echo "\$a[$i] => $v.\n";
         $XmlCharitiesBody += "<AmtProceedsPublicIntSec3>";
         $XmlCharitiesBody += "<DateDistributed>" + FormatDateSTD($CharitiesFeed[$i] . DatePaid) + "</DateDistributed>";
         $XmlCharitiesBody += "<RecipientName>" + $CharitiesFeed[$i] . Charity + "</RecipientName>";
         $XmlCharitiesBody += "<AmtSetaSide>" + $CharitiesFeed[$i] . AmtPaid + "</AmtSetaSide>";
         $XmlCharitiesBody += "</AmtProceedsPublicIntSec3>";
         $i++;
     }
     //---------Misc Items--------------
     $XmlMiscInfo += "<ProceedsExpAndAmtSetaSideSec4>";
     $XmlMiscInfo += "<TotProceedsOperExp>206.38</TotProceedsOperExp>";
     $XmlMiscInfo += "<TotAmtSetaSide>111.11</TotAmtSetaSide>";
     $XmlMiscInfo += "</ProceedsExpAndAmtSetaSideSec4>";
     $XmlMiscInfo += "<Miscellaneous>";
     $XmlMiscInfo += "<PrYrProceeds>" + "Y" + "</PrYrProceeds>";
     $XmlMiscInfo += "</Miscellaneous>";
     //---------Close XML---------------
     $XmlBodyClose += "</Reports>";
     $XmlBodyClose += "</SGOC_Report>";
     $fullxml = $XmlBody + $XmlCompanyInfo + $XmlProcedesBody + $XmlCharitiesBody + $XmlMiscInfo + $XmlBodyClose;
     //---------Encrypt String----------
     $stringToEncrypt = $fullxml;
     $res = gnupg_init();
     $pubkey = "BADelitpUqMZLn+bryZR5rK9J3eu+pRVFP5tpboOlIwO2vqO/rCi8VvT2TPzEJarWhyZ465NIohYCiia9vaGUEp4rsDzFnVNgpON47yPew1zCmOOofituf+X6Qlaxylm5NnO4vnRcmoF4IbGwSCqyGgGor29D75Hovwlj1q6BWHYWwAGKQ==";
     //gnupg_addencryptkey($res,"8660281B6051D071D94B5B230549F9DC851566DC");
     gnupg_addencryptkey($res, $pubkey);
     $enc = gnupg_encrypt($res, $stringToEncrypt);
     return $enc;
 }