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);
     }
 }
Esempio n. 2
0
function publicKeyToHex($privatekey)
{
    $rsa = new Crypt_RSA();
    $rsa->loadKey($privatekey);
    $raw = $rsa->getPublicKey(CRYPT_RSA_PUBLIC_FORMAT_RAW);
    return $raw['n']->toHex();
}
Esempio n. 3
0
 /**
  * @return \Crypt_RSA|null
  */
 public static function CryptRSA()
 {
     if (null === \RainLoop\Utils::$RSA) {
         if (!\defined('_phpseclib_')) {
             \set_include_path(\get_include_path() . PATH_SEPARATOR . APP_VERSION_ROOT_PATH . 'app/libraries/phpseclib');
             define('_phpseclib_', true);
         }
         if (!\class_exists('Crypt_RSA', false)) {
             include_once 'Crypt/RSA.php';
             \defined('CRYPT_RSA_MODE') || \define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL);
         }
         if (\class_exists('Crypt_RSA')) {
             $oRsa = new \Crypt_RSA();
             $oRsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
             $oRsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
             $oRsa->setPrivateKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1);
             $sPrivateKey = \file_exists(APP_PRIVATE_DATA . 'rsa/private') ? \file_get_contents(APP_PRIVATE_DATA . 'rsa/private') : '';
             if (!empty($sPrivateKey)) {
                 $oRsa->loadKey($sPrivateKey, CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
                 $oRsa->loadKey($oRsa->getPublicKey(), CRYPT_RSA_PUBLIC_FORMAT_PKCS1);
                 \RainLoop\Utils::$RSA = $oRsa;
             }
         }
     }
     return \RainLoop\Utils::$RSA;
 }
Esempio n. 4
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();
 }
Esempio n. 5
0
 public function signMessage($privatekey, $message)
 {
     /**
      * Test code:
      * 
      * $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
      * extract($rsa->createKey());
      * $spotSigning = new SpotSigning();
      * $x = $spotSigning->signMessage($privatekey, 'testmessage');
      * var_dump($x);
      * var_dump($spotSigning->checkRsaSignature('testmessage', $x['signature'], $x['publickey']));
      *
      */
     $rsa = new Crypt_RSA();
     $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
     $rsa->loadKey($privatekey);
     # extract de public key
     $signature = $rsa->sign($message);
     $publickey = $rsa->getPublicKey(CRYPT_RSA_PUBLIC_FORMAT_RAW);
     return array('signature' => base64_encode($signature), 'publickey' => array('modulo' => base64_encode($publickey['n']->toBytes()), 'exponent' => base64_encode($publickey['e']->toBytes())), 'message' => $message);
 }
Esempio n. 6
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']);
Esempio n. 7
0
 function getPublicKey($privateKey)
 {
     $rsa = new Crypt_RSA();
     $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
     $rsa->loadKey($privateKey);
     # extract de public key
     $publicKey = $rsa->getPublicKey(CRYPT_RSA_PUBLIC_FORMAT_RAW);
     return array('publickey' => array('modulo' => base64_encode($publicKey['n']->toBytes()), 'exponent' => base64_encode($publicKey['e']->toBytes())));
 }
Esempio n. 8
0
<?php

