Пример #1
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);
     }
 }
Пример #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param EntryCrypt $entryCrypt
  * @return Response
  */
 public function store(EntryCrypt $entryCrypt)
 {
     $userId = Input::get('user_id');
     $entryId = Input::get('id');
     $validator = Validator::make(['user_id' => $userId, 'entry_id' => $entryId], Share::$rules);
     if ($validator->fails()) {
         return Response::make($validator->messages()->first(), 419);
     }
     if (KeyShare::where('user_id', $userId)->where('entry_id', $entryId)->count() > 0) {
         return Response::make('User can already access this key.', 419);
     }
     $entry = Entry::findOrFail($entryId);
     $model = new Share();
     $model->user_by_id = Auth::user()->id;
     $model->user_id = $userId;
     $model->entry_id = $entryId;
     DB::transaction(function () use($model, $entryCrypt, $entry) {
         if (!$model->save()) {
             return Response::json(['flash' => 'Unauthorized.'], 403);
         }
         $entryCrypt->reencrypt($entry);
     });
     return Share::with('user')->where('id', $model->id)->first();
 }