Files @ 5a918cd2502e
Branch filter:

Location: gimmecert/docs/usage.rst

5a918cd2502e 14.4 KiB text/prs.fallenstein.rst Show Annotation Show as Raw Download as Raw
branko
Noticket: Switching to development version.
  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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
.. Copyright (C) 2018, 2020, 2024 Branko Majic

   This file is part of Gimmecert documentation.

   This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
   Unported License. To view a copy of this license, visit
   http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
   Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.


Usage
=====

Gimmecert provides a simple and clean CLI interface for all actions.

Description of all available commands, manadatory arguments, and
optional arguments is also made available via CLI by either using the
help flag (``-h`` / ``--help``) or help command.

Running the tool without any command or argument will output short
usage instructions listing available commands.

To get more detailed general help on tool usage, and list of available
commands with short description on what they do, run one of the
following::

  gimmecert -h
  gimmecert --help
  gimmecert help

To get more details on specific command, along what mandatory and
positional arguments are available, simply provide the help flag when
running them. For example::

  gimmecert init -h
  gimmecert init --help


Quickstart
----------

Gimmecert stores all of its artefacts within the ``.gimmecert``
sub-directory (relative to where the command is run).

Start off by switching to your project directory::

  cd ~/myproject/

Initialise the necessary directories and CA hierarchy::

  gimmecert init

This will create a single CA, providing the following artifacts:

- ``.gimmecert/ca/level1.key.pem`` (private key)
- ``.gimmecert/ca/level1.cert.pem`` (certificate)
- ``.gimmecert/ca/chain-full.cert.pem`` (full CA chain, in this case
  same as ``level1.cert.pem``)

Issue a server certificate::

  gimmecert server myserver1

This will create the following artifacts for the server:

- ``.gimmecert/server/myserver1.key.pem`` (private key)
- ``.gimmecert/server/myserver1.cert.pem`` (certificate)

Resulting certificate will include its own name as one of the DNS
subject alternative names.

Issue a client certificate::

  gimmecert client myclient1

This will create the following artifacts for the client:

- ``.gimmecert/client/myclient1.key.pem`` (private key)
- ``.gimmecert/client/myclient1.cert.pem`` (certificate)

Issue a server certificate with additional DNS subject alternative
names::

  gimmecert server myserver2 myserver2.local service.example.com

This will create the following artifacts for the server:

- ``.gimmecert/server/myserver2.key.pem`` (private key)
- ``.gimmecert/server/myserver2.cert.pem`` (certificate)

This time around, the ``myserver2`` certificate will include
``myserver2``, ``myserver2.local``, and ``service.example.com`` as DNS
subject alternative names.

Issue a server certificate by passing-in certificate signing request
(CSR) from which the public key should be extracted::

  openssl req -new -newkey rsa:2048 -nodes -keyout "/tmp/myserver3.key.pem" -subj "/CN=ignoredname" -out "/tmp/myserver3.csr.pem"
  gimmecert server --csr /tmp/myserver3.csr.pem myserver3

This will create the following artifacts for the server:

- ``.gimmecert/server/myserver3.csr.pem`` (CSR)
- ``.gimmecert/server/myserver3.cert.pem`` (certificate)

Renew existing certificates, keeping the same private key and naming::

  gimmecert renew server myserver1
  gimmecert renew server myclient1

Show information about CA hierarchy and issued certificates::

  gimmecert status


Initialisation
--------------

Initialisation has to be run one before being being able to issue
server and client certificates. This is done with::

  gimmecert init

Initialisation will:

- Set-up a local directory.
- Initialise the CA hierarchy used for issuing server and client
  certificates. This includes creation of CA private keys (RSA 2048),
  as well as issuance of corresponding certificates.

If you attempt to run initialisation from the same directory twice,
Gimmecert will refuse to do so. Should you need to recreate the
hierarchy, simply remove the ``.gimmcert/`` directory, and start
over. Keep in mind you will need to throw away all of generated key
material and certificates.

The following directories are created as part of initialisation
process:

- ``.gimmecert/``, base directory.
- ``.gimmecert/ca/``, used for storing CA private keys and
  certificates.
- ``.gimmecert/server/``, used for storing server private keys and
  certificates.
- ``.gimmecert/client/``, used for storing client private keys and
  certificates.

Both CA private keys and certificates are stored as OpenSSL-style PEM
files. The naming convention for keys is ``levelN.key.pem``, while for
certificates it is ``levelN.cert.pem``. ``N`` corresponds to CA
level. Level 1 is the root/self-signed CA, level 2 is CA signed by
level 1 CA and so forth.