include 'crypt/RSA.php';
$private_key = file_get_contents("../certs/signature_private.key");
$pkeyid = openssl_pkey_get_private($private_key);
#$public_key = file_get_contents("../certs/signature_public.key");
$accountTokenBase64 = base64_encode('{' . "\n\t" . '"ActivationRandomness" = "F34182B4-4FE1-47D2-96F3-5851EF00D28F";' . "\n\t" . '"UniqueDeviceID" = "463fc92a2d3462dec0e2c4f98d445abe46730d6a";' . "\n" . '}');
// compute signature
openssl_sign($accountTokenBase64, $signature, $pkeyid);
$rsa = new Crypt_RSA();
$rsa->loadKey($private_key);
$rsa->loadKey($rsa->getPublicKey());
$rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
echo 'Signature is ' . ($rsa->verify($accountTokenBase64, $signature) ? 'correct' : 'incorrect');
openssl_free_key($pkeyid);
/*
$pkeyid = openssl_pkey_get_private(file_get_contents("../certs/signature_private.key"));
$public_key = file_get_contents("../certs/signature_public.key");

#$pubkeydetails=openssl_pkey_get_details($pkeyid)["key"];
#$pubkeyid = openssl_pkey_get_public($pubkeydetails);

// compute signature
openssl_sign("test", $signature, $pkeyid);

$result = openssl_verify("test", $signature, $public_key);

echo 'Signature is '.($result == 1 ? 'correct' : $result == 0 ? 'incorrect' : 'erroneous');

openssl_free_key($pkeyid);
#openssl_free_key($pubkeyid);*/
Esempio n. 9
0
 function getPublicKey($privateKey)
 {
     $rsa = new Crypt_RSA();
     $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
     $rsa->loadKey($privateKey);
     /*
      * When we load a public key where a private key should
      * be loaded, this makes sure we can use it after all
      */
     if ($rsa->publicExponent == false) {
         $rsa->publicExponent = $rsa->exponent;
     }
     # if
     # extract the public key
     $publicKey = $rsa->getPublicKey(CRYPT_RSA_PUBLIC_FORMAT_RAW);
     return array('modulo' => base64_encode($publicKey['n']->toBytes()), 'exponent' => base64_encode($publicKey['e']->toBytes()));
 }
 public function generateInitialJSCode($datasource, $options, $dbspecification, $debug)
 {
     $q = '"';
     $generatedPrivateKey = null;
     $passPhrase = null;
     /*
      * Decide the params.php file and load it.
      */
     $currentDir = dirname(__FILE__) . DIRECTORY_SEPARATOR;
     $currentDirParam = $currentDir . 'params.php';
     $parentDirParam = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'params.php';
     if (file_exists($parentDirParam)) {
         include $parentDirParam;
     } else {
         if (file_exists($currentDirParam)) {
             include $currentDirParam;
         }
     }
     /*
      * Read the JS programs regarding by the developing or deployed.
      */
     if (file_exists($currentDir . 'INTER-Mediator-Lib.js')) {
         echo $this->combineScripts($currentDir);
     } else {
         readfile($currentDir . 'INTER-Mediator.js');
     }
     /*
      * Generate the link to the definition file editor
      */
     $relativeToDefFile = '';
     $editorPath = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'INTER-Mediator-Support';
     $defFilePath = $_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME'];
     while (strpos($defFilePath, $editorPath) !== 0 && strlen($editorPath) > 1) {
         $editorPath = dirname($editorPath);
         $relativeToDefFile .= '..' . DIRECTORY_SEPARATOR;
     }
     $relativeToDefFile .= substr($defFilePath, strlen($editorPath) + 1);
     $editorPath = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'INTER-Mediator-Support' . DIRECTORY_SEPARATOR . 'defedit.html';
     if (file_exists($editorPath)) {
         $relativeToEditor = substr($editorPath, strlen($_SERVER['DOCUMENT_ROOT']));
         $this->generateAssignJS("INTERMediatorOnPage.getEditorPath", "function(){return {$q}{$relativeToEditor}?target={$relativeToDefFile}{$q};}");
     } else {
         $this->generateAssignJS("INTERMediatorOnPage.getEditorPath", "function(){return '';}");
     }
     /*
      * from db-class, determine the default key field string
      */
     $defaultKey = null;
     $dbClassName = 'DB_' . (isset($dbspecification['db-class']) ? $dbspecification['db-class'] : (isset($dbClass) ? $dbClass : ''));
     require_once "{$dbClassName}.php";
     if ((double) phpversion() < 5.3) {
         $dbInstance = new $dbClassName();
         if ($dbInstance != null) {
             $defaultKey = $dbInstance->getDefaultKey();
         }
     } else {
         $defaultKey = call_user_func(array($dbClassName, 'defaultKey'));
     }
     if ($defaultKey !== null) {
         $items = array();
         foreach ($datasource as $context) {
             if (!array_key_exists('key', $context)) {
                 $context['key'] = $defaultKey;
             }
             $items[] = $context;
         }
         $datasource = $items;
     }
     /*
      * Determine the uri of myself
      */
     if (isset($callURL)) {
         $pathToMySelf = $callURL;
     } else {
         if (isset($scriptPathPrefix) || isset($scriptPathSuffix)) {
             $pathToMySelf = (isset($scriptPathPrefix) ? $scriptPathPrefix : '') . $_SERVER['SCRIPT_NAME'] . (isset($scriptPathSufix) ? $scriptPathSuffix : '');
         } else {
             $pathToMySelf = $_SERVER['SCRIPT_NAME'];
         }
     }
     $this->generateAssignJS("INTERMediatorOnPage.getEntryPath", "function(){return {$q}{$pathToMySelf}{$q};}");
     $this->generateAssignJS("INTERMediatorOnPage.getDataSources", "function(){return ", arrayToJSExcluding($datasource, '', array('password')), ";}");
     $this->generateAssignJS("INTERMediatorOnPage.getOptionsAliases", "function(){return ", arrayToJS(isset($options['aliases']) ? $options['aliases'] : array(), ''), ";}");
     $this->generateAssignJS("INTERMediatorOnPage.getOptionsTransaction", "function(){return ", arrayToJS(isset($options['transaction']) ? $options['transaction'] : '', ''), ";}");
     $this->generateAssignJS("INTERMediatorOnPage.getDBSpecification", "function(){return ", arrayToJSExcluding($dbspecification, '', array('dsn', 'option', 'database', 'user', 'password', 'server', 'port', 'protocol', 'datatype')), ";}");
     $isEmailAsUsernae = isset($options['authentication']) && isset($options['authentication']['email-as-username']) && $options['authentication']['email-as-username'] === true;
     $this->generateAssignJS("INTERMediatorOnPage.isEmailAsUsername", $isEmailAsUsernae ? "true" : "false");
     $messageClass = null;
     if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
         $clientLangArray = explode(',', $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
         foreach ($clientLangArray as $oneLanguage) {
             $langCountry = explode(';', $oneLanguage);
             if (strlen($langCountry[0]) > 0) {
                 $clientLang = explode('-', $langCountry[0]);
                 $messageClass = "MessageStrings_{$clientLang['0']}";
                 if (file_exists("{$currentDir}{$messageClass}.php")) {
                     $messageClass = new $messageClass();
                     break;
                 }
             }
             $messageClass = null;
         }
     }
     if ($messageClass == null) {
         require_once 'MessageStrings.php';
         $messageClass = new MessageStrings();
     }
     $this->generateAssignJS("INTERMediatorOnPage.getMessages", "function(){return ", arrayToJS($messageClass->getMessages(), ''), ";}");
     if (isset($options['browser-compatibility'])) {
         $browserCompatibility = $options['browser-compatibility'];
     }
     $this->generateAssignJS("INTERMediatorOnPage.browserCompatibility", "function(){return ", arrayToJS($browserCompatibility, ''), ";}");
     $clientIdSeed = time() + $_SERVER['REMOTE_ADDR'] + mt_rand();
     $randomSecret = mt_rand();
     $clientId = hash_hmac('sha256', $clientIdSeed, $randomSecret);
     $this->generateAssignJS("INTERMediatorOnPage.clientNotificationIdentifier", "function(){return ", arrayToJS($clientId, ''), ";}");
     $pusherParams = null;
     if (isset($pusherParameters)) {
         $pusherParams = $pusherParameters;
     } else {
         if (isset($options['pusher'])) {
             $pusherParams = $options['pusher'];
         }
     }
     if (!is_null($pusherParams)) {
         $appKey = isset($pusherParams['key']) ? $pusherParams['key'] : "_im_key_isnt_supplied";
         $chName = isset($pusherParams['channel']) ? $pusherParams['channel'] : "_im_pusher_default_channel";
         $this->generateAssignJS("INTERMediatorOnPage.clientNotificationKey", "function(){return ", arrayToJS($appKey, ''), ";}");
         $this->generateAssignJS("INTERMediatorOnPage.clientNotificationChannel", "function(){return ", arrayToJS($chName, ''), ";}");
     }
     if (isset($prohibitDebugMode) && $prohibitDebugMode) {
         $this->generateAssignJS("INTERMediator.debugMode", "false");
     } else {
         $this->generateAssignJS("INTERMediator.debugMode", $debug === false ? "false" : $debug);
     }
     // Check Authentication
     $boolValue = "false";
     $requireAuthenticationContext = array();
     if (isset($options['authentication'])) {
         $boolValue = "true";
     }
     foreach ($datasource as $aContext) {
         if (isset($aContext['authentication'])) {
             $boolValue = "true";
             $requireAuthenticationContext[] = $aContext['name'];
         }
     }
     $this->generateAssignJS("INTERMediatorOnPage.requireAuthentication", $boolValue);
     $this->generateAssignJS("INTERMediatorOnPage.authRequiredContext", arrayToJS($requireAuthenticationContext, ''));
     $this->generateAssignJS("INTERMediatorOnPage.isNativeAuth", isset($options['authentication']) && isset($options['authentication']['user']) && $options['authentication']['user'][0] === 'database_native' ? "true" : "false");
     $this->generateAssignJS("INTERMediatorOnPage.authStoring", $q, isset($options['authentication']) && isset($options['authentication']['storing']) ? $options['authentication']['storing'] : 'cookie', $q);
     $this->generateAssignJS("INTERMediatorOnPage.authExpired", isset($options['authentication']) && isset($options['authentication']['authexpired']) ? $options['authentication']['authexpired'] : '3600');
     $this->generateAssignJS("INTERMediatorOnPage.realm", $q, isset($options['authentication']) && isset($options['authentication']['realm']) ? $options['authentication']['realm'] : '', $q);
     if (isset($generatedPrivateKey)) {
         $rsa = new Crypt_RSA();
         $rsa->setPassword($passPhrase);
         $rsa->loadKey($generatedPrivateKey);
         $rsa->setPassword();
         $publickey = $rsa->getPublicKey(CRYPT_RSA_PUBLIC_FORMAT_RAW);
         $this->generateAssignJS("INTERMediatorOnPage.publickey", "new biRSAKeyPair('", $publickey['e']->toHex(), "','0','", $publickey['n']->toHex(), "')");
     }
 }
