Last active
October 2, 2024 16:39
-
-
Save crakaC/4b9db1221e7c83f401b5800bd69f4b16 to your computer and use it in GitHub Desktop.
テスト用のクライアント証明書を作ってAndroid端末にpushする
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
#!/bin/bash | |
TEMP_DIR=tmp | |
CA_KEY="${TEMP_DIR}/cakey.pem" | |
CA_CERT="${TEMP_DIR}/cacert.pem" | |
CLIENT_KEY="${TEMP_DIR}/client.key" | |
CLIENT_CSR="${TEMP_DIR}/client.csr" | |
CLIENT_CERT="${TEMP_DIR}/client.crt" | |
if [ ! -d $TEMP_DIR ]; then | |
mkdir -p $TEMP_DIR | |
fi | |
set -ex | |
# 自己署名証明書(CA) | |
openssl genpkey -out $CA_KEY -algorithm EC -pkeyopt ec_paramgen_curve:prime256v1 | |
openssl req -x509 -key $CA_KEY -out $CA_CERT -subj "/C=JP/CN=ca.example.com" | |
# クライアント証明書 | |
openssl genpkey -out $CLIENT_KEY -algorithm EC -pkeyopt ec_paramgen_curve:prime256v1 | |
openssl req -new -key $CLIENT_KEY -out $CLIENT_CSR -subj "/C=JP/CN=John Doe/[email protected]" | |
openssl x509 -req -in $CLIENT_CSR -out $CLIENT_CERT -CA $CA_CERT -CAkey $CA_KEY -days 3650 | |
# pfxファイルにまとめる | |
openssl pkcs12 -export -noiter -nomaciter -in $CLIENT_CERT -inkey $CLIENT_KEY -password pass:test -name "Client Cert" -out client.pfx |
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
.PHONY: gen | |
gen: | |
@make clean | |
bash generate_test_client_cert.sh | |
adb push client.pfx /sdcard/Download/client.pfx | |
.PHONY: clean | |
clean: | |
@rm -rf tmp client.* | |
@echo cleaned up! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment