Ejemplo n.º 1
0
 protected function fetchOpenIdConfig()
 {
     try {
         $apiClient = $this->getApiClient();
         $config = $apiClient->get('.well-known/openid-configuration');
         $jwkRes = $apiClient->get($config->jwks_uri);
         $jwks = $jwkRes->keys;
         $keys = [];
         $rsa = new \Crypt_RSA();
         foreach ($jwks as $key) {
             //if x509 key is available, we don't need to generate it below.
             if (!empty($key->x_509)) {
                 $keys[$key->kid] = $key->x_509;
                 continue;
             }
             $public = '<RSAKeyValue>
                  <Modulus>' . $this->base64_from_url($key->n) . '</Modulus>
                  <Exponent>' . $this->base64_from_url($key->e) . '</Exponent>
                </RSAKeyValue>';
             $rsa->loadKey($public, CRYPT_RSA_PUBLIC_FORMAT_XML);
             $rsa->setPublicKey();
             $keys[$key->kid] = $rsa->getPublicKey();
         }
         $config->keys = $keys;
         return $config;
     } catch (SSO\Exception\HttpException $e) {
         throw new OpenIdConfigurationException('OpenID configuration can not be fetched', 0, $e);
     }
 }
Ejemplo n.º 2
0
function signNewCert()
{
    if (!$GLOBALS['isCA']) {
        return false;
    } else {
        $CAPrivKey = new Crypt_RSA();
        $CAPrivKey->loadKey($GLOBALS['CAPrivKeyStr']);
        $CAx509 = new File_X509();
        $CAx509->loadX509($GLOBALS['CAPubX509']);
        //认证证书
        $privKey = new Crypt_RSA();
        $keyArray = $CAPrivKey->createKey($GLOBALS['RSALength']);
        $privKey->loadKey($keyArray['privatekey']);
        $pubKey = new Crypt_RSA();
        $pubKey->loadKey($keyArray['publickey']);
        $pubKey->setPublicKey();
        $subject = new File_X509();
        $subject->setDNProp('id-at-organizationName', $GLOBALS['CAname'] . ' cert');
        $subject->setPublicKey($pubKey);
        $issuer = new File_X509();
        $issuer->setPrivateKey($CAPrivKey);
        $issuer->setDN($CAx509->getDN());
        $x509 = new File_X509();
        $result = $x509->sign($issuer, $subject);
        return array('privateKey' => $privKey->getPrivateKey(), 'publicX509' => $x509->saveX509($result));
    }
}
Ejemplo n.º 3
0
 public function Rsa()
 {
     $modulus = 'ACD53F4BE9665DF48A2A1E39F4E7CDFAA0833AD986DD09831E519974D4E0228F43D9E58AE9ECEE865093D12E3EA576337C431F95C1C979784B8BDC93F244E072631339E8208CC5DF1377CB10E5018842DA9889856190F339CE8344FA906B67738BE292206EFAB71D33A5FC7EB1C3DBEC2F9A1A59B286C2B30C5E2FA0980D65A9';
     $exponent = '010001';
     $rsa = new Crypt_RSA();
     $modulus = $this->convertion($modulus);
     $exponent = $this->convertion($exponent);
     $rsa->loadKey(array('n' => $modulus, 'e' => $exponent));
     $rsa->setPublicKey();
     return $rsa->getPublicKey();
 }
Ejemplo n.º 4
0
 public function generateKeyPair($keyPath, $keySize = 1024)
 {
     $privKey = new \Crypt_RSA();
     extract($privKey->createKey($keySize));
     $privKey->loadKey($privatekey);
     $pubKey = new \Crypt_RSA();
     $pubKey->loadKey($publickey);
     $pubKey->setPublicKey();
     $subject = new \File_X509();
     $subject->setDNProp('id-of-organization', 'phpseclib demo cert');
     $subject->setPublicKey($pubKey);
     $issuer = new \File_X509();
     $issuer->setPrivateKey($privKey);
     $issuer->setDN($subject->getDN());
     $x509 = new \File_X509();
     $result = $x509->sign($issuer, $subject);
     file_put_contents($keyPath . '/private.key', $privKey->getPrivateKey());
     file_put_contents($keyPath . '/public.crt', $x509->saveX509($result));
 }
