mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
pkcs#11 fixes
- support pkcs#11 library selection by file dialog - don't prompt for pin if CKF_PROTECTED_AUTHENTICATION_PATH untested, because of ENODEV on my desk
This commit is contained in:
parent
b48170af65
commit
1f93c82010
@ -198,10 +198,12 @@ void db_key::showContextMenu(QContextMenuEvent *e, const QModelIndex &index)
|
||||
if (key->isScard() && pkcs11::loaded()) {
|
||||
menu->addAction(tr("Change PIN"), this,
|
||||
SLOT(changePin()));
|
||||
#if 0
|
||||
menu->addAction(tr("Init PIN with SO PIN (PUK)"), this,
|
||||
SLOT(initPin()));
|
||||
menu->addAction(tr("Change SO PIN (PUK)"), this,
|
||||
SLOT(changeSoPin()));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
menu->exec(e->globalPos());
|
||||
|
||||
@ -146,6 +146,20 @@ load_db::load_db()
|
||||
caption = QObject::tr("Open XCA Database");
|
||||
}
|
||||
|
||||
/* Shared library */
|
||||
load_pkcs11::load_pkcs11()
|
||||
:load_base()
|
||||
{
|
||||
#ifdef WIN32
|
||||
filter = QObject::tr("PKCS#11 library ( *.dll );;") + filter;
|
||||
#elif defined(Q_WS_MAC)
|
||||
filter = QObject::tr("PKCS#11 library ( *.dylib );;") + filter;
|
||||
#else
|
||||
filter = QObject::tr("PKCS#11 library ( *.so );;") + filter;
|
||||
#endif
|
||||
caption = QObject::tr("Open PKCS#11 shared library");
|
||||
}
|
||||
|
||||
/* General PEM loader */
|
||||
load_pem::load_pem()
|
||||
:load_base()
|
||||
|
||||
@ -79,6 +79,12 @@ class load_db: public load_base
|
||||
load_db();
|
||||
};
|
||||
|
||||
class load_pkcs11: public load_base
|
||||
{
|
||||
public:
|
||||
load_pkcs11();
|
||||
};
|
||||
|
||||
class load_pem: public load_base
|
||||
{
|
||||
public:
|
||||
|
||||
@ -165,6 +165,23 @@ QStringList pkcs11::tokenInfo()
|
||||
return tokenInfo(slot_id);
|
||||
}
|
||||
|
||||
bool pkcs11::protAuthPath(CK_SLOT_ID slot)
|
||||
{
|
||||
CK_TOKEN_INFO token_info;
|
||||
CK_RV rv;
|
||||
|
||||
rv = p11->C_GetTokenInfo(slot, &token_info);
|
||||
if (rv != CKR_OK) {
|
||||
pk11error("C_GetTokenInfo", rv);
|
||||
}
|
||||
return !!(token_info.flags & CKF_PROTECTED_AUTHENTICATION_PATH);
|
||||
}
|
||||
|
||||
bool pkcs11::protAuthPath()
|
||||
{
|
||||
return protAuthPath(slot_id);
|
||||
}
|
||||
|
||||
void pkcs11::loadAttribute(pk11_attribute &attribute, CK_OBJECT_HANDLE object)
|
||||
{
|
||||
attribute.load(session, object);
|
||||
|
||||
@ -33,6 +33,9 @@ class pkcs11
|
||||
|
||||
QStringList tokenInfo(CK_SLOT_ID slot);
|
||||
QStringList tokenInfo();
|
||||
bool protAuthPath(CK_SLOT_ID slot);
|
||||
bool protAuthPath();
|
||||
|
||||
void startSession(unsigned long slot, bool rw = false);
|
||||
CK_SLOT_ID *getSlotList(unsigned long *num_slots);
|
||||
void loadAttribute(pk11_attribute &attribute,
|
||||
|
||||
@ -301,7 +301,7 @@ QString pki_scard::getTypeString(void)
|
||||
|
||||
QString pki_scard::scardLogin(pkcs11 &p11, bool so, bool force) const
|
||||
{
|
||||
char pin[256];
|
||||
char _pin[256], *pin = _pin;
|
||||
int pinlen;
|
||||
bool need_login;
|
||||
|
||||
@ -315,10 +315,16 @@ QString pki_scard::scardLogin(pkcs11 &p11, bool so, bool force) const
|
||||
if (force || need_login) {
|
||||
if (!need_login)
|
||||
p11.logout();
|
||||
pinlen = MainWindow::passRead(pin, 256, 0, &p);
|
||||
if (pinlen == -1)
|
||||
return QString();
|
||||
if (p11.protAuthPath()) {
|
||||
pin = NULL;
|
||||
pinlen = 0;
|
||||
} else {
|
||||
pinlen = MainWindow::passRead(pin, 256, 0, &p);
|
||||
if (pinlen == -1)
|
||||
return QString();
|
||||
}
|
||||
p11.login((unsigned char*)pin, pinlen, so);
|
||||
pin = _pin;
|
||||
} else {
|
||||
return QString("");
|
||||
}
|
||||
@ -330,15 +336,10 @@ EVP_PKEY *pki_scard::decryptKey() const
|
||||
int slot_id;
|
||||
QString pin;
|
||||
struct {
|
||||
const void *password;
|
||||
char *password;
|
||||
const char *prompt_info;
|
||||
} cb_data = { NULL, NULL };
|
||||
|
||||
pass_info p(XCA_TITLE,
|
||||
pki_scard::tr("Please enter the PIN of the token: ") +
|
||||
getIntName());
|
||||
p.setPin();
|
||||
|
||||
slot_id = prepare_card();
|
||||
if (slot_id == -1)
|
||||
return NULL;
|
||||
@ -350,43 +351,45 @@ EVP_PKEY *pki_scard::decryptKey() const
|
||||
pin = scardLogin(p11, false);
|
||||
if (pin.isNull())
|
||||
return NULL;
|
||||
cb_data.password = CCHAR(pin);
|
||||
cb_data.password = strdup(CCHAR(pin));
|
||||
printf("PASSWORT: '%s'\n", cb_data.password);
|
||||
EVP_PKEY *pkey = ENGINE_load_private_key(p11_engine, CCHAR(key_id),
|
||||
NULL, &cb_data);
|
||||
NULL, &cb_data);
|
||||
free(cb_data.password);
|
||||
openssl_error();
|
||||
return pkey;
|
||||
}
|
||||
|
||||
void pki_scard::changePin()
|
||||
{
|
||||
char oldPin[256], newPin[256];
|
||||
char newPin[256], *pinp;
|
||||
int slot;
|
||||
|
||||
pass_info p(XCA_TITLE,
|
||||
pki_scard::tr("Please enter the PIN of the token: ") +
|
||||
getIntName());
|
||||
p.setPin();
|
||||
QString pin;
|
||||
|
||||
slot = prepare_card();
|
||||
if (slot == -1)
|
||||
return;
|
||||
|
||||
int oldPinLen = MainWindow::passRead(oldPin, 256, 0, &p);
|
||||
if (oldPinLen == -1)
|
||||
return;
|
||||
|
||||
pkcs11 p11;
|
||||
p11.startSession(slot, true);
|
||||
p11.logout();
|
||||
p11.login((unsigned char*)oldPin, oldPinLen, false);
|
||||
p.setDescription(qApp->translate("MainWindow",
|
||||
"Please enter the new Pin for the token: ") +getIntName());
|
||||
if (p11.protAuthPath()) {
|
||||
p11.setPin(NULL, 0, NULL ,0);
|
||||
}
|
||||
pin = scardLogin(p11, false, true);
|
||||
if (pin.isNull())
|
||||
return;
|
||||
pass_info p(XCA_TITLE, tr("Please enter the new Pin for the token: ") +
|
||||
getIntName());
|
||||
p.setPin();
|
||||
|
||||
int newPinLen = MainWindow::passWrite(newPin, 256, 0, &p);
|
||||
pinp = strdup(CCHAR(pin));
|
||||
if (newPinLen != -1) {
|
||||
p11.setPin((unsigned char*)oldPin, oldPinLen,
|
||||
p11.setPin((unsigned char*)pinp, pin.length(),
|
||||
(unsigned char*)newPin, newPinLen);
|
||||
}
|
||||
free(pinp);
|
||||
}
|
||||
|
||||
void pki_scard::initPin()
|
||||
|
||||
137
ui/Options.ui
137
ui/Options.ui
@ -1,7 +1,8 @@
|
||||
<ui version="4.0" >
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Options</class>
|
||||
<widget class="QDialog" name="Options" >
|
||||
<property name="geometry" >
|
||||
<widget class="QDialog" name="Options">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
@ -9,13 +10,13 @@
|
||||
<height>455</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" >
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="TextLabel1" >
|
||||
<property name="font" >
|
||||
<widget class="QLabel" name="TextLabel1">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Arial</family>
|
||||
<pointsize>14</pointsize>
|
||||
@ -26,59 +27,59 @@
|
||||
<strikeout>false</strikeout>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string><html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
<property name="text">
|
||||
<string><html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'Arial'; font-size:14pt; font-weight:400; font-style:normal; text-decoration:none;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">XCA Options</p></body></html></string>
|
||||
</style></head><body style=" font-family:'Arial'; font-size:14pt; font-weight:400; font-style:normal; text-decoration:none;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">XCA Options</p></body></html></string>
|
||||
</property>
|
||||
<property name="alignment" >
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox" >
|
||||
<property name="title" >
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Mandatory subject entries</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<layout class="QHBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin" >
|
||||
<property name="margin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<layout class="QVBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin" >
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QComboBox" name="extDNobj" />
|
||||
<widget class="QComboBox" name="extDNobj"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="extDNlist" />
|
||||
<widget class="QListWidget" name="extDNlist"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<layout class="QVBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin" >
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0" >
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
@ -87,15 +88,15 @@ p, li { white-space: pre-wrap; }
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="extDNadd" >
|
||||
<property name="text" >
|
||||
<widget class="QPushButton" name="extDNadd">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="extDNdel" >
|
||||
<property name="text" >
|
||||
<widget class="QPushButton" name="extDNdel">
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
</widget>
|
||||
@ -106,58 +107,58 @@ p, li { white-space: pre-wrap; }
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<layout class="QHBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin" >
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3" >
|
||||
<property name="text" >
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Default hash algorithm</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="hashBox" name="hashAlgo" />
|
||||
<widget class="hashBox" name="hashAlgo"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<layout class="QHBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin" >
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label" >
|
||||
<property name="text" >
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>String types</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="mbstring" />
|
||||
<widget class="QComboBox" name="mbstring"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" >
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2" >
|
||||
<property name="text" >
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>PKCS11 Library path: </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="pkcs11path" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
|
||||
<widget class="QLineEdit" name="pkcs11path">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
@ -165,14 +166,14 @@ p, li { white-space: pre-wrap; }
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
|
||||
<widget class="QPushButton" name="fileButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
@ -180,33 +181,33 @@ p, li { white-space: pre-wrap; }
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line" >
|
||||
<property name="orientation" >
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<layout class="QHBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin" >
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="cancelButton" >
|
||||
<property name="text" >
|
||||
<widget class="QPushButton" name="cancelButton">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0" >
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>21</width>
|
||||
<height>21</height>
|
||||
@ -215,8 +216,8 @@ p, li { white-space: pre-wrap; }
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="okButton" >
|
||||
<property name="text" >
|
||||
<widget class="QPushButton" name="okButton">
|
||||
<property name="text">
|
||||
<string>OK</string>
|
||||
</property>
|
||||
</widget>
|
||||
@ -245,11 +246,11 @@ p, li { white-space: pre-wrap; }
|
||||
<receiver>Options</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<hint type="sourcelabel">
|
||||
<x>224</x>
|
||||
<y>332</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<hint type="destinationlabel">
|
||||
<x>96</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
@ -261,11 +262,11 @@ p, li { white-space: pre-wrap; }
|
||||
<receiver>Options</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<hint type="sourcelabel">
|
||||
<x>305</x>
|
||||
<y>332</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<hint type="destinationlabel">
|
||||
<x>179</x>
|
||||
<y>282</y>
|
||||
</hint>
|
||||
|
||||
@ -69,3 +69,16 @@ QString Options::getStringOpt()
|
||||
return string_opts[mbstring->currentIndex()];
|
||||
}
|
||||
|
||||
void Options::on_fileButton_clicked(void)
|
||||
{
|
||||
load_pkcs11 l;
|
||||
QString fname;
|
||||
|
||||
fname = QFileDialog::getOpenFileName(this, l.caption,
|
||||
pkcs11path->text(), l.filter);
|
||||
|
||||
if (fname.isEmpty())
|
||||
return;
|
||||
pkcs11path->setText(fname);
|
||||
}
|
||||
|
||||
|
||||
@ -26,6 +26,7 @@ class Options: public QDialog, public Ui::Options
|
||||
QString getDnString();
|
||||
void setStringOpt(const QString string_opt);
|
||||
QString getStringOpt();
|
||||
void on_fileButton_clicked(void);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user