コード例 #1
0
	PGPKeySelectionDialog::PGPKeySelectionDialog (const QString& label,
			PGPKeySelectionDialog::Type type,
			const QCA::PGPKey& focusKey,
			QWidget *parent)
	: QDialog (parent)
	{
		Ui_.setupUi (this);
		Ui_.LabelText_->setText (label);

		switch (type)
		{
		case TPrivate:
			Keys_ = CryptoManager::Instance ().GetPrivateKeys ();
			break;
		case TPublic:
			Keys_ = CryptoManager::Instance ().GetPublicKeys ();
			break;
		}

		const auto& focusArr = !focusKey.isNull () ? focusKey.toArray () : QByteArray ();
		for (const auto& key : Keys_)
		{
			Ui_.KeyCombo_->addItem (key.primaryUserId () + " (" + key.keyId () + ")");
			if (key.toArray () == focusArr)
				Ui_.KeyCombo_->setCurrentIndex (Ui_.KeyCombo_->count () - 1);
		}
	}
コード例 #2
0
ファイル: cryptomanager.cpp プロジェクト: AlexWMF/leechcraft
	void CryptoManager::AssociatePrivateKey (IAccount *acc, const QCA::PGPKey& key) const
	{
		QSettings settings { QCoreApplication::organizationName (),
				QCoreApplication::applicationName () + "_Azoth" };
		settings.beginGroup ("PrivateKeys");
		if (key.isNull ())
			settings.remove (acc->GetAccountID ());
		else
			settings.setValue (acc->GetAccountID (), key.keyId ());
		settings.endGroup ();
	}
コード例 #3
0
ファイル: pgpmanager.cpp プロジェクト: ForNeVeR/leechcraft
	bool PgpManager::IsValidSignature (const QCA::PGPKey& pubkey,
			const QByteArray& message, const QByteArray& signature)
	{
		if (pubkey.isNull ())
		{
			warning (QString ("Cannot encrypt: public key is null"));
			return false;
		}

		QCA::OpenPGP pgp;
		QCA::SecureMessageKey key;
		QCA::SecureMessage msg (&pgp);
		key.setPGPPublicKey (pubkey);
		msg.setSigner (key);
		msg.setFormat (QCA::SecureMessage::Binary);
		msg.startVerify (WrapPGP (signature, PGPType::Signature).toUtf8 ());
		msg.update (message);
		msg.end ();
		msg.waitForFinished ();

		if (msg.verifySuccess ())
			return true;
		else
		{
			info (QString ("Invalid signature: %1").arg (msg.errorCode ()));
			return false;
		}
	}
コード例 #4
0
ファイル: pgpmanager.cpp プロジェクト: ForNeVeR/leechcraft
	QByteArray PgpManager::EncryptBody (const QCA::PGPKey& pubkey, const QByteArray& body)
	{
		if (pubkey.isNull ())
		{
			warning ("Cannot encrypt: public key is null");
			throw GPGExceptions::NullPubkey {};
		}

		QCA::SecureMessageKey msgKey;
		msgKey.setPGPPublicKey (pubkey);
		QCA::OpenPGP pgp;
		QCA::SecureMessage msg (&pgp);
		msg.setRecipient (msgKey);
		msg.setFormat (QCA::SecureMessage::Ascii);
		msg.startEncrypt ();
		msg.update (body);
		msg.end ();
		msg.waitForFinished ();

		if (!msg.success ())
		{
			info (QString { "Error encrypting: %1 (%2)." }
						.arg (msg.errorCode ())
						.arg (msg.diagnosticText ()));
			throw GPGExceptions::Encryption { msg.errorCode (), msg.diagnosticText () };
		}

		return msg.read ();
	}