Ejemplo n.º 5
0
 public function encrypt()
 {
     $binaryKey = bin2hex(base64_decode(GOOGLE_DEFAULT_PUBLIC_KEY));
     $half = substr($binaryKey, 8, 256);
     $modulus = new Math_BigInteger(hex2bin($half), 256);
     $half = substr($binaryKey, 272, 6);
     $exponent = new Math_BigInteger(hex2bin($half), 256);
     $sha1 = sha1(base64_decode($googleDefaultPublicKey), true);
     $signature = "00" . bin2hex(substr($sha1, 0, 4));
     $rsa = new Crypt_RSA();
     $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_RAW);
     $rsa->loadKey(array("n" => $modulus, "e" => $exponent));
     $rsa->setPublicKey();
     $plain = "{$email}{$password}";
     $rsa->setEncryptionMode("CRYPT_RSA_ENCRYPTION_OAEP");
     $encrypted = bin2hex($rsa->encrypt($plain));
     $output = hex2bin($signature . $encrypted);
     $b64EncryptedPasswd = str_replace(array("+", "/"), array("-", "_"), mb_convert_encoding(base64_encode($output), "US-ASCII"));
     return $b64EncryptedPasswd;
 }
Ejemplo n.º 6
0
 public function login($authcode = '', $twofactorcode = '')
 {
     $dologin = $this->getRSAkey();
     if ($dologin->publickey_mod && $dologin->publickey_exp && $dologin->timestamp) {
         $password = $this->config['password'];
         $rsa = new Crypt_RSA();
         $key = array('modulus' => new Math_BigInteger($dologin->publickey_mod, 16), 'publicExponent' => new Math_BigInteger($dologin->publickey_exp, 16));
         $rsa->loadKey($key, CRYPT_RSA_PUBLIC_FORMAT_RAW);
         $rsa->setPublicKey($key);
         $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
         $enc_password = base64_encode($rsa->encrypt($password));
         $login = $this->request('POST', 'https://steamcommunity.com/login/dologin/', array('password' => $enc_password, 'username' => $this->config['username'], 'twofactorcode' => $twofactorcode, 'emailauth' => $authcode, 'loginfriendlyname' => '', 'capatcha_text' => '', 'emailsteamid' => isset($this->accountdata['steamid']) ? $this->accountdata['steamid'] : '', 'rsatimestamp' => $dologin->timestamp, 'remember_login' => 'true', 'donotcache' => time()));
         $login = json_decode($login);
         if ($login->success == false) {
             if (isset($login->emailsteamid) && $login->emailauth_needed == true) {
                 if ($authcode == '') {
                     file_put_contents($this->config['datapath'] . '/logindata.json', json_encode(array('steamid' => $login->emailsteamid)));
                     $this->error('Please enter AUTHCODE available in your e-mail inbox (domain: ' . $login->emaildomain . ').');
                 } else {
                     $this->error('You enter bad authcode!');
                 }
             } else {
                 if ($login->requires_twofactor == true) {
                     if ($twofactorcode == '') {
                         $this->error('Please enter twofactorcode (mobile auth).');
                     } else {
                         $this->error('You enter bad twofactorcode!');
                     }
                 }
             }
         } else {
             preg_match_all('#g_sessionID\\s\\=\\s\\"(.*?)\\"\\;#si', $this->view('http://steamcommunity.com/id'), $matches);
             return array('steamid' => $login->transfer_parameters->steamid, 'sessionId' => $matches[1][0], 'cookies' => $this->cookiejarToString(file_get_contents('cookiejar.txt')));
         }
         return $login;
     } else {
         $this->error('Bad RSA!');
     }
     return $dologin;
 }
