|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Halt the tests on error |
| 4 | +set -e |
| 5 | + |
| 6 | +# Whever MySQL configs live, go there (this is for cross-platform) |
| 7 | +cd $(my_print_defaults --help | grep my.cnf | xargs find 2>/dev/null | xargs dirname) |
| 8 | + |
| 9 | +# Create config files to run openssl in batch mode |
| 10 | +# Set the CA startdate to yesterday to avoid "ASN: before date in the future" |
| 11 | +# (there can be 90k seconds in a daylight saving change day) |
| 12 | + |
| 13 | +echo " |
| 14 | +[ ca ] |
| 15 | +default_startdate = $(ruby -e 'print (Time.now - 90000).strftime("%y%m%d000000Z")') |
| 16 | +
|
| 17 | +[ req ] |
| 18 | +distinguished_name = req_distinguished_name |
| 19 | +
|
| 20 | +[ req_distinguished_name ] |
| 21 | +# If this isn't set, the error is "error, no objects specified in config file" |
| 22 | +commonName = Common Name (hostname, IP, or your name) |
| 23 | +
|
| 24 | +countryName_default = US |
| 25 | +stateOrProvinceName_default = CA |
| 26 | +localityName_default = San Francisco |
| 27 | +0.organizationName_default = test_example |
| 28 | +organizationalUnitName_default = Testing |
| 29 | +emailAddress_default = [email protected] |
| 30 | +" | tee ca.cnf cert.cnf |
| 31 | + |
| 32 | +# The client and server certs must have a diferent common name than the CA |
| 33 | +# to avoid "SSL connection error: error:00000001:lib(0):func(0):reason(1)" |
| 34 | + |
| 35 | +echo " |
| 36 | +commonName_default = ca_name |
| 37 | +" >> ca.cnf |
| 38 | + |
| 39 | +echo " |
| 40 | +commonName_default = cert_name |
| 41 | +" >> cert.cnf |
| 42 | + |
| 43 | +# Generate a set of certificates |
| 44 | +openssl genrsa -out ca-key.pem 2048 |
| 45 | +openssl req -new -x509 -nodes -days 1000 -key ca-key.pem -out ca-cert.pem -batch -config ca.cnf |
| 46 | +openssl req -newkey rsa:2048 -days 1000 -nodes -keyout pkcs8-server-key.pem -out server-req.pem -batch -config cert.cnf |
| 47 | +openssl x509 -req -in server-req.pem -days 1000 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 -out server-cert.pem |
| 48 | +openssl req -newkey rsa:2048 -days 1000 -nodes -keyout pkcs8-client-key.pem -out client-req.pem -batch -config cert.cnf |
| 49 | +openssl x509 -req -in client-req.pem -days 1000 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 -out client-cert.pem |
| 50 | + |
| 51 | +# Convert format from PKCS#8 to PKCS#1 |
| 52 | +openssl rsa -in pkcs8-server-key.pem -out server-key.pem |
| 53 | +openssl rsa -in pkcs8-client-key.pem -out client-key.pem |
| 54 | + |
| 55 | +# Put the configs into the server |
| 56 | +echo " |
| 57 | +[mysqld] |
| 58 | +ssl-ca=/etc/mysql/ca-cert.pem |
| 59 | +ssl-cert=/etc/mysql/server-cert.pem |
| 60 | +ssl-key=/etc/mysql/server-key.pem |
| 61 | +" >> my.cnf |
| 62 | + |
| 63 | +# FIXME The startdate code above isn't doing the trick, we must wait until the minute moves |
| 64 | +ruby -e 'start = Time.now.min; while Time.now.min == start; sleep 2; end' |
| 65 | + |
| 66 | +# Ok, let's see what we got! |
| 67 | +service mysql restart || brew services restart mysql |
0 commit comments