WvStreams
wvx509mgr.h
1 /* -*- Mode: C++ -*-
2  *
3  * X.509 certificate management class: This class builds upon the
4  * functionality provided by the WvX509 class, adding operations that are
5  * made possible with the addition of a private key (e.g. signing certificates
6  * and CRLs).
7  */
8 #ifndef __WVX509MGR_H
9 #define __WVX509MGR_H
10 
11 #include "wvx509.h"
12 #include "wvcrl.h"
13 
14 class WvX509Mgr : public WvX509
15 {
16  public:
21  WvX509Mgr();
22 
40  WvX509Mgr(WvStringParm _dname, WvRSAKey *_rsa, bool ca = false);
41 
49  WvX509Mgr(WvStringParm _dname, int bits, bool ca=false);
50 
54  WvX509Mgr(const WvX509Mgr &mgr);
55 
56  protected:
65  void create_selfissued(WvStringParm dname, bool is_ca = false);
66 
67 public:
69  virtual ~WvX509Mgr();
70 
75  virtual bool isok() const;
76 
80  virtual WvString errstr() const;
81 
85  bool operator! () const;
86 
90  WvRSAKey *get_rsa() { return rsa; }
91  void set_rsa(WvRSAKey *_rsa) { WVDELETE(rsa); rsa = new WvRSAKey(*_rsa); }
92 
98  bool bind_ssl(SSL_CTX *ctx);
99 
105  WvString signreq(WvStringParm pkcs10req) const;
106 
110  bool signcert(WvX509 &unsignedcert) const;
111 
117  bool signcrl(WvCRL &unsignedcrl) const;
118 
124  bool test() const;
125 
130  WvString sign(WvBuf &data) const;
131  WvString sign(WvStringParm data) const;
132 
136  virtual WvString encode(const WvX509::DumpMode mode) const;
137  virtual WvString encode(const WvRSAKey::DumpMode mode) const;
138  virtual void encode(const WvX509::DumpMode mode, WvBuf &buf) const;
139  virtual void encode(const WvRSAKey::DumpMode mode, WvBuf &buf) const;
140 
147  virtual void decode(const WvX509::DumpMode mode, WvStringParm encoded);
148  virtual void decode(const WvRSAKey::DumpMode mode, WvStringParm encoded);
149  virtual void decode(const WvX509::DumpMode mode, WvBuf &encoded);
150  virtual void decode(const WvRSAKey::DumpMode mode, WvBuf &encoded);
151 
157  bool write_p12(WvStringParm _fname, WvStringParm _pkcs12pass) const;
158 
164  void read_p12(WvStringParm _fname, WvStringParm _pkcs12pass);
165 
166  private:
172  mutable WvRSAKey *rsa;
173 
174  mutable WvLog debug;
175 };
176 #endif
WvX509Mgr::get_rsa
WvRSAKey * get_rsa()
Allow us access to the RSA member.
Definition: wvx509mgr.h:90
WvX509
X509 Class to handle certificates and their related functions.
Definition: wvx509.h:41
WvX509::DumpMode
DumpMode
Type for the encode() and decode() methods.
Definition: wvx509.h:56
WvX509Mgr::errstr
virtual WvString errstr() const
Says what the error is, if isok() is not true.
Definition: wvx509mgr.cc:184
WvX509Mgr::bind_ssl
bool bind_ssl(SSL_CTX *ctx)
Avoid a lot of ugliness by having it so that we are binding to the SSL context, and not the other way...
Definition: wvx509mgr.cc:200
WvX509Mgr::read_p12
void read_p12(WvStringParm _fname, WvStringParm _pkcs12pass)
And this reads from the file specified in filename using the password "_pkcs12pass",...
Definition: wvx509mgr.cc:561
WvX509Mgr::isok
virtual bool isok() const
Says if this certificate+key pair is good for use.
Definition: wvx509mgr.cc:172
WvRSAKey
An RSA public key or public/private key pair that can be used for encryption.
Definition: wvrsa.h:26
WvRSAKey::DumpMode
DumpMode
Type for the encode() and decode() methods.
Definition: wvrsa.h:36
WvString
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:329
WvLog
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
Definition: wvlog.h:56
WvX509Mgr::WvX509Mgr
WvX509Mgr()
Constructor to create a blank certificate + keypair (useful if, for example, you were going to load t...
Definition: wvx509mgr.cc:35
WvCRL
CRL Class to handle certificate revocation lists and their related functions.
Definition: wvcrl.h:28
WvX509Mgr::signreq
WvString signreq(WvStringParm pkcs10req) const
Take the PKCS#10 request in the string pkcs10req, sign it with the private key in rsa,...
Definition: wvx509mgr.cc:267
WvX509Mgr::operator!
bool operator!() const
The not operator returns true if !isok()
Definition: wvx509mgr.cc:178
WvX509Mgr::create_selfissued
void create_selfissued(WvStringParm dname, bool is_ca=false)
Given the Distinguished Name dname and an already generated keypair in rsa, return a Self Signed Cert...
Definition: wvx509mgr.cc:89
WvBufBase< unsigned char >
Specialization of WvBufBase for unsigned char type buffers intended for use with raw memory buffers.
Definition: wvbuf.h:22
WvX509Mgr::decode
virtual void decode(const WvX509::DumpMode mode, WvStringParm encoded)
Load the information from the format requested by mode into the class - this overwrites the certifica...
Definition: wvx509mgr.cc:664
WvX509Mgr
Definition: wvx509mgr.h:14
WvX509Mgr::sign
WvString sign(WvBuf &data) const
Sign the contents of data and return the signature as a BASE64 string.
Definition: wvx509mgr.cc:457
WvX509Mgr::signcert
bool signcert(WvX509 &unsignedcert) const
Sign the certificate with the rsa key associated with this class.
Definition: wvx509mgr.cc:344
WvX509Mgr::signcrl
bool signcrl(WvCRL &unsignedcrl) const
Sign the CRL with the rsa key associated with this class.
Definition: wvx509mgr.cc:393
WvX509Mgr::write_p12
bool write_p12(WvStringParm _fname, WvStringParm _pkcs12pass) const
This writes the certificate and RSA keys in PKCS12 format to the file specified by filename,...
Definition: wvx509mgr.cc:496
WvX509Mgr::test
bool test() const
Test to make sure that a certificate and a keypair go together.
Definition: wvx509mgr.cc:217
WvX509Mgr::~WvX509Mgr
virtual ~WvX509Mgr()
Destructor.
Definition: wvx509mgr.cc:165
WvX509Mgr::encode
virtual WvString encode(const WvX509::DumpMode mode) const
Encodes the information requested by mode into a buffer.
Definition: wvx509mgr.cc:633