/** * Execute the console command. * * @return mixed */ public function handle() { foreach (User::all() as $user) { if (!$user->rsaKey) { throw new \RuntimeException('user ' . $user->email . ' has no RSA key. Create it using key:generate:users'); } } if (!$this->filesystem->exists(config('app.backup_key'))) { $this->warn('Backup key does not exist. We recommend that you create one using key:generate:master'); } $entries = Entry::all(); foreach ($entries as $entry) { $list = $this->accessDecider->getUserListForEntry($entry); if ($list->count() == 0) { throw new \RuntimeException('Entry #' . $entry->id . ' has no access. Share it.'); } } foreach ($entries as $entry) { if ($entry->password != '') { continue; } echo $entry->id . '... '; $this->entryCrypt->encrypt($entry->password, $entry); echo ' encrypted!' . "\n"; } }
/** * 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); } }
/** * Update the specified resource in storage. * * @param Entry $model * @param Request $request * @param EntryCrypt $entryCrypt * @return Response */ public function update(Entry $model, Request $request, EntryCrypt $entryCrypt) { if (!$model->can_edit) { abort(403); } $model->name = $request->get('name'); $model->username = $request->get('username'); $model->url = $request->get('url'); $model->note = $request->get('note'); if (!is_null($request->get('password', null))) { $model->password = $request->get('password'); } DB::transaction(function () use($model, $entryCrypt, $request) { $model->save(); if (!is_null($request->get('password', null))) { $entryCrypt->encrypt($request->get('password'), $model); } $model->load('tags'); }); return $model; }