Skip to content

Commit

Permalink
Check all certificates in bundle for sha1 signed certificate
Browse files Browse the repository at this point in the history
Refs c9e090a

Signed-off-by: Eric D. Helms <[email protected]>
  • Loading branch information
ehelms authored and ekohl committed Dec 16, 2024
1 parent 042de38 commit be2304c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 25 deletions.
33 changes: 26 additions & 7 deletions definitions/checks/check_sha1_certificate_authority.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,33 @@ def run

return unless server_ca

certificate = OpenSSL::X509::Certificate.new(File.read(server_ca))
begin
certificates = load_fullchain(server_ca)
rescue OpenSSL::X509::CertificateError
assert(false, "Error reading server CA certificate #{server_ca}.")
else
msg = <<~MSG
Server CA certificate #{server_ca} signed with sha1 which will break on upgrade.
Update the server CA certificate with one signed with sha256 or
stronger then proceed with the upgrade.
MSG

msg = <<~MSG
Server CA certificate signed with sha1 which will break on upgrade.
Update the server CA certificate with one signed with sha256 or
stronger then proceed with the upgrade.
MSG
assert(
certificates.all? { |cert| cert.signature_algorithm != 'sha1WithRSAEncryption' },
msg
)
end
end

assert(certificate.signature_algorithm != 'sha1WithRSAEncryption', msg)
def load_fullchain(bundle_pem)
if OpenSSL::X509::Certificate.respond_to?(:load_file)
OpenSSL::X509::Certificate.load_file(bundle_pem)
else
# Can be removed when only Ruby with load_file support is supported
File.binread(bundle_pem).
lines.
slice_after(/END CERTIFICATE/).
map { |pem| OpenSSL::X509::Certificate.new(pem.join) }
end
end
end
65 changes: 47 additions & 18 deletions test/definitions/checks/check_sha1_certificate_authority_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,40 @@
let(:ca_cert) do
<<~CERT
-----BEGIN CERTIFICATE-----
MIIDHTCCAgWgAwIBAgIUbkOgb3ORoG8G9K3aCqGHvmxjMXQwDQYJKoZIhvcNAQEF
BQAwHjEcMBoGA1UEAwwTVGVzdCBTZWxmLVNpZ25lZCBDQTAeFw0yNDExMjYyMDMw
MTRaFw0zNDExMjQyMD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ZWQgQ0EwHhcNMjQxMjA2MTk1NzM2WhcN
MzQxMjA0MTk1NzM2WjAeMRwwGgYDVQQDDBNUZXN0IFNlbGYtU2lnbmVkIENBMIIB
IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2SygWdi+BjZRyo8G5WW/527S
JB3Mpkc35G0RQ+hszXlH6XqFw5NTcTebF5UnJ/DtuKQ0r4FAmJopH5/bejysb7xe
tV6vgjcga3C7XVuHs1dbU7NUVWEiy0VvhI/znIK7HQ2AI//5v8CaDMxnBD4El55Y
dagpBFCKuiuKTy4G1l4opeZGJe5ZFs10bPX5VbrqJs6l1p5C+ylrJmMxAwTtnq1Y
qFu9B8k9wjZYTBFcEAO4CEAs/EAIfQZcd6XCq2L/YhofqBXy7Nr97NZgPUH8UtZA
nTbG0P0dEBiSEx0rbbIg2ToAhcgLAgzPZbVV+fon/V2K7yq/Y+XQWMMGqTeuZwID
AQABMA0GCSqGSIb3DQEBBQUAA4IBAQB7UCCFbs2kkpFR2epS97Zc7/OBd1M9ZLCh
YRLJEjywrEnc/m8KQ9TqVSxWnk8O2Ld7hkrME4fZ+S8riXXrjv8kfRImoZE/3h2f
QDmKOS10d79ehEtgSKBToukEcwgL5q/PjQ840wEjJK5gEG3UoFXIl3/EkvPi8Vrq
ELBKYJhzaJA1g0ziOZWJh/sXI9ryIJ9XHUPwx5elqdtXMR0SRpvo1FmtATgBtPga
wQ6H2KHLnas9h1owoyPETxYnd7qgbNORGSglhH0PiUTbucD6ozU+VcBuq9qPJnwZ
76lKsVXoyGQydEuEYOmYstJqE+nBfVgPG4OwgHHHt99htimjCcn3
-----END CERTIFICATE-----
CERT
end
Expand All @@ -38,7 +55,7 @@
:installer,
answers: { 'certs' => { 'server_ca_cert' => 'ca-sha1.crt' } }
)
File.expects(:read).with('ca-sha1.crt').returns(ca_cert)
File.expects(:binread).with('ca-sha1.crt').returns(ca_cert)
result = run_step(subject)

assert result.fail?
Expand All @@ -54,4 +71,16 @@

assert result.success?
end

it 'throws an error if the certificate is incorrectly formatted' do
assume_feature_present(:katello)
assume_feature_present(
:installer,
answers: { 'certs' => { 'server_ca_cert' => 'ca-sha1.crt' } }
)
File.expects(:binread).with('ca-sha1.crt').returns('15231421')
result = run_step(subject)

assert result.fail?
end
end

0 comments on commit be2304c

Please sign in to comment.