~poptart/hosaka-pki

ref: 25cc2d9928ba8db6f4e43fc71063d6de663adbbc hosaka-pki/hosaka-pki.sh -rw-r--r-- 2.1 KiB
25cc2d99 — terrorbyte Started fixing the actual structure. This is actually a real project now 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh -e

readconf() {
	while IFS='=' read -r key val; do
    		[ "${key##\#*}" ] || continue
    		export "$key=$val" 2>/dev/null ||
    		     printf '%s is not a valid variable\n' "$key"
	done < "${1}"
}

sslgenconf() {
	#Generate conf for the CA and if an intermediate is in use, generate
	#for that as well
	sed -e "" < "$"
}

sslgenca() {
	#TODO automation support
	sslcreatedirs

}

ssluseintermediate() {
	case "$USEINTERMEDIATE" in
		y*|Y*)
			return 0
		;;
	*)
		;;
	esac
	return 1
}

sslcreatedirs() {
	mkdir -p "${SSL_CA_DIR}/intermediate" \
		"${SSL_CA_DIR}/certs" \
		"${SSL_CA_DIR}/crl" \
		"${SSL_CA_DIR}/csr" \
		"${SSL_CA_DIR}/private" \
		"${SSL_CA_DIR}/new" && \
	chmod 700 "${SSL_CA_DIR}/private"
	ssluseintermediate && \
		mkdir -p "${SSL_CA_DIR}/intermediate" \
			"${SSL_CA_DIR}/intermediate/certs" \
			"${SSL_CA_DIR}/intermediate/crl" \
			"${SSL_CA_DIR}/intermediate/csr" \
			"${SSL_CA_DIR}/intermediate/private" \
			"${SSL_CA_DIR}/intermediate/new" && \
		chmod 700 "${SSL_CA_DIR}/intermediate/private"
}

sslgenintermediate() {
	_UMASK="$(umask)"
	umask 077
	#TODO check if files exist
	#TODO check if ca on disk and if not exit
	printf "generating intermediate ca\\n"
	#TODO support automation ie, symm keys stored on disk
	openssl ecparam -genkey -name secp521r1 | openssl ec -aes-256-cbc \
		-out "${SSL_CA_DIR}/intermediate/private/intermediate.key.pem"
	printf "generating intermediate csr\\n"
	openssl req -config "${SSL_CA_DIR}/openssl.cnf" -new -sha512 \
		-key "${SSL_CA_DIR}/intermediate/private/intermediate.key.pem" \
		-out "${SSL_CA_DIR}/intermediate/csr/intermediate.csr.pem"
	printf "signing intermediate ca\\nenter ca cert password\\n"
	openssl ca -config "${SSL_CA_DIR}/openssl.cnf" \
		-extensions v3_intermediate_ca -days "$CADAYSVALID" -notext \
		-md "$MDALGORITHM" \
		-in "${SSL_CA_DIR}/intermediate/csr/intermediate.csr.pem" \
		-out "${SSL_CA_DIR}/intermediate/certs/intermediate.cert.pem"
	umask "${_UMASK}"
}

sslcheckcaondisk() {
	[ -f "$SSL_CA_DIR/private/ca.key.pem" ]
}
#
#sslsignserver() {
#
#}
#
#sslsignclient() {
#
#}
#sslcheckexpir() {
#
#}