Skip to content

Commit

Permalink
Separate cert generation and issuance test helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
bdewater committed Oct 20, 2019
1 parent e7ed01b commit e7b4b3f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions test/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ def file_path(category, name)

module_function

def issue_cert(dn, key, serial, extensions, issuer, issuer_key,
not_before: nil, not_after: nil, digest: "sha256")
def generate_cert(dn, key, serial, issuer,
not_before: nil, not_after: nil)
cert = OpenSSL::X509::Certificate.new
issuer = cert unless issuer
issuer_key = key unless issuer_key
cert.version = 2
cert.serial = serial
cert.subject = dn
Expand All @@ -73,6 +72,16 @@ def issue_cert(dn, key, serial, extensions, issuer, issuer_key,
now = Time.now
cert.not_before = not_before || now - 3600
cert.not_after = not_after || now + 3600
cert
end


def issue_cert(dn, key, serial, extensions, issuer, issuer_key,
not_before: nil, not_after: nil, digest: "sha256")
cert = generate_cert(dn, key, serial, issuer,
not_before: not_before, not_after: not_after)
issuer = cert unless issuer
issuer_key = key unless issuer_key
ef = OpenSSL::X509::ExtensionFactory.new
ef.subject_certificate = cert
ef.issuer_certificate = issuer
Expand Down

0 comments on commit e7b4b3f

Please sign in to comment.