From 0fd13a38751063a4f063dd7ffc02dfad88798708 Mon Sep 17 00:00:00 2001 From: chris2511 Date: Mon, 16 Jun 2003 09:04:55 +0000 Subject: [PATCH] moved common functions to super classes --- lib/Makefile.in | 4 +- lib/db_key.cpp | 23 +++-- lib/db_x509.cpp | 199 ++++++++++-------------------------------- lib/db_x509.h | 10 +-- lib/db_x509req.cpp | 67 +------------- lib/db_x509req.h | 12 +-- lib/db_x509super.cpp | 92 +++++++++++++++++++ lib/db_x509super.h | 75 ++++++++++++++++ lib/pki_x509req.cpp | 9 +- lib/pki_x509req.h | 6 +- lib/pki_x509super.cpp | 99 +++++++++++++++++++++ lib/pki_x509super.h | 76 ++++++++++++++++ 12 files changed, 409 insertions(+), 263 deletions(-) create mode 100644 lib/db_x509super.cpp create mode 100644 lib/db_x509super.h create mode 100644 lib/pki_x509super.cpp create mode 100644 lib/pki_x509super.h diff --git a/lib/Makefile.in b/lib/Makefile.in index 0a293827..a3c4f55a 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -18,9 +18,9 @@ CFLAGS=-Wall @ac_DEBUG@ ############################################## -PKIOBJS=pki_base.o pki_key.o pki_x509req.o pki_x509.o asn1time.o x509name.o +PKIOBJS=pki_base.o pki_key.o pki_x509super.o pki_x509req.o pki_x509.o asn1time.o x509name.o # pki_pkcs12.o pki_temp.o pki_crl.o pki_pkcs7.o -DBNAMES=db_key db_x509req db_x509 db_temp db_crl +DBNAMES=db_key db_x509super db_x509req db_x509 db_temp db_crl DBOBJS=db_base.o pass_info.o $(patsubst %,%.o,$(DBNAMES)) $(patsubst %,moc_%.o,$(DBNAMES)) DB_CPP=$(patsubst %,moc_%.cpp,$(DBNAMES)) diff --git a/lib/db_key.cpp b/lib/db_key.cpp index f2dc6cca..7aca34fb 100644 --- a/lib/db_key.cpp +++ b/lib/db_key.cpp @@ -50,7 +50,9 @@ #include "db_key.h" - +#define FOR_container for (pki_key *pki = (pki_key *)container.first(); \ + pki != 0; pki = (pki_key *)container.next() ) + db_key::db_key(DbEnv *dbe, string DBfile, DbTxn *tid) :db_base(dbe, DBfile, "keydb",tid) @@ -65,27 +67,21 @@ pki_base *db_key::newPKI(){ QStringList db_key::getPrivateDesc() { - pki_key *pki; QStringList x; x.clear(); - for ( pki = (pki_key *)container.first(); pki != 0; pki = (pki_key *)container.next() ) { - if (pki->isPrivKey()) { - x.append(pki->getDescription().c_str()); - } - } + FOR_container + if (pki->isPrivKey()) + x.append(pki->getIntName()); return x; } QStringList db_key::get0PrivateDesc() { - pki_key *pki; QStringList x; x.clear(); - for ( pki = (pki_key *)container.first(); pki != 0; pki = (pki_key *)container.next() ) { - if (pki->isPrivKey() && pki->getUcount() == 0) { - x.append(pki->getDescription().c_str()); - } - } + FOR_container + if (pki->isPrivKey() && pki->getUcount() == 0) + x.append(pki->getIntName()); return x; } @@ -101,3 +97,4 @@ void db_key::inToCont(pki_base *pki) emit newKey((pki_key *)pki); } +#undef FOR_container diff --git a/lib/db_x509.cpp b/lib/db_x509.cpp index 48cb688a..ce134ad3 100644 --- a/lib/db_x509.cpp +++ b/lib/db_x509.cpp @@ -50,7 +50,9 @@ #include "db_x509.h" - +#define FOR_container for (pki_x509 *pki = (pki_x509 *)container.first(); \ + pki != 0; pki = (pki_x509 *)container.next() ) + db_x509::db_x509(DbEnv *dbe, string DBfile, QListView *l, db_key *keyl, DbTxn *tid) :db_base(dbe, DBfile, "certdb", tid) @@ -143,86 +145,31 @@ bool db_x509::updateView() QStringList db_x509::getPrivateDesc() { - pki_x509 *pki; QStringList x; - if ( container.isEmpty() ) return x; - for ( pki = (pki_x509 *)container.first(); pki != 0; pki = (pki_x509 *)container.next() ) { + FOR_container if (pki->getKey()) - x.append(pki->getDescription().c_str()); - } + x.append(pki->getIntName()); return x; } QStringList db_x509::getSignerDesc() { - pki_x509 *pki; QStringList x; - if ( container.isEmpty() ) return x; - for ( pki = (pki_x509 *)container.first(); pki != 0; pki = (pki_x509 *)container.next() ) { + FOR_container if (pki->canSign()) - x.append(pki->getDescription().c_str()); - } + x.append(pki->getIntName()); return x; } -void db_x509::remFromCont(pki_base *pki) +void db_x509::remFromCont(pki_base *ref) { - container.remove(pki); - pki_x509 *pkiit; - QListIterator it(container); - for ( ; it.current(); ++it ) { - pkiit = (pki_x509 *)it.current(); - if (pkiit->getSigner() == pki) { - pkiit->delSigner(); - } - } + container.remove(ref); + FOR_container + pki->delSigner(ref); return; } -pki_key *db_x509::findKey(pki_x509* cert) -{ - pki_key *key = NULL, *refkey = NULL; - if (!cert) return NULL; - if ((key = cert->getKey()) != NULL ) return key; - refkey = cert->getPubKey(); - key = (pki_key *)keylist->getByReference(refkey); - if (key && key->isPubKey()) { - key = NULL; - } - if (refkey) delete(refkey); - return key; -} - -void db_x509::delKey(pki_key *delkey) -{ - pki_x509 *pki; - if ( container.isEmpty() ) return ; - for ( pki = (pki_x509 *)container.first(); pki != 0; pki = (pki_x509 *)container.next() ) { - if (pki->getKey() == delkey) { - pki->delKey(); - } - } - -} - - -void db_x509::newKey(pki_key *newkey) -{ - pki_x509 *pki; - pki_key *refkey; - if ( container.isEmpty() ) return ; - for ( pki = (pki_x509 *)container.first(); pki != 0; pki = (pki_x509 *)container.next() ) { - if (!pki->getKey()) { - refkey = pki->getPubKey(); - if (newkey->compare(refkey)) { - updateViewPKI(pki); - } - delete(refkey); - } - } -} - void db_x509::preprocess() { pki_x509 *pki; @@ -240,117 +187,63 @@ void db_x509::preprocess() calcEffTrust(); -/* - pki_x509 *signer; - while (! mycont.isEmpty() ) { - QListIterator it(mycont); - for (it.toFirst(); it.current(); ++it ) { - int trust = 1; // dont know - pki = (pki_x509 *)it.current(); - signer = pki->getSigner(); - CERR << "inloop " << pki->getDescription() <getTrust() != 1){ // Always trust it or never - trust = pki->getTrust(); - } - else if ( signer) { // Trust it, if we trust parent and there is a parent - if (signer == pki) { // if self signed - trust = 0; // no trust - } - else { - trust = signer->getEffTrust(); // inherit trustment of parent - } - } - else { // we do not trust an unknown signer - trust=0; - } - if (trust != 1) { // trustment deterministic - pki->setEffTrust(trust); - mycont.remove(pki); - it.toFirst(); - } - - } - } - return ; -*/ } void db_x509::calcEffTrust() { - pki_x509 *pki; - CERR("re calc eff trust X509"); - if ( container.isEmpty() ) return ; - QListIterator iter(container); - for ( ; iter.current(); ++iter ) { // find the signer and the key of the certificate... - pki = (pki_x509 *)iter.current(); - CERR("CalcTrust for: " << pki->getDescription().c_str()); + // find the signer and the key of the certificate... + FOR_container pki->calcEffTrust(); - } } -void db_x509::insertPKI(pki_base *pki) +void db_x509::insertPKI(pki_base *refpki) { - db_base::insertPKI(pki); - pki_x509 *cert, *x = (pki_x509 *)pki; + db_base::insertPKI(refpki); + pki_x509 *x = (pki_x509 *)refpki; findSigner(x); findKey(x); - for ( cert = (pki_x509 *)container.first(); cert != 0; cert = (pki_x509 *)container.next() ) { + FOR_container cert->verify(x); - } calcEffTrust(); - updateView(); } QList db_x509::getIssuedCerts(pki_x509 *issuer) { - pki_x509 *cert = NULL; QList c; c.clear(); if (!issuer) return c; - for ( cert = (pki_x509 *)container.first(); cert != 0; cert = (pki_x509 *)container.next() ) { - if (cert->getSigner() == issuer) { + FOR_container + if (pki->getSigner() == issuer) c.append(cert); - } - } return c; } -pki_x509 *db_x509::getBySubject(X509_NAME *xname) +pki_x509 *db_x509::getBySubject(const x509name &xname) { - pki_x509 *cert = NULL; - if (!xname) return cert; - if ( container.isEmpty() ) return cert; - for ( cert = (pki_x509 *)container.first(); cert != NULL; cert = (pki_x509 *)container.next() ) { - CERR(cert); - if (X509_NAME_cmp(X509_get_subject_name(cert->cert), xname) == 0) { - return cert; - } - } + FOR_container + if ( pki->getSubject == xname) + return pki; return NULL; } -pki_x509 *db_x509::getByIssSerial(pki_x509 *iss, long serial) +pki_x509 *db_x509::getByIssSerial(pki_x509 *iss, a1int &serial) { - pki_x509 *cert = NULL; - if (!iss || serial == -1) return cert; - for (cert=(pki_x509 *)container.first(); cert !=0; cert=(pki_x509 *)container.next() ) { - if ((cert->getSigner() == iss) && (serial == cert->getSerialLong())) { - return cert; - } - } + if (!iss || serial == -1) return NULL; + FOR_container + if ((pki->getSigner() == iss) && (serial == pki->getSerial())) + return pki; return NULL; } void db_x509::writeAllCerts(QString fname, bool onlyTrusted) { pki_x509 *cert = NULL; - for ( cert = (pki_x509 *)container.first(); cert != 0; cert = (pki_x509 *)container.next() ) { - if (onlyTrusted && cert->getTrust() != 2) continue; - cert->writeCert(fname.latin1(),true,true); + FOR_container { + if (onlyTrusted && pki->getTrust() != 2) continue; + pki->writeCert(fname.latin1(),true,true); } } @@ -358,28 +251,26 @@ QList db_x509::getCerts(bool onlyTrusted) { QList c; c.clear(); - pki_x509 *cert = NULL; - for ( cert = (pki_x509 *)container.first(); cert != 0; cert = (pki_x509 *)container.next() ) { - if (onlyTrusted && cert->getTrust() != 2) continue; - c.append(cert); + FOR_container { + if (onlyTrusted && pki->getTrust() != 2) continue; + c.append(pki); } return c; } -int db_x509::searchSerial(pki_x509 *signer) +a1int db_x509::searchSerial(pki_x509 *signer) { if (!signer) return 0; - int serial = signer->getCaSerial(); - int oserial = serial, myserial =0; - pki_x509 *cert = NULL; - for ( cert = (pki_x509 *)container.first(); cert != 0; cert = (pki_x509 *)container.next() ) { - if (cert->getSigner() == signer) { - sscanf(cert->getSerial().c_str(), "%x", &myserial); - if (myserial >= serial) { - serial = myserial + 1; + a1int sserial = signer->getCaSerial(); + a1int oserial = 0; + FOR_container + if (pki->getSigner() == signer) { + myserial = pki->getSerial(); + if (sserial < myserial ) { + sserial = myserial; } } - } - if (oserial < serial) return serial; - return 0; + return sserial; } + +#undef FOR_container diff --git a/lib/db_x509.h b/lib/db_x509.h index a7592b62..f7672b90 100644 --- a/lib/db_x509.h +++ b/lib/db_x509.h @@ -52,6 +52,7 @@ #include #include #include "db_key.h" +#include "db_x509super.h" #include "pki_x509.h" #include "pki_crl.h" @@ -59,11 +60,10 @@ #define DB_X509_H -class db_x509: public db_base +class db_x509: public db_x509super { Q_OBJECT protected: - db_key *keylist; QPixmap *certicon[4]; public: int viewState; @@ -78,17 +78,13 @@ class db_x509: public db_base void preprocess(); QStringList getPrivateDesc(); QStringList getSignerDesc(); - pki_key * findKey(pki_x509 *cert); void calcEffTrust(); QList getIssuedCerts(pki_x509 *issuer); QList getCerts(bool onlyTrusted); - pki_x509 *getBySubject(X509_NAME *xname); + pki_x509 *getBySubject(x509name *xname); int searchSerial(pki_x509 *signer); void writeAllCerts(QString fname, bool onlyTrusted); pki_x509 *getByIssSerial(pki_x509 *iss, long serial); - public slots: - void delKey(pki_key *delkey); - void newKey(pki_key *newKey); }; #endif diff --git a/lib/db_x509req.cpp b/lib/db_x509req.cpp index 2ef003b9..3b926791 100644 --- a/lib/db_x509req.cpp +++ b/lib/db_x509req.cpp @@ -51,78 +51,13 @@ #include "db_x509req.h" - db_x509req::db_x509req(DbEnv *dbe, string DBfile, db_key *dk, DbTxn *tid) - :db_base(dbe, DBfile, "reqdb", tid) + :db_x509super(dbe, DBfile, "reqdb", dk, tid) { loadContainer(); - keylist = dk; } pki_base *db_x509req::newPKI(){ return new pki_x509req(); } -void db_x509req::delKey(pki_key *delkey) -{ - pki_x509req *pki; - for ( pki = (pki_x509req *)container.first(); pki != 0; - pki = (pki_x509req *)container.next() ) { - if ( pki->getKey() == delkey) { - pki->setKey(NULL); - } - } -} - - -void db_x509req::newKey(pki_key *newkey) -{ - pki_key *refkey; - pki_x509req *pki; - CERR("newKey"); - if ( container.isEmpty() ) return ; - QListIterator iter(container); - for ( ; iter.current(); ++iter ) { // find the key of the request - pki = (pki_x509req *)iter.current(); - refkey = pki->getPubKey(); - if (refkey->compare(newkey)) { - pki->setKey(newkey); - } - delete refkey; - } -} - -void db_x509req::preprocess() -{ - pki_x509req *pki; - CERR("preprocess X509req"); - if ( container.isEmpty() ) return ; - QListIterator iter(container); - for ( ; iter.current(); ++iter ) { // find the key of the request - pki = (pki_x509req *)iter.current(); - findKey(pki); - CERR("Key of "<< pki->getDescription().c_str()); - } -} - - -pki_key *db_x509req::findKey(pki_x509req *req) -{ - pki_key *key, *refkey; - if (!req) return NULL; - MARK - if ((key = req->getKey()) != NULL ) return key; - refkey = req->getPubKey(); - key = (pki_key *)keylist->getByReference(refkey); - if (key && key->isPubKey()) { - key = NULL; - } - if (refkey) delete(refkey); - return key; -} - -void db_x509req::remFromCont(pki_base *pki) -{ - db_base::remFromCont(pki); -} - diff --git a/lib/db_x509req.h b/lib/db_x509req.h index d175401a..a13c842d 100644 --- a/lib/db_x509req.h +++ b/lib/db_x509req.h @@ -51,27 +51,19 @@ #include #include "db_key.h" +#include "db_x509super.h" #include "pki_x509req.h" #ifndef DB_X509REQ_H #define DB_X509REQ_H -class db_x509req: public db_base +class db_x509req: public db_x509super { Q_OBJECT - private: - db_key *keylist; public: db_x509req(DbEnv *dbe, string DBfile, db_key *dk, DbTxn *tid); pki_base *newPKI(); - void preprocess(); - pki_key *findKey(pki_x509req *req); - void remFromCont(pki_base *pki); - public slots: - void delKey(pki_key *delkey); - void newKey(pki_key *newKey); - }; #endif diff --git a/lib/db_x509super.cpp b/lib/db_x509super.cpp new file mode 100644 index 00000000..b63fdc7f --- /dev/null +++ b/lib/db_x509super.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2001 Christian Hohnstaedt. + * + * All rights reserved. + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the author nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * This program links to software with different licenses from: + * + * http://www.openssl.org which includes cryptographic software + * written by Eric Young (eay@cryptsoft.com)" + * + * http://www.sleepycat.com + * + * http://www.trolltech.com + * + * + * + * http://www.hohnstaedt.de/xca + * email: christian@hohnstaedt.de + * + * $Id$ + * + */ + + +#include "db_x509super.h" +#define FOR_container for (pki_x509super *pki = (pki_x509super *)container.first(); \ + pki != 0; pki = (pki_x509super *)container.next() ) + +db_x509super::db_x509super(DbEnv *dbe, string DBfile, string db, db_key *dk, DbTxn *tid) + :db_base(dbe, DBfile, db, tid) +{ + keylist = dk; +} + + +void db_x509super::delKey(pki_key *delkey) +{ + FOR_container { pki->delRefKey(delkey); } +} + +void db_x509super::newKey(pki_key *newkey) +{ + FOR_container { pki->setRefKey(newkey); } +} + +void db_x509super::preprocess() +{ + FOR_container { findKey(pki); } +} + +pki_key *db_x509super::findKey(pki_x509super *ref) +{ + pki_key *key, *refkey; + if (!ref) return NULL; + if ((key = ref->getRefKey()) != NULL ) return key; + refkey = ref->getPubKey(); + key = (pki_key *)keylist->getByReference(refkey); + if (key && key->isPubKey()) { + key = NULL; + } + if (refkey) delete(refkey); + return key; +} + +#undef FOR_container diff --git a/lib/db_x509super.h b/lib/db_x509super.h new file mode 100644 index 00000000..de8996f9 --- /dev/null +++ b/lib/db_x509super.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2001 Christian Hohnstaedt. + * + * All rights reserved. + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the author nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * This program links to software with different licenses from: + * + * http://www.openssl.org which includes cryptographic software + * written by Eric Young (eay@cryptsoft.com)" + * + * http://www.sleepycat.com + * + * http://www.trolltech.com + * + * + * + * http://www.hohnstaedt.de/xca + * email: christian@hohnstaedt.de + * + * $Id$ + * + */ + + +#include +#include "db_key.h" +#include "pki_x509super.h" + +#ifndef DB_X509SUPER_H +#define DB_X509SUPER_H + + +class db_x509super: public db_base +{ + Q_OBJECT + protected: + db_key *keylist; + public: + db_x509super(DbEnv *dbe, string DBfile, string db, db_key *dk, DbTxn *tid); + void preprocess(); + pki_key *findKey(pki_x509super *ref); + public slots: + void delKey(pki_key *delkey); + void newKey(pki_key *newKey); + +}; + +#endif diff --git a/lib/pki_x509req.cpp b/lib/pki_x509req.cpp index 8481be37..f4a1c745 100644 --- a/lib/pki_x509req.cpp +++ b/lib/pki_x509req.cpp @@ -73,8 +73,7 @@ void pki_x509req::createReq(pki_key &key, x509name &dist_name) X509_REQ_set_pubkey(request, key.getKey()); X509_REQ_get_subject_name(request) = dist_name.get(); openssl_error(); - const EVP_MD *digest = EVP_md5(); - X509_REQ_sign(request,key.getKey() ,digest); + X509_REQ_sign(request,key.getKey() , EVP_md5()); openssl_error(); } @@ -188,9 +187,3 @@ pki_key *pki_x509req::getPubKey() openssl_error(); return key; } - -pki_key *pki_x509req::getKey() -{ - return privkey; -} - diff --git a/lib/pki_x509req.h b/lib/pki_x509req.h index 277cd136..0880dce3 100644 --- a/lib/pki_x509req.h +++ b/lib/pki_x509req.h @@ -54,14 +54,15 @@ #include #include #include "pki_key.h" +#include "pki_x509super.h" #include "x509name.h" + class pki_x509; -class pki_x509req : public pki_base +class pki_x509req : public pki_x509super { protected: - pki_key *privkey; X509_REQ *request; public: pki_x509req(); @@ -74,7 +75,6 @@ class pki_x509req : public pki_base void writeReq(const string fname, bool PEM); int verify(); pki_key *getPubKey(); - pki_key *getKey(); void createReq(pki_key &key, x509name &dist_name); }; diff --git a/lib/pki_x509super.cpp b/lib/pki_x509super.cpp new file mode 100644 index 00000000..925baa58 --- /dev/null +++ b/lib/pki_x509super.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2001 Christian Hohnstaedt. + * + * All rights reserved. + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the author nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * This program links to software with different licenses from: + * + * http://www.openssl.org which includes cryptographic software + * written by Eric Young (eay@cryptsoft.com)" + * + * http://www.sleepycat.com + * + * http://www.trolltech.com + * + * + * + * http://www.hohnstaedt.de/xca + * email: christian@hohnstaedt.de + * + * $Id$ + * + */ + + + +#include "pki_x509super.h" + +pki_x509super::pki_x509super() : pki_base() {} + +pki_x509super::~pki_x509super() {} + +x509name pki_x509super::getSubject() +{ + x509name x; + openssl_error(); + return x; +} + + +int pki_x509super::verify() +{ + return -1; +} + +pki_key *pki_x509super::getPubKey() +{ + return NULL; +} + +pki_key *pki_x509super::getRefKey() +{ + return privkey; +} + +void pki_x509super::setRefKey(pki_key *ref) +{ + if (ref == NULL || ref->isPubKey() || privkey != NULL ) return; + pki_key *mk = getPubKey(); + if (ref->compare(mk)) { + // this is our key + privkey = ref; + ref->incUcount(); + } + delete mk; +} + +void pki_x509super::delRefKey(pki_key *ref) +{ + if (ref != privkey || ref == NULL) return; + ref->decUcount(); + privkey = NULL; +} diff --git a/lib/pki_x509super.h b/lib/pki_x509super.h new file mode 100644 index 00000000..4e77c25f --- /dev/null +++ b/lib/pki_x509super.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2001 Christian Hohnstaedt. + * + * All rights reserved. + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the author nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * This program links to software with different licenses from: + * + * http://www.openssl.org which includes cryptographic software + * written by Eric Young (eay@cryptsoft.com)" + * + * http://www.sleepycat.com + * + * http://www.trolltech.com + * + * + * + * http://www.hohnstaedt.de/xca + * email: christian@hohnstaedt.de + * + * $Id$ + * + */ + +#ifndef PKI_X509SUPER_H +#define PKI_X509SUPER_H + +#include +#include +#include "pki_key.h" +#include "x509name.h" + +class pki_x509; + +class pki_x509super : public pki_base +{ + protected: + pki_key *privkey; + public: + pki_x509super(); + ~pki_x509super(); + virtual x509name getSubject(); + int verify(); + pki_key *getPubKey(); + pki_key *getRefKey(); + void setRefKey(pki_key *ref); + void delRefKey(pki_key *ref); +}; + +#endif