-
-
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.
first pass at kms sign request and mocks
- Loading branch information
Showing
6 changed files
with
101 additions
and
14 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
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,54 @@ | ||
module Fog | ||
module AWS | ||
class KMS | ||
class Real | ||
require 'fog/aws/parsers/kms/sign' | ||
|
||
# Sign | ||
# | ||
# ==== Parameters | ||
# | ||
# === Returns | ||
# | ||
# ==== See Also | ||
# https://docs.aws.amazon.com/kms/latest/APIReference/API_Sign.html | ||
def sign(identifier, message, algorithm, options = {}) | ||
request({ | ||
'Action' => 'Sign', | ||
'KeyId' => identifier, | ||
'Message' => message, | ||
'SigningAlgorithm' => algorithm, | ||
:parser => Fog::Parsers::AWS::KMS::Sign.new | ||
}.merge!(options)) | ||
end | ||
end | ||
|
||
class Mock | ||
def sign(identifier, message, algorithm, _options = {}) | ||
response = Excon::Response.new | ||
pkey = self.data[:pkeys][identifier] | ||
unless pkey | ||
response.status = 404 | ||
raise(Excon::Errors.status_error({ expects: 200 }, response)) | ||
end | ||
|
||
# FIXME: SM2 support? | ||
sha = "SHA#{algorithm.split('_SHA_').last}" | ||
hash = OpenSSL::Digest.digest(sha, message) | ||
|
||
signopts = {} | ||
signopts[:rsa_padding_mode] = 'pss' if algorithm.start_with?('RSASSA_PSS') | ||
|
||
signature = pkey.sign_raw(sha, hash, signopts) | ||
|
||
response.body = { | ||
'KeyId' => identifier, | ||
'Signature' => Base64.strict_encode64(signature), | ||
'SigningAlgorithm' => algorithm | ||
} | ||
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