Do not reference the key by pointer, but by Key Id

This way the pointer to the key may change during reload.
This commit is contained in:
Christian Hohnstaedt 2019-03-22 15:00:19 +01:00
parent f43e7520db
commit 4eb7b170b1
5 changed files with 10 additions and 10 deletions

View File

@ -360,6 +360,7 @@ void pki_x509::store_token(bool alwaysSelect)
pkcs11 p11;
pki_key *privkey = getRefKey();
if (!privkey || !privkey->isToken() || alwaysSelect) {
if (!p11.selectToken(&slot, NULL))
return;
@ -400,6 +401,7 @@ void pki_x509::store_token(bool alwaysSelect)
void pki_x509::deleteFromToken()
{
pki_key *privkey = getRefKey();
pki_scard *card = dynamic_cast<pki_scard *>(privkey);
slotidList p11_slots;
@ -557,6 +559,7 @@ bool pki_x509::isCA() const
bool pki_x509::canSign() const
{
pki_key *privkey = getRefKey();
if (!privkey || privkey->isPubKey())
return false;
if (privkey->isToken() && !pkcs11::loaded())

View File

@ -25,7 +25,6 @@ QPixmap *pki_x509req::icon[3] = { NULL, NULL, NULL };
pki_x509req::pki_x509req(const QString name)
: pki_x509super(name)
{
privkey = NULL;
request = X509_REQ_new();
pki_openssl_error();
pkiType=x509_req;
@ -209,9 +208,7 @@ void pki_x509req::fromData(const unsigned char *p, db_header_t *head )
int size;
size = head->len - sizeof(db_header_t);
QByteArray ba((const char *)p, size);
privkey = NULL;
d2i(ba);
pki_openssl_error();

View File

@ -15,7 +15,6 @@ QPixmap *pki_x509super::icon[1];
pki_x509super::pki_x509super(const QString name)
: pki_x509name(name)
{
privkey = NULL;
}
pki_x509super::~pki_x509super()
@ -59,7 +58,7 @@ QSqlError pki_x509super::insertSqlData()
"VALUES (?, ?, ?, ?)");
q.bindValue(0, sqlItemId);
q.bindValue(1, (uint)getSubject().hashNum());
q.bindValue(2, privkey ? privkey->getSqlItemId() : QVariant());
q.bindValue(2, keySqlId);
q.bindValue(3, pubHash());
q.exec();
return q.lastError();
@ -69,12 +68,12 @@ void pki_x509super::restoreSql(const QSqlRecord &rec)
{
pki_base::restoreSql(rec);
keySqlId = rec.value(VIEW_x509super_keyid);
privkey = NULL;
}
QSqlError pki_x509super::deleteSqlData()
{
XSqlQuery q;
pki_key *privkey = getRefKey();
if (privkey)
privkey->resetUcount();
SQL_PREPARE(q, "DELETE FROM x509super WHERE item=?");
@ -85,12 +84,13 @@ QSqlError pki_x509super::deleteSqlData()
pki_key *pki_x509super::getRefKey() const
{
return privkey;
return db_base::lookupPki<pki_key>(keySqlId);
}
unsigned pki_x509super::pubHash() const
{
unsigned hash = 0;
pki_key *privkey = getRefKey();
if (privkey) {
hash = privkey->hash();
} else {
@ -119,7 +119,7 @@ bool pki_x509super::compareRefKey(pki_key *ref) const
void pki_x509super::setRefKey(pki_key *ref)
{
privkey = ref;
keySqlId = ref ? ref->getSqlItemId() : QVariant();
}
QString pki_x509super::getSigAlg() const
@ -149,6 +149,7 @@ QVariant pki_x509super::getIcon(const dbheader *hd) const
QVariant pki_x509super::column_data(const dbheader *hd) const
{
if (hd->id == HD_x509key_name) {
pki_key *privkey = getRefKey();
if (!privkey)
return QVariant("");
return QVariant(privkey->getIntName());

View File

@ -34,7 +34,6 @@ class pki_x509super : public pki_x509name
Q_OBJECT
protected:
QVariant keySqlId;
pki_key *privkey;
virtual int sigAlg() const = 0;
public:
pki_x509super(const QString name = "");

View File

@ -129,7 +129,7 @@ QString XSqlQuery::rewriteQuery(QString _q)
"items" << "crls" << "private_keys" << "public_keys" <<
"tokens" << "token_mechanism" << "templates" << "certs" <<
"authority" << "revocations" << "requests" << "x509super" <<
"settings" << "revocations" <<
"settings" <<
"view_public_keys" << "view_certs" << "view_requests" <<
"view_crls" << "view_templates" << "view_private" ;