Skip to content

Commit badf3af

Browse files
authored
Add KmsClient::getPublicKey and KmsClient::verify (#1825)
* Add KMS getPublicKey and verify * Fixed issued and adds tests * Fixed cs * Add changelog and fixed GetPublicKeyResponse * Fixed psalm issues * Fixed phpdoc * suppress conflicting pipeline checks * fixed psalm and changelog * fixed branch-alias
1 parent 908f674 commit badf3af

16 files changed

+1241
-2
lines changed

manifest.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,10 @@
383383
"Decrypt",
384384
"Encrypt",
385385
"GenerateDataKey",
386+
"GetPublicKey",
386387
"ListAliases",
387-
"Sign"
388+
"Sign",
389+
"Verify"
388390
]
389391
},
390392
"Lambda": {

psalm.baseline.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,16 @@
320320
<code><![CDATA[list<ChallengeNameType::*>]]></code>
321321
</MoreSpecificReturnType>
322322
</file>
323+
<file src="src/Service/Kms/src/Result/GetPublicKeyResponse.php">
324+
<LessSpecificReturnStatement>
325+
<code><![CDATA[$items]]></code>
326+
<code><![CDATA[$items]]></code>
327+
<code><![CDATA[$items]]></code>
328+
</LessSpecificReturnStatement>
329+
<MoreSpecificReturnType>
330+
<code><![CDATA[list<EncryptionAlgorithmSpec::*>]]></code>
331+
<code><![CDATA[list<KeyAgreementAlgorithmSpec::*>]]></code>
332+
<code><![CDATA[list<SigningAlgorithmSpec::*>]]></code>
333+
</MoreSpecificReturnType>
334+
</file>
323335
</files>

src/Service/Kms/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## NOT RELEASED
44

5+
### Added
6+
7+
- Added getPublicKey and verify operation
8+
59
## 1.6.0
610

711
### Added

src/Service/Kms/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"extra": {
3030
"branch-alias": {
31-
"dev-master": "1.6-dev"
31+
"dev-master": "1.7-dev"
3232
}
3333
}
3434
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace AsyncAws\Kms\Exception;
4+
5+
use AsyncAws\Core\Exception\Http\ClientException;
6+
7+
/**
8+
* The request was rejected because the signature verification failed. Signature verification fails when it cannot
9+
* confirm that signature was produced by signing the specified message with the specified KMS key and signing
10+
* algorithm.
11+
*/
12+
final class KMSInvalidSignatureException extends ClientException
13+
{
14+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
3+
namespace AsyncAws\Kms\Input;
4+
5+
use AsyncAws\Core\Exception\InvalidArgument;
6+
use AsyncAws\Core\Input;
7+
use AsyncAws\Core\Request;
8+
use AsyncAws\Core\Stream\StreamFactory;
9+
10+
final class GetPublicKeyRequest extends Input
11+
{
12+
/**
13+
* Identifies the asymmetric KMS key that includes the public key.
14+
*
15+
* To specify a KMS key, use its key ID, key ARN, alias name, or alias ARN. When using an alias name, prefix it with
16+
* `"alias/"`. To specify a KMS key in a different Amazon Web Services account, you must use the key ARN or alias ARN.
17+
*
18+
* For example:
19+
*
20+
* - Key ID: `1234abcd-12ab-34cd-56ef-1234567890ab`
21+
* - Key ARN: `arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab`
22+
* - Alias name: `alias/ExampleAlias`
23+
* - Alias ARN: `arn:aws:kms:us-east-2:111122223333:alias/ExampleAlias`
24+
*
25+
* To get the key ID and key ARN for a KMS key, use ListKeys or DescribeKey. To get the alias name and alias ARN, use
26+
* ListAliases.
27+
*
28+
* @required
29+
*
30+
* @var string|null
31+
*/
32+
private $keyId;
33+
34+
/**
35+
* A list of grant tokens.
36+
*
37+
* Use a grant token when your permission to call this operation comes from a new grant that has not yet achieved
38+
* *eventual consistency*. For more information, see Grant token [^1] and Using a grant token [^2] in the *Key
39+
* Management Service Developer Guide*.
40+
*
41+
* [^1]: https://docs.aws.amazon.com/kms/latest/developerguide/grants.html#grant_token
42+
* [^2]: https://docs.aws.amazon.com/kms/latest/developerguide/grant-manage.html#using-grant-token
43+
*
44+
* @var string[]|null
45+
*/
46+
private $grantTokens;
47+
48+
/**
49+
* @param array{
50+
* KeyId?: string,
51+
* GrantTokens?: null|string[],
52+
* '@region'?: string|null,
53+
* } $input
54+
*/
55+
public function __construct(array $input = [])
56+
{
57+
$this->keyId = $input['KeyId'] ?? null;
58+
$this->grantTokens = $input['GrantTokens'] ?? null;
59+
parent::__construct($input);
60+
}
61+
62+
/**
63+
* @param array{
64+
* KeyId?: string,
65+
* GrantTokens?: null|string[],
66+
* '@region'?: string|null,
67+
* }|GetPublicKeyRequest $input
68+
*/
69+
public static function create($input): self
70+
{
71+
return $input instanceof self ? $input : new self($input);
72+
}
73+
74+
/**
75+
* @return string[]
76+
*/
77+
public function getGrantTokens(): array
78+
{
79+
return $this->grantTokens ?? [];
80+
}
81+
82+
public function getKeyId(): ?string
83+
{
84+
return $this->keyId;
85+
}
86+
87+
/**
88+
* @internal
89+
*/
90+
public function request(): Request
91+
{
92+
// Prepare headers
93+
$headers = [
94+
'Content-Type' => 'application/x-amz-json-1.1',
95+
'X-Amz-Target' => 'TrentService.GetPublicKey',
96+
'Accept' => 'application/json',
97+
];
98+
99+
// Prepare query
100+
$query = [];
101+
102+
// Prepare URI
103+
$uriString = '/';
104+
105+
// Prepare Body
106+
$bodyPayload = $this->requestBody();
107+
$body = empty($bodyPayload) ? '{}' : json_encode($bodyPayload, 4194304);
108+
109+
// Return the Request
110+
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body));
111+
}
112+
113+
/**
114+
* @param string[] $value
115+
*/
116+
public function setGrantTokens(array $value): self
117+
{
118+
$this->grantTokens = $value;
119+
120+
return $this;
121+
}
122+
123+
public function setKeyId(?string $value): self
124+
{
125+
$this->keyId = $value;
126+
127+
return $this;
128+
}
129+
130+
private function requestBody(): array
131+
{
132+
$payload = [];
133+
if (null === $v = $this->keyId) {
134+
throw new InvalidArgument(\sprintf('Missing parameter "KeyId" for "%s". The value cannot be null.', __CLASS__));
135+
}
136+
$payload['KeyId'] = $v;
137+
if (null !== $v = $this->grantTokens) {
138+
$index = -1;
139+
$payload['GrantTokens'] = [];
140+
foreach ($v as $listValue) {
141+
++$index;
142+
$payload['GrantTokens'][$index] = $listValue;
143+
}
144+
}
145+
146+
return $payload;
147+
}
148+
}

0 commit comments

Comments
 (0)