Ejemplo n.º 7
0
 /**
  * @param string $certPem
  * @param array $keyPairPems
  *   Pair of PEM-encoded keys.
  * @param string $caCertPem
  * @return \File_X509
  */
 public static function loadCert($certPem, $keyPairPems = NULL, $caCertPem = NULL)
 {
     $certObj = new \File_X509();
     if (isset($caCertPem)) {
         $certObj->loadCA($caCertPem);
     }
     if ($certPem) {
         $certObj->loadX509($certPem);
     }
     if (isset($keyPairPems['privatekey'])) {
         $privKey = new \Crypt_RSA();
         $privKey->loadKey($keyPairPems['privatekey']);
         $certObj->setPrivateKey($privKey);
     }
     if (isset($keyPairPems['publickey'])) {
         $pubKey = new \Crypt_RSA();
         $pubKey->loadKey($keyPairPems['publickey']);
         $pubKey->setPublicKey();
         $certObj->setPublicKey($pubKey);
     }
     return $certObj;
 }
Ejemplo n.º 8
0
function jwkToPem($jwk)
{
    $modulus = new Math_BigInteger(base64url_decode($jwk['n']), 256);
    $exponent = new Math_BigInteger(base64_decode($jwk['e']), 256);
    $rsa = new Crypt_RSA();
    $rsa->loadKey(array('n' => $modulus, 'e' => $exponent));
    $rsa->setPublicKey();
    return str_replace("\r", "", $rsa->getPublicKey());
    // This shit is written for DOS
}
Ejemplo n.º 9
0
    /**
     * @group github468
     */
    public function testSignedPKCS1()
    {
        $rsa = new Crypt_RSA();
        $key = '-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC/k7FwSDE9R9rvTU2nGdJwKaVG
RvBIYGJNahseQhZkQH4CVFMdpWhmD8PyXpjNHtV1CJ0bqAX6e5QyNjvl0FeBj9dz
JWrQdxx/WNN+ABG426rgYYbeGcIlWLZCw6Bx/1HtN5ef6nVEoiGNChYKIRB4QFOi
01smFxps1w8ZIQnD6wIDAQAB
-----END PUBLIC KEY-----';
        $rsa->loadKey($key);
        $rsa->setPublicKey();
        $newkey = $rsa->getPublicKey();
        $this->assertSame(preg_replace('#\\s#', '', $key), preg_replace('#\\s#', '', $newkey));
    }
Ejemplo n.º 10
0
 /**
  * Create a CSR for an authority that can issue CRLs.
  *
  * @param array $keyPair
  * @param string $dn
  * @return string
  *   PEM-encoded CSR.
  */
 public static function createCrlDistCSR($keyPair, $dn)
 {
     $privKey = new \Crypt_RSA();
     $privKey->loadKey($keyPair['privatekey']);
     $pubKey = new \Crypt_RSA();
     $pubKey->loadKey($keyPair['publickey']);
     $pubKey->setPublicKey();
     $csr = new \File_X509();
     $csr->setPrivateKey($privKey);
     $csr->setPublicKey($pubKey);
     $csr->setDN($dn);
     $csr->loadCSR($csr->saveCSR($csr->signCSR(Constants::CERT_SIGNATURE_ALGORITHM)));
     $csr->setExtension('id-ce-keyUsage', array('cRLSign'));
     $csrData = $csr->signCSR(Constants::CERT_SIGNATURE_ALGORITHM);
     return $csr->saveCSR($csrData);
 }
Ejemplo n.º 11
0
 /**
  * Gets the public key
  *
  * Returns a Crypt_RSA object or a false.
  *
  * @access public
  * @return Mixed
  */
 function getPublicKey()
 {
     if (!isset($this->currentCert) || !is_array($this->currentCert) || !isset($this->currentCert['tbsCertificate'])) {
         return false;
     }
     $key = $this->currentCert['tbsCertificate']['subjectPublicKeyInfo']['subjectPublicKey'];
     switch ($this->currentCert['tbsCertificate']['subjectPublicKeyInfo']['algorithm']['algorithm']) {
         case 'rsaEncryption':
             if (!class_exists('Crypt_RSA')) {
                 require_once 'Crypt/RSA.php';
             }
             $publicKey = new Crypt_RSA();
             $publicKey->loadKey($key);
             $publicKey->setPublicKey();
             break;
         default:
             return false;
     }
     return $publicKey;
 }
