mirror of
https://github.com/chris2511/xca.git
synced 2026-09-14 11:06:19 +05:00
support exporting requests and certs as openssl config file
This commit is contained in:
parent
ca3129d07e
commit
7155c65ecb
@ -1,4 +1,5 @@
|
||||
|
||||
* Export requests or certificates as openssl config file
|
||||
* Support building with EC disabled
|
||||
* Close bug [3091576] Private key export is always PKCS#8 encoded
|
||||
* Feature Request [3058196] Autoload database
|
||||
|
||||
@ -647,6 +647,8 @@ void db_x509::showContextMenu(QContextMenuEvent *e, const QModelIndex &index)
|
||||
scardItems += subExport->addAction(tr("Other token"),
|
||||
this, SLOT(toOtherToken()));
|
||||
subExport->addAction(tr("Template"), this, SLOT(toTemplate()));
|
||||
subExport->addAction(tr("OpenSSL config"),
|
||||
this, SLOT(toOpenssl()));
|
||||
|
||||
menu->addAction(tr("Delete"), this, SLOT(delete_ask()));
|
||||
scardItems += menu->addAction(
|
||||
|
||||
@ -185,6 +185,8 @@ void db_x509req::showContextMenu(QContextMenuEvent *e, const QModelIndex &index)
|
||||
SLOT(pem2clipboard()));
|
||||
subExport->addAction(tr("File"), this, SLOT(store()));
|
||||
subExport->addAction(tr("Template"), this, SLOT(toTemplate()));
|
||||
subExport->addAction(tr("OpenSSL config"), this,
|
||||
SLOT(toOpenssl()));
|
||||
menu->addAction(tr("Delete"), this, SLOT(delete_ask()));
|
||||
|
||||
subExport->setEnabled(!req->isSpki());
|
||||
|
||||
@ -90,6 +90,21 @@ void db_x509super::extractPubkey()
|
||||
key->getMsg(pki_base::msg_import).arg(pki->getIntName()));
|
||||
}
|
||||
|
||||
void db_x509super::toOpenssl() const
|
||||
{
|
||||
pki_x509super *pki = static_cast<pki_x509super*>(currentIdx.internalPointer());
|
||||
QString fn = mainwin->getPath() + QDir::separator() +
|
||||
pki->getUnderlinedName() + ".conf";
|
||||
QString fname = QFileDialog::getSaveFileName(mainwin,
|
||||
tr("Save as OpenSSL config"), fn,
|
||||
tr("Config files ( *.conf *.cnf);; All files ( * )"));
|
||||
if (fname.isEmpty())
|
||||
return;
|
||||
fname = QDir::convertSeparators(fname);
|
||||
mainwin->setPath(fname.mid(0, fname.lastIndexOf(QRegExp("[/\\\\]")) ));
|
||||
pki->opensslConf(fname);
|
||||
}
|
||||
|
||||
void db_x509super::toTemplate()
|
||||
{
|
||||
pki_x509super *pki = static_cast<pki_x509super*>(currentIdx.internalPointer());
|
||||
|
||||
@ -32,8 +32,9 @@ class db_x509super: public db_x509name
|
||||
public slots:
|
||||
void delKey(pki_key *delkey);
|
||||
void newKey(pki_key *newKey);
|
||||
void toTemplate();
|
||||
void extractPubkey();
|
||||
void toTemplate();
|
||||
void toOpenssl() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
26
lib/oid.cpp
26
lib/oid.cpp
@ -14,6 +14,8 @@
|
||||
#include "func.h"
|
||||
#include "oid.h"
|
||||
|
||||
int first_additional_oid = 0;
|
||||
|
||||
/* reads additional OIDs from a file: oid, sn, ln */
|
||||
static void readOIDs(QString fname)
|
||||
{
|
||||
@ -31,7 +33,8 @@ static void readOIDs(QString fname)
|
||||
line++;
|
||||
pb = buff;
|
||||
pb = pb.trimmed();
|
||||
if (pb.startsWith('#') || pb.size() == 0) continue;
|
||||
if (pb.startsWith('#') || pb.size() == 0)
|
||||
continue;
|
||||
sl.clear();
|
||||
sl = pb.split(':');
|
||||
if (sl.count() != 3) {
|
||||
@ -40,11 +43,21 @@ static void readOIDs(QString fname)
|
||||
QString::number(line) );
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
OBJ_create(sl[0].trimmed().toAscii(),
|
||||
sl[1].trimmed().toAscii(),
|
||||
sl[2].trimmed().toAscii());
|
||||
} else {
|
||||
QByteArray oid = sl[0].trimmed().toAscii();
|
||||
QByteArray sn = sl[1].trimmed().toAscii();
|
||||
QByteArray ln = sl[2].trimmed().toAscii();
|
||||
|
||||
int nid = OBJ_txt2nid(oid.constData());
|
||||
if ((nid != NID_undef) && (sn != OBJ_nid2sn(nid))) {
|
||||
printf("OID: '%s' SN differs: '%s' '%s'\n",
|
||||
oid.constData(), sn.constData(),
|
||||
OBJ_nid2sn(nid));
|
||||
}
|
||||
if ((nid == NID_undef) || (sn != OBJ_nid2sn(nid))) {
|
||||
OBJ_create(oid.constData(), sn.constData(),
|
||||
ln.constData());
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
@ -55,6 +68,7 @@ void initOIDs()
|
||||
QString oids = QString(QDir::separator()) + "oids.txt";
|
||||
QString dir = getPrefix();
|
||||
|
||||
first_additional_oid = OBJ_new_nid(0);
|
||||
readOIDs(dir + oids);
|
||||
#ifndef WIN32
|
||||
#if !defined(Q_WS_MAC)
|
||||
|
||||
@ -11,6 +11,8 @@
|
||||
class QString;
|
||||
#include <QtCore/QList>
|
||||
|
||||
extern int first_additional_oid;
|
||||
|
||||
typedef QList<int> NIDlist;
|
||||
/* reads additional OIDs from a file: oid, sn, ln */
|
||||
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
#include "func.h"
|
||||
#include "oid.h"
|
||||
#include "pki_x509super.h"
|
||||
|
||||
pki_x509super::pki_x509super(const QString name)
|
||||
@ -59,6 +61,60 @@ QVariant pki_x509super::column_data(int id)
|
||||
return pki_x509name::column_data(id);
|
||||
}
|
||||
|
||||
static QString oid_sect()
|
||||
{
|
||||
QString ret;
|
||||
int i, max = OBJ_new_nid(0);
|
||||
|
||||
for (i=first_additional_oid; i < max; i++) {
|
||||
const char *sn = OBJ_nid2sn(i);
|
||||
if (!sn)
|
||||
break;
|
||||
ret += QString("%1 = %2\n").
|
||||
arg(OBJ_nid2sn(i)).
|
||||
arg(OBJ_obj2QString(OBJ_nid2obj(i), 1));
|
||||
}
|
||||
|
||||
if (!ret.isEmpty()) {
|
||||
ret = QString("oid_section = xca_oids\n\n"
|
||||
"[ xca_oids ]\n") + ret + "\n";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void pki_x509super::opensslConf(QString fname)
|
||||
{
|
||||
QString extensions;
|
||||
extList el = getV3ext();
|
||||
x509name n = getSubject();
|
||||
el.genGenericConf(&extensions);
|
||||
|
||||
QString name = n.taggedValues();
|
||||
QString final = oid_sect();
|
||||
final += QString("[ req ]\n"
|
||||
"default_bits = 1024\n"
|
||||
"default_keyfile = privkey.pem\n"
|
||||
"distinguished_name = xca_dn\n"
|
||||
"x509_extensions = xca_extensions\n"
|
||||
"req_extensions = xca_extensions\n"
|
||||
"string_mask = MASK:0x%3\n"
|
||||
"utf8 = yes\n"
|
||||
"prompt = no\n\n"
|
||||
"[ xca_dn ]\n"
|
||||
"%1\n"
|
||||
"[ xca_extensions ]\n"
|
||||
"%2").arg(name).arg(extensions).
|
||||
arg(ASN1_STRING_get_default_mask(), 0, 16);
|
||||
|
||||
FILE *fp = fopen(QString2filename(fname),"w");
|
||||
if (fp == NULL) {
|
||||
fopen_error(fname);
|
||||
return;
|
||||
}
|
||||
QByteArray ba = final.toUtf8();
|
||||
fwrite(ba.constData(), 1, ba.size(), fp);
|
||||
fclose(fp);
|
||||
}
|
||||
// Start class pki_x509name
|
||||
|
||||
pki_x509name::pki_x509name(const QString name)
|
||||
|
||||
@ -54,6 +54,7 @@ class pki_x509super : public pki_x509name
|
||||
void setRefKey(pki_key *ref);
|
||||
void delRefKey(pki_key *ref);
|
||||
QVariant column_data(int id);
|
||||
void opensslConf(QString fname);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user