public function saveAction() { $secret = new Secrets(); $text = $this->request->getPost('text'); $secret->content = $this->crypt->encrypt($text); if ($secret->save()) { $this->flash->success('Secret was successfully created!'); } }
/** * Get public key * * Gets the public key for the issuer. If our own identity provider is the issuer, we * can load our own public key avoiding network traffic. * * @access public * @static * @param string $issuer The issuers domain * @return AbstractPublicKey */ public static function getPublicKey($issuer) { // allow other retrievers for testing if ($issuer === Configuration::getInstance()->get("hostname")) { return Secrets::loadPublicKey(); } /*else if (config.get('disable_primary_support')) { throw new \Exception("this verifier doesn't respect certs issued from domains other than: " . Configuration::getInstance()->get("hostname")); }*/ // let's go fetch the public key for this host return Primary::getPublicKey($issuer); }
/** * Gets an instance of the public key of the identity provider * * @param optional string $name The basename of the certificate or null for default * @param optional string $dir The directory to the certificate or null for default * @return AbstractPublicKey The public key */ static function loadPublicKey($name = null, $dir = null) { $parsedCert = Secrets::readAndParseCert($name, $dir); if (!$parsedCert) { return null; } $pkString = $parsedCert["public-key"] ? $parsedCert["public-key"] : $parsedCert["publicKey"]; return AbstractPublicKey::deserialize(json_encode($pkString)); }
/** * Initialization routine * * @access public * @static */ public static function initialize() { if (Primary::$initialized) { return; } // Support "shimmed primaries" for local development. That is an environment variable that is any number of // CSV values of the form: // <domain>|<origin>|<path to .well-known/browserid>, // where 'domain' is the domain that we would like to shim. 'origin' is the origin to which traffic should // be directed, and 'path to .well-known/browserid' is a path to the browserid file for the domain // foreach(Configuration::getInstance()->get("shimmed_primaries") as $primary) //{ Primary::$well_know_path = Utils::path_concat(Configuration::getInstance()->get('base_path'), Configuration::getInstance()->get("shimmed_path")); if (is_file(Utils::path_concat(Primary::$well_know_path, 'persona.org'))) { //load sample file Primary::updateShimCache('login.persona.org', file_get_contents(Utils::path_concat(Primary::$well_know_path, 'persona.org'))); } /*$dom=array( 'login.persona.org'=> array( 'origin'=>'https://login.persona.org', //'delegate'=>'persona.org', 'PublicKeyFile'=>'1') );*/ //file_put_contents(Primary::$indexFile,json_encode($dom)); //list($domain, $origin, $path) = explode("|", $primary); //logger.info("inserted primary info for '" + domain + "' into cache, TODO point at '" + origin + "'"); //} Primary::$public_key = Secrets::loadPublicKey(); Primary::$initialized = true; }
<?php // Comment the following line out to test the script! die; error_reporting(0); require_once "../lib/browserid.php"; $name = $_REQUEST["name"]; $keysize = (int) $_REQUEST["keysize"]; echo "Usage: createKeys.php?name=<name>&keysize=<keysize>\r\n"; echo "Allowed keysizes: 64, 128, 256!\r\n"; // Generate keypair: echo "Generate key pair with keysize {$keysize}...\r\n"; $pair = RSAKeyPair::generate($keysize); echo "Keys were generated!\r\n"; // Write secret key to file: echo "Write Secret Key...\r\n"; $pathSecretKey = Secrets::getPathSecretKey($name); $handle = fopen($pathSecretKey, "w+"); fwrite($handle, $pair->getSecretKey()->serialize()); fclose($handle); echo "Secret Key was written to " . $pathSecretKey . "\r\n"; // Write public key to file: echo "Write Public Key...\r\n"; $pathPublicKey = Secrets::getPathPublicKey($name); $public = array("public-key" => json_decode($pair->getPublicKey()->serialize(), true)); $token = new WebToken($public); $handle = fopen($pathPublicKey, "w+"); fwrite($handle, $token->serialize($pair->getSecretKey())); fclose($handle); echo "Public Key was written to " . $pathPublicKey . "\r\n"; ?> </pre>
* * This program requires a PHP OAuth2 library, which is included in this branch and can be * found here: * http://oauth.googlecode.com/svn/code/php/ * * Sample usage of the program: * `php sample.php --term="bars" --location="San Francisco, CA"` */ // Enter the path that the oauth library is in relation to the php file require_once 'lib/OAuth.php'; require_once '/home/sean/projects/common/orm.php'; require_once '/home/sean/projects/common/utils.php'; // Set your OAuth credentials here // These credentials can be obtained from the 'Manage API Access' page in the // developers documentation (http://www.yelp.com/developers) $secrets = new Secrets(); $CONSUMER_KEY = $secrets->get('yelp', 'consumer_key'); $CONSUMER_SECRET = $secrets->get('yelp', 'consumer_secret'); $TOKEN = $secrets->get('yelp', 'token'); $TOKEN_SECRET = $secrets->get('yelp', 'token_secret'); $API_HOST = 'api.yelp.com'; $DEFAULT_TERM = 'dinner'; $DEFAULT_LOCATION = 'San Francisco, CA'; $SEARCH_LIMIT = 3; $SEARCH_PATH = '/v2/search/'; $BUSINESS_PATH = '/v2/business/'; /** * Makes a request to the Yelp API and returns the response * * @param $host The domain host of the API * @param $path The path of the APi after the domain
/** * Create identity certificate * * Create an identity certificate that is signed by this identity providers key * * @access public * @static * @param string $principal The mail address of the person to identify * @param AbstractPublicKey $publicKeyIdentity The public key of the person * @param int $now Unix Timestamp in milliseconds or null for now * @param string $issuer Issuer domain of the identity provider or null for the configured hostname * @return string The serialized signed identity certificate */ public static function createIdentityCert($principal, $publicKeyIdentity, $now = null, $issuer = null) { if ($now == null) { $now = time() * 1000; } if ($issuer == null) { $issuer = Configuration::getInstance()->get('hostname'); } $expires = $now + Configuration::getInstance()->get('identity_validity') * 1000; $certAssertion = new Assertion($now, $expires, $issuer, null); $certParams = new CertParams($publicKeyIdentity, array("email" => $principal)); $cert = new Cert($certAssertion, $certParams, null); return $cert->sign(Secrets::loadSecretKey()); }