Permalink
Browse files

Split OMEMO plug-in into files, various fixes

  • Loading branch information...
mar-v-in committed Mar 12, 2017
1 parent 7e1ecb3 commit a9ea0e9f87e71c60bc570066525d3e3634fbdcc0
View
@@ -5,3 +5,4 @@ Makefile
*.iml
.idea
.sqlite3
gschemas.compiled
View
@@ -4,7 +4,6 @@ include(${VALA_USE_FILE})
set(LIBDINO_PACKAGES
gee-0.8
gio-2.0
glib-2.0
gtk+-3.0
gmodule-2.0
@@ -1,12 +1,5 @@
namespace Dino.Plugins {
public errordomain Error {
NOT_SUPPORTED,
UNEXPECTED_TYPE,
NO_REGISTRATION_FUNCTION,
FAILED
}
private class Info : Object {
public Module module;
public Type gtype;
@@ -26,24 +19,24 @@ public class Loader : Object {
public RootInterface load(string name, Dino.Application app) throws Error {
if (Module.supported () == false) {
throw new Error.NOT_SUPPORTED ("Plugins are not supported");
throw new Error (-1, 0, "Plugins are not supported");
}
Module module = Module.open ("plugins/" + name, ModuleFlags.BIND_LAZY);
if (module == null) {
throw new Error.FAILED (Module.error ());
throw new Error (-1, 1, Module.error ());
}
void* function;
module.symbol ("register_plugin", out function);
if (function == null) {
throw new Error.NO_REGISTRATION_FUNCTION ("register_plugin () not found");
throw new Error (-1, 2, "register_plugin () not found");
}
RegisterPluginFunction register_plugin = (RegisterPluginFunction) function;
Type type = register_plugin (module);
if (type.is_a (typeof (RootInterface)) == false) {
throw new Error.UNEXPECTED_TYPE ("Unexpected type");
throw new Error (-1, 3, "Unexpected type");
}
Info info = new Plugins.Info (type, (owned) module);
View
@@ -10,7 +10,7 @@ void main(string[] args) {
foreach(string plugin in new string[]{"omemo", "openpgp"}) {
try {
loader.load(plugin, app);
} catch (Plugins.Error e) {
} catch (Error e) {
print(@"Error loading plugin $plugin: $(e.message)\n");
}
}
@@ -14,10 +14,20 @@ pkg_check_modules(OMEMO REQUIRED ${OMEMO_PACKAGES})
vala_precompile(OMEMO_VALA_C
SOURCES
src/plugin.vala
src/module.vala
src/manager.vala
src/account_settings_entry.vala
src/account_settings_widget.vala
src/bundle.vala
src/database.vala
src/encrypt_status.vala
src/encryption_list_entry.vala
src/manager.vala
src/message_flag.vala
src/plugin.vala
src/pre_key_store.vala
src/register_plugin.vala
src/session_store.vala
src/signed_pre_key_store.vala
src/stream_module.vala
CUSTOM_VAPIS
${CMAKE_BINARY_DIR}/exports/signal-protocol.vapi
${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi
@@ -0,0 +1,23 @@
namespace Dino.Plugins.Omemo {
public class AccountSettingsEntry : Plugins.AccountSettingsEntry {
private Plugin plugin;
public AccountSettingsEntry(Plugin plugin) {
this.plugin = plugin;
}
public override string id { get {
return "omemo_identity_key";
}}
public override string name { get {
return "OMEMO";
}}
public override Plugins.AccountSettingsWidget get_widget() {
return new AccountSettingWidget(plugin);
}
}
}
@@ -0,0 +1,63 @@
using Gtk;
using Dino.Entities;
namespace Dino.Plugins.Omemo {
public class AccountSettingWidget : Plugins.AccountSettingsWidget, Box {
private Plugin plugin;
private Label fingerprint;
private Account account;
public AccountSettingWidget(Plugin plugin) {
this.plugin = plugin;
fingerprint = new Label("...");
fingerprint.xalign = 0;
Border border = new Button().get_style_context().get_padding(StateFlags.NORMAL);
fingerprint.set_padding(border.left + 1, border.top + 1);
fingerprint.visible = true;
pack_start(fingerprint);
Button btn = new Button();
btn.image = new Image.from_icon_name("view-list-symbolic", IconSize.BUTTON);
btn.relief = ReliefStyle.NONE;
btn.visible = true;
btn.valign = Align.CENTER;
btn.clicked.connect(() => { activated(); });
pack_start(btn, false);
}
public void set_account(Account account) {
this.account = account;
try {
Qlite.Row? row = plugin.db.identity.row_with(plugin.db.identity.account_id, account.id);
if (row == null) {
fingerprint.set_markup(@"Own fingerprint\n<span font='8'>Will be generated on first connect</span>");
} else {
uint8[] arr = Base64.decode(row[plugin.db.identity.identity_key_public_base64]);
arr = arr[1:arr.length];
string res = "";
foreach (uint8 i in arr) {
string s = i.to_string("%x");
if (s.length == 1) s = "0" + s;
res = res + s;
if ((res.length % 9) == 8) {
if (res.length == 35) {
res += "\n";
} else {
res += " ";
}
}
}
fingerprint.set_markup(@"Own fingerprint\n<span font_family='monospace' font='8'>$res</span>");
}
} catch (Qlite.DatabaseError e) {
fingerprint.set_markup(@"Own fingerprint\n<span font='8'>Database error</span>");
}
}
public void deactivate() {
}
}
}
@@ -0,0 +1,87 @@
using Gee;
using Signal;
using Xmpp.Core;
namespace Dino.Plugins.Omemo {
public class Bundle {
private StanzaNode? node;
public Bundle(StanzaNode? node) {
this.node = node;
}
public int32 signed_pre_key_id { owned get {
if (node == null) return -1;
string id = node.get_deep_attribute("signedPreKeyPublic", "signedPreKeyId");
if (id == null) return -1;
return int.parse(id);
}}
public ECPublicKey? signed_pre_key { owned get {
if (node == null) return null;
string? key = node.get_deep_string_content("signedPreKeyPublic");
if (key == null) return null;
try {
return Plugin.context.decode_public_key(Base64.decode(key));
} catch (Error e) {
return null;
}
}}
public uint8[]? signed_pre_key_signature { owned get {
if (node == null) return null;
string? sig = node.get_deep_string_content("signedPreKeySignature");
if (sig == null) return null;
return Base64.decode(sig);
}}
public ECPublicKey? identity_key { owned get {
if (node == null) return null;
string? key = node.get_deep_string_content("identityKey");
if (key == null) return null;
try {
return Plugin.context.decode_public_key(Base64.decode(key));
} catch (Error e) {
return null;
}
}}
public ArrayList<PreKey> pre_keys { owned get {
ArrayList<PreKey> list = new ArrayList<PreKey>();
if (node == null || node.get_subnode("prekeys") == null) return list;
node.get_deep_subnodes("prekeys", "preKeyPublic")
.filter((node) => node.get_attribute("preKeyId") != null)
.map<PreKey>(PreKey.create)
.foreach((key) => list.add(key));
return list;
}}
public class PreKey {
private StanzaNode node;
public static PreKey create(owned StanzaNode node) {
return new PreKey(node);
}
public PreKey(StanzaNode node) {
this.node = node;
}
public int32 key_id { owned get {
return int.parse(node.get_attribute("preKeyId") ?? "-1");
}}
public ECPublicKey? key { owned get {
string? key = node.get_string_content();
if (key == null) return null;
try {
return Plugin.context.decode_public_key(Base64.decode(key));
} catch (Error e) {
return null;
}
}}
}
}
}
@@ -4,7 +4,7 @@ using Qlite;
using Dino.Entities;
namespace Dino.Omemo {
namespace Dino.Plugins.Omemo {
public class Database : Qlite.Database {
private const int VERSION = 0;
@@ -63,7 +63,7 @@ public class Database : Qlite.Database {
public PreKeyTable pre_key { get; private set; }
public SessionTable session { get; private set; }
public Database(string fileName) {
public Database(string fileName) throws DatabaseError {
base(fileName, VERSION);
identity = new IdentityTable(this);
signed_pre_key = new SignedPreKeyTable(this);
@@ -0,0 +1,17 @@
namespace Dino.Plugins.Omemo {
public class EncryptStatus {
public bool encrypted { get; internal set; }
public int other_devices { get; internal set; }
public int other_success { get; internal set; }
public int other_lost { get; internal set; }
public int other_unknown { get; internal set; }
public int other_failure { get; internal set; }
public int own_devices { get; internal set; }
public int own_success { get; internal set; }
public int own_lost { get; internal set; }
public int own_unknown { get; internal set; }
public int own_failure { get; internal set; }
}
}
@@ -0,0 +1,23 @@
namespace Dino.Plugins.Omemo {
public class EncryptionListEntry : Plugins.EncryptionListEntry, Object {
private Plugin plugin;
public EncryptionListEntry(Plugin plugin) {
this.plugin = plugin;
}
public Entities.Encryption encryption { get {
return Entities.Encryption.OMEMO;
}}
public string name { get {
return "OMEMO";
}}
public bool can_encrypt(Entities.Conversation conversation) {
return Manager.get_instance(plugin.app.stream_interaction).can_encrypt(conversation);
}
}
}
Oops, something went wrong.

0 comments on commit a9ea0e9

Please sign in to comment.