コード例 #1
0
function user_key_info($uid)
{
    global $db;
    // User key info
    $query = $db->query("SELECT fid4 FROM mybb_userfields WHERE ufid='{$uid}'");
    $userPubkey = $db->fetch_field($query, "fid4");
    if ($userPubkey == "") {
        return false;
    }
    // Set up keyring
    $keyring = ".trkeys";
    putenv("GNUPGHOME={$keyring}");
    // Import key
    $gpg = new gnupg();
    $gpg->seterrormode(gnupg::ERROR_WARNING);
    $wkey = $gpg->import($userPubkey);
    if (isset($wkey['fingerprint'])) {
        $keystatus = "OK";
        $key_fingerprint = $wkey['fingerprint'];
    } else {
        $keystatus = "Brak";
        $key_fingerprint = $lanag->na;
    }
    return ["key" => $userPubkey, "status" => $keystatus, "fingerprint" => $key_fingerprint];
}
コード例 #2
0
ファイル: elggpg.php プロジェクト: lorea/Hydra-dev
function elggpg_import_key($public_key, $user)
{
    $gpg = new gnupg();
    $info = $gpg->import($public_key);
    $new_fp = $info['fingerprint'];
    $user_fp = current(elgg_get_metadata(array('guid' => $user->guid, 'metadata_name' => 'openpgp_publickey')));
    $access_id = ACCESS_LOGGED_IN;
    if ($user_fp && $user_fp->value != $new_fp) {
        update_metadata($user_fp->id, $user_fp->name, $new_fp, 'text', $user->guid, $access_id);
        $info['imported'] = 1;
    } elseif (!$user_fp) {
        create_metadata($user->guid, "openpgp_publickey", $new_fp, 'text', $user->guid, $access_id);
        $info['imported'] = 1;
    }
    $info['key_id'] = elggpg_fp2keyid($new_fp);
    return $info;
}
コード例 #3
0
ファイル: pgp-2fa.php プロジェクト: hardest1/pgp-2fa
 public function encryptSecret($public_key)
 {
     // Set GnuPG homedir to /tmp
     putenv("GNUPGHOME=/tmp");
     // Create new GnuPG instance
     $gpg = new gnupg();
     // Import given public key
     $key = $gpg->import($public_key);
     // Add imported key for encryption
     $gpg->addencryptkey($key['fingerprint']);
     // Encrypt the secret to a PGP message
     $enc = $gpg->encrypt($this->secret);
     // Clear the encryption key
     $gpg->clearencryptkeys();
     // Return  the PGP message
     return $enc;
 }
コード例 #4
0
 /**
  * Imports a key into the keyring
  * @param string $key_data The actual ASCII contents of the key
  * @throws Exception
  * @return array Associative array describing success/failure/etc. of the import operation (@see php.net/manual/en/function.gnupg-import.php )
  */
 public function import_key($key_data)
 {
     $this->set_env();
     try {
         $gpg = new gnupg();
         // throw exception if error occurs
         $gpg->seterrormode(gnupg::ERROR_EXCEPTION);
         $result = $gpg->import($key_data);
         $this->restore_env();
         return $result;
     } catch (Exception $e) {
         // restore the envelope
         $this->restore_env();
         // re-throw the exception
         throw $e;
     }
 }
