Skip to content

Commit 46c8696

Browse files
rheniumhsbt
authored andcommitted
Drop encipherment key usages from Gem::Security.create_cert defaults
keyEncipherment should be set only when the subject public key is used for key transport, and dataEncipherment only when it is used to directly encrypt user data. RubyGems uses the key for neither purpose. These key usages are also not applicable to non-RSA keys. In preparation for ML-DSA support, remove them from the default settings.
1 parent 303e121 commit 46c8696

2 files changed

Lines changed: 6 additions & 12 deletions

File tree

lib/rubygems/security.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,12 @@ class Exception < Gem::Exception; end
387387
# The default set of extensions are:
388388
#
389389
# * The certificate is not a certificate authority
390-
# * The key for the certificate may be used for key and data encipherment
391-
# and digital signatures
390+
# * The key for the certificate may be used for digital signatures
392391
# * The certificate contains a subject key identifier
393392

394393
EXTENSIONS = {
395394
"basicConstraints" => "CA:FALSE",
396-
"keyUsage" =>
397-
"keyEncipherment,dataEncipherment,digitalSignature",
395+
"keyUsage" => "digitalSignature",
398396
"subjectKeyIdentifier" => "hash",
399397
}.freeze
400398

test/rubygems/test_gem_security.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ def test_class_create_cert
3434
assert_equal "CA:FALSE", constraints.value
3535

3636
key_usage = cert.extensions.find {|ext| ext.oid == "keyUsage" }
37-
assert_equal "Digital Signature, Key Encipherment, Data Encipherment",
38-
key_usage.value
37+
assert_include key_usage.value, "Digital Signature"
3938

4039
key_ident = cert.extensions.find {|ext| ext.oid == "subjectKeyIdentifier" }
4140
assert_equal 59, key_ident.value.length
@@ -80,8 +79,7 @@ def test_class_create_cert_email
8079
assert_equal "CA:FALSE", constraints.value
8180

8281
key_usage = cert.extensions.find {|ext| ext.oid == "keyUsage" }
83-
assert_equal "Digital Signature, Key Encipherment, Data Encipherment",
84-
key_usage.value
82+
assert_include key_usage.value, "Digital Signature"
8583

8684
key_ident = cert.extensions.find {|ext| ext.oid == "subjectKeyIdentifier" }
8785
assert_equal 59, key_ident.value.length
@@ -312,8 +310,7 @@ def test_class_sign_AltName
312310
assert_equal "CA:FALSE", constraints.value
313311

314312
key_usage = signed.extensions.find {|ext| ext.oid == "keyUsage" }
315-
assert_equal "Digital Signature, Key Encipherment, Data Encipherment",
316-
key_usage.value
313+
assert_include key_usage.value, "Digital Signature"
317314

318315
key_ident =
319316
signed.extensions.find {|ext| ext.oid == "subjectKeyIdentifier" }
@@ -490,8 +487,7 @@ def assert_sign(signing_cert, signing_key)
490487
assert_equal "CA:FALSE", constraints.value
491488

492489
key_usage = signed.extensions.find {|ext| ext.oid == "keyUsage" }
493-
assert_equal "Digital Signature, Key Encipherment, Data Encipherment",
494-
key_usage.value
490+
assert_include key_usage.value, "Digital Signature"
495491

496492
key_ident =
497493
signed.extensions.find {|ext| ext.oid == "subjectKeyIdentifier" }

0 commit comments

Comments
 (0)