-
Notifications
You must be signed in to change notification settings - Fork 253
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
enable TLS hostname validation #279
Changes from all commits
84ab4c2
7b2bb02
2137361
38b6147
b42e931
22eaf7c
d7b36d1
748f1b9
9bab5a5
381fdf4
fd1c823
7593af1
052f90d
ca4e390
c6a465f
1300bc0
440ce7f
199f429
caf1911
c801132
80bab6c
eeb7a6d
c5f2126
d2ba5e6
41881aa
19f9c7d
3c18b1e
0f51b56
02a29ea
7de6335
a890f03
3aebc3d
4e5a8e7
0a8c099
8ed4dca
efd354a
0926274
72ba381
435332d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
BASE_PATH=$( cd "`dirname $0`/../test/fixtures/ca" && pwd ) | ||
cd "${BASE_PATH}" || exit 4 | ||
|
||
USAGE=$( cat << EOS | ||
Usage: | ||
$0 --regenerate | ||
|
||
Generates a new self-signed CA, for integration testing. This should only need | ||
to be run if you are writing new TLS/SSL tests, and need to generate | ||
additional fixtuer CAs. | ||
|
||
This script uses the GnuTLS certtool CLI. If you are on macOS, | ||
'brew install gnutls', and it will be installed as 'gnutls-certtool'. | ||
Apple unfortunately ships with an incompatible /usr/bin/certtool that does | ||
different things. | ||
EOS | ||
) | ||
|
||
if [ "x$1" != 'x--regenerate' ]; then | ||
echo "${USAGE}" | ||
exit 1 | ||
fi | ||
|
||
TOOL=`type -p certtool` | ||
if [ "$(uname)" = "Darwin" ]; then | ||
TOOL=`type -p gnutls-certtool` | ||
if [ ! -x "${TOOL}" ]; then | ||
echo "Sorry, Darwin requires gnutls-certtool; try `brew install gnutls`" | ||
exit 2 | ||
fi | ||
fi | ||
|
||
if [ ! -x "${TOOL}" ]; then | ||
echo "Sorry, no certtool found!" | ||
exit 3 | ||
fi | ||
export TOOL | ||
|
||
|
||
${TOOL} --generate-privkey > ./cakey.pem | ||
${TOOL} --generate-self-signed \ | ||
--load-privkey ./cakey.pem \ | ||
--template ./ca.info \ | ||
--outfile ./cacert.pem | ||
|
||
echo "cert and private key generated! Don't forget to check them in" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ | |
set -e | ||
set -x | ||
|
||
BASE_PATH="$( cd `dirname $0`/../test/fixtures/openldap && pwd )" | ||
SEED_PATH="$( cd `dirname $0`/../test/fixtures && pwd )" | ||
BASE_PATH=$( cd "`dirname $0`/../test/fixtures/openldap" && pwd ) | ||
SEED_PATH=$( cd "`dirname $0`/../test/fixtures" && pwd ) | ||
|
||
dpkg -s slapd time ldap-utils gnutls-bin ssl-cert > /dev/null ||\ | ||
DEBIAN_FRONTEND=noninteractive apt-get update -y --force-yes && \ | ||
|
@@ -48,47 +48,58 @@ chown -R openldap.openldap /var/lib/ldap | |
rm -rf $TMPDIR | ||
|
||
# SSL | ||
export CA_CERT="/usr/local/share/ca-certificates/rubyldap-ca.crt" | ||
export CA_KEY="/etc/ssl/private/rubyldap-ca.key" | ||
|
||
sh -c "certtool --generate-privkey > /etc/ssl/private/cakey.pem" | ||
# The self-signed fixture CA cert & key are generated by | ||
# `script/generate-fiuxture-ca` and checked into version control. | ||
# You shouldn't need to muck with these unless you're writing more | ||
# TLS/SSL integration tests, and need special magic values in the cert. | ||
|
||
sh -c "cat > /etc/ssl/ca.info <<EOF | ||
cn = rubyldap | ||
ca | ||
cert_signing_key | ||
EOF" | ||
cp "${SEED_PATH}/ca/cacert.pem" "${CA_CERT}" | ||
cp "${SEED_PATH}/ca/cakey.pem" "${CA_KEY}" | ||
|
||
# Create the self-signed CA certificate: | ||
certtool --generate-self-signed \ | ||
--load-privkey /etc/ssl/private/cakey.pem \ | ||
--template /etc/ssl/ca.info \ | ||
--outfile /etc/ssl/certs/cacert.pem | ||
# actually add the fixture CA to the system store | ||
update-ca-certificates | ||
|
||
# Make a private key for the server: | ||
certtool --generate-privkey \ | ||
--bits 1024 \ | ||
--outfile /etc/ssl/private/ldap01_slapd_key.pem | ||
--bits 1024 \ | ||
--outfile /etc/ssl/private/ldap01_slapd_key.pem | ||
|
||
sh -c "cat > /etc/ssl/ldap01.info <<EOF | ||
organization = Example Company | ||
cn = ldap01.example.com | ||
dns_name = ldap01.example.com | ||
dns_name = ldap02.example.com | ||
dns_name = localhost | ||
tls_www_server | ||
encryption_key | ||
signing_key | ||
expiration_days = 3650 | ||
EOF" | ||
|
||
# The integration server may be accessed by IP address, in which case | ||
# we want some of the IPs included in the cert. We skip loopback (127.0.0.1) | ||
# because that's the IP we use in the integration test for cert name mismatches. | ||
ADDRS=$(ifconfig -a | grep 'inet addr:' | cut -f 2 -d : | cut -f 1 -d ' ') | ||
for ip in $ADDRS; do | ||
if [ "x$ip" = 'x127.0.0.1' ]; then continue; fi | ||
echo "ip_address = $ip" >> /etc/ssl/ldap01.info | ||
done | ||
|
||
# Create the server certificate | ||
certtool --generate-certificate \ | ||
--load-privkey /etc/ssl/private/ldap01_slapd_key.pem \ | ||
--load-ca-certificate /etc/ssl/certs/cacert.pem \ | ||
--load-ca-privkey /etc/ssl/private/cakey.pem \ | ||
--load-ca-certificate "${CA_CERT}" \ | ||
--load-ca-privkey "${CA_KEY}" \ | ||
--template /etc/ssl/ldap01.info \ | ||
--outfile /etc/ssl/certs/ldap01_slapd_cert.pem | ||
|
||
ldapmodify -Y EXTERNAL -H ldapi:/// <<EOF | true | ||
dn: cn=config | ||
add: olcTLSCACertificateFile | ||
olcTLSCACertificateFile: /etc/ssl/certs/cacert.pem | ||
olcTLSCACertificateFile: ${CA_CERT} | ||
- | ||
add: olcTLSCertificateFile | ||
olcTLSCertificateFile: /etc/ssl/certs/ldap01_slapd_cert.pem | ||
|
@@ -110,6 +121,14 @@ chmod g+r /etc/ssl/private/ldap01_slapd_key.pem | |
chmod o-r /etc/ssl/private/ldap01_slapd_key.pem | ||
|
||
# Drop packets on a secondary port used to specific timeout tests | ||
iptables -A OUTPUT -p tcp -j DROP --dport 8389 | ||
iptables -A INPUT -p tcp -j DROP --dport 8389 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you provide more a link or some background for why mac os blackholes here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DigitalOcean has a good write-up of iptables theory. In Travis CI, the test suite executes on the integration host itself. The With the switch to With Vagrant, now that the guest is dropping tcp/8389 on |
||
|
||
# Forward a port for Vagrant | ||
iptables -t nat -A PREROUTING -p tcp --dport 9389 -j REDIRECT --to-port 389 | ||
|
||
# fix up /etc/hosts for cert validation | ||
grep ldap01 /etc/hosts || echo "127.0.0.1 ldap01.example.com" >> /etc/hosts | ||
grep ldap02 /etc/hosts || echo "127.0.0.1 ldap02.example.com" >> /etc/hosts | ||
grep bogus /etc/hosts || echo "127.0.0.1 bogus.example.com" >> /etc/hosts | ||
|
||
service slapd restart |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cn = rubyldap | ||
ca | ||
cert_signing_key | ||
expiration_days = 7200 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIID7zCCAlegAwIBAgIMV7zWei6SNfABx6jMMA0GCSqGSIb3DQEBCwUAMBMxETAP | ||
BgNVBAMTCHJ1YnlsZGFwMB4XDTE2MDgyMzIzMDQyNloXDTM2MDUxMDIzMDQyNlow | ||
EzERMA8GA1UEAxMIcnVieWxkYXAwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGK | ||
AoIBgQDGe9wziGHZJhIf+IEKSk1tpT9Mu7YgsUwjrlutvkoO1Q6K+amTAVDXizPf | ||
1DVSDpZP5+CfBOznhgLMsPvrQ02w4qx5/6X9L+zJcMk8jTNYSKj5uIKpK52E7Uok | ||
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CNl7C4I5zCqLltEDkSoMP | ||
jDj/ | ||
-----END CERTIFICATE----- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No behavioral change, just fiddling with syntax