Ejemplo n.º 12
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     // ask fields
     $options = ['countryName' => 'CN', 'stateOrProvinceName' => 'Shanghai', 'localityName' => 'Shanghai'];
     if (!$input->getOption('default')) {
         foreach ($options as $ask => $default) {
             $q = new Question($ask . '[' . $default . ']: ', $default);
             $options[$ask] = $helper->ask($input, $output, $q);
         }
     }
     $output->writeln('Generating CA private key...');
     $CAPrivKey = new \Crypt_RSA();
     $key = $CAPrivKey->createKey(2048);
     file_put_contents(Application::$CONFIG_DIRECTORY . '/cert-ca.key', $key['privatekey']);
     $output->writeln('Generating self-signed CA certificate...');
     $CAPrivKey->loadKey($key['privatekey']);
     $pubKey = new \Crypt_RSA();
     $pubKey->loadKey($key['publickey']);
     $pubKey->setPublicKey();
     $subject = new \File_X509();
     $subject->setDNProp('id-at-organizationName', 'OpenVJ Certificate Authority');
     foreach ($options as $prop => $val) {
         $subject->setDNProp('id-at-' . $prop, $val);
     }
     $subject->setPublicKey($pubKey);
     $issuer = new \File_X509();
     $issuer->setPrivateKey($CAPrivKey);
     $issuer->setDN($CASubject = $subject->getDN());
     $x509 = new \File_X509();
     $x509->setStartDate('-1 month');
     $x509->setEndDate('+3 year');
     $x509->setSerialNumber(chr(1));
     $x509->makeCA();
     $result = $x509->sign($issuer, $subject, 'sha256WithRSAEncryption');
     file_put_contents(Application::$CONFIG_DIRECTORY . '/cert-ca.crt', $x509->saveX509($result));
     $output->writeln('Generating background service SSL private key...');
     $privKey = new \Crypt_RSA();
     $key = $privKey->createKey(2048);
     file_put_contents(Application::$CONFIG_DIRECTORY . '/cert-bg-server.key', $key['privatekey']);
     $privKey->loadKey($key['privatekey']);
     $output->writeln('Generating background service SSL certificate...');
     $pubKey = new \Crypt_RSA();
     $pubKey->loadKey($key['publickey']);
     $pubKey->setPublicKey();
     $subject = new \File_X509();
     $subject->setPublicKey($pubKey);
     $subject->setDNProp('id-at-organizationName', 'OpenVJ Background Service Certificate');
     foreach ($options as $prop => $val) {
         $subject->setDNProp('id-at-' . $prop, $val);
     }
     $subject->setDomain('127.0.0.1');
     $issuer = new \File_X509();
     $issuer->setPrivateKey($CAPrivKey);
     $issuer->setDN($CASubject);
     $x509 = new \File_X509();
     $x509->setStartDate('-1 month');
     $x509->setEndDate('+3 year');
     $x509->setSerialNumber(chr(1));
     $result = $x509->sign($issuer, $subject, 'sha256WithRSAEncryption');
     file_put_contents(Application::$CONFIG_DIRECTORY . '/cert-bg-server.crt', $x509->saveX509($result));
     $output->writeln('Generating background service client private key...');
     $privKey = new \Crypt_RSA();
     $key = $privKey->createKey(2048);
     file_put_contents(Application::$CONFIG_DIRECTORY . '/cert-bg-client.key', $key['privatekey']);
     $privKey->loadKey($key['privatekey']);
     $output->writeln('Generating background service client certificate...');
     $pubKey = new \Crypt_RSA();
     $pubKey->loadKey($key['publickey']);
     $pubKey->setPublicKey();
     $subject = new \File_X509();
     $subject->setPublicKey($pubKey);
     $subject->setDNProp('id-at-organizationName', 'OpenVJ Background Service Client Certificate');
     foreach ($options as $prop => $val) {
         $subject->setDNProp('id-at-' . $prop, $val);
     }
     $issuer = new \File_X509();
     $issuer->setPrivateKey($CAPrivKey);
     $issuer->setDN($CASubject);
     $x509 = new \File_X509();
     $x509->setStartDate('-1 month');
     $x509->setEndDate('+3 year');
     $x509->setSerialNumber(chr(1));
     $x509->loadX509($x509->saveX509($x509->sign($issuer, $subject, 'sha256WithRSAEncryption')));
     $x509->setExtension('id-ce-keyUsage', array('digitalSignature', 'keyEncipherment', 'dataEncipherment'));
     $x509->setExtension('id-ce-extKeyUsage', array('id-kp-serverAuth', 'id-kp-clientAuth'));
     $result = $x509->sign($issuer, $x509, 'sha256WithRSAEncryption');
     file_put_contents(Application::$CONFIG_DIRECTORY . '/cert-bg-client.crt', $x509->saveX509($result));
 }
