Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for sha1 CA certificate #1004

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bin/katello-certs-check
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ function check-shortname () {
fi
}

function check-ca-signing-algorithm () {
printf "Checking CA signing algorithm for sha1: "
CHECK=$(openssl crl2pkcs7 -nocrl -certfile "$CA_BUNDLE_FILE" | openssl pkcs7 -print | grep algorithm | grep -q 'sha1WithRSAEncryption')
if [[ $? == "0" ]]; then
error 4 "The file '$CA_BUNDLE_FILE' contains a certificate signed with sha1 and will break installation. Update the server CA certificate and its chain with one signed by sha256 or stronger."
else
success
fi
}

check-files-exist
check-server-cert-encoding
check-expiration
Expand All @@ -261,6 +271,7 @@ check-ca-bundle-trust-rules
check-cert-san
check-cert-usage-key-encipherment
check-shortname
check-ca-signing-algorithm

if [[ $EXIT_CODE == "0" ]] && ([[ $TARGET == ${SERVER_TARGET} ]] || [[ -z "$TARGET" ]]) ; then
echo -e "${GREEN}Validation succeeded${RESET}\n"
Expand Down
17 changes: 17 additions & 0 deletions spec/fixtures/katello-certs-check/certs/.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-----BEGIN CERTIFICATE-----
MIICwzCCAasCFCfqmT5iimHv5Qw7DMKZztytQza4MA0GCSqGSIb3DQEBBQUAMB4x
HDAaBgNVBAMME1Rlc3QgU2VsZi1TaWduZWQgQ0EwHhcNMjQxMjA2MTk1NjI4WhcN
MzQxMjA0MTk1NjI4WjAeMRwwGgYDVQQDDBNUZXN0IFNlbGYtU2lnbmVkIENBMIIB
IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnjSxkMAFGgEw8/5kJ/GccLFZ
4z4aJoYvf2brg1V158GOyEq3H49Uj46spgIFrMZeA38eQu4vWU0hm8G3mM73J/SM
xxqO+O+9voqfO+aVtKIplt9u87Ae0KYhnFIIMvgdXFhsq51vPkWDmabc7Oaw1JM5
aDigf2vcJ05gVOc4B8uw9S1cL8tsAyDXZfzlydvyPCVjFlj7TyPiCNqOL2WjqV8k
MJ9VCERxz/ywWKU+1YQnxhK/25IHvlu1xgvNOs76FE9axkzx9q10N8xPSAZ3BZuW
sdVrDLp5zbPcSZGuPjwRGiJ4V7bfpmloz91FyQh3o6cLGNtrVd/WNpr4Pj+0BQID
AQABMA0GCSqGSIb3DQEBBQUAA4IBAQAPgDEYoJRcerXYvWZiNtyK+8F3SCwm/1vE
mjBlq5604tcEPAkJCNqL4fEyj3vM5TUkPKBPZBvo3pkuMOCRqnlylfV+HVlPt7Zw
cXpCQxEvV39HaL0eHOJ4eUHYwbXwecqX/rqf+ncA1IQJsAomFlvK4KMlcrYm53Ul
vFd/o8xdeU3UvazPjPbxZ691DApkJ9WqxgXGemksQkZrK2i+7UZQ0CQNty6TKI8o
mp44Df94w/dXrs3bjAueNzD47tGMIlfwhw19k+r9qlThWiX3PIiAKvmYB2mM1BX3
XGlgRlt6C26INTO+GBTNo6YtuaTtNNxQrR97ASoNfF1rR0ZLwcqA
-----END CERTIFICATE-----
36 changes: 36 additions & 0 deletions spec/fixtures/katello-certs-check/certs/ca-sha1-bundle.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-----BEGIN CERTIFICATE-----
MIIDHTCCAgWgAwIBAgIUK+x25LNYYMHS83aWDnAYviwxEYEwDQYJKoZIhvcNAQEL
BQAwHjEcMBoGA1UEAwwTVGVzdCBTZWxmLVNpZ25lZCBDQTAeFw0yMDExMTgwMjMw
NDNaFw0zMDExMTYwMjMwNDNaMB4xHDAaBgNVBAMME1Rl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
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-----
17 changes: 17 additions & 0 deletions spec/fixtures/katello-certs-check/certs/ca-sha1.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-----BEGIN CERTIFICATE-----
MIICwzCCAasCFCfqmT5iimHv5Qw7DMKZztytQza5MA0GCSqGSIb3DQEBBQUAMB4x
HDAaBgNVBAMME1Rlc3QgU2VsZi1TaWduZWQgQ0EwHhcNMjQxMjA2MTk1NzM2WhcN
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-----
28 changes: 28 additions & 0 deletions spec/fixtures/katello-certs-check/certs/ca-sha1.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDZLKBZ2L4GNlHK
jwblZb/nbtIkHcymRzfkbRFD6GzNeUfpeoXD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QkLb6xmZSrZ9E8Of5/kUiFd35KudUQ+nGfkbgCwzPzdRPePUnlDyWdo
H+iq8cJpb5rg3z61aEA8PxXy6YmzWysqvuGp811qGayUQ7v7CHWwK/BdkwKBgCPC
uZzxLEgVElpjD0VmcS563c0mmZZ5zWuiJq2KEMJCJgc/Cgv6rWFgqNlkUOBsN6OM
VqRDjvbfcVmyoyrmI/YNbPMAB34gIc2KgqN4qFL8wu681A4mOT8ySb3E0ALI3fFG
G6p+xdW4DgFmuL8xJjam3xaoTpZvtFZGNx3sLXhVAoGBAKaQCjcR9EwCObim8+s8
l97xSSDtkcvHBcV3bWRo+5c5RiNShjNRYGnJ2YhaVgbB3kkVZjkfdMN/Ms5H1htF
SMrVKbByAQF9p8QeOoww99sx/dExwIA5p4VuUlmFHRhDCgnLhUXe/RJP5Y2+16hn
vDYEQDTkTV2whuDB51qV29Gz
-----END PRIVATE KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDejCCAmKgAwIBAgIUcHqMbOmM7gGFcfi3jIb1vTitbkQwDQYJKoZIhvcNAQEL
BQAwHjEcMBoGA1UEAwwTVGVzdCBTZWxmLVNpZ25lZCBDQTAeFw0yNDEyMDYxOTU3
MzZaFw0zNDEyMDQxOTU3MzZaMB4xHDAaBgNVBAMME2ZvcmVtYW4uZXhhbXBsZS5j
b20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQChlvkIs/8vsEQCVN/j
73ugXfufdYah8VzkcCjSocRoisszS+GUKKawwDd1zWdwOHcoV+7HBFKLAtyjhCFR
kqezttMTePWXhT4ted9La07zasXHCmy+GUTnuf0jgEX7SeG+0HOwVrm9rvq5cswS
up/QIL9BIYn+AQQELrS63yLqblc0WdV8VMnMjj46i/qZG2iJIoM/RVIfaq90if96
TijXt53LKHh1SV+LXZxt3BJgGTRFfaG843S1Aea6h9UFdrn7dzIDknrb7kWzz81K
Wear1trFdgkj13BbBF+AunbVejK8Pk6hm4i82ropBDxanSy7iOvlm/Uz9NDLKAON
dJ4xAgMBAAGjga8wgawwCwYDVR0PBAQDAgUgMDkGA1UdEQQyMDCCE2ZvcmVtYW4u
ZXhhbXBsZS5jb22CGWZvcmVtYW4tZWMzODQuZXhhbXBsZS5jb20wHQYDVR0OBBYE
FHnA0BUv7moEuAeEn/DGrIQbjD08MEMGA1UdIwQ8MDqhIqQgMB4xHDAaBgNVBAMM
E1Rlc3QgU2VsZi1TaWduZWQgQ0GCFCfqmT5iimHv5Qw7DMKZztytQza5MA0GCSqG
SIb3DQEBCwUAA4IBAQC0NSSu2LBWAMHol1ywQSk1+L5naiX8hn9aafgOcE8UlEAk
b05LCeqZ/MyDR1sxfDwKFIHjkDG0FjbizUr9R5J4PGHOgJuGFaePYrAGpCF03rFi
GmrYnxFo309wC2uBiuK5yMTif7/WM9QfhaZ3JGe9tpiZAHWkcjfYb5Ujc/LqQJ13
y6W9QpKWFaMEX/N6LMai6jto69Q+2WqTruw7mqBBW0MCaHNCeLIU9zzDyvwtoHzs
EJEsvkVhUBXtWhMPomxjfybHOB7rHPbNnyY+3tCKXO80w3GuWPlpdSVvphTujZtv
KMSeO4MwrU0j69tqzIsvG3ha0PNroRL6D0p45KLy
-----END CERTIFICATE-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQChlvkIs/8vsEQC
VN/j73ugXfufdYah8VzkcCjSocRoisszS+GUKKawwDd1zWdwOHcoV+7HBFKLAtyj
hCFRkqezttMTePWXhT4ted9La07zasXHCmy+GUTnuf0jgEX7SeG+0HOwVrm9rvq5
cswSup/QIL9BIYn+AQQELrS63yLqblc0WdV8VMnMjj46i/qZG2iJIoM/RVIfaq90
if96TijXt53LKHh1SV+LXZxt3BJgGTRFfaG843S1Aea6h9UFdrn7dzIDknrb7kWz
z81KWear1trFdgkj13BbBF+AunbVejK8Pk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Qmni0PdLvOdwo4MikCgYBHbMGfVtl4ht/YA+dkSDZ8
I2LvMVu7hLVrYh0OS9xVX0A21TDdA4j3aGZI1I1d5PRZ3oIlNQkbpN7uMlnpgqWO
2gw/s2fGJQ0ox0XGeJNDQQhN3BzKHy5sNDbVCwPkuBEG56c5Tj2VfgEFSucOp9AP
QvH1TYJFELH0XveWP/b/Eg==
-----END PRIVATE KEY-----
23 changes: 23 additions & 0 deletions spec/fixtures/katello-certs-check/create_cert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,29 @@ else
echo "CA certificate bundle with trust rules exists. Skipping."
fi

