Skip to content

Commit da736e6

Browse files
committed
Updating extentions in-place does not work with all Ruby implementations.
At least with jruby, the code fail to update the `crlNumber` correctly. While this is arguably a but in jruby, similar issues have been experienced with MRI, e.g.: https://github.com/smortex/puppet-renew-certificate/blob/761d5e768933aae0233e77aeac4aea01d3fd2fa8/exe/puppet-renew-certificate#L125 To avoid this issue, copy the extensions and re-create them one by one.
1 parent 9d39910 commit da736e6

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

lib/puppetserver/ca/action/prune.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,21 @@ def prune_CRL(crl)
136136
end
137137

138138
def update_pruned_CRL(crl, pkey)
139-
number_ext, other_ext = crl.extensions.partition{ |ext| ext.oid == "crlNumber" }
140-
number_ext.each do |crl_number|
141-
updated_crl_number = OpenSSL::BN.new(crl_number.value) + OpenSSL::BN.new(1)
142-
crl_number.value=(OpenSSL::ASN1::Integer(updated_crl_number))
139+
ef = OpenSSL::X509::ExtensionFactory.new
140+
ef.crl = crl
141+
142+
# Updating extensions in-place does not work with some ruby versions / implementation. Copy & recreate them.
143+
extensions = crl.extensions
144+
crl.extensions = []
145+
146+
extensions.each do |ext|
147+
if ext.oid == "crlNumber"
148+
crl.add_extension(ef.create_extension("crlNumber", OpenSSL::ASN1::Integer.new(ext.value.next)))
149+
else
150+
crl.add_extension(ext)
151+
end
143152
end
144-
crl.extensions=(number_ext + other_ext)
153+
145154
crl.sign(pkey, OpenSSL::Digest::SHA256.new)
146155
end
147156

0 commit comments

Comments
 (0)