OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / freeswan / pluto / x509.h
1 /* Support of X.509 certificates and CRLs
2  * Copyright (C) 2000 Andreas Hess, Patric Lichtsteiner, Roger Wegmann
3  * Copyright (C) 2001 Marco Bertossa, Andreas Schleiss
4  * Copyright (C) 2002 Mario Strasser
5  * Copyright (C) 2000-2002 Andreas Steffen, Zuercher Hochschule Winterthur
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation; either version 2 of the License, or (at your
10  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15  * for more details.
16  *
17  * RCSID $Id: x509.h,v 1.6 2004-09-30 23:14:52 danield Exp $
18  */
19 #ifndef _X509_H
20 #define _X509_H
21
22 /*
23  * path definitions for my X.509 or PGP cert, peer certs, cacerts and crls
24  */
25 #include <config/autoconf.h>
26
27 #ifdef CONFIG_USER_FLATFSD_FLATFSD
28 #define __IPSEC__PREFIX__ "/etc/config"
29 #else
30 #define __IPSEC__PREFIX__ "/etc"
31 #endif
32
33 #define X509_CERT_PATH  __IPSEC__PREFIX__ "/"
34 #define PGP_CERT_PATH   __IPSEC__PREFIX__ "/pgpcert.pgp"
35 #define CA_CERT_PATH    __IPSEC__PREFIX__
36 #define CRL_PATH        __IPSEC__PREFIX__
37 #define HOST_CERT_PATH    __IPSEC__PREFIX__
38
39 /* advance warning of imminent expiry of
40  * cacerts, public keys, and crls
41  */
42 #define CA_CERT_WARNING_INTERVAL        30 /* days */
43 #define PUBKEY_WARNING_INTERVAL         14 /* days */
44 #define CRL_WARNING_INTERVAL             7 /* days */
45
46 /* Definition of generalNames kinds */
47
48 typedef enum {
49     GN_OTHER_NAME =             0,
50     GN_RFC822_NAME =            1,
51     GN_DNS_NAME =               2,
52     GN_X400_ADDRESS =           3,
53     GN_DIRECTORY_NAME =         4,
54     GN_EDI_PARTY_NAME =         5,
55     GN_URI =                    6,
56     GN_IP_ADDRESS =             7,
57     GN_REGISTERED_ID =          8
58 } generalNames_t;
59
60 /* access structure for a GeneralName */
61
62 typedef struct generalName generalName_t;
63
64 struct generalName {
65     generalName_t   *next;
66     generalNames_t  kind;
67     chunk_t         name;
68 };
69
70 /* access structure for an X.509v3 certificate */
71
72 typedef struct x509cert x509cert_t;
73
74 struct x509cert {
75   x509cert_t     *next;
76   time_t         installed;
77   int            count;
78   chunk_t        certificate;
79   chunk_t          tbsCertificate;
80   u_int              version;
81   chunk_t            serialNumber;
82                 /*   signature */
83   chunk_t              sigAlg;
84   chunk_t            issuer;
85                 /*   validity */
86   time_t               notBefore;
87   time_t               notAfter;
88   chunk_t            subject;
89                 /*   subjectPublicKeyInfo */
90   enum pubkey_alg      subjectPublicKeyAlgorithm;
91                 /*     subjectPublicKey */
92   chunk_t                modulus;
93   chunk_t                publicExponent;
94   chunk_t            issuerUniqueID;
95   chunk_t            subjectUniqueID;
96                 /*   v3 extensions */
97                 /*   extension */
98                 /*     extension */
99                 /*       extnID */
100                 /*        critical */
101                 /*        extnValue */
102   bool                    isCA;
103   generalName_t           *subjectAltName;
104   generalName_t           *crlDistributionPoints;
105                 /* signatureAlgorithm */
106   chunk_t            algorithm;
107   chunk_t          signature;
108 };
109
110 /* access structure for a revoked serial number */
111
112 typedef struct revokedCert revokedCert_t;
113
114 struct revokedCert{
115   revokedCert_t *next;
116   chunk_t       userCertificate;
117   time_t        revocationDate;
118 };
119
120 /* storage structure for an X.509 CRL */
121
122 typedef struct x509crl x509crl_t;
123
124 struct x509crl {
125   x509crl_t     *next;
126   time_t         installed;
127   chunk_t        certificateList;
128   chunk_t          tbsCertList;
129   u_int              version;
130                  /*  signature */
131   chunk_t              sigAlg;
132   chunk_t            issuer;
133   time_t             thisUpdate;
134   time_t             nextUpdate;
135   revokedCert_t      *revokedCertificates;
136                 /*   crlExtensions */
137                 /* signatureAlgorithm */
138   chunk_t            algorithm;
139   chunk_t          signature;
140 };
141
142 /* stores either a X.509 or OpenPGP certificate */
143
144 typedef struct {
145     u_char type;
146     chunk_t cert;
147 } cert_t;
148
149 /*  do not send certificate requests
150  *  flag set in main.c and used in ipsec_doi.c
151  */
152 extern bool no_cr_send;
153
154 /* used for initialization */
155 extern const x509crl_t  empty_x509crl;
156 extern const x509cert_t empty_x509cert;
157
158 extern bool same_dn(chunk_t a, chunk_t b);
159 #define MAX_CA_PATH_LEN         7
160 extern void hex_str(chunk_t bin, chunk_t *str);
161 extern int dntoa(char *dst, size_t dstlen, chunk_t dn);
162 extern err_t atodn(char *src, chunk_t *dn);
163 extern void gntoid(struct id *id, const generalName_t *gn);
164 extern bool parse_x509cert(chunk_t blob, u_int level0, x509cert_t *cert);
165 extern bool parse_x509crl(chunk_t blob, u_int level0, x509crl_t *crl);
166 extern bool check_validity(const x509cert_t *cert);
167 extern bool verify_x509cert(const x509cert_t *cert);
168 extern bool get_mycert(cert_t *mycert, x509cert_t *cert);
169 extern x509cert_t* load_x509cert(const char* filename, const char* label);
170 extern x509cert_t* load_host_cert(const char* filename);
171 extern x509cert_t* add_x509cert(x509cert_t *cert);
172 extern void share_x509cert(x509cert_t *cert);
173 extern void release_x509cert(x509cert_t *cert);
174 extern void free_x509cert(x509cert_t *cert);
175 extern void store_x509certs(x509cert_t **firstcert);
176 extern void load_cacerts(void);
177 extern void load_crls(void);
178 extern void load_mycert(void);
179 extern void list_certs(bool utc);
180 extern void list_cacerts(bool utc);
181 extern void list_crls(bool utc);
182 extern void free_cacerts(void);
183 extern void free_crls(void);
184 extern void free_mycert(void);
185 extern void free_generalNames(generalName_t* gn);
186 #endif