Ejemplo n.º 13
0
 static function crypt_rsa_key($mod, $exp, $hash = 'SHA256')
 {
     $rsa = new Crypt_RSA();
     $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
     $rsa->setHash(strtolower($hash));
     $rsa->modulus = new Math_BigInteger($mod, 256);
     $rsa->k = strlen($rsa->modulus->toBytes());
     $rsa->exponent = new Math_BigInteger($exp, 256);
     $rsa->setPublicKey();
     return $rsa;
 }
Ejemplo n.º 14
0
$iPhoneDeviceCA = file_get_contents($iPhoneDeviceCAFile);
$CA_Certificate = new File_X509();
$CA_Certificate->setPrivateKey($CA_Key);
$CA_Certificate->loadX509($iPhoneDeviceCA);
// $CA_Certificate->setExtension( 'id-ce-authorityKeyIdentifier',
// $CA_Certificate->setKeyIdentifier ( base64_decode (
// 'sv4hI0SGlWp51YEmjnMQ2KdMjnQ=' ) ), false );
// Get And Store DeviceCertRequest Public Key.
$DeviceCertRequest = base64_decode($DeviceCertRequest);
$iPhoneDeviceVect = openssl_pkey_get_details(openssl_csr_get_public_key($DeviceCertRequest));
$iPhoneDevicePublicKey = $iPhoneDeviceVect['key'];
file_put_contents($DeviceCertRequest_PublicFile, $iPhoneDevicePublicKey);
// Load DeviceCertRequest Public Key.
$DeviceCertRequest_PublicKey = new Crypt_RSA();
$DeviceCertRequest_PublicKey->loadKey(file_get_contents($DeviceCertRequest_PublicFile));
$DeviceCertRequest_PublicKey->setPublicKey();
// Load CSR And get DN.
$DeviceCertRequest_CR = new File_X509();
$DeviceCertRequest_CR->loadCSR($DeviceCertRequest);
$doulCi_DN = $DeviceCertRequest_CR->getDNProp('id-at-commonName');
// Build the new Device Certificate.
$iPhoneDeviceCA = new File_X509();
// $iPhoneDeviceCA->loadCA ( $iPhoneDeviceCA );
$iPhoneDeviceCA->setPublicKey($DeviceCertRequest_PublicKey);
$iPhoneDeviceCA->setDN($DeviceCertRequest_CR->getDN(true));
$iPhoneDeviceCA->removeDNProp('id-at-commonName');
$iPhoneDeviceCA->setDN(array('rdnSequence' => array(array(array('type' => 'id-at-commonName', 'value' => array('ia5String' => $doulCi_DN))))));
$iPhoneDeviceCA->setStartDate('-1 day');
$iPhoneDeviceCA->setEndDate('+ 3 year');
$iPhoneDeviceCA->setSerialNumber('1184677871349854983709', 10);
// Sign Device Certificate.
Ejemplo n.º 15
0
$subject->setDNProp('id-at-organizationName', 'phpseclib demo CA');
$subject->setPublicKey($pubKey);
$issuer = new File_X509();
$issuer->setPrivateKey($CAPrivKey);
$issuer->setDN($CASubject = $subject->getDN());
$x509 = new File_X509();
$x509->makeCA();
$result = $x509->sign($issuer, $subject);
echo "the CA cert to be imported into the browser is as follows:\r\n\r\n";
echo $x509->saveX509($result);
echo "\r\n\r\n";
// create private key / x.509 cert for stunnel / website
$privKey = new Crypt_RSA();
extract($privKey->createKey());
$privKey->loadKey($privatekey);
$pubKey = new Crypt_RSA();
$pubKey->loadKey($publickey);
$pubKey->setPublicKey();
$subject = new File_X509();
$subject->setDNProp('id-at-organizationName', 'phpseclib demo cert');
$subject->setPublicKey($pubKey);
$issuer = new File_X509();
$issuer->setPrivateKey($CAPrivKey);
$issuer->setDN($CASubject);
$x509 = new File_X509();
$result = $x509->sign($issuer, $subject);
echo "the stunnel.pem contents are as follows:\r\n\r\n";
echo $privKey->getPrivateKey();
echo "\r\n";
echo $x509->saveX509($result);
echo "\r\n";
Ejemplo n.º 16
0
 public function exportPublicKey($format = CRYPT_RSA_PUBLIC_FORMAT_PKCS1)
 {
     $this->publicKey->setPublicKey();
     return $this->publicKey->getPublicKey($format);
 }