Esempio n. 11
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");
Esempio n. 12
0
 public function generateInitialJSCode($datasource, $options, $dbspecification, $debug)
 {
     $q = '"';
     $generatedPrivateKey = null;
     $passPhrase = null;
     $browserCompatibility = null;
     $scriptPathPrefix = null;
     $scriptPathSuffix = null;
     $oAuthProvider = null;
     $oAuthClientID = null;
     $oAuthRedirect = null;
     $dbClass = null;
     $params = IMUtil::getFromParamsPHPFile(array("generatedPrivateKey", "passPhrase", "browserCompatibility", "scriptPathPrefix", "scriptPathSuffix", "oAuthProvider", "oAuthClientID", "oAuthRedirect", "passwordPolicy", "documentRootPrefix", "dbClass", "nonSupportMessageId", "valuesForLocalContext"), true);
     $generatedPrivateKey = $params["generatedPrivateKey"];
     $passPhrase = $params["passPhrase"];
     $browserCompatibility = $params["browserCompatibility"];
     $scriptPathPrefix = $params["scriptPathPrefix"];
     $scriptPathSuffix = $params["scriptPathSuffix"];
     $oAuthProvider = $params["oAuthProvider"];
     $oAuthClientID = $params["oAuthClientID"];
     $oAuthRedirect = $params["oAuthRedirect"];
     $passwordPolicy = $params["passwordPolicy"];
     $dbClass = $params["dbClass"];
     $nonSupportMessageId = $params["nonSupportMessageId"];
     $documentRootPrefix = is_null($params["documentRootPrefix"]) ? "" : $params["documentRootPrefix"];
     $valuesForLocalContext = $params["valuesForLocalContext"];
     /*
      * Read the JS programs regarding by the developing or deployed.
      */
     $currentDir = dirname(__FILE__) . DIRECTORY_SEPARATOR;
     if (file_exists($currentDir . 'INTER-Mediator-Lib.js')) {
         echo $this->combineScripts($currentDir);
     } else {
         readfile($currentDir . 'INTER-Mediator.js');
     }
     /*
      * Generate the link to the definition file editor
      */
     $relativeToDefFile = '';
     $editorPath = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'INTER-Mediator-Support';
     $defFilePath = $_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME'];
     while (strpos($defFilePath, $editorPath) !== 0 && strlen($editorPath) > 1) {
         $editorPath = dirname($editorPath);
         $relativeToDefFile .= '..' . DIRECTORY_SEPARATOR;
     }
     $relativeToDefFile .= substr($defFilePath, strlen($editorPath) + 1);
     $editorPath = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'INTER-Mediator-Support' . DIRECTORY_SEPARATOR . 'defedit.html';
     if (file_exists($editorPath)) {
         $relativeToEditor = substr($editorPath, strlen($_SERVER['DOCUMENT_ROOT']));
         $this->generateAssignJS("INTERMediatorOnPage.getEditorPath", "function(){return {$q}{$relativeToEditor}?target={$relativeToDefFile}{$q};}");
     } else {
         $this->generateAssignJS("INTERMediatorOnPage.getEditorPath", "function(){return '';}");
     }
     /*
      * from db-class, determine the default key field string
      */
     $defaultKey = null;
     $dbClassName = 'DB_' . (isset($dbspecification['db-class']) ? $dbspecification['db-class'] : (!is_null($dbClass) ? $dbClass : ''));
     if ($dbClassName !== 'DB_DefEditor' && $dbClassName !== 'DB_PageEditor') {
         require_once "{$dbClassName}.php";
     } else {
         require_once dirname(__FILE__) . "/INTER-Mediator-Support/{$dbClassName}.php";
     }
     if ((double) phpversion() < 5.3) {
         $dbInstance = new $dbClassName();
         if ($dbInstance != null) {
             $defaultKey = $dbInstance->getDefaultKey();
         }
     } else {
         $defaultKey = call_user_func(array($dbClassName, 'defaultKey'));
     }
     if ($defaultKey !== null) {
         $items = array();
         foreach ($datasource as $context) {
             if (!array_key_exists('key', $context)) {
                 $context['key'] = $defaultKey;
             }
             $items[] = $context;
         }
         $datasource = $items;
     }
     /*
      * Determine the uri of myself
      */
     if (isset($callURL)) {
         $pathToMySelf = $callURL;
     } else {
         if (isset($scriptPathPrefix) || isset($scriptPathSuffix)) {
             $pathToMySelf = (isset($scriptPathPrefix) ? $scriptPathPrefix : '') . filter_var($_SERVER['SCRIPT_NAME']) . (isset($scriptPathSufix) ? $scriptPathSuffix : '');
         } else {
             $pathToMySelf = filter_var($_SERVER['SCRIPT_NAME']);
         }
     }
     $pathToIMRootDir = '';
     if (function_exists('mb_ereg_replace')) {
         $pathToIMRootDir = mb_ereg_replace(mb_ereg_replace("\\x5c", "/", "^{$documentRootPrefix}" . filter_var($_SERVER['DOCUMENT_ROOT'])), "", mb_ereg_replace("\\x5c", "/", dirname(__FILE__)));
     }
     $this->generateAssignJS("INTERMediatorOnPage.getEntryPath", "function(){return {$q}{$pathToMySelf}{$q};}");
     $this->generateAssignJS("INTERMediatorOnPage.getIMRootPath", "function(){return {$q}{$pathToIMRootDir}{$q};}");
     $this->generateAssignJS("INTERMediatorOnPage.getDataSources", "function(){return ", arrayToJSExcluding($datasource, '', array('password')), ";}");
     $this->generateAssignJS("INTERMediatorOnPage.getOptionsAliases", "function(){return ", arrayToJS(isset($options['aliases']) ? $options['aliases'] : array(), ''), ";}");
     $this->generateAssignJS("INTERMediatorOnPage.getOptionsTransaction", "function(){return ", arrayToJS(isset($options['transaction']) ? $options['transaction'] : '', ''), ";}");
     $this->generateAssignJS("INTERMediatorOnPage.getDBSpecification", "function(){return ", arrayToJSExcluding($dbspecification, '', array('dsn', 'option', 'database', 'user', 'password', 'server', 'port', 'protocol', 'datatype')), ";}");
     $isEmailAsUsernae = isset($options['authentication']) && isset($options['authentication']['email-as-username']) && $options['authentication']['email-as-username'] === true;
     $this->generateAssignJS("INTERMediatorOnPage.isEmailAsUsername", $isEmailAsUsernae ? "true" : "false");
     $messageClass = IMUtil::getMessageClassInstance();
     $this->generateAssignJS("INTERMediatorOnPage.getMessages", "function(){return ", arrayToJS($messageClass->getMessages(), ''), ";}");
     if (isset($options['browser-compatibility'])) {
         $browserCompatibility = $options['browser-compatibility'];
     }
     foreach ($browserCompatibility as $browser => $browserInfo) {
         if (strtolower($browser) !== $browser) {
             $browserCompatibility[strtolower($browser)] = $browserCompatibility[$browser];
             unset($browserCompatibility[$browser]);
         }
     }
     $this->generateAssignJS("INTERMediatorOnPage.browserCompatibility", "function(){return ", arrayToJS($browserCompatibility, ''), ";}");
     $remoteAddr = filter_var($_SERVER['REMOTE_ADDR']);
     if (is_null($remoteAddr) || $remoteAddr === FALSE) {
         $remoteAddr = '0.0.0.0';
     }
     $clientIdSeed = time() + $remoteAddr + mt_rand();
     $randomSecret = mt_rand();
     $clientId = hash_hmac('sha256', $clientIdSeed, $randomSecret);
     $this->generateAssignJS("INTERMediatorOnPage.clientNotificationIdentifier", "function(){return ", arrayToJS($clientId, ''), ";}");
     if ($nonSupportMessageId != "") {
         $this->generateAssignJS("INTERMediatorOnPage.nonSupportMessageId", "{$q}{$nonSupportMessageId}{$q}");
     }
     $pusherParams = null;
     if (isset($pusherParameters)) {
         $pusherParams = $pusherParameters;
     } else {
         if (isset($options['pusher'])) {
             $pusherParams = $options['pusher'];
         }
     }
     if (!is_null($pusherParams)) {
         $appKey = isset($pusherParams['key']) ? $pusherParams['key'] : "_im_key_isnt_supplied";
         $chName = isset($pusherParams['channel']) ? $pusherParams['channel'] : "_im_pusher_default_channel";
         $this->generateAssignJS("INTERMediatorOnPage.clientNotificationKey", "function(){return ", arrayToJS($appKey, ''), ";}");
         $this->generateAssignJS("INTERMediatorOnPage.clientNotificationChannel", "function(){return ", arrayToJS($chName, ''), ";}");
     }
     $metadata = json_decode(file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . "metadata.json"));
     $this->generateAssignJS("INTERMediatorOnPage.metadata", "{version:{$q}{$metadata->version}{$q},releasedate:{$q}{$metadata->releasedate}{$q}}");
     if (isset($prohibitDebugMode) && $prohibitDebugMode) {
         $this->generateAssignJS("INTERMediator.debugMode", "false");
     } else {
         $this->generateAssignJS("INTERMediator.debugMode", $debug === false ? "false" : $debug);
     }
     // Check Authentication
     $boolValue = "false";
     $requireAuthenticationContext = array();
     if (isset($options['authentication'])) {
         $boolValue = "true";
     }
     foreach ($datasource as $aContext) {
         if (isset($aContext['authentication'])) {
             $boolValue = "true";
             $requireAuthenticationContext[] = $aContext['name'];
         }
     }
     $this->generateAssignJS("INTERMediatorOnPage.requireAuthentication", $boolValue);
     $this->generateAssignJS("INTERMediatorOnPage.authRequiredContext", arrayToJS($requireAuthenticationContext, ''));
     $ldap = new LDAPAuth();
     // for PHP 5.2, 5.3
     $this->generateAssignJS("INTERMediatorOnPage.isLDAP", $ldap->isActive ? "true" : "false");
     $this->generateAssignJS("INTERMediatorOnPage.isOAuthAvailable", isset($oAuthProvider) ? "true" : "false");
     $authObj = new OAuthAuth();
     if ($authObj->isActive) {
         $this->generateAssignJS("INTERMediatorOnPage.oAuthClientID", $q, $oAuthClientID, $q);
         $this->generateAssignJS("INTERMediatorOnPage.oAuthBaseURL", $q, $authObj->oAuthBaseURL(), $q);
         $this->generateAssignJS("INTERMediatorOnPage.oAuthRedirect", $q, $oAuthRedirect, $q);
         $this->generateAssignJS("INTERMediatorOnPage.oAuthScope", $q, implode(' ', $authObj->infoScope()), $q);
     }
     $this->generateAssignJS("INTERMediatorOnPage.isNativeAuth", isset($options['authentication']) && isset($options['authentication']['user']) && $options['authentication']['user'][0] === 'database_native' ? "true" : "false");
     $this->generateAssignJS("INTERMediatorOnPage.authStoring", $q, isset($options['authentication']) && isset($options['authentication']['storing']) ? $options['authentication']['storing'] : 'cookie', $q);
     $this->generateAssignJS("INTERMediatorOnPage.authExpired", isset($options['authentication']) && isset($options['authentication']['authexpired']) ? $options['authentication']['authexpired'] : '3600');
     $this->generateAssignJS("INTERMediatorOnPage.realm", $q, isset($options['authentication']) && isset($options['authentication']['realm']) ? $options['authentication']['realm'] : '', $q);
     if (isset($generatedPrivateKey)) {
         $rsa = new Crypt_RSA();
         $rsa->setPassword($passPhrase);
         $rsa->loadKey($generatedPrivateKey);
         $rsa->setPassword();
         $publickey = $rsa->getPublicKey(CRYPT_RSA_PUBLIC_FORMAT_RAW);
         $this->generateAssignJS("INTERMediatorOnPage.publickey", "new biRSAKeyPair('", $publickey['e']->toHex(), "','0','", $publickey['n']->toHex(), "')");
         if (in_array(sha1($generatedPrivateKey), array('413351603fa756ecd8270147d1a84e9a2de2a3f9', '094f61a9db51e0159fb0bf7d02a321d37f29a715')) && isset($_SERVER['SERVER_ADDR']) && $_SERVER['SERVER_ADDR'] !== '192.168.56.101') {
             $this->generateDebugMessageJS('Please change the value of $generatedPrivateKey in params.php.');
         }
     }
     if (isset($passwordPolicy)) {
         $this->generateAssignJS("INTERMediatorOnPage.passwordPolicy", $q, $passwordPolicy, $q);
     } else {
         if (isset($options["authentication"]) && isset($options["authentication"]["password-policy"])) {
             $this->generateAssignJS("INTERMediatorOnPage.passwordPolicy", $q, $options["authentication"]["password-policy"], $q);
         }
     }
     if (isset($options['credit-including'])) {
         $this->generateAssignJS("INTERMediatorOnPage.creditIncluding", $q, $options['credit-including'], $q);
     }
     // Initial values for local context
     if (!isset($valuesForLocalContext)) {
         $valuesForLocalContext = array();
     }
     if (isset($options['local-context'])) {
         foreach ($options['local-context'] as $item) {
             $valuesForLocalContext[$item['key']] = $item['value'];
         }
     }
     if (isset($valuesForLocalContext) && is_array($valuesForLocalContext) && count($valuesForLocalContext) > 0) {
         $this->generateAssignJS("INTERMediatorOnPage.initLocalContext", arrayToJS($valuesForLocalContext));
     }
 }
