Example #1
0
 /**
  * Check configuration and load public key
  */
 public function boot(Application $app)
 {
     switch (true) {
         case ($key = "auth.force_guest") && !isset($app[$key]):
         case ($key = "auth.cookie_expiration") && !isset($app[$key]):
             throw new \Exception("\$app['{$key}']: invalid key");
             break;
     }
     $this->app = $app;
     if ($this->rsa === null) {
         switch (true) {
             case ($key = "auth.authenticator_url") && (!isset($app[$key]) || !\trim($app[$key])):
             case ($key = "auth.public_key.tmp_path") && (!isset($app[$key]) || !\trim($app[$key])):
                 throw new \Exception("\$app['{$key}']: invalid key");
                 break;
         }
         $app["auth.authenticator_url"] = \trim($app["auth.authenticator_url"], "/");
         $file = $app["auth.public_key.tmp_path"];
         if (!file_exists($file) || filemtime($file) < strtotime("-30seconds")) {
             $key = file_get_contents("{$app["auth.authenticator_url"]}/public.key");
             file_put_contents($file, $key);
         }
         $this->rsa = RSA::loadPublicKey("file://" . $file);
     }
 }
 /**
  * @BeforeSuite
  */
 public static function setUpRsa()
 {
     $public_key = getcwd() . "/tmp/public-" . getenv("APPLICATION_ENV") . ".key";
     if (true === file_exists($public_key)) {
         unlink($public_key);
     }
     passthru("[ -d tmp/keys ] || mkdir -p tmp/keys", $return);
     if (0 !== $return) {
         throw new \Exception("Error with RSA : l." . (__LINE__ - 2));
     }
     passthru("[ -f tmp/keys/private.key ] || openssl genrsa  -out tmp/keys/private.key 2048", $return);
     if (0 !== $return) {
         throw new \Exception("Error with RSA : l." . (__LINE__ - 2));
     }
     passthru("[ -f tmp/keys/public.key ]  || openssl rsa -in tmp/keys/private.key -pubout -out tmp/keys/public.key", $return);
     if (0 !== $return) {
         throw new \Exception("Error with RSA : l." . (__LINE__ - 4));
     }
     self::$rsa = \ETNA\RSA\RSA::loadPrivateKey("file://" . realpath(getcwd() . "/tmp/keys/private.key"));
 }