aws-sdk-cloudfront 1.154.0 → 1.155.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 954fa182dffe203eea931bf9910d6648ffb3a539694fc89ae1d09d1440964965
4
- data.tar.gz: fef6f98963a4de65fe744d812ac30ed45091d9b41cb1c4abfdb1956b3b03cd78
3
+ metadata.gz: 545f6bfeb8d3e33647c6d81747ada8268a025e092d3fb5ba3ec2ad7cb7ad4270
4
+ data.tar.gz: 8a324be000901cd6e71880a49ea30e89c4c4c8431e0ff7578cd28da4e2da4ba4
5
5
  SHA512:
6
- metadata.gz: 9ea4f808206542ea0c10945ee3fd56205ff1b3333c9265c1096bba34ed9e5b620b5029f73fa2122b8422bf1ffedf849615d3ed1006e3a9e82f72c90907bdd131
7
- data.tar.gz: cb37d3b7ce1f67044044a014636e39964562cebef3a2ff33427c7d62a51f41779de15c3123ebc88686a76721d2707566ce7b96bfa3fa81c961e8482ecaf67886
6
+ metadata.gz: 530f9271542b77f5d66ac0258b940ebfedbc714942286b7721b9cc0cd136f72d6c69ed0245619bdb8d4ca628aeb6d00842175ce083a056daa569c49f5f2107ea
7
+ data.tar.gz: 05ef8a82a99cd8ec4080fd37a537590be62b2d128f0c939c6c22da513427fb5d0be05e8e3a7325d06e4bbde30a64cf0ca56b8d3a36aa35e1c5fc013424b38565
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  Unreleased Changes
2
2
  ------------------
3
3
 
4
+ 1.155.0 (2026-09-23)
5
+ ------------------
6
+
7
+ * Feature - CloudFront signers now support SHA-256 signatures via the `:hash_algorithm` option (`'SHA1'` or `'SHA256'`, defaults to `'SHA1'`). Signers also validate that the private key is RSA or ECDSA (P-256), and custom policies are now minified before signing.
8
+
4
9
  1.154.0 (2026-09-11)
5
10
  ------------------
6
11
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.154.0
1
+ 1.155.0
@@ -13815,7 +13815,7 @@ module Aws::CloudFront
13815
13815
  tracer: tracer
13816
13816
  )
13817
13817
  context[:gem_name] = 'aws-sdk-cloudfront'
13818
- context[:gem_version] = '1.154.0'
13818
+ context[:gem_version] = '1.155.0'
13819
13819
  Seahorse::Client::Request.new(handlers, context)
13820
13820
  end
13821
13821
 
@@ -12,12 +12,20 @@ module Aws
12
12
  #
13
13
  # signer = Aws::CloudFront::CookieSigner.new(
14
14
  # key_pair_id: "cf-keypair-id",
15
- # private_key_path: "./unit_test_dummy_key"
15
+ # private_key_path: "./private_key.pem"
16
16
  # )
17
17
  # cookies = signer.signed_cookie(url,
18
18
  # policy: policy.to_json
19
19
  # )
20
20
  #
21
+ # Pass `hash_algorithm: 'SHA256'` to sign with SHA-256 instead of SHA-1:
22
+ #
23
+ # signer = Aws::CloudFront::CookieSigner.new(
24
+ # key_pair_id: "cf-keypair-id",
25
+ # private_key_path: "./private_key.pem",
26
+ # hash_algorithm: "SHA256"
27
+ # )
28
+ #
21
29
  class CookieSigner
22
30
  include Signer
23
31
 
@@ -8,13 +8,18 @@ require 'openssl'
8
8
  module Aws
9
9
  module CloudFront
10
10
  module Signer
11
+ # @api private
12
+ SUPPORTED_HASH_ALGORITHMS = %w[SHA1 SHA256].freeze
13
+
11
14
  # @option options [String] :key_pair_id
12
15
  # @option options [String] :private_key
13
16
  # @option options [String] :private_key_path
17
+ # @option options [String] :hash_algorithm ('SHA1') 'SHA1' or 'SHA256'
14
18
  def initialize(options = {})
15
19
  @key_pair_id = key_pair_id(options)
16
- @cipher = OpenSSL::Digest.new('SHA1')
17
- @private_key = OpenSSL::PKey.read(private_key(options))
20
+ @hash_algorithm = hash_algorithm(options)
21
+ @cipher = OpenSSL::Digest.new(@hash_algorithm)
22
+ @private_key = load_private_key(private_key(options))
18
23
  end
19
24
 
20
25
  private
