aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-03-10 16:16:48 +0100
committerfiaxh <git@mx.ax.lt>2017-03-10 17:29:23 +0100
commit9b8cf706d6b0ff83472af53c31b96c4c2f55f6b7 (patch)
treef31048126f135156da9d98f20cb4254933d9841d /xmpp-vala/src
parent2fe8489d368a371aefbfbe66e74621a8df14cdc2 (diff)
downloaddino-9b8cf706d6b0ff83472af53c31b96c4c2f55f6b7.tar.gz
dino-9b8cf706d6b0ff83472af53c31b96c4c2f55f6b7.zip
Outfactor PGP into pgpme-vala
Diffstat (limited to 'xmpp-vala/src')
-rw-r--r--xmpp-vala/src/core/xmpp_stream.vala16
-rw-r--r--xmpp-vala/src/module/xep/0027_pgp/module.vala113
2 files changed, 40 insertions, 89 deletions
diff --git a/xmpp-vala/src/core/xmpp_stream.vala b/xmpp-vala/src/core/xmpp_stream.vala
index e30a1c9b..5f92113d 100644
--- a/xmpp-vala/src/core/xmpp_stream.vala
+++ b/xmpp-vala/src/core/xmpp_stream.vala
@@ -227,19 +227,19 @@ public class XmppStream {
}
public abstract class XmppStreamFlag {
- internal abstract string get_ns();
- internal abstract string get_id();
+ public abstract string get_ns();
+ public abstract string get_id();
}
public abstract class XmppStreamModule : Object {
- internal abstract void attach(XmppStream stream);
- internal abstract void detach(XmppStream stream);
- internal abstract string get_ns();
- internal abstract string get_id();
+ public abstract void attach(XmppStream stream);
+ public abstract void detach(XmppStream stream);
+ public abstract string get_ns();
+ public abstract string get_id();
}
public abstract class XmppStreamNegotiationModule : XmppStreamModule {
- internal abstract bool mandatory_outstanding(XmppStream stream);
- internal abstract bool negotiation_active(XmppStream stream);
+ public abstract bool mandatory_outstanding(XmppStream stream);
+ public abstract bool negotiation_active(XmppStream stream);
}
}
diff --git a/xmpp-vala/src/module/xep/0027_pgp/module.vala b/xmpp-vala/src/module/xep/0027_pgp/module.vala
index fee6b9e4..63177f4d 100644
--- a/xmpp-vala/src/module/xep/0027_pgp/module.vala
+++ b/xmpp-vala/src/module/xep/0027_pgp/module.vala
@@ -12,8 +12,6 @@ namespace Xmpp.Xep.Pgp {
public signal void received_jid_key_id(XmppStream stream, string jid, string key_id);
- private static Object mutex = new Object();
-
private string? signed_status;
private string? own_key_id;
@@ -99,95 +97,48 @@ namespace Xmpp.Xep.Pgp {
}
private static string? gpg_encrypt(string plain, string[] key_ids) {
- lock (mutex) {
- GPG.Context context;
- GPGError.ErrorCode e = GPG.Context.Context(out context); if (e != GPGError.ErrorCode.NO_ERROR) return null;
- context.set_armor(true);
-
- Key[] keys = new Key[key_ids.length];
+ GPG.Key[] keys = new GPG.Key[key_ids.length];
+ string encr;
+ try {
for (int i = 0; i < key_ids.length; i++) {
- Key key;
- e = context.get_key(key_ids[i], out key, false); if (e != GPGError.ErrorCode.NO_ERROR) return null;
- keys[i] = key;
+ keys[i] = GPGHelper.get_public_key(key_ids[i]);
}
-
- GPG.Data plain_data;
- e = GPG.Data.create_from_memory(out plain_data, plain.data, false);
- GPG.Data enc_data;
- e = GPG.Data.create(out enc_data);
- e = context.op_encrypt(keys, GPG.EncryptFlags.ALWAYS_TRUST, plain_data, enc_data);
-
- string encr = get_string_from_data(enc_data);
- int encryption_start = encr.index_of("\n\n") + 2;
- return encr.substring(encryption_start, encr.length - "\n-----END PGP MESSAGE-----".length - encryption_start);
+ encr = GPGHelper.encrypt_armor(plain, keys, GPG.EncryptFlags.ALWAYS_TRUST);
+ } catch (Error e) {
+ return null;
}
+ int encryption_start = encr.index_of("\n\n") + 2;
+ return encr.substring(encryption_start, encr.length - "\n-----END PGP MESSAGE-----".length - encryption_start);
}
private static string? gpg_decrypt(string enc) {
- lock (mutex) {
- string armor = "-----BEGIN PGP MESSAGE-----\n\n" + enc + "\n-----END PGP MESSAGE-----";
-
- GPG.Data enc_data;
- GPGError.ErrorCode e = GPG.Data.create_from_memory(out enc_data, armor.data, false); if (e != GPGError.ErrorCode.NO_ERROR) return null;
- GPG.Data dec_data;
- e = GPG.Data.create(out dec_data); if (e != GPGError.ErrorCode.NO_ERROR) return null;
- GPG.Context context;
- e = GPG.Context.Context(out context); if (e != GPGError.ErrorCode.NO_ERROR) return null;
- e = context.op_decrypt(enc_data, dec_data); if (e != GPGError.ErrorCode.NO_ERROR) return null;
-
- string plain = get_string_from_data(dec_data);
- return plain;
- }
+ string armor = "-----BEGIN PGP MESSAGE-----\n\n" + enc + "\n-----END PGP MESSAGE-----";
+ string? decr = null;
+ try {
+ decr = GPGHelper.decrypt(armor);
+ } catch (Error e) { }
+ return decr;
}
private static string? gpg_verify(string sig, string signed_text) {
- lock (mutex) {
- string armor = "-----BEGIN PGP MESSAGE-----\n\n" + sig + "\n-----END PGP MESSAGE-----";
-
- GPG.Data sig_data;
- GPGError.ErrorCode e = GPG.Data.create_from_memory(out sig_data, armor.data, false); if (e != GPGError.ErrorCode.NO_ERROR) return null;
- GPG.Data plain_data;
- e = GPG.Data.create(out plain_data); if (e != GPGError.ErrorCode.NO_ERROR) return null;
- GPG.Context context;
- e = GPG.Context.Context(out context); if (e != GPGError.ErrorCode.NO_ERROR) return null;
- e = context.op_verify(sig_data, null, plain_data); if (e != GPGError.ErrorCode.NO_ERROR) return null;
- GPG.VerifyResult* verify_res = context.op_verify_result();
- if (verify_res == null || verify_res.signatures == null) return null;
- return verify_res.signatures.fpr;
+ string armor = "-----BEGIN PGP MESSAGE-----\n\n" + sig + "\n-----END PGP MESSAGE-----";
+ string? sign_key = null;
+ try {
+ sign_key = GPGHelper.get_sign_key(armor, signed_text);
+ } catch (Error e) { }
+ return sign_key;
+ }
+
+ private static string? gpg_sign(string str) {
+ string signed;
+ try {
+ signed = GPGHelper.sign(str, GPG.SigMode.CLEAR);
+ } catch (Error e) {
+ return null;
}
- }
-
- private static string? gpg_sign(string status) {
- lock (mutex) {
- GPG.Data status_data;
- GPGError.ErrorCode e = GPG.Data.create_from_memory(out status_data, status.data, false); if (e != GPGError.ErrorCode.NO_ERROR) return null;
- GPG.Data signed_data;
- e = GPG.Data.create(out signed_data); if (e != GPGError.ErrorCode.NO_ERROR) return null;
- GPG.Context context;
- e = GPG.Context.Context(out context); if (e != GPGError.ErrorCode.NO_ERROR) return null;
- e = context.op_sign(status_data, signed_data, GPG.SigMode.CLEAR); if (e != GPGError.ErrorCode.NO_ERROR) return null;
-
- string signed = get_string_from_data(signed_data);
- int signature_start = signed.index_of("-----BEGIN PGP SIGNATURE-----");
- signature_start = signed.index_of("\n\n", signature_start) + 2;
- return signed.substring(signature_start, signed.length - "\n-----END PGP SIGNATURE-----".length - signature_start);
- }
- }
-
- private static string get_string_from_data(GPG.Data data) {
- data.seek(0);
- uint8[] buf = new uint8[256];
- ssize_t? len = null;
- string res = "";
- do {
- len = data.read(buf);
- if (len > 0) {
- string part = (string) buf;
- part = part.substring(0, (long) len);
- res += part;
- }
- } while (len > 0);
- return res;
+ int signature_start = signed.index_of("-----BEGIN PGP SIGNATURE-----");
+ signature_start = signed.index_of("\n\n", signature_start) + 2;
+ return signed.substring(signature_start, signed.length - "\n-----END PGP SIGNATURE-----".length - signature_start);
}
}