Example #1
0
void
initialise()
{
   auto settings = config();
   sJitEnabled = settings->jit.enabled;

   // Initalise cpu!
   initialiseMemory();
   espresso::initialiseInstructionSet();
   interpreter::initialise();

   if (sJitEnabled) {
      auto backend = new jit::BinrecBackend {
         settings->jit.codeCacheSizeMB * 1024 * 1024,
         settings->jit.dataCacheSizeMB * 1024 * 1024
      };
      backend->setOptFlags(settings->jit.optimisationFlags);
      backend->setVerifyEnabled(settings->jit.verify, settings->jit.verifyAddress);
      jit::setBackend(backend);
   }

   sStartupTime = std::chrono::steady_clock::now();
}
Example #2
0
int MainWindow::init_database()
{
	int ret = 2;
	fprintf(stderr, "Opening database: %s\n", QString2filename(dbfile));
	keys = NULL; reqs = NULL; certs = NULL; temps = NULL; crls = NULL;

	certView->setRootIsDecorated(db_x509::treeview);

	try {
		ret = initPass();
		if (ret == 2)
			return ret;
		keys = new db_key(dbfile, this);
		reqs = new db_x509req(dbfile, this);
		certs = new db_x509(dbfile, this);
		temps = new db_temp(dbfile, this);
		crls = new db_crl(dbfile, this);
	}
	catch (errorEx &err) {
		Error(err);
		dbfile = "";
		return ret;
	}

	mandatory_dn = "";
	string_opt = QString("MASK:0x2002");
	ASN1_STRING_set_default_mask_asc((char*)CCHAR(string_opt));
	hashBox::resetDefault();
	pkcs11path = getDefaultPkcs11Lib();
	workingdir = QDir::currentPath();
	setOptFlags((QString()));
	try {
		pkcs11_lib p(pkcs11path);
	} catch (errorEx &e) {
		pkcs11path = QString();
	}

	connect( keys, SIGNAL(newKey(pki_key *)),
		certs, SLOT(newKey(pki_key *)) );
	connect( keys, SIGNAL(delKey(pki_key *)),
		certs, SLOT(delKey(pki_key *)) );
	connect( keys, SIGNAL(newKey(pki_key *)),
		reqs, SLOT(newKey(pki_key *)) );
	connect( keys, SIGNAL(delKey(pki_key *)),
		reqs, SLOT(delKey(pki_key *)) );

	connect( certs, SIGNAL(connNewX509(NewX509 *)), this,
		SLOT(connNewX509(NewX509 *)) );
	connect( reqs, SIGNAL(connNewX509(NewX509 *)), this,
		SLOT(connNewX509(NewX509 *)) );

	connect( reqs, SIGNAL(newCert(pki_x509req *)),
		certs, SLOT(newCert(pki_x509req *)) );
	connect( temps, SIGNAL(newCert(pki_temp *)),
		certs, SLOT(newCert(pki_temp *)) );
	connect( temps, SIGNAL(newReq(pki_temp *)),
		reqs, SLOT(newItem(pki_temp *)) );

	keyView->setIconSize(pki_evp::icon[0]->size());
	reqView->setIconSize(pki_x509req::icon[0]->size());
	certView->setIconSize(pki_x509::icon[0]->size());
	tempView->setIconSize(pki_temp::icon->size());
	crlView->setIconSize(pki_crl::icon->size());

	keyView->setModel(keys);
	reqView->setModel(reqs);
	certView->setModel(certs);
	tempView->setModel(temps);
	crlView->setModel(crls);

	try {
		db mydb(dbfile);
		char *p;
		if (!mydb.find(setting, "workingdir")) {
			if ((p = (char *)mydb.load(NULL))) {
				workingdir = p;
				free(p);
			}
		}
		mydb.first();
		if (!mydb.find(setting, "pkcs11path")) {
			if ((p = (char *)mydb.load(NULL))) {
				pkcs11path = p;
				free(p);
			}
		}
		mydb.first();
		if (!mydb.find(setting, "default_hash")) {
			if ((p = (char *)mydb.load(NULL))) {
				hashBox::setDefault(p);
				free(p);
			}
		}
		mydb.first();
		if (!mydb.find(setting, "mandatory_dn")) {
			if ((p = (char *)mydb.load(NULL))) {
				mandatory_dn = p;
				free(p);
			}
		}
		// what a stupid idea....
		mydb.first();
		if (!mydb.find(setting, "multiple_key_use")) {
			mydb.erase();
		}
		mydb.first();
		if (!mydb.find(setting, "string_opt")) {
			if ((p = (char *)mydb.load(NULL))) {
				string_opt = p;
				free(p);
			}
		}
		mydb.first();
		if (!mydb.find(setting, "suppress")) {
			if ((p = (char *)mydb.load(NULL))) {
				QString x = p;
				free(p);
				if (x == "1")
					pki_base::suppress_messages = 1;
			}
		}
		mydb.first();
		if (!mydb.find(setting, "optionflags")) {
			if ((p = (char *)mydb.load(NULL))) {
				setOptFlags((QString(p)));
				free(p);
			}
		}
		ASN1_STRING_set_default_mask_asc((char*)CCHAR(string_opt));
		mydb.first();
		if (!mydb.find(setting, "mw_geometry")) {
			db_header_t h;
			if ((p = (char *)mydb.load(&h))) {
				if (h.version == 1) {
					QByteArray ba;
					ba = QByteArray::fromRawData(p, h.len);
					int w, h, i;
					w = db::intFromData(ba);
					h = db::intFromData(ba);
					i = db::intFromData(ba);
					resize(w,h);
					if (i != -1)
						tabView->setCurrentIndex(i);
					}
				free(p);
			}
		}
	} catch (errorEx &err) {
		Error(err);
		return ret;
	}
	setWindowTitle(tr(XCA_TITLE));
	setItemEnabled(true);
	if (pki_evp::passwd.isNull())
		QMessageBox::information(this, XCA_TITLE,
			tr("Using or exporting private keys will not be possible without providing the correct password"));

	dbindex->setText(tr("Database") + ":" + dbfile);
	load_engine();
	return ret;
}
Example #3
0
int MainWindow::init_database()
{
	int ret = 2;
	qDebug("Opening database: %s", QString2filename(dbfile));
	keys = NULL; reqs = NULL; certs = NULL; temps = NULL; crls = NULL;

	Entropy::seed_rng();
	certView->setRootIsDecorated(db_x509::treeview);

	try {
		ret = initPass();
		if (ret == 2)
			return ret;
		keys = new db_key(dbfile, this);
		reqs = new db_x509req(dbfile, this);
		certs = new db_x509(dbfile, this);
		temps = new db_temp(dbfile, this);
		crls = new db_crl(dbfile, this);
		certs->updateAfterDbLoad();
	}
	catch (errorEx &err) {
		Error(err);
		dbfile = "";
		return ret;
	}

	searchEdit->setText("");
	searchEdit->show();
	statusBar()->addWidget(searchEdit, 1);
	mandatory_dn = "";
	explicit_dn = explicit_dn_default;

	string_opt = QString("MASK:0x2002");
	ASN1_STRING_set_default_mask_asc((char*)CCHAR(string_opt));
	hashBox::resetDefault();
	pkcs11path = QString();
	workingdir = QDir::currentPath();
	setOptFlags((QString()));

	connect( keys, SIGNAL(newKey(pki_key *)),
		certs, SLOT(newKey(pki_key *)) );
	connect( keys, SIGNAL(delKey(pki_key *)),
		certs, SLOT(delKey(pki_key *)) );
	connect( keys, SIGNAL(newKey(pki_key *)),
		reqs, SLOT(newKey(pki_key *)) );
	connect( keys, SIGNAL(delKey(pki_key *)),
		reqs, SLOT(delKey(pki_key *)) );

	connect( certs, SIGNAL(connNewX509(NewX509 *)), this,
		SLOT(connNewX509(NewX509 *)) );
	connect( reqs, SIGNAL(connNewX509(NewX509 *)), this,
		SLOT(connNewX509(NewX509 *)) );

	connect( reqs, SIGNAL(newCert(pki_x509req *)),
		certs, SLOT(newCert(pki_x509req *)) );
	connect( tempView, SIGNAL(newCert(pki_temp *)),
		certs, SLOT(newCert(pki_temp *)) );
	connect( tempView, SIGNAL(newReq(pki_temp *)),
		reqs, SLOT(newItem(pki_temp *)) );

	keyView->setIconSize(pki_evp::icon[0]->size());
	reqView->setIconSize(pki_x509req::icon[0]->size());
	certView->setIconSize(pki_x509::icon[0]->size());
	tempView->setIconSize(pki_temp::icon->size());
	crlView->setIconSize(pki_crl::icon->size());

	keyView->setModel(keys);
	reqView->setModel(reqs);
	certView->setModel(certs);
	tempView->setModel(temps);
	crlView->setModel(crls);
	try {
		db mydb(dbfile);

		while (mydb.find(setting, QString()) == 0) {
			QString key;
			db_header_t head;
			char *p = (char *)mydb.load(&head);
			if (!p) {
				if (mydb.next())
					break;
				continue;
			}
			key = head.name;

			if (key == "workingdir")
				workingdir = p;
			else if (key == "pkcs11path")
				pkcs11path = p;
			else if (key == "default_hash")
				hashBox::setDefault(p);
			else if (key == "mandatory_dn")
				mandatory_dn = p;
			else if (key == "explicit_dn")
				explicit_dn = p;
			/* what a stupid idea.... */
			else if (key == "multiple_key_use")
				mydb.erase();
			else if (key == "string_opt")
				string_opt = p;
			else if (key == "suppress")
				mydb.erase();
			else if (key == "optionflags1")
				setOptFlags((QString(p)));
			/* Different optionflags, since setOptFlags()
			 * does an abort() for unknown flags in
			 * older versions.   *Another stupid idea*
			 * This is for backward compatibility
			 */
			else if (key == "optionflags")
				setOptFlags_old((QString(p)));
			else if (key == "defaultkey")
				NewKey::setDefault((QString(p)));
			else if (key == "mw_geometry")
				set_geometry(p, &head);
			free(p);
			if (mydb.next())
				break;
		}
	} catch (errorEx &err) {
		Error(err);
		return ret;
	}
	ASN1_STRING_set_default_mask_asc((char*)CCHAR(string_opt));
	if (explicit_dn.isEmpty())
		explicit_dn = explicit_dn_default;
	setWindowTitle(tr(XCA_TITLE));
	setItemEnabled(true);
	if (pki_evp::passwd.isNull())
		XCA_INFO(tr("Using or exporting private keys will not be possible without providing the correct password"));

	dbindex->setText(tr("Database") + ": " + dbfile);
	load_engine();
	return ret;
}