-
-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add kms test lint fixes * remove unused default key policy constant from KMS create key request * minor cleanup and add first pass at schedule_key_deletion method and mock * fix for schedule_key_deletion test * [kms] convert create_key to options hash instead of positional arguments * fix mock data after options hash change * add KeySpec to create_key mock and expected format in tests * first pass at get_public_key requests and mocks * fix params for create_key in tests so that public_key/signing mocks will match * size for rsa key should be cast to integer * add mocks for ECC pkeys * first pass at kms sign request and mocks * simplify by using sign instead of sign_raw * switch to sign_pss, hopefully compatible with 3.0 * fix ec curve mapping * kms: mocks - cleanup signopts, support both raw and digest signing * starting to flesh out mock tests around signing/verification * further fleshing out/refining tests * add mock table tests for signing * get_public_key KeyId is actually ARN, also delete after sign table test, just in case * add missing keyspec to describe_key parser * add overlooked base64 encode to sign request calls * add a digest test to live+mock key tests as well
- Loading branch information
Showing
12 changed files
with
468 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Fog | ||
module Parsers | ||
module AWS | ||
module KMS | ||
class GetPublicKey < Fog::Parsers::Base | ||
def reset | ||
@response = {} | ||
end | ||
|
||
def start_element(name, attrs = []) | ||
super | ||
case name | ||
when 'EncryptionAlgorithms', 'KeyAgreementAlgorithms', 'SigningAlgorithms' | ||
@response[name] = [] | ||
end | ||
end | ||
|
||
def end_element(name) | ||
case name | ||
when 'KeyId', 'KeySpec', 'KeyUsage', 'PublicKey' | ||
@response[name] = value | ||
when 'EncryptionAlgorithms', 'KeyAgreementAlgorithms', 'SigningAlgorithms' | ||
@response[name] << value | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Fog | ||
module Parsers | ||
module AWS | ||
module KMS | ||
class ScheduleKeyDeletion < Fog::Parsers::Base | ||
def reset | ||
@response = {} | ||
end | ||
|
||
def start_element(name, attrs = []) | ||
super | ||
end | ||
|
||
def end_element(name) | ||
case name | ||
when 'DeletionDate' | ||
@response[name] = Time.parse(value) | ||
when 'KeyId', 'KeyState' | ||
@response[name] = value | ||
when 'PendingWindowInDays' | ||
@response[name] = value.to_i | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Fog | ||
module Parsers | ||
module AWS | ||
module KMS | ||
class Sign < Fog::Parsers::Base | ||
def reset | ||
@response = {} | ||
end | ||
|
||
def start_element(name, attrs = []) | ||
super | ||
end | ||
|
||
def end_element(name) | ||
case name | ||
when 'KeyId', 'Signature', 'SigningAlgorithm' | ||
@response[name] = value | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Fog | ||
module AWS | ||
class KMS | ||
class Real | ||
require 'fog/aws/parsers/kms/get_public_key' | ||
|
||
def get_public_key(identifier, grant_tokens = nil) | ||
request( | ||
'Action' => 'GetPublicKey', | ||
'GrantTokens' => grant_tokens, | ||
'KeyId' => identifier, | ||
:parser => Fog::Parsers::AWS::KMS::GetPublicKey.new | ||
) | ||
end | ||
end | ||
|
||
class Mock | ||
def get_public_key(identifier, _grant_tokens = []) | ||
response = Excon::Response.new | ||
key = self.data[:keys][identifier] | ||
pkey = self.data[:pkeys][identifier] | ||
|
||
response.body = { | ||
'KeyId' => key['Arn'], | ||
'KeyUsage' => key['KeyUsage'], | ||
'KeySpec' => key['KeySpec'], | ||
'PublicKey' => Base64.strict_encode64(pkey.public_to_der), | ||
'SigningAlgorithms' => key['SigningAlgorithms'] | ||
} | ||
response | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Fog | ||
module AWS | ||
class KMS | ||
class Real | ||
require 'fog/aws/parsers/kms/schedule_key_deletion' | ||
|
||
def schedule_key_deletion(identifier, pending_window_in_days) | ||
request( | ||
'Action' => 'ScheduleKeyDeletion', | ||
'KeyId' => identifier, | ||
'PendingWindowInDays' => pending_window_in_days, | ||
:parser => Fog::Parsers::AWS::KMS::ScheduleKeyDeletion.new | ||
) | ||
end | ||
end | ||
|
||
class Mock | ||
def schedule_key_deletion(identifier, pending_window_in_days) | ||
response = Excon::Response.new | ||
key = self.data[:keys][identifier] | ||
|
||
key['DeletionDate'] = Time.now + (60 * 60 * 24 * pending_window_in_days) | ||
key['Enabled'] = false | ||
key['KeyState'] = 'PendingDeletion' | ||
|
||
response.body = { | ||
'DeletionDate' => key['DeletionDate'], | ||
'KeyId' => key['KeyId'], | ||
'KeyState' => key['KeyState'], | ||
'PendingWindowInDays' => pending_window_in_days | ||
} | ||
response | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.