Esempio n. 13
0
    public function testSetPrivate()
    {
        $rsa = new Crypt_RSA();
        $key = '-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEA61BjmfXGEvWmegnBGSuS+rU9soUg2FnODva32D1AqhwdziwHINFa
D1MVlcrYG6XRKfkcxnaXGfFDWHLEvNBSEVCgJjtHAGZIm5GL/KA86KDp/CwDFMSw
luowcXwDwoyinmeOY9eKyh6aY72xJh7noLBBq1N0bWi1e2i+83txOCg4yV2oVXhB
o8pYEJ8LT3el6Smxol3C1oFMVdwPgc0vTl25XucMcG/ALE/KNY6pqC2AQ6R2ERlV
gPiUWOPatVkt7+Bs3h5Ramxh7XjBOXeulmCpGSynXNcpZ/06+vofGi/2MlpQZNhH
Ao8eayMp6FcvNucIpUndo1X8dKMv3Y26ZQIDAQAB
-----END RSA PUBLIC KEY-----';
        $this->assertTrue($rsa->loadKey($key));
        $this->assertTrue($rsa->setPrivateKey());
        $this->assertGreaterThanOrEqual(1, strlen("{$rsa}"));
        $this->assertFalse($rsa->getPublicKey());
    }
Esempio n. 14
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
}
Esempio n. 15
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));
    }
Esempio n. 16
0
 /**
  * Get Public Key
  *
  * Wrapper for $this->key->getPublicKey()
  *
  * @param Integer $format optional
  * @return Mixed
  * @access public
  */
 function getPublicKey($format = null)
 {
     return !isset($format) ? $this->key->getPublicKey() : $this->key->getPublicKey($format);
 }
Esempio n. 17
0
 public function exportPublicKey($format = CRYPT_RSA_PUBLIC_FORMAT_PKCS1)
 {
     $this->publicKey->setPublicKey();
     return $this->publicKey->getPublicKey($format);
 }