4 |
- |
1 |
######################################################################
|
|
|
2 |
#
|
|
|
3 |
# Make file to be installed in /etc/raddb/certs to enable
|
|
|
4 |
# the easy creation of certificates.
|
|
|
5 |
#
|
|
|
6 |
# See the README file in this directory for more information.
|
|
|
7 |
#
|
|
|
8 |
# $Id$
|
|
|
9 |
#
|
|
|
10 |
######################################################################
|
|
|
11 |
|
|
|
12 |
DH_KEY_SIZE = 1024
|
|
|
13 |
|
|
|
14 |
#
|
|
|
15 |
# Set the passwords
|
|
|
16 |
#
|
|
|
17 |
PASSWORD_SERVER = `grep output_password server.cnf | sed 's/.*=//;s/^ *//'`
|
|
|
18 |
PASSWORD_CA = `grep output_password ca.cnf | sed 's/.*=//;s/^ *//'`
|
|
|
19 |
PASSWORD_CLIENT = `grep output_password client.cnf | sed 's/.*=//;s/^ *//'`
|
|
|
20 |
|
|
|
21 |
USER_NAME = `grep emailAddress client.cnf | grep '@' | sed 's/.*=//;s/^ *//'`
|
|
|
22 |
CA_DEFAULT_DAYS = `grep default_days ca.cnf | sed 's/.*=//;s/^ *//'`
|
|
|
23 |
|
|
|
24 |
######################################################################
|
|
|
25 |
#
|
|
|
26 |
# Make the necessary files, but not client certificates.
|
|
|
27 |
#
|
|
|
28 |
######################################################################
|
|
|
29 |
.PHONY: all
|
|
|
30 |
all: index.txt serial dh random server ca
|
|
|
31 |
|
|
|
32 |
.PHONY: client
|
|
|
33 |
client: client.pem
|
|
|
34 |
|
|
|
35 |
.PHONY: ca
|
|
|
36 |
ca: ca.der
|
|
|
37 |
|
|
|
38 |
.PHONY: server
|
|
|
39 |
server: server.pem server.vrfy
|
|
|
40 |
|
|
|
41 |
######################################################################
|
|
|
42 |
#
|
|
|
43 |
# Diffie-Hellman parameters
|
|
|
44 |
#
|
|
|
45 |
######################################################################
|
|
|
46 |
dh:
|
|
|
47 |
openssl dhparam -out dh $(DH_KEY_SIZE)
|
|
|
48 |
|
|
|
49 |
######################################################################
|
|
|
50 |
#
|
|
|
51 |
# Create a new self-signed CA certificate
|
|
|
52 |
#
|
|
|
53 |
######################################################################
|
|
|
54 |
ca.key ca.pem: ca.cnf
|
|
|
55 |
openssl req -new -x509 -keyout ca.key -out ca.pem \
|
|
|
56 |
-days $(CA_DEFAULT_DAYS) -config ./ca.cnf
|
|
|
57 |
|
|
|
58 |
ca.der: ca.pem
|
|
|
59 |
openssl x509 -inform PEM -outform DER -in ca.pem -out ca.der
|
|
|
60 |
|
|
|
61 |
######################################################################
|
|
|
62 |
#
|
|
|
63 |
# Create a new server certificate, signed by the above CA.
|
|
|
64 |
#
|
|
|
65 |
######################################################################
|
|
|
66 |
server.csr server.key: server.cnf
|
|
|
67 |
openssl req -new -out server.csr -keyout server.key -config ./server.cnf
|
|
|
68 |
|
|
|
69 |
server.crt: server.csr ca.key ca.pem
|
|
|
70 |
openssl ca -batch -keyfile ca.key -cert ca.pem -in server.csr -key $(PASSWORD_CA) -out server.crt -extensions xpserver_ext -extfile xpextensions -config ./server.cnf
|
|
|
71 |
|
|
|
72 |
server.p12: server.crt
|
|
|
73 |
openssl pkcs12 -export -in server.crt -inkey server.key -out server.p12 -passin pass:$(PASSWORD_SERVER) -passout pass:$(PASSWORD_SERVER)
|
|
|
74 |
|
|
|
75 |
server.pem: server.p12
|
|
|
76 |
openssl pkcs12 -in server.p12 -out server.pem -passin pass:$(PASSWORD_SERVER) -passout pass:$(PASSWORD_SERVER)
|
|
|
77 |
|
|
|
78 |
.PHONY: server.vrfy
|
|
|
79 |
server.vrfy: ca.pem
|
|
|
80 |
openssl verify -CAfile ca.pem server.pem
|
|
|
81 |
|
|
|
82 |
######################################################################
|
|
|
83 |
#
|
|
|
84 |
# Create a new client certificate, signed by the the above server
|
|
|
85 |
# certificate.
|
|
|
86 |
#
|
|
|
87 |
######################################################################
|
|
|
88 |
client.csr client.key: client.cnf
|
|
|
89 |
openssl req -new -out client.csr -keyout client.key -config ./client.cnf
|
|
|
90 |
|
|
|
91 |
client.crt: client.csr ca.pem ca.key
|
|
|
92 |
openssl ca -batch -keyfile ca.key -cert ca.pem -in client.csr -key $(PASSWORD_CA) -out client.crt -extensions xpclient_ext -extfile xpextensions -config ./client.cnf
|
|
|
93 |
|
|
|
94 |
client.p12: client.crt
|
|
|
95 |
openssl pkcs12 -export -in client.crt -inkey client.key -out client.p12 -passin pass:$(PASSWORD_CLIENT) -passout pass:$(PASSWORD_CLIENT)
|
|
|
96 |
|
|
|
97 |
client.pem: client.p12
|
|
|
98 |
openssl pkcs12 -in client.p12 -out client.pem -passin pass:$(PASSWORD_CLIENT) -passout pass:$(PASSWORD_CLIENT)
|
|
|
99 |
cp client.pem $(USER_NAME).pem
|
|
|
100 |
|
|
|
101 |
.PHONY: client.vrfy
|
|
|
102 |
client.vrfy: server.pem client.pem
|
|
|
103 |
c_rehash .
|
|
|
104 |
openssl verify -CApath . client.pem
|
|
|
105 |
|
|
|
106 |
######################################################################
|
|
|
107 |
#
|
|
|
108 |
# Miscellaneous rules.
|
|
|
109 |
#
|
|
|
110 |
######################################################################
|
|
|
111 |
index.txt:
|
|
|
112 |
@touch index.txt
|
|
|
113 |
|
|
|
114 |
serial:
|
|
|
115 |
@echo '01' > serial
|
|
|
116 |
|
|
|
117 |
random:
|
|
|
118 |
@if [ -c /dev/urandom ] ; then \
|
|
|
119 |
dd if=/dev/urandom of=./random count=10 >/dev/null 2>&1; \
|
|
|
120 |
else \
|
|
|
121 |
date > ./random; \
|
|
|
122 |
fi
|
|
|
123 |
|
|
|
124 |
print:
|
|
|
125 |
openssl x509 -text -in server.crt
|
|
|
126 |
|
|
|
127 |
printca:
|
|
|
128 |
openssl x509 -text -in ca.pem
|
|
|
129 |
|
|
|
130 |
clean:
|
|
|
131 |
@rm -f *~ *old client.csr client.key client.crt client.p12 client.pem
|
|
|
132 |
|
|
|
133 |
#
|
|
|
134 |
# Make a target that people won't run too often.
|
|
|
135 |
#
|
|
|
136 |
destroycerts:
|
|
|
137 |
rm -f *~ dh *.csr *.crt *.p12 *.der *.pem *.key index.txt* \
|
|
|
138 |
serial* random *\.0 *\.1
|