Add token as item source, minor fixes

Use dynamic cast for sqlSELECTpki()
Fix Double-click links in cert details
This commit is contained in:
Christian Hohnstaedt 2017-11-20 08:48:57 +01:00
parent 0745e18da2
commit dc75fa0171
13 changed files with 58 additions and 40 deletions

View File

@ -81,7 +81,7 @@ void db_crl::removeSigner(pki_base *signer)
void db_crl::inToCont(pki_base *pki)
{
pki_crl *crl = (pki_crl *)pki;
pki_crl *crl = static_cast<pki_crl *>(pki);
unsigned hash = crl->getSubject().hashNum();
QList<pki_base *> items;
@ -91,15 +91,15 @@ void db_crl::inToCont(pki_base *pki)
QList<QVariant>() << QVariant(hash));
foreach(pki_base *b, items) {
qDebug() << "Possible Crl issuer:" << b->getIntName();
crl->verify(static_cast<pki_x509*>(b));
crl->verify(dynamic_cast<pki_x509*>(b));
}
db_base::inToCont(pki);
}
pki_base *db_crl::insert(pki_base *item)
{
pki_crl *crl = (pki_crl *)item;
pki_crl *oldcrl = (pki_crl *)getByReference(crl);
pki_crl *crl = static_cast<pki_crl *>(item);
pki_crl *oldcrl = dynamic_cast<pki_crl *>(getByReference(crl));
if (oldcrl) {
XCA_INFO(tr("The revocation list already exists in the database as:\n'%1'\nand so it was not imported").arg(oldcrl->getIntName()));
delete(crl);
@ -112,10 +112,10 @@ pki_base *db_crl::insert(pki_base *item)
void db_crl::showPki(pki_base *pki)
{
pki_crl *crl = (pki_crl *)pki;
CrlDetail *dlg;
dlg = new CrlDetail(mainwin);
pki_crl *crl = dynamic_cast<pki_crl *>(pki);
if (!crl)
return;
CrlDetail *dlg = new CrlDetail(mainwin);
if (!dlg)
return;

View File

@ -81,8 +81,9 @@ void db_key::remFromCont(QModelIndex &idx)
QList<pki_base*> items = sqlSELECTpki(
"SELECT item FROM x509super WHERE pkey is NULL");
foreach(pki_base *b, items) {
pki_x509super *x509s = static_cast<pki_x509super*>(b);
x509s->setRefKey(NULL);
pki_x509super *x509s = dynamic_cast<pki_x509super*>(b);
if (x509s)
x509s->setRefKey(NULL);
}
/* "UPDATE x509super SET pkey=NULL WHERE pkey=?" done in
* pki->deleteSqlData() */
@ -100,8 +101,8 @@ void db_key::inToCont(pki_base *pki)
SQL_PREPARE(q, "UPDATE x509super SET pkey=? WHERE item=?");
q.bindValue(0, key->getSqlItemId());
foreach(pki, items) {
pki_x509super *x509s = static_cast<pki_x509super*>(pki);
if (!x509s->compareRefKey(key))
pki_x509super *x509s = dynamic_cast<pki_x509super*>(pki);
if (!x509s || !x509s->compareRefKey(key))
continue;
/* Found item matching this key */
x509s->setRefKey(key);
@ -207,7 +208,10 @@ void db_key::load(void)
void db_key::showPki(pki_base *pki)
{
pki_evp *key = (pki_evp *)pki;
qDebug() << "showPki(pki_base *pki): " << pki->getType() << " - " << pki->getIntName();
pki_key *key = dynamic_cast<pki_key *>(pki);
if (!key)
return;
KeyDetail *dlg = new KeyDetail(mainwin);
if (dlg) {
dlg->setKey(key);

View File

@ -114,7 +114,9 @@ void db_temp::newItem()
}
void db_temp::showPki(pki_base *pki)
{
alterTemp(static_cast<pki_temp *>(pki));
pki_temp *t = dynamic_cast<pki_temp *>(pki);
if (t)
alterTemp(t);
}
void db_temp::load()

View File

@ -87,10 +87,10 @@ pki_base *db_x509::newPKI(enum pki_type type)
QList<pki_base *> db_x509::getAllIssuers()
{
/* Select X509 CA certificates with available private key */
return sqlSELECTpki("SELECT x509super.item FROM x509super "
"JOIN private_keys ON x509super.pkey = private_keys.item "
"JOIN certs ON certs.item = x509super.item "
"WHERE certs.ca=1");
return sqlSELECTpki("SELECT DISTINCT x.item "
"FROM (private_keys, tokens) JOIN x509super x "
"ON x.pkey = private_keys.item OR x.pkey = tokens.item "
"JOIN certs ON certs.item = x.item WHERE certs.ca=1");
}
void db_x509::remFromCont(QModelIndex &idx)
@ -200,8 +200,8 @@ void db_x509::inToCont(pki_base *pki)
"AND x509super.key_hash=?",
QList<QVariant>() << namehash << pubhash);
foreach(pki_base *b, items) {
pki_x509 *other = static_cast<pki_x509*>(b);
if (other == cert)
pki_x509 *other = dynamic_cast<pki_x509*>(b);
if (other == cert || !other)
continue;
if (!other->compareNameAndKey(cert))
continue;
@ -255,7 +255,9 @@ void db_x509::inToCont(pki_base *pki)
QList<QVariant>() << namehash);
SQL_PREPARE(q, "UPDATE crls SET issuer=? WHERE item=?");
foreach(pki_base *b, items) {
pki_crl *crl = static_cast<pki_crl*>(b);
pki_crl *crl = dynamic_cast<pki_crl*>(b);
if (!crl)
continue;
crl->verify(cert);
if (cert != crl->getIssuer())
continue;

View File

@ -187,9 +187,10 @@ void db_x509super::toTemplate(QModelIndex index)
void db_x509super::showPki(pki_base *pki)
{
pki_x509super *x = (pki_x509req *)pki;
CertDetail *dlg;
dlg = new CertDetail(mainwin);
pki_x509super *x = dynamic_cast<pki_x509super *>(pki);
if (!x)
return;
CertDetail *dlg = new CertDetail(mainwin);
if (!dlg)
return;

View File

@ -256,6 +256,7 @@ QString pki_base::pki_source_name() const
case imported: return tr("Imported");
case generated: return tr("Generated");
case transformed: return tr("Transformed");
case token: return tr("Token");
}
return QString("???");
}

View File

@ -31,7 +31,8 @@ enum pki_source {
unknown,
imported,
generated,
transformed
transformed,
token
};
#define VIEW_item_id 0

View File

@ -319,6 +319,8 @@ x509name pki_crl::getSubject() const
bool pki_crl::verify(pki_x509 *issuer)
{
if (!issuer)
return false;
if (getSubject() != issuer->getSubject())
return false;
pki_key *key = issuer->getPubKey();

View File

@ -36,6 +36,7 @@ void pki_scard::init(void)
{
ownPass = ptPin;
pkiType = smartCard;
isPub = false;
card_serial = card_manufacturer = card_label = "";
card_model = slot_label = "";
@ -238,6 +239,8 @@ void pki_scard::load_token(pkcs11 &p11, CK_OBJECT_HANDLE object)
card_manufacturer = ti.manufacturerID();
card_serial = ti.serial();
card_model = ti.model();
pkiSource = token;
isPub = false;
pk11_attr_data id(CKA_ID);
p11.loadAttribute(id, object);

View File

@ -331,6 +331,7 @@ void pki_x509::load_token(pkcs11 &p11, CK_OBJECT_HANDLE object)
}
}
setIntName(desc);
pkiSource = token;
pki_openssl_error();
}
@ -362,8 +363,8 @@ void pki_x509::store_token(bool alwaysSelect)
if (!p11.selectToken(&slot, NULL))
return;
} else {
card = (pki_scard *)privkey;
if (!card->prepare_card(&slot))
card = dynamic_cast<pki_scard *>(privkey);
if (!card || !card->prepare_card(&slot))
return;
}
@ -398,10 +399,10 @@ void pki_x509::store_token(bool alwaysSelect)
void pki_x509::deleteFromToken()
{
pki_scard *card = (pki_scard *)privkey;
pki_scard *card = dynamic_cast<pki_scard *>(privkey);
slotidList p11_slots;
if (!pkcs11::loaded())
if (!card || !pkcs11::loaded())
return;
if (privkey && privkey->isToken()) {
@ -896,7 +897,7 @@ int pki_x509::sigAlg()
pki_x509 *pki_x509::getSigner()
{
return (pki_x509 *)psigner;
return static_cast<pki_x509 *>(psigner);
}
bool pki_x509::isRevoked()

View File

@ -100,8 +100,9 @@ void CertDetail::setCert(pki_x509 *cert)
signature->setGreen();
signature->disableToolTip();
} else {
signature->setText(cert->getSigner()->getIntName());
privKey->setClickText(cert->getSqlItemId().toString());
pki_x509 *issuer = cert->getSigner();
signature->setText(issuer->getIntName());
signature->setClickText(issuer->getSqlItemId().toString());
signature->setGreen();
}

View File

@ -79,14 +79,14 @@ void ImportMulti::addItem(pki_base *pki)
mcont->inToCont(pki);
}
else if (cn == "pki_pkcs7") {
pki_pkcs7 *p7 = ( pki_pkcs7 *)pki;
pki_pkcs7 *p7 = static_cast<pki_pkcs7 *>(pki);
for (int i=0; i<p7->numCert(); i++) {
addItem(p7->getCert(i));
}
delete p7;
}
else if (cn == "pki_pkcs12") {
pki_pkcs12 *p12 = ( pki_pkcs12 *)pki;
pki_pkcs12 *p12 = static_cast<pki_pkcs12 *>(pki);
addItem(p12->getKey());
addItem(p12->getCert());
for (int i=0; i<p12->numCa(); i++) {
@ -95,7 +95,7 @@ void ImportMulti::addItem(pki_base *pki)
delete p12;
}
else if (cn == "pki_multi") {
pki_multi *pm = (pki_multi*)pki;
pki_multi *pm = static_cast<pki_multi*>(pki);
pki_base *inner;
while ((inner = pm->pull()))
addItem(inner);
@ -272,25 +272,25 @@ void ImportMulti::on_butDetails_clicked()
if (cn == "pki_x509"){
CertDetail *dlg;
dlg = new CertDetail(mainwin);
dlg->setCert((pki_x509 *)pki);
dlg->setCert(static_cast<pki_x509 *>(pki));
dlg->exec();
delete dlg;
} else if (cn == "pki_evp" || cn == "pki_scard") {
KeyDetail *dlg;
dlg = new KeyDetail(mainwin);
dlg->setKey((pki_key *)pki);
dlg->setKey(static_cast<pki_key *>(pki));
dlg->exec();
delete dlg;
} else if (cn == "pki_x509req") {
CertDetail *dlg;
dlg = new CertDetail(mainwin);
dlg->setReq((pki_x509req *)pki);
dlg->setReq(static_cast<pki_x509req *>(pki));
dlg->exec();
delete dlg;
} else if (cn == "pki_crl") {
CrlDetail *dlg;
dlg = new CrlDetail(mainwin);
dlg->setCrl((pki_crl *)pki);
dlg->setCrl(static_cast<pki_crl *>(pki));
dlg->exec();
delete dlg;
} else if (cn == "pki_temp") {

View File

@ -53,7 +53,7 @@ void KeyDetail::setKey(pki_key *key)
keyPrivEx->setRed();
} else if (key->isToken()) {
image->setPixmap(*MainWindow::scardImg);
pki_scard *card = (pki_scard *)key;
pki_scard *card = static_cast<pki_scard *>(key);
cardBox->setTitle(tr("Token") +" [" +card->getCardLabel() +"]");
cardManufacturer->setText(card->getManufacturer() + " " +
card->getModel());