diff options
author | Boris Pek <tehnick-8@yandex.ru> | 2018-03-14 22:12:53 (GMT) |
---|---|---|
committer | Tony Theodore <tonyt@logyst.com> | 2018-03-15 13:56:47 (GMT) |
commit | 477779a4c4c1d14e3d7f48081ef74c9b31307a64 (patch) | |
tree | d36268d044092952aa394cdefe36160c9e05ffed /src | |
parent | 01a4c03baab6c2c5be29ce02ce077c90e2e28ebe (diff) | |
download | mxe-477779a4c4c1d14e3d7f48081ef74c9b31307a64.zip mxe-477779a4c4c1d14e3d7f48081ef74c9b31307a64.tar.gz mxe-477779a4c4c1d14e3d7f48081ef74c9b31307a64.tar.bz2 |
add package libsignal-protocol-c
It should use git snapshots from master branch until the next
stable release. See:
https://github.com/signalapp/libsignal-protocol-c/issues/107
Diffstat (limited to 'src')
-rw-r--r-- | src/libsignal-protocol-c-test.c | 108 | ||||
-rw-r--r-- | src/libsignal-protocol-c.mk | 22 |
2 files changed, 130 insertions, 0 deletions
diff --git a/src/libsignal-protocol-c-test.c b/src/libsignal-protocol-c-test.c new file mode 100644 index 0000000..62e23eb --- /dev/null +++ b/src/libsignal-protocol-c-test.c @@ -0,0 +1,108 @@ +/* + * This file is part of MXE. See LICENSE.md for licensing information. + */ + +#include <signal_protocol.h> +#include <key_helper.h> +#include <session_builder.h> +#include <session_cipher.h> +#include <protocol.h> +#include <stdio.h> +#include <string.h> + +int main(void) +{ + int result = 0; + + // Library initialization + + signal_context *global_context = NULL; + result = signal_context_create(&global_context, NULL); + if (result != SG_SUCCESS) return 1; + + // Client install time + + uint32_t registration_id = 0; + result = signal_protocol_key_helper_generate_registration_id(®istration_id, 0, global_context); + if (result != SG_SUCCESS) return 1; + printf("registration_id = %i\n", registration_id); + fflush(stdout); + + ratchet_identity_key_pair *identity_key_pair = NULL; + result = signal_protocol_key_helper_generate_identity_key_pair(&identity_key_pair, global_context); + if (result != SG_SUCCESS) return 1; + + signal_protocol_key_helper_pre_key_list_node *pre_keys_head = NULL; + result = signal_protocol_key_helper_generate_pre_keys(&pre_keys_head, 13, 100, global_context); + if (result != SG_SUCCESS) return 1; + + session_signed_pre_key *signed_pre_key = NULL; + result = signal_protocol_key_helper_generate_signed_pre_key(&signed_pre_key, identity_key_pair, 5, 1482458501, global_context); + if (result != SG_SUCCESS) return 1; + + // Create the data store context, and add all the callbacks to it + + signal_protocol_store_context *store_context = NULL; + result = signal_protocol_store_context_create(&store_context, global_context); + if (result != SG_SUCCESS) return 1; + + signal_protocol_session_store session_store = { + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL + }; + result = signal_protocol_store_context_set_session_store(store_context, &session_store); + if (result != SG_SUCCESS) return 1; + + signal_protocol_pre_key_store pre_key_store = { + NULL, NULL, NULL, NULL, NULL, NULL + }; + result = signal_protocol_store_context_set_pre_key_store(store_context, &pre_key_store); + if (result != SG_SUCCESS) return 1; + + signal_protocol_signed_pre_key_store signed_pre_key_store = { + NULL, NULL, NULL, NULL, NULL, NULL + }; + result = signal_protocol_store_context_set_signed_pre_key_store(store_context, &signed_pre_key_store); + if (result != SG_SUCCESS) return 1; + + signal_protocol_identity_key_store identity_key_store = { + NULL, NULL, NULL, NULL, NULL, NULL + }; + result = signal_protocol_store_context_set_identity_key_store(store_context, &identity_key_store); + if (result != SG_SUCCESS) return 1; + + // Instantiate a session_builder for a recipient address + + signal_protocol_address address = { + "+14159998888", 12, 1 + }; + session_builder *builder = NULL; + result = session_builder_create(&builder, store_context, &address, global_context); + if (result != SG_SUCCESS) return 1; + + // Create the session cipher and encrypt the message + + session_cipher *cipher = NULL; + result = session_cipher_create(&cipher, store_context, &address, global_context); + if (result != SG_SUCCESS) return 1; + + const char *message = "Kill all humans!!!11100..........."; + const size_t message_len = strlen(message); + ciphertext_message *encrypted_message = NULL; + result = session_cipher_encrypt(cipher, (uint8_t*)message, message_len, &encrypted_message); + if (result != SG_SUCCESS) return 1; + + // Get the serialized content and deliver it + + signal_buffer *serialized = ciphertext_message_get_serialized(encrypted_message); + printf("message:\n%.*s\n", (int)signal_buffer_len(serialized), signal_buffer_data(serialized)); + fflush(stdout); + + // Cleanup + + SIGNAL_UNREF(encrypted_message); + session_cipher_free(cipher); + session_builder_free(builder); + signal_protocol_store_context_destroy(store_context); + + return 0; +} diff --git a/src/libsignal-protocol-c.mk b/src/libsignal-protocol-c.mk new file mode 100644 index 0000000..9e37306 --- /dev/null +++ b/src/libsignal-protocol-c.mk @@ -0,0 +1,22 @@ +# This file is part of MXE. See LICENSE.md for licensing information. + +PKG := libsignal-protocol-c +$(PKG)_WEBSITE := https://github.com/signalapp/libsignal-protocol-c +$(PKG)_DESCR := libsignal-protocol-c +$(PKG)_IGNORE := +$(PKG)_VERSION := 9e10362 +$(PKG)_CHECKSUM := 05a6161cca61e16679fe189039b3cdebe26ed7ee8414d59afdc60363f46fb8fe +$(PKG)_GH_CONF := signalapp/libsignal-protocol-c/branches/master +$(PKG)_DEPS := cc pthreads + +define $(PKG)_BUILD + cd '$(BUILD_DIR)' && '$(TARGET)-cmake' '$(SOURCE_DIR)' \ + -DPKG_CONFIG_EXECUTABLE='$(PREFIX)/bin/$(TARGET)-pkg-config' + $(MAKE) -C '$(BUILD_DIR)' -j '$(JOBS)' VERBOSE=1 + $(MAKE) -C '$(BUILD_DIR)' -j 1 install VERBOSE=1 + + '$(TARGET)-gcc' \ + -W -Wall -Werror -pedantic \ + '$(TEST_FILE)' -o '$(PREFIX)/$(TARGET)/bin/test-libsignal-protocol-c.exe' \ + `'$(TARGET)-pkg-config' libsignal-protocol-c --cflags --libs` +endef |