-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #285 from creditkudos/feature/add-rsa-pss-support
Add RSASSA-PSS signature signing support
- Loading branch information
Showing
8 changed files
with
150 additions
and
4 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,43 @@ | ||
module JWT | ||
module Algos | ||
module Ps | ||
# RSASSA-PSS signing algorithms | ||
|
||
module_function | ||
|
||
SUPPORTED = %w[PS256 PS384 PS512].freeze | ||
|
||
def sign(to_sign) | ||
require_openssl! | ||
|
||
algorithm, msg, key = to_sign.values | ||
|
||
key_class = key.class | ||
|
||
raise EncodeError, "The given key is a #{key_class}. It has to be an OpenSSL::PKey::RSA instance." if key_class == String | ||
|
||
translated_algorithm = algorithm.sub('PS', 'sha') | ||
|
||
key.sign_pss(translated_algorithm, msg, salt_length: :max, mgf1_hash: translated_algorithm) | ||
end | ||
|
||
def verify(to_verify) | ||
require_openssl! | ||
|
||
SecurityUtils.verify_ps(to_verify.algorithm, to_verify.public_key, to_verify.signing_input, to_verify.signature) | ||
end | ||
|
||
def require_openssl! | ||
if Object.const_defined?('OpenSSL') | ||
major, minor = OpenSSL::VERSION.split('.').first(2) | ||
|
||
unless major.to_i >= 2 && minor.to_i >= 1 | ||
raise JWT::RequiredDependencyError, "You currently have OpenSSL #{OpenSSL::VERSION}. PS support requires >= 2.1" | ||
end | ||
else | ||
raise JWT::RequiredDependencyError, 'PS signing requires OpenSSL +2.1' | ||
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
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