moved common functions to super classes

This commit is contained in:
chris2511 2003-06-16 09:04:55 +00:00
parent f58c672232
commit 0fd13a3875
12 changed files with 409 additions and 263 deletions

View File

@ -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))

View File

@ -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

View File

@ -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<pki_base> 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<pki_base> 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() <<endl;
if (pki->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<pki_base> 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<pki_x509> db_x509::getIssuedCerts(pki_x509 *issuer)
{
pki_x509 *cert = NULL;
QList<pki_x509> 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<pki_x509> db_x509::getCerts(bool onlyTrusted)
{
QList<pki_x509> 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

View File

@ -52,6 +52,7 @@
#include <qlistview.h>
#include <qpixmap.h>
#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<pki_x509> getIssuedCerts(pki_x509 *issuer);
QList<pki_x509> 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

View File

@ -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<pki_base> 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<pki_base> 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);
}

View File

@ -51,27 +51,19 @@
#include <qstringlist.h>
#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

92
lib/db_x509super.cpp Normal file
View File

@ -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

75
lib/db_x509super.h Normal file
View File

@ -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 <qstringlist.h>
#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

View File

@ -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;
}

View File

@ -54,14 +54,15 @@
#include <openssl/x509.h>
#include <openssl/pem.h>
#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);
};

99
lib/pki_x509super.cpp Normal file
View File

@ -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;
}

76
lib/pki_x509super.h Normal file
View File

@ -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 <openssl/x509.h>
#include <openssl/pem.h>
#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