Skip to content
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

MacOS: Option to skip TLS certificate creation for Safari #217

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

{
"label": "MacOS: Send package for notarization",
"command": "xcrun notarytool submit --keychain-profile \"autogram\" --keychain $APPLE_KEYCHAIN_PATH --wait target/Autogram-*.pkg",
"command": "pkgutil --check-signature target/Autogram-*.pkg && xcrun notarytool submit --keychain-profile \"autogram\" --keychain $APPLE_KEYCHAIN_PATH --wait target/Autogram-*.pkg",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toto je nieco nove?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toto je aby to faillo co najskor pred tym nez sa robi upload

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a teda ide iba o comand vo vscode, ktory pouziva developer

"options": {
"env": {
"JAVA_HOME": "${config:java.jdt.ls.java.home}",
Expand Down
1 change: 1 addition & 0 deletions src/main/scripts/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ if [[ "$platform" == "mac" ]]; then
fi

if [[ "$properties_mac_sign" == "1" ]]; then
export JPACKAGE_MAC_SIGN="1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toto tu ma byt na tvrdo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ano, jedine ine co by tam davalo zmysel je "$properties_mac_sign" ale to je tiez "1"

if [[ -z "$APPLE_DEVELOPER_IDENTITY" ]] || [[ -z "$APPLE_KEYCHAIN_PATH" ]]; then
echo "Missing APPLE_DEVELOPER_IDENTITY or APPLE_KEYCHAIN_PATH env variable"
exit 1
Expand Down
7 changes: 5 additions & 2 deletions src/main/scripts/resources/Autogram-post-image.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash -e
TARGET="$(cd ../images/*/*/Contents;pwd)"
SOURCE="$(cd ../../mac-launcher;pwd)"

Expand All @@ -11,5 +12,7 @@ chmod +x "$TARGET/MacOS/Autogram"

# codesign changed executables
ENTITLEMENTS=../../Autogram.entitlements
codesign -s "$APPLE_DEVELOPER_IDENTITY" --keychain $APPLE_KEYCHAIN_PATH --entitlements "$ENTITLEMENTS" --options=runtime --deep --timestamp --force "$TARGET/MacOS/Autogram"
codesign -s "$APPLE_DEVELOPER_IDENTITY" --keychain $APPLE_KEYCHAIN_PATH --entitlements "$ENTITLEMENTS" --options=runtime --deep --timestamp --force "$TARGET/MacOS/AutogramApp"
if [[ "$JPACKAGE_MAC_SIGN" == "1" ]]; then
codesign -s "$APPLE_DEVELOPER_IDENTITY" --keychain $APPLE_KEYCHAIN_PATH --entitlements "$ENTITLEMENTS" --options=runtime --deep --timestamp --force "$TARGET/MacOS/Autogram"
codesign -s "$APPLE_DEVELOPER_IDENTITY" --keychain $APPLE_KEYCHAIN_PATH --entitlements "$ENTITLEMENTS" --options=runtime --deep --timestamp --force "$TARGET/MacOS/AutogramApp"
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
function create_cert() {
TLS_DIR="$HOME/Library/Application Support/Autogram/tls"

osascript -e 'return display dialog "Teraz vygenerujeme Váš osobný SSL certifikát. Následne si od Vás inštalátor vyžiada heslo, aby certifikát mohol byť pridaný ako dôveryhodný pre spojenie so Safari." with icon caution'
if [ $? -ne 0 ]; then
return 0
fi

mkdir -p "$TLS_DIR"

# Create temp openssl configuration
SSL_CONFIG_TMP=$(mktemp)
echo "[ req ]
req_extensions = v3_req
x509_extensions = v3_req
distinguished_name = dn
prompt = no
encrypt_key = no

[ v3_req ]
subjectAltName = @alt_names
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth

certificatePolicies = 1.2.3.4

[dn]
C=SK
O=SSD
CN=loopback.autogram.slovensko.digital

[CA_default]
copy_extension=copy

[alt_names]
DNS.1=loopback.autogram.slovensko.digital

" >$SSL_CONFIG_TMP

cat $SSL_CONFIG_TMP

/usr/bin/openssl req -nodes -x509 -newkey rsa:4096 -keyout "$TLS_DIR/autogram-key.pem" -out "$TLS_DIR/autogram-cert.pem" -sha256 -days 365 -config $SSL_CONFIG_TMP

/usr/bin/openssl pkcs12 -export -in "$TLS_DIR/autogram-cert.pem" -inkey "$TLS_DIR/autogram-key.pem" -out "$TLS_DIR/autogram-pkcs12-cert.p12" -name "autogram-pkcs12-cert" -passout pass:

security -v add-trusted-cert -r trustRoot -p basic -p ssl -k $HOME/Library/Keychains/login.keychain-db "$TLS_DIR/autogram-cert.pem"

# Cleanup openssl config
rm $SSL_CONFIG_TMP
}

function remove_cert(){
TLS_DIR="$HOME/Library/Application Support/Autogram/tls"
security delete-certificate -Z $(openssl x509 -in "$TLS_DIR/autogram-cert.pem" -outform DER | shasum -a 1 ) "$HOME/Library/Keychains/login.keychain-db"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
source "$(dirname "$0")/cert-functions.sh";

create_cert
74 changes: 14 additions & 60 deletions src/main/scripts/resources/postinstall
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,22 @@ set +x

DEBUG=false

DESTINATION=${2:-"/Applications"}

if [ $DEBUG = true ]; then
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>>"$HOME/autogram-install.log" 2>&1
fi

# chown root:wheel "/Applications"
chmod a+rX "/Applications"
chmod +r "/Applications/Autogram.app/Contents/app/"*.jar


function create_cert() {
TLS_DIR="$HOME/Library/Application Support/Autogram/tls"

osascript -e 'return display dialog "Teraz vygenerujeme Váš osobný SSL certifikát. Následne si od Vás inštalátor vyžiada heslo, aby certifikát mohol byť pridaný ako dôveryhodný pre spojenie so Safari." with icon caution'
if [ $? -ne 0 ]; then
return 0
fi

mkdir -p "$TLS_DIR"

# Create temp openssl configuration
SSL_CONFIG_TMP=$(mktemp)
echo "[ req ]
req_extensions = v3_req
x509_extensions = v3_req
distinguished_name = dn
prompt = no
encrypt_key = no

[ v3_req ]
subjectAltName = @alt_names
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth

certificatePolicies = 1.2.3.4

[dn]
C=SK
O=SSD
CN=loopback.autogram.slovensko.digital

[CA_default]
copy_extension=copy

[alt_names]
DNS.1=loopback.autogram.slovensko.digital

" >$SSL_CONFIG_TMP
echo "Installing Autogram to $DESTINATION"

cat $SSL_CONFIG_TMP

/usr/bin/openssl req -nodes -x509 -newkey rsa:4096 -keyout "$TLS_DIR/autogram-key.pem" -out "$TLS_DIR/autogram-cert.pem" -sha256 -days 365 -config $SSL_CONFIG_TMP

/usr/bin/openssl pkcs12 -export -in "$TLS_DIR/autogram-cert.pem" -inkey "$TLS_DIR/autogram-key.pem" -out "$TLS_DIR/autogram-pkcs12-cert.p12" -name "autogram-pkcs12-cert" -passout pass:

security -v add-trusted-cert -r trustRoot -p basic -p ssl -k $HOME/Library/Keychains/login.keychain-db "$TLS_DIR/autogram-cert.pem"

# Cleanup openssl config
rm $SSL_CONFIG_TMP
}
# chown root:wheel "/Applications"
chmod a+rX "$DESTINATION"
chmod +r "$DESTINATION/Autogram.app/Contents/app/"*.jar
chmod +x "$DESTINATION/Autogram.app/Contents/Resources/Scripts/create-cert.sh"

function remove_cert(){
TLS_DIR="$HOME/Library/Application Support/Autogram/tls"
security delete-certificate -Z $(openssl x509 -in "$TLS_DIR/autogram-cert.pem" -outform DER | shasum -a 1 ) "$HOME/Library/Keychains/login.keychain-db"
}
source "$DESTINATION/Autogram.app/Contents/Resources/Scripts/cert-functions.sh";

function sudo_create_cert() {

Expand All @@ -78,8 +27,13 @@ function sudo_create_cert() {

# Run function create_cert in "unpriviledged" environment - with real user env
sudo -u "$USER" bash -c "$FUNC; remove_cert; create_cert"

}



if [[ -f "$HOME/Library/Application Support/Autogram/tls/skip" ]]; then
exit 0
fi

sudo_create_cert
exit 0