-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define new interfaces for version 2 #4
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PharIo\GnuPG; | ||
|
||
use PharIo\Executor\Executor; | ||
use PharIo\FileSystem\Directory; | ||
|
||
final class CliWrapper implements GPG | ||
{ | ||
public function __construct(Executor $executor, Directory $home, ?Directory $temp = null) | ||
{ | ||
} | ||
|
||
public function importPublicKey(string $keyData): PublicKey | ||
{ | ||
// TODO: Implement importPublicKey() method. | ||
} | ||
|
||
public function importSecretKey(string $keyData): SecretKey | ||
{ | ||
// TODO: Implement importSecretKey() method. | ||
} | ||
|
||
public function verify(string $message, Signature $signature): KeyInfo | ||
{ | ||
// TODO: Implement verify() method. | ||
} | ||
|
||
public function sign(SecretKey $privateKey, string $message): Signature | ||
{ | ||
// TODO: Implement sign() method. | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PharIo\GnuPG; | ||
|
||
final class FingerPrint | ||
{ | ||
private string $fingerPrint; | ||
|
||
public function getFingerPrint(): string | ||
{ | ||
return $this->fingerPrint; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PharIo\GnuPG; | ||
|
||
interface GPG | ||
{ | ||
/** | ||
* @param string $keyData raw key data | ||
* | ||
* @throws InvalidHomeDirectory | ||
* @throws InvalidKey | ||
*/ | ||
public function importPublicKey(string $keyData): PublicKey; | ||
|
||
/** | ||
* | ||
* @since 2.1 this method can be added later because phive is no just using the verify logic | ||
* @param string $keyData raw key data | ||
* | ||
* @throws InvalidHomeDirectory | ||
* @throws InvalidKey | ||
*/ | ||
public function importSecretKey(string $keyData, ?string $passphrase = null): SecretKey; | ||
|
||
/** | ||
* Verifies the message is signed with the sigature | ||
* | ||
*/ | ||
public function verify(string $message, SignatureData $signature): Signature; | ||
|
||
/** | ||
* Uses the secret to create a signature. | ||
* | ||
* @since 2.1 this method can be added later because phive is no just using the verify logic | ||
* @return Signature | ||
*/ | ||
public function sign(SecretKey $privateKey, string $message): Signature; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure yet what |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PharIo\GnuPG; | ||
|
||
class InvalidHomeDirectory extends Exception | ||
{ | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PharIo\GnuPG; | ||
|
||
class InvalidKey extends Exception | ||
{ | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PharIo\GnuPG; | ||
|
||
final class KeyId | ||
{ | ||
private string $id; | ||
|
||
public function getId(): string | ||
{ | ||
return $this->id; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PharIo\GnuPG; | ||
|
||
|
||
class KeyInfo | ||
{ | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PharIo\GnuPG; | ||
|
||
use PharIo\FileSystem\Directory; | ||
|
||
final class PeclWrapper implements GPG | ||
{ | ||
public function __construct(Directory $home, ?Directory $temp = null) | ||
{ | ||
$this->gpg = new \Gnupg(); | ||
} | ||
|
||
public function importPublicKey(string $keyData): PublicKey | ||
{ | ||
// TODO: Implement importPublicKey() method. | ||
} | ||
|
||
public function importSecretKey(string $keyData): SecretKey | ||
{ | ||
// TODO: Implement importSecretKey() method. | ||
} | ||
|
||
public function verify(string $message, Signature $signature): KeyInfo | ||
{ | ||
// TODO: Implement verify() method. | ||
} | ||
|
||
public function sign(SecretKey $privateKey, string $message): Signature | ||
{ | ||
// TODO: Implement sign() method. | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PharIo\GnuPG; | ||
|
||
class PublicKey | ||
{ | ||
private function __construct(string $id, string $fingerprint, array $uids, string $key, \DateTimeImmutable $created) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should refrain from using scalar types where possible.. |
||
{ | ||
} | ||
|
||
public function getId(): string { | ||
} | ||
|
||
public function getInfo(): string { | ||
} | ||
|
||
public function getKey(): string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably return |
||
|
||
} | ||
|
||
public function getFingerprint(): string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Introduce Value Object for the Fingerprint? |
||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PharIo\GnuPG; | ||
|
||
/** | ||
* @todo define what is needed here. | ||
*/ | ||
class SecretKey | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be renamed to |
||
{ | ||
|
||
|
||
public function getKeyData() {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PharIo\GnuPG; | ||
|
||
class SigatureFileData implements SignatureData | ||
{ | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PharIo\GnuPG; | ||
|
||
final class SigatureFileData implements SignatureData | ||
{ | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PharIo\GnuPG; | ||
|
||
|
||
Class Signature | ||
{ | ||
public function getKeyId(): KeyId | ||
{} | ||
|
||
public function getUserId(): UserId | ||
{} | ||
|
||
public function getSignatureInformation(): ?SignatureInfo | ||
{} | ||
|
||
public function getStatus(): Status | ||
{ | ||
} | ||
|
||
/** | ||
* Will return internal sigature data | ||
* | ||
* This can be stored to a file for example. | ||
*/ | ||
public function getData(): SignatureData { | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PharIo\GnuPG; | ||
|
||
|
||
interface SignatureData | ||
{ | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PharIo\GnuPG; | ||
|
||
Final class SignatureInfo | ||
{ | ||
private FingerPrint $fingerPrint; | ||
|
||
private DateTimeImmutable $createdAt; | ||
|
||
private DateTimeImmutable $expireAt; | ||
|
||
private UserId $userId; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PharIo\GnuPG; | ||
|
||
final class Status | ||
{ | ||
public static Good(): Status; | ||
public static Expired(): Status; | ||
public static KeyExpired(): Status; | ||
public static KeyRevoked(): Status; | ||
public static Bad(): Status; | ||
public static Error(): Status; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PharIo\GnuPG; | ||
|
||
class UserId | ||
{ | ||
private string $name; | ||
private string $email; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PharIo\GnuPG; | ||
|
||
class VerificiationFailed extends Exception | ||
{ | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, we do not have the data needed for constructing
PublicKey
when "only" importing. We'd have to explicitly query the key data afterwards.I'm also not convinced we need to return a
PublicKey
here, as I don't see that key to be commonly used by the caller directly after importing it to the keyring.It would make sense though to return something like a
KeyIdentifier
(containing the fingerprint and providing an additional accessormethod to get the ID - which is a fraction of the fingerprint), so the caller can use the ID to query for the public key if needed.That would save us from an redundant (internal) query.
Returning only the
KeyIdentifier
is also based on the data we get fromgnugp
:What we get from gnupg cli calls on import would be something like this:
According to a comment on the array returned by the
pecl gnupg import
function (probably based on theIMPORT_RES
line above and the fingerprint fromIMPORT_OK
) is:If anything goes wrong, we'll throw exceptions. I'm not sure if the pecl extension provides any usable error information that we could process (There is
gnupg::geterror()
) but i'd envision at least somewhat useful error messages but probably only one rather genericImportFailedException
kind of thing with error code and message as best we get...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally: Do you think it would make sense to wrap the
string
into a value object of some sort? It could verify the content is properly wrapped in the usual-----....
lines and has a useful minimum length to at least have the potential to be a valid key...?Maybe a
PublicKeyData
thing?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are absolutely right... I should have looked better at the output of gpg here.
I think we should return the keyid's that are imported. So the return type would be
An import could contain multiple keyId when the imported file contains multiple keys. There is no difference between import of a private or publickey from a user point of view. But I think when we want to support passphrase protected keys we might want to make a difference. Because the handling would be a bit different. the pecl library doesn't support this so people would need to use the cli wrapper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to disappoint again: If we rely on the pecl extension, it appears that we only get the count of UIDs, not the list of them. Why every someone consider that useful to hide ;)
I'm more and more wondering whether having
ext/gnupg
support is actually worth it ;) But we should at least design the objects so they can work in both...Fine with me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding:
Not happy yet with the signature either ;)
array
as a return type because it allows for all kinds of ugly edge casesstring
withPublicKeyData
? ;-)