コード例 #5
0
 /**
  * Dataflow 11
  */
 public function exportPresenterData()
 {
     ini_set('memory_limit', '4000M');
     ini_set("max_execution_time", 9000);
     $this->out('Exporting Presenter Data');
     $this->SystemSetting = ClassRegistry::init('SystemSetting');
     $this->Presenter = ClassRegistry::init('Presenter');
     $this->PresenterDocuments = ClassRegistry::init('PresenterDocuments');
     $this->User = ClassRegistry::init('User');
     $this->Address = ClassRegistry::init('Address');
     $this->Email = ClassRegistry::init('Email');
     $this->Phone = ClassRegistry::init('Phone');
     $this->PresenterSite = ClassRegistry::init('PresenterSite');
     $this->PresenterType = ClassRegistry::init('PresenterType');
     // reads for replicated
     $this->Presenter->useDbConfig = "replicated";
     $this->User->useDbConfig = "replicated";
     $this->Address->useDbConfig = "replicated";
     $this->Email->useDbConfig = "replicated";
     $this->PresenterDocuments->useDbConfig = "replicated";
     $this->PresenterType->useDbConfig = "replicated";
     $this->Phone->useDbConfig = "replicated";
     $this->PresenterSite->useDbConfig = "replicated";
     $db = ConnectionManager::getDataSource('default');
     $result = $db->query("Select date_sub(now(), interval 2 second) as timestamp");
     $two_seconds_ago = $result[0][0]["timestamp"];
     $folder = "dataflow11";
     $aes_key = md5(Configure::read('aesKey'));
     // get timestamp
     $last_time = $this->SystemSetting->getSystemSetting('netsuite_presenter_df', date('Y-m-d H:i:s'));
     $last_time_ranks = $this->SystemSetting->getSystemSetting('netsuite_presenter_df', date('Y-m-d H:i:s'));
     $this->out('From ' . $last_time . ' To ' . $two_seconds_ago, 1, Shell::VERBOSE);
     // check presenter auditdate
     $presenters = $this->Presenter->find('list', ['fields' => ['id'], 'conditions' => ['_auditdate >' => $last_time, '_auditdate <=' => $two_seconds_ago, 'presenter_status_id >' => PresenterStatus::PENDING_ERRORS]]);
     $this->out('Found ' . count($presenters) . ' Presenters', 1, Shell::VERBOSE);
     // check users
     $users = $this->User->query("\n\t\t\t\tSELECT p.id\n\t\t\t\tFROM users u\n\t\t\t\tJOIN presenters p on p.user_id = u.id\n\t\t\t\tWHERE u._auditdate > '{$last_time}'\n\t\t\t\t\tAND u._auditdate <= '{$two_seconds_ago}'\n\t\t\t\t\tAND p.presenter_status_id > " . PresenterStatus::PENDING_ERRORS . "\n\t\t\t");
     $user_count = 0;
     foreach ($users as $key => $value) {
         if (!array_key_exists($value['p']['id'], $presenters)) {
             $presenters[$value['p']['id']] = $value['p']['id'];
             $user_count++;
         }
     }
     unset($users);
     $this->out('Added ' . $user_count . ' Users', 1, Shell::VERBOSE);
     // check documents
     $docs = $this->PresenterDocuments->find('all', ['conditions' => ['date_received >' => $last_time, 'date_received <=' => $two_seconds_ago]]);
     $doc_count = 0;
     foreach ($docs as $key => $value) {
         if (!array_key_exists($value['PresenterDocuments']['presenter_id'], $presenters)) {
             $presenters[$value['PresenterDocuments']['presenter_id']] = $value['PresenterDocuments']['presenter_id'];
             $doc_count++;
         }
     }
     unset($docs);
     $this->out('Added ' . $doc_count . ' Docs', 1, Shell::VERBOSE);
     //check address
     $addresses = $this->Address->query("\n\t\t\t\tSELECT DISTINCT p.id\n\t\t\t\tFROM addresses a\n\t\t\t\tJOIN users u on a.user_id = u.id\n\t\t\t\tJOIN presenters p on p.user_id = u.id\n\t\t\t\tWHERE a._auditdate > '{$last_time}'\n\t\t\t\t\tAND a._auditdate <= '{$two_seconds_ago}'\n\t\t\t\t\tAND p.presenter_status_id > " . PresenterStatus::PENDING_ERRORS . "\n\t\t\t");
     $address_count = 0;
     foreach ($addresses as $key => $value) {
         if (!array_key_exists($value['p']['id'], $presenters)) {
             $presenters[$value['p']['id']] = $value['p']['id'];
             $address_count++;
         }
     }
     unset($addresses);
     $this->out('Added ' . $address_count . ' Addresses', 1, Shell::VERBOSE);
     // check presenter types
     $today = new DateTime();
     //			if ($today->format('d') == 6 && )
     $this_month = new DateTime('first day of this month 00:00:00');
     $this_yearmonth = $this_month->format('Ym');
     $last_month = new DateTime('first day of last month 00:00:00');
     $last_yearmonth = $last_month->format('Ym');
     //			$ranks = $this->PresenterType->getChanges($last_yearmonth, $this_yearmonth);
     $this->out('Total ' . count($presenters), 1, Shell::VERBOSE);
     // get the data on each presenter matched
     $presenter_chunks = array_chunk($presenters, 1000, TRUE);
     unset($presenters);
     $this->out('Chunked results into  ' . count($presenter_chunks) . " chunks", 1, Shell::VERBOSE);
     foreach ($presenter_chunks as $index => $chunk) {
         $this->out('Processing chunk  ' . $index, 1, Shell::VERBOSE);
         $results = [];
         foreach ($chunk as $presenter) {
             $p_data = $this->Presenter->query("\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\tuser_id,\n\t\t\t\t\t\t\tpresenter_sequence_id,\n\t\t\t\t\t\t\tsponsor_id,\n\t\t\t\t\t\t\t IF(government_id IS NOT NULL AND government_id != '',\n\t\t\t\t\t\t\t\tgovernment_id,\n\t\t\t\t\t\t\t\tCAST(AES_DECRYPT(government_id_encrypted, '{$aes_key}')AS CHAR (50))) as  government_id,\n\t\t\t\t\t\t\tmarket_id,\n\t\t\t\t\t\t\tconsent_to_agreements,\n\t\t\t\t\t\t\tterminated_date,\n\t\t\t\t\t\t\tpresenter_status_id,\n\t\t\t\t\t\t\tnickname,\n\t\t\t\t\t\t\ttax_exempt,\n\t\t\t\t\t\t\texempt_reasoncode,\n\t\t\t\t\t\t\tdefault_locale\n\t\t\t\t\t\tFROM presenters\n\t\t\t\t\t\t WHERE id = {$presenter};\n\t\t\t\t\t");
             $user_id = $p_data[0]['presenters']['user_id'];
             $presenter_id = $p_data[0]['presenters']['id'];
             $u_data = $this->User->find('first', ['conditions' => ['id' => $user_id], 'fields' => ['first_name', 'last_name', 'date_of_birth']]);
             $main_address_data = $this->Address->find('first', ['conditions' => ['user_id' => $user_id, 'address_type_id' => Address::TYPE_MAIN], 'fields' => ['address1', 'address2', 'address3', 'city', 'state_id', 'postal_code', 'country_id', 'address_type_id'], 'order' => 'id DESC']);
             $shipping_address_data = $this->Address->find('first', ['conditions' => ['user_id' => $user_id, 'address_type_id' => Address::TYPE_SHIPPING], 'fields' => ['address1', 'address2', 'address3', 'city', 'state_id', 'postal_code', 'country_id', 'address_type_id'], 'order' => 'id DESC']);
             $main_email_data = $this->Email->find('first', ['conditions' => ['user_id' => $user_id, 'email_type_id' => EmailType::MAIN], 'fields' => ['email'], 'order' => 'id DESC']);
             $royalty_email_data = $this->Email->find('first', ['conditions' => ['user_id' => $user_id, 'email_type_id' => EmailType::ROYALTIES], 'fields' => ['email'], 'order' => 'id DESC']);
             $ph_data = $this->Phone->find('first', ['conditions' => ['user_id' => $user_id, 'phone_type_id' => Phone::MAIN], 'fields' => ['phone'], 'order' => 'id DESC']);
             $site_data = $this->PresenterSite->find('first', ['conditions' => ['presenter_id' => $presenter_id], 'fields' => ['site_url'], 'order' => 'id DESC']);
             $doc_data = $this->PresenterDocuments->find('all', ['conditions' => ['presenter_id' => $presenter_id]]);
             foreach ($doc_data as $value) {
                 $doc_data = [];
                 $doc_data[] = ['document_id' => $value['PresenterDocuments']['document_id'], 'date_received' => $value['PresenterDocuments']['date_received']];
             }
             $presenter_type = $this->PresenterType->getRecognizedStatus($presenter_id);
             // put it all together
             $gpg = new gnupg();
             $import = $gpg->import(NETSUITE_PGP_KEY);
             $gpg->addencryptkey($import['fingerprint']);
             $enc = $gpg->encrypt($p_data[0][0]['government_id']);
             $result = ['presenter' => ["id" => (int) $p_data[0]['presenters']['id'], "presenter_sequence_id" => (int) $p_data[0]['presenters']['presenter_sequence_id'], "sponsor_id" => (int) $p_data[0]['presenters']['sponsor_id'], "market_id" => (int) $p_data[0]['presenters']['market_id'], "government_id" => $enc, "consent_to_agreements" => $p_data[0]['presenters']['consent_to_agreements'], "terminated_date" => $p_data[0]['presenters']['terminated_date'], "presenter_status_id" => (int) $p_data[0]['presenters']['presenter_status_id'], "nickname" => $p_data[0]['presenters']['nickname'], "tax_exempt" => $p_data[0]['presenters']['tax_exempt'], "exempt_reasoncode" => $p_data[0]['presenters']['exempt_reasoncode'], "default_locale" => $p_data[0]['presenters']['default_locale'], "presenter_rank" => $presenter_type['name']], 'user' => ['first_name' => $u_data['User']['first_name'], 'last_name' => $u_data['User']['last_name'], 'date_of_birth' => $u_data['User']['date_of_birth']], 'addresses' => [["address1" => $main_address_data['Address']['address1'], "address2" => $main_address_data['Address']['address2'], "address3" => $main_address_data['Address']['address3'], "city" => $main_address_data['Address']['city'], "state" => (int) $main_address_data['Address']['state_id'], "postal_code" => $main_address_data['Address']['postal_code'], "country" => (int) $main_address_data['Address']['country_id'], "address_type_id" => Address::TYPE_MAIN], ["address1" => $shipping_address_data['Address']['address1'], "address2" => $shipping_address_data['Address']['address2'], "address3" => $shipping_address_data['Address']['address3'], "city" => $shipping_address_data['Address']['city'], "state" => (int) $shipping_address_data['Address']['state_id'], "postal_code" => $shipping_address_data['Address']['postal_code'], "country" => (int) $shipping_address_data['Address']['country_id'], "address_type_id" => Address::TYPE_SHIPPING]], 'emails' => [['email_type_id' => EmailType::MAIN, 'email' => $main_email_data['Email']['email']], ['email_type_id' => EmailType::ROYALTIES, 'email' => $royalty_email_data['Email']['email']]], 'phones' => [['phone_type_id' => PhoneType::MAIN, 'phone' => $ph_data['Phone']['phone']]], 'site_url' => $site_data['PresenterSite']['site_url'], 'presenter_documents' => $doc_data];
             $results[] = $result;
         }
         $this->client->putObject(array('Bucket' => AWS_NETSUITE_SENDING_BUCKET, 'Key' => $folder . DS . 'tmp' . DS . $folder . '_' . time() . '.json', 'Body' => json_encode($results)));
         $this->out('File uploaded', 1, Shell::VERBOSE);
         //break;
     }
     // update the setting
     $this->SystemSetting->getDataSource()->reconnect();
     $this->SystemSetting->saveSetting('netsuite_presenter_df', $two_seconds_ago);
     $this->out('System Setting updated', 1, Shell::VERBOSE);
 }
