@@ -31,7 +31,7 @@ def authorize(*identifiers)
3131 end
3232
3333 def post_issue_hooks ( name )
34- cert = storage . get_certificate ( name )
34+ cert = load_certificate_from_storage ( name )
3535 execute_post_issue_hooks ( cert )
3636 end
3737
@@ -125,7 +125,8 @@ def save(name, version: 'current', **kwargs)
125125 def autorenew ( days : 30 , remaining_life : nil , names : nil )
126126 ( names || storage . list_certificates ) . each do |cn |
127127 puts "=> #{ cn } "
128- cert = storage . get_certificate ( cn )
128+ cert = load_certificate_from_storage ( cn )
129+
129130 not_after = cert . certificate . not_after . utc
130131
131132 lifetime = cert . certificate . not_after . utc - cert . certificate . not_before . utc
@@ -139,14 +140,14 @@ def autorenew(days: 30, remaining_life: nil, names: nil)
139140 puts " Not valid after: #{ not_after } (lifetime=#{ format_duration ( lifetime +1 ) } , remaining=#{ format_duration ( remaining ) } , #{ "%0.2f" % ( ratio . to_f *100 ) } %)"
140141 next unless has_to_renew
141142
142- puts " * Renewing: CN= #{ cert . name } , SANs=#{ cert . sans . join ( ',' ) } "
143+ puts " * Renewing: #{ cert . name . inspect } , SANs=#{ cert . sans . join ( ',' ) } "
143144 order_with_private_key ( cert . name , *cert . sans , private_key : regenerate_private_key ( cert . public_key ) )
144145 end
145146 end
146147
147148 def add_san ( name , *add_sans )
148- puts "=> reissuing CN= #{ name } with new SANs #{ add_sans . join ( ?,) } "
149- cert = storage . get_certificate ( name )
149+ puts "=> reissuing #{ name . inspect } with new SANs #{ add_sans . join ( ?,) } "
150+ cert = load_certificate_from_storage ( name )
150151 sans = cert . sans + add_sans
151152 puts " * SANs will be: #{ sans . join ( ?,) } "
152153 order_with_private_key ( cert . name , *sans , private_key : regenerate_private_key ( cert . public_key ) )
@@ -212,10 +213,11 @@ def account_key_passphrase
212213 end
213214 end
214215
215- def order_with_private_key ( *identifiers , private_key :, not_before : nil , not_after : nil )
216+ def order_with_private_key ( name , *identifiers , private_key :, not_before : nil , not_after : nil )
216217 order = OrderingService . new (
217218 acme : acme ,
218- identifiers : identifiers ,
219+ common_name : name ,
220+ identifiers : [ name , *identifiers ] ,
219221 private_key : private_key ,
220222 challenge_responder_rules : config . challenge_responders ,
221223 chain_preferences : config . chain_preferences ,
@@ -258,5 +260,12 @@ def regenerate_private_key(template)
258260 raise ArgumentError , "Unknown key type: #{ template . class } "
259261 end
260262 end
263+
264+ # Load certificate from storage, inherit name property to loaded certificate to ensure stability of #name during renewal.
265+ def load_certificate_from_storage ( name )
266+ retval = storage . get_certificate ( name )
267+ retval . name = name
268+ retval
269+ end
261270 end
262271end
0 commit comments