jwt-aws-kms 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 914aa0d86548b288e664ca6ec1fc307d9ed6314906d88a53724ea8f66a50de3f
4
+ data.tar.gz: 3194829083c71babcf27d4a7a9faa8c7461af0e8e4eec75a49450051c934b0fe
5
+ SHA512:
6
+ metadata.gz: 3a883fdf468c545b4d40ff7df480ec31dd18bb13b418a241d31cd85614fc73330a6f9d27c28d4335d4448eb1b8ef12e3c68e4b007f90c6fdadf721e5b6fc7d17
7
+ data.tar.gz: ca891f35bf16367d8aec94e021db54c684aeea578eebe31458feb81a90831caad1f11efb4077889fc4ce4c8f228b55c8b0b4808b8fc5a83992f32e1ccf09e70f
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "0.6.0"
3
+ }
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,22 @@
1
+ require:
2
+ - rubocop-rspec
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 3.0
6
+ NewCops: enable
7
+ SuggestExtensions: false
8
+
9
+ Style/StringLiterals:
10
+ EnforcedStyle: double_quotes
11
+
12
+ Style/StringLiteralsInInterpolation:
13
+ EnforcedStyle: double_quotes
14
+
15
+ Naming/FileName:
16
+ Exclude:
17
+ - lib/jwt-aws-kms.rb
18
+
19
+ Metrics/BlockLength:
20
+ Exclude:
21
+ - spec/**/*_spec.rb
22
+ - '*.gemspec'
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## [0.2.0](https://github.com/anakinj/jwt-kms/compare/v0.1.0...v0.2.0) (2024-09-20)
4
+
5
+
6
+ ### Features
7
+
8
+ * Support all HMAC algos ([eb09bd3](https://github.com/anakinj/jwt-kms/commit/eb09bd3a7ba6cc932ce8c96dffa696d04d36e59a))
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # JWT::KMS
2
+
3
+ AWS KMS algorithm extensions for ruby-jwt.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'jwt-aws-kms'
11
+ ```
12
+
13
+ And require the gem in your code.
14
+
15
+ ```ruby
16
+ require `jwt-aws-kms`
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+
23
+ # Create a key, for example with the ruby AWS SDK
24
+ key = Aws::KMS::Client.new.create_key(key_spec: "HMAC_512", key_usage: "GENERATE_VERIFY_MAC")
25
+
26
+ algo = ::JWT::Aws::KMS.for(algorithm: "HS512")
27
+
28
+ token = JWT.encode(payload, key.key_metadata.key_id, algo)
29
+ decoded_token = JWT.decode(token, key.key_metadata.key_id, true, algorithm: algo)
30
+ ```
31
+
32
+ ## Development
33
+
34
+ [Localstack](https://www.localstack.cloud/) can be used to simulate the AWS KMS environment.
35
+
36
+ ```
37
+ docker run \
38
+ --rm -it \
39
+ -p 127.0.0.1:4566:4566 \
40
+ -p 127.0.0.1:4510-4559:4510-4559 \
41
+ -v /var/run/docker.sock:/var/run/docker.sock \
42
+ localstack/localstack
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/anakinj/jwt-aws-kms. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/anakinj/jwt-aws-kms/blob/main/CODE_OF_CONDUCT.md).
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
52
+
53
+ ## Code of Conduct
54
+
55
+ Everyone interacting in the Jwt::Kms project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/anakinj/jwt-aws-kms/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JWT
4
+ module Aws
5
+ module KMS
6
+ # Represent a AWS HMAC key
7
+ # https://docs.aws.amazon.com/kms/latest/developerguide/hmac.html
8
+ class HmacKey
9
+ include JWT::JWA::SigningAlgorithm
10
+
11
+ MAPPINGS = {
12
+ "HS256" => "HMAC_SHA_256",
13
+ "HS384" => "HMAC_SHA_384",
14
+ "HS512" => "HMAC_SHA_512"
15
+ }.freeze
16
+
17
+ def initialize(algorithm:)
18
+ @alg = algorithm
19
+ end
20
+
21
+ def sign(data:, signing_key:, **)
22
+ KMS.client.generate_mac(key_id: signing_key, mac_algorithm: mac_algorithm, message: data).mac
23
+ end
24
+
25
+ def verify(data:, verification_key:, signature:, **)
26
+ KMS.client.verify_mac(key_id: verification_key, mac_algorithm: mac_algorithm, message: data,
27
+ mac: signature).mac_valid
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :key_id
33
+
34
+ def mac_algorithm
35
+ MAPPINGS.fetch(alg, nil)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JWT
4
+ module Aws
5
+ module KMS
6
+ # Represent a AWS asymmetric key
7
+ # https://docs.aws.amazon.com/kms/latest/developerguide/symmetric-asymmetric.html
8
+ class SignVerifyKey
9
+ include JWT::JWA::SigningAlgorithm
10
+
11
+ MAPPINGS = {
12
+ "RS256" => "RSASSA_PKCS1_V1_5_SHA_256",
13
+ "RS384" => "RSASSA_PKCS1_V1_5_SHA_384",
14
+ "RS512" => "RSASSA_PKCS1_V1_5_SHA_512",
15
+ "PS256" => "RSASSA_PSS_SHA_256",
16
+ "PS384" => "RSASSA_PSS_SHA_384",
17
+ "PS512" => "RSASSA_PSS_SHA_512",
18
+ "ES256" => "ECDSA_SHA_256",
19
+ "ES384" => "ECDSA_SHA_384",
20
+ "ES512" => "ECDSA_SHA_512"
21
+ }.freeze
22
+
23
+ def initialize(algorithm:)
24
+ @alg = algorithm
25
+ end
26
+
27
+ def sign(data:, signing_key:, **)
28
+ KMS.client.sign(key_id: signing_key, signing_algorithm: signing_algorithm,
29
+ message: data).signature
30
+ end
31
+
32
+ def verify(data:, verification_key:, signature:, **)
33
+ KMS.client.verify(key_id: verification_key, signing_algorithm: signing_algorithm,
34
+ message: data, signature: signature).signature_valid
35
+ end
36
+
37
+ private
38
+
39
+ attr_reader :key_id
40
+
41
+ def signing_algorithm
42
+ MAPPINGS.fetch(alg, nil)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JWT
4
+ module Aws
5
+ module KMS
6
+ VERSION = "0.6.0"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "aws-sdk-kms"
4
+ require "jwt"
5
+
6
+ require_relative "kms/version"
7
+ require_relative "kms/hmac_key"
8
+ require_relative "kms/sign_verify_key"
9
+
10
+ module JWT
11
+ # :nodoc:
12
+ module Aws
13
+ # :nodoc:
14
+ module KMS
15
+ def self.client
16
+ @client ||= ::Aws::KMS::Client.new
17
+ end
18
+
19
+ def self.for(algorithm:)
20
+ if HmacKey::MAPPINGS.key?(algorithm)
21
+ HmacKey
22
+ elsif SignVerifyKey::MAPPINGS.key?(algorithm)
23
+ SignVerifyKey
24
+ else
25
+ raise ArgumentError, "Algorithm #{algorithm} not supported"
26
+ end.new(algorithm: algorithm)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "jwt/aws/kms"
@@ -0,0 +1,9 @@
1
+ {
2
+ "release-type": "ruby",
3
+ "include-v-in-tag": true,
4
+ "packages": {
5
+ ".": {
6
+ "version-file": "lib/jwt/aws/kms/version.rb"
7
+ }
8
+ }
9
+ }
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jwt-aws-kms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - Joakim Antman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-09-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-kms
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jwt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '2.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '2.9'
41
+ description: Utilize AWS KMS to handle the signing and verification of JWT tokens
42
+ email:
43
+ - antman@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".release-please-manifest.json"
49
+ - ".rspec"
50
+ - ".rubocop.yml"
51
+ - CHANGELOG.md
52
+ - CODE_OF_CONDUCT.md
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - lib/jwt-aws-kms.rb
57
+ - lib/jwt/aws/kms.rb
58
+ - lib/jwt/aws/kms/hmac_key.rb
59
+ - lib/jwt/aws/kms/sign_verify_key.rb
60
+ - lib/jwt/aws/kms/version.rb
61
+ - release-please-config.json
62
+ homepage: https://github.com/anakinj/jwt-aws-kms
63
+ licenses:
64
+ - MIT
65
+ metadata:
66
+ allowed_push_host: https://rubygems.org
67
+ homepage_uri: https://github.com/anakinj/jwt-aws-kms
68
+ source_code_uri: https://github.com/anakinj/jwt-aws-kms
69
+ changelog_uri: https://github.com/anakinj/jwt-aws-kms/blob/v0.6.0/CHANGELOG.md
70
+ rubygems_mfa_required: 'true'
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 3.0.0
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.5.16
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: AWS KMS algorithm extension for ruby-jwt
90
+ test_files: []