コード例 #6
0
ファイル: member.php プロジェクト: gholol/ToRepublic2.5
         }
         $rawChallenge = generateString(64);
         $_SESSION['LOGIN_ST2_RAW_CHALLENGE'] = $rawChallenge;
         $_SESSION['LOGIN_ST2_LOGINDATA'] = serialize($loginhandler);
         //
         $query = $db->simple_select("users", "uid", "username='******'");
         $userid = $db->fetch_field($query, "uid");
         $query = $db->query("SELECT fid4 FROM mybb_userfields WHERE ufid=1");
         $userPubkey = $db->fetch_field($query, "fid4");
         if ($userPubkey == "" || $userPubkey == "None") {
             error($lang->error_missinggpg);
         }
         // Encrypt challenge using user's public key
         $gpg = new gnupg();
         // Import user's pubkey
         $gpgImportInfo = $gpg->import($userPubkey);
         // Add encryption key
         $gpgAddKey = $gpg->addencryptkey($gpgImportInfo['fingerprint']);
         $encryptedChallenge = $gpg->encrypt($rawChallenge);
         $plugins->add_hook("member_do_login_end", "add_gpg_vars");
         function add_gpg_vars()
         {
             global $encryptedChallenge, $rawChallenge, $redirectUrl, $mybb;
             $redirectUrl = $mybb->input['url'];
         }
         $plugins->run_hooks("member_do_login_end");
         // GO TO STEP 2
         eval("\$login = \"" . $templates->get("member_login_gpg") . "\";");
         output_page($login);
     }
 }
コード例 #7
0
ファイル: ajax_import_key.php プロジェクト: fbone/mediboard4
 * @license OXPL
 */
global $m;
CCanDo::checkAdmin();
$module = CValue::get("module");
$file = isset($_FILES['import']) ? $_FILES['import'] : null;
$fingerprint = $keydata = null;
if ($file) {
    $keydata = file_get_contents($file['tmp_name']);
    if ($module) {
        $path = CAppUI::conf("{$module} gnupg_path");
    }
    $gpg = new gnupg();
    if ($module && $path) {
        putenv("HOME={$path}");
    }
    $gpg->seterrormode(gnupg::ERROR_EXCEPTION);
    try {
        $info = $gpg->import($keydata);
    } catch (Exception $e) {
        mbTrace($e->getMessage());
    }
    if (array_key_exists("fingerprint", $info)) {
        $fingerprint = $info['fingerprint'];
    }
}
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("fingerprint", $fingerprint);
$smarty->assign("keydata", $keydata);
$smarty->display("ajax_import_key.tpl");