-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
127 additions
and
74 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
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,2 @@ | ||
module Epics::SignatureAlgorithm | ||
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,42 @@ | ||
class Epics::SignatureAlgorithm::Rsa < Epics::SignatureAlgorithm::Base | ||
HASH_ALGORITHM = 'SHA256' | ||
|
||
def initialize(encoded_key, passphrase = nil) | ||
if encoded_key.kind_of?(OpenSSL::PKey::RSA) | ||
self.key = encoded_key | ||
else | ||
self.key = OpenSSL::PKey::RSA.new(encoded_key) | ||
end | ||
end | ||
|
||
def n | ||
self.key.n.to_s(16) | ||
end | ||
|
||
def e | ||
self.key.e.to_s(16) | ||
end | ||
|
||
def sign(msg) | ||
key.sign( | ||
hash_algorithm, | ||
msg | ||
) | ||
end | ||
|
||
def verify(signature, msg) | ||
key.verify( | ||
hash_algorithm, | ||
Base64.decode64(signature), | ||
msg | ||
) | ||
end | ||
|
||
def hash_algorithm | ||
HASH_ALGORITHM | ||
end | ||
|
||
def digester | ||
@digester ||= OpenSSL::Digest::SHA256.new | ||
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,2 @@ | ||
class Epics::SignatureAlgorithm::RsaPkcs1 < Epics::SignatureAlgorithm::Rsa | ||
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 @@ | ||
class Epics::SignatureAlgorithm::RsaPss < Epics::SignatureAlgorithm::Rsa | ||
def sign(msg) | ||
key.sign_pss( | ||
hash_algorithm, | ||
msg, | ||
salt_length: :digest, | ||
mgf1_hash: mgf1_hash_algorithm, | ||
) | ||
end | ||
|
||
def verify(signature, msg) | ||
key.verify_pss( | ||
hash_algorithm, | ||
Base64.decode64(signature), | ||
msg, | ||
salt_length: :digest, | ||
mgf1_hash: mgf1_hash_algorithm, | ||
) | ||
end | ||
|
||
def mgf1_hash_algorithm | ||
HASH_ALGORITHM | ||
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
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