Ejemplo n.º 17
0
 /**
  * Quasi-private - marked public to work-around PHP 5.3 compat.
  *
  * @param string $key
  * @param string $type
  *   'public' or 'private'
  * @return \Crypt_RSA
  */
 public static function getRsa($key, $type)
 {
     $rsa = new \Crypt_RSA();
     $rsa->loadKey($key);
     if ($type == 'public') {
         $rsa->setPublicKey();
     }
     $rsa->setEncryptionMode(Constants::RSA_ENC_MODE);
     $rsa->setSignatureMode(Constants::RSA_SIG_MODE);
     $rsa->setHash(Constants::RSA_HASH);
     return $rsa;
 }
Ejemplo n.º 18
0
<?php

echo "test";
include 'fullRSA.php';
$key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtixUGzGpLXgZ7AV1HfmIHV/FEF+fww77FekRc2oLhUOd4HitwCPo76fjtdsQBEt8w9HZ3CXVphaAU2BA6MEZJ3ShVMsdAXb2ZA1C+lu7k1GV9M/BhucTg35HujSK647Sc5MwVLwFsN80dAnGsZF8gwb2TNUzXHwzbAb30T01zuqf8RCM75OwKZFYqzu7FOVrtk/w9mh92MOXG0l7WSqNIctu8Kxka/tEJJIA5nqMGNMocjwprXy66NS7FFy1GY+NnxfFLtODqq0tllc50UCDsnqSvNmj2wcnAcsCzNOoxPPgp7t8S+sQvOzgc5W3CDjIsYEiGD+vzSVNkGiRou577wIDAQAB';
$rsa = new Crypt_RSA();
$rsa->loadKey($key);
$rsa->setPublicKey($key);
echo $rsa->getPublicKey();
//$rsa = new MyEncryption();
echo "test";
//echo "encr: ".$rsa->encrypt("lo omg 6");
Ejemplo n.º 19
0
 public function loadPublicKeyPKCS1($key)
 {
     $rsa = new Crypt_RSA();
     if (!$rsa->setPublicKey($key, CRYPT_RSA_PUBLIC_FORMAT_PKCS1)) {
         throw new ServerException('Could not load PKCS1 public key. We probably got this from a remote Diaspora node as the profile public key.');
     }
     $this->publicKey = $rsa;
 }
