Refactored Vault & CredentialManager to support encryption and indexing.
https://git.n64.cc/nosial/ncc/-/issues/27
This commit is contained in:
parent
273d4b6612
commit
e53bc97e4a
5 changed files with 51 additions and 20 deletions
|
@ -47,6 +47,9 @@
|
||||||
{
|
{
|
||||||
unset($e);
|
unset($e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->Vault == null)
|
||||||
|
$this->Vault = new Vault();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,7 +84,7 @@
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
* @throws FileNotFoundException
|
* @throws FileNotFoundException
|
||||||
*/
|
*/
|
||||||
public function loadVault(): void
|
private function loadVault(): void
|
||||||
{
|
{
|
||||||
if($this->Vault !== null)
|
if($this->Vault !== null)
|
||||||
return;
|
return;
|
||||||
|
@ -127,4 +130,12 @@
|
||||||
{
|
{
|
||||||
return $this->CredentialsPath;
|
return $this->CredentialsPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Vault|null
|
||||||
|
*/
|
||||||
|
public function getVault(): ?Vault
|
||||||
|
{
|
||||||
|
return $this->Vault;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -131,7 +131,7 @@
|
||||||
|
|
||||||
if($entry->getPassword() === null)
|
if($entry->getPassword() === null)
|
||||||
{
|
{
|
||||||
if($entry->isEncrypted() && !$entry->isIsCurrentlyDecrypted())
|
if($entry->isEncrypted() && !$entry->isCurrentlyDecrypted())
|
||||||
{
|
{
|
||||||
return $entry->unlock($password);
|
return $entry->unlock($password);
|
||||||
}
|
}
|
||||||
|
@ -162,16 +162,7 @@
|
||||||
$entries = [];
|
$entries = [];
|
||||||
foreach($this->Entries as $entry)
|
foreach($this->Entries as $entry)
|
||||||
{
|
{
|
||||||
$entry_array = $entry->toArray($bytecode);
|
$entries[] = $entry->toArray($bytecode);;
|
||||||
|
|
||||||
if($entry->getPassword() !== null && $entry->isEncrypted())
|
|
||||||
{
|
|
||||||
$entry_array['password'] = Crypto::encryptWithPassword(
|
|
||||||
ZiProto::encode($entry_array['password']), $entry->getPassword()->__toString(), $bytecode
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$entries[] = $entry_array;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -87,12 +87,12 @@
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if($username == null)
|
if($username == null)
|
||||||
return $password == $this->Password->Password;
|
return $password == $this->Password->getPassword();
|
||||||
|
|
||||||
if($password == null)
|
if($password == null)
|
||||||
return $username == $this->Password->Username;
|
return $username == $this->Password->getUsername();
|
||||||
|
|
||||||
return $username == $this->Password->Username && $password == $this->Password->Password;
|
return $username == $this->Password->getUsername() && $password == $this->Password->getPassword();
|
||||||
|
|
||||||
case AuthenticationType::AccessToken:
|
case AuthenticationType::AccessToken:
|
||||||
if(!($this->Password instanceof AccessToken))
|
if(!($this->Password instanceof AccessToken))
|
||||||
|
@ -124,7 +124,7 @@
|
||||||
* @return bool
|
* @return bool
|
||||||
* @noinspection PhpUnused
|
* @noinspection PhpUnused
|
||||||
*/
|
*/
|
||||||
public function isIsCurrentlyDecrypted(): bool
|
public function isCurrentlyDecrypted(): bool
|
||||||
{
|
{
|
||||||
return $this->IsCurrentlyDecrypted;
|
return $this->IsCurrentlyDecrypted;
|
||||||
}
|
}
|
||||||
|
@ -222,12 +222,16 @@
|
||||||
*/
|
*/
|
||||||
public function toArray(bool $bytecode=false): array
|
public function toArray(bool $bytecode=false): array
|
||||||
{
|
{
|
||||||
if(!$this->Password)
|
if($this->Password !== null)
|
||||||
{
|
{
|
||||||
if($this->Encrypted && $this->IsCurrentlyDecrypted)
|
if($this->Encrypted && $this->IsCurrentlyDecrypted)
|
||||||
{
|
{
|
||||||
$password = $this->encrypt();
|
$password = $this->encrypt();
|
||||||
}
|
}
|
||||||
|
elseif($this->Encrypted)
|
||||||
|
{
|
||||||
|
$password = $this->Password;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$password = $this->Password->toArray(true);
|
$password = $this->Password->toArray(true);
|
||||||
|
@ -268,7 +272,8 @@
|
||||||
}
|
}
|
||||||
elseif(gettype($password) == 'array')
|
elseif(gettype($password) == 'array')
|
||||||
{
|
{
|
||||||
$self->Password = match (Functions::array_bc($data, 'authentication_type')) {
|
$self->Password = match (Functions::array_bc($data, 'authentication_type'))
|
||||||
|
{
|
||||||
AuthenticationType::UsernamePassword => UsernamePassword::fromArray($password),
|
AuthenticationType::UsernamePassword => UsernamePassword::fromArray($password),
|
||||||
AuthenticationType::AccessToken => AccessToken::fromArray($password)
|
AuthenticationType::AccessToken => AccessToken::fromArray($password)
|
||||||
};
|
};
|
||||||
|
|
|
@ -71,4 +71,12 @@
|
||||||
{
|
{
|
||||||
return $this->AccessToken;
|
return $this->AccessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $AccessToken
|
||||||
|
*/
|
||||||
|
public function setAccessToken(string $AccessToken): void
|
||||||
|
{
|
||||||
|
$this->AccessToken = $AccessToken;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -15,14 +15,14 @@
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $Username;
|
private $Username;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The entry's password
|
* The entry's password
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $Password;
|
private $Password;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array representation of the object
|
* Returns an array representation of the object
|
||||||
|
@ -90,4 +90,20 @@
|
||||||
{
|
{
|
||||||
return $this->Password;
|
return $this->Password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $Username
|
||||||
|
*/
|
||||||
|
public function setUsername(string $Username): void
|
||||||
|
{
|
||||||
|
$this->Username = $Username;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $Password
|
||||||
|
*/
|
||||||
|
public function setPassword(string $Password): void
|
||||||
|
{
|
||||||
|
$this->Password = $Password;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue