Use DES_set_key_unchecked().
[heimdal.git] / doc / hx509.texi
blob4a4078e8188dc88bf7788ebe0aa320ec0dc36443
1 \input texinfo @c -*- texinfo -*-
2 @c %**start of header
3 @c $Id$
4 @setfilename hx509.info
5 @settitle HX509
6 @iftex
7 @afourpaper
8 @end iftex
9 @c some sensible characters, please?
10 @tex
11 \input latin1.tex
12 @end tex
13 @setchapternewpage on
14 @syncodeindex pg cp
15 @c %**end of header
17 @include vars.texi
19 @set UPDATED $Date$
20 @set VERSION @value{PACKAGE_VERSION}
21 @set EDITION 1.0
23 @ifinfo
24 @dircategory Security
25 @direntry
26 * hx509: (hx509).               The X.509 distribution from KTH
27 @end direntry
28 @end ifinfo
30 @c title page
31 @titlepage
32 @title HX509
33 @subtitle X.509 distribution from KTH
34 @subtitle Edition @value{EDITION}, for version @value{VERSION}
35 @subtitle 2008
36 @author Love Hörnquist Åstrand
37 @author last updated @value{UPDATED}
39 @def@copynext{@vskip 20pt plus 1fil@penalty-1000}
40 @def@copyrightstart{}
41 @def@copyrightend{}
42 @page
43 @copyrightstart
44 Copyright (c) 1994-2008 Kungliga Tekniska Högskolan
45 (Royal Institute of Technology, Stockholm, Sweden).
46 All rights reserved.
48 Redistribution and use in source and binary forms, with or without
49 modification, are permitted provided that the following conditions
50 are met:
52 1. Redistributions of source code must retain the above copyright
53    notice, this list of conditions and the following disclaimer.
55 2. Redistributions in binary form must reproduce the above copyright
56    notice, this list of conditions and the following disclaimer in the
57    documentation and/or other materials provided with the distribution.
59 3. Neither the name of the Institute nor the names of its contributors
60    may be used to endorse or promote products derived from this software
61    without specific prior written permission.
63 THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
64 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
65 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
66 ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
67 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
68 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
69 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
70 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
71 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
72 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
73 SUCH DAMAGE.
75 @copynext
77 Copyright (c) 1988, 1990, 1993
78      The Regents of the University of California.  All rights reserved.
80 Redistribution and use in source and binary forms, with or without
81 modification, are permitted provided that the following conditions
82 are met:
84 1. Redistributions of source code must retain the above copyright
85    notice, this list of conditions and the following disclaimer.
87 2. Redistributions in binary form must reproduce the above copyright
88    notice, this list of conditions and the following disclaimer in the
89    documentation and/or other materials provided with the distribution.
91 3. Neither the name of the University nor the names of its contributors
92    may be used to endorse or promote products derived from this software
93    without specific prior written permission.
95 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
96 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
97 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
98 ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
99 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
100 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
101 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
102 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
103 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
104 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
105 SUCH DAMAGE.
107 @copynext
109 Copyright 1992 Simmule Turner and Rich Salz.  All rights reserved.
111 This software is not subject to any license of the American Telephone
112 and Telegraph Company or of the Regents of the University of California.
114 Permission is granted to anyone to use this software for any purpose on
115 any computer system, and to alter it and redistribute it freely, subject
116 to the following restrictions:
118 1. The authors are not responsible for the consequences of use of this
119    software, no matter how awful, even if they arise from flaws in it.
121 2. The origin of this software must not be misrepresented, either by
122    explicit claim or by omission.  Since few users ever read sources,
123    credits must appear in the documentation.
125 3. Altered versions must be plainly marked as such, and must not be
126    misrepresented as being the original software.  Since few users
127    ever read sources, credits must appear in the documentation.
129 4. This notice may not be removed or altered.
131 @copynext
133 IMath is Copyright 2002-2005 Michael J. Fromberger
134 You may use it subject to the following Licensing Terms:
136 Permission is hereby granted, free of charge, to any person obtaining
137 a copy of this software and associated documentation files (the
138 "Software"), to deal in the Software without restriction, including
139 without limitation the rights to use, copy, modify, merge, publish,
140 distribute, sublicense, and/or sell copies of the Software, and to
141 permit persons to whom the Software is furnished to do so, subject to
142 the following conditions:
144 The above copyright notice and this permission notice shall be
145 included in all copies or substantial portions of the Software.
147 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
148 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
149 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
150 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
151 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
152 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
153 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
155 @copyrightend
156 @end titlepage
158 @macro manpage{man, section}
159 @cite{\man\(\section\)}
160 @end macro
162 @c Less filling! Tastes great!
163 @iftex
164 @parindent=0pt
165 @global@parskip 6pt plus 1pt
166 @global@chapheadingskip = 15pt plus 4pt minus 2pt
167 @global@secheadingskip = 12pt plus 3pt minus 2pt
168 @global@subsecheadingskip = 9pt plus 2pt minus 2pt
169 @end iftex
170 @ifinfo
171 @paragraphindent 0
172 @end ifinfo
174 @ifnottex
175 @node Top, Introduction, (dir), (dir)
176 @top Heimdal
177 @end ifnottex
179 This manual is last updated @value{UPDATED} for version
180 @value{VERSION} of hx509.
182 @menu
183 * Introduction::
184 * What is X.509 ?::
185 * Setting up a CA::
186 * CMS signing and encryption::
187 * Certificate matching::
188 * Software PKCS 11 module::
190 @detailmenu
191  --- The Detailed Node Listing ---
193 Setting up a CA
195 @c * Issuing certificates::
196 * Creating a CA certificate::
197 * Issuing certificates::
198 * Issuing CRLs::
199 @c * Issuing a proxy certificate::
200 @c * Creating a user certificate::
201 @c * Validating a certificate::
202 @c * Validating a certificate path::
203 * Application requirements::
205 CMS signing and encryption
207 * CMS background::
209 Certificate matching
211 * Matching syntax::
213 Software PKCS 11 module
215 * How to use the PKCS11 module::
217 @end detailmenu
218 @end menu
220 @node Introduction, What is X.509 ?, Top, Top
221 @chapter Introduction
223 hx509 is a somewhat complete X.509 stack that can handle CMS messages
224 (crypto system used in S/MIME and Kerberos PK-INIT) and basic
225 certificate processing tasks, path construction, path validation, OCSP
226 and CRL validation, PKCS10 message construction, CMS Encrypted (shared
227 secret encrypted), CMS SignedData (certificate signed), and CMS
228 EnvelopedData (certificate encrypted).
230 hx509 can use PKCS11 tokens, PKCS12 files, PEM files, DER encoded files.
232 @node What is X.509 ?, Setting up a CA, Introduction, Top
233 @chapter What is X.509, PKIX, PKCS7 and CMS ? 
235 X.509 is from the beginning created by CCITT (later ITU) for the X.500
236 directory service. But today when people are talking about X.509 they
237 are commonly referring to IETF's PKIX Certificate and CRL Profile of the
238 X.509 v3 certificate standard, as specified in RFC 3280.
240 ITU continues to develop the X.509 standard together in a complicated
241 dance with IETF.
243 X.509 is public key based security system that have associated data
244 stored within a so called certificate. From the beginning X.509 was a
245 strict hierarchical system with one root. This didn't not work so over
246 time X.509 got support for multiple policy roots, bridges, and mesh
247 solutions. You can even use it as a peer to peer system, but this is not
248 very common.
250 @section Type of certificates
252 There are several flavors of certificate in X.509.
254 @itemize @bullet
256 @item Trust anchors
258 Trust anchors are strictly not certificate, but commonly stored in
259 certificate since they are easier to handle then. Trust anchor are the
260 keys that you trust to validate other certificate. This is done by
261 building a path from the certificate you wan to validate to to any of
262 the trust anchors you have.
264 @item End Entity (EE) certificates
266 End entity certificates is the most common type of certificate. End
267 entity certificates can't issue certificate them-self and is used to
268 authenticate and authorize user and services.
270 @item Certification Authority (CA) certificates
272 Certificate authority are certificates that have the right to issue
273 other certificate, they may be End entity certificates or Certificate
274 Authority certificates. There is no limit to how many certificates a CA
275 may issue, but there might other restrictions, like the maximum path
276 depth.
278 @item Proxy certificates
280 Remember that End Entity can't issue certificates by them own, it's not
281 really true. There there is an extension called proxy certificates,
282 defined in RFC3820, that allows certificates to be issued by end entity
283 certificates. The service that receives the proxy certificates must have
284 explicitly turned on support for proxy certificates, so their use is
285 somewhat limited.
287 Proxy certificates can be limited by policy stored in the certificate to
288 what they can be used for. This allows users to delegate the proxy
289 certificate to services (by sending over the certificate and private
290 key) so the service can access services on behalf of the user.
292 One example of this would be a print service. The user wants to print a
293 large job in the middle of the night when the printer isn't used that
294 much, so the user creates a proxy certificate with the policy that it
295 can only be used to access files related to this print job, creates the
296 print job description and send both the description and proxy
297 certificate with key over to print service. Later at night will the
298 print service, without the help of the user, access the files for the
299 the print job using the proxy certificate and print the job. Because of
300 the policy (limitation) in the proxy certificate, it can't be used for
301 any other purposes.
303 @end itemize
305 @section Building a path
307 Before validating a path the path must be constructed. Given a
308 certificate (EE, CA, Proxy, or any other type), the path construction
309 algorithm will try to find a path to one of the trust anchors.
311 It start with looking at whom issued the certificate, by name or Key
312 Identifier, and tries to find that certificate while at the same time
313 evaluates the policy.
315 @node Setting up a CA, Creating a CA certificate, What is X.509 ?, Top
316 @chapter Setting up a CA
318 Do not let this chapter scare you off, it's just to give you an idea how
319 to complicated setting up a CA can be. If you are just playing around,
320 skip all this and go to the next chapter, @pxref{Creating a CA
321 certificate}.
323 Creating a CA certificate should be more the just creating a
324 certificate, there is the policy of the CA. If it's just you and your
325 friend that is playing around then it probably doesn't matter what the
326 policy is. But then it comes to trust in an organisation, it will
327 probably matter more whom your users and sysadmins will find it
328 acceptable to trust.
330 At the same time, try to keep thing simple, it's not very hard to run a
331 Certificate authority and the process to get new certificates should
332 simple.
334 Fill all this in later.
336 How do you trust your CA.
338 What is the CA responsibility.
340 Review of CA activity.
342 How much process should it be to issue certificate.
344 Who is allowed to issue certificates.
346 Who is allowed to requests certificates.
348 How to handle certificate revocation, issuing CRLs and maintain OCSP
349 services.
351 @node Creating a CA certificate, Issuing certificates, Setting up a CA, Top
352 @section Creating a CA certificate
354 This section describes how to create a CA certificate and what to think
355 about.
357 @subsection Lifetime CA certificate
359 You probably want to create a CA certificate with a long lifetime, 10
360 years at the shortest. This because you don't want to push out the
361 certificate (as a trust anchor) to all you users once again when the old
362 one just expired. A trust anchor can't really expire, but not all
363 software works that way.
365 Keep in mind the security requirements might be different 10-20 years
366 into the future. For example, SHA1 is going to be withdrawn in 2010, so
367 make sure you have enough buffering in your choice of digest/hash
368 algorithms, signature algorithms and key lengths.
370 @subsection Create a CA certificate
372 This command below will create a CA certificate in the file ca.pem.
374 @example
375 hxtool issue-certificate \
376     --self-signed \
377     --issue-ca \
378     --generate-key=rsa \
379     --subject="CN=CertificateAuthority,DC=test,DC=h5l,DC=se" \
380     --lifetime=10years \
381     --certificate="FILE:ca.pem"
382 @end example
384 @subsection Extending lifetime of a CA certificate
386 You just realised that your CA certificate is going to expire soon and
387 that you need replace it with something else, the easiest way to do that
388 is to extend the lifetime of your CA certificate.
390 The example below will extend the CA certificate 10 years into the
391 future. You should compare this new certificate if it contains all the
392 special tweaks as the old certificate had.
394 @example
395 hxtool issue-certificate \
396     --self-signed \
397     --issue-ca \
398     --lifetime="10years" \
399     --template-certificate="FILE:ca.pem" \
400     --template-fields="serialNumber,notBefore,subject,SPKI" \
401     --ca-private-key=FILE:ca.pem \
402     --certificate="FILE:new-ca.pem"
403 @end example
405 @subsection Subordinate CA
407 This example create a new subordinate certificate authority.
409 @example
410 hxtool issue-certificate \
411     --ca-certificate=FILE:ca.pem \
412     --issue-ca \
413     --generate-key=rsa \
414     --subject="CN=CertificateAuthority,DC=dev,DC=test,DC=h5l,DC=se" \
415     --certificate="FILE:dev-ca.pem"
416 @end example
419 @node Issuing certificates, Issuing CRLs, Creating a CA certificate, Top
420 @section Issuing certificates
422 First you'll create a CA certificate, after that you have to deal with
423 your users and servers and issue certificate to them.
425 CA can generate the key for the user.
427 Can receive PKCS10 certificate requests from the users. PKCS10 is a
428 request for a certificate. The user can specified what DN the user wants
429 and what public key. To prove the user have the key, the whole request
430 is signed by the private key of the user.
432 @subsection Name space management
434 What people might want to see.
436 Re-issue certificates just because people moved within the organization.
438 Expose privacy information.
440 Using Sub-component name (+ notation).
442 @subsection Certificate Revocation, CRL and OCSP
444 Sonetimes people loose smartcard or computers and certificates have to
445 be make not valid any more, this is called revoking certificates. There
446 are two main protocols for doing this Certificate Revocations Lists
447 (CRL) and Online Certificate Status Protocol (OCSP).
449 If you know that the certificate is destroyed then there is no need to
450 revoke the certificate because it can not be used by someone else.
452 The main reason you as a CA administrator have to deal with CRLs however
453 will be that some software require there to be CRLs. Example of this is
454 Windows, so you have to deal with this somehow.
456 @node Issuing CRLs, Application requirements, Issuing certificates, Top
457 @section Issuing CRLs
459 Create an empty CRL with not certificates revoked. Default expiration
460 value is one year from now.
462 @example
463 hxtool crl-sign \
464         --crl-file=crl.der \
465         --signer=FILE:ca.pem
466 @end example
468 Create a CRL with all certificates in the directory
469 @file{/path/to/revoked/dir} included in the CRL as revoked.  Also make
470 it expire one month from now.
472 @example
473 hxtool crl-sign \
474         --crl-file=crl.der \
475         --signer=FILE:ca.pem \
476         --lifetime='1 month' \
477         DIR:/path/to/revoked/dir
478 @end example
480 @node Application requirements, CMS signing and encryption, Issuing CRLs, Top
481 @section Application requirements
483 Application have different requirements on certificates. This section
484 tries to expand what they are and how to use hxtool to generate
485 certificates for those services.
487 @subsection HTTPS - server
489 @example
490 hxtool issue-certificate \
491           --subject="CN=www.test.h5l.se,DC=test,DC=h5l,DC=se" \
492           --type="https-server" \
493           --hostname="www.test.h5l.se" \
494           --hostname="www2.test.h5l.se" \
495           ...
496 @end example
498 @subsection HTTPS - client
500 @example
501 hxtool issue-certificate \
502           --subject="UID=testus,DC=test,DC=h5l,DC=se" \
503           --type="https-client" \
504           ...
505 @end example
507 @subsection S/MIME - email
509 There are two things that should be set in S/MIME certificates, one or
510 more email addresses and an extended eku usage (EKU), emailProtection.
512 The email address format used in S/MIME certificates is defined in
513 RFC2822, section 3.4.1 and it should be an ``addr-spec''.
515 There are two ways to specifify email address in certificates. The old
516 ways is in the subject distinguished name, this should not be used. The
517 new way is using a Subject Alternative Name (SAN).
519 But even though email address is stored in certificates, they don't need
520 to, email reader programs are required to accept certificates that
521 doesn't have either of the two methods of storing email in certificates.
522 In that case, they try to protect the user by printing the name of the
523 certificate instead.
525 S/MIME certificate can be used in another special way. They can be
526 issued with a NULL subject distinguished name plus the email in SAN,
527 this is a valid certificate. This is used when you wont want to share
528 more information then you need to.
530 hx509 issue-certificate supports adding the email SAN to certificate by
531 using the --email option, --email also gives an implicit emailProtection
532 eku. If you want to create an certificate without an email address, the
533 option --type=email will add the emailProtection EKU.
535 @example
536 hxtool issue-certificate \
537           --subject="UID=testus-email,DC=test,DC=h5l,DC=se" \
538           --type=email \
539           --email="testus@@test.h5l.se" \
540           ...
541 @end example
543 An example of an certificate without and subject distinguished name with
544 an email address in a SAN.
546 @example
547 hxtool issue-certificate \
548           --subject="" \
549           --type=email \
550           --email="testus@@test.h5l.se" \
551           ...
552 @end example
554 @subsection PK-INIT
556 How to create a certificate for a KDC.
558 @example
559 hxtool issue-certificate \
560     --type="pkinit-kdc" \
561     --pk-init-principal="krbtgt/TEST.H5L.SE@@TEST.H5L.SE" \
562     --hostname kerberos.test.h5l.se \
563     --hostname pal.test.h5l.se \
564     ...
565 @end example
567 How to create a certificate for a user.
569 @example
570 hxtool issue-certificate \
571     --type="pkinit-client" \
572     --pk-init-principal="user@@TEST.H5L.SE" \
573     ...
574 @end example
576 @subsection XMPP/Jabber
578 The jabber server certificate should have a dNSname that is the same as
579 the user entered into the application, not the same as the host name of
580 the machine.
582 @example
583 hxtool issue-certificate \
584           --subject="CN=xmpp1.test.h5l.se,DC=test,DC=h5l,DC=se" \
585           --hostname="xmpp1.test.h5l.se" \
586           --hostname="test.h5l.se" \
587           ...
588 @end example
590 The certificate may also contain a jabber identifier (JID) that, if the
591 receiver allows it, authorises the server or client to use that JID.
593 When storing a JID inside the certificate, both for server and client,
594 it's stored inside a UTF8String within an otherName entity inside the
595 subjectAltName, using the OID id-on-xmppAddr (1.3.6.1.5.5.7.8.5).
597 To read more about the requirements, see RFC3920, Extensible Messaging
598 and Presence Protocol (XMPP): Core.
600 hxtool issue-certificate have support to add jid to the certificate
601 using the option @kbd{--jid}.
603 @example
604 hxtool issue-certificate \
605           --subject="CN=Love,DC=test,DC=h5l,DC=se" \
606           --jid="lha@@test.h5l.se" \
607           ...
608 @end example
611 @node CMS signing and encryption, CMS background, Application requirements, Top
612 @chapter CMS signing and encryption
614 CMS is the Cryptographic Message System that among other, is used by
615 S/MIME (secure email) and Kerberos PK-INIT. It's an extended version of
616 the RSA, Inc standard PKCS7.
618 @node CMS background, Certificate matching, CMS signing and encryption, Top
619 @section CMS background
622 @node Certificate matching, Matching syntax, CMS background, Top
623 @chapter Certificate matching
625 To match certificates hx509 have a special query language to match
626 certifictes in queries and ACLs.
628 @node Matching syntax, Software PKCS 11 module, Certificate matching, Top
629 @section Matching syntax
631 This is the language definitions somewhat slopply descriped:
633 @example
635 expr = TRUE, 
636      FALSE,
637      ! expr,
638      expr AND expr,
639      expr OR expr,
640      ( expr )
641      compare
643 compare =
644      word == word,
645      word != word,
646      word IN ( word [, word ...])
647      word IN %@{variable.subvariable@}
649 word =
650      STRING,
651      %@{variable@}
653 @end example
655 @node Software PKCS 11 module, How to use the PKCS11 module, Matching syntax, Top
656 @chapter Software PKCS 11 module
658 PKCS11 is a standard created by RSA, Inc to support hardware and
659 software encryption modules. It can be used by smartcard to expose the
660 crypto primitives inside without exposing the crypto keys.
662 Hx509 includes a software implementation of PKCS11 that runs within the
663 memory space of the process and thus exposes the keys to the
664 application.
666 @node How to use the PKCS11 module, , Software PKCS 11 module, Top
667 @section How to use the PKCS11 module
669 @example
670 $ cat > ~/.soft-pkcs11.rc <<EOF
671 mycert  cert    User certificate        FILE:/Users/lha/Private/pkinit.pem
672 app-fatal       true
674 $ kinit -C PKCS11:/usr/heimdal/lib/hx509.so lha@@EXAMPLE.ORG
675 @end example
678 @c @shortcontents
679 @contents
681 @bye