2017-03-12 01:28:23 +00:00
|
|
|
using Gee;
|
|
|
|
using Signal;
|
2018-01-12 20:03:09 +00:00
|
|
|
using Xmpp;
|
2017-03-12 01:28:23 +00:00
|
|
|
|
|
|
|
namespace Dino.Plugins.Omemo {
|
|
|
|
|
|
|
|
public class Bundle {
|
|
|
|
private StanzaNode? node;
|
|
|
|
|
|
|
|
public Bundle(StanzaNode? node) {
|
|
|
|
this.node = node;
|
2017-04-18 15:55:20 +00:00
|
|
|
assert(Plugin.ensure_context());
|
2017-03-12 01:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int32 signed_pre_key_id { owned get {
|
|
|
|
if (node == null) return -1;
|
2017-04-18 15:55:20 +00:00
|
|
|
string? id = ((!)node).get_deep_attribute("signedPreKeyPublic", "signedPreKeyId");
|
2017-03-12 01:28:23 +00:00
|
|
|
if (id == null) return -1;
|
2017-04-18 15:55:20 +00:00
|
|
|
return int.parse((!)id);
|
2017-03-12 01:28:23 +00:00
|
|
|
}}
|
|
|
|
|
|
|
|
public ECPublicKey? signed_pre_key { owned get {
|
|
|
|
if (node == null) return null;
|
2017-04-18 15:55:20 +00:00
|
|
|
string? key = ((!)node).get_deep_string_content("signedPreKeyPublic");
|
2017-03-12 01:28:23 +00:00
|
|
|
if (key == null) return null;
|
|
|
|
try {
|
2017-04-18 15:55:20 +00:00
|
|
|
return Plugin.get_context().decode_public_key(Base64.decode((!)key));
|
2017-03-12 01:28:23 +00:00
|
|
|
} catch (Error e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
|
|
|
|
public uint8[]? signed_pre_key_signature { owned get {
|
|
|
|
if (node == null) return null;
|
2017-04-18 15:55:20 +00:00
|
|
|
string? sig = ((!)node).get_deep_string_content("signedPreKeySignature");
|
2017-03-12 01:28:23 +00:00
|
|
|
if (sig == null) return null;
|
2017-04-18 15:55:20 +00:00
|
|
|
return Base64.decode((!)sig);
|
2017-03-12 01:28:23 +00:00
|
|
|
}}
|
|
|
|
|
|
|
|
public ECPublicKey? identity_key { owned get {
|
|
|
|
if (node == null) return null;
|
2017-04-18 15:55:20 +00:00
|
|
|
string? key = ((!)node).get_deep_string_content("identityKey");
|
2017-03-12 01:28:23 +00:00
|
|
|
if (key == null) return null;
|
|
|
|
try {
|
2017-04-18 15:55:20 +00:00
|
|
|
return Plugin.get_context().decode_public_key(Base64.decode((!)key));
|
2017-03-12 01:28:23 +00:00
|
|
|
} catch (Error e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
|
|
|
|
public ArrayList<PreKey> pre_keys { owned get {
|
|
|
|
ArrayList<PreKey> list = new ArrayList<PreKey>();
|
2017-04-18 15:55:20 +00:00
|
|
|
if (node == null || ((!)node).get_subnode("prekeys") == null) return list;
|
|
|
|
((!)node).get_deep_subnodes("prekeys", "preKeyPublic")
|
|
|
|
.filter((node) => ((!)node).get_attribute("preKeyId") != null)
|
2017-03-12 01:28:23 +00:00
|
|
|
.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 {
|
2017-04-18 15:55:20 +00:00
|
|
|
return Plugin.get_context().decode_public_key(Base64.decode((!)key));
|
2017-03-12 01:28:23 +00:00
|
|
|
} catch (Error e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|