diff --git a/src/ncc/Managers/CredentialManager.php b/src/ncc/Managers/CredentialManager.php index cfe6c3d..606b8c5 100644 --- a/src/ncc/Managers/CredentialManager.php +++ b/src/ncc/Managers/CredentialManager.php @@ -47,6 +47,9 @@ { unset($e); } + + if($this->Vault == null) + $this->Vault = new Vault(); } /** @@ -81,7 +84,7 @@ * @throws RuntimeException * @throws FileNotFoundException */ - public function loadVault(): void + private function loadVault(): void { if($this->Vault !== null) return; @@ -127,4 +130,12 @@ { return $this->CredentialsPath; } + + /** + * @return Vault|null + */ + public function getVault(): ?Vault + { + return $this->Vault; + } } \ No newline at end of file diff --git a/src/ncc/Objects/Vault.php b/src/ncc/Objects/Vault.php index c8440e3..9f95e41 100644 --- a/src/ncc/Objects/Vault.php +++ b/src/ncc/Objects/Vault.php @@ -131,7 +131,7 @@ if($entry->getPassword() === null) { - if($entry->isEncrypted() && !$entry->isIsCurrentlyDecrypted()) + if($entry->isEncrypted() && !$entry->isCurrentlyDecrypted()) { return $entry->unlock($password); } @@ -162,16 +162,7 @@ $entries = []; foreach($this->Entries as $entry) { - $entry_array = $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; + $entries[] = $entry->toArray($bytecode);; } return [ diff --git a/src/ncc/Objects/Vault/Entry.php b/src/ncc/Objects/Vault/Entry.php index e85df14..0925c41 100644 --- a/src/ncc/Objects/Vault/Entry.php +++ b/src/ncc/Objects/Vault/Entry.php @@ -87,12 +87,12 @@ return false; if($username == null) - return $password == $this->Password->Password; + return $password == $this->Password->getPassword(); 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: if(!($this->Password instanceof AccessToken)) @@ -124,7 +124,7 @@ * @return bool * @noinspection PhpUnused */ - public function isIsCurrentlyDecrypted(): bool + public function isCurrentlyDecrypted(): bool { return $this->IsCurrentlyDecrypted; } @@ -222,12 +222,16 @@ */ public function toArray(bool $bytecode=false): array { - if(!$this->Password) + if($this->Password !== null) { if($this->Encrypted && $this->IsCurrentlyDecrypted) { $password = $this->encrypt(); } + elseif($this->Encrypted) + { + $password = $this->Password; + } else { $password = $this->Password->toArray(true); @@ -268,7 +272,8 @@ } 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::AccessToken => AccessToken::fromArray($password) }; diff --git a/src/ncc/Objects/Vault/Password/AccessToken.php b/src/ncc/Objects/Vault/Password/AccessToken.php index ec00407..84420b6 100644 --- a/src/ncc/Objects/Vault/Password/AccessToken.php +++ b/src/ncc/Objects/Vault/Password/AccessToken.php @@ -71,4 +71,12 @@ { return $this->AccessToken; } + + /** + * @param string $AccessToken + */ + public function setAccessToken(string $AccessToken): void + { + $this->AccessToken = $AccessToken; + } } \ No newline at end of file diff --git a/src/ncc/Objects/Vault/Password/UsernamePassword.php b/src/ncc/Objects/Vault/Password/UsernamePassword.php index 25097a6..ca9c883 100644 --- a/src/ncc/Objects/Vault/Password/UsernamePassword.php +++ b/src/ncc/Objects/Vault/Password/UsernamePassword.php @@ -15,14 +15,14 @@ * * @var string */ - public $Username; + private $Username; /** * The entry's password * * @var string */ - public $Password; + private $Password; /** * Returns an array representation of the object @@ -90,4 +90,20 @@ { 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; + } } \ No newline at end of file