mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
autodetect and load any type of PEM files
either with -P option or menu Import->PEM file
This commit is contained in:
parent
ecb593ab01
commit
85e91b4391
@ -1,3 +1,4 @@
|
|||||||
|
* autodetect and load any type of PEM files
|
||||||
* fix version number in exported *.xca template
|
* fix version number in exported *.xca template
|
||||||
* fix import of older XCA templates
|
* fix import of older XCA templates
|
||||||
* add support for predefined templates as there was in 0.5.1
|
* add support for predefined templates as there was in 0.5.1
|
||||||
|
|||||||
2
img/.gitignore
vendored
Normal file
2
img/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
img.rc
|
||||||
|
imgres.cpp
|
||||||
@ -22,7 +22,8 @@
|
|||||||
#define D2I_CLASHT(f, t, a, PP, s) f(t,a,(unsigned char **)PP,s)
|
#define D2I_CLASHT(f, t, a, PP, s) f(t,a,(unsigned char **)PP,s)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CCHAR(x) ((const char *)(x).toAscii().constData())
|
//#define CCHAR(x) ((const char *)(x).toAscii().constData())
|
||||||
|
#define CCHAR(x) qPrintable(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TRACE printf("File: "__FILE__" Func: %s Line: %d\n",__func__, __LINE__);
|
#define TRACE printf("File: "__FILE__" Func: %s Line: %d\n",__func__, __LINE__);
|
||||||
|
|||||||
@ -224,3 +224,87 @@ load_db::load_db()
|
|||||||
filter = QObject::tr("XCA Databases ( *.xdb );;") + filter;
|
filter = QObject::tr("XCA Databases ( *.xdb );;") + filter;
|
||||||
caption = QObject::tr("Open XCA Database");
|
caption = QObject::tr("Open XCA Database");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* General PEM loader */
|
||||||
|
static load_base *getload(QString text)
|
||||||
|
{
|
||||||
|
int pos;
|
||||||
|
#define D5 "-----"
|
||||||
|
pos = text.indexOf(D5 "BEGIN ");
|
||||||
|
if (pos <0)
|
||||||
|
return NULL;
|
||||||
|
text = text.remove(0, pos + 11);
|
||||||
|
printf("Text B: %s\n", CCHAR(text));
|
||||||
|
if (text.startsWith(PEM_STRING_X509_OLD D5) ||
|
||||||
|
text.startsWith(PEM_STRING_X509 D5) ||
|
||||||
|
text.startsWith(PEM_STRING_X509_TRUSTED D5))
|
||||||
|
return new load_cert();
|
||||||
|
|
||||||
|
if (text.startsWith(PEM_STRING_PKCS7 D5))
|
||||||
|
return new load_pkcs7();
|
||||||
|
|
||||||
|
if (text.startsWith(PEM_STRING_X509_REQ_OLD D5) ||
|
||||||
|
text.startsWith(PEM_STRING_X509_REQ D5))
|
||||||
|
return new load_req();
|
||||||
|
|
||||||
|
if (text.startsWith(PEM_STRING_X509_CRL D5))
|
||||||
|
return new load_crl();
|
||||||
|
|
||||||
|
if (text.startsWith(PEM_STRING_EVP_PKEY D5) ||
|
||||||
|
text.startsWith(PEM_STRING_PUBLIC D5) ||
|
||||||
|
text.startsWith(PEM_STRING_RSA D5) ||
|
||||||
|
text.startsWith(PEM_STRING_RSA_PUBLIC D5) ||
|
||||||
|
text.startsWith(PEM_STRING_DSA D5) ||
|
||||||
|
text.startsWith(PEM_STRING_DSA_PUBLIC D5) ||
|
||||||
|
text.startsWith(PEM_STRING_PKCS8 D5) ||
|
||||||
|
text.startsWith(PEM_STRING_PKCS8INF D5))
|
||||||
|
return new load_key();
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
load_pem::load_pem()
|
||||||
|
:load_base()
|
||||||
|
{
|
||||||
|
filter = QObject::tr("Pem files ( *.pem );;") + filter;
|
||||||
|
caption = QObject::tr("Load PEM encoded file");
|
||||||
|
}
|
||||||
|
|
||||||
|
pki_base * load_pem::loadItem(QString fname)
|
||||||
|
{
|
||||||
|
char buf[100];
|
||||||
|
int len;
|
||||||
|
FILE * fp;
|
||||||
|
QString text;
|
||||||
|
pki_base *item = NULL;
|
||||||
|
load_base *lb = NULL;
|
||||||
|
|
||||||
|
try {
|
||||||
|
fp = fopen(CCHAR(fname), "r");
|
||||||
|
if (!fp)
|
||||||
|
throw errorEx(QObject::tr("File open error: ") + fname);
|
||||||
|
len = fread(buf, 1, 99, fp);
|
||||||
|
fclose(fp);
|
||||||
|
if (len < 11)
|
||||||
|
throw errorEx(QObject::tr("File corrupted: ") + fname);
|
||||||
|
buf[len] = '\0';
|
||||||
|
text = buf;
|
||||||
|
lb = getload(text);
|
||||||
|
if (!lb)
|
||||||
|
throw errorEx(QObject::tr("Unknown PEM file: ") + fname);
|
||||||
|
printf("CAPTION = '%s' for %s \n", CCHAR(lb->caption),
|
||||||
|
CCHAR(fname));
|
||||||
|
item = lb->loadItem(fname);
|
||||||
|
delete lb;
|
||||||
|
printf("LOAD success: %s\n", CCHAR(fname));
|
||||||
|
}
|
||||||
|
catch (errorEx &err) {
|
||||||
|
MainWindow::Error(err);
|
||||||
|
if (item)
|
||||||
|
delete item;
|
||||||
|
item = NULL;
|
||||||
|
if (lb)
|
||||||
|
delete lb;
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
};
|
||||||
|
|||||||
@ -119,4 +119,11 @@ class load_db: public load_base
|
|||||||
load_db();
|
load_db();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class load_pem: public load_base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
load_pem();
|
||||||
|
pki_base * loadItem(QString s);
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -70,6 +70,7 @@ fprintf(stderr, " -v show version information and exit\n"
|
|||||||
" -7 expect all following non-option arguments to be PKCS#7 files\n"
|
" -7 expect all following non-option arguments to be PKCS#7 files\n"
|
||||||
" -l expect all following non-option arguments to be Revocation lists\n"
|
" -l expect all following non-option arguments to be Revocation lists\n"
|
||||||
" -t expect all following non-option arguments to be XCA templates\n"
|
" -t expect all following non-option arguments to be XCA templates\n"
|
||||||
|
" -P expect all following non-option arguments to be PEM encoded 'thingies'\n"
|
||||||
" -d expect the following argument to be the database name to use\n"
|
" -d expect the following argument to be the database name to use\n"
|
||||||
" -x Exit after processing all commandline options\n\n");
|
" -x Exit after processing all commandline options\n\n");
|
||||||
|
|
||||||
|
|||||||
@ -90,6 +90,8 @@ void MainWindow::init_menu()
|
|||||||
SLOT(on_BNimportTemp_clicked()) );
|
SLOT(on_BNimportTemp_clicked()) );
|
||||||
import->addAction(tr("Revocation list"), this,
|
import->addAction(tr("Revocation list"), this,
|
||||||
SLOT(on_BNimportCrl_clicked()) );
|
SLOT(on_BNimportCrl_clicked()) );
|
||||||
|
import->addAction(tr("PEM file"), this,
|
||||||
|
SLOT(loadPem()) );
|
||||||
|
|
||||||
help = menuBar()->addMenu(tr("&Help") );
|
help = menuBar()->addMenu(tr("&Help") );
|
||||||
help->addAction(tr("&Content"), this, SLOT(help()), Qt::Key_F1 );
|
help->addAction(tr("&Content"), this, SLOT(help()), Qt::Key_F1 );
|
||||||
|
|||||||
@ -195,8 +195,7 @@ void MainWindow::read_cmdline()
|
|||||||
pki_base *item = NULL;
|
pki_base *item = NULL;
|
||||||
load_base *lb = NULL;
|
load_base *lb = NULL;
|
||||||
exitApp = 0;
|
exitApp = 0;
|
||||||
ImportMulti *dlgi = NULL;
|
ImportMulti *dlgi = new ImportMulti(this);
|
||||||
dlgi = new ImportMulti(this);
|
|
||||||
while (cnt < qApp->argc()) {
|
while (cnt < qApp->argc()) {
|
||||||
arg = qApp->argv()[cnt];
|
arg = qApp->argv()[cnt];
|
||||||
if (arg[0] == '-') { // option
|
if (arg[0] == '-') { // option
|
||||||
@ -211,6 +210,7 @@ void MainWindow::read_cmdline()
|
|||||||
case '7' : lb = new load_pkcs7(); break;
|
case '7' : lb = new load_pkcs7(); break;
|
||||||
case 'l' : lb = new load_crl(); break;
|
case 'l' : lb = new load_crl(); break;
|
||||||
case 't' : lb = new load_temp(); break;
|
case 't' : lb = new load_temp(); break;
|
||||||
|
case 'P' : lb = new load_pem(); break;
|
||||||
case 'd' : force_load=1; break;
|
case 'd' : force_load=1; break;
|
||||||
case 'v' : fprintf(stderr, XCA_TITLE " Version " VER "\n");
|
case 'v' : fprintf(stderr, XCA_TITLE " Version " VER "\n");
|
||||||
opt=0; exitApp=1; break;
|
opt=0; exitApp=1; break;
|
||||||
@ -249,6 +249,12 @@ void MainWindow::read_cmdline()
|
|||||||
delete dlgi;
|
delete dlgi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::loadPem()
|
||||||
|
{
|
||||||
|
load_pem l;
|
||||||
|
if (keys)
|
||||||
|
keys->load_default(l);
|
||||||
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -66,7 +66,6 @@
|
|||||||
|
|
||||||
#define DBFILE "xca.xdb"
|
#define DBFILE "xca.xdb"
|
||||||
|
|
||||||
|
|
||||||
class db_x509;
|
class db_x509;
|
||||||
|
|
||||||
class MainWindow: public QMainWindow, public Ui::MainWindow
|
class MainWindow: public QMainWindow, public Ui::MainWindow
|
||||||
@ -127,6 +126,7 @@ class MainWindow: public QMainWindow, public Ui::MainWindow
|
|||||||
void help();
|
void help();
|
||||||
void import_dbdump();
|
void import_dbdump();
|
||||||
void undelete();
|
void undelete();
|
||||||
|
void loadPem();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_keyView_doubleClicked(const QModelIndex &m);
|
void on_keyView_doubleClicked(const QModelIndex &m);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user