-
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
Open
subdan
wants to merge
4
commits into
master
Choose a base branch
from
feature/self-signed-certificate
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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=http://localhost | ||
OU=Catbird |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/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 | ||
|
||
# Convert RSA Key from .pem to .key format | ||
openssl rsa -outform der -in key.pem -out cert.key -passin pass:"$password" | ||
|
||
echo "Key created: cert.key" | ||
|
||
# Generate the self-signed certificate and private key | ||
openssl req -x509 -new -nodes -passin pass:"$password" -config "$CONFIG_FILE" -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. 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" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.