Example #1
0
 public function extractKeyAndUser(Request $request)
 {
     $apiKey = $request->header('Authorization');
     if (!$apiKey) {
         throw new InvalidAuthException('No Authorization header provided.');
     }
     if (strpos($apiKey, 'Basic ') === 0) {
         $apiKey = substr($apiKey, 5, strlen($apiKey));
     }
     $parts = explode(':', $apiKey);
     if (sizeof($parts) != 2) {
         throw new InvalidAuthException('Invalid Authorization header provided. It has to be user:code');
     }
     $user = User::where('email', trim($parts[0]))->first();
     if ($user) {
         try {
             $key = new PrivateKey($user->rsaKey->private);
             $pass = Crypt::decrypt(trim($parts[1]));
             $key->unlock($pass);
             return ['user' => $user, 'key' => $key];
         } catch (\Exception $e) {
             throw new InvalidAuthException($e->getMessage());
         }
     }
     return null;
 }
Example #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $key = new PrivateKey($this->fs->get($this->argument('keyPath')));
     $key->unlock(md5($this->ask('What is the master key secret?')));
     $entry = Entry::where('id', $this->argument('id'))->first();
     $masterShare = $entry->keyShares()->whereNull('user_id')->firstOrFail();
     $this->output->writeln("Password:");
     $this->output->writeln($this->sealer->unseal($entry->data, $masterShare->public, $key));
 }
Example #3
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $user = User::where('email', $this->argument('email'))->first();
     $key = new PrivateKey($this->fs->get($this->argument('keyPath')));
     $key->unlock(md5($this->ask('What is the master key secret?')));
     $entries = KeyShare::where('user_id', $user->id)->with('entry')->get();
     foreach ($entries as $share) {
         $masterShare = $share->entry->keyShares()->whereNull('user_id')->firstOrFail();
         $data = $this->sealer->unseal($share->entry->data, $masterShare->public, $key);
         $this->crypt->encrypt($data, $share->entry);
     }
 }