-
Notifications
You must be signed in to change notification settings - Fork 375
Separated rbnacl hmac implementations #521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
anakinj
merged 1 commit into
jwt:main
from
anakinj:separated-rbnacl-hmac-implementations
Nov 12, 2022
Merged
Separated rbnacl hmac implementations #521
anakinj
merged 1 commit into
jwt:main
from
anakinj:separated-rbnacl-hmac-implementations
Nov 12, 2022
Conversation
This file contains hidden or 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
- HMAC using OpenSSL (default) - HMAC with RbNaCl for keys under 32 chars (rbnacl < 6.0) - HMAC with RbNaCl (rbnacl >= 6.0)
db7a947
to
18888b8
Compare
oskarpearson
added a commit
to BloomAndWild/messagebird-ruby-rest-api
that referenced
this pull request
Jan 29, 2025
- Remove reference to 'secure_compare' method in ruby-jwt that this code shouldn't be using, so as to support ruby-jwt v2.6.0 and above - Add support for ruby-jwt up to and including version 3.* (currently in beta) so that we don't have to bump support again later - Bump development dependencies of rspec, rubocop, and webmock Prior versions of this code depended on the method `JWT::SecurityUtils.secure_compare` Release v2.6.0 of ruby-jwt moved the `JWT::SecurityUtils.secure_compare` method a a different namespace as part of jwt/ruby-jwt#521 While we could simply change this code to instead refer to that new namespace, I believe that the intention of ruby-jwt was that `secure_compare` should not have been used outside of the internals of ruby-jwt. This is supported by the [The ruby-jwt README examples](https://github.com/jwt/ruby-jwt/blob/v3.0.0.beta1/README.md#custom-algorithms) where the ruby-jwt team recommend using `OpenSSL.fixed_length_secure_compare` (instead of `JWT::SecurityUtils.secure_compare`) The code in this change is based on the logic in https://github.com/rails/rails/blob/cf6ff17e9a3c6c1139040b519a341f55f0be16cf/activesupport/lib/active_support/security_utils.rb#L33 so as to avoid adding a dependency on ActiveSupport for this single method. Note that unlike in the code in the above url we don't fall back to a custom implementation of `fixed_length_secure_compare`, since `OpenSSL.fixed_length_secure_compare` [is present in OpenSSL 2.2](https://github.com/ruby/openssl/blob/master/History.md#version-220) This gem already depends on Ruby 3.0 and above, which already [includes that version of OpenSSL](https://stdgems.org/openssl/) Note that the code also doesn't need to handle nil/empty cases, unlike the [original implementation of JWT::SecurityUtils.secure_compare](https://github.com/jwt/ruby-jwt/pull/15/files#diff-2961689829b1ae20b5e8222673335c323355389f753c50b8a5b98380086f63b9R98) because these are already handled in the call to `validate_url` in one case, and `validate_payload` itself.
oskarpearson
added a commit
to BloomAndWild/messagebird-ruby-rest-api
that referenced
this pull request
Jan 29, 2025
… new Ruby vers - Remove reference to 'secure_compare' method in ruby-jwt that this code shouldn't be using, so as to support ruby-jwt v2.6.0 and above - Add support for ruby-jwt up to and including version 3.* (currently in beta) so that we don't have to bump support again later - Bump development dependencies of rspec, rubocop, and webmock - Add recent Ruby versions to the test matrix (I left version 3.0 in place, although it's no longer officially supported so as to avoid inconveniencing existing users that are stuck on version 3.0) Prior versions of this code depended on the method `JWT::SecurityUtils.secure_compare` Release v2.6.0 of ruby-jwt moved the `JWT::SecurityUtils.secure_compare` method to a different namespace as part of jwt/ruby-jwt#521 While we could simply change this code to instead refer to that new namespace, I believe that the intention of ruby-jwt was that `secure_compare` should not have been used outside of the internals of ruby-jwt. This is supported by the [The ruby-jwt README examples](https://github.com/jwt/ruby-jwt/blob/v3.0.0.beta1/README.md#custom-algorithms) where the ruby-jwt team recommend using `OpenSSL.fixed_length_secure_compare` instead of `JWT::SecurityUtils.secure_compare` The code in this change is based on the logic in https://github.com/rails/rails/blob/cf6ff17e9a3c6c1139040b519a341f55f0be16cf/activesupport/lib/active_support/security_utils.rb#L33 so as to avoid adding a dependency on ActiveSupport for this single method. Note that unlike in the code in the above url we don't fall back to a custom implementation of `fixed_length_secure_compare`, since `OpenSSL.fixed_length_secure_compare` [is present in OpenSSL 2.2](https://github.com/ruby/openssl/blob/master/History.md#version-220) and this gem already depends on Ruby 3.0 and above, which already [includes that version of OpenSSL](https://stdgems.org/openssl/) Note that the code also doesn't need to handle nil/empty cases, unlike the [original implementation of JWT::SecurityUtils.secure_compare](https://github.com/jwt/ruby-jwt/pull/15/files#diff-2961689829b1ae20b5e8222673335c323355389f753c50b8a5b98380086f63b9R98) because these are already handled in the call to `validate_url` in one case, and `validate_payload` itself in the other.
oskarpearson
added a commit
to BloomAndWild/messagebird-ruby-rest-api
that referenced
this pull request
Jan 29, 2025
… new Ruby vers - Remove reference to 'secure_compare' method in ruby-jwt that this code shouldn't be using, so as to support ruby-jwt v2.6.0 and above - Add support for ruby-jwt up to and including version 3.* (currently in beta) so that we don't have to bump support again later - Bump development dependencies of rspec, rubocop, and webmock - Add recent Ruby versions to the test matrix (I left version 3.0 in place, although it's no longer officially supported, so as to avoid inconveniencing existing users that are stuck on version 3.0) Prior versions of this code depended on the method `JWT::SecurityUtils.secure_compare` Release v2.6.0 of ruby-jwt moved the `JWT::SecurityUtils.secure_compare` method to a different namespace as part of jwt/ruby-jwt#521 While we could simply change this code to instead refer to that new namespace, I believe that the intention of ruby-jwt was that `secure_compare` should not have been used outside of the internals of ruby-jwt. This is supported by the [The ruby-jwt README examples](https://github.com/jwt/ruby-jwt/blob/v3.0.0.beta1/README.md#custom-algorithms) where the ruby-jwt team recommend using `OpenSSL.fixed_length_secure_compare` instead of `JWT::SecurityUtils.secure_compare` The code in this change is based on the logic in https://github.com/rails/rails/blob/cf6ff17e9a3c6c1139040b519a341f55f0be16cf/activesupport/lib/active_support/security_utils.rb#L33 so as to avoid adding a dependency on ActiveSupport for this single method. Unlike the code in the above url we don't fall back to a custom implementation of `fixed_length_secure_compare`, since `OpenSSL.fixed_length_secure_compare` [is present in OpenSSL 2.2](https://github.com/ruby/openssl/blob/master/History.md#version-220) and this gem already depends on Ruby 3.0 and above, which already [includes that version of OpenSSL](https://stdgems.org/openssl/) This code also doesn't need to handle nil/empty cases, unlike the [original implementation of JWT::SecurityUtils.secure_compare](https://github.com/jwt/ruby-jwt/pull/15/files#diff-2961689829b1ae20b5e8222673335c323355389f753c50b8a5b98380086f63b9R98) because these are already handled in the call to `validate_url` in one case, and `validate_payload` itself in the other.
oskarpearson
added a commit
to BloomAndWild/messagebird-ruby-rest-api
that referenced
this pull request
Jan 29, 2025
… Ruby vers - Remove reference to 'secure_compare' method in ruby-jwt that this code shouldn't be using, so as to support ruby-jwt v2.6.0 and above - Add support for ruby-jwt up to and including version 3.* (currently in beta) so that we don't have to bump support again later - Bump development dependencies of rspec, rubocop, and webmock - Add recent Ruby versions to the test matrix (I left version 3.0 in place, although it's no longer officially supported, so as to avoid inconveniencing existing users that are stuck on version 3.0) Prior versions of this code depended on the method `JWT::SecurityUtils.secure_compare` Release v2.6.0 of ruby-jwt moved the `JWT::SecurityUtils.secure_compare` method to a different namespace as part of jwt/ruby-jwt#521 While we could simply change this code to instead refer to that new namespace, I believe that the intention of ruby-jwt was that `secure_compare` should not have been used outside of the internals of ruby-jwt. This is supported by the [The ruby-jwt README examples](https://github.com/jwt/ruby-jwt/blob/v3.0.0.beta1/README.md#custom-algorithms) where the ruby-jwt team recommend using `OpenSSL.fixed_length_secure_compare` instead of `JWT::SecurityUtils.secure_compare` The code in this change is based on the logic in https://github.com/rails/rails/blob/cf6ff17e9a3c6c1139040b519a341f55f0be16cf/activesupport/lib/active_support/security_utils.rb#L33 so as to avoid adding a dependency on ActiveSupport for this single method. Unlike the code in the above url we don't fall back to a custom implementation of `fixed_length_secure_compare`, since `OpenSSL.fixed_length_secure_compare` [is present in OpenSSL 2.2](https://github.com/ruby/openssl/blob/master/History.md#version-220) and this gem already depends on Ruby 3.0 and above, which already [includes that version of OpenSSL](https://stdgems.org/openssl/) This code also doesn't need to handle nil/empty cases, unlike the [original implementation of JWT::SecurityUtils.secure_compare](https://github.com/jwt/ruby-jwt/pull/15/files#diff-2961689829b1ae20b5e8222673335c323355389f753c50b8a5b98380086f63b9R98) because these are already handled in the call to `validate_url` in one case, and `validate_payload` itself in the other.
oskarpearson
added a commit
to BloomAndWild/messagebird-ruby-rest-api
that referenced
this pull request
Jan 29, 2025
… Ruby vers - Remove reference to 'secure_compare' method in ruby-jwt that this code shouldn't be using, so as to support ruby-jwt v2.6.0 and above - Add support for ruby-jwt up to and including version 3.* (currently in beta) so that we don't have to bump support again later - Bump development dependencies of rspec, rubocop, and webmock - Add recent Ruby versions to the test matrix (I left version 3.0 in place, although it's no longer officially supported, so as to avoid inconveniencing existing users that are stuck on version 3.0) Prior versions of this code depended on the method `JWT::SecurityUtils.secure_compare` Release v2.6.0 of ruby-jwt moved the `JWT::SecurityUtils.secure_compare` method to a different namespace as part of jwt/ruby-jwt#521 While we could simply change this code to instead refer to that new namespace, I believe that the intention of ruby-jwt was that `secure_compare` should not have been used outside of the internals of ruby-jwt. This is supported by the [The ruby-jwt README examples](https://github.com/jwt/ruby-jwt/blob/v3.0.0.beta1/README.md#custom-algorithms) where the ruby-jwt team recommend using `OpenSSL.fixed_length_secure_compare` instead of `JWT::SecurityUtils.secure_compare` The code in this change is based on the logic in https://github.com/rails/rails/blob/cf6ff17e9a3c6c1139040b519a341f55f0be16cf/activesupport/lib/active_support/security_utils.rb#L33 so as to avoid adding a dependency on ActiveSupport for this single method. Unlike the code in the activesupport url above we don't fall back to a custom implementation of `fixed_length_secure_compare`, since `OpenSSL.fixed_length_secure_compare` [is present in OpenSSL 2.2](https://github.com/ruby/openssl/blob/master/History.md#version-220) and this gem already depends on Ruby 3.0 and above, which already [includes that version of OpenSSL](https://stdgems.org/openssl/) This code also doesn't need to handle nil/empty cases, unlike the [original implementation of JWT::SecurityUtils.secure_compare](https://github.com/jwt/ruby-jwt/pull/15/files#diff-2961689829b1ae20b5e8222673335c323355389f753c50b8a5b98380086f63b9R98) because these are already handled in the call to `validate_url` in one case, and `validate_payload` itself in the other.
oskarpearson
added a commit
to BloomAndWild/messagebird-ruby-rest-api
that referenced
this pull request
Jan 29, 2025
… Ruby vers - Remove reference to 'secure_compare' method in ruby-jwt that this code shouldn't be using, so as to support ruby-jwt v2.6.0 and above - Add support for ruby-jwt up to and including version 3.* (currently in beta) so that we don't have to bump support again later - Add recent Ruby versions to the test matrix (I left version 3.0 in place, although it's no longer officially supported, so as to avoid inconveniencing existing users that are stuck on version 3.0) Prior versions of this code depended on the method `JWT::SecurityUtils.secure_compare` Release v2.6.0 of ruby-jwt moved the `JWT::SecurityUtils.secure_compare` method to a different namespace as part of jwt/ruby-jwt#521 While we could simply change this code to instead refer to that new namespace, I believe that the intention of ruby-jwt was that `secure_compare` should not have been used outside of the internals of ruby-jwt. This is supported by the [The ruby-jwt README examples](https://github.com/jwt/ruby-jwt/blob/v3.0.0.beta1/README.md#custom-algorithms) where the ruby-jwt team recommend using `OpenSSL.fixed_length_secure_compare` instead of `JWT::SecurityUtils.secure_compare` The code in this change is based on the logic in https://github.com/rails/rails/blob/cf6ff17e9a3c6c1139040b519a341f55f0be16cf/activesupport/lib/active_support/security_utils.rb#L33 so as to avoid adding a dependency on ActiveSupport for this single method. Unlike the code in the activesupport url above we don't fall back to a custom implementation of `fixed_length_secure_compare`, since `OpenSSL.fixed_length_secure_compare` [is present in OpenSSL 2.2](https://github.com/ruby/openssl/blob/master/History.md#version-220) and this gem already depends on Ruby 3.0 and above, which already [includes that version of OpenSSL](https://stdgems.org/openssl/) This code also doesn't need to handle nil/empty cases, unlike the [original implementation of JWT::SecurityUtils.secure_compare](https://github.com/jwt/ruby-jwt/pull/15/files#diff-2961689829b1ae20b5e8222673335c323355389f753c50b8a5b98380086f63b9R98) because these are already handled in the call to `validate_url` in one case, and `validate_payload` itself in the other.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This moves the RbNaCl specific logic from the default (OpenSSL) HMAC algorithm into dedicated classes.
Why multiple? Well, in the process of extracting the logic I noticed RbNaCl is not having the key limit of 32 chars anymore, so there is now two variants for the RbNaCl implementation for backwards compatibility with pre 6.0 RbNACl versions.
Support for
'rbnacl', '< 6.0'
with the fixed key length of 32 chars could be dropped in ruby-jwt 3.0.