Debian Codegraph @

example/client/README

raw
1 This directory contains a sample EST client application. It utilizes
2 OpenSSL for the SSL stack to be used for HTTP requests, libest for
3 the EST stack, and OpenSSL for certificate and crypto operations.
4 This README assumes the example EST server is already running on the
5 local host and listening to port 8085.
6
7 To build the example on Windows:
8
9 Prerequisite: EST sample applications make use of the GNU getopt library for command line
10 argument parsing. The getopt library is not a part of the C library provided with
11 Microsoft Visual Studio. An open source port for getopt exists under the LGPL3 license
12 and must be acquired separately at the link provided below:
13 http://www.codeproject.com/Articles/157001/Full-getopt-Port-for-Unicode-and-Multibyte-Microso
14 Download the archive which provides the two source files getopt.c and getopt.h and place both
15 source files into the "util" directory.
16
17 1. Set the following environment variables to tell the Gradle build script
18 where to find your installations of OpenSSL and EST
19
20 EST_DIR - must contain the est.lib link file and est.dll binary
21
22
23 set EST_DIR=C:\PathToYourLibraryInstalls\EST
24
25 SSL_DIR - must contain an "include" subdirectory for the OpenSSL header files,
26 a "bin" subdirectory for the OpenSSL dll binaries, and a "lib" subdirectory
27 for the OpenSSL link files
28
29 set SSL_DIR=C:\PathToYourLibraryInstalls\OpenSSL
30
31 PATH - must contain the path to your Visual Studio 2013 VC bin directory
32 prior to any other Visual Studio bin directory and the path to
33 your Gradle executable (which should already be in PATH)
34
35 set PATH=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin;%PATH%
36
37 2. From the "example" directory, type:
38
39 gradle -b build_examples.gradle clean
40
41 to clean out any prior builds and then:
42
43 gradle -b build_examples.gradle build
44
45 to build both estclient and estclient_simple executables.
46 The executables are placed in the directory shown below:
47
48 example\build\exe\estclient\estclient.exe
49
50 example\build\exe\estclient_simple\estclient_simple.exe
51
52 To run the example:
53
54 1. Set LD_LIBRARY_PATH to include the directories where libest.so
55 and libcrypto.so are installed.
56
57 export LD_LIBRARY_PATH=/usr/local/ssl/lib:/usr/local/est/lib
58
59 On Windows, set the PATH environment variables to where
60 libeay32.dll and ssleay32.dll are installed and where est.dll
61 is installed.
62
63 set PATH=C:\PathToYourLibraryInstalls\EST;C:\PathToYourLibraryInstalls\OpenSSL\bin;%PATH%
64
65 2. Set the following environment variable to specify the location
66 of the file containing the CA certificates used for verifying
67 the server. In this example we use the trusted certs for
68 the example EST server:
69
70 export EST_OPENSSL_CACERT=../server/estCA/cacert.crt
71
72 On Windows, the command would appear as follows:
73
74 set EST_OPENSSL_CACERT=..\server\estCA\cacert.crt
75
76 3. Produce a new private key, connect to the EST server listening on port 8085,
77 and request a new certificate. The example EST server uses the user ID and
78 password estuser/estpwd:
79
80 ./estclient -e -s 127.0.0.1 -p 8085 -u estuser -h estpwd -o /tmp
81
82 Note: The new private key is stored at /tmp/key-x-x.pem.
83 To check the cert response, use this command:
84
85 openssl base64 -d -in /tmp/cert-0-0.pkcs7 | \
86 openssl pkcs7 -inform DER -text -print_certs
87
88 Instead of producing a new key along with a (re-)enrollment request,
89 you may use an existing key stored in a PEM file
90 or generate a fresh one yourself, using for instance the following command:
91
92 openssl ecparam -name prime256v1 -genkey -out privkey.pem
93
94 To use an existing private key for the CSR, supply it using the -x option:
95
96 ./estclient -e -s 127.0.0.1 -p 8085 -u estuser -h estpwd -x privkey.pem -o /tmp
97
98 You may also use an existing CSR for enrollment, supplied using the -y option:
99
100 ./estclient -e -s 127.0.0.1 -p 8085 -u estuser -h estpwd -y req.p10 -o /tmp
101
102 4. Optionally you can request attributes as a single request or as
103 part of the enroll. For a simple attributes request use the
104 following command:
105
106 ./estclient -a -s 127.0.0.1 -p 8085 -o /tmp
107
108 To view the list attributes obtained this way, you may use:
109
110 openssl base64 -d -A -in /tmp/csr-0-0.base64 | \
111 openssl asn1parse -inform DER
112
113 Then you can perform the enroll using this command:
114
115 ./estclient -e -a -s 127.0.0.1 -p 8085 -u estuser -h estpwd -o /tmp
116
117 5. Optionally, you can use a certificate to identify the EST client
118 to the server instead of specifying the HTTP user name/password.
119 Now that you've enrolled a certificate in step #3
120 above, you can use that certificate to enroll again. Note, your
121 EST server should be configured not to force HTTP authentication.
122
123 First, convert the pkcs7 cert from step 3 to a PEM cert:
124
125 openssl base64 -d -in /tmp/cert-0-0.pkcs7 | \
126 openssl pkcs7 -inform DER -print_certs -out /tmp/cert-0-0.pem
127
128 Next, save the private key:
129
130 cp /tmp/key-x-x.pem /tmp/savekey.pem
131
132 Next, use this cert as identity to do another enroll operation:
133
134 ./estclient -e -s 127.0.0.1 -p 8085 -c /tmp/cert-0-0.pem \
135 -k /tmp/savekey.pem -o /tmp
136
137 Note: RFC 7030 requires the certificate to be encoded as base64 PKCS7. This encoding isn't
138 very useful for most applications. The estclient includes the --pem-output option as
139 a convenience to convert the newly enrolled certificate to PEM format. When not using
140 the --pem-output option, the following OpenSSL command can be used to convert
141 base64 PKCS7 to PEM:
142
143 openssl base64 -d -in /tmp/newcert.pkcs7 | \
144 openssl pkcs7 -inform DER -print_certs -out /tmp/savecert.pem