2014년 4월 16일 수요일

Self-signed Certificate Makefile(CMake)

매번 self-signed 인증서 만들기 귀찮고 해서 Makefile로 만들어 보았다.

Makefile:
TARGETS=certificate.pem privatekey.pem intermediate.pem privatekey.key

all: $(TARGETS)

clean:
$(RM) $(TARGETS)

privatekey.key:
openssl genrsa -passout pass:1111 -des3 -out $@ 1024

privatekey.pem:privatekey.key
openssl rsa -passin pass:1111 -in $< -out $@

certificate.pem:privatekey.pem
openssl req -batch -utf8 -new -x509 -nodes -sha1 -days 365 -key privatekey.pem -out $@

intermediate.pem:certificate.pem
cp $< $@

약간 응용해서 CMake 버전도 만들어 보았다.

CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)

project(certs)

add_custom_command(OUTPUT privatekey.key
COMMAND openssl genrsa -passout pass:1111 -des3 -out privatekey.key 1024
COMMENT "Generating privatekey"
)

add_custom_command(OUTPUT privatekey.pem
COMMAND openssl rsa -passin pass:1111 -in privatekey.key -out privatekey.pem
COMMENT "Convert privatekey to PEM style"
DEPENDS privatekey.key
)

add_custom_command(OUTPUT certificate.pem
COMMAND openssl req -batch -utf8 -new -x509 -nodes -sha1 -days 365 -key privatekey.pem -out certificate.pem
COMMENT "Generating self-signed certificate"
DEPENDS privatekey.pem
)

add_custom_command(OUTPUT intermediate.pem
COMMAND cp certificate.pem intermediate.pem
COMMENT "Generating intermediate cert"
DEPENDS certificate.pem
)

add_custom_target(certs ALL
DEPENDS intermediate.pem)