In addition to individual CA certificates, Gimmecert will also store
the full certificate chain (including the level 1 CA certificate) in
file ``chain-full.cert.pem``.

Subject DN naming convention for all CAs is ``CN=BASENAME Level N
CA``. ``N`` is the CA level, while ``BASENAME`` is by default equal to
current (working) directory name.

By defualt the tool will initialise a one-level CA hierarchy
(i.e. just the root CA).

Both the base name and CA hierarchy depth can be easily overridden by
providing options (both long and short forms are available)::

  gimmecert init --ca-base-name "My Project" --ca-hierarchy-depth 3
  gimmecert init -b "My Project" -d 3

The above examples would both result in creation of the following CA
artifacts:

- ``.gimmecert/ca/level1.key.pem``
- ``.gimmecert/ca/level1.cert.pem`` (subject DN ``My Project Level 1 CA``)
- ``.gimmecert/ca/level2.key.pem``
- ``.gimmecert/ca/level2.cert.pem`` (subject DN ``My Project Level 2 CA``)
- ``.gimmecert/ca/level3.key.pem``
- ``.gimmecert/ca/level3.cert.pem`` (subject DN ``My Project Level 3 CA``)
- ``.gimmecert/ca/chain-full.cert.pem``


Issuing server certificates
---------------------------

Server certificates can be issued once the initialisation is
complete. Command supports passing-in additional DNS subject
alternative names as additional positional arguments::

  gimmecert server NAME [DNS_NAME [DNS_NAME ...]]

The command will:

- Generate a 2048-bit RSA private key.
- Issue a certificate associated with the generated private key using
  the leaf CA (the one deepest in hierachy).

Resulting private keys and certificates are stored within directory
``.gimmecert/server/``. Private key naming convention is
``NAME.key.pem``, while certificates are stored as
``NAME.cert.pem``. In both cases the OpenSSL-style PEM format is used
for storage.

Subject DN naming convention for server certificates is ``CN=NAME``,
where ``NAME`` is passed-in via positional argument.

By default the certificate will include the passed-in server name as
one of its DNS subject alternative names, but additional DNS names can
be passed-in as well. For example::

  gimmecert server myserver myserver.local service.example.com

Key usage and extended key usage in certificate are set typical TLS
server use (e.g. *digital signature* + *key encipherment* for KU, and
*TLS WWW server authentication* for EKU).

Rerunning the command will not overwrite existing data.

.. note::
   For changing the list of additional subject alternative names
   included in already issued server certificates, see the
   ``--update-dns-names`` option in the ``gimmecert renew`` command.

In addition to generating a private key, it is also possible to
pass-in a certificate signing request (CSR). If specified path is a
dash (``-``), CSR is read from standard input. The resulting
certificate will contain public key from the CSR. All other
information stored in the CSR (naming, extensions) is ignored. For
example::

  # Issue server certificate by passing-in path to a generated CSR.
  gimmecert server --csr /tmp/myown.csr.pem myserver

  # Issue server certificate by reading the CSR from standard input.
  gimmecert server --csr - myserver

  # Issue server certificate by reading the CSR from standard input,
  # using redirection.
  gimmecert server --csr - myserver < /tmp/myown.csr.pem

The passed-in CSR will be stored alongside certificate, under
``.gimmecert/server/NAME.csr.pem``.


Issuing client certificates
---------------------------

Client certificates can be issued once the initialisation is
complete. Command accepts a single positional argument::

  gimmecert client NAME

The command will:

- Generate a 2048-bit RSA private key.
- Issue a certificate associated with the generated private key using
  the leaf CA (the one deepest in hierachy).

Rerunning the command will not overwrite existing data.

Resulting private keys and certificates are stored within directory
``.gimmecert/client/``. Private key naming convention is
``NAME.key.pem``, while certificates are stored as
``NAME.cert.pem``. In both cases the OpenSSL-style PEM format is used
for storage.

Subject DN naming convention for client certificates is ``CN=NAME``,
where ``NAME`` is passed-in via positional argument.

Key usage and extended key usage in certificate are set typical TLS
client use (e.g. *digital signature* + *key encipherment* for KU, and
*TLS WWW client authentication* for EKU).

