~ubuntu-branches/ubuntu/trusty/wvstreams/trusty

« back to all changes in this revision

Viewing changes to include/wvcrl.h

  • Committer: Bazaar Package Importer
  • Author(s): Peter Eisentraut
  • Date: 2008-04-05 14:47:52 UTC
  • mfrom: (0.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080405144752-gka8v86xuo52fmto
Tags: 4.4.1-0.2
* Non-maintainer upload.
* Fixed dependency information LSB header in init.d script
  (closes: #470067)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- Mode: C++ -*-
2
2
 * Worldvisions Weaver Software:
3
 
 *   Copyright (C) 1997-2005 Net Integration Technologies, Inc.
 
3
 *   Copyright (C) 1997-2007 Net Integration Technologies, Inc. and others.
4
4
 *
5
5
 * X.509v3 CRL management classes.
6
6
 */ 
7
7
#ifndef __WVCRL_H
8
8
#define __WVCRL_H
9
9
 
 
10
#include "wverror.h"
10
11
#include "wvlog.h"
11
 
#include "wverror.h"
 
12
#include "wvx509.h"
12
13
 
13
14
// Structures to make the compiler happy so we don't have to include x509v3.h ;)
14
15
struct X509_crl_st;
18
19
struct asn1_string_st;
19
20
typedef struct asn1_string_st ASN1_INTEGER;
20
21
 
21
 
class WvRSAKey;
22
22
class WvX509Mgr;
23
23
 
24
24
/**
25
 
 * CRL Class to handle certificates and their related
 
25
 * CRL Class to handle certificate revocation lists and their related
26
26
 * functions
27
27
 */
28
 
class WvCRLMgr
 
28
class WvCRL
29
29
{
30
30
public:
31
31
    /**
32
 
     * Where errors go when they happen
33
 
     */
34
 
    WvError err;
35
 
 
36
 
    /**
37
32
     * Type for the @ref encode() and @ref decode() methods:
38
33
     * CRLPEM   = PEM Encoded X.509 CRL
39
 
     * CRLDER   = DER Encoded X.509 CRL returned in Base64
40
 
     * TEXT     = Decoded Human readable format.
41
 
     */
42
 
    enum DumpMode { PEM = 0, DER, TEXT };
 
34
     * CRLDER   = DER Encoded X.509 CRL 
 
35
     * CRLFilePEM   = PEM Encoded X.509 CRL
 
36
     * CRLFileDER   = DER Encoded X.509 CRL 
 
37
     */
 
38
    enum DumpMode { CRLPEM = 0, CRLDER, CRLFilePEM, CRLFileDER };
 
39
 
 
40
    /**
 
41
     * Initialize a blank (null) CRL object.
 
42
     */
 
43
    WvCRL();
 
44
    
 
45
    /**
 
46
     * Initialize a CRL object, signed and created by the certificate
 
47
     * 'cacert'.
 
48
     */
 
49
    WvCRL(const WvX509Mgr &cacert);
 
50
 
 
51
    /** Destructor */
 
52
    virtual ~WvCRL();
 
53
 
 
54
    /** Accessor for CRL */
 
55
    X509_CRL *getcrl()
 
56
    { return crl; }
 
57
 
 
58
    /**
 
59
     * Check the CRL in crl against the CA certificate in cert
 
60
     * - returns true if CRL was signed by that CA certificate.
 
61
     */
 
62
    bool signedbyca(const WvX509 &cacert) const;
 
63
 
 
64
    /**
 
65
     * Check the issuer name of the CRL in crl against the CA certificate in cert
 
66
     * - returns true if the names match.
 
67
     */
 
68
    bool issuedbyca(const WvX509 &cacert) const;
 
69
 
 
70
    /**
 
71
     * Checks to see if the CRL is expired (i.e.: the present time is past the
 
72
     * nextUpdate extension).
 
73
     * - returns true if CRL has expired.
 
74
     */
 
75
    bool expired() const;
 
76
 
 
77
    /*
 
78
     * Checks to see if the CRL has any critical extensions in it.
 
79
     * - returns true if the CRL has any critical extensions.
 
80
     */
 
81
    bool has_critical_extensions() const;
43
82
 
44
83
    /**
45
84
     * Type for @ref validate() method:
48
87
     * NOT_THIS_CA = the certificate is not signed by this CA
49
88
     * NO_VALID_SIGNATURE = the certificate claims to be signed by this CA (Issuer is the same),
50
89
     *                      but the signature is invalid.
51
 
     * BEFORE_VALID = the certificate has not become valid yet
52
 
     * AFTER_VALID = the certificate is past it's validity period
53
 
     * REVOKED = the certificate has been revoked (it's serial number is in this CRL)
54
 
     */
55
 
    
56
 
    enum Valid { CRLERROR = -1, VALID, NOT_THIS_CA, NO_VALID_SIGNATURE, BEFORE_VALID, AFTER_VALID, REVOKED };
57
 
    
58
 
    /**
59
 
     * Initialize a blank CRL Object
60
 
     * 
61
 
     * This either initializes a completely empty object, or takes
62
 
     * a pre-allocated _crl - takes ownership.
63
 
     */
64
 
    WvCRLMgr(X509_CRL *_crl = NULL);
65
 
    
66
 
private:
 
90
     */    
 
91
    enum Valid { CRLERROR = -1, VALID, NOT_THIS_CA, NO_VALID_SIGNATURE, 
 
92
                 EXPIRED, UNHANDLED_CRITICAL_EXTENSIONS };
 
93
 
 
94
    /**
 
95
     * Checks to see that a CRL is signed and issued by a CA certificate, and
 
96
     * that it has not expired.
 
97
     * - returns a validity status.
 
98
     * Get the Authority key Info
 
99
     */
 
100
    Valid validate(const WvX509 &cacert) const;
 
101
 
 
102
    /**
 
103
     * Get the Authority key Info
 
104
     */
 
105
    WvString get_aki() const;
 
106
 
67
107
    /** 
68
 
     * Placeholder for Copy Constructor: this doesn't exist yet, but it keeps
69
 
     * us out of trouble :) 
70
 
     */
71
 
    WvCRLMgr(const WvCRLMgr &mgr);
72
 
 
73
 
public:
74
 
    /** Destructor */
75
 
    virtual ~WvCRLMgr();
76
 
    
77
 
 
78
 
    /** Accessor for CRL */
79
 
    X509_CRL *getcrl()
80
 
    { return crl; }
81
 
 
82
 
 
83
 
    /**
84
 
     * Given the CRL object crl, return a hexified string
85
 
     * useful in a WvConf or UniConf file.
86
 
     * 
87
 
     */
88
 
    WvString hexify();
89
 
 
90
 
    /**
91
 
     * Function to verify the validity of a certificate given by
92
 
     * cert. This function checks three things:
93
 
     * 1: That the certificate has been issued by the same CA that
94
 
     *    has signed this CRL.
95
 
     * 2: That the certificate is within it's validity range
96
 
     * 3: That the certificate isn't in the CRL.
97
 
     */
98
 
    Valid validate(WvX509Mgr *cert);
99
 
 
100
 
    /**
101
 
     * Check the CRL in crl  against the CA certificates in
102
 
     * certdir - returns true if crl was signed by one of the CA
103
 
     * certificates.
104
 
     */
105
 
    bool signedbyCAindir(WvStringParm certdir);
106
 
   
107
 
    
108
 
    /**
109
 
     * Check the CRL in crl against the CA certificate in certfile
110
 
     * - returns true if crl was signed by that CA certificate. 
111
 
     */
112
 
    bool signedbyCAinfile(WvStringParm certfile);
113
 
    
114
 
    
115
 
    /**
116
 
     * Check the CRL in crl against the CA certificate in cacert
117
 
     * - returns true if CRL was signed by that CA certificate.
118
 
     */
119
 
    bool signedbyCA(WvX509Mgr *cert);
120
 
    
 
108
     * Get the CRL Issuer.
 
109
     */
 
110
    WvString get_issuer() const;
 
111
 
121
112
    /**
122
113
     * Do we have any errors... convenience function..
123
114
     */
124
 
    bool isok()
125
 
    { return err.isok(); }
126
 
    
127
 
    
128
 
    /**
129
 
     * Set the CA for this CRL...
130
 
     */
131
 
    void setca(WvX509Mgr *cacert);
132
 
    
 
115
    bool isok() const;
133
116
    
134
117
    /** 
135
118
     * Return the information requested by mode as a WvString. 
136
119
     */
137
 
    WvString encode(const DumpMode mode);
138
 
 
 
120
    WvString encode(const DumpMode mode) const;
 
121
    void encode(const DumpMode mode, WvBuf &buf) const;
139
122
 
140
123
    /**
141
124
     * Load the information from the format requested by mode into
142
 
     * the class - this overwrites the certificate, and possibly the
143
 
     * key - and to enable two stage loading (the certificate first, then the
144
 
     * key), it DOES NOT call test() - that will be up to the programmer
145
 
     */
146
 
    void decode(const DumpMode mode, WvStringParm PemEncoded);
147
 
 
148
 
    
149
 
    /** 
150
 
     * Return the CRL Issuer (usually the CA who signed 
151
 
     * the certificate)
152
 
     */
153
 
    WvString get_issuer();
154
 
 
155
 
    
 
125
     * the class - this overwrites the CRL.
 
126
     */
 
127
    void decode(const DumpMode mode, WvStringParm encoded);
 
128
    void decode(const DumpMode mode, WvBuf &encoded);
 
129
 
156
130
    /**
157
131
     * Is the certificate in cert revoked?
158
132
     */
159
 
    bool isrevoked(WvX509Mgr *cert);
160
 
    bool isrevoked(WvStringParm serial_number);
161
 
    
162
 
    
163
 
    /**
164
 
     * How many certificates in the CRL?
165
 
     */
166
 
    int numcerts();
167
 
 
168
 
    
169
 
    /**
170
 
     * Add the certificate in cert to the CRL
171
 
     */
172
 
    void addcert(WvX509Mgr *cert);
173
 
 
174
 
 
 
133
    bool isrevoked(const WvX509 &cert) const;
 
134
    bool isrevoked(WvStringParm serial_number) const;
 
135
 
 
136
    /**
 
137
     * Add the certificate specified by cert to the CRL.
 
138
     */
 
139
    void addcert(const WvX509 &cert);
 
140
 
 
141
    /**
 
142
     * Counts the number of certificates in this CRL.
 
143
     * WARNING: this method will be very slow and will consume a lot
 
144
     * of memory for large CRLs.
 
145
     */
 
146
    int numcerts() const;
 
147
    
175
148
private:
176
 
    /** X.509v3 CRL - this is why this class exists */
177
 
    WvLog debug;
178
 
 
179
 
    X509_CRL     *crl;
180
 
    WvX509Mgr    *cacert;
181
 
    int          certcount;
182
 
    WvString     issuer;
183
 
 
184
 
    ASN1_INTEGER *serial_to_int(WvStringParm serial);
185
 
    void         setupcrl();
186
 
 
 
149
    mutable WvLog debug;
 
150
    X509_CRL *crl;
187
151
};
188
152
 
189
153
#endif // __WVCRL_H