CA_SHA1_CERT_NAME=ca-sha1
CA_SHA1_CERT_BUNDLE=ca-sha1-bundle
if [[ ! -f "$CERTS_DIR/$CA_SHA1_CERT_NAME.key" || ! -f "$CERTS_DIR/$CA_SHA1_CERT_NAME.crt" || ! -f "$CERTS_DIR/$CA_SHA1_CERT_BUNDLE.crt" ]]; then
echo "Generate CA with sha1 signing algorithm"
openssl genrsa -out $CERTS_DIR/$CA_SHA1_CERT_NAME.key 2048
openssl req -new -key $CERTS_DIR/$CA_SHA1_CERT_NAME.key -sha1 -out $CERTS_DIR/$CA_SHA1_CERT_NAME.csr -subj "/CN=Test Self-Signed CA"
openssl x509 -req -in $CERTS_DIR/$CA_SHA1_CERT_NAME.csr -CA $CERTS_DIR/$CA_CERT_NAME.crt -CAkey $CERTS_DIR/$CA_CERT_NAME.key -CAcreateserial -out $CERTS_DIR/$CA_SHA1_CERT_NAME.crt -days 3650 -sha1

cat $CERTS_DIR/$CA_CERT_NAME.crt $CERTS_DIR/$CA_SHA1_CERT_NAME.crt > $CERTS_DIR/$CA_SHA1_CERT_BUNDLE.crt
else
echo "CA certificate exists. Skipping."
fi

