Skip to content

Commit 64f70b5

Browse files
dpkpjeffwidman
authored andcommitted
Generate SSL certificates for local testing (#1756)
This doesn't fully implement SSL fixtures, but as a first step it should help with automatically generating required certificates / keystores / etc. My hope is that this helps generate more community support for SSL testing!
1 parent ee4a53e commit 64f70b5

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/fixtures.py

+29
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,35 @@ def get_open_port():
4141
sock.close()
4242
return port
4343

44+
def gen_ssl_resources(directory):
45+
os.system("""
46+
cd {0}
47+
echo Generating SSL resources in {0}
48+
49+
# Step 1
50+
keytool -keystore kafka.server.keystore.jks -alias localhost -validity 1 \
51+
-genkey -storepass foobar -keypass foobar \
52+
-dname "CN=localhost, OU=kafka-python, O=kafka-python, L=SF, ST=CA, C=US" \
53+
-ext SAN=dns:localhost
54+
55+
# Step 2
56+
openssl genrsa -out ca-key 2048
57+
openssl req -new -x509 -key ca-key -out ca-cert -days 1 \
58+
-subj "/C=US/ST=CA/O=MyOrg, Inc./CN=mydomain.com"
59+
keytool -keystore kafka.server.truststore.jks -alias CARoot -import \
60+
-file ca-cert -storepass foobar -noprompt
61+
62+
# Step 3
63+
keytool -keystore kafka.server.keystore.jks -alias localhost -certreq \
64+
-file cert-file -storepass foobar
65+
openssl x509 -req -CA ca-cert -CAkey ca-key -in cert-file -out cert-signed \
66+
-days 1 -CAcreateserial -passin pass:foobar
67+
keytool -keystore kafka.server.keystore.jks -alias CARoot -import \
68+
-file ca-cert -storepass foobar -noprompt
69+
keytool -keystore kafka.server.keystore.jks -alias localhost -import \
70+
-file cert-signed -storepass foobar -noprompt
71+
""".format(directory))
72+
4473
class Fixture(object):
4574
kafka_version = os.environ.get('KAFKA_VERSION', '0.11.0.2')
4675
scala_version = os.environ.get("SCALA_VERSION", '2.8.0')

0 commit comments

Comments
 (0)