mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
all strings replaced by QString
This commit is contained in:
parent
64243d896b
commit
fe46ff670f
186
CertView.cpp
186
CertView.cpp
@ -52,11 +52,13 @@
|
||||
#include "CertView.h"
|
||||
#include "MainWindow.h"
|
||||
#include <qcheckbox.h>
|
||||
#include <qlabel.h>
|
||||
#include <qcombobox.h>
|
||||
#include <qradiobutton.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <qpopupmenu.h>
|
||||
#include "CertExtend.h"
|
||||
#include "CertDetail.h"
|
||||
|
||||
CertView::CertView(QWidget * parent = 0, const char * name = 0, WFlags f = 0)
|
||||
:XcaListView(parent, name, f)
|
||||
@ -234,7 +236,7 @@ void CertView::newCert(NewX509 *dlg)
|
||||
}
|
||||
}
|
||||
if (cont.length() > 0){
|
||||
addStr(subAltName,cont.latin1());
|
||||
addStr(subAltName,cont);
|
||||
}
|
||||
if (subAltName.length() > 0) {
|
||||
CERR( "SubAltName:" << subAltName);
|
||||
@ -257,7 +259,7 @@ void CertView::newCert(NewX509 *dlg)
|
||||
}
|
||||
}
|
||||
if (cont.length() > 0){
|
||||
addStr(issAltName,cont.latin1());
|
||||
addStr(issAltName,cont);
|
||||
}
|
||||
if (issAltName.length() > 0) {
|
||||
CERR("IssAltName:" << issAltName);
|
||||
@ -316,7 +318,8 @@ void CertView::extendCert()
|
||||
{
|
||||
pki_x509 *oldcert = NULL, *signer = NULL, *newcert =NULL;
|
||||
pki_key *signkey = NULL;
|
||||
int serial, days, x;
|
||||
int days, x;
|
||||
a1int serial;
|
||||
try {
|
||||
CertExtend_UI *dlg = new CertExtend_UI(this, NULL, true);
|
||||
dlg->image->setPixmap(*MainWindow::certImg);
|
||||
@ -325,16 +328,15 @@ void CertView::extendCert()
|
||||
return;
|
||||
}
|
||||
oldcert = (pki_x509 *)getSelected();
|
||||
if (!oldcert || !(signer = oldcert->getSigner()) || !(signkey = signer->getKey()) || signkey->isPubKey()) return;
|
||||
if (!oldcert || !(signer = oldcert->getSigner()) || !(signkey = signer->getRefKey()) || signkey->isPubKey()) return;
|
||||
newcert = new pki_x509(oldcert);
|
||||
serial = signer->getIncCaSerial();
|
||||
|
||||
// get signers own serial to avoid having the same
|
||||
if (serial == atoi(signer->getSerial().c_str())) { // FIXME: anybody tell me the string method for this ?
|
||||
if (serial == signer->getSerial()) {
|
||||
serial = signer->getIncCaSerial(); // just take the next one
|
||||
}
|
||||
certs->updatePKI(signer); // not so pretty ....
|
||||
CERR("serial is: " << serial );
|
||||
db->updatePKI(signer); // FIXME::not so pretty ....
|
||||
|
||||
// Date handling
|
||||
x = dlg->validNumber->text().toInt();
|
||||
@ -344,7 +346,8 @@ void CertView::extendCert()
|
||||
|
||||
// change date and serial
|
||||
newcert->setSerial(serial);
|
||||
newcert->setDates(x); // now and now + x days
|
||||
newcert->setNotBefore(dlg->getNotBefore());
|
||||
newcert->setNotAfter(dlg->getNotAfter());
|
||||
|
||||
if (newcert->resetTimes(signer) > 0) {
|
||||
if (QMessageBox::information(this,tr(XCA_TITLE),
|
||||
@ -358,7 +361,7 @@ void CertView::extendCert()
|
||||
// and finally sign the request
|
||||
newcert->sign(signkey);
|
||||
CERR( "SIGNED");
|
||||
insertCert(newcert);
|
||||
insert(newcert);
|
||||
CERR("inserted");
|
||||
delete dlg;
|
||||
}
|
||||
@ -369,23 +372,23 @@ void CertView::extendCert()
|
||||
}
|
||||
}
|
||||
|
||||
bool CertView::show(pki_base *basecert, bool import)
|
||||
void CertView::show(pki_base *basecert, bool import)
|
||||
{
|
||||
pki_x509 *cert = (pki_x509 *)basecert;
|
||||
if (!cert) return false;
|
||||
if (opensslError(cert)) return false;
|
||||
if (!cert) return;
|
||||
if (opensslError(cert)) return ;
|
||||
try {
|
||||
CertDetail_UI *dlg = new CertDetail_UI(this,0,true);
|
||||
bool ret;
|
||||
dlg->image->setPixmap(*certImg);
|
||||
dlg->descr->setText(cert->getDescription().c_str());
|
||||
dlg->descr->setText(cert->getIntName());
|
||||
dlg->setCaption(tr(XCA_TITLE));
|
||||
|
||||
// examine the key
|
||||
pki_key *key= cert->getKey();
|
||||
if (key)
|
||||
if (key->isPrivKey()) {
|
||||
dlg->privKey->setText(key->getDescription().c_str());
|
||||
dlg->privKey->setText(key->getIntName());
|
||||
dlg->privKey->setDisabled(false);
|
||||
}
|
||||
|
||||
@ -398,7 +401,7 @@ bool CertView::show(pki_base *basecert, bool import)
|
||||
}
|
||||
|
||||
else {
|
||||
dlg->verify->setText(cert->getSigner()->getDescription().c_str());
|
||||
dlg->verify->setText(cert->getSigner()->getIntName());
|
||||
}
|
||||
|
||||
// check trust state
|
||||
@ -408,40 +411,41 @@ bool CertView::show(pki_base *basecert, bool import)
|
||||
CERR( cert->getEffTrust() );
|
||||
|
||||
// the serial
|
||||
dlg->serialNr->setText(cert->getSerial().c_str());
|
||||
dlg->serialNr->setText(cert->getSerial().toHex());
|
||||
|
||||
// details of subject
|
||||
string land = cert->getDNs(NID_countryName);
|
||||
string land1 = cert->getDNs(NID_stateOrProvinceName);
|
||||
x509name subj = cert->getSubject();
|
||||
QString land = subj.getEntryByNid(NID_countryName);
|
||||
QString land1 = subj.getEntryByNid(NID_stateOrProvinceName);
|
||||
if (land != "" && land1 != "")
|
||||
land += " / " +land1;
|
||||
else
|
||||
land+=land1;
|
||||
|
||||
dlg->dnCN->setText(subj.geEntryByNid(NID_commonName));
|
||||
dlg->dnC->setText(land);
|
||||
dlg->dnL->setText(subj.getEntryByNid(NID_localityName));
|
||||
dlg->dnO->setText(subj.getEntryByNid(NID_organizationName));
|
||||
dlg->dnOU->setText(subj.getEntryByNid(NID_organizationalUnitName));
|
||||
dlg->dnEmail->setText(subj.getEntryByNid(NID_pkcs9_emailAddress));
|
||||
|
||||
dlg->dnCN->setText(cert->getDNs(NID_commonName).c_str() );
|
||||
dlg->dnC->setText(land.c_str());
|
||||
dlg->dnL->setText(cert->getDNs(NID_localityName).c_str());
|
||||
dlg->dnO->setText(cert->getDNs(NID_organizationName).c_str());
|
||||
dlg->dnOU->setText(cert->getDNs(NID_organizationalUnitName).c_str());
|
||||
dlg->dnEmail->setText(cert->getDNs(NID_pkcs9_emailAddress).c_str());
|
||||
|
||||
MARK
|
||||
// same for issuer....
|
||||
land = cert->getDNi(NID_countryName);
|
||||
land1 = cert->getDNi(NID_stateOrProvinceName);
|
||||
x509name iss = cert->getIssuer();
|
||||
land = iss.getEntryByNid(NID_countryName);
|
||||
land1 = iss.getEntryByNid(NID_stateOrProvinceName);
|
||||
if (land != "" && land1 != "")
|
||||
land += " / " +land1;
|
||||
else
|
||||
land+=land1;
|
||||
dlg->dnCN_2->setText(cert->getDNi(NID_commonName).c_str() );
|
||||
dlg->dnC_2->setText(land.c_str());
|
||||
dlg->dnL_2->setText(cert->getDNi(NID_localityName).c_str());
|
||||
dlg->dnO_2->setText(cert->getDNi(NID_organizationName).c_str());
|
||||
dlg->dnOU_2->setText(cert->getDNi(NID_organizationalUnitName).c_str());
|
||||
dlg->dnEmail_2->setText(cert->getDNi(NID_pkcs9_emailAddress).c_str());
|
||||
dlg->notBefore->setText(cert->notBefore().c_str());
|
||||
dlg->notAfter->setText(cert->notAfter().c_str());
|
||||
|
||||
dlg->dnCN_2->setText(iss.getEntryByNid(NID_commonName) );
|
||||
dlg->dnC_2->setText(land);
|
||||
dlg->dnL_2->setText(iss.getEntryByNid(NID_localityName));
|
||||
dlg->dnO_2->setText(iss.getEntryByNid(NID_organizationName));
|
||||
dlg->dnOU_2->setText(iss.getEntryByNid(NID_organizationalUnitName));
|
||||
dlg->dnEmail_2->setText(iss.getEntryByNid(NID_pkcs9_emailAddress));
|
||||
dlg->notBefore->setText(cert.getNotBefore().toPretty());
|
||||
dlg->notAfter->setText(cert.getNotAfter().toPretty());
|
||||
MARK
|
||||
|
||||
// validation of the Date
|
||||
@ -453,18 +457,18 @@ bool CertView::show(pki_base *basecert, bool import)
|
||||
dlg->dateValid->setText(tr("Not valid"));
|
||||
dlg->dateValid->setDisabled(true);
|
||||
}
|
||||
string revdate = cert->revokedAt();
|
||||
if (revdate != "") {
|
||||
dlg->dateValid->setText(tr("Revoked: ")+ revdate.c_str());
|
||||
if (cert->isRevoked()) {
|
||||
dlg->dateValid->setText(tr("Revoked: ") +
|
||||
cert->getRevoked().toPretty());
|
||||
dlg->dateValid->setDisabled(true);
|
||||
|
||||
}
|
||||
// the fingerprints
|
||||
dlg->fpMD5->setText(cert->fingerprint(EVP_md5()).c_str());
|
||||
dlg->fpSHA1->setText(cert->fingerprint(EVP_sha1()).c_str());
|
||||
dlg->fpMD5->setText(cert->fingerprint(EVP_md5()));
|
||||
dlg->fpSHA1->setText(cert->fingerprint(EVP_sha1()));
|
||||
|
||||
// V3 extensions
|
||||
dlg->v3Extensions->setText(cert->printV3ext().c_str());
|
||||
dlg->v3Extensions->setText(cert->printV3ext());
|
||||
|
||||
// rename the buttons in case of import
|
||||
if (import) {
|
||||
@ -473,33 +477,33 @@ bool CertView::show(pki_base *basecert, bool import)
|
||||
}
|
||||
|
||||
// show it to the user...
|
||||
string odesc = cert->getDescription();
|
||||
QString odesc = cert->getIntName();
|
||||
ret = dlg->exec();
|
||||
string ndesc = dlg->descr->text().latin1();
|
||||
QString ndesc = dlg->descr->text();
|
||||
delete dlg;
|
||||
if (!ret && import) {
|
||||
delete cert;
|
||||
}
|
||||
if (!ret) return false;
|
||||
if (!ret) return;
|
||||
|
||||
if (!certs) {
|
||||
if (!db) {
|
||||
init_database();
|
||||
}
|
||||
if (import) {
|
||||
cert = insertCert(cert);
|
||||
cert = insert(cert);
|
||||
}
|
||||
if (ndesc != odesc) {
|
||||
certs->renamePKI(cert, ndesc);
|
||||
return true;
|
||||
db->renamePKI(cert, ndesc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (errorEx &err) {
|
||||
Error(err);
|
||||
}
|
||||
return false;
|
||||
return ;
|
||||
}
|
||||
|
||||
void CertView::deleteCert()
|
||||
void CertView::deleteItem()
|
||||
{
|
||||
try {
|
||||
pki_x509 *cert = (pki_x509 *)getSelected();
|
||||
@ -517,7 +521,7 @@ void CertView::deleteCert()
|
||||
}
|
||||
}
|
||||
|
||||
void CertView::loadCert()
|
||||
void CertView::loadItem()
|
||||
{
|
||||
QStringList filter;
|
||||
filter.append(tr("Certificates ( *.pem *.der *.crt *.cer )"));
|
||||
@ -527,7 +531,7 @@ void CertView::loadCert()
|
||||
|
||||
void CertView::loadItem(QString fname)
|
||||
{
|
||||
pki_x509 *cert = new pki_x509(s.latin1());
|
||||
pki_x509 *cert = new pki_x509(s);
|
||||
return cert;
|
||||
}
|
||||
|
||||
@ -553,7 +557,7 @@ void CertView::loadPKCS12()
|
||||
s = *it;
|
||||
s = QDir::convertSeparators(s);
|
||||
try {
|
||||
pk12 = new pki_pkcs12(s.latin1(), &CertView::passRead);
|
||||
pk12 = new pki_pkcs12(s, &CertView::passRead);
|
||||
insertP12(pk12);
|
||||
MARK
|
||||
}
|
||||
@ -630,9 +634,9 @@ void CertView::loadPKCS7()
|
||||
s = *it;
|
||||
s = QDir::convertSeparators(s);
|
||||
try {
|
||||
pk7 = new pki_pkcs7(s.latin1());
|
||||
pk7 = new pki_pkcs7(s);
|
||||
MARK
|
||||
pk7->readP7(s.latin1());
|
||||
pk7->readP7(s);
|
||||
MARK
|
||||
for (int i=0; i<pk7->numCert(); i++) {
|
||||
acert = pk7->getCert(i);
|
||||
@ -658,7 +662,7 @@ pki_x509 *CertView::insert(pki_base *item)
|
||||
if (oldcert) {
|
||||
QMessageBox::information(this,tr(XCA_TITLE),
|
||||
tr("The certificate already exists in the database as") +":\n'" +
|
||||
QString::fromLatin1(oldcert->getDescription().c_str()) +
|
||||
QString::fromLatin1(oldcert->getIntName()) +
|
||||
"'\n" + tr("and so it was not imported"), "OK");
|
||||
delete(cert);
|
||||
return oldcert;
|
||||
@ -671,7 +675,7 @@ pki_x509 *CertView::insert(pki_base *item)
|
||||
}
|
||||
int serial;
|
||||
if (cert->getSigner() != cert && cert->getSigner()) {
|
||||
sscanf(cert->getSerial().c_str(), "%x", &serial);
|
||||
sscanf(cert->getSerial(), "%x", &serial);
|
||||
CERR("OTHER SIGNER" << serial);
|
||||
if (serial >= cert->getSigner()->getCaSerial()) {
|
||||
QMessageBox::information(this,tr(XCA_TITLE),
|
||||
@ -703,8 +707,8 @@ void CertView::writeCert()
|
||||
pki_x509 *oldcrt = NULL;
|
||||
if (!crt) return;
|
||||
pki_key *privkey = crt->getKey();
|
||||
ExportCert *dlg = new ExportCert((crt->getDescription() + ".crt").c_str(),
|
||||
(privkey && privkey->isPrivKey()), getPath(), crt->tinyCAfname().c_str() );
|
||||
ExportCert *dlg = new ExportCert((crt->getIntName() + ".crt"),
|
||||
(privkey && privkey->isPrivKey()), getPath(), crt->tinyCAfname() );
|
||||
dlg->image->setPixmap(*certImg);
|
||||
int dlgret = dlg->exec();
|
||||
newPath(dlg->dirPath);
|
||||
@ -721,11 +725,11 @@ void CertView::writeCert()
|
||||
try {
|
||||
switch (dlg->exportFormat->currentItem()) {
|
||||
case 0: // PEM
|
||||
crt->writeCert(fname.latin1(),true,false);
|
||||
crt->writeCert(fname,true,false);
|
||||
break;
|
||||
case 1: // PEM with chain
|
||||
while(crt && crt != oldcrt) {
|
||||
crt->writeCert(fname.latin1(),true,true);
|
||||
crt->writeCert(fname,true,true);
|
||||
oldcrt = crt;
|
||||
crt = crt->getSigner();
|
||||
}
|
||||
@ -737,7 +741,7 @@ void CertView::writeCert()
|
||||
certs->writeAllCerts(fname,false);
|
||||
break;
|
||||
case 4: // DER
|
||||
crt->writeCert(fname.latin1(),false,false);
|
||||
crt->writeCert(fname,false,false);
|
||||
break;
|
||||
case 5: // P7 lonely
|
||||
writePKCS7(fname, P7_ONLY);
|
||||
@ -774,12 +778,12 @@ void CertView::writePKCS12(QString s, bool chain)
|
||||
if (!privkey || privkey->isPubKey()) {
|
||||
QMessageBox::warning(this,tr(XCA_TITLE),
|
||||
tr("There was no key found for the Certificate: ") +
|
||||
QString::fromLatin1(cert->getDescription().c_str()) );
|
||||
QString::fromLatin1(cert->getIntName()) );
|
||||
return;
|
||||
}
|
||||
if (s.isEmpty()) return;
|
||||
s = QDir::convertSeparators(s);
|
||||
pki_pkcs12 *p12 = new pki_pkcs12(cert->getDescription(), cert, privkey, &CertView::passWrite);
|
||||
pki_pkcs12 *p12 = new pki_pkcs12(cert->getIntName(), cert, privkey, &CertView::passWrite);
|
||||
pki_x509 *signer = cert->getSigner();
|
||||
int cnt =0;
|
||||
while ((signer != NULL ) && (signer != cert) && chain) {
|
||||
@ -790,7 +794,7 @@ void CertView::writePKCS12(QString s, bool chain)
|
||||
signer=signer->getSigner();
|
||||
}
|
||||
CERR("start writing" );
|
||||
p12->writePKCS12(s.latin1());
|
||||
p12->writePKCS12(s);
|
||||
delete p12;
|
||||
}
|
||||
catch (errorEx &err) {
|
||||
@ -822,7 +826,7 @@ void CertView::writePKCS7(QString s, int type) {
|
||||
}
|
||||
}
|
||||
}
|
||||
p7->writeP7(s.latin1(), false);
|
||||
p7->writeP7(s, false);
|
||||
}
|
||||
catch (errorEx &err) {
|
||||
Error(err);
|
||||
@ -841,7 +845,7 @@ void CertView::signP7()
|
||||
if (!privkey || privkey->isPubKey()) {
|
||||
QMessageBox::warning(this,tr(XCA_TITLE),
|
||||
tr("There was no key found for the Certificate: ") +
|
||||
QString::fromLatin1(cert->getDescription().c_str()) );
|
||||
QString::fromLatin1(cert->getIntName()) );
|
||||
return;
|
||||
}
|
||||
filt.append("All Files ( *.* )");
|
||||
@ -861,8 +865,8 @@ void CertView::signP7()
|
||||
for ( QStringList::Iterator it = slist.begin(); it != slist.end(); ++it ) {
|
||||
s = *it;
|
||||
s = QDir::convertSeparators(s);
|
||||
p7->signFile(cert, s.latin1());
|
||||
p7->writeP7((s + ".p7s").latin1(), true);
|
||||
p7->signFile(cert, s);
|
||||
p7->writeP7((s + ".p7s"), true);
|
||||
}
|
||||
delete p7;
|
||||
}
|
||||
@ -881,7 +885,7 @@ void CertView::encryptP7()
|
||||
if (!privkey || privkey->isPubKey()) {
|
||||
QMessageBox::warning(this,tr(XCA_TITLE),
|
||||
tr("There was no key found for the Certificate: ") +
|
||||
QString::fromLatin1(cert->getDescription().c_str()) );
|
||||
QString::fromLatin1(cert->getIntName()) );
|
||||
return;
|
||||
}
|
||||
filt.append("All Files ( *.* )");
|
||||
@ -904,9 +908,9 @@ void CertView::encryptP7()
|
||||
MARK
|
||||
s = QDir::convertSeparators(s);
|
||||
MARK
|
||||
p7->encryptFile(cert, s.latin1());
|
||||
p7->encryptFile(cert, s);
|
||||
MARK
|
||||
p7->writeP7((s + ".p7m").latin1(), true);
|
||||
p7->writeP7((s + ".p7m"), true);
|
||||
MARK
|
||||
}
|
||||
delete p7;
|
||||
@ -933,7 +937,7 @@ void CertView::popupMenu(QListViewItem *item, const QPoint &pt, int x) {
|
||||
menu->insertItem(tr("Import from PKCS#7"), this, SLOT(loadPKCS7()));
|
||||
}
|
||||
else {
|
||||
pki_x509 *cert = (pki_x509 *)certs->getSelectedPKI(item->text(0).latin1());
|
||||
pki_x509 *cert = (pki_x509 *)certs->getSelectedPKI(item->text(0));
|
||||
menu->insertItem(tr("Rename"), this, SLOT(startRenameCert()));
|
||||
menu->insertItem(tr("Show Details"), this, SLOT(showDetailsCert()));
|
||||
menu->insertItem(tr("Export"), subExport);
|
||||
@ -999,7 +1003,7 @@ void CertView::setTrust()
|
||||
if (state == 0 ) dlg->trust0->setChecked(true);
|
||||
if (state == 1 ) dlg->trust1->setChecked(true);
|
||||
if (state == 2 ) dlg->trust2->setChecked(true);
|
||||
dlg->certName->setText(cert->getDescription().c_str());
|
||||
dlg->certName->setText(cert->getIntName());
|
||||
if (dlg->exec()) {
|
||||
if (dlg->trust0->isChecked()) newstate = 0;
|
||||
if (dlg->trust1->isChecked()) newstate = 1;
|
||||
@ -1082,7 +1086,7 @@ void CertView::setTemplate()
|
||||
{
|
||||
pki_x509 *cert = (pki_x509 *)certs->getSelectedPKI();
|
||||
if (!cert) return;
|
||||
QString templ = cert->getTemplate().c_str();
|
||||
QString templ = cert->getTemplate();
|
||||
QStringList tempList = temps->getDesc();
|
||||
unsigned int i, sel=0;
|
||||
bool ok;
|
||||
@ -1095,7 +1099,7 @@ void CertView::setTemplate()
|
||||
tr("Please select the default Template for signing"),
|
||||
tempList, sel, false, &ok, this );
|
||||
if (ok && (templ != nTempl)) {
|
||||
cert->setTemplate(nTempl.latin1());
|
||||
cert->setTemplate(nTempl);
|
||||
certs->updatePKI(cert);
|
||||
}
|
||||
}
|
||||
@ -1129,9 +1133,9 @@ void CertView::toTinyCA()
|
||||
char buf[200];
|
||||
QList<pki_x509> list;
|
||||
pki_x509 *issuedcert;
|
||||
QString dname = crt->getDescription().c_str();
|
||||
QString tcatempdir = settings->getString("TinyCAtempdir").c_str();
|
||||
QString tcadir = settings->getString("TinyCAdir").c_str();
|
||||
QString dname = crt->getIntName();
|
||||
QString tcatempdir = settings->getString("TinyCAtempdir");
|
||||
QString tcadir = settings->getString("TinyCAdir");
|
||||
if (tcatempdir.isEmpty()) {
|
||||
tcatempdir = "templates";
|
||||
}
|
||||
@ -1147,8 +1151,8 @@ void CertView::toTinyCA()
|
||||
tcadir = dlg->tinycadir->text();
|
||||
dname = dlg->dname->text();
|
||||
|
||||
settings->putString("TinyCAtempdir", tcatempdir.latin1());
|
||||
settings->putString("TinyCAdir", tcadir.latin1());
|
||||
settings->putString("TinyCAtempdir", tcatempdir);
|
||||
settings->putString("TinyCAdir", tcadir);
|
||||
|
||||
if (dname.isEmpty()) return;
|
||||
const EVP_CIPHER *enc = EVP_des_ede3_cbc();
|
||||
@ -1160,7 +1164,7 @@ void CertView::toTinyCA()
|
||||
|
||||
//create directory tree
|
||||
if (! mkDir(tcadir)) return;
|
||||
chdir(tcadir.latin1());
|
||||
chdir(tcadir);
|
||||
if (! mkDir("certs")) return;
|
||||
if (! mkDir("crl")) return;
|
||||
if (! mkDir("keys")) return;
|
||||
@ -1188,7 +1192,7 @@ void CertView::toTinyCA()
|
||||
// copy openssl.cnf
|
||||
tcatempdir += QDir::separator();
|
||||
tcatempdir += "openssl.cnf";
|
||||
fpr = fopen(tcatempdir.latin1(), "r");
|
||||
fpr = fopen(tcatempdir, "r");
|
||||
if (!fpr) {
|
||||
fopenerror("openssl.cnf" );
|
||||
return;
|
||||
@ -1204,7 +1208,7 @@ void CertView::toTinyCA()
|
||||
if (x != 0) {
|
||||
x[0]='\0';
|
||||
fputs(buf, fp);
|
||||
fputs(tcadir.latin1(), fp);
|
||||
fputs(tcadir, fp);
|
||||
fputs(x+5, fp);
|
||||
}
|
||||
else {
|
||||
@ -1234,8 +1238,8 @@ void CertView::toTinyCA()
|
||||
chdir("..");
|
||||
}
|
||||
fprintf(fp, "%c\t%s\t%s\t%s\tunknown\t%s\n", rev? 'R':'V',
|
||||
nadate.c_str(), revdate.c_str(), issuedcert->getSerial().c_str(),
|
||||
issuedcert->subjectOneLine().c_str() );
|
||||
nadate, revdate, issuedcert->getSerial(),
|
||||
issuedcert->subjectOneLine() );
|
||||
|
||||
}
|
||||
}
|
||||
@ -1270,12 +1274,12 @@ bool db_x509::updateView()
|
||||
if (((parentitem != NULL) || (signer == pki) || (signer == NULL) || viewState == 0) && (pki->getPointer() == NULL )) {
|
||||
// create the listview item
|
||||
if (parentitem != NULL) {
|
||||
current = new QListViewItem(parentitem, pki->getDescription().c_str());
|
||||
CERR("Adding as client: "<<pki->getDescription().c_str());
|
||||
current = new QListViewItem(parentitem, pki->getIntName());
|
||||
CERR("Adding as client: "<<pki->getIntName());
|
||||
}
|
||||
else {
|
||||
current = new QListViewItem(listView, pki->getDescription().c_str());
|
||||
CERR("Adding as parent: "<<pki->getDescription().c_str());
|
||||
current = new QListViewItem(listView, pki->getIntName());
|
||||
CERR("Adding as parent: "<<pki->getIntName());
|
||||
}
|
||||
pki->setPointer(current);
|
||||
mycont.remove(pki);
|
||||
|
||||
36
KeyView.cpp
36
KeyView.cpp
@ -89,14 +89,14 @@ void KeyView::newItem()
|
||||
progress->setMinimumDuration(0);
|
||||
progress->setProgress(0);
|
||||
progress->setCaption(tr(XCA_TITLE));
|
||||
pki_key *nkey = new pki_key (dlg->keyDesc->text().latin1(),
|
||||
pki_key *nkey = new pki_key (dlg->keyDesc->text(),
|
||||
&incProgress,
|
||||
progress,
|
||||
sizeList[sel]);
|
||||
progress->cancel();
|
||||
delete progress;
|
||||
insert(nkey);
|
||||
x = nkey->getDescription().c_str();
|
||||
x = nkey->getIntName();
|
||||
emit keyDone(x);
|
||||
}
|
||||
catch (errorEx &err) {
|
||||
@ -118,14 +118,10 @@ void KeyView::show(pki_base *item, bool import)
|
||||
KeyDetail_UI *detDlg = new KeyDetail_UI(this, 0, true, 0 );
|
||||
try {
|
||||
detDlg->setCaption(tr(XCA_TITLE));
|
||||
detDlg->keyDesc->setText(
|
||||
key->getDescription().c_str() );
|
||||
detDlg->keyLength->setText(
|
||||
key->length().c_str() );
|
||||
detDlg->keyPubEx->setText(
|
||||
key->pubEx().c_str() );
|
||||
detDlg->keyModulus->setText(
|
||||
key->modulus().c_str() );
|
||||
detDlg->keyDesc->setText( key->getIntName() );
|
||||
detDlg->keyLength->setText( key->length() );
|
||||
detDlg->keyPubEx->setText( key->pubEx() );
|
||||
detDlg->keyModulus->setText( key->modulus());
|
||||
if (key->isPubKey()) {
|
||||
detDlg->keyPrivEx->setText(tr("not available") );
|
||||
detDlg->keyPrivEx->setDisabled(true);
|
||||
@ -155,7 +151,7 @@ void KeyView::show(pki_base *item, bool import)
|
||||
if (import) {
|
||||
key = (pki_key *)insert(key);
|
||||
}
|
||||
CERR(ndesc << " " << key->getDescription());
|
||||
CERR(ndesc << " " << key->getIntName());
|
||||
if ( ndesc != odesc) {
|
||||
MARK
|
||||
try {
|
||||
@ -179,7 +175,7 @@ void KeyView::load()
|
||||
|
||||
pki_base *KeyView::loadItem(QString fname)
|
||||
{
|
||||
pki_base *lkey = new pki_key(fname.latin1(), &MainWindow::passRead);
|
||||
pki_base *lkey = new pki_key(fname, &MainWindow::passRead);
|
||||
return lkey;
|
||||
}
|
||||
|
||||
@ -194,7 +190,7 @@ pki_base* KeyView::insert(pki_base *item)
|
||||
lkey->isPubKey()){
|
||||
QMessageBox::information(this,tr(XCA_TITLE),
|
||||
tr("The key is already in the database as") +":\n'" +
|
||||
QString::fromLatin1(oldkey->getDescription().c_str()) +
|
||||
oldkey->getIntName() +
|
||||
"'\n" + tr("and is not going to be imported"), "OK");
|
||||
delete(lkey);
|
||||
return oldkey;
|
||||
@ -202,11 +198,11 @@ pki_base* KeyView::insert(pki_base *item)
|
||||
else {
|
||||
QMessageBox::information(this,tr(XCA_TITLE),
|
||||
tr("The database already contains the public part of the imported key as") +":\n'" +
|
||||
QString::fromLatin1(oldkey->getDescription().c_str()) +
|
||||
oldkey->getIntName() +
|
||||
"'\n" + tr("and will be completed by the new, private part of the key"), "OK");
|
||||
CERR( "before deleting pki...");
|
||||
db->deletePKI(oldkey);
|
||||
lkey->setDescription(oldkey->getDescription());
|
||||
lkey->setIntName(oldkey->getIntName());
|
||||
delete(oldkey);
|
||||
}
|
||||
}
|
||||
@ -227,7 +223,7 @@ void KeyView::store()
|
||||
pki_key *targetKey = NULL;
|
||||
targetKey = (pki_key *)getSelected();
|
||||
if (!targetKey) return;
|
||||
ExportKey *dlg = new ExportKey((targetKey->getDescription() + ".pem").c_str(),
|
||||
ExportKey *dlg = new ExportKey((targetKey->getIntName() + ".pem"),
|
||||
targetKey->isPubKey(), MainWindow::getPath(), this);
|
||||
dlg->image->setPixmap(*image);
|
||||
int dlgret = dlg->exec();
|
||||
@ -237,8 +233,8 @@ void KeyView::store()
|
||||
delete dlg;
|
||||
return;
|
||||
}
|
||||
string fname = dlg->filename->text().latin1();
|
||||
if (fname == "") {
|
||||
QString fname = dlg->filename->text();
|
||||
if (fname.isEmpty()) {
|
||||
delete dlg;
|
||||
return;
|
||||
}
|
||||
@ -293,10 +289,10 @@ void KeyView::updateViewItem(pki_base *pki)
|
||||
if (! pki) return;
|
||||
XcaListView::updateViewItem(pki);
|
||||
int pixnum = 0;
|
||||
QListViewItem *current = (QListViewItem *)pki->getPointer();
|
||||
QListViewItem *current = pki->getLvi();
|
||||
if (!current) return;
|
||||
if (((pki_key *)pki)->isPubKey()) pixnum += 1;
|
||||
current->setPixmap(0, *keyicon[pixnum]);
|
||||
current->setText(1, ((pki_key *)pki)->length().c_str());
|
||||
current->setText(1, ((pki_key *)pki)->length());
|
||||
current->setText(2, QString::number(((pki_key *)pki)->getUcount()));
|
||||
}
|
||||
|
||||
106
NewX509.cpp
106
NewX509.cpp
@ -199,8 +199,8 @@ You are done with entering all parameters for the Template.
|
||||
After this step the template can be assigned to one of your CAs to be autoatically \
|
||||
applied when signing with this CA.");
|
||||
tText=tr("Template");
|
||||
if (temp->getDescription() != "--") {
|
||||
description->setText(temp->getDescription().c_str());
|
||||
if (temp->getIntName() != "--") {
|
||||
description->setText(temp->getIntName());
|
||||
tText += tr(" change");
|
||||
}
|
||||
setup();
|
||||
@ -241,7 +241,7 @@ void NewX509::defineRequest(pki_x509req *req)
|
||||
if (!req) return;
|
||||
fromReqCB->setEnabled(true);
|
||||
fromReqCB->setChecked(true);
|
||||
QString reqname = req->getDescription().c_str();
|
||||
QString reqname = req->getIntName();
|
||||
#ifdef qt3
|
||||
reqList->setCurrentText(reqname);
|
||||
#else
|
||||
@ -298,23 +298,23 @@ void NewX509::int2lb(QListBox *lb, int x)
|
||||
|
||||
void NewX509::fromTemplate(pki_temp *temp)
|
||||
{
|
||||
countryName->setText(temp->C.c_str());
|
||||
stateOrProvinceName->setText(temp->P.c_str());
|
||||
localityName->setText(temp->L.c_str());
|
||||
organisationName->setText(temp->O.c_str());
|
||||
organisationalUnitName->setText(temp->OU.c_str());
|
||||
commonName->setText(temp->CN.c_str());
|
||||
emailAddress->setText(temp->EMAIL.c_str());
|
||||
subAltName->setText(temp->subAltName.c_str());
|
||||
issAltName->setText(temp->issAltName.c_str());
|
||||
crlDist->setText(temp->crlDist.c_str());
|
||||
nsComment->setText(temp->nsComment.c_str());
|
||||
nsBaseUrl->setText(temp->nsBaseUrl.c_str());
|
||||
nsRevocationUrl->setText(temp->nsRevocationUrl.c_str());
|
||||
nsCARevocationUrl->setText(temp->nsCARevocationUrl.c_str());
|
||||
nsRenewalUrl->setText(temp->nsRenewalUrl.c_str());
|
||||
nsCaPolicyUrl->setText(temp->nsCaPolicyUrl.c_str());
|
||||
nsSslServerName->setText(temp->nsSslServerName.c_str());
|
||||
countryName->setText(temp->C);
|
||||
stateOrProvinceName->setText(temp->P);
|
||||
localityName->setText(temp->L);
|
||||
organisationName->setText(temp->O);
|
||||
organisationalUnitName->setText(temp->OU);
|
||||
commonName->setText(temp->CN);
|
||||
emailAddress->setText(temp->EMAIL);
|
||||
subAltName->setText(temp->subAltName);
|
||||
issAltName->setText(temp->issAltName);
|
||||
crlDist->setText(temp->crlDist);
|
||||
nsComment->setText(temp->nsComment);
|
||||
nsBaseUrl->setText(temp->nsBaseUrl);
|
||||
nsRevocationUrl->setText(temp->nsRevocationUrl);
|
||||
nsCARevocationUrl->setText(temp->nsCARevocationUrl);
|
||||
nsRenewalUrl->setText(temp->nsRenewalUrl);
|
||||
nsCaPolicyUrl->setText(temp->nsCaPolicyUrl);
|
||||
nsSslServerName->setText(temp->nsSslServerName);
|
||||
int2lb(nsCertType, temp->nsCertType);
|
||||
basicCA->setCurrentItem(temp->ca?1:0);
|
||||
bcCritical->setChecked(temp->bcCrit);
|
||||
@ -326,8 +326,8 @@ void NewX509::fromTemplate(pki_temp *temp)
|
||||
issAltCp->setChecked(temp->issAltCp);
|
||||
int2lb(keyUsage, temp->keyUse);
|
||||
int2lb(ekeyUsage, temp->eKeyUse);
|
||||
validNumber->setText(QString::number(temp->validN));
|
||||
validRange->setCurrentItem(temp->validM);
|
||||
//validNumber->setText(QString::number(temp->validN));
|
||||
//validRange->setCurrentItem(temp->validM);
|
||||
if (temp->pathLen) {
|
||||
basicPath->setText(QString::number(temp->pathLen));
|
||||
}
|
||||
@ -336,24 +336,24 @@ void NewX509::fromTemplate(pki_temp *temp)
|
||||
|
||||
void NewX509::toTemplate(pki_temp *temp)
|
||||
{
|
||||
temp->setDescription(description->text().latin1());
|
||||
temp->C = countryName->text().latin1();
|
||||
temp->P = stateOrProvinceName->text().latin1();
|
||||
temp->L = localityName->text().latin1();
|
||||
temp->O = organisationName->text().latin1();
|
||||
temp->OU = organisationalUnitName->text().latin1();
|
||||
temp->CN = commonName->text().latin1();
|
||||
temp->EMAIL = emailAddress->text().latin1();
|
||||
temp->subAltName = subAltName->text().latin1();
|
||||
temp->issAltName = issAltName->text().latin1();
|
||||
temp->crlDist = crlDist->text().latin1();
|
||||
temp->nsComment = nsComment->text().latin1();
|
||||
temp->nsBaseUrl = nsBaseUrl->text().latin1();
|
||||
temp->nsRevocationUrl = nsRevocationUrl->text().latin1();
|
||||
temp->nsCARevocationUrl = nsCARevocationUrl->text().latin1();
|
||||
temp->nsRenewalUrl = nsRenewalUrl->text().latin1();
|
||||
temp->nsCaPolicyUrl = nsCaPolicyUrl->text().latin1();
|
||||
temp->nsSslServerName = nsSslServerName->text().latin1();
|
||||
temp->setIntName(description->text());
|
||||
temp->C = countryName->text();
|
||||
temp->P = stateOrProvinceName->text();
|
||||
temp->L = localityName->text();
|
||||
temp->O = organisationName->text();
|
||||
temp->OU = organisationalUnitName->text();
|
||||
temp->CN = commonName->text();
|
||||
temp->EMAIL = emailAddress->text();
|
||||
temp->subAltName = subAltName->text();
|
||||
temp->issAltName = issAltName->text();
|
||||
temp->crlDist = crlDist->text();
|
||||
temp->nsComment = nsComment->text();
|
||||
temp->nsBaseUrl = nsBaseUrl->text();
|
||||
temp->nsRevocationUrl = nsRevocationUrl->text();
|
||||
temp->nsCARevocationUrl = nsCARevocationUrl->text();
|
||||
temp->nsRenewalUrl = nsRenewalUrl->text();
|
||||
temp->nsCaPolicyUrl = nsCaPolicyUrl->text();
|
||||
temp->nsSslServerName = nsSslServerName->text();
|
||||
temp->nsCertType = lb2int(nsCertType);
|
||||
temp->ca = basicCA->currentItem();
|
||||
temp->bcCrit = bcCritical->isChecked();
|
||||
@ -365,8 +365,8 @@ void NewX509::toTemplate(pki_temp *temp)
|
||||
temp->issAltCp = issAltCp->isChecked();
|
||||
temp->keyUse = lb2int(keyUsage);
|
||||
temp->eKeyUse = lb2int(ekeyUsage);
|
||||
temp->validN = validNumber->text().toInt();
|
||||
temp->validM = validRange->currentItem();
|
||||
//temp->validN = validNumber->text().toInt();
|
||||
//temp->validM = validRange->currentItem();
|
||||
temp->pathLen = basicPath->text().toInt();
|
||||
}
|
||||
|
||||
@ -426,13 +426,13 @@ void NewX509::signerChanged()
|
||||
CERR("signer Changed");
|
||||
if (!certs) return;
|
||||
QString name = certList->currentText();
|
||||
CERR( "Certificate: " << name.latin1());
|
||||
CERR( "Certificate: " << name);
|
||||
|
||||
if (name.isEmpty()) return;
|
||||
pki_x509 *cert = (pki_x509 *)certs->getByName(name);
|
||||
|
||||
if (!cert) return;
|
||||
QString templ = cert->getTemplate().c_str();
|
||||
QString templ = cert->getTemplate();
|
||||
|
||||
if (templ.isEmpty()) return;
|
||||
CERR( "set Template: " << templ );
|
||||
@ -460,7 +460,7 @@ void NewX509::templateChanged(QString tempname)
|
||||
|
||||
void NewX509::templateChanged(pki_temp *templ)
|
||||
{
|
||||
QString tempname = templ->getDescription().c_str();
|
||||
QString tempname = templ->getIntName();
|
||||
templateChanged(tempname);
|
||||
}
|
||||
|
||||
@ -523,7 +523,7 @@ void NewX509::helpClicked()
|
||||
|
||||
pki_key *NewX509::getSelectedKey()
|
||||
{
|
||||
return MainWindow::getKeyByName(keyList->currentText());
|
||||
return (pki_key *)MainWindow::keys->getByName(keyList->currentText());
|
||||
}
|
||||
|
||||
x509name NewX509::getX509name()
|
||||
@ -538,3 +538,17 @@ x509name NewX509::getX509name()
|
||||
x.addEntryByNid(NID_pkcs9_emailAddress, emailAddress->text());
|
||||
return x;
|
||||
}
|
||||
|
||||
a1time NewX509::getNotBefore()
|
||||
{
|
||||
a1time nb;
|
||||
nb.set(nbYear->getText() + nbMon->getText() + nbDay->getText());
|
||||
return nb;
|
||||
}
|
||||
|
||||
a1time NewX509::getNotAfter()
|
||||
{
|
||||
a1time nb;
|
||||
nb.set(nbYear->getText() + nbMon->getText() + nbDay->getText());
|
||||
return nb;
|
||||
}
|
||||
|
||||
@ -111,7 +111,7 @@ void ReqView::show(pki_base *item, bool import)
|
||||
try {
|
||||
pki_x509req *req = (pki_x509req *)item;
|
||||
ReqDetail_UI *dlg = new ReqDetail_UI(this,0,true);
|
||||
dlg->descr->setText(req->getDescription().c_str());
|
||||
dlg->descr->setText(req->getIntName());
|
||||
dlg->setCaption(tr(XCA_TITLE));
|
||||
if (!req->verify() ) {
|
||||
dlg->verify->setDisabled(true);
|
||||
@ -177,7 +177,7 @@ void ReqView::load()
|
||||
|
||||
pki_base *ReqView::loadItem(QString fname)
|
||||
{
|
||||
pki_base *req = new pki_x509req(fname.latin1());
|
||||
pki_base *req = new pki_x509req(fname);
|
||||
return req;
|
||||
}
|
||||
|
||||
@ -215,7 +215,7 @@ void ReqView::store(bool pem)
|
||||
if (s.isEmpty()) return;
|
||||
s=QDir::convertSeparators(s);
|
||||
try {
|
||||
req->writeReq(s.latin1(), pem);
|
||||
req->writeReq(s, pem);
|
||||
}
|
||||
catch (errorEx &err) {
|
||||
Error(err);
|
||||
@ -249,7 +249,7 @@ pki_base *ReqView::insert(pki_base *item)
|
||||
if (oldreq) {
|
||||
QMessageBox::information(this,tr(XCA_TITLE),
|
||||
tr("The certificate signing request already exists in the database as") +":\n'" +
|
||||
QString::fromLatin1(oldreq->getDescription().c_str()) +
|
||||
oldreq->getIntName() +
|
||||
"'\n" + tr("and thus was not stored"), "OK");
|
||||
delete(req);
|
||||
return oldreq;
|
||||
|
||||
@ -194,8 +194,6 @@ void XcaListView::Error(errorEx &err)
|
||||
|
||||
bool XcaListView::Error(pki_base *pki)
|
||||
{
|
||||
string err;
|
||||
|
||||
if (!pki) {
|
||||
QMessageBox::warning(this,tr(XCA_TITLE), tr("The system detected a NULL pointer, maybe the system is out of memory" ));
|
||||
qFatal("NULL pointer detected - Exiting");
|
||||
@ -211,7 +209,7 @@ void XcaListView::updateView()
|
||||
pki_base *pki;
|
||||
container = db->getContainer();
|
||||
if (container.isEmpty()) return;
|
||||
for ( pki = container.first(); pki != NULL; pki = container.next() ) pki->delPointer();
|
||||
for ( pki = container.first(); pki != NULL; pki = container.next() ) pki->delLvi();
|
||||
QListIterator<pki_base> it(container);
|
||||
for ( ; it.current(); ++it ) {
|
||||
pki = it.current();
|
||||
|
||||
@ -118,6 +118,11 @@ QString a1time::toSortable() const
|
||||
return t;
|
||||
}
|
||||
|
||||
void a1time::set(const QString &s)
|
||||
{
|
||||
ASN1_GENERALIZEDTIME_set_string(time, (char *)s.latin1());
|
||||
}
|
||||
|
||||
int a1time::ymdg(int *y, int *m, int *d, int *g) const
|
||||
{
|
||||
char *v;
|
||||
@ -180,3 +185,47 @@ int a1time::derSize() const
|
||||
{
|
||||
return i2d_ASN1_TIME(time, NULL);
|
||||
}
|
||||
|
||||
|
||||
/* this was happily copied from OpenSSL 0.9.7
|
||||
* and is used if linking against 0.9.6
|
||||
*/
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER < 0x00907000L
|
||||
/* Convert an ASN1_TIME structure to GeneralizedTime */
|
||||
ASN1_GENERALIZEDTIME *a1time::ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out)
|
||||
{
|
||||
ASN1_GENERALIZEDTIME *ret;
|
||||
char *str;
|
||||
|
||||
// if (!ASN1_TIME_check(t)) return NULL;
|
||||
|
||||
if (!out || !*out)
|
||||
{
|
||||
if (!(ret = ASN1_GENERALIZEDTIME_new ()))
|
||||
return NULL;
|
||||
if (out) *out = ret;
|
||||
}
|
||||
else ret = *out;
|
||||
|
||||
/* If already GeneralizedTime just copy across */
|
||||
if (t->type == V_ASN1_GENERALIZEDTIME)
|
||||
{
|
||||
if(!ASN1_STRING_set(ret, t->data, t->length))
|
||||
return NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* grow the string */
|
||||
if (!ASN1_STRING_set(ret, NULL, t->length + 2))
|
||||
return NULL;
|
||||
str = (char *)ret->data;
|
||||
/* Work out the century and prepend */
|
||||
if (t->data[0] >= '5') strcpy(str, "19");
|
||||
else strcpy(str, "20");
|
||||
|
||||
strncat(str, (char *)t->data, t->length);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -58,12 +58,16 @@ class a1time
|
||||
{
|
||||
private:
|
||||
ASN1_GENERALIZEDTIME *time;
|
||||
#if OPENSSL_VERSION_NUMBER < 0x00907000L
|
||||
ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out);
|
||||
#endif
|
||||
public:
|
||||
a1time();
|
||||
a1time(const ASN1_TIME *a);
|
||||
~a1time();
|
||||
void set(const ASN1_TIME *a);
|
||||
void set(time_t t);
|
||||
void set(const QString &s);
|
||||
QString toPretty() const;
|
||||
QString toPlain() const;
|
||||
QString toSortable() const;
|
||||
|
||||
@ -54,16 +54,16 @@
|
||||
#include <qmessagebox.h>
|
||||
#include <qdir.h>
|
||||
|
||||
db_base::db_base(DbEnv *dbe, string DBfile, string DB, DbTxn *global_tid)
|
||||
db_base::db_base(DbEnv *dbe, QString DBfile, QString DB, DbTxn *global_tid)
|
||||
{
|
||||
dbenv = dbe;
|
||||
data = new Db(dbe, 0);
|
||||
CERR("DB:" << DBfile);
|
||||
try {
|
||||
#if DB_VERSION_MAJOR >= 4 && DB_VERSION_MINOR >=1
|
||||
data->open(NULL, DBfile.c_str(), DB.c_str(), DB_BTREE, DB_CREATE, 0600);
|
||||
data->open(NULL, DBfile.latin1(), DB.latin1(), DB_BTREE, DB_CREATE, 0600);
|
||||
#else
|
||||
data->open(DBfile.c_str(), DB.c_str(), DB_BTREE, DB_CREATE, 0600);
|
||||
data->open(DBfile.latin1(), DB.latin1(), DB_BTREE, DB_CREATE, 0600);
|
||||
#endif
|
||||
}
|
||||
catch (DbException &err) {
|
||||
@ -105,15 +105,15 @@ void *db_base::getData(void *key, int length, int *dsize)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *db_base::getData(string key, int *dsize)
|
||||
void *db_base::getData(QString key, int *dsize)
|
||||
{
|
||||
return getData((void *)key.c_str(), key.length()+ 1, dsize);
|
||||
return getData((void *)key.latin1(), key.length()+ 1, dsize);
|
||||
}
|
||||
|
||||
|
||||
string db_base::getString(string key)
|
||||
QString db_base::getString(QString key)
|
||||
{
|
||||
string x = "";
|
||||
QString x = "";
|
||||
int dsize;
|
||||
char *p = (char *)getData(key, &dsize);
|
||||
if (p == NULL) {
|
||||
@ -122,29 +122,29 @@ string db_base::getString(string key)
|
||||
}
|
||||
if ( p[dsize-1] != '\0' ) {
|
||||
int a =p[dsize-1];
|
||||
CERR( "getString: stringerror "<< a <<" != 0 (returning empty string) size:" <<dsize);
|
||||
CERR( "getString: QStringerror "<< a <<" != 0 (returning empty QString) size:" <<dsize);
|
||||
return x;
|
||||
}
|
||||
x = p;
|
||||
free(p);
|
||||
if ( (int)x.length() != (dsize-1) ) {
|
||||
CERR( "error with '"<<key<<"': "<< x.c_str() <<" "<<dsize);
|
||||
CERR( "error with '"<<key<<"': "<< x.latin1() <<" "<<dsize);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
string db_base::getString(char *key)
|
||||
QString db_base::getString(char *key)
|
||||
{
|
||||
string x = key;
|
||||
QString x = key;
|
||||
return getString(x);
|
||||
}
|
||||
|
||||
|
||||
int db_base::getInt(string key)
|
||||
int db_base::getInt(QString key)
|
||||
{
|
||||
string x = getString(key);
|
||||
return atoi(x.c_str());
|
||||
QString x = getString(key);
|
||||
return atoi(x.latin1());
|
||||
}
|
||||
|
||||
|
||||
@ -162,30 +162,30 @@ void db_base::putData(void *key, int keylen, void *dat, int datalen)
|
||||
}
|
||||
}
|
||||
|
||||
void db_base::putString(string key, void *dat, int datalen)
|
||||
void db_base::putString(QString key, void *dat, int datalen)
|
||||
{
|
||||
CERR( key );
|
||||
putData((void *)key.c_str(), key.length()+1, dat, datalen);
|
||||
putData((void *)key.latin1(), key.length()+1, dat, datalen);
|
||||
}
|
||||
|
||||
void db_base::putString(string key, string dat)
|
||||
void db_base::putString(QString key, QString dat)
|
||||
{
|
||||
CERR( key);
|
||||
putString(key, (void *)dat.c_str(), dat.length() +1);
|
||||
putString(key, (void *)dat.latin1(), dat.length() +1);
|
||||
}
|
||||
|
||||
void db_base::putString(char *key, string dat)
|
||||
void db_base::putString(char *key, QString dat)
|
||||
{
|
||||
string x = key;
|
||||
QString x = key;
|
||||
CERR(key);
|
||||
putString(x,dat);
|
||||
}
|
||||
|
||||
void db_base::putInt(string key, int dat)
|
||||
void db_base::putInt(QString key, int dat)
|
||||
{
|
||||
char buf[100];
|
||||
sprintf(buf,"%i",dat);
|
||||
string x = buf;
|
||||
QString x = buf;
|
||||
putString(key, x);
|
||||
}
|
||||
|
||||
@ -199,7 +199,7 @@ void db_base::loadContainer()
|
||||
data->cursor(tid, &cursor, 0);
|
||||
Dbt *k = new Dbt();
|
||||
Dbt *d = new Dbt();
|
||||
string desc;
|
||||
QString desc;
|
||||
pki_base *pki;
|
||||
container.clear();
|
||||
CERR("Load Container");
|
||||
@ -210,13 +210,13 @@ void db_base::loadContainer()
|
||||
try {
|
||||
pki = newPKI();
|
||||
CERR("PKItest");
|
||||
CERR(desc.c_str());
|
||||
CERR(desc.latin1());
|
||||
pki->fromData(p, size);
|
||||
pki->setDescription(desc);
|
||||
pki->setIntName(desc);
|
||||
container.append(pki);
|
||||
}
|
||||
catch (errorEx &err) {
|
||||
QMessageBox::warning(NULL,tr(XCA_TITLE), tr("Error loading: '") + desc.c_str() + "'\n" +
|
||||
QMessageBox::warning(NULL,tr(XCA_TITLE), tr("Error loading: '") + desc.latin1() + "'\n" +
|
||||
err.getCString());
|
||||
}
|
||||
}
|
||||
@ -252,11 +252,11 @@ void db_base::_writePKI(pki_base *pki, bool overwrite, DbTxn *tid)
|
||||
{
|
||||
int flags = 0;
|
||||
if (!overwrite) flags = DB_NOOVERWRITE;
|
||||
string desc = pki->getDescription();
|
||||
QString desc = pki->getIntName();
|
||||
if (desc == "") {
|
||||
desc="unnamed";
|
||||
}
|
||||
string orig = desc;
|
||||
QString orig = desc;
|
||||
int size=0;
|
||||
char field[10];
|
||||
unsigned char *p = pki->toData(&size);
|
||||
@ -264,17 +264,17 @@ void db_base::_writePKI(pki_base *pki, bool overwrite, DbTxn *tid)
|
||||
int x = DB_KEYEXIST;
|
||||
// exception occuring here will be catched by the caller
|
||||
while (x == DB_KEYEXIST) {
|
||||
Dbt k((void *)desc.c_str(), desc.length() + 1);
|
||||
Dbt k((void *)desc.latin1(), desc.length() + 1);
|
||||
Dbt d((void *)p, size);
|
||||
CERR("Size: " << d.get_size());
|
||||
if ((x = data->put(tid, &k, &d, flags ))!=0) {
|
||||
data->err(x,"DB Error put");
|
||||
sprintf(field,"%02i", ++cnt);
|
||||
string z = field;
|
||||
QString z = field;
|
||||
desc = orig + "_" + z ;
|
||||
}
|
||||
}
|
||||
pki->setDescription(desc);
|
||||
pki->setIntName(desc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -96,7 +96,7 @@ class db_base: public QObject
|
||||
void _removePKI(pki_base *pki, DbTxn *tid );
|
||||
void removeItem(QString k, DbTxn *tid);
|
||||
public:
|
||||
db_base(DbEnv *dbe, string DBfile, string db, DbTxn *global_tid);
|
||||
db_base(DbEnv *dbe, QString DBfile, QString db, DbTxn *global_tid);
|
||||
virtual ~db_base();
|
||||
virtual pki_base *newPKI(){
|
||||
CERR("VIRTUAL CALLED: newPKI"); return NULL;}
|
||||
@ -115,15 +115,15 @@ class db_base: public QObject
|
||||
virtual void remFromCont(pki_base *pki);
|
||||
virtual void inToCont(pki_base *pki);
|
||||
void *getData(void* key, int length, int *dsize);
|
||||
void *getData(string key, int *dsize);
|
||||
string getString(string key);
|
||||
string getString(char *key);
|
||||
int getInt(string key);
|
||||
void *getData(QString key, int *dsize);
|
||||
QString getString(QString key);
|
||||
QString getString(char *key);
|
||||
int getInt(QString key);
|
||||
void putData(void *key, int keylen, void *dat, int datalen);
|
||||
void putString(string key, void *dat, int datalen);
|
||||
void putString(string key, string dat);
|
||||
void putString(char *key, string dat);
|
||||
void putInt(string key, int dat);
|
||||
void putString(QString key, void *dat, int datalen);
|
||||
void putString(QString key, QString dat);
|
||||
void putString(char *key, QString dat);
|
||||
void putInt(QString key, int dat);
|
||||
QPixmap *loadImg(const char *name);
|
||||
QList<pki_base> getContainer();
|
||||
};
|
||||
|
||||
@ -51,7 +51,7 @@
|
||||
|
||||
#include "db_crl.h"
|
||||
|
||||
db_crl::db_crl(DbEnv *dbe, string DBfile, DbTxn *tid)
|
||||
db_crl::db_crl(DbEnv *dbe, QString DBfile, DbTxn *tid)
|
||||
:db_base(dbe, DBfile, "crldb", tid)
|
||||
{
|
||||
loadContainer();
|
||||
|
||||
@ -49,10 +49,8 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "db_base.h"
|
||||
#include "db_x509.h"
|
||||
#include "pki_crl.h"
|
||||
#include <qstringlist.h>
|
||||
|
||||
#ifndef DB_CRL_H
|
||||
#define DB_CRL_H
|
||||
@ -65,7 +63,7 @@ class db_crl: public db_base
|
||||
QPixmap *crlicon;
|
||||
db_x509 *certs;
|
||||
public:
|
||||
db_crl(DbEnv *dbe, string DBfile, DbTxn *tid);
|
||||
db_crl(DbEnv *dbe, QString DBfile, DbTxn *tid);
|
||||
pki_base *newPKI();
|
||||
void revokeCerts(pki_crl *crl);
|
||||
void preprocess();
|
||||
|
||||
@ -54,7 +54,7 @@
|
||||
pki != 0; pki = (pki_key *)container.next() )
|
||||
|
||||
|
||||
db_key::db_key(DbEnv *dbe, string DBfile, DbTxn *tid)
|
||||
db_key::db_key(DbEnv *dbe, QString DBfile, DbTxn *tid)
|
||||
:db_base(dbe, DBfile, "keydb",tid)
|
||||
{
|
||||
loadContainer();
|
||||
|
||||
@ -61,7 +61,7 @@ class db_key: public db_base
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
db_key(DbEnv *dbe, string DBfile, DbTxn *tid);
|
||||
db_key(DbEnv *dbe, QString DBfile, DbTxn *tid);
|
||||
pki_base *newPKI();
|
||||
QStringList getPrivateDesc();
|
||||
QStringList get0PrivateDesc();
|
||||
|
||||
@ -52,7 +52,7 @@
|
||||
#include "db_temp.h"
|
||||
|
||||
|
||||
db_temp::db_temp(DbEnv *dbe, string DBfile, QListView *l, DbTxn *tid)
|
||||
db_temp::db_temp(DbEnv *dbe, QString DBfile, QListView *l, DbTxn *tid)
|
||||
:db_base(dbe, DBfile, "tempdb", tid)
|
||||
{
|
||||
loadContainer();
|
||||
|
||||
@ -49,13 +49,12 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "db_base.h"
|
||||
#include "pki_temp.h"
|
||||
#include <qstringlist.h>
|
||||
|
||||
#ifndef DB_TEMP_H
|
||||
#define DB_TEMP_H
|
||||
|
||||
#include "db_base.h"
|
||||
#include "pki_temp.h"
|
||||
|
||||
|
||||
class db_temp: public db_base
|
||||
{
|
||||
@ -63,7 +62,7 @@ class db_temp: public db_base
|
||||
protected:
|
||||
QPixmap *keyicon;
|
||||
public:
|
||||
db_temp(DbEnv *dbe, string DBfile, QListView *l, DbTxn *tid);
|
||||
db_temp(DbEnv *dbe, QString DBfile, QListView *l, DbTxn *tid);
|
||||
pki_base *newPKI();
|
||||
};
|
||||
|
||||
|
||||
@ -54,7 +54,7 @@
|
||||
pki != 0; pki = (pki_x509 *)container.next() )
|
||||
|
||||
|
||||
db_x509::db_x509(DbEnv *dbe, string DBfile, QListView *l, db_key *keyl, DbTxn *tid)
|
||||
db_x509::db_x509(DbEnv *dbe, QString DBfile, QListView *l, db_key *keyl, DbTxn *tid)
|
||||
:db_x509super(dbe, DBfile, "certdb", keyl, tid)
|
||||
{
|
||||
loadContainer();
|
||||
|
||||
@ -66,7 +66,7 @@ class db_x509: public db_x509super
|
||||
protected:
|
||||
QPixmap *certicon[4];
|
||||
public:
|
||||
db_x509(DbEnv *dbe, string DBfile, QListView *l, db_key *keyl, DbTxn *tid);
|
||||
db_x509(DbEnv *dbe, QString DBfile, QListView *l, db_key *keyl, DbTxn *tid);
|
||||
pki_base *newPKI();
|
||||
pki_x509 *findSigner(pki_x509 *client);
|
||||
bool updateView();
|
||||
|
||||
@ -50,8 +50,9 @@
|
||||
|
||||
|
||||
#include "db_x509req.h"
|
||||
#include "pki_x509req.h"
|
||||
|
||||
db_x509req::db_x509req(DbEnv *dbe, string DBfile, db_key *dk, DbTxn *tid)
|
||||
db_x509req::db_x509req(DbEnv *dbe, QString DBfile, db_key *dk, DbTxn *tid)
|
||||
:db_x509super(dbe, DBfile, "reqdb", dk, tid)
|
||||
{
|
||||
loadContainer();
|
||||
|
||||
@ -49,10 +49,8 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <qstringlist.h>
|
||||
#include "db_key.h"
|
||||
#include "db_x509super.h"
|
||||
#include "pki_x509req.h"
|
||||
|
||||
#ifndef DB_X509REQ_H
|
||||
#define DB_X509REQ_H
|
||||
@ -62,7 +60,7 @@ class db_x509req: public db_x509super
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
db_x509req(DbEnv *dbe, string DBfile, db_key *dk, DbTxn *tid);
|
||||
db_x509req(DbEnv *dbe, QString DBfile, db_key *dk, DbTxn *tid);
|
||||
pki_base *newPKI();
|
||||
};
|
||||
|
||||
|
||||
@ -53,7 +53,7 @@
|
||||
#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_x509super::db_x509super(DbEnv *dbe, QString DBfile, QString db, db_key *dk, DbTxn *tid)
|
||||
:db_base(dbe, DBfile, db, tid)
|
||||
{
|
||||
keylist = dk;
|
||||
|
||||
@ -49,7 +49,6 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <qstringlist.h>
|
||||
#include "db_key.h"
|
||||
#include "pki_x509super.h"
|
||||
|
||||
@ -63,7 +62,7 @@ class db_x509super: public db_base
|
||||
protected:
|
||||
db_key *keylist;
|
||||
public:
|
||||
db_x509super(DbEnv *dbe, string DBfile, string db, db_key *dk, DbTxn *tid);
|
||||
db_x509super(DbEnv *dbe, QString DBfile, QString db, db_key *dk, DbTxn *tid);
|
||||
void preprocess();
|
||||
pki_key *findKey(pki_x509super *ref);
|
||||
public slots:
|
||||
|
||||
@ -48,33 +48,26 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "../config.h"
|
||||
#endif
|
||||
|
||||
#include "base.h"
|
||||
|
||||
#ifndef PKI_EXCEPTION_H
|
||||
#define PKI_EXCEPTION_H
|
||||
|
||||
#include <qstring.h>
|
||||
#include "base.h"
|
||||
|
||||
class errorEx
|
||||
{
|
||||
private:
|
||||
string msg;
|
||||
QString msg;
|
||||
public:
|
||||
errorEx(string txt, string className = "") {
|
||||
errorEx(QString txt, QString className = "") {
|
||||
msg = txt;
|
||||
if (!className.empty())
|
||||
if (!className.isEmpty())
|
||||
msg += " (" + className + ")";
|
||||
}
|
||||
errorEx(const errorEx &e) { msg = e.msg; }
|
||||
string getString(){return msg;}
|
||||
const char *getCString(){return msg.c_str();}
|
||||
bool isEmpty() { return msg.empty();}
|
||||
QString getString() const {return msg;}
|
||||
const char *getCString() const {return msg.latin1();}
|
||||
bool isEmpty() const { return msg.isEmpty();}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -54,10 +54,10 @@
|
||||
|
||||
int pki_base::pki_counter = 0;
|
||||
|
||||
pki_base::pki_base(const string d)
|
||||
pki_base::pki_base(const QString d)
|
||||
{
|
||||
desc = d;
|
||||
className = "pki_base";
|
||||
class_name = "pki_base";
|
||||
pointer = NULL;
|
||||
pki_counter++;
|
||||
}
|
||||
@ -65,7 +65,7 @@ pki_base::pki_base(const string d)
|
||||
pki_base::pki_base()
|
||||
{
|
||||
desc = "";
|
||||
className = "pki_base";
|
||||
class_name = "pki_base";
|
||||
pointer=NULL;
|
||||
pki_counter++;
|
||||
}
|
||||
@ -76,16 +76,9 @@ pki_base::~pki_base(void)
|
||||
}
|
||||
|
||||
|
||||
string pki_base::getDescription()
|
||||
{
|
||||
string x = desc;
|
||||
return x;
|
||||
}
|
||||
|
||||
QString pki_base::getIntName()
|
||||
{
|
||||
QString x = desc.c_str();
|
||||
return x;
|
||||
return desc;
|
||||
}
|
||||
|
||||
int pki_base::get_pki_counter()
|
||||
@ -93,15 +86,9 @@ int pki_base::get_pki_counter()
|
||||
return pki_counter;
|
||||
}
|
||||
|
||||
string pki_base::getClassName()
|
||||
QString pki_base::getClassName()
|
||||
{
|
||||
return className;
|
||||
}
|
||||
|
||||
|
||||
void pki_base::setDescription(const string d)
|
||||
{
|
||||
desc = d;
|
||||
return class_name;
|
||||
}
|
||||
|
||||
void pki_base::setIntName(const QString d)
|
||||
@ -109,18 +96,17 @@ void pki_base::setIntName(const QString d)
|
||||
desc = d.latin1();
|
||||
}
|
||||
|
||||
|
||||
void pki_base::fopen_error(const string fname)
|
||||
void pki_base::fopen_error(const QString fname)
|
||||
{
|
||||
string txt = "Error opening file: '" + fname + "'";
|
||||
QString txt = "Error opening file: '" + fname + "'";
|
||||
openssl_error(txt);
|
||||
}
|
||||
|
||||
|
||||
void pki_base::openssl_error(const string myerr) const
|
||||
void pki_base::openssl_error(const QString myerr) const
|
||||
{
|
||||
string errtxt = "";
|
||||
string error = "";
|
||||
QString errtxt = "";
|
||||
QString error = "";
|
||||
if (myerr != "") {
|
||||
CERR("PKI ERROR: " << myerr);
|
||||
error += myerr + "\n";
|
||||
@ -130,8 +116,8 @@ void pki_base::openssl_error(const string myerr) const
|
||||
CERR("OpenSSL: " << errtxt);
|
||||
error += errtxt + "\n";
|
||||
}
|
||||
if (!error.empty()) {
|
||||
throw errorEx(error, className);
|
||||
if (!error.isEmpty()) {
|
||||
throw errorEx(error, class_name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,12 +125,12 @@ void pki_base::openssl_error(const string myerr) const
|
||||
bool pki_base::ign_openssl_error() const
|
||||
{
|
||||
// ignore openssl errors
|
||||
string errtxt;
|
||||
QString errtxt;
|
||||
while (int i = ERR_get_error() ) {
|
||||
errtxt = ERR_error_string(i ,NULL);
|
||||
CERR("IGNORE -> OpenSSL: " << errtxt << " <- IGNORE");
|
||||
}
|
||||
return !errtxt.empty();
|
||||
return !errtxt.isEmpty();
|
||||
}
|
||||
|
||||
int pki_base::intToData(unsigned char **p, const int val)
|
||||
@ -181,17 +167,17 @@ bool pki_base::boolFromData(unsigned char **p)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pki_base::stringToData(unsigned char **p, const string val)
|
||||
int pki_base::stringToData(unsigned char **p, const QString val)
|
||||
{
|
||||
int s = (val.length() +1) * sizeof(char);
|
||||
memcpy(*p, val.c_str(), s);
|
||||
memcpy(*p, val.latin1(), s);
|
||||
*p += s;
|
||||
return s;
|
||||
}
|
||||
|
||||
string pki_base::stringFromData(unsigned char **p)
|
||||
QString pki_base::stringFromData(unsigned char **p)
|
||||
{
|
||||
string ret="";
|
||||
QString ret="";
|
||||
while(**p) {
|
||||
ret +=(char)**p;
|
||||
*p += sizeof(char);
|
||||
@ -199,3 +185,14 @@ string pki_base::stringFromData(unsigned char **p)
|
||||
*p += sizeof(char);
|
||||
return ret;
|
||||
}
|
||||
|
||||
QString pki_base::rmslashdot(const QString &s)
|
||||
{
|
||||
int r = s.findRev('.');
|
||||
#ifdef WIN32
|
||||
int l = s.findRev('\\');
|
||||
#else
|
||||
int l = s.findRev('/');
|
||||
#endif
|
||||
return s.mid(l+1,r-l-1);
|
||||
}
|
||||
|
||||
@ -54,30 +54,29 @@
|
||||
#include <openssl/err.h>
|
||||
#include <qstring.h>
|
||||
#include <qlistview.h>
|
||||
#include <string>
|
||||
#include "base.h"
|
||||
|
||||
#define p_tr pass_info::tr
|
||||
|
||||
class pki_base
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
static int pki_counter;
|
||||
protected:
|
||||
string desc;
|
||||
string className;
|
||||
QString desc;
|
||||
QString class_name;
|
||||
QListViewItem *pointer;
|
||||
void openssl_error(const string myerr = "") const;
|
||||
void fopen_error(const string fname);
|
||||
void openssl_error(const QString myerr = "") const;
|
||||
void fopen_error(const QString fname);
|
||||
bool ign_openssl_error() const;
|
||||
int intToData(unsigned char **p, const int val);
|
||||
int intFromData(unsigned char **p);
|
||||
int boolToData(unsigned char **p, const bool val);
|
||||
bool boolFromData(unsigned char **p);
|
||||
int stringToData(unsigned char **p, const string val);
|
||||
string stringFromData(unsigned char **p);
|
||||
int stringToData(unsigned char **p, const QString val);
|
||||
QString stringFromData(unsigned char **p);
|
||||
public:
|
||||
pki_base(const string d);
|
||||
pki_base(const QString d);
|
||||
pki_base();
|
||||
static int get_pki_counter();
|
||||
virtual void fromData(unsigned char *p, int size)
|
||||
@ -87,16 +86,13 @@ class pki_base
|
||||
virtual bool compare(pki_base *ref)
|
||||
{ CERR("VIRTUAL FUNCTION CALLED: compare"); return false;};
|
||||
virtual ~pki_base();
|
||||
string getDescription();
|
||||
void setDescription(const string d );
|
||||
QString getIntName();
|
||||
void setIntName(const QString d );
|
||||
void setPointer(void *ptr) { pointer = (QListViewItem *)ptr; }
|
||||
void delPointer() { pointer = NULL; }
|
||||
void *getPointer() { return (void *)pointer; }
|
||||
void delLvi() { pointer = NULL; }
|
||||
QListViewItem *getLvi() { return pointer; }
|
||||
void setLvi(QListViewItem *ptr) { pointer = ptr; }
|
||||
string getClassName();
|
||||
QString getClassName();
|
||||
QString rmslashdot(const QString &fname);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -52,12 +52,12 @@
|
||||
#include "pki_crl.h"
|
||||
|
||||
|
||||
pki_crl::pki_crl(const string d, pki_x509 *iss )
|
||||
pki_crl::pki_crl(const QString d, pki_x509 *iss )
|
||||
:pki_base(d)
|
||||
{
|
||||
issuer = iss;
|
||||
crl = NULL;
|
||||
className="pki_crl";
|
||||
class_name="pki_crl";
|
||||
if (!iss) openssl_error("no issuer");
|
||||
crl = X509_CRL_new();
|
||||
X509V3_set_ctx(&ctx, issuer->cert, NULL, NULL, crl, 0);
|
||||
@ -76,13 +76,13 @@ pki_crl::pki_crl(const string d, pki_x509 *iss )
|
||||
openssl_error();
|
||||
}
|
||||
|
||||
pki_crl::pki_crl(const string fname )
|
||||
pki_crl::pki_crl(const QString fname )
|
||||
:pki_base(fname)
|
||||
{
|
||||
issuer = NULL;
|
||||
crl = X509_CRL_new();
|
||||
className="pki_crl";
|
||||
FILE * fp = fopen(fname.c_str(), "r");
|
||||
class_name="pki_crl";
|
||||
FILE * fp = fopen(fname, "r");
|
||||
if (fp != NULL) {
|
||||
crl = PEM_read_X509_CRL(fp, &crl, NULL, NULL);
|
||||
if (!crl) {
|
||||
@ -92,14 +92,7 @@ pki_crl::pki_crl(const string fname )
|
||||
crl = d2i_X509_CRL_fp(fp, &crl);
|
||||
}
|
||||
fclose(fp);
|
||||
int r = fname.rfind('.');
|
||||
#ifdef WIN32
|
||||
int l = fname.rfind('\\');
|
||||
#else
|
||||
int l = fname.rfind('/');
|
||||
#endif
|
||||
CERR( fname << "r,l: "<< r <<","<< l );
|
||||
setDescription(fname.substr(l+1,r-l-1));
|
||||
setIntName(rmslashdot(fname));
|
||||
openssl_error();
|
||||
}
|
||||
else fopen_error(fname);
|
||||
@ -110,7 +103,7 @@ pki_crl::pki_crl()
|
||||
{
|
||||
issuer = NULL;
|
||||
crl = X509_CRL_new();
|
||||
className="pki_crl";
|
||||
class_name="pki_crl";
|
||||
openssl_error();
|
||||
}
|
||||
|
||||
@ -179,20 +172,13 @@ void pki_crl::addRevoked(pki_x509 *client)
|
||||
openssl_error();
|
||||
}
|
||||
|
||||
void pki_crl::addV3ext(int nid, string exttext)
|
||||
void pki_crl::addV3ext(int nid, const QString &exttext)
|
||||
{
|
||||
X509_EXTENSION *ext;
|
||||
int len;
|
||||
char *c = NULL;
|
||||
if ((len = exttext.length()) == 0) return;
|
||||
len++;
|
||||
c = (char *)OPENSSL_malloc(len);
|
||||
openssl_error();
|
||||
strncpy(c, exttext.c_str(), len);
|
||||
char *c = (char *)exttext.latin1();
|
||||
ext = X509V3_EXT_conf_nid(NULL, &ctx, nid, c);
|
||||
OPENSSL_free(c);
|
||||
if (!ext) {
|
||||
string x="CRL v3 Extension: " + exttext;
|
||||
QString x="CRL v3 Extension: " + exttext;
|
||||
openssl_error(x);
|
||||
return;
|
||||
}
|
||||
@ -210,9 +196,9 @@ void pki_crl::sign(pki_key *key)
|
||||
}
|
||||
|
||||
|
||||
void pki_crl::writeCrl(const string fname, bool pem)
|
||||
void pki_crl::writeCrl(const QString fname, bool pem)
|
||||
{
|
||||
FILE *fp = fopen(fname.c_str(),"w");
|
||||
FILE *fp = fopen(fname,"w");
|
||||
if (fp != NULL) {
|
||||
if (crl){
|
||||
CERR("writing CRL");
|
||||
@ -229,10 +215,12 @@ void pki_crl::writeCrl(const string fname, bool pem)
|
||||
|
||||
pki_x509 *pki_crl::getIssuer() { return issuer; }
|
||||
|
||||
ASN1_TIME *pki_crl::getDate()
|
||||
a1time pki_crl::getDate()
|
||||
{
|
||||
if (!crl || !crl->crl) return NULL;
|
||||
return crl->crl->lastUpdate;
|
||||
a1time a;
|
||||
if (!crl || !crl->crl) return a;
|
||||
a.set(crl->crl->lastUpdate);
|
||||
return a;
|
||||
}
|
||||
|
||||
int pki_crl::numRev()
|
||||
@ -243,49 +231,38 @@ int pki_crl::numRev()
|
||||
return 0;
|
||||
}
|
||||
|
||||
long pki_crl::getSerial(int num)
|
||||
a1int pki_crl::getSerial(int num)
|
||||
{
|
||||
X509_REVOKED *ret = NULL;
|
||||
long serial=-1;
|
||||
a1int serial;
|
||||
serial = -1;
|
||||
if (crl && crl->crl && crl->crl->revoked) {
|
||||
ret = sk_X509_REVOKED_value(crl->crl->revoked, num);
|
||||
serial = ASN1_INTEGER_get(ret->serialNumber);
|
||||
serial.set(ret->serialNumber);
|
||||
}
|
||||
openssl_error();
|
||||
return serial;
|
||||
}
|
||||
|
||||
ASN1_TIME *pki_crl::getRevDate(int num)
|
||||
a1time pki_crl::getRevDate(int num)
|
||||
{
|
||||
X509_REVOKED *ret = NULL;
|
||||
ASN1_TIME *t = NULL;
|
||||
a1time t;;
|
||||
if (crl && crl->crl && crl->crl->revoked) {
|
||||
ret = sk_X509_REVOKED_value(crl->crl->revoked, num);
|
||||
openssl_error();
|
||||
t = M_ASN1_TIME_dup(ret->revocationDate);
|
||||
t.set(ret->revocationDate);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
string pki_crl::issuerName()
|
||||
{
|
||||
char *x = NULL;
|
||||
if (crl && crl->crl && crl->crl->issuer)
|
||||
x = X509_NAME_oneline(crl->crl->issuer, NULL ,0);
|
||||
string ret = x;
|
||||
if (x)
|
||||
OPENSSL_free(x);
|
||||
openssl_error();
|
||||
return ret;
|
||||
}
|
||||
|
||||
X509_NAME *pki_crl::getIssuerX509_NAME()
|
||||
x509name pki_crl::getIssuerName()
|
||||
{
|
||||
x509name x;
|
||||
if (crl && crl->crl && crl->crl->issuer) {
|
||||
return crl->crl->issuer;
|
||||
x.set(crl->crl->issuer);
|
||||
}
|
||||
else
|
||||
return NULL ;
|
||||
return x ;
|
||||
}
|
||||
|
||||
bool pki_crl::verify(pki_key *key)
|
||||
@ -298,7 +275,7 @@ bool pki_crl::verify(pki_key *key)
|
||||
return ret ;
|
||||
}
|
||||
|
||||
string pki_crl::printV3ext()
|
||||
QString pki_crl::printV3ext()
|
||||
{
|
||||
#define V3_BUF 100
|
||||
ASN1_OBJECT *obj;
|
||||
@ -306,7 +283,7 @@ string pki_crl::printV3ext()
|
||||
int i, len, n = X509_CRL_get_ext_count(crl);
|
||||
char buffer[V3_BUF+1];
|
||||
X509_EXTENSION *ex;
|
||||
string text="";
|
||||
QString text="";
|
||||
for (i=0; i<n; i++) {
|
||||
text += "<b><u>";
|
||||
ex = X509_CRL_get_ext(crl,i);
|
||||
|
||||
@ -53,9 +53,11 @@
|
||||
#define PKI_CRL_H
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <openssl/pem.h>
|
||||
#include "pki_x509.h"
|
||||
#include "x509name.h"
|
||||
#include "asn1time.h"
|
||||
#include "asn1int.h"
|
||||
|
||||
class pki_crl: public pki_base
|
||||
{
|
||||
@ -65,30 +67,29 @@ class pki_crl: public pki_base
|
||||
X509V3_CTX ctx;
|
||||
public:
|
||||
X509_CRL *crl;
|
||||
pki_crl(const string d, pki_x509 *iss);
|
||||
pki_crl(const string fname);
|
||||
pki_crl(const QString d, pki_x509 *iss);
|
||||
pki_crl(const QString fname);
|
||||
pki_crl();
|
||||
/* destructor */
|
||||
~pki_crl();
|
||||
|
||||
void addRevoked(pki_x509 *rev);
|
||||
void addExt(int nid, string value);
|
||||
void write(string fname);
|
||||
void addV3ext(int nid, string exttext);
|
||||
void addExt(int nid, QString value);
|
||||
void write(QString fname);
|
||||
void addV3ext(int nid, const QString &exttext);
|
||||
void sign(pki_key *key);
|
||||
void writeCrl(const string fname, bool pem = true);
|
||||
void writeCrl(const QString fname, bool pem = true);
|
||||
pki_x509 *getIssuer();
|
||||
ASN1_TIME *pki_crl::getDate();
|
||||
x509name getIssuerName();
|
||||
a1time getDate();
|
||||
virtual void fromData(unsigned char *p, int size);
|
||||
virtual unsigned char *toData(int *size);
|
||||
virtual bool compare(pki_base *refcrl);
|
||||
int numRev();
|
||||
string issuerName();
|
||||
X509_NAME *getIssuerX509_NAME();
|
||||
bool verify(pki_key *pkey);
|
||||
long getSerial(int num);
|
||||
ASN1_TIME *getRevDate(int num);
|
||||
string printV3ext();
|
||||
a1int getSerial(int num);
|
||||
a1time getRevDate(int num);
|
||||
QString printV3ext();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -58,10 +58,10 @@ char pki_key::passwd[40]="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
|
||||
void pki_key::init()
|
||||
{
|
||||
ucount = 0;
|
||||
className = "pki_key";
|
||||
class_name = "pki_key";
|
||||
}
|
||||
|
||||
pki_key::pki_key(const string d, void (*cb)(int, int,void *),void *prog, int bits = 1024, int type): pki_base(d)
|
||||
pki_key::pki_key(const QString d, void (*cb)(int, int,void *),void *prog, int bits = 1024, int type): pki_base(d)
|
||||
{
|
||||
init();
|
||||
key = EVP_PKEY_new();
|
||||
@ -94,7 +94,7 @@ pki_key::pki_key(const pki_key *pk)
|
||||
openssl_error();
|
||||
}
|
||||
|
||||
pki_key::pki_key(const string d, int type )
|
||||
pki_key::pki_key(const QString d, int type )
|
||||
:pki_base(d)
|
||||
{
|
||||
init();
|
||||
@ -110,15 +110,14 @@ pki_key::pki_key(EVP_PKEY *pkey)
|
||||
key = pkey;
|
||||
}
|
||||
|
||||
pki_key::pki_key(const string fname, pem_password_cb *cb, int type )
|
||||
pki_key::pki_key(const QString fname, pem_password_cb *cb, int type )
|
||||
:pki_base(fname)
|
||||
{
|
||||
init();
|
||||
pass_info p(XCA_TITLE, p_tr("Please enter the password to decrypt the RSA key."));
|
||||
pass_info p(XCA_TITLE, tr("Please enter the password to decrypt the RSA key."));
|
||||
key = EVP_PKEY_new();
|
||||
key->type = EVP_PKEY_type(type);
|
||||
error = "";
|
||||
FILE *fp = fopen(fname.c_str(), "r");
|
||||
FILE *fp = fopen(fname.latin1(), "r");
|
||||
RSA *rsakey = NULL;
|
||||
if (fp != NULL) {
|
||||
rsakey = PEM_read_RSAPrivateKey(fp, NULL, cb, &p);
|
||||
@ -143,8 +142,8 @@ pki_key::pki_key(const string fname, pem_password_cb *cb, int type )
|
||||
if (!rsakey) {
|
||||
ign_openssl_error();
|
||||
rewind(fp);
|
||||
p.setTitle(p_tr("Password for PKCS#8 private key"));
|
||||
p.setDescription(p_tr("Please enter the password to decrypt the PKCS#8 private key."));
|
||||
p.setTitle(tr("Password for PKCS#8 private key"));
|
||||
p.setDescription(tr("Please enter the password to decrypt the PKCS#8 private key."));
|
||||
CERR("Fallback to PKCS#8 Private key");
|
||||
d2i_PKCS8PrivateKey_fp(fp, &key, cb, &p);
|
||||
}
|
||||
@ -153,14 +152,7 @@ pki_key::pki_key(const string fname, pem_password_cb *cb, int type )
|
||||
openssl_error();
|
||||
CERR("assigning loaded key");
|
||||
}
|
||||
int r = fname.rfind('.');
|
||||
#ifdef WIN32
|
||||
int l = fname.rfind('\\');
|
||||
#else
|
||||
int l = fname.rfind('/');
|
||||
#endif
|
||||
CERR( fname << "r,l: "<< r <<","<< l );
|
||||
setDescription(fname.substr(l+1,r-l-1));
|
||||
setIntName(rmslashdot(fname));
|
||||
openssl_error();
|
||||
}
|
||||
else fopen_error(fname);
|
||||
@ -291,10 +283,10 @@ pki_key::~pki_key()
|
||||
}
|
||||
|
||||
|
||||
void pki_key::writePKCS8(const string fname, pem_password_cb *cb)
|
||||
void pki_key::writePKCS8(const QString fname, pem_password_cb *cb)
|
||||
{
|
||||
pass_info p(XCA_TITLE, p_tr("Please enter the password protecting the PKCS#8 key"));
|
||||
FILE *fp = fopen(fname.c_str(),"w");
|
||||
pass_info p(XCA_TITLE, tr("Please enter the password protecting the PKCS#8 key"));
|
||||
FILE *fp = fopen(fname.latin1(),"w");
|
||||
if (fp != NULL) {
|
||||
if (key){
|
||||
CERR( "writing PKCS8");
|
||||
@ -307,15 +299,15 @@ void pki_key::writePKCS8(const string fname, pem_password_cb *cb)
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void pki_key::writeKey(const string fname, const EVP_CIPHER *enc,
|
||||
void pki_key::writeKey(const QString fname, const EVP_CIPHER *enc,
|
||||
pem_password_cb *cb, bool PEM)
|
||||
{
|
||||
pass_info p(XCA_TITLE, p_tr("Please enter the password protecting the RSA private key"));
|
||||
pass_info p(XCA_TITLE, tr("Please enter the password protecting the RSA private key"));
|
||||
if (isPubKey()) {
|
||||
writePublic(fname, PEM);
|
||||
return;
|
||||
}
|
||||
FILE *fp = fopen(fname.c_str(),"w");
|
||||
FILE *fp = fopen(fname.latin1(),"w");
|
||||
if (fp != NULL) {
|
||||
if (key){
|
||||
CERR("writing Private Key");
|
||||
@ -332,9 +324,9 @@ void pki_key::writeKey(const string fname, const EVP_CIPHER *enc,
|
||||
}
|
||||
|
||||
|
||||
void pki_key::writePublic(const string fname, bool PEM)
|
||||
void pki_key::writePublic(const QString fname, bool PEM)
|
||||
{
|
||||
FILE *fp = fopen(fname.c_str(),"w");
|
||||
FILE *fp = fopen(fname.latin1(),"w");
|
||||
if (fp != NULL) {
|
||||
if (key->type == EVP_PKEY_RSA) {
|
||||
CERR("writing Public Key");
|
||||
@ -350,19 +342,19 @@ void pki_key::writePublic(const string fname, bool PEM)
|
||||
}
|
||||
|
||||
|
||||
string pki_key::length()
|
||||
QString pki_key::length()
|
||||
{
|
||||
char st[64];
|
||||
sprintf(st,"%i bit", EVP_PKEY_size(key) * 8 );
|
||||
openssl_error();
|
||||
string x = st;
|
||||
QString x = st;
|
||||
return x;
|
||||
}
|
||||
|
||||
string pki_key::BN2string(BIGNUM *bn)
|
||||
QString pki_key::BN2QString(BIGNUM *bn)
|
||||
{
|
||||
if (bn == NULL) return "--";
|
||||
string x="";
|
||||
QString x="";
|
||||
char zs[10];
|
||||
int j;
|
||||
int size = BN_num_bytes(bn);
|
||||
@ -377,17 +369,17 @@ string pki_key::BN2string(BIGNUM *bn)
|
||||
return x;
|
||||
}
|
||||
|
||||
string pki_key::modulus() {
|
||||
return BN2string(key->pkey.rsa->n);
|
||||
QString pki_key::modulus() {
|
||||
return BN2QString(key->pkey.rsa->n);
|
||||
}
|
||||
|
||||
string pki_key::pubEx() {
|
||||
return BN2string(key->pkey.rsa->e);
|
||||
QString pki_key::pubEx() {
|
||||
return BN2QString(key->pkey.rsa->e);
|
||||
}
|
||||
|
||||
string pki_key::privEx() {
|
||||
QString pki_key::privEx() {
|
||||
if (isPubKey()) return "Not existent (not a private key)";
|
||||
return BN2string(key->pkey.rsa->d);
|
||||
return BN2QString(key->pkey.rsa->d);
|
||||
}
|
||||
|
||||
bool pki_key::compare(pki_base *ref)
|
||||
|
||||
@ -52,7 +52,7 @@
|
||||
#define PKI_KEY_H
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <qstring.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/pem.h>
|
||||
@ -64,12 +64,13 @@
|
||||
|
||||
class pki_key: public pki_base
|
||||
{
|
||||
|
||||
friend class pki_x509req;
|
||||
friend class pki_x509;
|
||||
friend class pki_crl;
|
||||
protected:
|
||||
EVP_PKEY *key;
|
||||
string BN2string(BIGNUM *bn);
|
||||
QString BN2QString(BIGNUM *bn);
|
||||
int ucount; // usage counter
|
||||
public:
|
||||
static char passwd[40];
|
||||
@ -79,13 +80,13 @@ class pki_key: public pki_base
|
||||
* bits is the keylength in bits
|
||||
* cb a callback for e.g. a progress bar
|
||||
*/
|
||||
pki_key(const string d, void (*cb)(int, int,void *),void *prog,int bits,int type = EVP_PKEY_RSA);
|
||||
pki_key(const QString d, void (*cb)(int, int,void *),void *prog,int bits,int type = EVP_PKEY_RSA);
|
||||
|
||||
/* constructor to load a key from a file
|
||||
* fname = filename
|
||||
* pem_password_cb = password callback function
|
||||
*/
|
||||
pki_key(const string fname, pem_password_cb *cb,int type = EVP_PKEY_RSA);
|
||||
pki_key(const QString fname, pem_password_cb *cb,int type = EVP_PKEY_RSA);
|
||||
|
||||
// copy constructor
|
||||
pki_key::pki_key(const pki_key *pk);
|
||||
@ -98,20 +99,20 @@ class pki_key: public pki_base
|
||||
* size = size of datastruct
|
||||
*/
|
||||
|
||||
pki_key(const string d, int type=EVP_PKEY_RSA);
|
||||
pki_key(const QString d, int type=EVP_PKEY_RSA);
|
||||
pki_key(EVP_PKEY *pkey);
|
||||
void init();
|
||||
void fromData(unsigned char *p, int size);
|
||||
unsigned char *toData(int *size);
|
||||
bool compare(pki_base *ref);
|
||||
string length();
|
||||
string modulus();
|
||||
string pubEx();
|
||||
string privEx();
|
||||
void writeKey(const string fname, const EVP_CIPHER *enc,
|
||||
QString length();
|
||||
QString modulus();
|
||||
QString pubEx();
|
||||
QString privEx();
|
||||
void writeKey(const QString fname, const EVP_CIPHER *enc,
|
||||
pem_password_cb *cb, bool PEM);
|
||||
void writePublic(const string fname, bool PEM);
|
||||
void writePKCS8(const string fname, pem_password_cb *cb);
|
||||
void writePublic(const QString fname, bool PEM);
|
||||
void writePKCS8(const QString fname, pem_password_cb *cb);
|
||||
bool isPrivKey();
|
||||
bool isPubKey();
|
||||
int verify();
|
||||
|
||||
@ -54,10 +54,10 @@
|
||||
#include "exception.h"
|
||||
|
||||
|
||||
pki_pkcs12::pki_pkcs12(const string d, pki_x509 *acert, pki_key *akey, pem_password_cb *cb):
|
||||
pki_pkcs12::pki_pkcs12(const QString d, pki_x509 *acert, pki_key *akey, pem_password_cb *cb):
|
||||
pki_base(d)
|
||||
{
|
||||
className="pki_pkcs12";
|
||||
class_name="pki_pkcs12";
|
||||
key = new pki_key(akey);
|
||||
cert = new pki_x509(acert);
|
||||
certstack = sk_X509_new_null();
|
||||
@ -66,7 +66,7 @@ pki_pkcs12::pki_pkcs12(const string d, pki_x509 *acert, pki_key *akey, pem_passw
|
||||
openssl_error();
|
||||
}
|
||||
|
||||
pki_pkcs12::pki_pkcs12(const string fname, pem_password_cb *cb)
|
||||
pki_pkcs12::pki_pkcs12(const QString fname, pem_password_cb *cb)
|
||||
:pki_base(fname)
|
||||
{
|
||||
FILE *fp;
|
||||
@ -75,10 +75,10 @@ pki_pkcs12::pki_pkcs12(const string fname, pem_password_cb *cb)
|
||||
X509 *mycert;
|
||||
key=NULL; cert=NULL; pkcs12=NULL;
|
||||
passcb = cb;
|
||||
className="pki_pkcs12";
|
||||
class_name="pki_pkcs12";
|
||||
certstack = sk_X509_new_null();
|
||||
pass_info p(XCA_TITLE, p_tr("Please enter the password to decrypt the PKCS#12 file."));
|
||||
fp = fopen(fname.c_str(), "rb");
|
||||
pass_info p(XCA_TITLE, tr("Please enter the password to decrypt the PKCS#12 file."));
|
||||
fp = fopen(fname, "rb");
|
||||
if (fp) {
|
||||
pkcs12 = d2i_PKCS12_fp(fp, NULL);
|
||||
CERR("PK12");
|
||||
@ -93,12 +93,12 @@ pki_pkcs12::pki_pkcs12(const string fname, pem_password_cb *cb)
|
||||
openssl_error();
|
||||
if (mykey) {
|
||||
key = new pki_key(mykey);
|
||||
key->setDescription("pk12-import");
|
||||
key->setIntName("pk12-import");
|
||||
//EVP_PKEY_free(mykey);
|
||||
}
|
||||
if (mycert) {
|
||||
cert = new pki_x509(mycert);
|
||||
cert->setDescription("pk12-import");
|
||||
cert->setIntName("pk12-import");
|
||||
//X509_free(mycert);
|
||||
}
|
||||
}
|
||||
@ -135,12 +135,12 @@ void pki_pkcs12::addCaCert(pki_x509 *ca)
|
||||
openssl_error();
|
||||
}
|
||||
|
||||
void pki_pkcs12::writePKCS12(const string fname)
|
||||
void pki_pkcs12::writePKCS12(const QString fname)
|
||||
{
|
||||
char pass[30];
|
||||
char desc[100];
|
||||
strncpy(desc,getDescription().c_str(),100);
|
||||
pass_info p(XCA_TITLE, p_tr("Please enter the password to encrypt the PKCS#12 file"));
|
||||
strncpy(desc,getIntName(),100);
|
||||
pass_info p(XCA_TITLE, tr("Please enter the password to encrypt the PKCS#12 file"));
|
||||
if (!pkcs12) {
|
||||
if (cert == NULL || key == NULL) {
|
||||
openssl_error("No key or no Cert and no pkcs12....");
|
||||
@ -152,7 +152,7 @@ void pki_pkcs12::writePKCS12(const string fname)
|
||||
openssl_error();
|
||||
CERR("after PKCS12_create....");
|
||||
}
|
||||
FILE *fp = fopen(fname.c_str(),"wb");
|
||||
FILE *fp = fopen(fname,"wb");
|
||||
if (fp != NULL) {
|
||||
CERR("writing PKCS#12");
|
||||
i2d_PKCS12_fp(fp, pkcs12);
|
||||
@ -182,7 +182,7 @@ pki_x509 *pki_pkcs12::getCa(int x) {
|
||||
pki_x509 *cert;
|
||||
cert = new pki_x509(X509_dup(sk_X509_value(certstack, x)));
|
||||
openssl_error();
|
||||
cert->setDescription("pk12-import");
|
||||
cert->setIntName("pk12-import");
|
||||
return cert;
|
||||
}
|
||||
|
||||
|
||||
@ -50,7 +50,6 @@
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/stack.h>
|
||||
#include <openssl/evp.h>
|
||||
@ -76,8 +75,8 @@ class pki_pkcs12: public pki_base
|
||||
pem_password_cb *passcb;
|
||||
public:
|
||||
|
||||
pki_pkcs12(const string d, pki_x509 *acert, pki_key *akey, pem_password_cb *cb);
|
||||
pki_pkcs12(const string fname, pem_password_cb *cb);
|
||||
pki_pkcs12(const QString d, pki_x509 *acert, pki_key *akey, pem_password_cb *cb);
|
||||
pki_pkcs12(const QString fname, pem_password_cb *cb);
|
||||
|
||||
/* destructor */
|
||||
~pki_pkcs12();
|
||||
@ -89,7 +88,7 @@ class pki_pkcs12: public pki_base
|
||||
//bool fromData(unsigned char *p, int size);
|
||||
//unsigned char *toData(int *size);
|
||||
//bool compare(pki_base *ref);
|
||||
void writePKCS12(const string fname);
|
||||
void writePKCS12(const QString fname);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -53,13 +53,13 @@
|
||||
#include "exception.h"
|
||||
|
||||
|
||||
pki_pkcs7::pki_pkcs7(const string d )
|
||||
pki_pkcs7::pki_pkcs7(const QString d )
|
||||
:pki_base(d)
|
||||
{
|
||||
p7 = PKCS7_new();
|
||||
PKCS7_set_type(p7, NID_pkcs7_signed);
|
||||
PKCS7_content_new(p7, NID_pkcs7_data);
|
||||
className = "pki_pkcs7";
|
||||
class_name = "pki_pkcs7";
|
||||
}
|
||||
|
||||
|
||||
@ -68,12 +68,12 @@ pki_pkcs7::~pki_pkcs7()
|
||||
if (p7) PKCS7_free(p7);
|
||||
}
|
||||
|
||||
void pki_pkcs7::encryptFile(pki_x509 *crt, string filename)
|
||||
void pki_pkcs7::encryptFile(pki_x509 *crt, QString filename)
|
||||
{
|
||||
BIO *bio = NULL;
|
||||
STACK_OF(X509) *certstack;
|
||||
if (!crt) return;
|
||||
bio = BIO_new_file(filename.c_str(), "r");
|
||||
bio = BIO_new_file(filename, "r");
|
||||
certstack = sk_X509_new_null();
|
||||
sk_X509_push(certstack, crt->getCert());
|
||||
openssl_error();
|
||||
@ -89,7 +89,7 @@ void pki_pkcs7::signBio(pki_x509 *crt, BIO *bio)
|
||||
STACK_OF(X509) *certstack;
|
||||
if (!crt) return;
|
||||
privkey = crt->getRefKey();
|
||||
if (!privkey) throw errorEx("No private key for signing found", className);
|
||||
if (!privkey) throw errorEx("No private key for signing found", class_name);
|
||||
certstack = sk_X509_new_null();
|
||||
|
||||
pki_x509 *signer = crt->getSigner();
|
||||
@ -108,11 +108,11 @@ void pki_pkcs7::signBio(pki_x509 *crt, BIO *bio)
|
||||
}
|
||||
|
||||
|
||||
void pki_pkcs7::signFile(pki_x509 *crt, string filename)
|
||||
void pki_pkcs7::signFile(pki_x509 *crt, QString filename)
|
||||
{
|
||||
BIO *bio = NULL;
|
||||
if (!crt) return;
|
||||
bio = BIO_new_file(filename.c_str(), "r");
|
||||
bio = BIO_new_file(filename, "r");
|
||||
openssl_error();
|
||||
signBio(crt, bio);
|
||||
BIO_free(bio);
|
||||
@ -129,10 +129,10 @@ void pki_pkcs7::signCert(pki_x509 *crt, pki_x509 *contCert)
|
||||
BIO_free(bio);
|
||||
}
|
||||
|
||||
void pki_pkcs7::writeP7(string fname,bool PEM)
|
||||
void pki_pkcs7::writeP7(QString fname,bool PEM)
|
||||
{
|
||||
FILE *fp;
|
||||
fp = fopen(fname.c_str(),"w");
|
||||
fp = fopen(fname,"w");
|
||||
if (fp != NULL) {
|
||||
if (p7){
|
||||
if (PEM)
|
||||
@ -150,7 +150,7 @@ pki_x509 *pki_pkcs7::getCert(int x) {
|
||||
pki_x509 *cert;
|
||||
cert = new pki_x509(X509_dup(sk_X509_value(getCertStack(), x)));
|
||||
openssl_error();
|
||||
cert->setDescription("pk7-import");
|
||||
cert->setIntName("pk7-import");
|
||||
return cert;
|
||||
}
|
||||
|
||||
@ -160,10 +160,10 @@ int pki_pkcs7::numCert() {
|
||||
return n;
|
||||
}
|
||||
|
||||
void pki_pkcs7::readP7(string fname)
|
||||
void pki_pkcs7::readP7(QString fname)
|
||||
{
|
||||
FILE *fp;
|
||||
fp = fopen(fname.c_str(), "rb");
|
||||
fp = fopen(fname, "rb");
|
||||
if (fp) {
|
||||
p7 = PEM_read_PKCS7(fp, NULL, NULL, NULL);
|
||||
if (!p7) {
|
||||
|
||||
@ -52,7 +52,6 @@
|
||||
#define PKI_PKCS7_H
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "pki_x509.h"
|
||||
|
||||
class pki_pkcs7: public pki_base
|
||||
@ -63,15 +62,15 @@ class pki_pkcs7: public pki_base
|
||||
STACK_OF(X509) *getCertStack();
|
||||
void signBio(pki_x509 *crt, BIO * bio);
|
||||
public:
|
||||
pki_pkcs7(const string d);
|
||||
pki_pkcs7(const QString d);
|
||||
/* destructor */
|
||||
~pki_pkcs7();
|
||||
|
||||
void signFile(pki_x509 *crt, string filename);
|
||||
void signFile(pki_x509 *crt, QString filename);
|
||||
void signCert(pki_x509 *crt, pki_x509 *contCert);
|
||||
void encryptFile(pki_x509 *crt, string filename);
|
||||
void writeP7(string fname,bool PEM);
|
||||
void readP7(string fname);
|
||||
void encryptFile(pki_x509 *crt, QString filename);
|
||||
void writeP7(QString fname,bool PEM);
|
||||
void readP7(QString fname);
|
||||
pki_x509 *getCert(int x);
|
||||
void addCert(pki_x509 *crt);
|
||||
int numCert(); // number of certs;
|
||||
|
||||
@ -90,7 +90,7 @@ pki_temp::pki_temp(const pki_temp *pk)
|
||||
eKeyUse=pk->eKeyUse;
|
||||
}
|
||||
|
||||
pki_temp::pki_temp(const string d, int atype)
|
||||
pki_temp::pki_temp(const QString d, int atype)
|
||||
:pki_base(d)
|
||||
{
|
||||
version=1;
|
||||
|
||||
@ -52,7 +52,6 @@
|
||||
#define PKI_TEMP_H
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "pki_base.h"
|
||||
|
||||
#define tEMPTY 0
|
||||
@ -67,16 +66,16 @@ class pki_temp: public pki_base
|
||||
int version;
|
||||
|
||||
public:
|
||||
string C,P,L,O,OU,CN,EMAIL;
|
||||
string subAltName, issAltName, crlDist;
|
||||
string nsComment, nsBaseUrl, nsRevocationUrl, nsCARevocationUrl, nsRenewalUrl, nsCaPolicyUrl, nsSslServerName;
|
||||
QString C,P,L,O,OU,CN,EMAIL;
|
||||
QString subAltName, issAltName, crlDist;
|
||||
QString nsComment, nsBaseUrl, nsRevocationUrl, nsCARevocationUrl, nsRenewalUrl, nsCaPolicyUrl, nsSslServerName;
|
||||
bool ca, bcCrit, keyUseCrit, eKeyUseCrit, subKey, authKey, subAltCp, issAltCp ;
|
||||
int type, nsCertType, pathLen, validN, validM, keyUse, eKeyUse;
|
||||
|
||||
// methods
|
||||
|
||||
pki_temp(const pki_temp *pk);
|
||||
pki_temp(const string d, int atype=0);
|
||||
pki_temp(const QString d, int atype=0);
|
||||
/* destructor */
|
||||
~pki_temp();
|
||||
void fromData(unsigned char *p, int size);
|
||||
|
||||
@ -85,9 +85,9 @@ pki_x509::pki_x509()
|
||||
openssl_error();
|
||||
}
|
||||
|
||||
pki_x509::pki_x509(const string fname)
|
||||
pki_x509::pki_x509(const QString fname)
|
||||
{
|
||||
FILE *fp = fopen(fname.c_str(),"r");
|
||||
FILE *fp = fopen(fname.latin1(),"r");
|
||||
init();
|
||||
if (fp != NULL) {
|
||||
cert = PEM_read_X509(fp, NULL, NULL, NULL);
|
||||
@ -97,15 +97,7 @@ pki_x509::pki_x509(const string fname)
|
||||
CERR("Fallback to certificate DER");
|
||||
cert = d2i_X509_fp(fp, NULL);
|
||||
}
|
||||
openssl_error();
|
||||
int r = fname.rfind('.');
|
||||
#ifdef WIN32
|
||||
int l = fname.rfind('\\');
|
||||
#else
|
||||
int l = fname.rfind('/');
|
||||
#endif
|
||||
desc = fname.substr(l+1,r-l-1);
|
||||
if (desc == "") desc = fname;
|
||||
setIntName(rmslashdot(fname));
|
||||
openssl_error();
|
||||
}
|
||||
else fopen_error(fname);
|
||||
@ -133,7 +125,7 @@ void pki_x509::init()
|
||||
caTemplate = "";
|
||||
crlDays = 30;
|
||||
lastCrl.now();
|
||||
className = "pki_x509";
|
||||
class_name = "pki_x509";
|
||||
cert = NULL;
|
||||
isrevoked = false;
|
||||
}
|
||||
@ -361,14 +353,12 @@ unsigned char *pki_x509::toData(int *size)
|
||||
return p;
|
||||
}
|
||||
|
||||
void pki_x509::writeCert(const string fname, bool PEM, bool append)
|
||||
void pki_x509::writeCert(const QString fname, bool PEM, bool append)
|
||||
{
|
||||
FILE *fp;
|
||||
if (append)
|
||||
fp = fopen(fname.c_str(),"a");
|
||||
else
|
||||
fp = fopen(fname.c_str(),"w");
|
||||
|
||||
char *_a = "a", *_w="w", *p = _w;
|
||||
if (append) p=_a;
|
||||
fp = fopen(fname.latin1(), p);
|
||||
if (fp != NULL) {
|
||||
if (cert){
|
||||
if (PEM)
|
||||
@ -441,10 +431,10 @@ void pki_x509::setPubKey(pki_key *key)
|
||||
X509_set_pubkey(cert, key->getKey());
|
||||
}
|
||||
|
||||
string pki_x509::fingerprint(const EVP_MD *digest)
|
||||
QString pki_x509::fingerprint(const EVP_MD *digest)
|
||||
{
|
||||
int j;
|
||||
string fp="";
|
||||
QString fp="";
|
||||
char zs[4];
|
||||
unsigned int n;
|
||||
unsigned char md[EVP_MAX_MD_SIZE];
|
||||
@ -500,7 +490,7 @@ void pki_x509::delSigner(pki_x509 *s)
|
||||
psigner = NULL;
|
||||
}
|
||||
|
||||
string pki_x509::printV3ext()
|
||||
QString pki_x509::printV3ext()
|
||||
{
|
||||
#define V3_BUF 100
|
||||
ASN1_OBJECT *obj;
|
||||
@ -508,7 +498,7 @@ string pki_x509::printV3ext()
|
||||
int i, len, n = X509_get_ext_count(cert);
|
||||
char buffer[V3_BUF+1];
|
||||
X509_EXTENSION *ex;
|
||||
string text="";
|
||||
QString text="";
|
||||
for (i=0; i<n; i++) {
|
||||
text += "<b><u>";
|
||||
ex = X509_get_ext(cert,i);
|
||||
@ -632,9 +622,9 @@ int pki_x509::getCrlDays() {return crlDays;}
|
||||
|
||||
void pki_x509::setCrlDays(int s){if (s>0) crlDays = s;}
|
||||
|
||||
string pki_x509::getTemplate(){ return caTemplate; }
|
||||
QString pki_x509::getTemplate(){ return caTemplate; }
|
||||
|
||||
void pki_x509::setTemplate(string s) {if (s.length()>0) caTemplate = s; }
|
||||
void pki_x509::setTemplate(QString s) {if (s.length()>0) caTemplate = s; }
|
||||
|
||||
void pki_x509::setLastCrl(a1time &time)
|
||||
{
|
||||
|
||||
@ -74,18 +74,18 @@ class pki_x509 : public pki_x509super
|
||||
int efftrust;
|
||||
a1int caSerial;
|
||||
int crlDays;
|
||||
string caTemplate;
|
||||
QString caTemplate;
|
||||
X509 *cert;
|
||||
void init();
|
||||
public:
|
||||
pki_x509(X509 *c);
|
||||
pki_x509(const pki_x509 *crt);
|
||||
pki_x509();
|
||||
pki_x509(const string fname);
|
||||
pki_x509(const QString fname);
|
||||
~pki_x509();
|
||||
|
||||
void setSerial(const a1int &serial);
|
||||
a1int pki_x509::getSerial() const;
|
||||
a1int getSerial() const;
|
||||
void setNotBefore(const a1time &a1);
|
||||
void setNotAfter(const a1time &a1);
|
||||
a1time getNotBefore() const;
|
||||
@ -99,14 +99,14 @@ class pki_x509 : public pki_x509super
|
||||
virtual unsigned char *toData(int *size);
|
||||
virtual bool compare(pki_base *refcert);
|
||||
bool canSign();
|
||||
void writeCert(const string fname, bool PEM, bool append = false);
|
||||
void writeCert(const QString fname, bool PEM, bool append = false);
|
||||
bool verify(pki_x509 *signer);
|
||||
pki_key *getPubKey(); // will be created temporarily and must be freed
|
||||
void setPubKey(pki_key *key);
|
||||
pki_x509 *getSigner();
|
||||
void delSigner(pki_x509 *s);
|
||||
string fingerprint(const EVP_MD *digest);
|
||||
string printV3ext();
|
||||
QString fingerprint(const EVP_MD *digest);
|
||||
QString printV3ext();
|
||||
int checkDate();
|
||||
void addV3ext(int nid, const QString exttext);
|
||||
void sign(pki_key *signkey);
|
||||
@ -123,8 +123,8 @@ class pki_x509 : public pki_x509super
|
||||
a1int getIncCaSerial();
|
||||
a1int getCaSerial();
|
||||
void setCaSerial(a1int s);
|
||||
void setTemplate(string s);
|
||||
string getTemplate();
|
||||
void setTemplate(QString s);
|
||||
QString getTemplate();
|
||||
void setCrlDays(int s);
|
||||
int getCrlDays();
|
||||
void setLastCrl(a1time &time);
|
||||
|
||||
@ -57,7 +57,7 @@ pki_x509req::pki_x509req()
|
||||
: pki_x509super()
|
||||
{
|
||||
privkey = NULL;
|
||||
className = "pki_x509req";
|
||||
class_name = "pki_x509req";
|
||||
request = X509_REQ_new();
|
||||
openssl_error();
|
||||
}
|
||||
@ -85,11 +85,11 @@ pki_x509req::~pki_x509req()
|
||||
}
|
||||
|
||||
|
||||
pki_x509req::pki_x509req(const string fname)
|
||||
pki_x509req::pki_x509req(const QString fname)
|
||||
{
|
||||
privkey = NULL;
|
||||
className = "pki_x509req";
|
||||
FILE *fp = fopen(fname.c_str(),"r");
|
||||
class_name = "pki_x509req";
|
||||
FILE *fp = fopen(fname.latin1(),"r");
|
||||
if (fp != NULL) {
|
||||
request = PEM_read_X509_REQ(fp, NULL, NULL, NULL);
|
||||
if (!request) {
|
||||
@ -99,14 +99,7 @@ pki_x509req::pki_x509req(const string fname)
|
||||
request = d2i_X509_REQ_fp(fp, NULL);
|
||||
openssl_error();
|
||||
}
|
||||
int r = fname.rfind('.');
|
||||
#ifdef WIN32
|
||||
int l = fname.rfind('\\');
|
||||
#else
|
||||
int l = fname.rfind('/');
|
||||
#endif
|
||||
desc = fname.substr(l+1,r-l-1);
|
||||
if (desc == "") desc = fname;
|
||||
setIntName(rmslashdot(fname));
|
||||
openssl_error();
|
||||
}
|
||||
else fopen_error(fname);
|
||||
@ -140,9 +133,9 @@ unsigned char *pki_x509req::toData(int *size)
|
||||
return p;
|
||||
}
|
||||
|
||||
void pki_x509req::writeReq(const string fname, bool PEM)
|
||||
void pki_x509req::writeReq(const QString fname, bool PEM)
|
||||
{
|
||||
FILE *fp = fopen(fname.c_str(),"w");
|
||||
FILE *fp = fopen(fname.latin1(),"w");
|
||||
if (fp != NULL) {
|
||||
if (request){
|
||||
if (PEM)
|
||||
|
||||
@ -66,13 +66,13 @@ class pki_x509req : public pki_x509super
|
||||
X509_REQ *request;
|
||||
public:
|
||||
pki_x509req();
|
||||
pki_x509req(const string fname);
|
||||
pki_x509req(const QString fname);
|
||||
~pki_x509req();
|
||||
virtual void fromData(unsigned char *p, int size);
|
||||
virtual unsigned char *toData(int *size);
|
||||
virtual bool compare(pki_base *refreq);
|
||||
x509name getSubject();
|
||||
void writeReq(const string fname, bool PEM);
|
||||
void writeReq(const QString fname, bool PEM);
|
||||
int verify();
|
||||
pki_key *getPubKey();
|
||||
void createReq(pki_key *key, x509name &dist_name);
|
||||
|
||||
@ -65,6 +65,13 @@ x509name::~x509name()
|
||||
X509_NAME_free(xn);
|
||||
}
|
||||
|
||||
void x509name::set(const X509_NAME *n)
|
||||
{
|
||||
X509_NAME_free(xn);
|
||||
xn = X509_NAME_dup((X509_NAME *)n);
|
||||
}
|
||||
|
||||
|
||||
QString x509name::subjectOneLine() const
|
||||
{
|
||||
char *x = X509_NAME_oneline(xn, NULL ,0);
|
||||
|
||||
@ -62,6 +62,7 @@ class x509name
|
||||
x509name();
|
||||
x509name(const X509_NAME *n);
|
||||
~x509name();
|
||||
void set(const X509_NAME *n);
|
||||
QString subjectOneLine() const;
|
||||
QString getEntryByNid(int nid) const;
|
||||
int entryCount() const;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user