mirror of
https://github.com/chris2511/xca.git
synced 2026-09-14 11:06:19 +05:00
Preprocessing of certs and requests
QT3 listviewrenaming update of single items (and not the whole View) database access improved (update, rename)
This commit is contained in:
parent
f536e85c3d
commit
eabc8eb4e8
@ -6,7 +6,7 @@
|
||||
MainWindow::MainWindow(QWidget *parent, const char *name )
|
||||
:MainWindow_UI(parent, name)
|
||||
{
|
||||
connect((QObject *) quitApp, SIGNAL(clicked()), (QObject *)qApp, SLOT(quit()) );
|
||||
connect( (QObject *)quitApp, SIGNAL(clicked()), (QObject *)qApp, SLOT(quit()) );
|
||||
QString cpr = "(c) 2002 by Christian@Hohnstaedt.de - Version: ";
|
||||
copyright->setText(cpr + VER);
|
||||
baseDir = QDir::homeDirPath() + BASE_DIR;
|
||||
@ -36,6 +36,11 @@ MainWindow::MainWindow(QWidget *parent, const char *name )
|
||||
bigKey->setPixmap(*keyImg);
|
||||
bigCsr->setPixmap(*csrImg);
|
||||
bigCert->setPixmap(*certImg);
|
||||
#ifdef qt3
|
||||
connect( keyList, SIGNAL(itemRenamed(QListViewItem *, int, const QString &)),this, SLOT(renameKey(QListViewItem *, int, const QString &)));
|
||||
connect( reqList, SIGNAL(itemRenamed(QListViewItem *, int, const QString &)),this, SLOT(renameReq(QListViewItem *, int, const QString &)));
|
||||
connect( certList, SIGNAL(itemRenamed(QListViewItem *, int, const QString &)),this, SLOT(renameCert(QListViewItem *, int, const QString &)));
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@ -90,6 +95,16 @@ void MainWindow::initPass()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::renamePKI(db_base *db)
|
||||
{
|
||||
pki_base * pki = db->getSelectedPKI();
|
||||
Rename_UI *dlg = new Rename_UI(this,0,true);
|
||||
dlg->newName->setText(pki->getDescription().c_str());
|
||||
if (dlg->exec()) {
|
||||
db->renamePKI(pki, dlg->newName->text().latin1());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Static Password Callback functions
|
||||
|
||||
@ -134,16 +149,6 @@ void MainWindow::incProgress(int a, int b, void *progress)
|
||||
((QProgressDialog *)progress)->setProgress(++i);
|
||||
}
|
||||
|
||||
void MainWindow::renamePKI(db_base *db)
|
||||
{
|
||||
pki_base * pki = db->getSelectedPKI();
|
||||
Rename_UI *dlg = new Rename_UI(this,0,true);
|
||||
dlg->newName->setText(pki->getDescription().c_str());
|
||||
if (dlg->exec()) {
|
||||
db->updatePKI(pki, dlg->newName->text().latin1());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
string MainWindow::md5passwd()
|
||||
{
|
||||
|
||||
10
MainWindow.h
10
MainWindow.h
@ -49,6 +49,7 @@
|
||||
#define CERR cerr
|
||||
#endif
|
||||
|
||||
#define qt3 1
|
||||
|
||||
class MainWindow: public MainWindow_UI
|
||||
{
|
||||
@ -105,11 +106,14 @@ class MainWindow: public MainWindow_UI
|
||||
void showPopupCert(QListViewItem *item,const QPoint &pt, int x);
|
||||
void showPopupKey(QListViewItem *item,const QPoint &pt, int x);
|
||||
void showPopupReq(QListViewItem *item,const QPoint &pt, int x);
|
||||
void renameCert();
|
||||
void renameKey();
|
||||
void renameReq();
|
||||
void startRenameCert();
|
||||
void startRenameKey();
|
||||
void startRenameReq();
|
||||
void setTrust();
|
||||
void revoke();
|
||||
void unRevoke();
|
||||
void renameKey(QListViewItem *item, int col, const QString &text);
|
||||
void renameReq(QListViewItem *item, int col, const QString &text);
|
||||
void renameCert(QListViewItem *item, int col, const QString &text);
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -81,7 +81,7 @@ void MainWindow::showDetailsKey(pki_key *key)
|
||||
if ( !detDlg->exec()) return;
|
||||
string ndesc = detDlg->keyDesc->text().latin1();
|
||||
if (ndesc != key->getDescription()) {
|
||||
keys->updatePKI(key, ndesc);
|
||||
keys->renamePKI(key, ndesc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,7 +212,7 @@ void MainWindow::showPopupKey(QListViewItem *item, const QPoint &pt, int x) {
|
||||
menu->insertItem(tr("Import"), this, SLOT(loadKey()));
|
||||
}
|
||||
else {
|
||||
menu->insertItem(tr("Rename"), this, SLOT(renameKey()));
|
||||
menu->insertItem(tr("Rename"), this, SLOT(startRenameKey()));
|
||||
menu->insertItem(tr("Show Details"), this, SLOT(showDetailsKey()));
|
||||
menu->insertItem(tr("Export"), this, SLOT(writeKey()));
|
||||
menu->insertItem(tr("Delete"), this, SLOT(deleteKey()));
|
||||
@ -221,6 +221,20 @@ void MainWindow::showPopupKey(QListViewItem *item, const QPoint &pt, int x) {
|
||||
return;
|
||||
}
|
||||
|
||||
void MainWindow::renameKey() {
|
||||
renamePKI(keys);
|
||||
void MainWindow::renameKey(QListViewItem *item, int col, const QString &text)
|
||||
{
|
||||
pki_base *pki = keys->getSelectedPKI(item);
|
||||
string txt = text.latin1();
|
||||
keys->renamePKI(pki, txt);
|
||||
}
|
||||
|
||||
void MainWindow::startRenameKey()
|
||||
{
|
||||
#ifdef qt3
|
||||
pki_base *pki = keys->getSelectedPKI();
|
||||
QListViewItem *item = (QListViewItem *)pki->getPointer();
|
||||
item->startRename(0);
|
||||
#else
|
||||
renamePKI(certs);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ void MainWindow::newCert()
|
||||
pki_x509 *cert = NULL;
|
||||
pki_x509 *signcert = NULL;
|
||||
pki_x509req *req = NULL;
|
||||
pki_key *signkey = NULL, *key = NULL;
|
||||
pki_key *signkey = NULL, *clientkey = NULL;
|
||||
int serial = 42; // :-)
|
||||
|
||||
// Step 1 - Subject and key
|
||||
@ -14,8 +14,8 @@ void MainWindow::newCert()
|
||||
dlg1->image->setPixmap(*certImg);
|
||||
if (! dlg1->exec()) return;
|
||||
if (dlg1->fromDataRB->isChecked()) {
|
||||
key = (pki_key *)keys->getSelectedPKI(dlg1->keyList->currentText().latin1());
|
||||
if (opensslError(key)) return;
|
||||
clientkey = (pki_key *)keys->getSelectedPKI(dlg1->keyList->currentText().latin1());
|
||||
if (opensslError(clientkey)) return;
|
||||
string cn = dlg1->commonName->text().latin1();
|
||||
string c = dlg1->countryName->text().latin1();
|
||||
string l = dlg1->localityName->text().latin1();
|
||||
@ -24,13 +24,14 @@ void MainWindow::newCert()
|
||||
string ou = dlg1->organisationalUnitName->text().latin1();
|
||||
string email = dlg1->emailAddress->text().latin1();
|
||||
string desc = dlg1->description->text().latin1();
|
||||
req = new pki_x509req(key, cn,c,l,st,o,ou,email,desc,"");
|
||||
req = new pki_x509req(clientkey, cn,c,l,st,o,ou,email,desc,"");
|
||||
if (opensslError(req)) return;
|
||||
}
|
||||
else {
|
||||
// A PKCS#10 Request was selected
|
||||
req = (pki_x509req *)reqs->getSelectedPKI(dlg1->reqList->currentText().latin1());
|
||||
if (opensslError(req)) return;
|
||||
//clientkey = req->getKey();
|
||||
}
|
||||
|
||||
// Step 2 - select Signing
|
||||
@ -54,7 +55,7 @@ void MainWindow::newCert()
|
||||
if (dlg2->foreignSignRB->isChecked()) {
|
||||
signcert = (pki_x509 *)certs->getSelectedPKI(dlg2->certList->currentText().latin1());
|
||||
if (opensslError(signcert)) return;
|
||||
signkey = certs->findKey(signcert);
|
||||
signkey = signcert->getKey();
|
||||
if (opensslError(signkey)) return;
|
||||
// search for serial in database
|
||||
string serhash = signcert->fingerprint(EVP_md5()) + "serial";
|
||||
@ -64,7 +65,7 @@ void MainWindow::newCert()
|
||||
|
||||
}
|
||||
else {
|
||||
signkey = key;
|
||||
signkey = clientkey;
|
||||
bool ok;
|
||||
serial = dlg2->serialNr->text().toInt(&ok);
|
||||
if (!ok) serial = 0;
|
||||
@ -82,7 +83,7 @@ void MainWindow::newCert()
|
||||
if (days == 1) x *= 30;
|
||||
if (days == 2) x *= 365;
|
||||
|
||||
cert = new pki_x509(req->getDescription(), req, signcert, x, serial);
|
||||
cert = new pki_x509(req->getDescription(), clientkey, req, signcert, x, serial);
|
||||
if (opensslError(cert)) return;
|
||||
|
||||
// handle extensions
|
||||
@ -162,7 +163,7 @@ void MainWindow::showDetailsCert(pki_x509 *cert)
|
||||
dlg->descr->setText(cert->getDescription().c_str());
|
||||
|
||||
// examine the key
|
||||
pki_key *key= (pki_key *)keys->findPKI(cert->getKey());
|
||||
pki_key *key= cert->getKey();
|
||||
if (key)
|
||||
if (key->isPrivKey()) {
|
||||
dlg->privKey->setText(key->getDescription().c_str());
|
||||
@ -182,9 +183,10 @@ void MainWindow::showDetailsCert(pki_x509 *cert)
|
||||
}
|
||||
|
||||
// check trust state
|
||||
if (!cert->getEffTrust()) {
|
||||
if (cert->getEffTrust() == 0) {
|
||||
dlg->verify->setDisabled(true);
|
||||
}
|
||||
CERR << cert->getEffTrust() <<endl;
|
||||
|
||||
// the serial
|
||||
dlg->serialNr->setText(cert->getSerial().c_str());
|
||||
@ -245,7 +247,7 @@ void MainWindow::showDetailsCert(pki_x509 *cert)
|
||||
if ( !dlg->exec()) return;
|
||||
string ndesc = dlg->descr->text().latin1();
|
||||
if (ndesc != cert->getDescription()) {
|
||||
certs->updatePKI(cert, ndesc);
|
||||
certs->renamePKI(cert, ndesc);
|
||||
}
|
||||
opensslError(cert);
|
||||
}
|
||||
@ -361,7 +363,7 @@ void MainWindow::showPopupCert(QListViewItem *item, const QPoint &pt, int x) {
|
||||
}
|
||||
else {
|
||||
pki_x509 *cert = (pki_x509 *)certs->getSelectedPKI(item->text(0).latin1());
|
||||
menu->insertItem(tr("Rename"), this, SLOT(renameCert()));
|
||||
menu->insertItem(tr("Rename"), this, SLOT(startRenameCert()));
|
||||
menu->insertItem(tr("Show Details"), this, SLOT(showDetailsCert()));
|
||||
menu->insertItem(tr("Export"), this, SLOT(writeCert()));
|
||||
menu->insertItem(tr("Delete"), this, SLOT(deleteCert()));
|
||||
@ -375,7 +377,7 @@ void MainWindow::showPopupCert(QListViewItem *item, const QPoint &pt, int x) {
|
||||
}
|
||||
else
|
||||
itemRevoke = menu->insertItem(tr("Revoke"), this, SLOT(revoke()));
|
||||
canSign = (certs->findKey(cert->getSigner()) != NULL) && (cert->getSigner() != cert);
|
||||
canSign = (cert->getSigner() && (cert->getSigner()->getKey() != NULL)) && (cert->getSigner() != cert);
|
||||
}
|
||||
menu->setItemEnabled(itemExtend, canSign);
|
||||
menu->setItemEnabled(itemRevoke, canSign);
|
||||
@ -384,8 +386,12 @@ void MainWindow::showPopupCert(QListViewItem *item, const QPoint &pt, int x) {
|
||||
return;
|
||||
}
|
||||
|
||||
void MainWindow::renameCert() {
|
||||
renamePKI(certs);
|
||||
void MainWindow::renameCert(QListViewItem *item, int col, const QString &text)
|
||||
{
|
||||
if (col != 0) return;
|
||||
pki_base *pki = certs->getSelectedPKI(item);
|
||||
string txt = text.latin1();
|
||||
certs->renamePKI(pki, txt);
|
||||
}
|
||||
|
||||
void MainWindow::setTrust()
|
||||
@ -409,7 +415,8 @@ void MainWindow::setTrust()
|
||||
if (dlg->trust2->isChecked()) newstate = 2;
|
||||
if (newstate==state) return;
|
||||
cert->setTrust(newstate);
|
||||
certs->updatePKI(cert, cert->getDescription());
|
||||
certs->updatePKI(cert);
|
||||
certs->updateViewAll();
|
||||
}
|
||||
|
||||
void MainWindow::revoke()
|
||||
@ -417,7 +424,8 @@ void MainWindow::revoke()
|
||||
pki_x509 *cert = (pki_x509 *)certs->getSelectedPKI();
|
||||
if (!cert) return;
|
||||
cert->setRevoked(true);
|
||||
certs->updatePKI(cert, cert->getDescription());
|
||||
certs->updatePKI(cert);
|
||||
certs->updateViewAll();
|
||||
}
|
||||
|
||||
void MainWindow::unRevoke()
|
||||
@ -425,5 +433,18 @@ void MainWindow::unRevoke()
|
||||
pki_x509 *cert = (pki_x509 *)certs->getSelectedPKI();
|
||||
if (!cert) return;
|
||||
cert->setRevoked(false);
|
||||
certs->updatePKI(cert, cert->getDescription());
|
||||
certs->updatePKI(cert);
|
||||
certs->updateViewAll();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::startRenameCert()
|
||||
{
|
||||
#ifdef qt3
|
||||
pki_base *pki = certs->getSelectedPKI();
|
||||
QListViewItem *item = (QListViewItem *)pki->getPointer();
|
||||
item->startRename(0);
|
||||
#else
|
||||
renamePKI(certs);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ void MainWindow::showDetailsReq(pki_x509req *req)
|
||||
if ( !dlg->exec()) return;
|
||||
string ndesc = dlg->descr->text().latin1();
|
||||
if (ndesc != req->getDescription()) {
|
||||
reqs->updatePKI(req, ndesc);
|
||||
reqs->renamePKI(req, ndesc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,7 +137,7 @@ void MainWindow::showPopupReq(QListViewItem *item, const QPoint &pt, int x) {
|
||||
menu->insertItem(tr("Import"), this, SLOT(loadReq()));
|
||||
}
|
||||
else {
|
||||
menu->insertItem(tr("Rename"), this, SLOT(renameReq()));
|
||||
menu->insertItem(tr("Rename"), this, SLOT(startRenameReq()));
|
||||
menu->insertItem(tr("Show Details"), this, SLOT(showDetailsReq()));
|
||||
menu->insertItem(tr("Export"), this, SLOT(writeReq()));
|
||||
menu->insertItem(tr("Delete"), this, SLOT(deleteReq()));
|
||||
@ -146,6 +146,21 @@ void MainWindow::showPopupReq(QListViewItem *item, const QPoint &pt, int x) {
|
||||
return;
|
||||
}
|
||||
|
||||
void MainWindow::renameReq() {
|
||||
renamePKI(reqs);
|
||||
void MainWindow::renameReq(QListViewItem *item, int col, const QString &text)
|
||||
{
|
||||
pki_base *pki = reqs->getSelectedPKI(item);
|
||||
string txt = text.latin1();
|
||||
reqs->renamePKI(pki, txt);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::startRenameReq()
|
||||
{
|
||||
#ifdef qt3
|
||||
pki_base *pki = reqs->getSelectedPKI();
|
||||
QListViewItem *item = (QListViewItem *)pki->getPointer();
|
||||
item->startRename(0);
|
||||
#else
|
||||
renamePKI(certs);
|
||||
#endif
|
||||
}
|
||||
|
||||
114
lib/db_base.cpp
114
lib/db_base.cpp
@ -165,6 +165,7 @@ void db_base::loadContainer()
|
||||
delete (k);
|
||||
delete (d);
|
||||
freeCursor(cursor);
|
||||
preprocess();
|
||||
}
|
||||
|
||||
|
||||
@ -174,19 +175,32 @@ bool db_base::updateView()
|
||||
listView->clear();
|
||||
pki_base *pki;
|
||||
if (container.isEmpty()) return false;
|
||||
for ( pki = container.first(); pki != NULL; pki = container.next() ) pki->delPointer();
|
||||
QListIterator<pki_base> it(container);
|
||||
for ( ; it.current(); ++it ) {
|
||||
pki = it.current();
|
||||
QListViewItem * lvi = new QListViewItem(listView, pki->getDescription().c_str());
|
||||
lvi->setPixmap(0, *icon);
|
||||
QListViewItem *lvi = new QListViewItem(listView, pki->getDescription().c_str());
|
||||
listView->insertItem(lvi);
|
||||
pki->setPointer(lvi);
|
||||
updateViewPKI(pki);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool db_base::insertPKI(pki_base *pki)
|
||||
bool db_base::insertPKI(pki_base *pki)
|
||||
{
|
||||
bool s = _writePKI(pki, false);
|
||||
if (s) {
|
||||
inToCont(pki);
|
||||
updateView();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
bool db_base::_writePKI(pki_base *pki, bool overwrite, DbTxn *tid = NULL)
|
||||
{
|
||||
int flags = 0;
|
||||
if (!overwrite) flags = DB_NOOVERWRITE;
|
||||
string desc = pki->getDescription();
|
||||
string orig = desc;
|
||||
int size=0;
|
||||
@ -200,7 +214,7 @@ bool db_base::insertPKI(pki_base *pki)
|
||||
Dbt d((void *)p, size);
|
||||
cerr << "Size: " << d.get_size() << "\n";
|
||||
|
||||
if ((x = data->put(NULL, &k, &d, DB_NOOVERWRITE ))!=0) {
|
||||
if ((x = data->put(tid, &k, &d, flags ))!=0) {
|
||||
data->err(x,"DB Error put");
|
||||
sprintf(field,"%02i", ++cnt);
|
||||
string z = field;
|
||||
@ -209,27 +223,61 @@ bool db_base::insertPKI(pki_base *pki)
|
||||
}
|
||||
if (x != DB_KEYEXIST && x != 0) {
|
||||
data->err(x,"DB Error put");
|
||||
//return false;
|
||||
OPENSSL_free(p);
|
||||
return false;
|
||||
}
|
||||
OPENSSL_free(p);
|
||||
pki->setDescription(desc);
|
||||
container.append(pki);
|
||||
updateView();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool db_base::deletePKI(pki_base *pki)
|
||||
bool db_base::_removePKI(pki_base *pki, DbTxn *tid = NULL)
|
||||
{
|
||||
string desc = pki->getDescription();
|
||||
Dbt k((void *)desc.c_str(), desc.length() + 1);
|
||||
int x = data->del(NULL, &k, 0);
|
||||
int x = data->del(tid, &k, 0);
|
||||
if (x){
|
||||
data->err(x,"DB Error del");
|
||||
return false;
|
||||
}
|
||||
remFromCont(pki);
|
||||
updateView();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool db_base::deletePKI(pki_base *pki)
|
||||
{
|
||||
bool s = _removePKI(pki);
|
||||
if (s) {
|
||||
remFromCont(pki);
|
||||
updateView();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
bool db_base::renamePKI(pki_base *pki, string desc)
|
||||
{
|
||||
string oldname = pki->getDescription();
|
||||
DbTxn *tid = NULL;
|
||||
//dbenv->txn_begin(NULL, &tid, 0);
|
||||
if (! _removePKI(pki, tid)) {
|
||||
//tid->abort();
|
||||
return false;
|
||||
}
|
||||
pki->setDescription(desc);
|
||||
if (! _writePKI(pki, false, tid)) {
|
||||
//tid->abort();
|
||||
return false;
|
||||
}
|
||||
// rename the pki in the listView .....
|
||||
QListViewItem * item = (QListViewItem *)pki->getPointer();
|
||||
if (!item) {
|
||||
//tid->abort();
|
||||
return false;
|
||||
}
|
||||
item->setText(0, pki->getDescription().c_str());
|
||||
//tid->commit(0);
|
||||
updateViewPKI(pki);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -238,14 +286,18 @@ void db_base::remFromCont(pki_base *pki)
|
||||
container.remove(pki);
|
||||
}
|
||||
|
||||
bool db_base::updatePKI(pki_base *pki, string desc)
|
||||
|
||||
void db_base::inToCont(pki_base *pki)
|
||||
{
|
||||
if (deletePKI(pki)){
|
||||
pki->setDescription(desc);
|
||||
return insertPKI(pki);
|
||||
}
|
||||
updateView();
|
||||
return true;
|
||||
container.append(pki);
|
||||
}
|
||||
|
||||
|
||||
bool db_base::updatePKI(pki_base *pki)
|
||||
{
|
||||
bool s = _writePKI(pki, true);
|
||||
if (s) updateViewPKI(pki);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@ -258,8 +310,23 @@ pki_base *db_base::getSelectedPKI(string desc)
|
||||
pki = it.current();
|
||||
if (pki->getDescription() == desc) return pki;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
pki_base *db_base::getSelectedPKI(void *item)
|
||||
{
|
||||
if (item == NULL) return NULL;
|
||||
pki_base *pki;
|
||||
QListIterator<pki_base> it(container);
|
||||
for ( ; it.current(); ++it ) {
|
||||
pki = it.current();
|
||||
if (pki->getPointer() == item) return pki;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
pki_base *db_base::getSelectedPKI()
|
||||
{
|
||||
const char *tp;
|
||||
@ -290,3 +357,12 @@ QPixmap *db_base::loadImg(const char *name )
|
||||
return new QPixmap(path + name);
|
||||
}
|
||||
|
||||
void db_base::updateViewPKI(pki_base *pki)
|
||||
{
|
||||
if (! pki) return;
|
||||
QListViewItem *current = (QListViewItem *)pki->getPointer();
|
||||
if (!current) return;
|
||||
current->setRenameEnabled(0,true);
|
||||
current->setText(0, pki->getDescription().c_str());
|
||||
}
|
||||
|
||||
|
||||
@ -23,16 +23,20 @@ class db_base: public QObject
|
||||
DbEnv *dbenv;
|
||||
QListView *listView;
|
||||
QList<pki_base> container;
|
||||
QPixmap *icon;
|
||||
bool _writePKI(pki_base *pki, bool overwrite, DbTxn *tid = NULL);
|
||||
bool _removePKI(pki_base *pki, DbTxn *tid = NULL);
|
||||
public:
|
||||
db_base(DbEnv *dbe, string DBfile, string db);
|
||||
virtual ~db_base();
|
||||
virtual pki_base *newPKI(){
|
||||
CERR<<"VIRTUAL CALLED: newPKI\n"; return NULL;}
|
||||
virtual bool updateView();
|
||||
virtual void updateViewPKI(pki_base *pki);
|
||||
virtual bool insertPKI(pki_base *pki);
|
||||
bool deletePKI(pki_base *pki);
|
||||
bool updatePKI(pki_base *pki, string desc);
|
||||
virtual bool deletePKI(pki_base *pki);
|
||||
virtual bool updatePKI(pki_base *pki);
|
||||
virtual bool renamePKI(pki_base *pki, string desc);
|
||||
pki_base *getSelectedPKI(void *item);
|
||||
pki_base *getSelectedPKI(string desc);
|
||||
pki_base *getSelectedPKI();
|
||||
pki_base *findPKI(pki_base *refpki);
|
||||
@ -41,6 +45,7 @@ class db_base: public QObject
|
||||
* i.e search for signers and keys */
|
||||
virtual void preprocess() {return;}
|
||||
virtual void remFromCont(pki_base *pki);
|
||||
virtual void inToCont(pki_base *pki);
|
||||
Dbc *getCursor();
|
||||
bool freeCursor(Dbc *cursor);
|
||||
void *getData(void* key, int length, int *dsize);
|
||||
|
||||
@ -6,6 +6,8 @@ db_key::db_key(DbEnv *dbe, string DBfile, QListView *l)
|
||||
{
|
||||
listView = l;
|
||||
loadContainer();
|
||||
keyicon[0] = loadImg("key.png");
|
||||
keyicon[1] = loadImg("halfkey.png");
|
||||
updateView();
|
||||
}
|
||||
|
||||
@ -14,30 +16,6 @@ pki_base *db_key::newPKI(){
|
||||
}
|
||||
|
||||
|
||||
bool db_key::updateView()
|
||||
{
|
||||
listView->clear();
|
||||
QPixmap *pm[2];
|
||||
pm[0] = loadImg("key.png");
|
||||
pm[1] = loadImg("halfkey.png");
|
||||
pki_key *pki;
|
||||
QListViewItem *current;
|
||||
cerr <<"myupdate keys"<<endl;
|
||||
if ( container.isEmpty() ) return false;
|
||||
QListIterator<pki_base> it(container);
|
||||
for ( ; it.current(); ++it ) {
|
||||
pki = (pki_key *)it.current();
|
||||
// create the listview item
|
||||
current = new QListViewItem(listView, pki->getDescription().c_str());
|
||||
CERR<< "Adding as parent: "<<pki->getDescription().c_str()<<endl;
|
||||
int pixnum = 0;
|
||||
if (pki->isPubKey()) pixnum += 1;
|
||||
current->setPixmap(0, *pm[pixnum]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
QStringList db_key::getPrivateDesc()
|
||||
{
|
||||
pki_key *pki;
|
||||
@ -52,13 +30,24 @@ QStringList db_key::getPrivateDesc()
|
||||
|
||||
void db_key::remFromCont(pki_base *pki)
|
||||
{
|
||||
container.remove(pki);
|
||||
db_base::remFromCont(pki);
|
||||
emit delKey((pki_key *)pki);
|
||||
}
|
||||
|
||||
bool db_key::insertPKI(pki_base *pki)
|
||||
void db_key::inToCont(pki_base *pki)
|
||||
{
|
||||
db_base::insertPKI(pki);
|
||||
db_base::inToCont(pki);
|
||||
emit newKey((pki_key *)pki);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void db_key::updateViewPKI(pki_base *pki)
|
||||
{
|
||||
db_base::updateViewPKI(pki);
|
||||
if (! pki) return;
|
||||
int pixnum = 0;
|
||||
QListViewItem *current = (QListViewItem *)pki->getPointer();
|
||||
if (!current) return;
|
||||
if (((pki_key *)pki)->isPubKey()) pixnum += 1;
|
||||
current->setPixmap(0, *keyicon[pixnum]);
|
||||
}
|
||||
|
||||
@ -9,12 +9,14 @@
|
||||
class db_key: public db_base
|
||||
{
|
||||
Q_OBJECT
|
||||
protected:
|
||||
QPixmap *keyicon[2];
|
||||
public:
|
||||
db_key(DbEnv *dbe, string DBfile, QListView *l);
|
||||
pki_base *newPKI();
|
||||
QStringList getPrivateDesc();
|
||||
bool updateView();
|
||||
bool insertPKI(pki_base *pki);
|
||||
void updateViewPKI(pki_base *pki);
|
||||
void inToCont(pki_base *pki);
|
||||
void remFromCont(pki_base *pki);
|
||||
signals:
|
||||
void delKey(pki_key *delkey);
|
||||
|
||||
154
lib/db_x509.cpp
154
lib/db_x509.cpp
@ -6,6 +6,12 @@ db_x509::db_x509(DbEnv *dbe, string DBfile, QListView *l, db_key *keyl)
|
||||
{
|
||||
keylist = keyl;
|
||||
listView = l;
|
||||
certicon[0] = loadImg("validcert.png");
|
||||
certicon[1] = loadImg("validcertkey.png");
|
||||
certicon[2] = loadImg("invalidcert.png");
|
||||
certicon[3] = loadImg("invalidcertkey.png");
|
||||
listView->addColumn(tr("Trust state"));
|
||||
listView->addColumn(tr("Revokation"));
|
||||
loadContainer();
|
||||
updateView();
|
||||
connect(keyl, SIGNAL(delKey(pki_key *)), this, SLOT(delKey(pki_key *)));
|
||||
@ -36,19 +42,15 @@ bool db_x509::updateView()
|
||||
{
|
||||
listView->clear();
|
||||
listView->setRootIsDecorated(true);
|
||||
QPixmap *pm[4];
|
||||
pm[0] = loadImg("validcert.png");
|
||||
pm[1] = loadImg("invalidcert.png");
|
||||
pm[2] = loadImg("validcertkey.png");
|
||||
pm[3] = loadImg("invalidcertkey.png");
|
||||
pki_x509 *pki;
|
||||
pki_base *pkib;
|
||||
pki_x509 *signer;
|
||||
QListViewItem *parentitem;
|
||||
QListViewItem *current;
|
||||
cerr <<"myupdate"<<endl;
|
||||
if ( container.isEmpty() ) return false;
|
||||
QList<pki_base> mycont = container;
|
||||
for ( pki = (pki_x509 *)container.first(); pki != NULL; pki = (pki_x509 *)container.next() ) pki->delPointer();
|
||||
for ( pkib = container.first(); pkib != NULL; pkib = container.next() ) pkib->delPointer();
|
||||
int f=0;
|
||||
while (! mycont.isEmpty() ) {
|
||||
cerr << "-----------------------------------------------------------------Round "<< f++ <<endl;
|
||||
@ -56,7 +58,7 @@ bool db_x509::updateView()
|
||||
for ( ; it.current(); ++it ) {
|
||||
pki = (pki_x509 *)it.current();
|
||||
parentitem = NULL;
|
||||
signer = findSigner(pki);
|
||||
signer = pki->getSigner();
|
||||
if ((signer != pki) && (signer != NULL)) // foreign signed
|
||||
parentitem = (QListViewItem *)signer->getPointer();
|
||||
if (((parentitem != NULL) || (signer == pki) || (signer == NULL)) && (pki->getPointer() == NULL )) {
|
||||
@ -70,21 +72,8 @@ bool db_x509::updateView()
|
||||
cerr<< "Adding as parent: "<<pki->getDescription().c_str()<<endl;
|
||||
}
|
||||
pki->setPointer(current);
|
||||
int pixnum = 0;
|
||||
if (pki->getTrust() == 0){ // Never Trust it
|
||||
pixnum += 1;
|
||||
}
|
||||
else if (pki->getTrust() == 1) { // Trust it, if we trust parent
|
||||
if (signer == pki ) pixnum += 1; // self signed
|
||||
else if (!signer) pixnum += 1 ; // no signer
|
||||
else if (!signer->getEffTrust()) pixnum += 1 ; // no trust of parent
|
||||
}
|
||||
if (pixnum == 0) pki->setEffTrust(true);
|
||||
else pki->setEffTrust(false); // remember the effektive truststate
|
||||
if (findKey(pki)) pixnum += 2;
|
||||
// if pki->getTrust() == 2 trust it always
|
||||
current->setPixmap(0, *pm[pixnum]);
|
||||
mycont.remove(pki);
|
||||
updateViewPKI(pki);
|
||||
it.toFirst();
|
||||
}
|
||||
}
|
||||
@ -93,6 +82,42 @@ bool db_x509::updateView()
|
||||
return true;
|
||||
}
|
||||
|
||||
void db_x509::updateViewPKI(pki_base *pki)
|
||||
{
|
||||
db_base::updateViewPKI(pki);
|
||||
if (! pki) return;
|
||||
QString truststatus[] = { tr("Not trusted"), tr("Trust inherited"), tr("Always Trusted") };
|
||||
int pixnum = 0;
|
||||
QListViewItem *current = (QListViewItem *)pki->getPointer();
|
||||
if (!current) return;
|
||||
if (((pki_x509 *)pki)->getKey()) {
|
||||
pixnum += 1;
|
||||
}
|
||||
if (((pki_x509 *)pki)->calcEffTrust() == 0){
|
||||
pixnum += 2;
|
||||
}
|
||||
current->setPixmap(0, *certicon[pixnum]);
|
||||
current->setText(1, truststatus[((pki_x509 *)pki)->getTrust() ]);
|
||||
if ( ((pki_x509 *)pki)->isRevoked() ){
|
||||
current->setText(2, tr("Revoked"));
|
||||
}
|
||||
else {
|
||||
current->setText(2, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void db_x509::updateViewAll()
|
||||
{
|
||||
pki_x509 *pki;
|
||||
QListIterator<pki_base> it(container);
|
||||
for ( ; it.current(); ++it ) {
|
||||
pki = (pki_x509 *)it.current();
|
||||
updateViewPKI(pki);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
QStringList db_x509::getPrivateDesc()
|
||||
{
|
||||
@ -100,7 +125,7 @@ QStringList db_x509::getPrivateDesc()
|
||||
QStringList x;
|
||||
if ( container.isEmpty() ) return x;
|
||||
for ( pki = (pki_x509 *)container.first(); pki != 0; pki = (pki_x509 *)container.next() ) {
|
||||
if (findKey(pki))
|
||||
if (pki->getKey())
|
||||
x.append(pki->getDescription().c_str());
|
||||
}
|
||||
return x;
|
||||
@ -114,7 +139,7 @@ void db_x509::remFromCont(pki_base *pki)
|
||||
QListIterator<pki_base> it(container);
|
||||
for ( ; it.current(); ++it ) {
|
||||
pkiit = (pki_x509 *)it.current();
|
||||
if (pkiit->getSigner()==pki) {
|
||||
if (pkiit->getSigner() == pki) {
|
||||
pkiit->delSigner();
|
||||
}
|
||||
}
|
||||
@ -123,24 +148,93 @@ void db_x509::remFromCont(pki_base *pki)
|
||||
|
||||
pki_key *db_x509::findKey(pki_x509* cert)
|
||||
{
|
||||
pki_key *key, *refkey;
|
||||
if (!cert) return NULL;
|
||||
pki_key *key;
|
||||
key = (pki_key *)keylist->findPKI(cert->getKey());
|
||||
if (key)
|
||||
if (key->isPubKey())
|
||||
if ((key = cert->getKey()) != NULL ) return key;
|
||||
refkey = cert->getPubKey();
|
||||
key = (pki_key *)keylist->findPKI(refkey);
|
||||
if (key && key->isPubKey()) {
|
||||
key = NULL;
|
||||
|
||||
}
|
||||
cert->setKey(key);
|
||||
delete(refkey);
|
||||
return key;
|
||||
}
|
||||
|
||||
void db_x509::delKey(pki_key *delkey)
|
||||
{
|
||||
updateView();
|
||||
pki_x509 *pki;
|
||||
if ( container.isEmpty() ) return ;
|
||||
for ( pki = (pki_x509 *)container.first(); pki != 0; pki = (pki_x509 *)container.next() ) {
|
||||
if (pki->getKey()) {
|
||||
pki->delKey();
|
||||
updateViewPKI(pki);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void db_x509::newKey(pki_key *newkey)
|
||||
{
|
||||
updateView();
|
||||
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)) {
|
||||
pki->setKey(newkey);
|
||||
updateViewPKI(pki);
|
||||
}
|
||||
delete(refkey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void db_x509::preprocess()
|
||||
{
|
||||
pki_x509 *pki;
|
||||
pki_x509 *signer;
|
||||
CERR <<"preprocess X509"<<endl;
|
||||
if ( container.isEmpty() ) return ;
|
||||
// copy the container, cause we will drop the handled items...
|
||||
QList<pki_base> mycont = container;
|
||||
QListIterator<pki_base> iter(mycont);
|
||||
for ( ; iter.current(); ++iter ) { // find the signer and the key of the certificate...
|
||||
pki = (pki_x509 *)iter.current();
|
||||
findSigner(pki);
|
||||
CERR << "Signer of "<< pki->getDescription().c_str() << endl;
|
||||
findKey(pki);
|
||||
CERR << "Key of "<< pki->getDescription().c_str() << endl;
|
||||
}
|
||||
CERR << "Signers and keys done "<< endl;
|
||||
while (! mycont.isEmpty() ) {
|
||||
QListIterator<pki_base> it(mycont);
|
||||
for (it.toFirst(); it.current(); ++it ) {
|
||||
int trust = 1; // dont know
|
||||
pki = (pki_x509 *)it.current();
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
if (trust != 1) { // trustment deterministic
|
||||
pki->setEffTrust(trust);
|
||||
mycont.remove(pki);
|
||||
it.toFirst();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -12,12 +12,16 @@ class db_x509: public db_base
|
||||
Q_OBJECT
|
||||
protected:
|
||||
db_key *keylist;
|
||||
QPixmap *certicon[4];
|
||||
public:
|
||||
db_x509(DbEnv *dbe, string DBfile, QListView *l, db_key *keyl);
|
||||
pki_base *newPKI();
|
||||
pki_x509 *findSigner(pki_x509 *client);
|
||||
bool updateView();
|
||||
void updateViewAll();
|
||||
void updateViewPKI(pki_base *pki);
|
||||
void remFromCont(pki_base *pki);
|
||||
void preprocess();
|
||||
QStringList getPrivateDesc();
|
||||
pki_key * findKey(pki_x509 *cert);
|
||||
public slots:
|
||||
|
||||
@ -7,9 +7,11 @@ db_x509req::db_x509req(DbEnv *dbe, string DBfile, QListView *l, db_key *keyl)
|
||||
listView = l;
|
||||
keylist = keyl;
|
||||
loadContainer();
|
||||
updateView();
|
||||
reqicon[0] = loadImg("req.png");
|
||||
reqicon[1] = loadImg("reqkey.png");
|
||||
connect(keyl, SIGNAL(delKey(pki_key *)), this, SLOT(delKey(pki_key *)));
|
||||
connect(keyl, SIGNAL(newKey(pki_key *)), this, SLOT(newKey(pki_key *)));
|
||||
updateView();
|
||||
}
|
||||
|
||||
pki_base *db_x509req::newPKI(){
|
||||
@ -27,29 +29,6 @@ QStringList db_x509req::getDesc()
|
||||
return x;
|
||||
}
|
||||
|
||||
bool db_x509req::updateView()
|
||||
{
|
||||
listView->clear();
|
||||
QPixmap *pm[2];
|
||||
pm[0] = loadImg("req.png");
|
||||
pm[1] = loadImg("reqkey.png");
|
||||
pki_x509req *pki;
|
||||
QListViewItem *current;
|
||||
cerr <<"myupdate requests"<<endl;
|
||||
if ( container.isEmpty() ) return false;
|
||||
QListIterator<pki_base> it(container);
|
||||
for ( ; it.current(); ++it ) {
|
||||
pki = (pki_x509req *)it.current();
|
||||
// create the listview item
|
||||
current = new QListViewItem(listView, pki->getDescription().c_str());
|
||||
cerr<< "Adding as parent: "<<pki->getDescription().c_str()<<endl;
|
||||
int pixnum = 0;
|
||||
if (keylist->findPKI(pki->getKey())) pixnum += 1;
|
||||
current->setPixmap(0, *pm[pixnum]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void db_x509req::delKey(pki_key *delkey)
|
||||
{
|
||||
@ -62,3 +41,42 @@ void db_x509req::newKey(pki_key *newkey)
|
||||
updateView();
|
||||
}
|
||||
|
||||
void db_x509req::updateViewPKI(pki_base *pki)
|
||||
{
|
||||
db_base::updateViewPKI(pki);
|
||||
if (! pki) return;
|
||||
int pixnum = 0;
|
||||
QListViewItem *current = (QListViewItem *)pki->getPointer();
|
||||
if (!current) return;
|
||||
if (((pki_x509req *)pki)->getKey() != NULL ) pixnum += 1;
|
||||
current->setPixmap(0, *reqicon[pixnum]);
|
||||
}
|
||||
|
||||
void db_x509req::preprocess()
|
||||
{
|
||||
pki_x509req *pki;
|
||||
CERR <<"preprocess X509req"<<endl;
|
||||
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() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pki_key *db_x509req::findKey(pki_x509req *req)
|
||||
{
|
||||
pki_key *key, *refkey;
|
||||
if (!req) return NULL;
|
||||
if ((key = req->getKey()) != NULL ) return key;
|
||||
refkey = req->getPubKey();
|
||||
key = (pki_key *)keylist->findPKI(refkey);
|
||||
if (key && key->isPubKey()) {
|
||||
key = NULL;
|
||||
}
|
||||
req->setKey(key);
|
||||
delete(refkey);
|
||||
return key;
|
||||
}
|
||||
|
||||
@ -11,11 +11,14 @@ class db_x509req: public db_base
|
||||
Q_OBJECT
|
||||
protected:
|
||||
db_key *keylist;
|
||||
QPixmap *reqicon[2];
|
||||
public:
|
||||
db_x509req(DbEnv *dbe, string DBfile, QListView *l, db_key *keyl);
|
||||
pki_base *newPKI();
|
||||
QStringList getDesc();
|
||||
bool updateView();
|
||||
void updateViewPKI(pki_base *pki);
|
||||
void preprocess();
|
||||
pki_key *findKey(pki_x509req *req);
|
||||
public slots:
|
||||
void delKey(pki_key *delkey);
|
||||
void newKey(pki_key *newKey);
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
#include "pki_x509.h"
|
||||
|
||||
|
||||
pki_x509::pki_x509(string d, pki_x509req *req, pki_x509 *signer, int days, int serial)
|
||||
pki_x509::pki_x509(string d,pki_key *clientKey, pki_x509req *req, pki_x509 *signer, int days, int serial)
|
||||
:pki_base( d )
|
||||
{
|
||||
X509_NAME *issn, *reqn;
|
||||
@ -37,7 +37,9 @@ pki_x509::pki_x509(string d, pki_x509req *req, pki_x509 *signer, int days, int s
|
||||
X509V3_set_ctx(&ext_ctx, signer->cert, cert, req->request, NULL, 0);
|
||||
|
||||
trust = 2;
|
||||
efftrust = 2;
|
||||
psigner = signer;
|
||||
pkey = clientKey;
|
||||
revoked = NULL;
|
||||
}
|
||||
|
||||
@ -47,7 +49,9 @@ pki_x509::pki_x509() : pki_base()
|
||||
cert = X509_new();
|
||||
openssl_error();
|
||||
psigner = NULL;
|
||||
pkey= NULL;
|
||||
trust = 0;
|
||||
efftrust = 0;
|
||||
revoked = NULL;
|
||||
}
|
||||
|
||||
@ -84,8 +88,10 @@ pki_x509::pki_x509(const string fname)
|
||||
else pki_error("Error opening file");
|
||||
fclose(fp);
|
||||
trust = 1;
|
||||
efftrust = 1;
|
||||
psigner = NULL;
|
||||
revoked = NULL;
|
||||
pkey = NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -108,6 +114,9 @@ void pki_x509::sign(pki_key *signkey)
|
||||
X509_sign(cert, signkey->key, digest);
|
||||
openssl_error();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Save the Certificate to data and back:
|
||||
* Version 1:
|
||||
* int Version
|
||||
@ -141,6 +150,7 @@ bool pki_x509::fromData(unsigned char *p, int size)
|
||||
cert = d2i_X509(NULL, &p, size);
|
||||
revoked = NULL;
|
||||
trust = 1;
|
||||
efftrust = 1;
|
||||
}
|
||||
if (openssl_error()) return false;
|
||||
return true;
|
||||
@ -267,7 +277,7 @@ bool pki_x509::verify(pki_x509 *signer)
|
||||
}
|
||||
|
||||
|
||||
pki_key *pki_x509::getKey()
|
||||
pki_key *pki_x509::getPubKey()
|
||||
{
|
||||
EVP_PKEY *pkey = X509_get_pubkey(cert);
|
||||
pki_key *key = new pki_key(pkey);
|
||||
@ -306,6 +316,9 @@ int pki_x509::checkDate()
|
||||
|
||||
|
||||
pki_x509 *pki_x509::getSigner() { return (psigner); }
|
||||
pki_key *pki_x509::getKey() { return (pkey); }
|
||||
void pki_x509::setKey(pki_key *key) { pkey = key; }
|
||||
void pki_x509::delKey() { pkey = NULL; }
|
||||
|
||||
|
||||
void pki_x509::delSigner() { psigner=NULL; }
|
||||
@ -365,14 +378,15 @@ void pki_x509::setTrust(int t)
|
||||
trust = t;
|
||||
}
|
||||
|
||||
bool pki_x509::getEffTrust()
|
||||
int pki_x509::getEffTrust()
|
||||
{
|
||||
return efftrust;
|
||||
}
|
||||
|
||||
void pki_x509::setEffTrust(bool t)
|
||||
void pki_x509::setEffTrust(int t)
|
||||
{
|
||||
efftrust = t;
|
||||
if (t>= 0 && t<= 2)
|
||||
efftrust = t;
|
||||
}
|
||||
|
||||
|
||||
@ -385,7 +399,7 @@ bool pki_x509::isRevoked()
|
||||
void pki_x509::setRevoked(bool rev)
|
||||
{
|
||||
if (rev) {
|
||||
setEffTrust(false);
|
||||
setEffTrust(0);
|
||||
setTrust(0);
|
||||
if (revoked) return;
|
||||
revoked = ASN1_TIME_new();
|
||||
@ -398,3 +412,21 @@ void pki_x509::setRevoked(bool rev)
|
||||
}
|
||||
}
|
||||
|
||||
int pki_x509::calcEffTrust()
|
||||
{
|
||||
int mytrust = trust;
|
||||
if (mytrust != 1) {
|
||||
efftrust = mytrust;
|
||||
return mytrust;
|
||||
}
|
||||
//we must look at the parent certs
|
||||
pki_x509 *signer = getSigner();
|
||||
while (mytrust==1 && signer != NULL && signer != this) {
|
||||
mytrust = signer->getTrust();
|
||||
signer = signer->getSigner();
|
||||
}
|
||||
|
||||
if (mytrust == 1) mytrust = 0;
|
||||
efftrust = mytrust;
|
||||
return mytrust;
|
||||
}
|
||||
|
||||
@ -12,14 +12,14 @@ class pki_x509 : public pki_base
|
||||
{
|
||||
private:
|
||||
pki_x509 *psigner;
|
||||
pki_x509 *pkey;
|
||||
pki_key *pkey;
|
||||
X509V3_CTX ext_ctx;
|
||||
X509 *cert;
|
||||
ASN1_TIME *revoked;
|
||||
int trust;
|
||||
bool efftrust;
|
||||
int efftrust;
|
||||
public:
|
||||
pki_x509(string d, pki_x509req *req, pki_x509 *signer, int days, int serial);
|
||||
pki_x509(string d, pki_key *clientKey, pki_x509req *req, pki_x509 *signer, int days, int serial);
|
||||
pki_x509();
|
||||
pki_x509(const string fname);
|
||||
~pki_x509();
|
||||
@ -31,6 +31,9 @@ class pki_x509 : public pki_base
|
||||
void writeCert(const string fname, bool PEM);
|
||||
bool verify(pki_x509 *signer);
|
||||
pki_key *getKey();
|
||||
pki_key *getPubKey(); // will be created temporarily and must be freed
|
||||
void delKey();
|
||||
void setKey(pki_key *key);
|
||||
string notAfter();
|
||||
string notBefore();
|
||||
string revokedAt();
|
||||
@ -46,10 +49,11 @@ class pki_x509 : public pki_base
|
||||
X509 *getCert(){ return cert;}
|
||||
int getTrust();
|
||||
void setTrust(int t);
|
||||
bool getEffTrust();
|
||||
void setEffTrust(bool t);
|
||||
int getEffTrust();
|
||||
void setEffTrust(int t);
|
||||
void setRevoked(bool rev);
|
||||
bool isRevoked();
|
||||
int calcEffTrust();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -163,10 +163,22 @@ int pki_x509req::verify()
|
||||
else return pki_base::VERIFY_ERROR;
|
||||
}
|
||||
|
||||
pki_key *pki_x509req::getKey()
|
||||
pki_key *pki_x509req::getPubKey()
|
||||
{
|
||||
EVP_PKEY *pkey = X509_REQ_get_pubkey(request);
|
||||
pki_key *key = new pki_key(pkey);
|
||||
openssl_error();
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
pki_key *pki_x509req::getKey()
|
||||
{
|
||||
return privkey;
|
||||
}
|
||||
|
||||
|
||||
void pki_x509req::setKey(pki_key *key)
|
||||
{
|
||||
privkey = key;
|
||||
}
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
|
||||
class pki_x509req : public pki_base
|
||||
{
|
||||
protected:
|
||||
pki_key *privkey;
|
||||
public:
|
||||
X509_REQ *request;
|
||||
pki_x509req(pki_key *key, const string cn,
|
||||
@ -24,7 +26,9 @@ class pki_x509req : public pki_base
|
||||
string getDN(int nid);
|
||||
void writeReq(const string fname, bool PEM);
|
||||
int verify();
|
||||
pki_key *getPubKey();
|
||||
pki_key *getKey();
|
||||
void setKey(pki_key *key);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user