mirror of
https://github.com/chris2511/xca.git
synced 2026-09-14 11:06:19 +05:00
This patchset adds: - configure.mac now looks for qmake, backs up xcode project, uses xca.pro to generate a new one, generates a different local.h - mac-package.sh generates a standalone .app bundle for distribution using deployqt from trolltech labs, packages up manual, COPYRIGHT, etc into a .dmg - mac packaging niceties in the qmake project - mac icon file - usability fixes for OS X: - look for user configured oids and such in ~/Library/Preferences/xca if it exists - look for original ones in app bundle/Contents/Resources (it tried to do this before...) - more robust code for getting bundle location (less likely to be broken by Apple in OS revisions) - start browsing for files in ~/Documents - fix wildcards on mac so files without extensions will be opened - fix save behavior for .xdb files so that it's hard to get one that doesn't end in .xdb, as this causes difficulty w/Qt Notes: - one of the compilation fixes was in the new revocation data function that replaced the old macros... I didn't have time to verify that my fix doesn't break when used with 0.9.8. - QStringToAsn1() is clearly incorrect but I haven't yet determined what callers expect, so I just called it out in a comment and did not yet fix it - I added some code that I haven't tested on Windows because I thought it might be a nice function to have there too. I have not added anything to call that function, however, since I don't currently have a machine I can test on :). The code is clearly marked in comments.
169 lines
4.8 KiB
C++
169 lines
4.8 KiB
C++
/* vi: set sw=4 ts=4:
|
|
*
|
|
* Copyright (C) 2001 - 2007 Christian Hohnstaedt.
|
|
*
|
|
* All rights reserved.
|
|
*/
|
|
|
|
|
|
#include "MainWindow.h"
|
|
#include "Options.h"
|
|
#include "lib/load_obj.h"
|
|
#include "lib/pass_info.h"
|
|
#include "ui_Options.h"
|
|
#include "widgets/hashBox.h"
|
|
#include <qapplication.h>
|
|
#include <qmenubar.h>
|
|
#include <qmessagebox.h>
|
|
|
|
void MainWindow::init_menu()
|
|
{
|
|
QMenu *file, *help, *import;
|
|
|
|
file = menuBar()->addMenu(tr("&File"));
|
|
file->addAction(tr("New &DataBase"), this,
|
|
SLOT(new_database()), Qt::CTRL+Qt::Key_N );
|
|
file->addAction(tr("Open &DataBase"), this,
|
|
SLOT(load_database()), Qt::CTRL+Qt::Key_L );
|
|
acList += file->addAction(tr("&Close DataBase"), this,
|
|
SLOT(close_database()), Qt::CTRL+Qt::Key_C );
|
|
acList += file->addAction(tr("&Dump DataBase"), this,
|
|
SLOT(dump_database()), Qt::CTRL+Qt::Key_D );
|
|
acList += file->addAction(tr("&Import old db_dump"), this,
|
|
SLOT(import_dbdump()), Qt::CTRL+Qt::Key_I );
|
|
acList += file->addAction(tr("&Undelete items"), this,
|
|
SLOT(undelete()), Qt::CTRL+Qt::Key_U );
|
|
file->addSeparator();
|
|
acList += file->addAction(tr("Options"), this, SLOT(setOptions()) );
|
|
file->addSeparator();
|
|
file->addAction(tr("E&xit"), qApp, SLOT(quit()), Qt::ALT+Qt::Key_F4 );
|
|
|
|
import = menuBar()->addMenu(tr("I&mport"));
|
|
import->addAction(tr("Keys"), this,
|
|
SLOT(on_BNimportKey_clicked()) );
|
|
import->addAction(tr("Requests"), this,
|
|
SLOT(on_BNimportReq_clicked()) );
|
|
import->addAction(tr("Certificates"), this,
|
|
SLOT(on_BNimportCert_clicked()) );
|
|
import->addAction(tr("PKCS#12"), this,
|
|
SLOT(on_BNimportPKCS12_clicked()) );
|
|
import->addAction(tr("PKCS#7"), this,
|
|
SLOT(on_BNimportPKCS7_clicked()) );
|
|
import->addAction(tr("Template"), this,
|
|
SLOT(on_BNimportTemp_clicked()) );
|
|
import->addAction(tr("Revocation list"), this,
|
|
SLOT(on_BNimportCrl_clicked()) );
|
|
import->addAction(tr("PEM file"), this,
|
|
SLOT(loadPem()) );
|
|
import->addAction(tr("paste PEM file"), this,
|
|
SLOT(pastePem()) );
|
|
|
|
|
|
help = menuBar()->addMenu(tr("&Help") );
|
|
help->addAction(tr("&Content"), this, SLOT(help()), Qt::Key_F1 );
|
|
help->addAction(tr("&About"), this, SLOT(about()) );
|
|
help->addAction(tr("Donations"), this, SLOT(donations()) );
|
|
wdList += import;
|
|
}
|
|
|
|
void MainWindow::new_database()
|
|
{
|
|
load_db l;
|
|
QString selectedFilter;
|
|
QString fname = QFileDialog::getSaveFileName(this, l.caption, homedir,
|
|
l.filter, &selectedFilter, QFileDialog::DontConfirmOverwrite);
|
|
|
|
if (fname.isEmpty())
|
|
return;
|
|
|
|
close_database();
|
|
homedir = fname.mid(0, fname.lastIndexOf(QDir::separator()) );
|
|
// make sure that, if the 3 letter extension was left selected in Qt's OS X file open dialog,
|
|
// the filename actually ends with that extension. Otherwise usability breaks in jarring ways.
|
|
dbfile = getFullFilename(fname,selectedFilter);
|
|
init_database();
|
|
}
|
|
|
|
void MainWindow::load_database()
|
|
{
|
|
load_db l;
|
|
QString fname = QFileDialog::getOpenFileName(this, l.caption, homedir,
|
|
l.filter);
|
|
|
|
if (fname.isEmpty())
|
|
return;
|
|
|
|
close_database();
|
|
homedir = fname.mid(0, fname.lastIndexOf(QDir::separator()) );
|
|
dbfile = fname;
|
|
init_database();
|
|
}
|
|
|
|
void MainWindow::import_dbdump()
|
|
{
|
|
extern int read_dump(const char *, db_base **, char *, int);
|
|
char buf[50];
|
|
|
|
db_base *dbl[] = { keys, reqs, certs, temps, crls };
|
|
if (!keys)
|
|
return;
|
|
QString pass;
|
|
QString file = QFileDialog::getOpenFileName(this, tr(XCA_TITLE), homedir,
|
|
#if defined(Q_WS_MAC)
|
|
tr("Database dump ( *.dump );;All files ( * )"));
|
|
#else
|
|
tr("Database dump ( *.dump );;All files ( *.* )"));
|
|
#endif
|
|
|
|
if (file.isEmpty())
|
|
return;
|
|
|
|
pass_info p(tr("Import password"),
|
|
tr("Please enter the password of the old database"), this);
|
|
if (passRead(buf, 50, 0, &p) <0)
|
|
return;
|
|
pass = buf;
|
|
try {
|
|
read_dump(CCHAR(file), dbl, buf, 50);
|
|
//printf("MD5:%s, r:%s\n", CCHAR(pki_key::md5passwd(CCHAR(pass))),buf);
|
|
if (pki_key::md5passwd(CCHAR(pass)) != buf) {
|
|
int ret = QMessageBox::warning(this, tr(XCA_TITLE),
|
|
tr("Password verification error. Ignore keys ?"),
|
|
tr("Import anyway"), tr("Cancel"));
|
|
if (ret)
|
|
return;
|
|
}
|
|
pki_key::setOldPasswd(CCHAR(pass));
|
|
read_dump(CCHAR(file), dbl, NULL, 0);
|
|
pki_key::eraseOldPasswd();
|
|
} catch (errorEx &err) {
|
|
Error(err);
|
|
}
|
|
}
|
|
|
|
void MainWindow::setOptions()
|
|
{
|
|
Options *opt = new Options(this);
|
|
|
|
opt->setStringOpt(string_opt);
|
|
if (!opt->exec())
|
|
return;
|
|
|
|
QString alg = opt->hashAlgo->currentHashName();
|
|
db mydb(dbfile);
|
|
mydb.set((const unsigned char *)CCHAR(alg), alg.length()+1, 1,
|
|
setting, "default_hash");
|
|
hashBox::setDefault(alg);
|
|
|
|
mandatory_dn = opt->getDnString();
|
|
mydb.set((const unsigned char *)CCHAR(mandatory_dn),
|
|
mandatory_dn.length()+1, 1, setting, "mandatory_dn");
|
|
|
|
if (opt->getStringOpt() != string_opt) {
|
|
string_opt = opt->getStringOpt();
|
|
ASN1_STRING_set_default_mask_asc((char *)CCHAR(string_opt));
|
|
mydb.set((const unsigned char *)CCHAR(string_opt),
|
|
string_opt.length()+1, 1, setting, "string_opt");
|
|
}
|
|
}
|