-
Notifications
You must be signed in to change notification settings - Fork 10
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 scripts to generate certificate and add it to the macOS Keychain and iOS Keychain #44
base: master
Are you sure you want to change the base?
Changes from 1 commit
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,31 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
CERT_FILE=root-ca.pem | ||
if ! test -f "$CERT_FILE"; then | ||
echo "$CERT_FILE file doesn't exists. Generate it using generate-self-signed-certificate.sh" | ||
exit 1 | ||
fi | ||
|
||
# Find booted iOS Simulator | ||
while true; do | ||
export UDID=$(xcrun simctl list devices | grep "(Booted)" | grep -E -o -i "([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})") | ||
if [ -z "$UDID" ] | ||
then | ||
echo "Please launch an iOS Simulator in which you would like to install certificate and press any key" | ||
read input | ||
else | ||
break | ||
fi | ||
done | ||
|
||
# Add certificate to iOS Simulator | ||
echo "Adding certificate to iOS Sumulator..." | ||
xcrun simctl keychain booted add-root-cert root-ca.pem | ||
|
||
# Restart booted iOS Simulator | ||
echo "Restarning iOS Sumulator..." | ||
xcrun simctl shutdown $UDID | ||
xcrun simctl boot $UDID | ||
|
||
echo "Certificate has been successfully added to the iOS Simulator Keychain" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
CERT_FILE=root-ca.pem | ||
if ! test -f "$CERT_FILE"; then | ||
echo "$CERT_FILE file doesn't exists. Generate it using generate-certificate.sh." | ||
exit 1 | ||
fi | ||
|
||
# Add certificate to macOS Keychain | ||
echo "You will be promted to authenticate to mark certificate as trusted" | ||
|
||
# Get path to the local keychain and trim whitespaces and quotation marks symbol | ||
LOGIN_KEYCHAIN="$(security login-keychain | sed 's/[[:space:]]*"//g')" | ||
security add-trusted-cert -k $LOGIN_KEYCHAIN root-ca.pem | ||
|
||
echo "Certificate has been successfully added to the macOS Keychain" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[ ca ] | ||
default_ca = CA_default | ||
[ CA_default ] | ||
default_md = sha256 | ||
[ v3_ca ] | ||
subjectKeyIdentifier=hash | ||
authorityKeyIdentifier=keyid:always,issuer | ||
basicConstraints = critical,CA:true | ||
keyUsage=critical,keyCertSign | ||
extendedKeyUsage = serverAuth,clientAuth | ||
[ req ] | ||
prompt = no | ||
distinguished_name = req_distinguished_name | ||
[ req_distinguished_name ] | ||
C=RU | ||
L=RU | ||
O=Catbird | ||
CN=Catbird | ||
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. here you probably need to specify the host? 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. Yes, but we do not have website. 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. Changed to |
||
OU=Catbird |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
# Get an existing Catbird certificate | ||
security find-certificate -c Catbird -p > root-ca.pem |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
CONFIG_FILE=cert.config | ||
if ! test -f "$CONFIG_FILE"; then | ||
echo "$CONFIG_FILE file doesn't exists. Add cert.config file with certificate configuration." | ||
exit 1 | ||
fi | ||
|
||
echo "Creating new certificate from cert.config" | ||
|
||
echo "Enter password for new certificate." | ||
read -s -p "Password: " password | ||
|
||
# Generate RSA Key | ||
openssl genrsa -aes256 -passout pass:"$password" -out key.pem 2048 | ||
|
||
# Generate the self-signed certificate and private key | ||
openssl req -x509 -new -nodes -passin pass:"$password" -config cert.config -key key.pem -sha256 -extensions v3_ca -days 365 -out root-ca.pem | ||
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. Not used 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. Fixed |
||
|
||
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. For Vaport, the key is needed in the Key format
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. Added. |
||
# Cleanup | ||
rm key.pem | ||
|
||
echo "Certificate created: root_ca.pem" |
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.
Do I need to add to the system Keychain ?
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain root-ca.pem
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.
It seems, no.