Ejemplo n.º 20
0
 public function encryptPassword($email, $password)
 {
     $googleDefaultPublicKey = "AAAAgMom/1a/v0lblO2Ubrt60J2gcuXSljGFQXgcyZWveWLEwo6prwgi3iJIZdodyhKZQrNWp5nKJ3srRXcUW+F1BD3baEVGcmEgqaLZUNBjm057pKRI16kB0YppeGx5qIQ5QjKzsR8ETQbKLNWgRY0QRNVz34kMJR3P/LgHax/6rmf5AAAAAwEAAQ==";
     $binaryKey = bin2hex(base64_decode($googleDefaultPublicKey));
     $half = substr($binaryKey, 8, 256);
     $modulus = new Math_BigInteger(hex2bin($half), 256);
     $half = substr($binaryKey, 272, 6);
     $exponent = new Math_BigInteger(hex2bin($half), 256);
     $sha1 = sha1(base64_decode($googleDefaultPublicKey), true);
     $signature = "00" . bin2hex(substr($sha1, 0, 4));
     $rsa = new Crypt_RSA();
     $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_RAW);
     $rsa->loadKey(array("n" => $modulus, "e" => $exponent));
     $rsa->setPublicKey();
     $plain = "{$email}{$password}";
     $rsa->setEncryptionMode("CRYPT_RSA_ENCRYPTION_OAEP");
     $encrypted = bin2hex($rsa->encrypt($plain));
     $output = hex2bin($signature . $encrypted);
     $b64EncryptedPasswd = str_replace(array("+", "/"), array("-", "_"), mb_convert_encoding(base64_encode($output), "US-ASCII"));
     return $b64EncryptedPasswd;
 }
Ejemplo n.º 21
0
 /**
  * Gets the public key
  *
  * Returns a Crypt_RSA object or a false.
  *
  * @access public
  * @return Mixed
  */
 function getPublicKey()
 {
     if (isset($this->publicKey)) {
         return $this->publicKey;
     }
     if (isset($this->currentCert) && is_array($this->currentCert)) {
         foreach (array('tbsCertificate/subjectPublicKeyInfo', 'certificationRequestInfo/subjectPKInfo') as $path) {
             $keyinfo = $this->_subArray($this->currentCert, $path);
             if (!empty($keyinfo)) {
                 break;
             }
         }
     }
     if (empty($keyinfo)) {
         return false;
     }
     $key = $keyinfo['subjectPublicKey'];
     switch ($keyinfo['algorithm']['algorithm']) {
         case 'rsaEncryption':
             require_once 'Crypt/RSA.php';
             $publicKey = new Crypt_RSA();
             $publicKey->loadKey($key);
             $publicKey->setPublicKey();
             break;
         default:
             return false;
     }
     return $publicKey;
 }
