summaryrefslogtreecommitdiff
path: root/libs/libaxolotl/src/fingerprint.c
diff options
context:
space:
mode:
Diffstat (limited to 'libs/libaxolotl/src/fingerprint.c')
-rw-r--r--libs/libaxolotl/src/fingerprint.c450
1 files changed, 323 insertions, 127 deletions
diff --git a/libs/libaxolotl/src/fingerprint.c b/libs/libaxolotl/src/fingerprint.c
index 42827825cc..1058e90571 100644
--- a/libs/libaxolotl/src/fingerprint.c
+++ b/libs/libaxolotl/src/fingerprint.c
@@ -5,9 +5,10 @@
#include "FingerprintProtocol.pb-c.h"
#include "signal_protocol_internal.h"
+#include "vpool.h"
-#define VERSION 0
-#define SHA512_DIGEST_LENGTH 64
+#define FINGERPRINT_VERSION 0
+#define FINGERPRINT_LENGTH 30
#define MAX(a,b) (((a)>(b))?(a):(b))
@@ -31,26 +32,44 @@ struct scannable_fingerprint
signal_type_base base;
uint32_t version;
char *local_stable_identifier;
- ec_public_key *local_identity_key;
+ signal_buffer *local_fingerprint;
char *remote_stable_identifier;
- ec_public_key *remote_identity_key;
+ signal_buffer *remote_fingerprint;
};
struct fingerprint_generator
{
int iterations;
+ int scannable_version;
signal_context *global_context;
};
-static int fingerprint_generator_create_display_string(fingerprint_generator *generator, char **display_string,
- const char *local_stable_identifier, ec_public_key *identity_key);
+static int fingerprint_generator_get_logical_key_bytes(signal_buffer **key_bytes,
+ const ec_public_key_list *unsorted_key_list);
-int fingerprint_generator_create(fingerprint_generator **generator, int iterations, signal_context *global_context)
+static int fingerprint_generator_create_for_impl(fingerprint_generator *generator,
+ const char *local_stable_identifier, const signal_buffer *local_identity_buffer,
+ const char *remote_stable_identifier, const signal_buffer *remote_identity_buffer,
+ fingerprint **fingerprint_val);
+
+static int fingerprint_generator_get_fingerprint(fingerprint_generator *generator, signal_buffer **fingerprint_buffer,
+ const char *stable_identifier, const signal_buffer *identity_buffer);
+
+static int fingerprint_generator_create_display_string(fingerprint_generator *generator,
+ char **display_string, signal_buffer *fingerprint_buffer);
+
+int fingerprint_generator_create(fingerprint_generator **generator,
+ int iterations, int scannable_version,
+ signal_context *global_context)
{
fingerprint_generator *result_generator;
assert(global_context);
+ if(scannable_version < 0 || scannable_version > 1) {
+ return SG_ERR_INVAL;
+ }
+
result_generator = malloc(sizeof(fingerprint_generator));
if(!result_generator) {
return SG_ERR_NOMEM;
@@ -58,6 +77,7 @@ int fingerprint_generator_create(fingerprint_generator **generator, int iteratio
memset(result_generator, 0, sizeof(fingerprint_generator));
result_generator->iterations = iterations;
+ result_generator->scannable_version = scannable_version;
result_generator->global_context = global_context;
*generator = result_generator;
@@ -65,25 +85,99 @@ int fingerprint_generator_create(fingerprint_generator **generator, int iteratio
}
int fingerprint_generator_create_for(fingerprint_generator *generator,
- const char *local_stable_identifier, ec_public_key *local_identity_key,
- const char *remote_stable_identifier, ec_public_key *remote_identity_key,
+ const char *local_stable_identifier, const ec_public_key *local_identity_key,
+ const char *remote_stable_identifier, const ec_public_key *remote_identity_key,
+ fingerprint **fingerprint_val)
+{
+ int result = 0;
+ signal_buffer *local_key_buffer = 0;
+ signal_buffer *remote_key_buffer = 0;
+
+ result = ec_public_key_serialize(&local_key_buffer, local_identity_key);
+ if(result < 0) {
+ goto complete;
+ }
+
+ result = ec_public_key_serialize(&remote_key_buffer, remote_identity_key);
+ if(result < 0) {
+ goto complete;
+ }
+
+ result = fingerprint_generator_create_for_impl(generator,
+ local_stable_identifier, local_key_buffer,
+ remote_stable_identifier, remote_key_buffer,
+ fingerprint_val);
+
+complete:
+ signal_buffer_free(local_key_buffer);
+ signal_buffer_free(remote_key_buffer);
+ return result;
+}
+
+int fingerprint_generator_create_for_list(fingerprint_generator *generator,
+ const char *local_stable_identifier, const ec_public_key_list *local_identity_key_list,
+ const char *remote_stable_identifier, const ec_public_key_list *remote_identity_key_list,
+ fingerprint **fingerprint_val)
+{
+ int result = 0;
+ signal_buffer *local_key_buffer = 0;
+ signal_buffer *remote_key_buffer = 0;
+
+ result = fingerprint_generator_get_logical_key_bytes(&local_key_buffer, local_identity_key_list);
+ if(result < 0) {
+ goto complete;
+ }
+
+ result = fingerprint_generator_get_logical_key_bytes(&remote_key_buffer, remote_identity_key_list);
+ if(result < 0) {
+ goto complete;
+ }
+
+ result = fingerprint_generator_create_for_impl(generator,
+ local_stable_identifier, local_key_buffer,
+ remote_stable_identifier, remote_key_buffer,
+ fingerprint_val);
+
+complete:
+ signal_buffer_free(local_key_buffer);
+ signal_buffer_free(remote_key_buffer);
+ return result;
+}
+
+int fingerprint_generator_create_for_impl(fingerprint_generator *generator,
+ const char *local_stable_identifier, const signal_buffer *local_identity_buffer,
+ const char *remote_stable_identifier, const signal_buffer *remote_identity_buffer,
fingerprint **fingerprint_val)
{
int result = 0;
fingerprint *result_fingerprint = 0;
+ signal_buffer *local_fingerprint_buffer = 0;
+ signal_buffer *remote_fingerprint_buffer = 0;
displayable_fingerprint *displayable = 0;
char *displayable_local = 0;
char *displayable_remote = 0;
scannable_fingerprint *scannable = 0;
+ result = fingerprint_generator_get_fingerprint(generator,
+ &local_fingerprint_buffer, local_stable_identifier, local_identity_buffer);
+ if(result < 0) {
+ goto complete;
+ }
+
+ result = fingerprint_generator_get_fingerprint(generator,
+ &remote_fingerprint_buffer, remote_stable_identifier, remote_identity_buffer);
+ if(result < 0) {
+ goto complete;
+ }
+
result = fingerprint_generator_create_display_string(generator, &displayable_local,
- local_stable_identifier, local_identity_key);
+ local_fingerprint_buffer);
if(result < 0) {
goto complete;
}
result = fingerprint_generator_create_display_string(generator, &displayable_remote,
- remote_stable_identifier, remote_identity_key);
+ remote_fingerprint_buffer);
if(result < 0) {
goto complete;
}
@@ -93,9 +187,19 @@ int fingerprint_generator_create_for(fingerprint_generator *generator,
goto complete;
}
- result = scannable_fingerprint_create(&scannable, VERSION,
- local_stable_identifier, local_identity_key,
- remote_stable_identifier, remote_identity_key);
+ if(generator->scannable_version == 0) {
+ result = scannable_fingerprint_create(&scannable, 0,
+ local_stable_identifier, local_identity_buffer,
+ remote_stable_identifier, remote_identity_buffer);
+ }
+ else if(generator->scannable_version == 1) {
+ result = scannable_fingerprint_create(&scannable, 1,
+ 0, local_fingerprint_buffer,
+ 0, remote_fingerprint_buffer);
+ }
+ else {
+ result = SG_ERR_INVAL;
+ }
if(result < 0) {
goto complete;
}
@@ -103,6 +207,8 @@ int fingerprint_generator_create_for(fingerprint_generator *generator,
result = fingerprint_create(&result_fingerprint, displayable, scannable);
complete:
+ signal_buffer_free(local_fingerprint_buffer);
+ signal_buffer_free(remote_fingerprint_buffer);
if(displayable_local) {
free(displayable_local);
}
@@ -117,13 +223,69 @@ complete:
return result;
}
-int fingerprint_generator_create_display_string(fingerprint_generator *generator, char **display_string,
- const char *stable_identifier, ec_public_key *identity_key)
+int fingerprint_generator_get_logical_key_bytes(signal_buffer **key_bytes,
+ const ec_public_key_list *unsorted_key_list)
+{
+ int result = 0;
+ ec_public_key_list *sorted_key_list = 0;
+ ec_public_key *key_element = 0;
+ unsigned int list_size = 0;
+ unsigned int i = 0;
+ struct vpool vp;
+ signal_buffer *buffer = 0;
+
+ vpool_init(&vp, 1024, 0);
+
+ sorted_key_list = ec_public_key_list_copy(unsorted_key_list);
+ if(!sorted_key_list) {
+ result = SG_ERR_NOMEM;
+ goto complete;
+ }
+
+ ec_public_key_list_sort(sorted_key_list);
+ list_size = ec_public_key_list_size(sorted_key_list);
+
+ for(i = 0; i < list_size; i++) {
+ key_element = ec_public_key_list_at(sorted_key_list, i);
+
+ result = ec_public_key_serialize(&buffer, key_element);
+ if (result < 0) {
+ goto complete;
+ }
+
+ if(!vpool_insert(&vp, vpool_get_length(&vp),
+ signal_buffer_data(buffer), signal_buffer_len(buffer))) {
+ result = SG_ERR_NOMEM;
+ goto complete;
+ }
+
+ signal_buffer_free(buffer);
+ buffer = 0;
+ }
+
+ buffer = signal_buffer_create(vpool_get_buf(&vp), vpool_get_length(&vp));
+ if(!buffer) {
+ result = SG_ERR_NOMEM;
+ goto complete;
+ }
+
+complete:
+ ec_public_key_list_free(sorted_key_list);
+ vpool_final(&vp);
+ if(result >= 0) {
+ *key_bytes = buffer;
+ }
+ else {
+ signal_buffer_free(buffer);
+ }
+ return result;
+}
+
+int fingerprint_generator_get_fingerprint(fingerprint_generator *generator, signal_buffer **fingerprint_buffer,
+ const char *stable_identifier, const signal_buffer *identity_buffer)
{
int result = 0;
- char *result_string = 0;
void *digest_context = 0;
- signal_buffer *identity_buffer = 0;
signal_buffer *hash_buffer = 0;
signal_buffer *hash_out_buffer = 0;
uint8_t *data = 0;
@@ -132,18 +294,13 @@ int fingerprint_generator_create_display_string(fingerprint_generator *generator
assert(generator);
assert(stable_identifier);
- assert(identity_key);
+ assert(identity_buffer);
result = signal_sha512_digest_init(generator->global_context, &digest_context);
if(result < 0) {
goto complete;
}
- result = ec_public_key_serialize(&identity_buffer, identity_key);
- if(result < 0) {
- goto complete;
- }
-
len = 2 + signal_buffer_len(identity_buffer) + strlen(stable_identifier);
hash_buffer = signal_buffer_alloc(len);
@@ -157,8 +314,8 @@ int fingerprint_generator_create_display_string(fingerprint_generator *generator
memset(data, 0, len);
data[0] = 0;
- data[1] = (uint8_t)VERSION;
- memcpy(data + 2, signal_buffer_data(identity_buffer), signal_buffer_len(identity_buffer));
+ data[1] = (uint8_t)FINGERPRINT_VERSION;
+ memcpy(data + 2, signal_buffer_const_data(identity_buffer), signal_buffer_len(identity_buffer));
memcpy(data + 2 + signal_buffer_len(identity_buffer), stable_identifier, strlen(stable_identifier));
for(i = 0; i < generator->iterations; i++) {
@@ -173,7 +330,7 @@ int fingerprint_generator_create_display_string(fingerprint_generator *generator
result = signal_sha512_digest_update(generator->global_context,
digest_context,
- signal_buffer_data(identity_buffer),
+ signal_buffer_const_data(identity_buffer),
signal_buffer_len(identity_buffer));
if(result < 0) {
goto complete;
@@ -190,21 +347,53 @@ int fingerprint_generator_create_display_string(fingerprint_generator *generator
hash_out_buffer = 0;
}
- data = signal_buffer_data(hash_buffer);
len = signal_buffer_len(hash_buffer);
- if(len < 30) {
+ if(len < FINGERPRINT_LENGTH) {
result = SG_ERR_UNKNOWN;
goto complete;
}
- result_string = malloc(31);
+complete:
+ if(digest_context) {
+ signal_sha512_digest_cleanup(generator->global_context, digest_context);
+ }
+ if(result >= 0) {
+ *fingerprint_buffer = hash_buffer;
+ }
+ else {
+ signal_buffer_free(hash_buffer);
+ }
+ return result;
+}
+
+int fingerprint_generator_create_display_string(fingerprint_generator *generator,
+ char **display_string, signal_buffer *fingerprint_buffer)
+{
+ int result = 0;
+ char *result_string = 0;
+ uint8_t *data = 0;
+ size_t len = 0;
+ int i = 0;
+
+ assert(generator);
+ assert(fingerprint_buffer);
+
+ data = signal_buffer_data(fingerprint_buffer);
+ len = signal_buffer_len(fingerprint_buffer);
+
+ if(len < FINGERPRINT_LENGTH) {
+ result = SG_ERR_UNKNOWN;
+ goto complete;
+ }
+
+ result_string = malloc(FINGERPRINT_LENGTH+1);
if(!result_string) {
result = SG_ERR_NOMEM;
goto complete;
}
- for(i = 0; i < 30; i += 5) {
+ for(i = 0; i < FINGERPRINT_LENGTH; i += 5) {
uint64_t chunk = ((uint64_t)data[i] & 0xFFL) << 32 |
((uint64_t)data[i + 1] & 0xFFL) << 24 |
((uint64_t)data[i + 2] & 0xFFL) << 16 |
@@ -218,12 +407,6 @@ int fingerprint_generator_create_display_string(fingerprint_generator *generator
}
complete:
- if(digest_context) {
- signal_sha512_digest_cleanup(generator->global_context, digest_context);
- }
- signal_buffer_free(identity_buffer);
- signal_buffer_free(hash_buffer);
- signal_buffer_free(hash_out_buffer);
if(result >= 0) {
*display_string = result_string;
}
@@ -260,13 +443,13 @@ int fingerprint_create(fingerprint **fingerprint_val, displayable_fingerprint *d
return 0;
}
-displayable_fingerprint *fingerprint_get_displayable(fingerprint *fingerprint_val)
+displayable_fingerprint *fingerprint_get_displayable(const fingerprint *fingerprint_val)
{
assert(fingerprint_val);
return fingerprint_val->displayable;
}
-scannable_fingerprint *fingerprint_get_scannable(fingerprint *fingerprint_val)
+scannable_fingerprint *fingerprint_get_scannable(const fingerprint *fingerprint_val)
{
assert(fingerprint_val);
return fingerprint_val->scannable;
@@ -343,19 +526,19 @@ complete:
return result;
}
-const char *displayable_fingerprint_local(displayable_fingerprint *displayable)
+const char *displayable_fingerprint_local(const displayable_fingerprint *displayable)
{
assert(displayable);
return displayable->local_fingerprint;
}
-const char *displayable_fingerprint_remote(displayable_fingerprint *displayable)
+const char *displayable_fingerprint_remote(const displayable_fingerprint *displayable)
{
assert(displayable);
return displayable->remote_fingerprint;
}
-const char *displayable_fingerprint_text(displayable_fingerprint *displayable)
+const char *displayable_fingerprint_text(const displayable_fingerprint *displayable)
{
assert(displayable);
return displayable->display_text;
@@ -378,14 +561,17 @@ void displayable_fingerprint_destroy(signal_type_base *type)
int scannable_fingerprint_create(scannable_fingerprint **scannable,
uint32_t version,
- const char *local_stable_identifier, ec_public_key *local_identity_key,
- const char *remote_stable_identifier, ec_public_key *remote_identity_key)
+ const char *local_stable_identifier, const signal_buffer *local_fingerprint,
+ const char *remote_stable_identifier, const signal_buffer *remote_fingerprint)
{
int result = 0;
scannable_fingerprint *result_scannable = 0;
- if(!local_stable_identifier || !local_identity_key ||
- !remote_stable_identifier || !remote_identity_key) {
+ if(version == 0 && (!local_stable_identifier || !remote_stable_identifier)) {
+ return SG_ERR_INVAL;
+ }
+
+ if(!local_fingerprint || !remote_fingerprint) {
return SG_ERR_INVAL;
}
@@ -399,24 +585,44 @@ int scannable_fingerprint_create(scannable_fingerprint **scannable,
result_scannable->version = version;
- result_scannable->local_stable_identifier = strdup(local_stable_identifier);
- if(!result_scannable->local_stable_identifier) {
+ if(version == 0 && local_stable_identifier) {
+ result_scannable->local_stable_identifier = strdup(local_stable_identifier);
+ if(!result_scannable->local_stable_identifier) {
+ result = SG_ERR_NOMEM;
+ goto complete;
+ }
+ }
+
+ if(version == 0) {
+ result_scannable->local_fingerprint = signal_buffer_copy(local_fingerprint);
+ }
+ else {
+ result_scannable->local_fingerprint = signal_buffer_n_copy(local_fingerprint, 32);
+ }
+ if(!result_scannable->local_fingerprint) {
result = SG_ERR_NOMEM;
goto complete;
}
- result_scannable->local_identity_key = local_identity_key;
- SIGNAL_REF(local_identity_key);
+ if(version == 0 && remote_stable_identifier) {
+ result_scannable->remote_stable_identifier = strdup(remote_stable_identifier);
+ if(!result_scannable->remote_stable_identifier) {
+ result = SG_ERR_NOMEM;
+ goto complete;
+ }
+ }
- result_scannable->remote_stable_identifier = strdup(remote_stable_identifier);
- if(!result_scannable->remote_stable_identifier) {
+ if(version == 0) {
+ result_scannable->remote_fingerprint = signal_buffer_copy(remote_fingerprint);
+ }
+ else {
+ result_scannable->remote_fingerprint = signal_buffer_n_copy(remote_fingerprint, 32);
+ }
+ if(!result_scannable->remote_fingerprint) {
result = SG_ERR_NOMEM;
goto complete;
}
- result_scannable->remote_identity_key = remote_identity_key;
- SIGNAL_REF(remote_identity_key);
-
complete:
if(result < 0) {
SIGNAL_UNREF(result_scannable);
@@ -433,42 +639,42 @@ int scannable_fingerprint_serialize(signal_buffer **buffer, const scannable_fing
int result = 0;
size_t result_size = 0;
signal_buffer *result_buf = 0;
- Textsecure__CombinedFingerprint combined_fingerprint = TEXTSECURE__COMBINED_FINGERPRINT__INIT;
- Textsecure__FingerprintData local_fingerprint = TEXTSECURE__FINGERPRINT_DATA__INIT;
- Textsecure__FingerprintData remote_fingerprint = TEXTSECURE__FINGERPRINT_DATA__INIT;
+ Textsecure__CombinedFingerprints combined_fingerprint = TEXTSECURE__COMBINED_FINGERPRINTS__INIT;
+ Textsecure__LogicalFingerprint local_fingerprint = TEXTSECURE__LOGICAL_FINGERPRINT__INIT;
+ Textsecure__LogicalFingerprint remote_fingerprint = TEXTSECURE__LOGICAL_FINGERPRINT__INIT;
size_t len = 0;
uint8_t *data = 0;
combined_fingerprint.version = scannable->version;
combined_fingerprint.has_version = 1;
- if(scannable->local_stable_identifier && scannable->local_identity_key) {
- signal_protocol_str_serialize_protobuf(&local_fingerprint.identifier, scannable->local_stable_identifier);
- local_fingerprint.has_identifier = 1;
-
- result = ec_public_key_serialize_protobuf(&local_fingerprint.publickey, scannable->local_identity_key);
- if(result < 0) {
- goto complete;
+ if(scannable->local_fingerprint) {
+ if(scannable->version == 0 && scannable->local_stable_identifier) {
+ signal_protocol_str_serialize_protobuf(&local_fingerprint.identifier, scannable->local_stable_identifier);
+ local_fingerprint.has_identifier = 1;
}
- local_fingerprint.has_publickey = 1;
+
+ local_fingerprint.content.data = signal_buffer_data(scannable->local_fingerprint);
+ local_fingerprint.content.len = signal_buffer_len(scannable->local_fingerprint);
+ local_fingerprint.has_content = 1;
combined_fingerprint.localfingerprint = &local_fingerprint;
}
- if(scannable->remote_stable_identifier && scannable->remote_identity_key) {
- signal_protocol_str_serialize_protobuf(&remote_fingerprint.identifier, scannable->remote_stable_identifier);
- remote_fingerprint.has_identifier = 1;
-
- result = ec_public_key_serialize_protobuf(&remote_fingerprint.publickey, scannable->remote_identity_key);
- if(result < 0) {
- goto complete;
+ if(scannable->remote_fingerprint) {
+ if(scannable->version == 0 && scannable->remote_stable_identifier) {
+ signal_protocol_str_serialize_protobuf(&remote_fingerprint.identifier, scannable->remote_stable_identifier);
+ remote_fingerprint.has_identifier = 1;
}
- remote_fingerprint.has_publickey = 1;
+
+ remote_fingerprint.content.data = signal_buffer_data(scannable->remote_fingerprint);
+ remote_fingerprint.content.len = signal_buffer_len(scannable->remote_fingerprint);
+ remote_fingerprint.has_content = 1;
combined_fingerprint.remotefingerprint = &remote_fingerprint;
}
- len = textsecure__combined_fingerprint__get_packed_size(&combined_fingerprint);
+ len = textsecure__combined_fingerprints__get_packed_size(&combined_fingerprint);
result_buf = signal_buffer_alloc(len);
if(!result_buf) {
@@ -477,7 +683,7 @@ int scannable_fingerprint_serialize(signal_buffer **buffer, const scannable_fing
}
data = signal_buffer_data(result_buf);
- result_size = textsecure__combined_fingerprint__pack(&combined_fingerprint, data);
+ result_size = textsecure__combined_fingerprints__pack(&combined_fingerprint, data);
if(result_size != len) {
signal_buffer_free(result_buf);
result = SG_ERR_INVALID_PROTO_BUF;
@@ -486,12 +692,6 @@ int scannable_fingerprint_serialize(signal_buffer **buffer, const scannable_fing
}
complete:
- if(local_fingerprint.publickey.data) {
- free(local_fingerprint.publickey.data);
- }
- if(remote_fingerprint.publickey.data) {
- free(remote_fingerprint.publickey.data);
- }
if(result >= 0) {
*buffer = result_buf;
}
@@ -501,14 +701,14 @@ complete:
int scannable_fingerprint_deserialize(scannable_fingerprint **scannable, const uint8_t *data, size_t len, signal_context *global_context)
{
int result = 0;
- Textsecure__CombinedFingerprint *combined_fingerprint = 0;
+ Textsecure__CombinedFingerprints *combined_fingerprint = 0;
uint32_t version = 0;
char *local_stable_identifier = 0;
- ec_public_key *local_identity_key = 0;
+ signal_buffer *local_fingerprint = 0;
char *remote_stable_identifier = 0;
- ec_public_key *remote_identity_key = 0;
+ signal_buffer *remote_fingerprint = 0;
- combined_fingerprint = textsecure__combined_fingerprint__unpack(0, len, data);
+ combined_fingerprint = textsecure__combined_fingerprints__unpack(0, len, data);
if(!combined_fingerprint) {
result = SG_ERR_INVALID_PROTO_BUF;
goto complete;
@@ -526,12 +726,12 @@ int scannable_fingerprint_deserialize(scannable_fingerprint **scannable, const u
goto complete;
}
}
- if(combined_fingerprint->localfingerprint->has_publickey) {
- result = curve_decode_point(&local_identity_key,
- combined_fingerprint->localfingerprint->publickey.data,
- combined_fingerprint->localfingerprint->publickey.len,
- global_context);
- if(result < 0) {
+ if(combined_fingerprint->localfingerprint->has_content) {
+ local_fingerprint = signal_buffer_create(
+ combined_fingerprint->localfingerprint->content.data,
+ combined_fingerprint->localfingerprint->content.len);
+ if(!local_fingerprint) {
+ result = SG_ERR_NOMEM;
goto complete;
}
}
@@ -545,90 +745,88 @@ int scannable_fingerprint_deserialize(scannable_fingerprint **scannable, const u
goto complete;
}
}
- if(combined_fingerprint->remotefingerprint->has_publickey) {
- result = curve_decode_point(&remote_identity_key,
- combined_fingerprint->remotefingerprint->publickey.data,
- combined_fingerprint->remotefingerprint->publickey.len,
- global_context);
- if(result < 0) {
+ if(combined_fingerprint->remotefingerprint->has_content) {
+ remote_fingerprint = signal_buffer_create(
+ combined_fingerprint->remotefingerprint->content.data,
+ combined_fingerprint->remotefingerprint->content.len);
+ if(!remote_fingerprint) {
+ result = SG_ERR_NOMEM;
goto complete;
}
}
}
result = scannable_fingerprint_create(scannable, version,
- local_stable_identifier, local_identity_key,
- remote_stable_identifier, remote_identity_key);
+ local_stable_identifier, local_fingerprint,
+ remote_stable_identifier, remote_fingerprint);
complete:
if(combined_fingerprint) {
- textsecure__combined_fingerprint__free_unpacked(combined_fingerprint, 0);
+ textsecure__combined_fingerprints__free_unpacked(combined_fingerprint, 0);
}
if(local_stable_identifier) {
free(local_stable_identifier);
}
- if(local_identity_key) {
- SIGNAL_UNREF(local_identity_key);
- }
if(remote_stable_identifier) {
free(remote_stable_identifier);
}
- if(remote_identity_key) {
- SIGNAL_UNREF(remote_identity_key);
- }
+ signal_buffer_free(local_fingerprint);
+ signal_buffer_free(remote_fingerprint);
return result;
}
-uint32_t scannable_fingerprint_get_version(scannable_fingerprint *scannable)
+uint32_t scannable_fingerprint_get_version(const scannable_fingerprint *scannable)
{
assert(scannable);
return scannable->version;
}
-const char *scannable_fingerprint_get_local_stable_identifier(scannable_fingerprint *scannable)
+const char *scannable_fingerprint_get_local_stable_identifier(const scannable_fingerprint *scannable)
{
assert(scannable);
return scannable->local_stable_identifier;
}
-ec_public_key *scannable_fingerprint_get_local_identity_key(scannable_fingerprint *scannable)
+signal_buffer *scannable_fingerprint_get_local_fingerprint(const scannable_fingerprint *scannable)
{
assert(scannable);
- return scannable->local_identity_key;
+ return scannable->local_fingerprint;
}
-const char *scannable_fingerprint_get_remote_stable_identifier(scannable_fingerprint *scannable)
+const char *scannable_fingerprint_get_remote_stable_identifier(const scannable_fingerprint *scannable)
{
assert(scannable);
return scannable->remote_stable_identifier;
}
-ec_public_key *scannable_fingerprint_get_remote_identity_key(scannable_fingerprint *scannable)
+signal_buffer *scannable_fingerprint_get_remote_fingerprint(const scannable_fingerprint *scannable)
{
assert(scannable);
- return scannable->remote_identity_key;
+ return scannable->remote_fingerprint;
}
-int scannable_fingerprint_compare(scannable_fingerprint *scannable, const scannable_fingerprint *other_scannable)
+int scannable_fingerprint_compare(const scannable_fingerprint *scannable, const scannable_fingerprint *other_scannable)
{
- if(!other_scannable->remote_identity_key || !other_scannable->local_identity_key ||
+ if(!other_scannable->remote_fingerprint || !other_scannable->local_fingerprint ||
other_scannable->version != scannable->version) {
return SG_ERR_FP_VERSION_MISMATCH;
}
- if(strcmp(scannable->local_stable_identifier, other_scannable->remote_stable_identifier) != 0) {
- return SG_ERR_FP_IDENT_MISMATCH;
- }
+ if(scannable->version == 0) {
+ if(strcmp(scannable->local_stable_identifier, other_scannable->remote_stable_identifier) != 0) {
+ return SG_ERR_FP_IDENT_MISMATCH;
+ }
- if(strcmp(scannable->remote_stable_identifier, other_scannable->local_stable_identifier) != 0) {
- return SG_ERR_FP_IDENT_MISMATCH;
+ if(strcmp(scannable->remote_stable_identifier, other_scannable->local_stable_identifier) != 0) {
+ return SG_ERR_FP_IDENT_MISMATCH;
+ }
}
- if(ec_public_key_compare(scannable->local_identity_key, other_scannable->remote_identity_key) != 0) {
+ if(signal_buffer_compare(scannable->local_fingerprint, other_scannable->remote_fingerprint) != 0) {
return 0;
}
- if(ec_public_key_compare(scannable->remote_identity_key, other_scannable->local_identity_key) != 0) {
+ if(signal_buffer_compare(scannable->remote_fingerprint, other_scannable->local_fingerprint) != 0) {
return 0;
}
@@ -642,14 +840,12 @@ void scannable_fingerprint_destroy(signal_type_base *type)
if(scannable->local_stable_identifier) {
free(scannable->local_stable_identifier);
}
-
- SIGNAL_UNREF(scannable->local_identity_key);
-
if(scannable->remote_stable_identifier) {
free(scannable->remote_stable_identifier);
}
- SIGNAL_UNREF(scannable->remote_identity_key);
+ signal_buffer_free(scannable->local_fingerprint);
+ signal_buffer_free(scannable->remote_fingerprint);
free(scannable);
}