@@ -78,7 +83,7 @@ module Aws
78
83
  def signature(params = {})
79
84
  signature_content = {}
80
85
  if params[:policy]
81
- policy = params[:policy].gsub('/\s/s', '')
86
+ policy = params[:policy].gsub(/\s/, '')
82
87
  signature_content['Policy'] = encode(policy)
83
88
  elsif params[:resource] && params[:expires]
84
89
  policy = canned_policy(params[:resource], params[:expires])
@@ -90,12 +95,18 @@ module Aws
90
95
 
91
96
  signature_content['Signature'] = encode(sign_policy(policy))
92
97
  signature_content['Key-Pair-Id'] = @key_pair_id
98
+ # omitted for SHA1 to keep existing signed URLs and cookies unchanged
99
+ signature_content['Hash-Algorithm'] = @hash_algorithm if @hash_algorithm == 'SHA256'
93
100
  signature_content
94
101
  end
95
102
 
96
103
  # create the signature string with policy signed
97
104
  def sign_policy(policy)
98
105
  @private_key.sign(@cipher, policy)
106
+ rescue OpenSSL::PKey::PKeyError => e
107
+ msg = "failed to sign with #{@hash_algorithm}: #{e.message}"
108
+ msg += ", consider `hash_algorithm: 'SHA256'`" if @hash_algorithm == 'SHA1'
109
+ raise ArgumentError, msg
99
110
  end
100
111
 
101
112
  # create canned policy that used for signing
@@ -121,6 +132,16 @@ module Aws
121
132
  options[:key_pair_id]
122
133
  end
123
134
 
135
+ def hash_algorithm(options)
136
+ algorithm = (options[:hash_algorithm] || 'SHA1').to_s.upcase
137
+ unless SUPPORTED_HASH_ALGORITHMS.include?(algorithm)
138
+ msg = ":hash_algorithm must be one of #{SUPPORTED_HASH_ALGORITHMS.join(', ')}"
139
+ raise ArgumentError, msg
140
+ end
141
+
142
+ algorithm
143
+ end
144
+
124
145
  def private_key(options)
125
146
  if options[:private_key]
126
147
  options[:private_key]
@@ -131,6 +152,23 @@ module Aws
131
152
  raise ArgumentError, msg
132
153
  end
133
154
  end
155
+
156
+ def load_private_key(pem)
157
+ key = OpenSSL::PKey.read(pem)
158
+ case key
159
+ when OpenSSL::PKey::RSA
160
+ key
161
+ when OpenSSL::PKey::EC
162
+ curve = key.group.curve_name
163
+ raise ArgumentError, "unsupported ECDSA curve `#{curve}', must be prime256v1" unless curve == 'prime256v1'
164
+
165
+ key
166
+ else
167
+ raise ArgumentError, "unsupported private key type #{key.class}, must be RSA or ECDSA"
168
+ end
169
+ rescue OpenSSL::PKey::PKeyError
170
+ raise ArgumentError, 'invalid private key, must be a PEM-encoded RSA or ECDSA private key'
171
+ end
134
172
  end
135
173
  end
136
174
  end
@@ -12,12 +12,20 @@ module Aws
12
12
  #
13
13
  # signer = Aws::CloudFront::UrlSigner.new(
14
14
  # key_pair_id: "cf-keypair-id",
15
- # private_key_path: "./unit_test_dummy_key"
15
+ # private_key_path: "./private_key.pem"
16
16
  # )
17
17
  # url = signer.signed_url(url,
18
18
  # policy: policy.to_json
19
19
  # )
20
20
  #
21
+ # Pass `hash_algorithm: 'SHA256'` to sign with SHA-256 instead of SHA-1:
22
+ #
23
+ # signer = Aws::CloudFront::UrlSigner.new(
24
+ # key_pair_id: "cf-keypair-id",
25
+ # private_key_path: "./private_key.pem",
26
+ # hash_algorithm: "SHA256"
27
+ # )
28
+ #
21
29
  class UrlSigner
22
30
  include Signer
23
31
 
@@ -55,7 +55,7 @@ module Aws::CloudFront
55
55
  autoload :EndpointProvider, 'aws-sdk-cloudfront/endpoint_provider'
56
56
  autoload :Endpoints, 'aws-sdk-cloudfront/endpoints'
57
57
 
58
- GEM_VERSION = '1.154.0'
58
+ GEM_VERSION = '1.155.0'
59
59
 
60
60
  end
61
61
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-sdk-cloudfront
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.154.0
4
+ version: 1.155.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amazon Web Services