Ejemplo n.º 22
0
$community = get_community_users($db);
// если мест в пуле нет, то просто запишем юзера в очередь
$pool_max_users = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\tSELECT `pool_max_users`\n\t\t\tFROM `" . DB_PREFIX . "config`\n\t\t\t", 'fetch_one');
if (sizeof($community) >= $pool_max_users) {
    $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\tINSERT IGNORE INTO `" . DB_PREFIX . "pool_waiting_list` (\n\t\t\t\t`email`,\n\t\t\t\t`time`,\n\t\t\t\t`user_id`\n\t\t\t)\n\t\t\tVALUES (\n\t\t\t\t\t'{$email}',\n\t\t\t\t\t" . time() . ",\n\t\t\t\t\t{$user_id}\n\t\t\t)");
    die(json_encode(array('error' => $lng['pool_is_full'])));
}
// регистрируем юзера в пуле
// вначале убедитмся, что такой user_id у нас уже не зареган
$community = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\tSELECT `user_id`\n\t\tFROM `" . DB_PREFIX . "community`\n\t\tWHERE `user_id` = {$user_id}\n\t\t", 'fetch_one');
if ($community) {
    die(json_encode(array('error' => $lng['pool_user_id_is_busy'])));
}
$db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\tINSERT IGNORE INTO `" . DB_PREFIX . "community` (\n\t\t\t`user_id`\n\t\t)\n\t\tVALUES (\n\t\t\t{$user_id}\n\t\t)");
$rsa = new Crypt_RSA();
$key = array();
$key['e'] = new Math_BigInteger($_POST['e'], 16);
$key['n'] = new Math_BigInteger($_POST['n'], 16);
$rsa->setPublicKey($key, CRYPT_RSA_PUBLIC_FORMAT_RAW);
$PublicKey = clear_public_key($rsa->getPublicKey());
// если таблы my для этого юзера уже есть в БД, то они перезапишутся.
$mysqli_link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, DB_PORT);
$db_name = DB_NAME;
$prefix = DB_PREFIX;
include ABSPATH . 'schema.php';
mysqli_query($mysqli_link, 'SET NAMES "utf8" ');
pool_add_users("{$user_id};{$PublicKey}\n", $my_queries, $mysqli_link, DB_PREFIX, false);
define('MY_PREFIX', $user_id . '_');
$db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\tUPDATE `" . DB_PREFIX . MY_PREFIX . "my_table`\n\t\tSET `email` = '{$email}'\n\t\t");
print json_encode(array('success' => $lng['pool_sign_up_success']));
unset($_SESSION['restricted']);
Ejemplo n.º 23
0
 /**
  * Set Public Key
  *
  * Called by System_SSH_Agent::requestIdentities()
  *
  * @param Crypt_RSA $key
  * @access private
  */
 function setPublicKey($key)
 {
     $this->key = $key;
     $this->key->setPublicKey();
 }
Ejemplo n.º 24
0
ZTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAp+pWUbIk+mTyQp2hT95RMAFX
pC83IckQckh6FoXGj9n5CVNW1U1tAcj0bi+zVrF2yPX0AjuYLMBIS9bRtrJ6Cu/P
fhyqfgkK4XFOdTcvupegXZi5QakmcQOFotubpuD5Z+6FnhDsJz57bORcznCzu60Y
Ers/c3NjwSCFFi/IyPMCAwEAAaAAMA0GCSqGSIb3DQEBBQUAA4GBAE2zL2HLSCPE
8XsFKrB1J7w7pKxjf64QVHjp5aK3HtOUL89TRJFzHdpXMG58GrKibRWK19+kTQg4
zXyNVXEc4CnOFO2U5vPbdFmpgHc5IXFZZJgHrQo+JD39EJ5O0rtchKeYnePbK+X4
5fcixklRySJ06YthmX3FHitD3ExjaI8p
-----END CERTIFICATE REQUEST-----
';
$vectxq = openssl_pkey_get_details(openssl_csr_get_public_key($csr));
$pkeyxq = $vectxq['key'];
file_put_contents('certs/pubkey.pem', $pkeyxq);
// Load the certificate public key.
$pubkey = new Crypt_RSA();
$pubkey->loadKey(file_get_contents('certs/pubkey.pem'));
$pubkey->setPublicKey();
// Build the new certificate.
$iPhoneDeviceCA = new File_X509();
$iPhoneDeviceCA->loadCA($pemca);
$iPhoneDeviceCA->setPublicKey($pubkey);
$iPhoneDeviceCA->setDN('C=US, ST=Some-State, L=Cupertino, O=Apple Inc., OU=Apple iPhone, CN=Apple iPhone Device CA');
$iPhoneDeviceCA->setStartDate('-1 day');
$iPhoneDeviceCA->setEndDate('+ 1 year');
$iPhoneDeviceCA->setSerialNumber('10134611745959375605', 10);
// Sign new certificate.
$iPhoneDeviceCA_Result = $iPhoneDeviceCA->sign($ca, $iPhoneDeviceCA);
// Output it.
echo $iPhoneDeviceCA->saveX509($iPhoneDeviceCA_Result) . "\n";
// subject=/C=US/O=Apple Inc./OU=Apple iPhone/CN=Apple iPhone Device CA
// issuer=/C=US/O=Apple Inc./OU=Apple Certification Authority/CN=Apple iPhone
// Certification Authority