In addition to generating a private key, it is also possible to
pass-in a certificate signing request (CSR). If specified path is a
dash (``-``), CSR is read from standard input. The resulting
certificate will contain public key from the CSR. All other
information stored in the CSR (naming, extensions) is ignored. For
example::

  # Issue client certificate by passing-in path to a generated CSR.
  gimmecert client --csr /tmp/myown.csr.pem myclient

  # Issue client certificate by reading the CSR from standard input.
  gimmecert client --csr - myclient

  # Issue client certificate by reading the CSR from standard input,
  # using redirection.
  gimmecert client --csr - myclient < /tmp/myown.csr.pem

The passed-in CSR will be stored alongside certificate, under
``.gimmecert/client/NAME.csr.pem``.


Renewing certificates
---------------------

Both client and server certificates can be renewed by simply providing
the type and name. This is useful when a certificate has expired, and
it should be renewed with identical naming and private key. Command
requires two positional argumensts::

  gimmecert renew (server|client) NAME

The command will:

- By default keep the existing private key generated for end entity
  (new one can be requested as well).
- Re-use naming and any extensions stored in existing certificate.
- Overwrite the existing certificate with a new one.
- Show information where the artifacts can be grabbed from.

To also generate a new private key during renewal, use the
``--new-private-key`` or ``-p`` option. For example::

  gimmecert renew --new-private-key server myserver
  gimmecert renew -p server my server

To replace the existing private key or CSR during renewal with a new
CSR, use the ``--csr`` option and pass along path to the file. If
specified path is a dash (``-``), CSR is read from standard input. For
example::

  gimmecert renew --csr /tmp/myserver.csr.pem server myserver
  gimmecert renew --csr - server myserver < /tmp/myserver.csr.pem
  gimmecert renew --csr - client myclient

If you initially made a mistake when providing additional DNS subject
alternative names for a server certificate, you can easily fix this
with the ``--update-dns-names`` or ``-u`` option::

  # Replace existing additional names with just one name.
  gimmecert renew server --update-dns-names "correctname.example.com" myserver

  # Replace existing additional names with mutliple names.
  gimmecert renew server --update-dns-names "correctname1.example.com,correctname2.example.com" myserver 

  # Remove additional names altogether.
  gimmecert renew server --update-dns-names "" myserver


Getting information about CA hierarchy and issued certificates
--------------------------------------------------------------

In order to show information about the CA hierarchy and issued
certificates simply run the status command::

  gimmecert status

The command will:

- Show default key algorithm used by the CA hierarchy.
- Show information about every CA in generated hierarchy (subject DN,
  validity, certificate paths, whether the CA is used for issuing end
  entity certificates).
- Show information about all issued server certificates (subject DN,
  DNS subject alternative names, key algorithm, validity, private key
  or CSR path, certificate path).
- Show information about all issued client certificates (subject DN,
  validity, key algorithm, private key or CSR path, certificate path).

Validity of all certificates is shown in UTC.

Command can also be used for checking if Gimmecert has been
initialised in local directory or not.


Key algorithm
-------------

Gimmecert by default generates 2048-bit RSA private keys for the
entire CA hierarchy.

The key algorithm and parameters can also be explicitly specified for
every command that generates private keys: ``init``, ``server``,
``client``, and ``renew``. This can be done using either the long form
(``--key-specification``) or short form (``-k``) option, followed by
the formatted key specification that designates the key algorithm and
its associated generation parameters.

To request an RSA key, use the format ``rsa:KEY_SIZE``. For ECDSA, the
format is ``ecdsa:CURVE_NAME``. Minimal size for RSA keys is ``512``,
while for ECDSA you can pick between one of the following elliptic
curves:

- secp192r1
- secp224r1
- secp256k1
- secp256r1
- secp384r1
- secp521r1

Key specification picked for the CA hierarchy is also by default used
when generating private keys for end entities when no explicit key
specification is provided. The sole exception to this rule is key
generation during renewal. During renewals, if a new private key is
requested, the current key algorithm and generation parameters of an
entity are preserved.

The ``--key-specification`` option is mutually exclusive with the
``--csr`` option. In case of the ``renew`` command it can only be used
together with the ``--new-private-key`` option.

Here are some examples on key specification usage::

  # Initialise CA hierarchy using 3072-bit RSA keys.
  gimmecert init --key-specification rsa:3072

  # Issue a server certificate using the default key specification of
  # the CA hierarchy.
  gimmecert server myserver

  # Issue a client certificate using ECDSA key specification.
  gimmecert client -k ecdsa:secp521r1 myclient

  # Renew a server certificate while requesting a new, 1024-bit RSA,
  # private key.
  gimmecert renew myserver --new-private-key -k rsa:1024