CERT_NAME=foreman-sha1.example.com
if [[ ! -f "$CERTS_DIR/$CERT_NAME.key" || ! -f "$CERTS_DIR/$CERT_NAME.crt" ]]; then
echo "Generate server certificate"
openssl genrsa -out $CERTS_DIR/$CERT_NAME.key 2048
openssl req -new -key $CERTS_DIR/$CERT_NAME.key -out $CERTS_DIR/$CERT_NAME.csr -subj "/CN=foreman.example.com"
openssl x509 -req -in $CERTS_DIR/$CERT_NAME.csr -CA $CERTS_DIR/$CA_SHA1_CERT_NAME.crt -CAkey $CERTS_DIR/$CA_SHA1_CERT_NAME.key -CAcreateserial -out $CERTS_DIR/$CERT_NAME.crt -days 3650 -sha256 -extfile extensions.txt -extensions extensions
else
echo "Server certificate with bad SAN exists. Skipping."
fi

CERT_NAME=foreman-bad-san.example.com
if [[ ! -f "$CERTS_DIR/$CERT_NAME.key" || ! -f "$CERTS_DIR/$CERT_NAME.crt" ]]; then
echo "Generate server certificate"
Expand Down
26 changes: 26 additions & 0 deletions spec/katello_certs_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,30 @@ def fixture(filename)
expect(status.exitstatus).to eq 10
end
end

context 'with sha1 server CA certificate' do
let(:key) { File.join(certs_directory, 'foreman-sha1.example.com.key') }
let(:cert) { File.join(certs_directory, 'foreman-sha1.example.com.crt') }
let(:ca) { File.join(certs_directory, 'ca-sha1.crt') }

it 'fails' do
command_with_certs = "#{command} -b #{ca} -k #{key} -c #{cert}"
_stdout, stderr, status = Open3.capture3(command_with_certs)
expect(stderr).to include "The file '#{ca}' contains a certificate signed with sha1 and will break installation. Update the server CA certificate and its chain with one signed by sha256 or stronger."
expect(status.exitstatus).to eq 4
end
end

context 'with sha1 server CA certificate bundle' do
let(:key) { File.join(certs_directory, 'foreman-sha1.example.com.key') }
let(:cert) { File.join(certs_directory, 'foreman-sha1.example.com.crt') }
let(:ca) { File.join(certs_directory, 'ca-sha1-bundle.crt') }

it 'fails' do
command_with_certs = "#{command} -b #{ca} -k #{key} -c #{cert}"
_stdout, stderr, status = Open3.capture3(command_with_certs)
expect(stderr).to include "The file '#{ca}' contains a certificate signed with sha1 and will break installation. Update the server CA certificate and its chain with one signed by sha256 or stronger."
expect(status.exitstatus).to eq 4
end
end
end
Loading