Compare commits

..

2 commits

Author SHA1 Message Date
Lukas Lihotzki
1e55032377 Simplify olm-sdk/build.gradle by using defaults
This doesn't change the output.

Signed-off-by: Lukas Lihotzki <lukas@lihotzki.de>
2021-05-04 18:05:17 -04:00
Lukas Lihotzki
2949811917 Use CMake for Android builds (externalNativeBuild)
Signed-off-by: Lukas Lihotzki <lukas@lihotzki.de>
2021-05-04 18:05:09 -04:00
452 changed files with 1596 additions and 45378 deletions

View file

@ -1,14 +0,0 @@
root = true
[*]
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
[*.{c,cpp,h,hh,py,ts,js,java,m}]
indent_style = space
indent_size = 4
[Makefile]
indent_style = tab

10
.gitignore vendored
View file

@ -9,13 +9,6 @@
/python/dist /python/dist
/javascript/checksums.txt /javascript/checksums.txt
/javascript/checksums.txt.asc /javascript/checksums.txt.asc
/javascript/olm_prefix.js
/compile_commands.json
/.clang-format
.ccls-cache/
/python/.eggs
/python/install-temp
/result
# Xcode # Xcode
build/ build/
@ -38,6 +31,3 @@ xcuserdata/
*.dSYM *.dSYM
Pods/ Pods/
*.xcworkspace *.xcworkspace
# JetBrains tools
.idea/

View file

@ -1,51 +0,0 @@
default:
image: registry.fedoraproject.org/fedora-minimal:latest
stages:
- build
- test
- trigger
build:lib:
stage: build
tags:
- docker
script:
- microdnf --assumeyes --nodocs install cmake gcc gcc-c++
- cmake . -Bbuild
- cmake --build build
artifacts:
paths:
- build/
test:lib:
stage: test
tags:
- docker
needs:
- build:lib
script:
- microdnf --assumeyes --nodocs install cmake
- pushd build/tests
- ctest .
artifacts:
paths:
- build/tests/Testing/Temporary/
trigger:android:
stage: trigger
trigger:
strategy: depend
include: android/.gitlab-ci.yml
trigger:javascript:
stage: trigger
trigger:
strategy: depend
include: javascript/.gitlab-ci.yml
trigger:python:
stage: trigger
trigger:
strategy: depend
include: python/.gitlab-ci.yml

View file

@ -1,135 +1,3 @@
Changes in `3.2.16 <https://gitlab.matrix.org/matrix-org/olm/tags/3.2.16>`_
===========================================================================
This release includes the following changes since 3.2.15:
* Fix and modernize the Python packaging (thanks to Alfred Wingate)
Changes in `3.2.15 <https://gitlab.matrix.org/matrix-org/olm/tags/3.2.15>`_
===========================================================================
This release includes the following changes since 3.2.14:
* Improvements to Python packaging
* No longer depend on ``future`` since Python 2 is no longer supported.
* Improve compatibility with tox 4.
* Add support for making standalone sdist.
* Improvements to Nix flake (Thanks to Jon Ringer)
* Improve structure.
* Enable Darwin builds.
* Typescript type fix.
Changes in `3.2.14 <https://gitlab.matrix.org/matrix-org/olm/tags/3.2.14>`_
===========================================================================
This release includes the following changes since 3.2.13:
* TypeScript type improvements.
* Improvements to Python packaging
* Documentation improvements.
Changes in `3.2.13 <https://gitlab.matrix.org/matrix-org/olm/tags/3.2.13>`_
===========================================================================
This release includes the following changes since 3.2.12:
* Fix compilation with newer versions of emscripten.
* The npm package is compiled with emscripten 3.1.17 to fix compatibility with
node 18.
* Add py.typed to Python wheels.
* Some documentation fixes and updates.
* Improve the pkgconfig file.
Changes in `3.2.12 <https://gitlab.matrix.org/matrix-org/olm/tags/3.2.12>`_
===========================================================================
This release includes the following changes since 3.2.11:
* Expose olm_sas_calculate_mac_fixed_base64 in the bindings.
* Allow memory to grow in wasm. Thanks to benkuly for the suggestion.
* Fix Python type hints.
* Some Python build fixes.
* Initial work on a Nix flake for building and testing.
Changes in `3.2.11 <https://gitlab.matrix.org/matrix-org/olm/tags/3.2.11>`_
===========================================================================
This release includes the following changes since 3.2.10:
* Fix building documentation. Thanks to Jonas Smedegaard. The documents
written in Markdown are now converted to HTML using Pandoc.
* Add methods for getting unpublished fallback key in Objective-C binding.
* Add public pickle/unpickle methods to Java binding.
* Add wrapper for olm_session_describe to Java binding. Thanks to Alex Baker.
Changes in `3.2.10 <https://gitlab.matrix.org/matrix-org/olm/tags/3.2.10>`_
===========================================================================
This release includes no change since 3.2.9, but is created to be able to
publish again the Android library on MavenCentral.
Changes in `3.2.9 <https://gitlab.matrix.org/matrix-org/olm/tags/3.2.9>`_
=========================================================================
This release includes the following changes since 3.2.8:
* Switch C++ tests to use doctest. Thanks to Nicolas Werner.
* Switch JavaScript tests to use jasmine instead of deprecated jasmine-node.
* Add session describe function to Python binding. Thanks to Tulir Asokan.
Changes in `3.2.8 <https://gitlab.matrix.org/matrix-org/olm/tags/3.2.8>`_
=========================================================================
This release includes the following changes since 3.2.7:
* Improve handling of olm_session_describe when the buffer is too small.
* Ensure random arrays are blanked in JavaScript bindings.
Changes in `3.2.7 <https://gitlab.matrix.org/matrix-org/olm/tags/3.2.7>`_
=========================================================================
This release includes the following changes since 3.2.6:
* Fix installation with the Makefile.
* Fix exporting again, so we only export olm symbols.
* Fix WASM build. Thanks to Benjamin Kampmann.
* Add more functions for fallback keys.
Changes in `3.2.6 <https://gitlab.matrix.org/matrix-org/olm/tags/3.2.6>`_
=========================================================================
This release includes the following changes since 3.2.5:
* Fix building on various platforms when using CMake. Building from the
Makefile still assumes that it is using gcc.
Changes in `3.2.5 <https://gitlab.matrix.org/matrix-org/olm/tags/3.2.5>`_
=========================================================================
This release includes the following changes since 3.2.4:
* Add functions for getting error codes rather than error strings. Thanks to
Nicolas Werner for the suggestion.
* Only export olm symbols. Thanks to Mohammed Sadiq for the suggestion.
* Improve error handling in unpickle functions.
* Add support for fallback keys to the Objective-C and Android bindings.
Changes in `3.2.4 <https://gitlab.matrix.org/matrix-org/olm/tags/3.2.4>`_
=========================================================================
This release includes the following changes since 3.2.3:
* Android build fixes.
Changes in `3.2.3 <https://gitlab.matrix.org/matrix-org/olm/tags/3.2.3>`_
=========================================================================
This release includes the following changes since 3.2.2:
* Add some checks for invalid input and ensure all fields are initialized.
* Include LibreJS license tags. Thanks to Johannes Marbach for the suggestion.
* Support for Swift Package Manager. Thanks to Johannes Marbach.
Changes in `3.2.2 <https://gitlab.matrix.org/matrix-org/olm/tags/3.2.2>`_ Changes in `3.2.2 <https://gitlab.matrix.org/matrix-org/olm/tags/3.2.2>`_
========================================================================= =========================================================================
@ -177,13 +45,11 @@ Changes in `3.1.5 <https://gitlab.matrix.org/matrix-org/olm/tags/3.1.5>`_
This release includes the following changes since 3.1.4: This release includes the following changes since 3.1.4:
* Build improvements: * Build improvements:
* Fix CMake handling when installing in a non-standard location. Thanks to * Fix CMake handling when installing in a non-standard location. Thanks to
Alexey Rusakov. Alexey Rusakov.
* Add support in the Makefile for creating a WASM-ready archive. Thanks to * Add support in the Makefile for creating a WASM-ready archive. Thanks to
stoically. stoically.
* Improve support for LLVM is Makefile. Thanks to caywin25 for reporting. * Improve support for LLVM is Makefile. Thanks to caywin25 for reporting.
* Add a TypeScript definition file. * Add a TypeScript definition file.
* Some documentation and example fixes. * Some documentation and example fixes.
* Add list of bindings to the README. * Add list of bindings to the README.

View file

@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.4) cmake_minimum_required(VERSION 3.4)
project(olm VERSION 3.2.16 LANGUAGES CXX C) project(olm VERSION 3.2.2 LANGUAGES CXX C)
option(OLM_ANDROID_JNI "Add Android JNI support" OFF)
option(OLM_TESTS "Build tests" ON) option(OLM_TESTS "Build tests" ON)
option(BUILD_SHARED_LIBS "Build as a shared library" ON) option(BUILD_SHARED_LIBS "Build as a shared library" ON)
@ -21,10 +22,6 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release) set(CMAKE_BUILD_TYPE Release)
endif() endif()
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
add_library(olm add_library(olm
src/account.cpp src/account.cpp
src/base64.cpp src/base64.cpp
@ -52,10 +49,20 @@ add_library(olm
lib/curve25519-donna/curve25519-donna.c) lib/curve25519-donna/curve25519-donna.c)
add_library(Olm::Olm ALIAS olm) add_library(Olm::Olm ALIAS olm)
# restrict the exported symbols if(OLM_ANDROID_JNI)
include(GenerateExportHeader) target_sources(olm PRIVATE
generate_export_header(olm jni/olm_account.cpp
EXPORT_FILE_NAME ${CMAKE_CURRENT_SOURCE_DIR}/include/olm/olm_export.h) jni/olm_session.cpp
jni/olm_jni_helper.cpp
jni/olm_inbound_group_session.cpp
jni/olm_outbound_group_session.cpp
jni/olm_utility.cpp
jni/olm_manager.cpp
jni/olm_pk.cpp
jni/olm_sas.cpp)
target_link_libraries(olm log)
target_compile_definitions(olm PRIVATE "$<$<CONFIG:DEBUG>:NDK_DEBUG>")
endif()
target_include_directories(olm target_include_directories(olm
PUBLIC PUBLIC
@ -93,12 +100,10 @@ install(TARGETS olm
set_target_properties(olm PROPERTIES EXPORT_NAME Olm) set_target_properties(olm PROPERTIES EXPORT_NAME Olm)
install(FILES install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/include/olm/olm.h ${CMAKE_CURRENT_SOURCE_DIR}/include/olm/olm.h
${CMAKE_CURRENT_SOURCE_DIR}/include/olm/olm_export.h
${CMAKE_CURRENT_SOURCE_DIR}/include/olm/outbound_group_session.h ${CMAKE_CURRENT_SOURCE_DIR}/include/olm/outbound_group_session.h
${CMAKE_CURRENT_SOURCE_DIR}/include/olm/inbound_group_session.h ${CMAKE_CURRENT_SOURCE_DIR}/include/olm/inbound_group_session.h
${CMAKE_CURRENT_SOURCE_DIR}/include/olm/pk.h ${CMAKE_CURRENT_SOURCE_DIR}/include/olm/pk.h
${CMAKE_CURRENT_SOURCE_DIR}/include/olm/sas.h ${CMAKE_CURRENT_SOURCE_DIR}/include/olm/sas.h
${CMAKE_CURRENT_SOURCE_DIR}/include/olm/error.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/olm) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/olm)
if (UNIX AND NOT APPLE) if (UNIX AND NOT APPLE)

139
Makefile
View file

@ -4,12 +4,15 @@ include common.mk
VERSION := $(MAJOR).$(MINOR).$(PATCH) VERSION := $(MAJOR).$(MINOR).$(PATCH)
PREFIX ?= /usr/local PREFIX ?= /usr/local
BUILD_DIR := build BUILD_DIR := build
RELEASE_OPTIMIZE_FLAGS ?= -O3 RELEASE_OPTIMIZE_FLAGS ?= -g -O3
DEBUG_OPTIMIZE_FLAGS ?= -g -O0 -U_FORTIFY_SOURCE DEBUG_OPTIMIZE_FLAGS ?= -g -O0
JS_OPTIMIZE_FLAGS ?= -O3 JS_OPTIMIZE_FLAGS ?= -O3
FUZZER_OPTIMIZE_FLAGS ?= -O3 FUZZING_OPTIMIZE_FLAGS ?= -O3
CC = gcc
EMCC = emcc EMCC = emcc
EMAR = emar EMAR = emar
AFL_CC = afl-gcc
AFL_CXX = afl-g++
AR = ar AR = ar
UNAME := $(shell uname) UNAME := $(shell uname)
@ -30,29 +33,24 @@ JS_ASMJS_TARGET := javascript/olm_legacy.js
WASM_TARGET := $(BUILD_DIR)/wasm/libolm.a WASM_TARGET := $(BUILD_DIR)/wasm/libolm.a
JS_EXPORTED_FUNCTIONS := javascript/exported_functions.json JS_EXPORTED_FUNCTIONS := javascript/exported_functions.json
JS_EXPORTED_RUNTIME_METHODS := [ALLOC_STACK,writeAsciiToMemory,intArrayFromString,UTF8ToString,stringToUTF8] JS_EXTRA_EXPORTED_RUNTIME_METHODS := [ALLOC_STACK]
JS_EXTERNS := javascript/externs.js JS_EXTERNS := javascript/externs.js
PUBLIC_HEADERS := include/olm/olm.h include/olm/outbound_group_session.h include/olm/inbound_group_session.h include/olm/pk.h include/olm/sas.h include/olm/error.h include/olm/olm_export.h PUBLIC_HEADERS := include/olm/olm.h include/olm/outbound_group_session.h include/olm/inbound_group_session.h include/olm/pk.h include/olm/sas.h
SOURCES := $(wildcard src/*.cpp) $(wildcard src/*.c) \ SOURCES := $(wildcard src/*.cpp) $(wildcard src/*.c) \
lib/crypto-algorithms/sha256.c \ lib/crypto-algorithms/sha256.c \
lib/crypto-algorithms/aes.c \ lib/crypto-algorithms/aes.c \
lib/curve25519-donna/curve25519-donna.c lib/curve25519-donna/curve25519-donna.c
FUZZER_SOURCES := $(wildcard fuzzing/fuzzers/fuzz_*.cpp) $(wildcard fuzzing/fuzzers/fuzz_*.c) FUZZER_SOURCES := $(wildcard fuzzers/fuzz_*.cpp) $(wildcard fuzzers/fuzz_*.c)
TEST_SOURCES := $(wildcard tests/test_*.cpp) $(wildcard tests/test_*.c) TEST_SOURCES := $(wildcard tests/test_*.cpp) $(wildcard tests/test_*.c)
OBJECTS := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCES))) OBJECTS := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCES)))
RELEASE_OBJECTS := $(addprefix $(BUILD_DIR)/release/,$(OBJECTS)) RELEASE_OBJECTS := $(addprefix $(BUILD_DIR)/release/,$(OBJECTS))
DEBUG_OBJECTS := $(addprefix $(BUILD_DIR)/debug/,$(OBJECTS)) DEBUG_OBJECTS := $(addprefix $(BUILD_DIR)/debug/,$(OBJECTS))
FUZZER_OBJECTS := $(addprefix $(BUILD_DIR)/fuzzers/objects/,$(OBJECTS)) FUZZER_OBJECTS := $(addprefix $(BUILD_DIR)/fuzzers/objects/,$(OBJECTS))
FUZZER_ASAN_OBJECTS := $(addprefix $(BUILD_DIR)/fuzzers/objects/,$(addprefix asan_,$(OBJECTS))) FUZZER_BINARIES := $(addprefix $(BUILD_DIR)/,$(basename $(FUZZER_SOURCES)))
FUZZER_MSAN_OBJECTS := $(addprefix $(BUILD_DIR)/fuzzers/objects/,$(addprefix msan_,$(OBJECTS)))
FUZZER_DEBUG_OBJECTS := $(addprefix $(BUILD_DIR)/fuzzers/objects/,$(addprefix debug_,$(OBJECTS)))
FUZZER_BINARIES := $(addprefix $(BUILD_DIR)/fuzzers/,$(basename $(notdir $(FUZZER_SOURCES))))
FUZZER_ASAN_BINARIES := $(addsuffix _asan,$(FUZZER_BINARIES))
FUZZER_MSAN_BINARIES := $(addsuffix _msan,$(FUZZER_BINARIES))
FUZZER_DEBUG_BINARIES := $(patsubst $(BUILD_DIR)/fuzzers/fuzz_%,$(BUILD_DIR)/fuzzers/debug_%,$(FUZZER_BINARIES)) FUZZER_DEBUG_BINARIES := $(patsubst $(BUILD_DIR)/fuzzers/fuzz_%,$(BUILD_DIR)/fuzzers/debug_%,$(FUZZER_BINARIES))
TEST_BINARIES := $(patsubst tests/%,$(BUILD_DIR)/tests/%,$(basename $(TEST_SOURCES))) TEST_BINARIES := $(patsubst tests/%,$(BUILD_DIR)/tests/%,$(basename $(TEST_SOURCES)))
JS_OBJECTS := $(addprefix $(BUILD_DIR)/javascript/,$(OBJECTS)) JS_OBJECTS := $(addprefix $(BUILD_DIR)/javascript/,$(OBJECTS))
@ -93,7 +91,7 @@ LDFLAGS += -Wall -Werror
CFLAGS_NATIVE = -fPIC CFLAGS_NATIVE = -fPIC
CXXFLAGS_NATIVE = -fPIC CXXFLAGS_NATIVE = -fPIC
EMCCFLAGS = --closure 1 --memory-init-file 0 -s NO_FILESYSTEM=1 -s INVOKE_RUN=0 -s MODULARIZE=1 -Wno-error=closure EMCCFLAGS = --closure 1 --memory-init-file 0 -s NO_FILESYSTEM=1 -s INVOKE_RUN=0 -s MODULARIZE=1
# Olm generally doesn't need a lot of memory to encrypt / decrypt its usual # Olm generally doesn't need a lot of memory to encrypt / decrypt its usual
# payloads (ie. Matrix messages), but we do need about 128K of heap to encrypt # payloads (ie. Matrix messages), but we do need about 128K of heap to encrypt
@ -103,29 +101,18 @@ EMCCFLAGS = --closure 1 --memory-init-file 0 -s NO_FILESYSTEM=1 -s INVOKE_RUN=0
# (This can't be changed by the app with wasm since it's baked into the wasm). # (This can't be changed by the app with wasm since it's baked into the wasm).
# (emscripten also mandates at least 16MB of memory for asm.js now, so # (emscripten also mandates at least 16MB of memory for asm.js now, so
# we don't use this for the legacy build.) # we don't use this for the legacy build.)
EMCCFLAGS_WASM += -s TOTAL_STACK=65536 -s TOTAL_MEMORY=262144 -s ALLOW_MEMORY_GROWTH EMCCFLAGS_WASM += -s TOTAL_STACK=65536 -s TOTAL_MEMORY=262144
EMCCFLAGS_ASMJS += -s WASM=0 EMCCFLAGS_ASMJS += -s WASM=0
EMCC.c = $(EMCC) $(CFLAGS) $(CPPFLAGS) -c -DNDEBUG -DOLM_STATIC_DEFINE=1 EMCC.c = $(EMCC) $(CFLAGS) $(CPPFLAGS) -c
EMCC.cc = $(EMCC) $(CXXFLAGS) $(CPPFLAGS) -c -DNDEBUG -DOLM_STATIC_DEFINE=1 EMCC.cc = $(EMCC) $(CXXFLAGS) $(CPPFLAGS) -c
EMCC_LINK = $(EMCC) $(LDFLAGS) $(EMCCFLAGS) EMCC_LINK = $(EMCC) $(LDFLAGS) $(EMCCFLAGS)
AFL_CC = afl-clang-fast
AFL_CXX = afl-clang-fast++
AFL.c = $(AFL_CC) $(CFLAGS) $(CPPFLAGS) -c AFL.c = $(AFL_CC) $(CFLAGS) $(CPPFLAGS) -c
AFL.cc = $(AFL_CXX) $(CXXFLAGS) $(CPPFLAGS) -c AFL.cc = $(AFL_CXX) $(CXXFLAGS) $(CPPFLAGS) -c
AFL_LINK.c = $(AFL_CC) $(LDFLAGS) $(CFLAGS) $(CPPFLAGS) AFL_LINK.c = $(AFL_CC) $(LDFLAGS) $(CFLAGS) $(CPPFLAGS)
AFL_LINK.cc = $(AFL_CXX) $(LDFLAGS) $(CXXFLAGS) $(CPPFLAGS) AFL_LINK.cc = $(AFL_CXX) $(LDFLAGS) $(CXXFLAGS) $(CPPFLAGS)
AFL_ASAN.c = AFL_USE_ASAN=1 $(AFL_CC) -m32 $(CFLAGS) $(CPPFLAGS) -c
AFL_ASAN.cc = AFL_USE_ASAN=1 $(AFL_CXX) -m32 $(CXXFLAGS) $(CPPFLAGS) -c
AFL_LINK_ASAN.c = AFL_USE_ASAN=1 $(AFL_CC) -m32 $(LDFLAGS) $(CFLAGS) $(CPPFLAGS)
AFL_LINK_ASAN.cc = AFL_USE_ASAN=1 $(AFL_CXX) -m32 $(LDFLAGS) $(CXXFLAGS) $(CPPFLAGS)
AFL_MSAN.c = AFL_USE_MSAN=1 $(AFL_CC) $(CFLAGS) $(CPPFLAGS) -c
AFL_MSAN.cc = AFL_USE_MSAN=1 $(AFL_CXX) $(CXXFLAGS) $(CPPFLAGS) -c
AFL_LINK_MSAN.c = AFL_USE_MSAN=1 $(AFL_CC) $(LDFLAGS) $(CFLAGS) $(CPPFLAGS)
AFL_LINK_MSAN.cc = AFL_USE_MSAN=1 $(AFL_CXX) $(LDFLAGS) $(CXXFLAGS) $(CPPFLAGS)
# generate .d files when compiling # generate .d files when compiling
CPPFLAGS += -MMD CPPFLAGS += -MMD
@ -143,23 +130,12 @@ $(DEBUG_TARGET): LDFLAGS += $(DEBUG_OPTIMIZE_FLAGS)
$(TEST_BINARIES): CPPFLAGS += -Itests/include $(TEST_BINARIES): CPPFLAGS += -Itests/include
$(TEST_BINARIES): LDFLAGS += $(DEBUG_OPTIMIZE_FLAGS) -L$(BUILD_DIR) $(TEST_BINARIES): LDFLAGS += $(DEBUG_OPTIMIZE_FLAGS) -L$(BUILD_DIR)
$(FUZZER_OBJECTS): CFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -D OLM_FUZZING=1 $(FUZZER_OBJECTS): CFLAGS += $(FUZZER_OPTIMIZE_FLAGS)
$(FUZZER_OBJECTS): CXXFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -D OLM_FUZZING=1 $(FUZZER_OBJECTS): CXXFLAGS += $(FUZZER_OPTIMIZE_FLAGS)
$(FUZZER_DEBUG_OBJECTS): CFLAGS += $(DEBUG_OPTIMIZE_FLAGS) $(CFLAGS_NATIVE) -D OLM_FUZZING=1 $(FUZZER_BINARIES): CPPFLAGS += -Ifuzzers/include
$(FUZZER_DEBUG_OBJECTS): CXXFLAGS += $(DEBUG_OPTIMIZE_FLAGS) $(CXXFLAGS_NATIVE) -D OLM_FUZZING=1 $(FUZZER_BINARIES): LDFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -L$(BUILD_DIR)
$(FUZZER_ASAN_OBJECTS): CFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -D OLM_FUZZING=1 $(FUZZER_DEBUG_BINARIES): CPPFLAGS += -Ifuzzers/include
$(FUZZER_ASAN_OBJECTS): CXXFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -D OLM_FUZZING=1 $(FUZZER_DEBUG_BINARIES): LDFLAGS += $(DEBUG_OPTIMIZE_FLAGS)
$(FUZZER_MSAN_OBJECTS): CFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -D OLM_FUZZING=1
$(FUZZER_MSAN_OBJECTS): CXXFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -D OLM_FUZZING=1
$(FUZZER_BINARIES): CPPFLAGS += -Ifuzzing/fuzzers/include
$(FUZZER_BINARIES): LDFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -L$(BUILD_DIR) -lstdc++
$(FUZZER_ASAN_BINARIES): CPPFLAGS += -Ifuzzing/fuzzers/include
$(FUZZER_ASAN_BINARIES): LDFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -L$(BUILD_DIR) -lstdc++
$(FUZZER_MSAN_BINARIES): CPPFLAGS += -Ifuzzing/fuzzers/include
$(FUZZER_MSAN_BINARIES): LDFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -L$(BUILD_DIR) -lstdc++
$(FUZZER_DEBUG_BINARIES): CPPFLAGS += -Ifuzzing/fuzzers/include
$(FUZZER_DEBUG_BINARIES): LDFLAGS += $(DEBUG_OPTIMIZE_FLAGS) -lstdc++
$(JS_OBJECTS): CFLAGS += $(JS_OPTIMIZE_FLAGS) $(JS_OBJECTS): CFLAGS += $(JS_OPTIMIZE_FLAGS)
$(JS_OBJECTS): CXXFLAGS += $(JS_OPTIMIZE_FLAGS) $(JS_OBJECTS): CXXFLAGS += $(JS_OPTIMIZE_FLAGS)
@ -185,12 +161,6 @@ lib: $(RELEASE_TARGET)
.PHONY: lib .PHONY: lib
$(RELEASE_TARGET): $(RELEASE_OBJECTS) $(RELEASE_TARGET): $(RELEASE_OBJECTS)
@echo
@echo '****************************************************************************'
@echo '* WARNING: Building olm with make is deprecated. Please use cmake instead. *'
@echo '****************************************************************************'
@echo
$(CXX) $(LDFLAGS) --shared -fPIC \ $(CXX) $(LDFLAGS) --shared -fPIC \
$(OLM_LDFLAGS) \ $(OLM_LDFLAGS) \
$(OUTPUT_OPTION) $(RELEASE_OBJECTS) $(OUTPUT_OPTION) $(RELEASE_OBJECTS)
@ -221,32 +191,32 @@ wasm: $(WASM_TARGET)
$(WASM_TARGET): $(WASM_OBJECTS) $(WASM_TARGET): $(WASM_OBJECTS)
$(EMAR) rcs $@ $^ $(EMAR) rcs $@ $^
javascript/olm_prefix.js: javascript/olm_prefix.js.in Makefile common.mk javascript/olm_prefix.js: javascript/olm_prefix.js.in Makefile
sed s/@VERSION@/$(VERSION)/ javascript/olm_prefix.js.in > $@ sed s/@VERSION@/$(VERSION)/ javascript/olm_prefix.js.in > $@
# Note that the output file we give to emcc determines the name of the # Note that the output file we give to emcc determines the name of the
# wasm file baked into the js, hence messing around outputting to olm.js # wasm file baked into the js, hence messing around outputting to olm.js
# and then renaming it. # and then renaming it.
$(JS_WASM_TARGET): $(JS_OBJECTS) $(JS_PRE) $(JS_POST) $(JS_EXPORTED_FUNCTIONS) $(JS_PREFIX) $(JS_SUFFIX) $(JS_WASM_TARGET): $(JS_OBJECTS) $(JS_PRE) $(JS_POST) $(JS_EXPORTED_FUNCTIONS) $(JS_PREFIX) $(JS_SUFFIX)
EMCC_CLOSURE_ARGS="--externs $(CURDIR)/$(JS_EXTERNS)" $(EMCC_LINK) \ EMCC_CLOSURE_ARGS="--externs $(JS_EXTERNS)" $(EMCC_LINK) \
$(EMCCFLAGS_WASM) \ $(EMCCFLAGS_WASM) \
$(foreach f,$(JS_PRE),--pre-js $(f)) \ $(foreach f,$(JS_PRE),--pre-js $(f)) \
$(foreach f,$(JS_POST),--post-js $(f)) \ $(foreach f,$(JS_POST),--post-js $(f)) \
$(foreach f,$(JS_PREFIX),--extern-pre-js $(f)) \ $(foreach f,$(JS_PREFIX),--extern-pre-js $(f)) \
$(foreach f,$(JS_SUFFIX),--extern-post-js $(f)) \ $(foreach f,$(JS_SUFFIX),--extern-post-js $(f)) \
-s "EXPORTED_FUNCTIONS=@$(JS_EXPORTED_FUNCTIONS)" \ -s "EXPORTED_FUNCTIONS=@$(JS_EXPORTED_FUNCTIONS)" \
-s "EXPORTED_RUNTIME_METHODS=$(JS_EXPORTED_RUNTIME_METHODS)" \ -s "EXTRA_EXPORTED_RUNTIME_METHODS=$(JS_EXTRA_EXPORTED_RUNTIME_METHODS)" \
-o $@ $(JS_OBJECTS) -o $@ $(JS_OBJECTS)
$(JS_ASMJS_TARGET): $(JS_OBJECTS) $(JS_PRE) $(JS_POST) $(JS_EXPORTED_FUNCTIONS) $(JS_PREFIX) $(JS_SUFFIX) $(JS_ASMJS_TARGET): $(JS_OBJECTS) $(JS_PRE) $(JS_POST) $(JS_EXPORTED_FUNCTIONS) $(JS_PREFIX) $(JS_SUFFIX)
EMCC_CLOSURE_ARGS="--externs $(CURDIR)/$(JS_EXTERNS)" $(EMCC_LINK) \ EMCC_CLOSURE_ARGS="--externs $(JS_EXTERNS)" $(EMCC_LINK) \
$(EMCCFLAGS_ASMJS) \ $(EMCCFLAGS_ASMJS) \
$(foreach f,$(JS_PRE),--pre-js $(f)) \ $(foreach f,$(JS_PRE),--pre-js $(f)) \
$(foreach f,$(JS_POST),--post-js $(f)) \ $(foreach f,$(JS_POST),--post-js $(f)) \
$(foreach f,$(JS_PREFIX),--extern-pre-js $(f)) \ $(foreach f,$(JS_PREFIX),--extern-pre-js $(f)) \
$(foreach f,$(JS_SUFFIX),--extern-post-js $(f)) \ $(foreach f,$(JS_SUFFIX),--extern-post-js $(f)) \
-s "EXPORTED_FUNCTIONS=@$(JS_EXPORTED_FUNCTIONS)" \ -s "EXPORTED_FUNCTIONS=@$(JS_EXPORTED_FUNCTIONS)" \
-s "EXPORTED_RUNTIME_METHODS=$(JS_EXPORTED_RUNTIME_METHODS)" \ -s "EXTRA_EXPORTED_RUNTIME_METHODS=$(JS_EXTRA_EXPORTED_RUNTIME_METHODS)" \
-o $@ $(JS_OBJECTS) -o $@ $(JS_OBJECTS)
build_tests: $(TEST_BINARIES) build_tests: $(TEST_BINARIES)
@ -263,7 +233,7 @@ test_mem: build_tests
valgrind -q --leak-check=yes --exit-on-first-error=yes --error-exitcode=1 $$i || exit $$?; \ valgrind -q --leak-check=yes --exit-on-first-error=yes --error-exitcode=1 $$i || exit $$?; \
done done
fuzzers: $(FUZZER_BINARIES) $(FUZZER_ASAN_BINARIES) $(FUZZER_MSAN_BINARIES) $(FUZZER_DEBUG_BINARIES) fuzzers: $(FUZZER_BINARIES) $(FUZZER_DEBUG_BINARIES)
.PHONY: fuzzers .PHONY: fuzzers
$(JS_EXPORTED_FUNCTIONS): $(PUBLIC_HEADERS) $(JS_EXPORTED_FUNCTIONS): $(PUBLIC_HEADERS)
@ -348,61 +318,21 @@ $(BUILD_DIR)/fuzzers/objects/%.o: %.cpp
$(call mkdir,$(dir $@)) $(call mkdir,$(dir $@))
$(AFL.cc) $(OUTPUT_OPTION) $< $(AFL.cc) $(OUTPUT_OPTION) $<
$(BUILD_DIR)/fuzzers/objects/asan_%.o: %.c $(BUILD_DIR)/fuzzers/fuzz_%: fuzzers/fuzz_%.c $(FUZZER_OBJECTS)
$(call mkdir,$(dir $@))
$(AFL_ASAN.c) $(OUTPUT_OPTION) $<
$(BUILD_DIR)/fuzzers/objects/asan_%.o: %.cpp
$(call mkdir,$(dir $@))
$(AFL_ASAN.cc) $(OUTPUT_OPTION) $<
$(BUILD_DIR)/fuzzers/objects/msan_%.o: %.c
$(call mkdir,$(dir $@))
$(AFL_MSAN.c) $(OUTPUT_OPTION) $<
$(BUILD_DIR)/fuzzers/objects/msan_%.o: %.cpp
$(call mkdir,$(dir $@))
$(AFL_MSAN.cc) $(OUTPUT_OPTION) $<
$(BUILD_DIR)/fuzzers/objects/debug_%.o: %.c
$(call mkdir,$(dir $@))
$(COMPILE.c) $(OUTPUT_OPTION) $<
$(BUILD_DIR)/fuzzers/objects/debug_%.o: %.cpp
$(call mkdir,$(dir $@))
$(COMPILE.cc) $(OUTPUT_OPTION) $<
$(BUILD_DIR)/fuzzers/fuzz_%: fuzzing/fuzzers/fuzz_%.c $(FUZZER_OBJECTS)
$(AFL_LINK.c) -o $@ $< $(FUZZER_OBJECTS) $(LOADLIBES) $(LDLIBS) $(AFL_LINK.c) -o $@ $< $(FUZZER_OBJECTS) $(LOADLIBES) $(LDLIBS)
$(BUILD_DIR)/fuzzers/fuzz_%: fuzzing/fuzzers/fuzz_%.cpp $(FUZZER_OBJECTS) $(BUILD_DIR)/fuzzers/fuzz_%: fuzzers/fuzz_%.cpp $(FUZZER_OBJECTS)
$(AFL_LINK.cc) -o $@ $< $(FUZZER_OBJECTS) $(LOADLIBES) $(LDLIBS) $(AFL_LINK.cc) -o $@ $< $(FUZZER_OBJECTS) $(LOADLIBES) $(LDLIBS)
$(BUILD_DIR)/fuzzers/debug_%: fuzzing/fuzzers/fuzz_%.c $(FUZZER_DEBUG_OBJECTS) $(BUILD_DIR)/fuzzers/debug_%: fuzzers/fuzz_%.c $(DEBUG_OBJECTS)
$(LINK.c) -o $@ $< $(FUZZER_DEBUG_OBJECTS) $(LOADLIBES) $(LDLIBS) $(LINK.c) -o $@ $< $(DEBUG_OBJECTS) $(LOADLIBES) $(LDLIBS)
$(BUILD_DIR)/fuzzers/debug_%: fuzzing/fuzzers/fuzz_%.cpp $(FUZZER_DEBUG_OBJECTS) $(BUILD_DIR)/fuzzers/debug_%: fuzzers/fuzz_%.cpp $(DEBUG_OBJECTS)
$(LINK.cc) -o $@ $< $(FUZZER_DEBUG_OBJECTS) $(LOADLIBES) $(LDLIBS) $(LINK.cc) -o $@ $< $(DEBUG_OBJECTS) $(LOADLIBES) $(LDLIBS)
$(BUILD_DIR)/fuzzers/fuzz_%_asan: fuzzing/fuzzers/fuzz_%.c $(FUZZER_ASAN_OBJECTS)
$(AFL_LINK_ASAN.c) -o $@ $< $(FUZZER_ASAN_OBJECTS) $(LOADLIBES) $(LDLIBS)
$(BUILD_DIR)/fuzzers/fuzz_%_asan: fuzzing/fuzzers/fuzz_%.cpp $(FUZZER_ASAN_OBJECTS)
$(AFL_LINK_ASAN.cc) -o $@ $< $(FUZZER_ASAN_OBJECTS) $(LOADLIBES) $(LDLIBS)
$(BUILD_DIR)/fuzzers/fuzz_%_msan: fuzzing/fuzzers/fuzz_%.c $(FUZZER_MSAN_OBJECTS)
$(AFL_LINK_MSAN.c) -o $@ $< $(FUZZER_MSAN_OBJECTS) $(LOADLIBES) $(LDLIBS)
$(BUILD_DIR)/fuzzers/fuzz_%_msan: fuzzing/fuzzers/fuzz_%.cpp $(FUZZER_MSAN_OBJECTS)
$(AFL_LINK_MSAN.cc) -o $@ $< $(FUZZER_MSAN_OBJECTS) $(LOADLIBES) $(LDLIBS)
%.html: %.rst %.html: %.rst
rst2html $< $@ rst2html $< $@
%.html: %.md
pandoc --from markdown --to html5 --standalone --lua-filter gitlab-math.lua --katex -o $@ $<
### dependencies ### dependencies
-include $(RELEASE_OBJECTS:.o=.d) -include $(RELEASE_OBJECTS:.o=.d)
@ -410,10 +340,5 @@ $(BUILD_DIR)/fuzzers/fuzz_%_msan: fuzzing/fuzzers/fuzz_%.cpp $(FUZZER_MSAN_OBJEC
-include $(JS_OBJECTS:.o=.d) -include $(JS_OBJECTS:.o=.d)
-include $(TEST_BINARIES:=.d) -include $(TEST_BINARIES:=.d)
-include $(FUZZER_OBJECTS:.o=.d) -include $(FUZZER_OBJECTS:.o=.d)
-include $(FUZZER_DEBUG_OBJECTS:.o=.d)
-include $(FUZZER_ASAN_OBJECTS:.o=.d)
-include $(FUZZER_MSAN_OBJECTS:.o=.d)
-include $(FUZZER_BINARIES:=.d) -include $(FUZZER_BINARIES:=.d)
-include $(FUZZER_ASAN_BINARIES:=.d)
-include $(FUZZER_MSAN_BINARIES:=.d)
-include $(FUZZER_DEBUG_BINARIES:=.d) -include $(FUZZER_DEBUG_BINARIES:=.d)

View file

@ -3,7 +3,7 @@ Pod::Spec.new do |s|
# The libolm version # The libolm version
MAJOR = 3 MAJOR = 3
MINOR = 2 MINOR = 2
PATCH = 16 PATCH = 2
s.name = "OLMKit" s.name = "OLMKit"
s.version = "#{MAJOR}.#{MINOR}.#{PATCH}" s.version = "#{MAJOR}.#{MINOR}.#{PATCH}"

View file

@ -2,7 +2,7 @@
import PackageDescription import PackageDescription
let major = 3, minor = 2, patch = 16 let major = 3, minor = 2, patch = 2
let package = Package( let package = Package(
name: "Olm", name: "Olm",

171
README.md
View file

@ -9,133 +9,52 @@ The specification of the Olm ratchet can be found in [docs/olm.md](docs/olm.md).
This library also includes an implementation of the Megolm cryptographic This library also includes an implementation of the Megolm cryptographic
ratchet, as specified in [docs/megolm.md](docs/megolm.md). ratchet, as specified in [docs/megolm.md](docs/megolm.md).
## Installing
### Linux and other Unix-like systems
Your distribution may have pre-compiled packages available. If not, or if you
need a newer version, you will need to compile from source. See the "Building"
section below for more details.
### macOS
The easiest way to install on macOS is via Homebrew. If you do not have
Homebrew installed, follow the instructions at https://brew.sh/ to install it.
You can then install libolm by running
```bash
brew install libolm
```
If you also need the Python packages, you can run
```bash
pip3 install python-olm --global-option="build_ext" --global-option="--include-dirs="`brew --prefix libolm`"/include" --global-option="--library-dirs="`brew --prefix libolm`"/lib"
```
Note that this will install an older version of the Python bindings, which may
be missing some functions. If you need the latest version, you will need to
build from source.
### Windows
You will need to build from source. See the "Building" section below for more
details.
### Bindings
#### JavaScript
You can use pre-built npm packages, available at
<https://gitlab.matrix.org/matrix-org/olm/-/packages?type=npm>.
#### Python
A Python source package and pre-built packages for certain architectures from
<https://pypi.org/project/python-olm/>. If a pre-built package is not
available for your architecture, you will need:
- cmake (recommended) or GNU make
- a C/C++ compiler
to build the source package.
You can then run `pip install python-olm`.
Currently, we try to provide packages for all supported versions of Python on
x86-64, i686, and aarch64, but we cannot guarantee that packages for all
versions will be available on all architectures.
#### Android
Pre-built Android bindings are available at
<https://gitlab.matrix.org/matrix-org/olm/-/packages?type=Maven>.
## Building ## Building
To build olm as a shared library run: To build olm as a shared library run either:
```bash ```bash
cmake . -Bbuild cmake . -Bbuild
cmake --build build cmake --build build
``` ```
To run the tests, run: or:
```bash
make
```
Using cmake is the preferred method for building the shared library; the
Makefile may be removed in the future.
To run the tests when using cmake, run:
```bash ```bash
cd build/tests cd build/tests
ctest . ctest .
``` ```
To run the tests when using make, run:
To build olm as a static library (which still needs libstdc++ dynamically) run:
```bash ```bash
cmake . -Bbuild -DBUILD_SHARED_LIBS=NO make test
cmake --build build
``` ```
The library can also be used as a dependency with CMake using: To build the JavaScript bindings, install emscripten from http://kripken.github.io/emscripten-site/ and then run:
```cmake
find_package(Olm::Olm REQUIRED)
target_link_libraries(my_exe Olm::Olm)
```
### Bindings
#### JavaScript
The recommended way to build the JavaScript bindings is using
[Nix](https://nixos.org/). With Nix, you can run
```bash
nix build .\#javascript
```
to build the bindings.
If you do not have Nix you can, install emscripten from https://emscripten.org/
and then run:
```bash ```bash
make js make js
``` ```
Emscripten can also be run via Docker, in which case, you need to pass through Note that if you run emscripten in a docker container, you need to pass through
the EMCC_CLOSURE_ARGS environment variable. the EMCC_CLOSURE_ARGS environment variable.
#### Android
To build the android project for Android bindings, run: To build the android project for Android bindings, run:
```bash ```bash
cd android cd android
./gradlew clean build ./gradlew clean assembleRelease
``` ```
#### Objective-C
To build the Xcode workspace for Objective-C bindings, run: To build the Xcode workspace for Objective-C bindings, run:
```bash ```bash
@ -144,9 +63,7 @@ pod install
open OLMKit.xcworkspace open OLMKit.xcworkspace
``` ```
#### Python To build the Python bindings, first build olm as a shared library as above, and
To build the Python 3 bindings, first build olm as a library as above, and
then run: then run:
```bash ```bash
@ -154,31 +71,30 @@ cd python
make make
``` ```
### Using make instead of cmake to make both the Python 2 and Python 3 bindings. To make only one version, use
``make olm-python2`` or ``make olm-python3`` instead of just ``make``.
**WARNING:** Using cmake is the preferred method for building the olm library; To build olm as a static library (which still needs libstdc++ dynamically) run
the Makefile may be removed in the future or have functionality removed. In either:
addition, the Makefile may make certain assumptions about your system and is
not as well tested.
To build olm as a dynamic library, run:
```bash ```bash
make cmake . -Bbuild -DBUILD_SHARED_LIBS=NO
cmake --build build
``` ```
To run the tests, run: or
```bash
make test
```
To build olm as a static library, run:
```bash ```bash
make static make static
``` ```
The library can also be used as a dependency with CMake using:
```cmake
find_package(Olm::Olm REQUIRED)
target_link_libraries(my_exe Olm::Olm)
```
## Bindings ## Bindings
libolm can be used in different environments using bindings. In addition to the libolm can be used in different environments using bindings. In addition to the
@ -186,19 +102,16 @@ JavaScript, Python, Java (Android), and Objective-C bindings included in this
repository, some bindings are (in alphabetical order): repository, some bindings are (in alphabetical order):
- [cl-megolm](https://github.com/K1D77A/cl-megolm) (MIT) Common Lisp bindings - [cl-megolm](https://github.com/K1D77A/cl-megolm) (MIT) Common Lisp bindings
- [dart-olm](https://gitlab.com/famedly/company/frontend/libraries/dart-olm) (AGPLv3) Dart bindings - [dart-olm](https://gitlab.com/famedly/libraries/dart-olm) (AGPLv3) Dart bindings
- [Dhole/go-olm](https://github.com/Dhole/go-olm) (Apache-2.0) Go bindings - [Dhole/go-olm](https://github.com/Dhole/go-olm) (Apache-2.0) Go bindings
- [jOlm](https://github.com/brevilo/jolm) (Apache-2.0) Java bindings
- [libQtOlm](https://gitlab.com/b0/libqtolm/) (GPLv3) Qt bindings - [libQtOlm](https://gitlab.com/b0/libqtolm/) (GPLv3) Qt bindings
- [matrix-kt](https://github.com/Dominaezzz/matrix-kt) (Apache-2.0) Kotlin - [matrix-kt](https://github.com/Dominaezzz/matrix-kt) (Apache-2.0) Kotlin
library for Matrix, including Olm methods library for Matrix, including Olm methods
- [maunium.net/go/mautrix/crypto/olm](https://github.com/tulir/mautrix-go/tree/master/crypto/olm) - [maunium.net/go/mautrix/crypto/olm](https://github.com/tulir/mautrix-go/tree/master/crypto/olm)
(Apache-2.0) fork of Dhole/go-olm (Apache-2.0) fork of Dhole/go-olm
- [nim-olm](https://codeberg.org/BarrOff/nim-olm) (MIT) Nim bindings - [nim-olm](https://gitea.com/BarrOff/nim-olm) (MIT) Nim bindings
- [olm-sys](https://gitlab.gnome.org/BrainBlasted/olm-sys) (Apache-2.0) Rust - [olm-sys](https://gitlab.gnome.org/BrainBlasted/olm-sys) (Apache-2.0) Rust
bindings bindings
- [Trixnity](https://gitlab.com/trixnity/trixnity) (Apache-2.0) Kotlin SDK for
Matrix, including Olm bindings
Note that bindings may have a different license from libolm, and are *not* Note that bindings may have a different license from libolm, and are *not*
endorsed by the Matrix.org Foundation C.I.C. endorsed by the Matrix.org Foundation C.I.C.
@ -206,8 +119,8 @@ endorsed by the Matrix.org Foundation C.I.C.
## Release process ## Release process
First: bump version numbers in ``common.mk``, ``CMakeLists.txt``, First: bump version numbers in ``common.mk``, ``CMakeLists.txt``,
``javascript/package.json``, ``python/pyproject.toml``, ``OLMKit.podspec``, ``javascript/package.json``, ``python/olm/__version__.py``, ``OLMKit.podspec``, ``Package.swift``,
``Package.swift``, and ``android/gradle.properties``. and ``android/olm-sdk/java/org/matrix/olm/OlmManager.java`` in function ``getVersion()```.
Also, ensure the changelog is up to date, and that everything is committed to Also, ensure the changelog is up to date, and that everything is committed to
git. git.
@ -247,14 +160,6 @@ Python and JavaScript packages are published to the registry at
documentation contains instructions on how to set up twine (Python) and npm documentation contains instructions on how to set up twine (Python) and npm
(JavaScript) to upload to the registry. (JavaScript) to upload to the registry.
To publish the Android library to MavenCentral (you will need some secrets), in the /android folder:
- Run the command `./gradlew clean build publish --no-daemon --no-parallel --stacktrace`. The generated AAR must be approx 500 kb.
- Connect to https://s01.oss.sonatype.org
- Click on Staging Repositories and check the the files have been uploaded
- Click on close
- Wait (check Activity tab until step "Repository closed" is displayed)
- Click on release. The staging repository will disappear
- Check that the release is available in https://repo1.maven.org/maven2/org/matrix/android/olm-sdk/ (it can take a few minutes)
## Design ## Design
@ -307,13 +212,9 @@ about it at
https://www.nccgroup.com/globalassets/our-research/us/public-reports/2016/november/ncc_group_olm_cryptogrpahic_review_2016_11_01.pdf https://www.nccgroup.com/globalassets/our-research/us/public-reports/2016/november/ncc_group_olm_cryptogrpahic_review_2016_11_01.pdf
and https://matrix.org/blog/2016/11/21/matrixs-olm-end-to-end-encryption-security-assessment-released-and-implemented-cross-platform-on-riot-at-last/ and https://matrix.org/blog/2016/11/21/matrixs-olm-end-to-end-encryption-security-assessment-released-and-implemented-cross-platform-on-riot-at-last/
## Security issues
If you think you found a security issue in libolm, any of its bindings or the Olm/Megolm protocols, please follow our [Security Disclosure Policy](https://matrix.org/security-disclosure-policy/) to report.
## Bug reports ## Bug reports
For non-sensitive bugs, please file bug reports at https://github.com/matrix-org/olm/issues. Please file bug reports at https://github.com/matrix-org/olm/issues
## What's an olm? ## What's an olm?

View file

@ -1,29 +0,0 @@
# Cross-compile for Windows (64-bit) using Mingw-w64
# Build using:
# cmake . -Bbuild -DCMAKE_TOOLCHAIN_FILE=Windows64.cmake
# cmake --build build
# from @ticho:cyberdi.sk
# https://paste.debian.net/1201338/
# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Windows)
# which compilers to use for C and C++
SET(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc-posix)
SET(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++-posix)
SET(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# static-link against the standard libraries
set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++")

BIN
android/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -1,46 +0,0 @@
# TODO: consider replacing this with a smaller image
image: docker.io/inovex/gitlab-ci-android
stages:
- build
- test
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
before_script:
- export GRADLE_USER_HOME=$(pwd)/.gradle
- export ANDROID_HOME=${ANDROID_SDK_HOME}
- echo "sdk.dir=${ANDROID_SDK_HOME}" > ./android/local.properties
- echo "ndk.dir=${ANDROID_NDK_HOME}" >> ./android/local.properties
- cp -R $ANDROID_SDK_ROOT/licenses ./android/.
- chmod +x ./android/gradlew
cache:
key: ${CI_PROJECT_ID}
paths:
- android/.gradle/
build:android:aar:
stage: build
tags:
- docker
script:
- pushd android
- ./gradlew clean assembleRelease
artifacts:
expire_in: 1 weeks
paths:
- android/olm-sdk/build/outputs/aar/*.aar
- android/local.properties
test:android:aar:
stage: test
tags:
- docker
script:
- pushd android
- ./gradlew assembleAndroidTest
# TODO: Add emulator to run tests
needs:
- build:android:aar

View file

@ -5,16 +5,20 @@ OlmLibSdk exposes an android wrapper to libolm.
Installation Installation
------------ ------------
Create a libs directory in your project directory
Copy the olm-sdk.aar into it.
Android Olm library is released on MavenCentral. In your build.gradle file, add in the android section::
Add this dependency to your project: repositories {
flatDir {
dir 'libs'
}
}
```groovy Add in the dependencies category::
implementation "org.matrix.android:olm:3.2.8"
```
Latest version: ![Latest version](https://img.shields.io/maven-central/v/org.matrix.android/olm) compile(name: 'olm-sdk', ext: 'aar')
Development Development
----------- -----------

View file

@ -6,10 +6,8 @@ buildscript {
google() google()
} }
dependencies { dependencies {
// Release notes of Android Gradle Plugin (AGP): classpath 'com.android.tools.build:gradle:4.1.3'
// https://developer.android.com/studio/releases/gradle-plugin
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.18.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
} }
@ -20,17 +18,6 @@ allprojects {
mavenCentral() mavenCentral()
google() google()
} }
plugins.withId("com.vanniktech.maven.publish.base") {
group = project.getProperties().getOrDefault("GROUP", "0.0.0")
version = project.getProperties().getOrDefault("VERSION_NAME", "name")
mavenPublishing {
publishToMavenCentral("S01")
pomFromGradleProperties()
signAllPublications()
}
}
} }
task clean(type: Delete) { task clean(type: Delete) {

View file

@ -21,29 +21,3 @@
android.useAndroidX=true android.useAndroidX=true
org.gradle.configureondemand=false org.gradle.configureondemand=false
# Maven publication
# Ref: https://github.com/vanniktech/gradle-maven-publish-plugin
GROUP=org.matrix.android
POM_ARTIFACT_ID=olm
VERSION_NAME=3.2.16
POM_PACKAGING=aar
POM_NAME=Olm Android wrapper
POM_DESCRIPTION=An Android wrapper to libolm.
POM_INCEPTION_YEAR=2021
POM_URL=https://gitlab.matrix.org/matrix-org/olm
POM_LICENSE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo
POM_SCM_URL=https://gitlab.matrix.org/matrix-org/olm
POM_SCM_CONNECTION=scm:git:https://gitlab.matrix.org/matrix-org/olm.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://git@gitlab.int.matrix.org:matrix-org/olm.git
POM_DEVELOPER_ID=matrixdev
POM_DEVELOPER_NAME=matrixdev
POM_DEVELOPER_URL=https://gitlab.matrix.org/matrix-org
POM_DEVELOPER_EMAIL=android@element.io

View file

@ -1,6 +1,7 @@
#Thu Oct 13 09:38:01 CEST 2016
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionSha256Sum=c9490e938b221daf0094982288e4038deed954a3f12fb54cbf270ddf4e37d879 distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip distributionSha256Sum=81003f83b0056d20eedf48cddd4f52a9813163d4ba185bcf8abd34b8eeea4cbd
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View file

@ -1,26 +1,26 @@
import org.apache.tools.ant.taskdefs.condition.Os
import com.vanniktech.maven.publish.AndroidLibrary
import com.vanniktech.maven.publish.JavadocJar
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
apply plugin: "com.vanniktech.maven.publish.base"
android { android {
compileSdk 31 compileSdkVersion 30
defaultConfig { defaultConfig {
minSdk 14 minSdkVersion 16
targetSdk 31 targetSdkVersion 30
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField "String", "OLM_VERSION", "\"${project.getProperties().getOrDefault("VERSION_NAME", "0.0.0")}\""
// The following argument makes the Android Test Orchestrator run its // The following argument makes the Android Test Orchestrator run its
// "pm clear" command after each test invocation. This command ensures // "pm clear" command after each test invocation. This command ensures
// that the app's state is completely cleared between tests. // that the app's state is completely cleared between tests.
testInstrumentationRunnerArguments clearPackageData: 'true' testInstrumentationRunnerArguments clearPackageData: 'true'
buildConfigField "String", "OLM_VERSION", "\"${project.getProperties().getOrDefault("VERSION_NAME", "0.0.0")}\"" externalNativeBuild {
cmake {
arguments '-DCMAKE_C_FLAGS=-fstack-protector-all -Wall',
'-DCMAKE_CXX_FLAGS=-fstack-protector-all -Wall',
'-DOLM_ANDROID_JNI=on',
'-DOLM_TESTS=off'
}
}
} }
buildTypes { buildTypes {
debug { debug {
@ -38,9 +38,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
} }
sourceSets.main { externalNativeBuild {
jniLibs.srcDir 'src/main/libs' cmake {
jni.srcDirs = [] path '../../CMakeLists.txt'
}
} }
task buildJavaDoc(type: Javadoc) { task buildJavaDoc(type: Javadoc) {
@ -51,58 +52,11 @@ android {
failOnError false failOnError false
} }
task ndkBuildNativeRelease(type: Exec, description: 'NDK building..') {
println 'ndkBuildNativeRelease starts..'
workingDir file('src/main')
commandLine getNdkBuildCmd(), 'NDK_DEBUG=0'
}
task ndkBuildNativeDebug(type: Exec, description: 'NDK building..') {
println 'ndkBuildNativeDebug starts..'
workingDir file('src/main')
commandLine getNdkBuildCmd(), 'NDK_DEBUG=1'
}
task cleanNative(type: Exec, description: 'Clean NDK build') {
workingDir file('src/main')
commandLine getNdkBuildCmd(), 'clean'
}
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {
compileTask -> compileTask ->
if (compileTask.name.startsWith('compileDebugJava')) {
println 'test compile: Debug'
compileTask.dependsOn ndkBuildNativeDebug
} else if (compileTask.name.startsWith('compileReleaseJava')) {
println 'test compile: Release'
compileTask.dependsOn ndkBuildNativeRelease
}
compileTask.dependsOn buildJavaDoc compileTask.dependsOn buildJavaDoc
} }
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
android.libraryVariants.all { variant ->
if (variant.name == 'release') {
owner.classpath += variant.javaCompileProvider.get().classpath
}
}
exclude '**/R.html', '**/R.*.html', '**/index.html'
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
archiveClassifier.set('javadoc')
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
archiveClassifier.set('sources')
from android.sourceSets.main.java.srcDirs
}
clean.dependsOn cleanNative
libraryVariants.all { variant -> libraryVariants.all { variant ->
variant.outputs.each { output -> variant.outputs.each { output ->
@ -112,29 +66,6 @@ android {
} }
} }
} }
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}
def getNdkFolder() {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkFolder = properties.getProperty('ndk.dir', null)
if (ndkFolder == null)
throw new GradleException("NDK location missing. Define it with ndk.dir in the local.properties file")
return ndkFolder
}
def getNdkBuildCmd() {
def ndkBuildCmd = getNdkFolder() + "/ndk-build"
if (Os.isFamily(Os.FAMILY_WINDOWS))
ndkBuildCmd += ".cmd"
return ndkBuildCmd
} }
def gitRevision() { def gitRevision() {
@ -156,12 +87,8 @@ dependencies {
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'junit:junit:4.13.2' androidTestImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:core:1.4.0' androidTestImplementation 'androidx.test:core:1.3.0'
androidTestImplementation 'androidx.test:runner:1.4.0' androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test:rules:1.4.0' androidTestImplementation 'androidx.test:rules:1.3.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.ext:junit:1.1.2'
}
mavenPublishing {
configure(new AndroidLibrary(new JavadocJar.Empty(), false))
} }

View file

@ -488,19 +488,4 @@ public class OlmAccountTest {
fail(e.getMessage()); fail(e.getMessage());
} }
} }
@Test
public void test18GenerateFallbackKey() {
try {
OlmAccount account1 = new OlmAccount();
account1.generateFallbackKey();
Map<String, Map<String, String>> fallbackKeyMap = account1.fallbackKey();
assertNotNull(fallbackKeyMap);
assertEquals(1, fallbackKeyMap.size());
} catch (OlmException e) {
fail(e.getMessage());
}
}
} }

View file

@ -1011,75 +1011,4 @@ public class OlmSessionTest {
assertTrue(bobSession.isReleased()); assertTrue(bobSession.isReleased());
} }
@Test
public void test07AliceBobSessionDescribe() {
// creates alice & bob accounts
OlmAccount aliceAccount = null;
OlmAccount bobAccount = null;
try {
aliceAccount = new OlmAccount();
bobAccount = new OlmAccount();
} catch (OlmException e) {
fail(e.getMessage());
}
// test accounts creation
assertTrue(0 != bobAccount.getOlmAccountId());
assertTrue(0 != aliceAccount.getOlmAccountId());
// CREATE ALICE SESSION
OlmSession aliceSession = null;
try {
aliceSession = new OlmSession();
} catch (OlmException e) {
fail("Exception Msg=" + e.getMessage());
}
assertTrue(0 != aliceSession.getOlmSessionId());
// CREATE ALICE SESSION
OlmSession bobSession = null;
try {
bobSession = new OlmSession();
} catch (OlmException e) {
e.printStackTrace();
fail(e.getMessage());
}
assertTrue(0 != bobSession.getOlmSessionId());
String aliceSessionDescribe = null;
try {
aliceSessionDescribe = aliceSession.sessionDescribe();
} catch (Exception e) {
fail(e.getMessage());
}
assertNotNull(aliceSessionDescribe);
String bobSessionDescribe = null;
try {
bobSessionDescribe = bobSession.sessionDescribe();
} catch (Exception e) {
fail(e.getMessage());
}
assertNotNull(bobSessionDescribe);
// must be the same for both ends of the conversation
assertEquals(aliceSessionDescribe, bobSessionDescribe);
assertEquals(
"sender chain index: 0 receiver chain indices: skipped message keys:",
aliceSessionDescribe
);
aliceAccount.releaseAccount();
bobAccount.releaseAccount();
assertTrue(aliceAccount.isReleased());
assertTrue(bobAccount.isReleased());
bobSession.releaseSession();
aliceSession.releaseSession();
assertTrue(bobSession.isReleased());
assertTrue(aliceSession.isReleased());
}
} }

View file

@ -114,11 +114,11 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
/** /**
* Return the identity keys (identity and fingerprint keys) in a dictionary.<br> * Return the identity keys (identity and fingerprint keys) in a dictionary.<br>
* Public API for {@link #identityKeysJni()}.<br> * Public API for {@link #identityKeysJni()}.<br>
* Ex:<code> * Ex:<tt>
* { * {
* "curve25519":"Vam++zZPMqDQM6ANKpO/uAl5ViJSHxV9hd+b0/fwRAg", * "curve25519":"Vam++zZPMqDQM6ANKpO/uAl5ViJSHxV9hd+b0/fwRAg",
* "ed25519":"+v8SOlOASFTMrX3MCKBM4iVnYoZ+JIjpNt1fi8Z9O2I" * "ed25519":"+v8SOlOASFTMrX3MCKBM4iVnYoZ+JIjpNt1fi8Z9O2I"
* }</code> * }</tt>
* @return identity keys dictionary if operation succeeds, null otherwise * @return identity keys dictionary if operation succeeds, null otherwise
* @exception OlmException the failure reason * @exception OlmException the failure reason
*/ */
@ -195,14 +195,14 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
/** /**
* Return the "one time keys" in a dictionary.<br> * Return the "one time keys" in a dictionary.<br>
* The number of "one time keys", is specified by {@link #generateOneTimeKeys(int)}<br> * The number of "one time keys", is specified by {@link #generateOneTimeKeys(int)}<br>
* Ex:<code> * Ex:<tt>
* { "curve25519": * { "curve25519":
* { * {
* "AAAABQ":"qefVZd8qvjOpsFzoKSAdfUnJVkIreyxWFlipCHjSQQg", * "AAAABQ":"qefVZd8qvjOpsFzoKSAdfUnJVkIreyxWFlipCHjSQQg",
* "AAAABA":"/X8szMU+p+lsTnr56wKjaLgjTMQQkCk8EIWEAilZtQ8", * "AAAABA":"/X8szMU+p+lsTnr56wKjaLgjTMQQkCk8EIWEAilZtQ8",
* "AAAAAw":"qxNxxFHzevFntaaPdT0fhhO7tc7pco4+xB/5VRG81hA", * "AAAAAw":"qxNxxFHzevFntaaPdT0fhhO7tc7pco4+xB/5VRG81hA",
* } * }
* }</code><br> * }</tt><br>
* Public API for {@link #oneTimeKeysJni()}.<br> * Public API for {@link #oneTimeKeysJni()}.<br>
* Note: these keys are to be published on the server. * Note: these keys are to be published on the server.
* @return one time keys in string dictionary. * @return one time keys in string dictionary.
@ -234,7 +234,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
/** /**
* Get the public parts of the unpublished "one time keys" for the account.<br> * Get the public parts of the unpublished "one time keys" for the account.<br>
* The returned data is a JSON-formatted object with the single property * The returned data is a JSON-formatted object with the single property
* <code>curve25519</code>, which is itself an object mapping key id to * <tt>curve25519</tt>, which is itself an object mapping key id to
* base64-encoded Curve25519 key.<br> * base64-encoded Curve25519 key.<br>
* @return byte array containing the one time keys or throw an exception if it fails * @return byte array containing the one time keys or throw an exception if it fails
*/ */
@ -417,99 +417,4 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
* @return the deserialized account * @return the deserialized account
**/ **/
private native long deserializeJni(byte[] aSerializedDataBuffer, byte[] aKeyBuffer); private native long deserializeJni(byte[] aSerializedDataBuffer, byte[] aKeyBuffer);
/**
* Return a pickled account as a bytes buffer.<br>
* The account is serialized and encrypted with aKey.
* In case of failure, an error human readable
* description is provide in aErrorMsg.
* @param aKey encryption key
* @param aErrorMsg error message description
* @return the pickled account as bytes buffer
*/
public byte[] pickle(byte[] aKey, StringBuffer aErrorMsg) {
return serialize(aKey, aErrorMsg);
}
/**
* Loads an account from a pickled bytes buffer.<br>
* See {@link #serialize(byte[], StringBuffer)}
* @param aSerializedData bytes buffer
* @param aKey key used to encrypted
* @exception Exception the exception
*/
public void unpickle(byte[] aSerializedData, byte[] aKey) throws Exception {
deserialize(aSerializedData, aKey);
}
/**
* Generates a new fallback key.
* @throws OlmException exception with a reason.
*/
public void generateFallbackKey() throws OlmException {
try {
generateFallbackKeyJni();
} catch (Exception e) {
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_GENERATE_FALLBACK_KEY, e.getMessage());
}
}
private native void generateFallbackKeyJni();
/**
* Return the "fallback key" in a dictionary.<br>
* Ex:<code>
* { "curve25519":
* {
* "AAAABQ":"qefVZd8qvjOpsFzoKSAdfUnJVkIreyxWFlipCHjSQQg"
* }
* }</code><br>
* Public API for {@link #fallbackKeyJni()}.<br>
* Note: the key is to be published on the server.
* @return fallback key in string dictionary.
* @exception OlmException the failure reason
*/
public Map<String, Map<String, String>> fallbackKey() throws OlmException {
JSONObject fallbackKeyJsonObj = null;
byte[] fallbackKeyBuffer;
try {
fallbackKeyBuffer = fallbackKeyJni();
} catch (Exception e) {
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_FALLBACK_KEY, e.getMessage());
}
if( null != fallbackKeyBuffer) {
try {
fallbackKeyJsonObj = new JSONObject(new String(fallbackKeyBuffer, "UTF-8"));
} catch (Exception e) {
Log.e(LOG_TAG, "## fallbackKey(): Exception - Msg=" + e.getMessage());
}
} else {
Log.e(LOG_TAG, "## fallbackKey(): Failure - identityKeysJni()=null");
}
return OlmUtility.toStringMapMap(fallbackKeyJsonObj);
}
private native byte[] fallbackKeyJni();
/**
* Forget about the old fallback key.
*
* This should be called once you are reasonably certain that you will not
* receive any more messages that use the old fallback key (e.g. 5 minutes
* after the new fallback key has been published).
* @throws OlmException the failure reason
**/
public void forgetFallbackKey() throws OlmException {
try {
forgetFallbackKeyJni();
} catch (Exception e) {
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_FORGET_FALLBACK_KEY, e.getMessage());
}
}
private native void forgetFallbackKeyJni();
} }

View file

@ -35,9 +35,6 @@ public class OlmException extends IOException {
public static final int EXCEPTION_CODE_ACCOUNT_REMOVE_ONE_TIME_KEYS = 105; public static final int EXCEPTION_CODE_ACCOUNT_REMOVE_ONE_TIME_KEYS = 105;
public static final int EXCEPTION_CODE_ACCOUNT_MARK_ONE_KEYS_AS_PUBLISHED = 106; public static final int EXCEPTION_CODE_ACCOUNT_MARK_ONE_KEYS_AS_PUBLISHED = 106;
public static final int EXCEPTION_CODE_ACCOUNT_SIGN_MESSAGE = 107; public static final int EXCEPTION_CODE_ACCOUNT_SIGN_MESSAGE = 107;
public static final int EXCEPTION_CODE_ACCOUNT_GENERATE_FALLBACK_KEY = 108;
public static final int EXCEPTION_CODE_ACCOUNT_FALLBACK_KEY = 109;
public static final int EXCEPTION_CODE_ACCOUNT_FORGET_FALLBACK_KEY = 110;
public static final int EXCEPTION_CODE_CREATE_INBOUND_GROUP_SESSION = 200; public static final int EXCEPTION_CODE_CREATE_INBOUND_GROUP_SESSION = 200;
public static final int EXCEPTION_CODE_INIT_INBOUND_GROUP_SESSION = 201; public static final int EXCEPTION_CODE_INIT_INBOUND_GROUP_SESSION = 201;
@ -60,7 +57,6 @@ public class OlmException extends IOException {
public static final int EXCEPTION_CODE_SESSION_ENCRYPT_MESSAGE = 404; public static final int EXCEPTION_CODE_SESSION_ENCRYPT_MESSAGE = 404;
public static final int EXCEPTION_CODE_SESSION_DECRYPT_MESSAGE = 405; public static final int EXCEPTION_CODE_SESSION_DECRYPT_MESSAGE = 405;
public static final int EXCEPTION_CODE_SESSION_SESSION_IDENTIFIER = 406; public static final int EXCEPTION_CODE_SESSION_SESSION_IDENTIFIER = 406;
public static final int EXCEPTION_CODE_SESSION_SESSION_DESCRIBE = 407;
public static final int EXCEPTION_CODE_UTILITY_CREATION = 500; public static final int EXCEPTION_CODE_UTILITY_CREATION = 500;
public static final int EXCEPTION_CODE_UTILITY_VERIFY_SIGNATURE = 501; public static final int EXCEPTION_CODE_UTILITY_VERIFY_SIGNATURE = 501;

View file

@ -369,29 +369,4 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
* @return the deserialized session * @return the deserialized session
**/ **/
private native long deserializeJni(byte[] aSerializedData, byte[] aKey); private native long deserializeJni(byte[] aSerializedData, byte[] aKey);
/**
* Return a pickled inbound group session as a bytes buffer.<br>
* The session is serialized and encrypted with aKey.
* In case of failure, an error human readable
* description is provide in aErrorMsg.
* @param aKey encryption key
* @param aErrorMsg error message description
* @return the pickled inbound group session as bytes buffer
*/
public byte[] pickle(byte[] aKey, StringBuffer aErrorMsg) {
return serialize(aKey, aErrorMsg);
}
/**
* Loads an inbound group session from a pickled bytes buffer.<br>
* See {@link #serialize(byte[], StringBuffer)}
* @param aSerializedData bytes buffer
* @param aKey key used to encrypted
* @exception Exception the exception
*/
public void unpickle(byte[] aSerializedData, byte[] aKey) throws Exception {
deserialize(aSerializedData, aKey);
}
} }

View file

@ -46,7 +46,7 @@ public class OlmManager {
* @return the library version * @return the library version
*/ */
public String getVersion() { public String getVersion() {
return BuildConfig.OLM_VERSION; return "3.2.2";
} }
/** /**

View file

@ -293,28 +293,4 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
**/ **/
private native long deserializeJni(byte[] aSerializedData, byte[] aKey); private native long deserializeJni(byte[] aSerializedData, byte[] aKey);
/**
* Return a pickled outbound group session as a bytes buffer.<br>
* The session is serialized and encrypted with aKey.
* In case of failure, an error human readable
* description is provide in aErrorMsg.
* @param aKey encryption key
* @param aErrorMsg error message description
* @return the pickled outbound group session as bytes buffer
*/
public byte[] pickle(byte[] aKey, StringBuffer aErrorMsg) {
return serialize(aKey, aErrorMsg);
}
/**
* Loads an outbound group session from a pickled bytes buffer.<br>
* See {@link #serialize(byte[], StringBuffer)}
* @param aSerializedData bytes buffer
* @param aKey key used to encrypted
* @exception Exception the exception
*/
public void unpickle(byte[] aSerializedData, byte[] aKey) throws Exception {
deserialize(aSerializedData, aKey);
}
} }

View file

@ -106,16 +106,6 @@ public class OlmSAS {
return null; return null;
} }
public String calculateMacFixedBase64(String message, String info) throws OlmException {
try {
byte[] bytes = calculateMacFixedBase64Jni(message.getBytes("UTF-8"), info.getBytes("UTF-8"));
if (bytes != null) return new String(bytes, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new OlmException(OlmException.EXCEPTION_CODE_SAS_ERROR, e.getMessage());
}
return null;
}
public String calculateMacLongKdf(String message, String info) throws OlmException { public String calculateMacLongKdf(String message, String info) throws OlmException {
try { try {
byte[] bytes = calculateMacLongKdfJni(message.getBytes("UTF-8"), info.getBytes("UTF-8")); byte[] bytes = calculateMacLongKdfJni(message.getBytes("UTF-8"), info.getBytes("UTF-8"));
@ -150,8 +140,6 @@ public class OlmSAS {
private native byte[] calculateMacJni(byte[] message, byte[] info); private native byte[] calculateMacJni(byte[] message, byte[] info);
private native byte[] calculateMacFixedBase64Jni(byte[] message, byte[] info);
private native byte[] calculateMacLongKdfJni(byte[] message, byte[] info); private native byte[] calculateMacLongKdfJni(byte[] message, byte[] info);
/** /**

View file

@ -223,23 +223,6 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
*/ */
private native byte[] getSessionIdentifierJni(); private native byte[] getSessionIdentifierJni();
public String sessionDescribe() throws OlmException {
try {
byte[] buffer = olmSessionDescribeJni();
if (null != buffer) {
return new String(buffer, "UTF-8");
}
} catch (Exception e) {
Log.e(LOG_TAG, "## sessionDescribe(): " + e.getMessage());
throw new OlmException(OlmException.EXCEPTION_CODE_SESSION_SESSION_DESCRIBE, e.getMessage());
}
return null;
}
private native byte[] olmSessionDescribeJni();
/** /**
* Checks if the PRE_KEY({@link OlmMessage#MESSAGE_TYPE_PRE_KEY}) message is for this in-bound session.<br> * Checks if the PRE_KEY({@link OlmMessage#MESSAGE_TYPE_PRE_KEY}) message is for this in-bound session.<br>
* This API may be used to process a "m.room.encrypted" event when type = 1 (PRE_KEY). * This API may be used to process a "m.room.encrypted" event when type = 1 (PRE_KEY).
@ -465,30 +448,5 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
* @return the deserialized session * @return the deserialized session
**/ **/
private native long deserializeJni(byte[] aSerializedData, byte[] aKey); private native long deserializeJni(byte[] aSerializedData, byte[] aKey);
/**
* Return a pickled session as a bytes buffer.<br>
* The session is serialized and encrypted with aKey.
* In case of failure, an error human readable
* description is provide in aErrorMsg.
* @param aKey encryption key
* @param aErrorMsg error message description
* @return the pickled session as bytes buffer
*/
public byte[] pickle(byte[] aKey, StringBuffer aErrorMsg) {
return serialize(aKey, aErrorMsg);
}
/**
* Loads a session from a pickled bytes buffer.<br>
* See {@link #serialize(byte[], StringBuffer)}
* @param aSerializedData bytes buffer
* @param aKey key used to encrypted
* @exception Exception the exception
*/
public void unpickle(byte[] aSerializedData, byte[] aKey) throws Exception {
deserialize(aSerializedData, aKey);
}
} }

View file

@ -1,67 +0,0 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := olm
SRC_ROOT_DIR := ../../../../..
include $(LOCAL_PATH)/$(SRC_ROOT_DIR)/common.mk
OLM_VERSION := $(MAJOR).$(MINOR).$(PATCH)
$(info LOCAL_PATH=$(LOCAL_PATH))
$(info SRC_ROOT_DIR=$(SRC_ROOT_DIR))
$(info OLM_VERSION=$(OLM_VERSION))
LOCAL_CPPFLAGS+= -std=c++11 -Wall
LOCAL_CONLYFLAGS+= -std=c99
LOCAL_CFLAGS+= -DOLMLIB_VERSION_MAJOR=$(MAJOR) \
-DOLMLIB_VERSION_MINOR=$(MINOR) \
-DOLMLIB_VERSION_PATCH=$(PATCH)
#LOCAL_CFLAGS+= -DNDK_DEBUG
LOCAL_CFLAGS+=-fstack-protector-all -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Wall
LOCAL_LDFLAGS=-z relro -z now
LOCAL_C_INCLUDES+= $(LOCAL_PATH)/$(SRC_ROOT_DIR)/include/ \
$(LOCAL_PATH)/$(SRC_ROOT_DIR)/lib
$(info LOCAL_C_INCLUDES=$(LOCAL_C_INCLUDES))
LOCAL_SRC_FILES := $(SRC_ROOT_DIR)/src/account.cpp \
$(SRC_ROOT_DIR)/src/base64.cpp \
$(SRC_ROOT_DIR)/src/cipher.cpp \
$(SRC_ROOT_DIR)/src/crypto.cpp \
$(SRC_ROOT_DIR)/src/memory.cpp \
$(SRC_ROOT_DIR)/src/message.cpp \
$(SRC_ROOT_DIR)/src/olm.cpp \
$(SRC_ROOT_DIR)/src/pickle.cpp \
$(SRC_ROOT_DIR)/src/ratchet.cpp \
$(SRC_ROOT_DIR)/src/session.cpp \
$(SRC_ROOT_DIR)/src/utility.cpp \
$(SRC_ROOT_DIR)/src/pk.cpp \
$(SRC_ROOT_DIR)/src/sas.c \
$(SRC_ROOT_DIR)/src/ed25519.c \
$(SRC_ROOT_DIR)/src/error.c \
$(SRC_ROOT_DIR)/src/inbound_group_session.c \
$(SRC_ROOT_DIR)/src/megolm.c \
$(SRC_ROOT_DIR)/src/outbound_group_session.c \
$(SRC_ROOT_DIR)/src/pickle_encoding.c \
$(SRC_ROOT_DIR)/lib/crypto-algorithms/sha256.c \
$(SRC_ROOT_DIR)/lib/crypto-algorithms/aes.c \
$(SRC_ROOT_DIR)/lib/curve25519-donna/curve25519-donna.c \
olm_account.cpp \
olm_session.cpp \
olm_jni_helper.cpp \
olm_inbound_group_session.cpp \
olm_outbound_group_session.cpp \
olm_utility.cpp \
olm_manager.cpp \
olm_pk.cpp \
olm_sas.cpp
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)

View file

@ -1,3 +0,0 @@
APP_PLATFORM := android-16
APP_ABI := arm64-v8a armeabi-v7a x86_64 x86
APP_STL := c++_static

View file

@ -1,4 +1,4 @@
MAJOR := 3 MAJOR := 3
MINOR := 2 MINOR := 2
PATCH := 16 PATCH := 2

View file

@ -109,7 +109,7 @@ discriminate between sessions.
### Sharing session data ### Sharing session data
To allow other participants in the conversation to decrypt messages, the To allow other participants in the conversation to decrypt messages, the
session data is formatted as described in [Session-sharing format](#session-sharing-format). It is then session data is formatted as described in [Session-sharing format](#Session-sharing-format). It is then
shared with other participants in the conversation via a secure peer-to-peer shared with other participants in the conversation via a secure peer-to-peer
channel (such as that provided by [Olm][]). channel (such as that provided by [Olm][]).
@ -182,13 +182,9 @@ but the decision of which ratchet states to cache is left to the application.
## Data exchange formats ## Data exchange formats
### Session sharing format ### Session-sharing format
This format is used for the initial sharing of a Megolm session with other The Megolm key-sharing format is as follows:
group participants who need to be able to read messages encrypted by this
session.
The session sharing format is as follows:
``` ```
+---+----+--------+--------+--------+--------+------+-----------+ +---+----+--------+--------+--------+--------+------+-----------+
@ -206,33 +202,6 @@ part of the Ed25519 keypair $`K`$.
The data is then signed using the Ed25519 keypair, and the 64-byte signature is The data is then signed using the Ed25519 keypair, and the 64-byte signature is
appended. appended.
### Session export format
Once the session is initially shared with the group participants, each
participant needs to retain a copy of the session if they want to maintain
their ability to decrypt messages encrypted with that session.
For forward-secrecy purposes, a participant may choose to store a ratcheted
version of the session. But since the ratchet index is covered by the
signature, this would invalidate the signature. So we define a similar format,
called the *session export format*, which is identical to the [session sharing
format](#session-sharing-format) except for dropping the signature.
The Megolm session export format is thus as follows:
```
+---+----+--------+--------+--------+--------+------+
| V | i | R(i,0) | R(i,1) | R(i,2) | R(i,3) | Kpub |
+---+----+--------+--------+--------+--------+------+
0 1 5 37 69 101 133 165 bytes
```
The version byte, ``V``, is ``"\x01"``.
This is followed by the ratchet index, $`i`$, which is encoded as a
big-endian 32-bit integer; the ratchet values $`R_{i,j}`$; and the public
part of the Ed25519 keypair $`K`$.
### Message format ### Message format
Megolm messages consist of a one byte version, followed by a variable length Megolm messages consist of a one byte version, followed by a variable length

View file

@ -1,10 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python
import sys import sys
import re import re
import json import json
expr = re.compile(r"(_*olm_[^( ]*)\(") expr = re.compile(r"(olm_[^( ]*)\(")
exports = {'_free', '_malloc'} exports = {'_free', '_malloc'}

View file

@ -1,60 +0,0 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1664871473,
"narHash": "sha256-1LzbW6G6Uz8akWiOdlIi435GAm1ct5jF5tovw/9to0o=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b7a6fde153d9470afdb6aa1da51c4117f03b84ed",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"npmlock2nix": {
"flake": false,
"locked": {
"lastModified": 1654775747,
"narHash": "sha256-9pXHDpIjmsK5390wmpGHu9aA4QOPpegPBvThHeBlef4=",
"owner": "nix-community",
"repo": "npmlock2nix",
"rev": "5c4f247688fc91d665df65f71c81e0726621aaa8",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "npmlock2nix",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"npmlock2nix": "npmlock2nix"
}
}
},
"root": "root",
"version": 7
}

View file

@ -1,40 +0,0 @@
{
description = "An implementation of the Double Ratchet cryptographic ratchet";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# We can't use the current stable release because of
# https://github.com/emscripten-core/emscripten/issues/16913
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.npmlock2nix = {
url = "github:nix-community/npmlock2nix";
flake = false;
};
outputs = { self, nixpkgs, flake-utils, npmlock2nix }:
let
localOverlay = import ./nix/overlay.nix;
pkgsForSystem = system: import nixpkgs {
inherit system;
overlays = [
(final: prev: {
npmlock2nix = final.callPackage npmlock2nix {};
node_modules = final.npmlock2nix.node_modules { src = ./javascript; };
})
localOverlay
];
};
in (
# some systems cause issues, e.g. i686-linux is unsupported by gradle,
# which causes "nix flake check" to fail. Investigate more later, but for
# now, we will just allow x86_64-linux
flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ] (system: rec {
legacyPackages = pkgsForSystem system;
checks = {
inherit (legacyPackages) olm-gcc-cmake olm-clang-cmake olm-gcc-make;
};
packages = {
javascript = legacyPackages.olm-javascript;
};
}
));
}

View file

@ -11,6 +11,4 @@ int main(int argc, const char *argv[]) {
decode_message(*reader, message_buffer, message_length, 8); decode_message(*reader, message_buffer, message_length, 8);
free(message_buffer); free(message_buffer);
delete reader; delete reader;
return EXIT_SUCCESS;
} }

View file

@ -3,10 +3,11 @@
#include "fuzzing.hh" #include "fuzzing.hh"
int main(int argc, const char *argv[]) { int main(int argc, const char *argv[]) {
size_t ignored;
if (argc <= 3) { if (argc <= 3) {
const char * message = "Usage: decrypt: <session_key> <session_file>" const char * message = "Usage: decrypt: <session_key> <session_file>"
" <message_type>\n"; " <message_type>\n";
(void)write(STDERR_FILENO, message, strlen(message)); ignored = write(STDERR_FILENO, message, strlen(message));
exit(3); exit(3);
} }
@ -58,12 +59,7 @@ int main(int argc, const char *argv[]) {
) )
); );
(void)write(STDOUT_FILENO, plaintext, length); ignored = write(STDOUT_FILENO, plaintext, length);
(void)write(STDOUT_FILENO, "\n", 1); ignored = write(STDOUT_FILENO, "\n", 1);
return ignored;
free(session_buffer);
free(message_buffer);
free(tmp_buffer);
return EXIT_SUCCESS;
} }

View file

@ -0,0 +1,73 @@
#include "olm/olm.hh"
#include "fuzzing.hh"
int main(int argc, const char *argv[]) {
size_t ignored;
if (argc <= 2) {
const char * message = "Usage: decrypt <pickle_key> <group_session>\n";
ignored = write(STDERR_FILENO, message, strlen(message));
exit(3);
}
const char * key = argv[1];
size_t key_length = strlen(key);
int session_fd = check_errno(
"Error opening session file", open(argv[2], O_RDONLY)
);
uint8_t *session_buffer;
ssize_t session_length = check_errno(
"Error reading session file", read_file(session_fd, &session_buffer)
);
int message_fd = STDIN_FILENO;
uint8_t * message_buffer;
ssize_t message_length = check_errno(
"Error reading message file", read_file(message_fd, &message_buffer)
);
uint8_t * tmp_buffer = (uint8_t *) malloc(message_length);
memcpy(tmp_buffer, message_buffer, message_length);
uint8_t session_memory[olm_inbound_group_session_size()];
OlmInboundGroupSession * session = olm_inbound_group_session(session_memory);
check_error(
olm_inbound_group_session_last_error,
session,
"Error unpickling session",
olm_unpickle_inbound_group_session(
session, key, key_length, session_buffer, session_length
)
);
size_t max_length = check_error(
olm_inbound_group_session_last_error,
session,
"Error getting plaintext length",
olm_group_decrypt_max_plaintext_length(
session, tmp_buffer, message_length
)
);
uint8_t plaintext[max_length];
uint32_t ratchet_index;
size_t length = check_error(
olm_inbound_group_session_last_error,
session,
"Error decrypting message",
olm_group_decrypt(
session,
message_buffer, message_length,
plaintext, max_length, &ratchet_index
)
);
ignored = write(STDOUT_FILENO, plaintext, length);
ignored = write(STDOUT_FILENO, "\n", 1);
return ignored;
}

View file

@ -0,0 +1,14 @@
#include "olm/account.hh"
#include "fuzzing.hh"
int main(int argc, const char *argv[]) {
int pickle_fd = STDIN_FILENO;
uint8_t * pickle_buffer;
ssize_t pickle_length = check_errno(
"Error reading pickle file", read_file(pickle_fd, &pickle_buffer)
);
olm::Account * account = new olm::Account;
unpickle(pickle_buffer, pickle_buffer + pickle_length, *account);
free(pickle_buffer);
delete account;
}

View file

@ -11,6 +11,4 @@ int main(int argc, const char *argv[]) {
unpickle(pickle_buffer, pickle_buffer + pickle_length, *session); unpickle(pickle_buffer, pickle_buffer + pickle_length, *session);
free(pickle_buffer); free(pickle_buffer);
delete session; delete session;
return EXIT_SUCCESS;
} }

View file

@ -15,43 +15,28 @@ ssize_t read_file(
uint8_t **buffer uint8_t **buffer
) { ) {
size_t buffer_size = 4096; size_t buffer_size = 4096;
size_t buffer_pos = 0;
uint8_t * current_buffer = (uint8_t *) malloc(buffer_size); uint8_t * current_buffer = (uint8_t *) malloc(buffer_size);
if (!current_buffer) return -1; if (current_buffer == NULL) return -1;
size_t buffer_pos = 0;
while (1) { while (1) {
ssize_t count = read( ssize_t count = read(
fd, current_buffer + buffer_pos, buffer_size - buffer_pos fd, current_buffer + buffer_pos, buffer_size - buffer_pos
); );
if (count < 0) break;
if (count < 0) break; // A read error happened, so just fail immediately.
if (count == 0) { if (count == 0) {
// Nothing more left to read. We downsize the buffer to fit the uint8_t * return_buffer = (uint8_t *) realloc(current_buffer, buffer_pos);
// data exactly, unless no data was read at all, in which case we if (return_buffer == NULL) break;
// skip the downsizing. *buffer = return_buffer;
if (buffer_pos != 0) {
current_buffer = (uint8_t *) realloc(current_buffer, buffer_pos);
if (!current_buffer) break;
}
// The read was successful so we return the allocated buffer.
*buffer = current_buffer;
return buffer_pos; return buffer_pos;
} }
buffer_pos += count; buffer_pos += count;
// We've reached capacity, so enlarge the buffer.
if (buffer_pos == buffer_size) { if (buffer_pos == buffer_size) {
buffer_size *= 2; buffer_size *= 2;
uint8_t * new_buffer = (uint8_t *) realloc(current_buffer, buffer_size); uint8_t * new_buffer = (uint8_t *) realloc(current_buffer, buffer_size);
if (!new_buffer) break; if (new_buffer == NULL) break;
current_buffer = new_buffer; current_buffer = new_buffer;
} }
} }
free(current_buffer); free(current_buffer);
return -1; return -1;
} }
@ -77,12 +62,13 @@ size_t check_error(
) { ) {
if (value == olm_error()) { if (value == olm_error()) {
const char * olm_message = f(object); const char * olm_message = f(object);
(void)write(STDERR_FILENO, message, strlen(message)); ssize_t ignored;
(void)write(STDERR_FILENO, ": ", 2); ignored = write(STDERR_FILENO, message, strlen(message));
(void)write(STDERR_FILENO, olm_message, strlen(olm_message)); ignored = write(STDERR_FILENO, ": ", 2);
(void)write(STDERR_FILENO, "\n", 1); ignored = write(STDERR_FILENO, olm_message, strlen(olm_message));
ignored = write(STDERR_FILENO, "\n", 1);
exit(2); exit(2);
return ignored;
} }
return value; return value;
} }

View file

@ -1,10 +0,0 @@
# Directory structure
- `fuzzers/`: Sources for the fuzzing harnesses.
- `corpora/`: Contains the fuzzing corpora and assorted tools. The corpora are
filed under a directory with the same name as the fuzzing harness. Each of
those directories also contains the following:
- `in/`: Contains the actual corpus test cases.
- `tools/`: Any tools useful for that particular harness. A good example
would be a binary which generates seed test cases.

View file

@ -1,102 +0,0 @@
#include "olm/olm.hh"
#include "fuzzing.hh"
#ifndef __AFL_FUZZ_TESTCASE_LEN
ssize_t fuzz_len;
#define __AFL_FUZZ_TESTCASE_LEN fuzz_len
unsigned char fuzz_buf[1024000];
#define __AFL_FUZZ_TESTCASE_BUF fuzz_buf
#define __AFL_FUZZ_INIT() void sync(void);
#define __AFL_LOOP(x) ((fuzz_len = read(0, fuzz_buf, sizeof(fuzz_buf))) > 0 ? 1 : 0)
#define __AFL_INIT() sync()
#endif
__AFL_FUZZ_INIT();
int main(int argc, const char *argv[]) {
if (argc <= 2) {
const char * message = "Usage: decrypt <pickle_key> <group_session>\n";
(void)write(STDERR_FILENO, message, strlen(message));
exit(3);
}
const char * key = argv[1];
size_t key_length = strlen(key);
int session_fd = check_errno(
"Error opening session file", open(argv[2], O_RDONLY)
);
uint8_t *session_buffer;
ssize_t session_length = check_errno(
"Error reading session file", read_file(session_fd, &session_buffer)
);
uint8_t session_memory[olm_inbound_group_session_size()];
OlmInboundGroupSession * session = olm_inbound_group_session(session_memory);
check_error(
olm_inbound_group_session_last_error,
session,
"Error unpickling session",
olm_unpickle_inbound_group_session(
session, key, key_length, session_buffer, session_length
)
);
#ifdef __AFL_HAVE_MANUAL_CONTROL
__AFL_INIT();
#endif
size_t test_case_buf_len = 1024;
uint8_t * message_buffer = (uint8_t *) malloc(test_case_buf_len);
uint8_t * tmp_buffer = (uint8_t *) malloc(test_case_buf_len);
while (__AFL_LOOP(10000)) {
size_t message_length = __AFL_FUZZ_TESTCASE_LEN;
if (message_length > test_case_buf_len) {
message_buffer = (uint8_t *)realloc(message_buffer, message_length);
tmp_buffer = (uint8_t *)realloc(tmp_buffer, message_length);
if (!message_buffer || !tmp_buffer) return 1;
}
memcpy(message_buffer, __AFL_FUZZ_TESTCASE_BUF, message_length);
memcpy(tmp_buffer, message_buffer, message_length);
size_t max_length = check_error(
olm_inbound_group_session_last_error,
session,
"Error getting plaintext length",
olm_group_decrypt_max_plaintext_length(
session, tmp_buffer, message_length
)
);
uint8_t plaintext[max_length];
uint32_t ratchet_index;
size_t length = check_error(
olm_inbound_group_session_last_error,
session,
"Error decrypting message",
olm_group_decrypt(
session,
message_buffer, message_length,
plaintext, max_length, &ratchet_index
)
);
(void)write(STDOUT_FILENO, plaintext, length);
(void)write(STDOUT_FILENO, "\n", 1);
}
free(session_buffer);
free(message_buffer);
free(tmp_buffer);
return EXIT_SUCCESS;
}

View file

@ -1,41 +0,0 @@
#include "fuzzing.hh"
#include "olm/account.hh"
#include "olm/olm.h"
size_t fuzz_unpickle_account(
OlmAccount * account, void * pickled, size_t pickled_length
) {
olm::Account & object = *reinterpret_cast<olm::Account *>(account);
std::uint8_t * const pos = reinterpret_cast<std::uint8_t *>(pickled);
std::uint8_t * const end = pos + pickled_length;
if (!unpickle(pos, end, object)) {
if (object.last_error == OlmErrorCode::OLM_SUCCESS) {
object.last_error = OlmErrorCode::OLM_CORRUPTED_PICKLE;
}
return std::size_t(-1);
}
return pickled_length;
}
int main(int argc, const char * argv[]) {
int pickle_fd = STDIN_FILENO;
uint8_t * pickle_buffer;
ssize_t pickle_length = check_errno(
"Error reading pickle file", read_file(pickle_fd, &pickle_buffer));
void * account_buf = malloc(olm_account_size());
if (!account_buf) {
return 3;
}
OlmAccount * account = olm_account(account_buf);
check_error(olm_account_last_error, account, "Error unpickling account",
fuzz_unpickle_account(account, pickle_buffer, pickle_length));
free(pickle_buffer);
free(account);
return EXIT_SUCCESS;
}

View file

@ -1,28 +0,0 @@
#include <olm/outbound_group_session.h>
#include "fuzzing.h"
int main(int argc, const char *argv[]) {
if (argc != 1) {
printf("Usage: %s <input_file\n", argv[0]);
exit(3);
}
void *session_buffer = malloc(olm_outbound_group_session_size());
OlmOutboundGroupSession *session = olm_outbound_group_session(session_buffer);
int pickle_fd = STDIN_FILENO;
uint8_t *pickle_buffer;
ssize_t pickle_length = check_errno("Error reading message file",
read_file(pickle_fd, &pickle_buffer));
check_outbound_group_session(
session, "Error unpickling outbound group session",
olm_unpickle_outbound_group_session(session, "", 0, pickle_buffer,
pickle_length));
free(session_buffer);
free(pickle_buffer);
return EXIT_SUCCESS;
}

View file

@ -1,101 +0,0 @@
#include "olm/olm.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stddef.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define OLM_FUZZING 1
ssize_t read_file(
int fd,
uint8_t **buffer
) {
size_t buffer_size = 1;
size_t buffer_pos = 0;
uint8_t * current_buffer = (uint8_t *) malloc(buffer_size);
if (!current_buffer) return -1;
while (1) {
ssize_t count = read(
fd, current_buffer + buffer_pos, buffer_size - buffer_pos
);
if (count < 0) break; // A read error happened, so just fail immediately.
if (count == 0) {
// Nothing more left to read. We downsize the buffer to fit the
// data exactly, unless no data was read at all, in which case we
// skip the downsizing.
if (buffer_pos != 0) {
current_buffer = (uint8_t *) realloc(current_buffer, buffer_pos);
if (!current_buffer) break;
}
// The read was successful so we return the allocated buffer.
*buffer = current_buffer;
return buffer_pos;
}
buffer_pos += count;
// We've reached capacity, so enlarge the buffer.
if (buffer_pos == buffer_size) {
buffer_size *= 2;
uint8_t * new_buffer = (uint8_t *) realloc(current_buffer, buffer_size);
if (!new_buffer) break;
current_buffer = new_buffer;
}
}
free(current_buffer);
return -1;
}
ssize_t check_errno(
const char * message,
ssize_t value
) {
if (value == (ssize_t)-1) {
perror(message);
exit(1);
}
return value;
}
size_t check_error(
const char * message,
const char * olm_message,
size_t value
) {
if (value == olm_error()) {
(void)write(STDERR_FILENO, message, strlen(message));
(void)write(STDERR_FILENO, ": ", 2);
(void)write(STDERR_FILENO, olm_message, strlen(olm_message));
(void)write(STDERR_FILENO, "\n", 1);
exit(2);
}
return value;
}
size_t check_session(
OlmSession * session,
const char * message,
size_t value
) {
return check_error(message, olm_session_last_error(session), value);
}
size_t check_outbound_group_session(
OlmOutboundGroupSession * session,
const char * message,
size_t value
) {
return check_error(message, olm_outbound_group_session_last_error(session), value);
}

View file

@ -1,118 +0,0 @@
#!/usr/bin/bash
# Needs to be started in tmux.
script_dir() {
dirname "$(readlink -f "$0")"
}
fuzzer_dir() {
printf '%s/fuzzers\n' "$(script_dir)"
}
fuzzer_list() {
find "$(fuzzer_dir)" -maxdepth 1 -type f \( -name '*.cpp' -or -name '*.c' \) -printf '%P\n' \
| while read -r fuzzer; do
fuzzer="${fuzzer#fuzz_}"
printf '%s\n' "${fuzzer%.c*}"
done
}
usage() {
printf '%s: HARNESS FUZZER\n\n' "$(basename "$0")"
printf ' HARNESS ∈ {\n'
# We want word-splitting here so that each fuzzer ends up as a separate
# argument.
# shellcheck disable=SC2046
printf '%30s,\n' $(fuzzer_list | tr '\n' ' ')
printf ' }\n'
printf ' FUZZER ∈ {afl, afl++}\n'
}
if [[ $# -ne 2 ]]; then
usage
exit 1
fi
case "$2" in
afl++)
export AFL_PATH=/home/dkasak/code/projects/afl/afl++
export AFL_AUTORESUME=1
AFL_ARGS_FUZZER0="-D"
AFL_ARGS_FUZZER1="-L 0"
AFL_ARGS_FUZZER2="-p rare"
AFL_ARGS_FUZZER3="-p fast"
AFL_ARGS_FUZZER4="-p exploit"
AFL_ARGS_FUZZER5="-p explore"
;;
afl)
export AFL_PATH=/usr/bin
;;
*)
printf 'Unknown fuzzer: %s\n' "$2"
exit 1
;;
esac
export AFL=$AFL_PATH/afl-fuzz
export AFL_TMPDIR=/tmp
case "$1" in
group_decrypt)
FUZZER_ARG1="fuzzing/$1/pickled-inbound-group-session.txt"
;;
decrypt)
FUZZER_ARG1="fuzzing/$1/pickled-session.txt"
FUZZER_ARG2="1"
;;
decode_message)
;;
unpickle_session)
;;
unpickle_account)
;;
unpickle_account_test)
;;
unpickle_megolm_outbound)
;;
*)
printf 'Unknown harness: %s\n' "$1"
exit 1
;;
esac
cd "$(script_dir)" || exit 1
# Fuzzer args are deliberately not quoted below so that word-splitting happens.
# This is used so that they expand into nothing in cases where they are missing
# or to expand into multiple arguments from a string definition.
# shellcheck disable=SC2086
tmux new-window -d -n "M" -- \
"$AFL" -i "corpora/$1/in" -o "corpora/$1/out" -M i0 "$AFL_ARGS_FUZZER0" \
-- "../build/fuzzers/fuzz_$1" $FUZZER_ARG1 $FUZZER_ARG2
# shellcheck disable=SC2086
tmux new-window -d -n "S1" -- \
"$AFL" -i "corpora/$1/in" -o "corpora/$1/out" -S i1 "$AFL_ARGS_FUZZER1" \
-- "../build/fuzzers/fuzz_$1" $FUZZER_ARG1 $FUZZER_ARG2
# shellcheck disable=SC2086
tmux new-window -d -n "S2" -- \
"$AFL" -i "corpora/$1/in" -o "corpora/$1/out" -S i2 $AFL_ARGS_FUZZER2 \
-- "../build/fuzzers/fuzz_$1" $FUZZER_ARG1 $FUZZER_ARG2
# shellcheck disable=SC2086
tmux new-window -d -n "S3" -- \
"$AFL" -i "corpora/$1/in" -o "corpora/$1/out" -S i3 $AFL_ARGS_FUZZER3 \
-- "../build/fuzzers/fuzz_$1" $FUZZER_ARG1 $FUZZER_ARG2
# shellcheck disable=SC2086
tmux new-window -d -n "S4" -- \
"$AFL" -i "corpora/$1/in" -o "corpora/$1/out" -S i4 $AFL_ARGS_FUZZER4 \
-- "../build/fuzzers/fuzz_$1_asan" $FUZZER_ARG1 $FUZZER_ARG2
# shellcheck disable=SC2086
tmux new-window -d -n "S5" -- \
"$AFL" -i "corpora/$1/in" -o "corpora/$1/out" -S i5 $AFL_ARGS_FUZZER5 \
-- "../build/fuzzers/fuzz_$1" $FUZZER_ARG1 $FUZZER_ARG2

View file

@ -1,17 +0,0 @@
function Math(el)
if el.mathtype == "InlineMath" then
if el.text:sub(1,1) == '`' and el.text:sub(#el.text) == '`' then
local text = el.text:sub(2,#el.text-1)
return pandoc.Math(el.mathtype, text)
else
local cont = pandoc.read(el.text)
return { pandoc.Str("$") } .. cont.blocks[1].content .. { pandoc.Str("$") }
end
end
end
function CodeBlock(el)
if el.classes[1] == "math" then
return pandoc.Para({ pandoc.Math("DisplayMath", el.text) })
end
end

View file

@ -43,14 +43,13 @@ struct Account {
Account(); Account();
IdentityKeys identity_keys; IdentityKeys identity_keys;
List<OneTimeKey, MAX_ONE_TIME_KEYS> one_time_keys; List<OneTimeKey, MAX_ONE_TIME_KEYS> one_time_keys;
std::uint8_t num_fallback_keys;
OneTimeKey current_fallback_key; OneTimeKey current_fallback_key;
OneTimeKey prev_fallback_key; OneTimeKey prev_fallback_key;
std::uint32_t next_one_time_key_id; std::uint32_t next_one_time_key_id;
OlmErrorCode last_error; OlmErrorCode last_error;
/** Number of random bytes needed to create a new account */ /** Number of random bytes needed to create a new account */
std::size_t new_account_random_length() const; std::size_t new_account_random_length();
/** Create a new account. Returns std::size_t(-1) on error. If the number of /** Create a new account. Returns std::size_t(-1) on error. If the number of
* random bytes is too small then last_error will be NOT_ENOUGH_RANDOM */ * random bytes is too small then last_error will be NOT_ENOUGH_RANDOM */
@ -59,7 +58,7 @@ struct Account {
); );
/** Number of bytes needed to output the identity keys for this account */ /** Number of bytes needed to output the identity keys for this account */
std::size_t get_identity_json_length() const; std::size_t get_identity_json_length();
/** Output the identity keys for this account as JSON in the following /** Output the identity keys for this account as JSON in the following
* format: * format:
@ -78,7 +77,7 @@ struct Account {
/** /**
* The length of an ed25519 signature in bytes. * The length of an ed25519 signature in bytes.
*/ */
std::size_t signature_length() const; std::size_t signature_length();
/** /**
* Signs a message with the ed25519 key for this account. * Signs a message with the ed25519 key for this account.
@ -89,7 +88,7 @@ struct Account {
); );
/** Number of bytes needed to output the one time keys for this account */ /** Number of bytes needed to output the one time keys for this account */
std::size_t get_one_time_keys_json_length() const; std::size_t get_one_time_keys_json_length();
/** Output the one time keys that haven't been published yet as JSON: /** Output the one time keys that haven't been published yet as JSON:
* *
@ -107,20 +106,18 @@ struct Account {
std::uint8_t * one_time_json, std::size_t one_time_json_length std::uint8_t * one_time_json, std::size_t one_time_json_length
); );
/** Mark the current list of one_time_keys and the current fallback key as /** Mark the current list of one_time_keys as being published. They
* being published. The current one time keys will no longer be returned by * will no longer be returned by get_one_time_keys_json_length(). */
* get_one_time_keys_json() and the current fallback key will no longer be
* returned by get_unpublished_fallback_key_json(). */
std::size_t mark_keys_as_published(); std::size_t mark_keys_as_published();
/** The largest number of one time keys this account can store. */ /** The largest number of one time keys this account can store. */
std::size_t max_number_of_one_time_keys() const; std::size_t max_number_of_one_time_keys();
/** The number of random bytes needed to generate a given number of new one /** The number of random bytes needed to generate a given number of new one
* time keys. */ * time keys. */
std::size_t generate_one_time_keys_random_length( std::size_t generate_one_time_keys_random_length(
std::size_t number_of_keys std::size_t number_of_keys
) const; );
/** Generates a number of new one time keys. If the total number of keys /** Generates a number of new one time keys. If the total number of keys
* stored by this account exceeds max_number_of_one_time_keys() then the * stored by this account exceeds max_number_of_one_time_keys() then the
@ -132,7 +129,7 @@ struct Account {
); );
/** The number of random bytes needed to generate a fallback key. */ /** The number of random bytes needed to generate a fallback key. */
std::size_t generate_fallback_key_random_length() const; std::size_t generate_fallback_key_random_length();
/** Generates a new fallback key. Returns std::size_t(-1) on error. If the /** Generates a new fallback key. Returns std::size_t(-1) on error. If the
* number of random bytes is too small then last_error will be * number of random bytes is too small then last_error will be
@ -141,17 +138,8 @@ struct Account {
std::uint8_t const * random, std::size_t random_length std::uint8_t const * random, std::size_t random_length
); );
/** Number of bytes needed to output the fallback keys for this account */ /** Number of bytes needed to output the one time keys for this account */
std::size_t get_fallback_key_json_length() const; std::size_t get_fallback_key_json_length();
/** Deprecated: use get_unpublished_fallback_key_json instead */
std::size_t get_fallback_key_json(
std::uint8_t * fallback_json, std::size_t fallback_json_length
);
/** Number of bytes needed to output the unpublished fallback keys for this
* account */
std::size_t get_unpublished_fallback_key_json_length() const;
/** Output the fallback key as JSON: /** Output the fallback key as JSON:
* *
@ -162,18 +150,13 @@ struct Account {
* ] * ]
* } * }
* *
* if there is a fallback key and it has not been published yet.
*
* Returns the size of the JSON written or std::size_t(-1) on error. * Returns the size of the JSON written or std::size_t(-1) on error.
* If the buffer is too small last_error will be OUTPUT_BUFFER_TOO_SMALL. * If the buffer is too small last_error will be OUTPUT_BUFFER_TOO_SMALL.
*/ */
std::size_t get_unpublished_fallback_key_json( std::size_t get_fallback_key_json(
std::uint8_t * fallback_json, std::size_t fallback_json_length std::uint8_t * fallback_json, std::size_t fallback_json_length
); );
/** Forget about the old fallback key */
void forget_old_fallback_key();
/** Lookup a one time key with the given public key */ /** Lookup a one time key with the given public key */
OneTimeKey const * lookup_key( OneTimeKey const * lookup_key(
_olm_curve25519_public_key const & public_key _olm_curve25519_public_key const & public_key

View file

@ -22,10 +22,6 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
// Note: exports in this file are only for unit tests. Nobody else should be
// using this externally
#include "olm/olm_export.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -34,7 +30,7 @@ extern "C" {
/** /**
* The number of bytes of unpadded base64 needed to encode a length of input. * The number of bytes of unpadded base64 needed to encode a length of input.
*/ */
OLM_EXPORT size_t _olm_encode_base64_length( size_t _olm_encode_base64_length(
size_t input_length size_t input_length
); );
@ -46,7 +42,7 @@ OLM_EXPORT size_t _olm_encode_base64_length(
* *
* Returns number of bytes encoded * Returns number of bytes encoded
*/ */
OLM_EXPORT size_t _olm_encode_base64( size_t _olm_encode_base64(
uint8_t const * input, size_t input_length, uint8_t const * input, size_t input_length,
uint8_t * output uint8_t * output
); );
@ -55,7 +51,7 @@ OLM_EXPORT size_t _olm_encode_base64(
* The number of bytes of raw data a length of unpadded base64 will encode to. * The number of bytes of raw data a length of unpadded base64 will encode to.
* Returns size_t(-1) if the length is not a valid length for base64. * Returns size_t(-1) if the length is not a valid length for base64.
*/ */
OLM_EXPORT size_t _olm_decode_base64_length( size_t _olm_decode_base64_length(
size_t input_length size_t input_length
); );
@ -67,7 +63,7 @@ OLM_EXPORT size_t _olm_decode_base64_length(
* *
* Returns number of bytes decoded * Returns number of bytes decoded
*/ */
OLM_EXPORT size_t _olm_decode_base64( size_t _olm_decode_base64(
uint8_t const * input, size_t input_length, uint8_t const * input, size_t input_length,
uint8_t * output uint8_t * output
); );

View file

@ -18,16 +18,12 @@
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
// Note: exports in this file are only for unit tests. Nobody else should be
// using this externally
#include "olm/olm_export.h"
namespace olm { namespace olm {
/** /**
* The number of bytes of unpadded base64 needed to encode a length of input. * The number of bytes of unpadded base64 needed to encode a length of input.
*/ */
OLM_EXPORT std::size_t encode_base64_length( std::size_t encode_base64_length(
std::size_t input_length std::size_t input_length
); );
@ -37,7 +33,7 @@ OLM_EXPORT std::size_t encode_base64_length(
* The input can overlap with the last three quarters of the output buffer. * The input can overlap with the last three quarters of the output buffer.
* That is, the input pointer may be output + output_length - input_length. * That is, the input pointer may be output + output_length - input_length.
*/ */
OLM_EXPORT std::uint8_t * encode_base64( std::uint8_t * encode_base64(
std::uint8_t const * input, std::size_t input_length, std::uint8_t const * input, std::size_t input_length,
std::uint8_t * output std::uint8_t * output
); );
@ -46,7 +42,7 @@ OLM_EXPORT std::uint8_t * encode_base64(
* The number of bytes of raw data a length of unpadded base64 will encode to. * The number of bytes of raw data a length of unpadded base64 will encode to.
* Returns std::size_t(-1) if the length is not a valid length for base64. * Returns std::size_t(-1) if the length is not a valid length for base64.
*/ */
OLM_EXPORT std::size_t decode_base64_length( std::size_t decode_base64_length(
std::size_t input_length std::size_t input_length
); );
@ -55,12 +51,8 @@ OLM_EXPORT std::size_t decode_base64_length(
* Writes decode_base64_length(input_length) bytes to the output buffer. * Writes decode_base64_length(input_length) bytes to the output buffer.
* The output can overlap with the first three quarters of the input buffer. * The output can overlap with the first three quarters of the input buffer.
* That is, the input pointers and output pointer may be the same. * That is, the input pointers and output pointer may be the same.
*
* Returns the number of bytes of raw data the base64 input decoded to. If the
* input length supplied is not a valid length for base64, returns
* std::size_t(-1) and does not decode.
*/ */
OLM_EXPORT std::size_t decode_base64( std::uint8_t const * decode_base64(
std::uint8_t const * input, std::size_t input_length, std::uint8_t const * input, std::size_t input_length,
std::uint8_t * output std::uint8_t * output
); );

View file

@ -19,10 +19,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
// Note: exports in this file are only for unit tests. Nobody else should be
// using this externally
#include "olm/olm_export.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -115,7 +111,7 @@ struct _olm_cipher_aes_sha_256 {
size_t kdf_info_length; size_t kdf_info_length;
}; };
OLM_EXPORT extern const struct _olm_cipher_ops _olm_cipher_aes_sha_256_ops; extern const struct _olm_cipher_ops _olm_cipher_aes_sha_256_ops;
/** /**
* get an initializer for an instance of struct _olm_cipher_aes_sha_256. * get an initializer for an instance of struct _olm_cipher_aes_sha_256.

View file

@ -20,10 +20,6 @@
#ifndef OLM_CRYPTO_H_ #ifndef OLM_CRYPTO_H_
#define OLM_CRYPTO_H_ #define OLM_CRYPTO_H_
// Note: exports in this file are only for unit tests. Nobody else should be
// using this externally
#include "olm/olm_export.h"
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
@ -98,13 +94,13 @@ struct _olm_ed25519_key_pair {
/** The length of output the aes_encrypt_cbc function will write */ /** The length of output the aes_encrypt_cbc function will write */
OLM_EXPORT size_t _olm_crypto_aes_encrypt_cbc_length( size_t _olm_crypto_aes_encrypt_cbc_length(
size_t input_length size_t input_length
); );
/** Encrypts the input using AES256 in CBC mode with PKCS#7 padding. /** Encrypts the input using AES256 in CBC mode with PKCS#7 padding.
* The output buffer must be big enough to hold the output including padding */ * The output buffer must be big enough to hold the output including padding */
OLM_EXPORT void _olm_crypto_aes_encrypt_cbc( void _olm_crypto_aes_encrypt_cbc(
const struct _olm_aes256_key *key, const struct _olm_aes256_key *key,
const struct _olm_aes256_iv *iv, const struct _olm_aes256_iv *iv,
const uint8_t *input, size_t input_length, const uint8_t *input, size_t input_length,
@ -115,7 +111,7 @@ OLM_EXPORT void _olm_crypto_aes_encrypt_cbc(
* least the same size as the input buffer. Returns the length of the plaintext * least the same size as the input buffer. Returns the length of the plaintext
* without padding on success or std::size_t(-1) if the padding is invalid. * without padding on success or std::size_t(-1) if the padding is invalid.
*/ */
OLM_EXPORT size_t _olm_crypto_aes_decrypt_cbc( size_t _olm_crypto_aes_decrypt_cbc(
const struct _olm_aes256_key *key, const struct _olm_aes256_key *key,
const struct _olm_aes256_iv *iv, const struct _olm_aes256_iv *iv,
uint8_t const * input, size_t input_length, uint8_t const * input, size_t input_length,
@ -125,7 +121,7 @@ OLM_EXPORT size_t _olm_crypto_aes_decrypt_cbc(
/** Computes SHA-256 of the input. The output buffer must be a least /** Computes SHA-256 of the input. The output buffer must be a least
* SHA256_OUTPUT_LENGTH (32) bytes long. */ * SHA256_OUTPUT_LENGTH (32) bytes long. */
OLM_EXPORT void _olm_crypto_sha256( void _olm_crypto_sha256(
uint8_t const * input, size_t input_length, uint8_t const * input, size_t input_length,
uint8_t * output uint8_t * output
); );
@ -134,7 +130,7 @@ OLM_EXPORT void _olm_crypto_sha256(
* http://tools.ietf.org/html/rfc2104 * http://tools.ietf.org/html/rfc2104
* Computes HMAC-SHA-256 of the input for the key. The output buffer must * Computes HMAC-SHA-256 of the input for the key. The output buffer must
* be at least SHA256_OUTPUT_LENGTH (32) bytes long. */ * be at least SHA256_OUTPUT_LENGTH (32) bytes long. */
OLM_EXPORT void _olm_crypto_hmac_sha256( void _olm_crypto_hmac_sha256(
uint8_t const * key, size_t key_length, uint8_t const * key, size_t key_length,
uint8_t const * input, size_t input_length, uint8_t const * input, size_t input_length,
uint8_t * output uint8_t * output
@ -144,7 +140,7 @@ OLM_EXPORT void _olm_crypto_hmac_sha256(
/** HMAC-based Key Derivation Function (HKDF) /** HMAC-based Key Derivation Function (HKDF)
* https://tools.ietf.org/html/rfc5869 * https://tools.ietf.org/html/rfc5869
* Derives key material from the input bytes. */ * Derives key material from the input bytes. */
OLM_EXPORT void _olm_crypto_hkdf_sha256( void _olm_crypto_hkdf_sha256(
uint8_t const * input, size_t input_length, uint8_t const * input, size_t input_length,
uint8_t const * info, size_t info_length, uint8_t const * info, size_t info_length,
uint8_t const * salt, size_t salt_length, uint8_t const * salt, size_t salt_length,
@ -155,7 +151,7 @@ OLM_EXPORT void _olm_crypto_hkdf_sha256(
/** Generate a curve25519 key pair /** Generate a curve25519 key pair
* random_32_bytes should be CURVE25519_RANDOM_LENGTH (32) bytes long. * random_32_bytes should be CURVE25519_RANDOM_LENGTH (32) bytes long.
*/ */
OLM_EXPORT void _olm_crypto_curve25519_generate_key( void _olm_crypto_curve25519_generate_key(
uint8_t const * random_32_bytes, uint8_t const * random_32_bytes,
struct _olm_curve25519_key_pair *output struct _olm_curve25519_key_pair *output
); );
@ -164,7 +160,7 @@ OLM_EXPORT void _olm_crypto_curve25519_generate_key(
/** Create a shared secret using our private key and their public key. /** Create a shared secret using our private key and their public key.
* The output buffer must be at least CURVE25519_SHARED_SECRET_LENGTH (32) bytes long. * The output buffer must be at least CURVE25519_SHARED_SECRET_LENGTH (32) bytes long.
*/ */
OLM_EXPORT void _olm_crypto_curve25519_shared_secret( void _olm_crypto_curve25519_shared_secret(
const struct _olm_curve25519_key_pair *our_key, const struct _olm_curve25519_key_pair *our_key,
const struct _olm_curve25519_public_key *their_key, const struct _olm_curve25519_public_key *their_key,
uint8_t * output uint8_t * output
@ -173,7 +169,7 @@ OLM_EXPORT void _olm_crypto_curve25519_shared_secret(
/** Generate an ed25519 key pair /** Generate an ed25519 key pair
* random_32_bytes should be ED25519_RANDOM_LENGTH (32) bytes long. * random_32_bytes should be ED25519_RANDOM_LENGTH (32) bytes long.
*/ */
OLM_EXPORT void _olm_crypto_ed25519_generate_key( void _olm_crypto_ed25519_generate_key(
uint8_t const * random_bytes, uint8_t const * random_bytes,
struct _olm_ed25519_key_pair *output struct _olm_ed25519_key_pair *output
); );
@ -182,7 +178,7 @@ OLM_EXPORT void _olm_crypto_ed25519_generate_key(
* *
* The output buffer must be at least ED25519_SIGNATURE_LENGTH (64) bytes * The output buffer must be at least ED25519_SIGNATURE_LENGTH (64) bytes
* long. */ * long. */
OLM_EXPORT void _olm_crypto_ed25519_sign( void _olm_crypto_ed25519_sign(
const struct _olm_ed25519_key_pair *our_key, const struct _olm_ed25519_key_pair *our_key,
const uint8_t * message, size_t message_length, const uint8_t * message, size_t message_length,
uint8_t * output uint8_t * output
@ -191,7 +187,7 @@ OLM_EXPORT void _olm_crypto_ed25519_sign(
/** Verify an ed25519 signature /** Verify an ed25519 signature
* The signature input buffer must be ED25519_SIGNATURE_LENGTH (64) bytes long. * The signature input buffer must be ED25519_SIGNATURE_LENGTH (64) bytes long.
* Returns non-zero if the signature is valid. */ * Returns non-zero if the signature is valid. */
OLM_EXPORT int _olm_crypto_ed25519_verify( int _olm_crypto_ed25519_verify(
const struct _olm_ed25519_public_key *their_key, const struct _olm_ed25519_public_key *their_key,
const uint8_t * message, size_t message_length, const uint8_t * message, size_t message_length,
const uint8_t * signature const uint8_t * signature

View file

@ -15,8 +15,6 @@
#ifndef OLM_ERROR_H_ #ifndef OLM_ERROR_H_
#define OLM_ERROR_H_ #define OLM_ERROR_H_
#include "olm/olm_export.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -60,18 +58,12 @@ enum OlmErrorCode {
*/ */
OLM_SAS_THEIR_KEY_NOT_SET = 16, OLM_SAS_THEIR_KEY_NOT_SET = 16,
/**
* The pickled object was successfully decoded, but the unpickling still failed
* because it had some extraneous junk data at the end.
*/
OLM_PICKLE_EXTRA_DATA = 17,
/* remember to update the list of string constants in error.c when updating /* remember to update the list of string constants in error.c when updating
* this list. */ * this list. */
}; };
/** get a string representation of the given error code. */ /** get a string representation of the given error code. */
OLM_EXPORT const char * _olm_error_to_string(enum OlmErrorCode error); const char * _olm_error_to_string(enum OlmErrorCode error);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"

View file

@ -18,10 +18,6 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "olm/error.h"
#include "olm/olm_export.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -29,38 +25,31 @@ extern "C" {
typedef struct OlmInboundGroupSession OlmInboundGroupSession; typedef struct OlmInboundGroupSession OlmInboundGroupSession;
/** get the size of an inbound group session, in bytes. */ /** get the size of an inbound group session, in bytes. */
OLM_EXPORT size_t olm_inbound_group_session_size(void); size_t olm_inbound_group_session_size(void);
/** /**
* Initialise an inbound group session object using the supplied memory * Initialise an inbound group session object using the supplied memory
* The supplied memory should be at least olm_inbound_group_session_size() * The supplied memory should be at least olm_inbound_group_session_size()
* bytes. * bytes.
*/ */
OLM_EXPORT OlmInboundGroupSession * olm_inbound_group_session( OlmInboundGroupSession * olm_inbound_group_session(
void *memory void *memory
); );
/** /**
* A null terminated string describing the most recent error to happen to a * A null terminated string describing the most recent error to happen to a
* group session */ * group session */
OLM_EXPORT const char *olm_inbound_group_session_last_error( const char *olm_inbound_group_session_last_error(
const OlmInboundGroupSession *session
);
/**
* An error code describing the most recent error to happen to a group
* session */
OLM_EXPORT enum OlmErrorCode olm_inbound_group_session_last_error_code(
const OlmInboundGroupSession *session const OlmInboundGroupSession *session
); );
/** Clears the memory used to back this group session */ /** Clears the memory used to back this group session */
OLM_EXPORT size_t olm_clear_inbound_group_session( size_t olm_clear_inbound_group_session(
OlmInboundGroupSession *session OlmInboundGroupSession *session
); );
/** Returns the number of bytes needed to store an inbound group session */ /** Returns the number of bytes needed to store an inbound group session */
OLM_EXPORT size_t olm_pickle_inbound_group_session_length( size_t olm_pickle_inbound_group_session_length(
const OlmInboundGroupSession *session const OlmInboundGroupSession *session
); );
@ -72,7 +61,7 @@ OLM_EXPORT size_t olm_pickle_inbound_group_session_length(
* is smaller than olm_pickle_inbound_group_session_length() then * is smaller than olm_pickle_inbound_group_session_length() then
* olm_inbound_group_session_last_error() will be "OUTPUT_BUFFER_TOO_SMALL" * olm_inbound_group_session_last_error() will be "OUTPUT_BUFFER_TOO_SMALL"
*/ */
OLM_EXPORT size_t olm_pickle_inbound_group_session( size_t olm_pickle_inbound_group_session(
OlmInboundGroupSession *session, OlmInboundGroupSession *session,
void const * key, size_t key_length, void const * key, size_t key_length,
void * pickled, size_t pickled_length void * pickled, size_t pickled_length
@ -88,7 +77,7 @@ OLM_EXPORT size_t olm_pickle_inbound_group_session(
* olm_inbound_group_session_last_error() will be "INVALID_BASE64". The input * olm_inbound_group_session_last_error() will be "INVALID_BASE64". The input
* pickled buffer is destroyed * pickled buffer is destroyed
*/ */
OLM_EXPORT size_t olm_unpickle_inbound_group_session( size_t olm_unpickle_inbound_group_session(
OlmInboundGroupSession *session, OlmInboundGroupSession *session,
void const * key, size_t key_length, void const * key, size_t key_length,
void * pickled, size_t pickled_length void * pickled, size_t pickled_length
@ -105,7 +94,7 @@ OLM_EXPORT size_t olm_unpickle_inbound_group_session(
* * OLM_INVALID_BASE64 if the session_key is not valid base64 * * OLM_INVALID_BASE64 if the session_key is not valid base64
* * OLM_BAD_SESSION_KEY if the session_key is invalid * * OLM_BAD_SESSION_KEY if the session_key is invalid
*/ */
OLM_EXPORT size_t olm_init_inbound_group_session( size_t olm_init_inbound_group_session(
OlmInboundGroupSession *session, OlmInboundGroupSession *session,
/* base64-encoded keys */ /* base64-encoded keys */
uint8_t const * session_key, size_t session_key_length uint8_t const * session_key, size_t session_key_length
@ -120,7 +109,7 @@ OLM_EXPORT size_t olm_init_inbound_group_session(
* * OLM_INVALID_BASE64 if the session_key is not valid base64 * * OLM_INVALID_BASE64 if the session_key is not valid base64
* * OLM_BAD_SESSION_KEY if the session_key is invalid * * OLM_BAD_SESSION_KEY if the session_key is invalid
*/ */
OLM_EXPORT size_t olm_import_inbound_group_session( size_t olm_import_inbound_group_session(
OlmInboundGroupSession *session, OlmInboundGroupSession *session,
/* base64-encoded keys; note that it will be overwritten with the base64-decoded /* base64-encoded keys; note that it will be overwritten with the base64-decoded
data. */ data. */
@ -137,7 +126,7 @@ OLM_EXPORT size_t olm_import_inbound_group_session(
* *
* Returns olm_error() on failure. * Returns olm_error() on failure.
*/ */
OLM_EXPORT size_t olm_group_decrypt_max_plaintext_length( size_t olm_group_decrypt_max_plaintext_length(
OlmInboundGroupSession *session, OlmInboundGroupSession *session,
uint8_t * message, size_t message_length uint8_t * message, size_t message_length
); );
@ -161,7 +150,7 @@ OLM_EXPORT size_t olm_group_decrypt_max_plaintext_length(
* message's index (ie, it was sent before the session key was shared with * message's index (ie, it was sent before the session key was shared with
* us) * us)
*/ */
OLM_EXPORT size_t olm_group_decrypt( size_t olm_group_decrypt(
OlmInboundGroupSession *session, OlmInboundGroupSession *session,
/* input; note that it will be overwritten with the base64-decoded /* input; note that it will be overwritten with the base64-decoded
@ -177,7 +166,7 @@ OLM_EXPORT size_t olm_group_decrypt(
/** /**
* Get the number of bytes returned by olm_inbound_group_session_id() * Get the number of bytes returned by olm_inbound_group_session_id()
*/ */
OLM_EXPORT size_t olm_inbound_group_session_id_length( size_t olm_inbound_group_session_id_length(
const OlmInboundGroupSession *session const OlmInboundGroupSession *session
); );
@ -189,7 +178,7 @@ OLM_EXPORT size_t olm_inbound_group_session_id_length(
* last_error will be OUTPUT_BUFFER_TOO_SMALL if the id buffer was too * last_error will be OUTPUT_BUFFER_TOO_SMALL if the id buffer was too
* small. * small.
*/ */
OLM_EXPORT size_t olm_inbound_group_session_id( size_t olm_inbound_group_session_id(
OlmInboundGroupSession *session, OlmInboundGroupSession *session,
uint8_t * id, size_t id_length uint8_t * id, size_t id_length
); );
@ -197,7 +186,7 @@ OLM_EXPORT size_t olm_inbound_group_session_id(
/** /**
* Get the first message index we know how to decrypt. * Get the first message index we know how to decrypt.
*/ */
OLM_EXPORT uint32_t olm_inbound_group_session_first_known_index( uint32_t olm_inbound_group_session_first_known_index(
const OlmInboundGroupSession *session const OlmInboundGroupSession *session
); );
@ -210,14 +199,14 @@ OLM_EXPORT uint32_t olm_inbound_group_session_first_known_index(
* *
* This is mainly intended for the unit tests, currently. * This is mainly intended for the unit tests, currently.
*/ */
OLM_EXPORT int olm_inbound_group_session_is_verified( int olm_inbound_group_session_is_verified(
const OlmInboundGroupSession *session const OlmInboundGroupSession *session
); );
/** /**
* Get the number of bytes returned by olm_export_inbound_group_session() * Get the number of bytes returned by olm_export_inbound_group_session()
*/ */
OLM_EXPORT size_t olm_export_inbound_group_session_length( size_t olm_export_inbound_group_session_length(
const OlmInboundGroupSession *session const OlmInboundGroupSession *session
); );
@ -233,7 +222,7 @@ OLM_EXPORT size_t olm_export_inbound_group_session_length(
* given index (ie, it was sent before the session key was shared with * given index (ie, it was sent before the session key was shared with
* us) * us)
*/ */
OLM_EXPORT size_t olm_export_inbound_group_session( size_t olm_export_inbound_group_session(
OlmInboundGroupSession *session, OlmInboundGroupSession *session,
uint8_t * key, size_t key_length, uint32_t message_index uint8_t * key, size_t key_length, uint32_t message_index
); );

View file

@ -99,9 +99,9 @@ public:
return *this; return *this;
} }
T * this_pos = _data; T * this_pos = _data;
const T * other_pos = other._data; T * const other_pos = other._data;
while (other_pos != other._end) { while (other_pos != other._end) {
*this_pos = *other_pos; *this_pos = *other;
++this_pos; ++this_pos;
++other_pos; ++other_pos;
} }

View file

@ -23,10 +23,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
// Note: exports in this file are only for unit tests. Nobody else should be
// using this externally
#include "olm/olm_export.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -63,25 +59,25 @@ extern const struct _olm_cipher *megolm_cipher;
* initialize the megolm ratchet. random_data should be at least * initialize the megolm ratchet. random_data should be at least
* MEGOLM_RATCHET_LENGTH bytes of randomness. * MEGOLM_RATCHET_LENGTH bytes of randomness.
*/ */
OLM_EXPORT void megolm_init(Megolm *megolm, uint8_t const *random_data, uint32_t counter); void megolm_init(Megolm *megolm, uint8_t const *random_data, uint32_t counter);
/** Returns the number of bytes needed to store a megolm */ /** Returns the number of bytes needed to store a megolm */
OLM_EXPORT size_t megolm_pickle_length(const Megolm *megolm); size_t megolm_pickle_length(const Megolm *megolm);
/** /**
* Pickle the megolm. Returns a pointer to the next free space in the buffer. * Pickle the megolm. Returns a pointer to the next free space in the buffer.
*/ */
OLM_EXPORT uint8_t * megolm_pickle(const Megolm *megolm, uint8_t *pos); uint8_t * megolm_pickle(const Megolm *megolm, uint8_t *pos);
/** /**
* Unpickle the megolm. Returns a pointer to the next item in the buffer. * Unpickle the megolm. Returns a pointer to the next item in the buffer.
*/ */
OLM_EXPORT const uint8_t * megolm_unpickle(Megolm *megolm, const uint8_t *pos, const uint8_t * megolm_unpickle(Megolm *megolm, const uint8_t *pos,
const uint8_t *end); const uint8_t *end);
/** advance the ratchet by one step */ /** advance the ratchet by one step */
OLM_EXPORT void megolm_advance(Megolm *megolm); void megolm_advance(Megolm *megolm);
/** /**
* get the key data in the ratchet. The returned data is * get the key data in the ratchet. The returned data is
@ -90,7 +86,7 @@ OLM_EXPORT void megolm_advance(Megolm *megolm);
#define megolm_get_data(megolm) ((const uint8_t *)((megolm)->data)) #define megolm_get_data(megolm) ((const uint8_t *)((megolm)->data))
/** advance the ratchet to a given count */ /** advance the ratchet to a given count */
OLM_EXPORT void megolm_advance_to(Megolm *megolm, uint32_t advance_to); void megolm_advance_to(Megolm *megolm, uint32_t advance_to);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"

View file

@ -27,10 +27,6 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
// Note: exports in this file are only for unit tests. Nobody else should be
// using this externally
#include "olm/olm_export.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -38,7 +34,7 @@ extern "C" {
/** /**
* The length of the buffer needed to hold a group message. * The length of the buffer needed to hold a group message.
*/ */
OLM_EXPORT size_t _olm_encode_group_message_length( size_t _olm_encode_group_message_length(
uint32_t chain_index, uint32_t chain_index,
size_t ciphertext_length, size_t ciphertext_length,
size_t mac_length, size_t mac_length,
@ -59,7 +55,7 @@ OLM_EXPORT size_t _olm_encode_group_message_length(
* *
* Returns the size of the message, up to the MAC. * Returns the size of the message, up to the MAC.
*/ */
OLM_EXPORT size_t _olm_encode_group_message( size_t _olm_encode_group_message(
uint8_t version, uint8_t version,
uint32_t message_index, uint32_t message_index,
size_t ciphertext_length, size_t ciphertext_length,
@ -80,7 +76,7 @@ struct _OlmDecodeGroupMessageResults {
/** /**
* Reads the message headers from the input buffer. * Reads the message headers from the input buffer.
*/ */
OLM_EXPORT void _olm_decode_group_message( void _olm_decode_group_message(
const uint8_t *input, size_t input_length, const uint8_t *input, size_t input_length,
size_t mac_length, size_t signature_length, size_t mac_length, size_t signature_length,

View file

@ -27,16 +27,13 @@
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
// Note: exports in this file are only for unit tests. Nobody else should be
// using this externally
#include "olm/olm_export.h"
namespace olm { namespace olm {
/** /**
* The length of the buffer needed to hold a message. * The length of the buffer needed to hold a message.
*/ */
OLM_EXPORT std::size_t encode_message_length( std::size_t encode_message_length(
std::uint32_t counter, std::uint32_t counter,
std::size_t ratchet_key_length, std::size_t ratchet_key_length,
std::size_t ciphertext_length, std::size_t ciphertext_length,
@ -64,7 +61,7 @@ struct MessageReader {
* Writes the message headers into the output buffer. * Writes the message headers into the output buffer.
* Populates the writer struct with pointers into the output buffer. * Populates the writer struct with pointers into the output buffer.
*/ */
OLM_EXPORT void encode_message( void encode_message(
MessageWriter & writer, MessageWriter & writer,
std::uint8_t version, std::uint8_t version,
std::uint32_t counter, std::uint32_t counter,
@ -78,7 +75,7 @@ OLM_EXPORT void encode_message(
* Reads the message headers from the input buffer. * Reads the message headers from the input buffer.
* Populates the reader struct with pointers into the input buffer. * Populates the reader struct with pointers into the input buffer.
*/ */
OLM_EXPORT void decode_message( void decode_message(
MessageReader & reader, MessageReader & reader,
std::uint8_t const * input, std::size_t input_length, std::uint8_t const * input, std::size_t input_length,
std::size_t mac_length std::size_t mac_length

View file

@ -19,12 +19,9 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "olm/error.h"
#include "olm/inbound_group_session.h" #include "olm/inbound_group_session.h"
#include "olm/outbound_group_session.h" #include "olm/outbound_group_session.h"
#include "olm/olm_export.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -39,94 +36,79 @@ typedef struct OlmUtility OlmUtility;
/** Get the version number of the library. /** Get the version number of the library.
* Arguments will be updated if non-null. * Arguments will be updated if non-null.
*/ */
OLM_EXPORT void olm_get_library_version(uint8_t *major, uint8_t *minor, uint8_t *patch); void olm_get_library_version(uint8_t *major, uint8_t *minor, uint8_t *patch);
/** The size of an account object in bytes */ /** The size of an account object in bytes */
OLM_EXPORT size_t olm_account_size(void); size_t olm_account_size(void);
/** The size of a session object in bytes */ /** The size of a session object in bytes */
OLM_EXPORT size_t olm_session_size(void); size_t olm_session_size(void);
/** The size of a utility object in bytes */ /** The size of a utility object in bytes */
OLM_EXPORT size_t olm_utility_size(void); size_t olm_utility_size(void);
/** Initialise an account object using the supplied memory /** Initialise an account object using the supplied memory
* The supplied memory must be at least olm_account_size() bytes */ * The supplied memory must be at least olm_account_size() bytes */
OLM_EXPORT OlmAccount * olm_account( OlmAccount * olm_account(
void * memory void * memory
); );
/** Initialise a session object using the supplied memory /** Initialise a session object using the supplied memory
* The supplied memory must be at least olm_session_size() bytes */ * The supplied memory must be at least olm_session_size() bytes */
OLM_EXPORT OlmSession * olm_session( OlmSession * olm_session(
void * memory void * memory
); );
/** Initialise a utility object using the supplied memory /** Initialise a utility object using the supplied memory
* The supplied memory must be at least olm_utility_size() bytes */ * The supplied memory must be at least olm_utility_size() bytes */
OLM_EXPORT OlmUtility * olm_utility( OlmUtility * olm_utility(
void * memory void * memory
); );
/** The value that olm will return from a function if there was an error */ /** The value that olm will return from a function if there was an error */
OLM_EXPORT size_t olm_error(void); size_t olm_error(void);
/** A null terminated string describing the most recent error to happen to an /** A null terminated string describing the most recent error to happen to an
* account */ * account */
OLM_EXPORT const char * olm_account_last_error( const char * olm_account_last_error(
OlmAccount const * account OlmAccount * account
);
/** An error code describing the most recent error to happen to an account */
OLM_EXPORT enum OlmErrorCode olm_account_last_error_code(
OlmAccount const * account
); );
/** A null terminated string describing the most recent error to happen to a /** A null terminated string describing the most recent error to happen to a
* session */ * session */
OLM_EXPORT const char * olm_session_last_error( const char * olm_session_last_error(
OlmSession const * session OlmSession * session
);
/** An error code describing the most recent error to happen to a session */
OLM_EXPORT enum OlmErrorCode olm_session_last_error_code(
OlmSession const * session
); );
/** A null terminated string describing the most recent error to happen to a /** A null terminated string describing the most recent error to happen to a
* utility */ * utility */
OLM_EXPORT const char * olm_utility_last_error( const char * olm_utility_last_error(
OlmUtility const * utility OlmUtility * utility
);
/** An error code describing the most recent error to happen to a utility */
OLM_EXPORT enum OlmErrorCode olm_utility_last_error_code(
OlmUtility const * utility
); );
/** Clears the memory used to back this account */ /** Clears the memory used to back this account */
OLM_EXPORT size_t olm_clear_account( size_t olm_clear_account(
OlmAccount * account OlmAccount * account
); );
/** Clears the memory used to back this session */ /** Clears the memory used to back this session */
OLM_EXPORT size_t olm_clear_session( size_t olm_clear_session(
OlmSession * session OlmSession * session
); );
/** Clears the memory used to back this utility */ /** Clears the memory used to back this utility */
OLM_EXPORT size_t olm_clear_utility( size_t olm_clear_utility(
OlmUtility * utility OlmUtility * utility
); );
/** Returns the number of bytes needed to store an account */ /** Returns the number of bytes needed to store an account */
OLM_EXPORT size_t olm_pickle_account_length( size_t olm_pickle_account_length(
OlmAccount const * account OlmAccount * account
); );
/** Returns the number of bytes needed to store a session */ /** Returns the number of bytes needed to store a session */
OLM_EXPORT size_t olm_pickle_session_length( size_t olm_pickle_session_length(
OlmSession const * session OlmSession * session
); );
/** Stores an account as a base64 string. Encrypts the account using the /** Stores an account as a base64 string. Encrypts the account using the
@ -134,7 +116,7 @@ OLM_EXPORT size_t olm_pickle_session_length(
* Returns olm_error() on failure. If the pickle output buffer * Returns olm_error() on failure. If the pickle output buffer
* is smaller than olm_pickle_account_length() then * is smaller than olm_pickle_account_length() then
* olm_account_last_error() will be "OUTPUT_BUFFER_TOO_SMALL" */ * olm_account_last_error() will be "OUTPUT_BUFFER_TOO_SMALL" */
OLM_EXPORT size_t olm_pickle_account( size_t olm_pickle_account(
OlmAccount * account, OlmAccount * account,
void const * key, size_t key_length, void const * key, size_t key_length,
void * pickled, size_t pickled_length void * pickled, size_t pickled_length
@ -145,7 +127,7 @@ OLM_EXPORT size_t olm_pickle_account(
* Returns olm_error() on failure. If the pickle output buffer * Returns olm_error() on failure. If the pickle output buffer
* is smaller than olm_pickle_session_length() then * is smaller than olm_pickle_session_length() then
* olm_session_last_error() will be "OUTPUT_BUFFER_TOO_SMALL" */ * olm_session_last_error() will be "OUTPUT_BUFFER_TOO_SMALL" */
OLM_EXPORT size_t olm_pickle_session( size_t olm_pickle_session(
OlmSession * session, OlmSession * session,
void const * key, size_t key_length, void const * key, size_t key_length,
void * pickled, size_t pickled_length void * pickled, size_t pickled_length
@ -157,7 +139,7 @@ OLM_EXPORT size_t olm_pickle_session(
* will be "BAD_ACCOUNT_KEY". If the base64 couldn't be decoded then * will be "BAD_ACCOUNT_KEY". If the base64 couldn't be decoded then
* olm_account_last_error() will be "INVALID_BASE64". The input pickled * olm_account_last_error() will be "INVALID_BASE64". The input pickled
* buffer is destroyed */ * buffer is destroyed */
OLM_EXPORT size_t olm_unpickle_account( size_t olm_unpickle_account(
OlmAccount * account, OlmAccount * account,
void const * key, size_t key_length, void const * key, size_t key_length,
void * pickled, size_t pickled_length void * pickled, size_t pickled_length
@ -169,57 +151,57 @@ OLM_EXPORT size_t olm_unpickle_account(
* will be "BAD_ACCOUNT_KEY". If the base64 couldn't be decoded then * will be "BAD_ACCOUNT_KEY". If the base64 couldn't be decoded then
* olm_session_last_error() will be "INVALID_BASE64". The input pickled * olm_session_last_error() will be "INVALID_BASE64". The input pickled
* buffer is destroyed */ * buffer is destroyed */
OLM_EXPORT size_t olm_unpickle_session( size_t olm_unpickle_session(
OlmSession * session, OlmSession * session,
void const * key, size_t key_length, void const * key, size_t key_length,
void * pickled, size_t pickled_length void * pickled, size_t pickled_length
); );
/** The number of random bytes needed to create an account.*/ /** The number of random bytes needed to create an account.*/
OLM_EXPORT size_t olm_create_account_random_length( size_t olm_create_account_random_length(
OlmAccount const * account OlmAccount * account
); );
/** Creates a new account. Returns olm_error() on failure. If there weren't /** Creates a new account. Returns olm_error() on failure. If there weren't
* enough random bytes then olm_account_last_error() will be * enough random bytes then olm_account_last_error() will be
* "NOT_ENOUGH_RANDOM" */ * "NOT_ENOUGH_RANDOM" */
OLM_EXPORT size_t olm_create_account( size_t olm_create_account(
OlmAccount * account, OlmAccount * account,
void * random, size_t random_length void * random, size_t random_length
); );
/** The size of the output buffer needed to hold the identity keys */ /** The size of the output buffer needed to hold the identity keys */
OLM_EXPORT size_t olm_account_identity_keys_length( size_t olm_account_identity_keys_length(
OlmAccount const * account OlmAccount * account
); );
/** Writes the public parts of the identity keys for the account into the /** Writes the public parts of the identity keys for the account into the
* identity_keys output buffer. Returns olm_error() on failure. If the * identity_keys output buffer. Returns olm_error() on failure. If the
* identity_keys buffer was too small then olm_account_last_error() will be * identity_keys buffer was too small then olm_account_last_error() will be
* "OUTPUT_BUFFER_TOO_SMALL". */ * "OUTPUT_BUFFER_TOO_SMALL". */
OLM_EXPORT size_t olm_account_identity_keys( size_t olm_account_identity_keys(
OlmAccount * account, OlmAccount * account,
void * identity_keys, size_t identity_key_length void * identity_keys, size_t identity_key_length
); );
/** The length of an ed25519 signature encoded as base64. */ /** The length of an ed25519 signature encoded as base64. */
OLM_EXPORT size_t olm_account_signature_length( size_t olm_account_signature_length(
OlmAccount const * account OlmAccount * account
); );
/** Signs a message with the ed25519 key for this account. Returns olm_error() /** Signs a message with the ed25519 key for this account. Returns olm_error()
* on failure. If the signature buffer was too small then * on failure. If the signature buffer was too small then
* olm_account_last_error() will be "OUTPUT_BUFFER_TOO_SMALL" */ * olm_account_last_error() will be "OUTPUT_BUFFER_TOO_SMALL" */
OLM_EXPORT size_t olm_account_sign( size_t olm_account_sign(
OlmAccount * account, OlmAccount * account,
void const * message, size_t message_length, void const * message, size_t message_length,
void * signature, size_t signature_length void * signature, size_t signature_length
); );
/** The size of the output buffer needed to hold the one time keys */ /** The size of the output buffer needed to hold the one time keys */
OLM_EXPORT size_t olm_account_one_time_keys_length( size_t olm_account_one_time_keys_length(
OlmAccount const * account OlmAccount * account
); );
/** Writes the public parts of the unpublished one time keys for the account /** Writes the public parts of the unpublished one time keys for the account
@ -240,31 +222,25 @@ OLM_EXPORT size_t olm_account_one_time_keys_length(
* <p> * <p>
* If the one_time_keys buffer was too small then olm_account_last_error() * If the one_time_keys buffer was too small then olm_account_last_error()
* will be "OUTPUT_BUFFER_TOO_SMALL". */ * will be "OUTPUT_BUFFER_TOO_SMALL". */
OLM_EXPORT size_t olm_account_one_time_keys( size_t olm_account_one_time_keys(
OlmAccount * account, OlmAccount * account,
void * one_time_keys, size_t one_time_keys_length void * one_time_keys, size_t one_time_keys_length
); );
/** Marks the current set of one time keys and fallback key as being published /** Marks the current set of one time keys as being published. */
* Once marked as published, the one time keys will no longer be returned by size_t olm_account_mark_keys_as_published(
* olm_account_one_time_keys(), and the fallback key will no longer be returned
* by olm_account_unpublished_fallback_key().
*
* Returns the number of one-time keys that were marked as published. Note that
* this count does not include the fallback key. */
OLM_EXPORT size_t olm_account_mark_keys_as_published(
OlmAccount * account OlmAccount * account
); );
/** The largest number of one time keys this account can store. */ /** The largest number of one time keys this account can store. */
OLM_EXPORT size_t olm_account_max_number_of_one_time_keys( size_t olm_account_max_number_of_one_time_keys(
OlmAccount const * account OlmAccount * account
); );
/** The number of random bytes needed to generate a given number of new one /** The number of random bytes needed to generate a given number of new one
* time keys. */ * time keys. */
OLM_EXPORT size_t olm_account_generate_one_time_keys_random_length( size_t olm_account_generate_one_time_keys_random_length(
OlmAccount const * account, OlmAccount * account,
size_t number_of_keys size_t number_of_keys
); );
@ -272,63 +248,40 @@ OLM_EXPORT size_t olm_account_generate_one_time_keys_random_length(
* by this account exceeds max_number_of_one_time_keys() then the old keys are * by this account exceeds max_number_of_one_time_keys() then the old keys are
* discarded. Returns olm_error() on error. If the number of random bytes is * discarded. Returns olm_error() on error. If the number of random bytes is
* too small then olm_account_last_error() will be "NOT_ENOUGH_RANDOM". */ * too small then olm_account_last_error() will be "NOT_ENOUGH_RANDOM". */
OLM_EXPORT size_t olm_account_generate_one_time_keys( size_t olm_account_generate_one_time_keys(
OlmAccount * account, OlmAccount * account,
size_t number_of_keys, size_t number_of_keys,
void * random, size_t random_length void * random, size_t random_length
); );
/** The number of random bytes needed to generate a fallback key. */ /** The number of random bytes needed to generate a fallback key. */
OLM_EXPORT size_t olm_account_generate_fallback_key_random_length( size_t olm_account_generate_fallback_key_random_length(
OlmAccount const * account OlmAccount * account
); );
/** Generates a new fallback key. Only one previous fallback key is /** Generates a new fallback key. Only one previous fallback key is
* stored. Returns olm_error() on error. If the number of random bytes is too * stored. Returns olm_error() on error. If the number of random bytes is too
* small then olm_account_last_error() will be "NOT_ENOUGH_RANDOM". */ * small then olm_account_last_error() will be "NOT_ENOUGH_RANDOM". */
OLM_EXPORT size_t olm_account_generate_fallback_key( size_t olm_account_generate_fallback_key(
OlmAccount * account, OlmAccount * account,
void * random, size_t random_length void * random, size_t random_length
); );
/** The number of bytes needed to hold the fallback key as returned by /** The number of bytes needed to hold the fallback key as returned by
* olm_account_fallback_key. */ * olm_account_fallback_key. */
OLM_EXPORT size_t olm_account_fallback_key_length( size_t olm_account_fallback_key_length(
OlmAccount const * account
);
/** Deprecated: use olm_account_unpublished_fallback_key instead */
OLM_EXPORT size_t olm_account_fallback_key(
OlmAccount * account,
void * fallback_key, size_t fallback_key_size
);
/** The number of bytes needed to hold the unpublished fallback key as returned
* by olm_account_unpublished fallback_key. */
OLM_EXPORT size_t olm_account_unpublished_fallback_key_length(
OlmAccount const * account
);
/** Returns the fallback key (if present, and if unpublished) into the
* fallback_key buffer */
OLM_EXPORT size_t olm_account_unpublished_fallback_key(
OlmAccount * account,
void * fallback_key, size_t fallback_key_size
);
/** Forget about the old fallback key. This should be called once you are
* reasonably certain that you will not receive any more messages that use
* the old fallback key (e.g. 5 minutes after the new fallback key has been
* published).
*/
OLM_EXPORT void olm_account_forget_old_fallback_key(
OlmAccount * account OlmAccount * account
); );
size_t olm_account_fallback_key(
OlmAccount * account,
void * fallback_key, size_t fallback_key_size
);
/** The number of random bytes needed to create an outbound session */ /** The number of random bytes needed to create an outbound session */
OLM_EXPORT size_t olm_create_outbound_session_random_length( size_t olm_create_outbound_session_random_length(
OlmSession const * session OlmSession * session
); );
/** Creates a new out-bound session for sending messages to a given identity_key /** Creates a new out-bound session for sending messages to a given identity_key
@ -336,9 +289,9 @@ OLM_EXPORT size_t olm_create_outbound_session_random_length(
* decoded as base64 then olm_session_last_error() will be "INVALID_BASE64" * decoded as base64 then olm_session_last_error() will be "INVALID_BASE64"
* If there weren't enough random bytes then olm_session_last_error() will * If there weren't enough random bytes then olm_session_last_error() will
* be "NOT_ENOUGH_RANDOM". */ * be "NOT_ENOUGH_RANDOM". */
OLM_EXPORT size_t olm_create_outbound_session( size_t olm_create_outbound_session(
OlmSession * session, OlmSession * session,
OlmAccount const * account, OlmAccount * account,
void const * their_identity_key, size_t their_identity_key_length, void const * their_identity_key, size_t their_identity_key_length,
void const * their_one_time_key, size_t their_one_time_key_length, void const * their_one_time_key, size_t their_one_time_key_length,
void * random, size_t random_length void * random, size_t random_length
@ -349,19 +302,24 @@ OLM_EXPORT size_t olm_create_outbound_session(
* couldn't be decoded then olm_session_last_error will be "INVALID_BASE64". * couldn't be decoded then olm_session_last_error will be "INVALID_BASE64".
* If the message was for an unsupported protocol version then * If the message was for an unsupported protocol version then
* olm_session_last_error() will be "BAD_MESSAGE_VERSION". If the message * olm_session_last_error() will be "BAD_MESSAGE_VERSION". If the message
* couldn't be decoded then olm_session_last_error() will be * couldn't be decoded then then olm_session_last_error() will be
* "BAD_MESSAGE_FORMAT". If the message refers to an unknown one time * "BAD_MESSAGE_FORMAT". If the message refers to an unknown one time
* key then olm_session_last_error() will be "BAD_MESSAGE_KEY_ID". */ * key then olm_session_last_error() will be "BAD_MESSAGE_KEY_ID". */
OLM_EXPORT size_t olm_create_inbound_session( size_t olm_create_inbound_session(
OlmSession * session, OlmSession * session,
OlmAccount * account, OlmAccount * account,
void * one_time_key_message, size_t message_length void * one_time_key_message, size_t message_length
); );
/** Same as olm_create_inbound_session, but ensures that the identity key /** Create a new in-bound session for sending/receiving messages from an
* in the pre-key message matches the expected identity key, supplied via the * incoming PRE_KEY message. Returns olm_error() on failure. If the base64
* `their_identity_key` parameter. Fails early if there is no match. */ * couldn't be decoded then olm_session_last_error will be "INVALID_BASE64".
OLM_EXPORT size_t olm_create_inbound_session_from( * If the message was for an unsupported protocol version then
* olm_session_last_error() will be "BAD_MESSAGE_VERSION". If the message
* couldn't be decoded then then olm_session_last_error() will be
* "BAD_MESSAGE_FORMAT". If the message refers to an unknown one time
* key then olm_session_last_error() will be "BAD_MESSAGE_KEY_ID". */
size_t olm_create_inbound_session_from(
OlmSession * session, OlmSession * session,
OlmAccount * account, OlmAccount * account,
void const * their_identity_key, size_t their_identity_key_length, void const * their_identity_key, size_t their_identity_key_length,
@ -369,30 +327,27 @@ OLM_EXPORT size_t olm_create_inbound_session_from(
); );
/** The length of the buffer needed to return the id for this session. */ /** The length of the buffer needed to return the id for this session. */
OLM_EXPORT size_t olm_session_id_length( size_t olm_session_id_length(
OlmSession const * session OlmSession * session
); );
/** An identifier for this session. Will be the same for both ends of the /** An identifier for this session. Will be the same for both ends of the
* conversation. If the id buffer is too small then olm_session_last_error() * conversation. If the id buffer is too small then olm_session_last_error()
* will be "OUTPUT_BUFFER_TOO_SMALL". */ * will be "OUTPUT_BUFFER_TOO_SMALL". */
OLM_EXPORT size_t olm_session_id( size_t olm_session_id(
OlmSession * session, OlmSession * session,
void * id, size_t id_length void * id, size_t id_length
); );
OLM_EXPORT int olm_session_has_received_message( int olm_session_has_received_message(
OlmSession const *session OlmSession *session
); );
/** /**
* Write a null-terminated string describing the internal state of an olm * Write a null-terminated string describing the internal state of an olm
* session to the buffer provided for debugging and logging purposes. If the * session to the buffer provided for debugging and logging purposes.
* buffer is not large enough to hold the entire string, it will be truncated
* and will end with "...". A buffer length of 600 will be enough to hold any
* output.
*/ */
OLM_EXPORT void olm_session_describe(OlmSession * session, char *buf, size_t buflen); void olm_session_describe(OlmSession * session, char *buf, size_t buflen);
/** Checks if the PRE_KEY message is for this in-bound session. This can happen /** Checks if the PRE_KEY message is for this in-bound session. This can happen
* if multiple messages are sent to this account before this account sends a * if multiple messages are sent to this account before this account sends a
@ -403,7 +358,7 @@ OLM_EXPORT void olm_session_describe(OlmSession * session, char *buf, size_t buf
* unsupported protocol version then olm_session_last_error() will be * unsupported protocol version then olm_session_last_error() will be
* "BAD_MESSAGE_VERSION". If the message couldn't be decoded then then * "BAD_MESSAGE_VERSION". If the message couldn't be decoded then then
* olm_session_last_error() will be "BAD_MESSAGE_FORMAT". */ * olm_session_last_error() will be "BAD_MESSAGE_FORMAT". */
OLM_EXPORT size_t olm_matches_inbound_session( size_t olm_matches_inbound_session(
OlmSession * session, OlmSession * session,
void * one_time_key_message, size_t message_length void * one_time_key_message, size_t message_length
); );
@ -417,7 +372,7 @@ OLM_EXPORT size_t olm_matches_inbound_session(
* unsupported protocol version then olm_session_last_error() will be * unsupported protocol version then olm_session_last_error() will be
* "BAD_MESSAGE_VERSION". If the message couldn't be decoded then then * "BAD_MESSAGE_VERSION". If the message couldn't be decoded then then
* olm_session_last_error() will be "BAD_MESSAGE_FORMAT". */ * olm_session_last_error() will be "BAD_MESSAGE_FORMAT". */
OLM_EXPORT size_t olm_matches_inbound_session_from( size_t olm_matches_inbound_session_from(
OlmSession * session, OlmSession * session,
void const * their_identity_key, size_t their_identity_key_length, void const * their_identity_key, size_t their_identity_key_length,
void * one_time_key_message, size_t message_length void * one_time_key_message, size_t message_length
@ -426,7 +381,7 @@ OLM_EXPORT size_t olm_matches_inbound_session_from(
/** Removes the one time keys that the session used from the account. Returns /** Removes the one time keys that the session used from the account. Returns
* olm_error() on failure. If the account doesn't have any matching one time * olm_error() on failure. If the account doesn't have any matching one time
* keys then olm_account_last_error() will be "BAD_MESSAGE_KEY_ID". */ * keys then olm_account_last_error() will be "BAD_MESSAGE_KEY_ID". */
OLM_EXPORT size_t olm_remove_one_time_keys( size_t olm_remove_one_time_keys(
OlmAccount * account, OlmAccount * account,
OlmSession * session OlmSession * session
); );
@ -435,19 +390,19 @@ OLM_EXPORT size_t olm_remove_one_time_keys(
* OLM_MESSAGE_TYPE_PRE_KEY if the message will be a PRE_KEY message. * OLM_MESSAGE_TYPE_PRE_KEY if the message will be a PRE_KEY message.
* Returns OLM_MESSAGE_TYPE_MESSAGE if the message will be a normal message. * Returns OLM_MESSAGE_TYPE_MESSAGE if the message will be a normal message.
* Returns olm_error on failure. */ * Returns olm_error on failure. */
OLM_EXPORT size_t olm_encrypt_message_type( size_t olm_encrypt_message_type(
OlmSession const * session OlmSession * session
); );
/** The number of random bytes needed to encrypt the next message. */ /** The number of random bytes needed to encrypt the next message. */
OLM_EXPORT size_t olm_encrypt_random_length( size_t olm_encrypt_random_length(
OlmSession const * session OlmSession * session
); );
/** The size of the next message in bytes for the given number of plain-text /** The size of the next message in bytes for the given number of plain-text
* bytes. */ * bytes. */
OLM_EXPORT size_t olm_encrypt_message_length( size_t olm_encrypt_message_length(
OlmSession const * session, OlmSession * session,
size_t plaintext_length size_t plaintext_length
); );
@ -457,7 +412,7 @@ OLM_EXPORT size_t olm_encrypt_message_length(
* olm_session_last_error() will be "OUTPUT_BUFFER_TOO_SMALL". If there * olm_session_last_error() will be "OUTPUT_BUFFER_TOO_SMALL". If there
* weren't enough random bytes then olm_session_last_error() will be * weren't enough random bytes then olm_session_last_error() will be
* "NOT_ENOUGH_RANDOM". */ * "NOT_ENOUGH_RANDOM". */
OLM_EXPORT size_t olm_encrypt( size_t olm_encrypt(
OlmSession * session, OlmSession * session,
void const * plaintext, size_t plaintext_length, void const * plaintext, size_t plaintext_length,
void * random, size_t random_length, void * random, size_t random_length,
@ -472,7 +427,7 @@ OLM_EXPORT size_t olm_encrypt(
* protocol then olm_session_last_error() will be "BAD_MESSAGE_VERSION". * protocol then olm_session_last_error() will be "BAD_MESSAGE_VERSION".
* If the message couldn't be decoded then olm_session_last_error() will be * If the message couldn't be decoded then olm_session_last_error() will be
* "BAD_MESSAGE_FORMAT". */ * "BAD_MESSAGE_FORMAT". */
OLM_EXPORT size_t olm_decrypt_max_plaintext_length( size_t olm_decrypt_max_plaintext_length(
OlmSession * session, OlmSession * session,
size_t message_type, size_t message_type,
void * message, size_t message_length void * message, size_t message_length
@ -489,7 +444,7 @@ OLM_EXPORT size_t olm_decrypt_max_plaintext_length(
* olm_session_last_error() will be BAD_MESSAGE_FORMAT". * olm_session_last_error() will be BAD_MESSAGE_FORMAT".
* If the MAC on the message was invalid then olm_session_last_error() will * If the MAC on the message was invalid then olm_session_last_error() will
* be "BAD_MESSAGE_MAC". */ * be "BAD_MESSAGE_MAC". */
OLM_EXPORT size_t olm_decrypt( size_t olm_decrypt(
OlmSession * session, OlmSession * session,
size_t message_type, size_t message_type,
void * message, size_t message_length, void * message, size_t message_length,
@ -497,14 +452,14 @@ OLM_EXPORT size_t olm_decrypt(
); );
/** The length of the buffer needed to hold the SHA-256 hash. */ /** The length of the buffer needed to hold the SHA-256 hash. */
OLM_EXPORT size_t olm_sha256_length( size_t olm_sha256_length(
OlmUtility const * utility OlmUtility * utility
); );
/** Calculates the SHA-256 hash of the input and encodes it as base64. If the /** Calculates the SHA-256 hash of the input and encodes it as base64. If the
* output buffer is smaller than olm_sha256_length() then * output buffer is smaller than olm_sha256_length() then
* olm_utility_last_error() will be "OUTPUT_BUFFER_TOO_SMALL". */ * olm_utility_last_error() will be "OUTPUT_BUFFER_TOO_SMALL". */
OLM_EXPORT size_t olm_sha256( size_t olm_sha256(
OlmUtility * utility, OlmUtility * utility,
void const * input, size_t input_length, void const * input, size_t input_length,
void * output, size_t output_length void * output, size_t output_length
@ -513,7 +468,7 @@ OLM_EXPORT size_t olm_sha256(
/** Verify an ed25519 signature. If the key was too small then /** Verify an ed25519 signature. If the key was too small then
* olm_utility_last_error() will be "INVALID_BASE64". If the signature was invalid * olm_utility_last_error() will be "INVALID_BASE64". If the signature was invalid
* then olm_utility_last_error() will be "BAD_MESSAGE_MAC". */ * then olm_utility_last_error() will be "BAD_MESSAGE_MAC". */
OLM_EXPORT size_t olm_ed25519_verify( size_t olm_ed25519_verify(
OlmUtility * utility, OlmUtility * utility,
void const * key, size_t key_length, void const * key, size_t key_length,
void const * message, size_t message_length, void const * message, size_t message_length,

View file

@ -1,42 +0,0 @@
#ifndef OLM_EXPORT_H
#define OLM_EXPORT_H
#ifdef OLM_STATIC_DEFINE
# define OLM_EXPORT
# define OLM_NO_EXPORT
#else
# ifndef OLM_EXPORT
# ifdef olm_EXPORTS
/* We are building this library */
# define OLM_EXPORT
# else
/* We are using this library */
# define OLM_EXPORT
# endif
# endif
# ifndef OLM_NO_EXPORT
# define OLM_NO_EXPORT
# endif
#endif
#ifndef OLM_DEPRECATED
# define OLM_DEPRECATED __attribute__ ((__deprecated__))
#endif
#ifndef OLM_DEPRECATED_EXPORT
# define OLM_DEPRECATED_EXPORT OLM_EXPORT OLM_DEPRECATED
#endif
#ifndef OLM_DEPRECATED_NO_EXPORT
# define OLM_DEPRECATED_NO_EXPORT OLM_NO_EXPORT OLM_DEPRECATED
#endif
#if 0 /* DEFINE_NO_DEPRECATED */
# ifndef OLM_NO_DEPRECATED
# define OLM_NO_DEPRECATED
# endif
#endif
#endif /* OLM_EXPORT_H */

View file

@ -18,10 +18,6 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "olm/error.h"
#include "olm/olm_export.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -29,38 +25,31 @@ extern "C" {
typedef struct OlmOutboundGroupSession OlmOutboundGroupSession; typedef struct OlmOutboundGroupSession OlmOutboundGroupSession;
/** get the size of an outbound group session, in bytes. */ /** get the size of an outbound group session, in bytes. */
OLM_EXPORT size_t olm_outbound_group_session_size(void); size_t olm_outbound_group_session_size(void);
/** /**
* Initialise an outbound group session object using the supplied memory * Initialise an outbound group session object using the supplied memory
* The supplied memory should be at least olm_outbound_group_session_size() * The supplied memory should be at least olm_outbound_group_session_size()
* bytes. * bytes.
*/ */
OLM_EXPORT OlmOutboundGroupSession * olm_outbound_group_session( OlmOutboundGroupSession * olm_outbound_group_session(
void *memory void *memory
); );
/** /**
* A null terminated string describing the most recent error to happen to a * A null terminated string describing the most recent error to happen to a
* group session */ * group session */
OLM_EXPORT const char *olm_outbound_group_session_last_error( const char *olm_outbound_group_session_last_error(
const OlmOutboundGroupSession *session
);
/**
* An error code describing the most recent error to happen to a group
* session */
OLM_EXPORT enum OlmErrorCode olm_outbound_group_session_last_error_code(
const OlmOutboundGroupSession *session const OlmOutboundGroupSession *session
); );
/** Clears the memory used to back this group session */ /** Clears the memory used to back this group session */
OLM_EXPORT size_t olm_clear_outbound_group_session( size_t olm_clear_outbound_group_session(
OlmOutboundGroupSession *session OlmOutboundGroupSession *session
); );
/** Returns the number of bytes needed to store an outbound group session */ /** Returns the number of bytes needed to store an outbound group session */
OLM_EXPORT size_t olm_pickle_outbound_group_session_length( size_t olm_pickle_outbound_group_session_length(
const OlmOutboundGroupSession *session const OlmOutboundGroupSession *session
); );
@ -72,7 +61,7 @@ OLM_EXPORT size_t olm_pickle_outbound_group_session_length(
* is smaller than olm_pickle_outbound_group_session_length() then * is smaller than olm_pickle_outbound_group_session_length() then
* olm_outbound_group_session_last_error() will be "OUTPUT_BUFFER_TOO_SMALL" * olm_outbound_group_session_last_error() will be "OUTPUT_BUFFER_TOO_SMALL"
*/ */
OLM_EXPORT size_t olm_pickle_outbound_group_session( size_t olm_pickle_outbound_group_session(
OlmOutboundGroupSession *session, OlmOutboundGroupSession *session,
void const * key, size_t key_length, void const * key, size_t key_length,
void * pickled, size_t pickled_length void * pickled, size_t pickled_length
@ -88,7 +77,7 @@ OLM_EXPORT size_t olm_pickle_outbound_group_session(
* olm_outbound_group_session_last_error() will be "INVALID_BASE64". The input * olm_outbound_group_session_last_error() will be "INVALID_BASE64". The input
* pickled buffer is destroyed * pickled buffer is destroyed
*/ */
OLM_EXPORT size_t olm_unpickle_outbound_group_session( size_t olm_unpickle_outbound_group_session(
OlmOutboundGroupSession *session, OlmOutboundGroupSession *session,
void const * key, size_t key_length, void const * key, size_t key_length,
void * pickled, size_t pickled_length void * pickled, size_t pickled_length
@ -96,7 +85,7 @@ OLM_EXPORT size_t olm_unpickle_outbound_group_session(
/** The number of random bytes needed to create an outbound group session */ /** The number of random bytes needed to create an outbound group session */
OLM_EXPORT size_t olm_init_outbound_group_session_random_length( size_t olm_init_outbound_group_session_random_length(
const OlmOutboundGroupSession *session const OlmOutboundGroupSession *session
); );
@ -105,7 +94,7 @@ OLM_EXPORT size_t olm_init_outbound_group_session_random_length(
* failure last_error will be set with an error code. The last_error will be * failure last_error will be set with an error code. The last_error will be
* NOT_ENOUGH_RANDOM if the number of random bytes was too small. * NOT_ENOUGH_RANDOM if the number of random bytes was too small.
*/ */
OLM_EXPORT size_t olm_init_outbound_group_session( size_t olm_init_outbound_group_session(
OlmOutboundGroupSession *session, OlmOutboundGroupSession *session,
uint8_t *random, size_t random_length uint8_t *random, size_t random_length
); );
@ -113,7 +102,7 @@ OLM_EXPORT size_t olm_init_outbound_group_session(
/** /**
* The number of bytes that will be created by encrypting a message * The number of bytes that will be created by encrypting a message
*/ */
OLM_EXPORT size_t olm_group_encrypt_message_length( size_t olm_group_encrypt_message_length(
OlmOutboundGroupSession *session, OlmOutboundGroupSession *session,
size_t plaintext_length size_t plaintext_length
); );
@ -124,7 +113,7 @@ OLM_EXPORT size_t olm_group_encrypt_message_length(
* error code. The last_error will be OUTPUT_BUFFER_TOO_SMALL if the output * error code. The last_error will be OUTPUT_BUFFER_TOO_SMALL if the output
* buffer is too small. * buffer is too small.
*/ */
OLM_EXPORT size_t olm_group_encrypt( size_t olm_group_encrypt(
OlmOutboundGroupSession *session, OlmOutboundGroupSession *session,
uint8_t const * plaintext, size_t plaintext_length, uint8_t const * plaintext, size_t plaintext_length,
uint8_t * message, size_t message_length uint8_t * message, size_t message_length
@ -134,7 +123,7 @@ OLM_EXPORT size_t olm_group_encrypt(
/** /**
* Get the number of bytes returned by olm_outbound_group_session_id() * Get the number of bytes returned by olm_outbound_group_session_id()
*/ */
OLM_EXPORT size_t olm_outbound_group_session_id_length( size_t olm_outbound_group_session_id_length(
const OlmOutboundGroupSession *session const OlmOutboundGroupSession *session
); );
@ -146,7 +135,7 @@ OLM_EXPORT size_t olm_outbound_group_session_id_length(
* last_error will be OUTPUT_BUFFER_TOO_SMALL if the id buffer was too * last_error will be OUTPUT_BUFFER_TOO_SMALL if the id buffer was too
* small. * small.
*/ */
OLM_EXPORT size_t olm_outbound_group_session_id( size_t olm_outbound_group_session_id(
OlmOutboundGroupSession *session, OlmOutboundGroupSession *session,
uint8_t * id, size_t id_length uint8_t * id, size_t id_length
); );
@ -157,14 +146,14 @@ OLM_EXPORT size_t olm_outbound_group_session_id(
* Each message is sent with an increasing index; this returns the index for * Each message is sent with an increasing index; this returns the index for
* the next message. * the next message.
*/ */
OLM_EXPORT uint32_t olm_outbound_group_session_message_index( uint32_t olm_outbound_group_session_message_index(
OlmOutboundGroupSession *session OlmOutboundGroupSession *session
); );
/** /**
* Get the number of bytes returned by olm_outbound_group_session_key() * Get the number of bytes returned by olm_outbound_group_session_key()
*/ */
OLM_EXPORT size_t olm_outbound_group_session_key_length( size_t olm_outbound_group_session_key_length(
const OlmOutboundGroupSession *session const OlmOutboundGroupSession *session
); );
@ -178,7 +167,7 @@ OLM_EXPORT size_t olm_outbound_group_session_key_length(
* failure. On failure last_error will be set with an error code. The * failure. On failure last_error will be set with an error code. The
* last_error will be OUTPUT_BUFFER_TOO_SMALL if the buffer was too small. * last_error will be OUTPUT_BUFFER_TOO_SMALL if the buffer was too small.
*/ */
OLM_EXPORT size_t olm_outbound_group_session_key( size_t olm_outbound_group_session_key(
OlmOutboundGroupSession *session, OlmOutboundGroupSession *session,
uint8_t * key, size_t key_length uint8_t * key, size_t key_length
); );

View file

@ -15,25 +15,8 @@
#ifndef OLM_PICKLE_H_ #ifndef OLM_PICKLE_H_
#define OLM_PICKLE_H_ #define OLM_PICKLE_H_
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
/* Convenience macro for checking the return value of internal unpickling
* functions and returning early on failure. */
#ifndef UNPICKLE_OK
#define UNPICKLE_OK(x) do { if (!(x)) return NULL; } while(0)
#endif
/* Convenience macro for failing on corrupted pickles from public
* API unpickling functions. */
#define FAIL_ON_CORRUPTED_PICKLE(pos, session) \
do { \
if (!pos) { \
session->last_error = OLM_CORRUPTED_PICKLE; \
return (size_t)-1; \
} \
} while(0)
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -76,7 +59,7 @@ uint8_t * _olm_pickle_ed25519_public_key(
); );
/** Unpickle the ed25519 public key. Returns a pointer to the next item in the /** Unpickle the ed25519 public key. Returns a pointer to the next item in the
* buffer on success, NULL on error. */ * buffer. */
const uint8_t * _olm_unpickle_ed25519_public_key( const uint8_t * _olm_unpickle_ed25519_public_key(
const uint8_t *pos, const uint8_t *end, const uint8_t *pos, const uint8_t *end,
struct _olm_ed25519_public_key * value struct _olm_ed25519_public_key * value
@ -94,7 +77,7 @@ uint8_t * _olm_pickle_ed25519_key_pair(
); );
/** Unpickle the ed25519 key pair. Returns a pointer to the next item in the /** Unpickle the ed25519 key pair. Returns a pointer to the next item in the
* buffer on success, NULL on error. */ * buffer. */
const uint8_t * _olm_unpickle_ed25519_key_pair( const uint8_t * _olm_unpickle_ed25519_key_pair(
const uint8_t *pos, const uint8_t *end, const uint8_t *pos, const uint8_t *end,
struct _olm_ed25519_key_pair * value struct _olm_ed25519_key_pair * value

View file

@ -21,12 +21,6 @@
#include <cstring> #include <cstring>
#include <cstdint> #include <cstdint>
/* Convenience macro for checking the return value of internal unpickling
* functions and returning early on failure. */
#ifndef UNPICKLE_OK
#define UNPICKLE_OK(x) do { if (!(x)) return nullptr; } while(0)
#endif
namespace olm { namespace olm {
inline std::size_t pickle_length( inline std::size_t pickle_length(
@ -46,23 +40,6 @@ std::uint8_t const * unpickle(
); );
inline std::size_t pickle_length(
const std::uint8_t & value
) {
return 1;
}
std::uint8_t * pickle(
std::uint8_t * pos,
std::uint8_t value
);
std::uint8_t const * unpickle(
std::uint8_t const * pos, std::uint8_t const * end,
std::uint8_t & value
);
inline std::size_t pickle_length( inline std::size_t pickle_length(
const bool & value const bool & value
) { ) {
@ -111,21 +88,11 @@ std::uint8_t const * unpickle(
olm::List<T, max_size> & list olm::List<T, max_size> & list
) { ) {
std::uint32_t size; std::uint32_t size;
pos = unpickle(pos, end, size); pos = unpickle(pos, end, size);
if (!pos) {
return nullptr;
}
while (size-- && pos != end) { while (size-- && pos != end) {
T * value = list.insert(list.end()); T * value = list.insert(list.end());
pos = unpickle(pos, end, *value); pos = unpickle(pos, end, *value);
if (!pos) {
return nullptr;
} }
}
return pos; return pos;
} }

View file

@ -23,10 +23,6 @@
#include "olm/error.h" #include "olm/error.h"
// Note: exports in this file are only for unit tests. Nobody else should be
// using this externally
#include "olm/olm_export.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -35,7 +31,7 @@ extern "C" {
/** /**
* Get the number of bytes needed to encode a pickle of the length given * Get the number of bytes needed to encode a pickle of the length given
*/ */
OLM_EXPORT size_t _olm_enc_output_length(size_t raw_length); size_t _olm_enc_output_length(size_t raw_length);
/** /**
* Get the point in the output buffer that the raw pickle should be written to. * Get the point in the output buffer that the raw pickle should be written to.
@ -45,7 +41,7 @@ OLM_EXPORT size_t _olm_enc_output_length(size_t raw_length);
* base-64 encoding would otherwise overwrite the end of the input before it * base-64 encoding would otherwise overwrite the end of the input before it
* was encoded.) * was encoded.)
*/ */
OLM_EXPORT uint8_t *_olm_enc_output_pos(uint8_t * output, size_t raw_length); uint8_t *_olm_enc_output_pos(uint8_t * output, size_t raw_length);
/** /**
* Encrypt and encode the given pickle in-situ. * Encrypt and encode the given pickle in-situ.
@ -55,7 +51,7 @@ OLM_EXPORT uint8_t *_olm_enc_output_pos(uint8_t * output, size_t raw_length);
* *
* Returns the number of bytes in the encoded pickle. * Returns the number of bytes in the encoded pickle.
*/ */
OLM_EXPORT size_t _olm_enc_output( size_t _olm_enc_output(
uint8_t const * key, size_t key_length, uint8_t const * key, size_t key_length,
uint8_t *pickle, size_t raw_length uint8_t *pickle, size_t raw_length
); );
@ -66,7 +62,7 @@ OLM_EXPORT size_t _olm_enc_output(
* Returns the number of bytes in the decoded pickle, or olm_error() on error, * Returns the number of bytes in the decoded pickle, or olm_error() on error,
* in which case *last_error will be updated, if last_error is non-NULL. * in which case *last_error will be updated, if last_error is non-NULL.
*/ */
OLM_EXPORT size_t _olm_enc_input( size_t _olm_enc_input(
uint8_t const * key, size_t key_length, uint8_t const * key, size_t key_length,
uint8_t * input, size_t b64_length, uint8_t * input, size_t b64_length,
enum OlmErrorCode * last_error enum OlmErrorCode * last_error

View file

@ -19,10 +19,6 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "olm/error.h"
#include "olm/olm_export.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -30,55 +26,49 @@ extern "C" {
typedef struct OlmPkEncryption OlmPkEncryption; typedef struct OlmPkEncryption OlmPkEncryption;
/* The size of an encryption object in bytes */ /* The size of an encryption object in bytes */
OLM_EXPORT size_t olm_pk_encryption_size(void); size_t olm_pk_encryption_size(void);
/** Initialise an encryption object using the supplied memory /** Initialise an encryption object using the supplied memory
* The supplied memory must be at least olm_pk_encryption_size() bytes */ * The supplied memory must be at least olm_pk_encryption_size() bytes */
OLM_EXPORT OlmPkEncryption *olm_pk_encryption( OlmPkEncryption *olm_pk_encryption(
void * memory void * memory
); );
/** A null terminated string describing the most recent error to happen to an /** A null terminated string describing the most recent error to happen to an
* encryption object */ * encryption object */
OLM_EXPORT const char * olm_pk_encryption_last_error( const char * olm_pk_encryption_last_error(
const OlmPkEncryption * encryption OlmPkEncryption * encryption
);
/** An error code describing the most recent error to happen to an encryption
* object */
OLM_EXPORT enum OlmErrorCode olm_pk_encryption_last_error_code(
const OlmPkEncryption * encryption
); );
/** Clears the memory used to back this encryption object */ /** Clears the memory used to back this encryption object */
OLM_EXPORT size_t olm_clear_pk_encryption( size_t olm_clear_pk_encryption(
OlmPkEncryption *encryption OlmPkEncryption *encryption
); );
/** Set the recipient's public key for encrypting to */ /** Set the recipient's public key for encrypting to */
OLM_EXPORT size_t olm_pk_encryption_set_recipient_key( size_t olm_pk_encryption_set_recipient_key(
OlmPkEncryption *encryption, OlmPkEncryption *encryption,
void const *public_key, size_t public_key_length void const *public_key, size_t public_key_length
); );
/** Get the length of the ciphertext that will correspond to a plaintext of the /** Get the length of the ciphertext that will correspond to a plaintext of the
* given length. */ * given length. */
OLM_EXPORT size_t olm_pk_ciphertext_length( size_t olm_pk_ciphertext_length(
const OlmPkEncryption *encryption, OlmPkEncryption *encryption,
size_t plaintext_length size_t plaintext_length
); );
/** Get the length of the message authentication code. */ /** Get the length of the message authentication code. */
OLM_EXPORT size_t olm_pk_mac_length( size_t olm_pk_mac_length(
const OlmPkEncryption *encryption OlmPkEncryption *encryption
); );
/** Get the length of a public or ephemeral key */ /** Get the length of a public or ephemeral key */
OLM_EXPORT size_t olm_pk_key_length(void); size_t olm_pk_key_length(void);
/** The number of random bytes needed to encrypt a message. */ /** The number of random bytes needed to encrypt a message. */
OLM_EXPORT size_t olm_pk_encrypt_random_length( size_t olm_pk_encrypt_random_length(
const OlmPkEncryption *encryption OlmPkEncryption *encryption
); );
/** Encrypt a plaintext for the recipient set using /** Encrypt a plaintext for the recipient set using
@ -91,7 +81,7 @@ OLM_EXPORT size_t olm_pk_encrypt_random_length(
* ephemeral_key buffers were too small then olm_pk_encryption_last_error() * ephemeral_key buffers were too small then olm_pk_encryption_last_error()
* will be "OUTPUT_BUFFER_TOO_SMALL". If there weren't enough random bytes then * will be "OUTPUT_BUFFER_TOO_SMALL". If there weren't enough random bytes then
* olm_pk_encryption_last_error() will be "OLM_INPUT_BUFFER_TOO_SMALL". */ * olm_pk_encryption_last_error() will be "OLM_INPUT_BUFFER_TOO_SMALL". */
OLM_EXPORT size_t olm_pk_encrypt( size_t olm_pk_encrypt(
OlmPkEncryption *encryption, OlmPkEncryption *encryption,
void const * plaintext, size_t plaintext_length, void const * plaintext, size_t plaintext_length,
void * ciphertext, size_t ciphertext_length, void * ciphertext, size_t ciphertext_length,
@ -103,38 +93,32 @@ OLM_EXPORT size_t olm_pk_encrypt(
typedef struct OlmPkDecryption OlmPkDecryption; typedef struct OlmPkDecryption OlmPkDecryption;
/* The size of a decryption object in bytes */ /* The size of a decryption object in bytes */
OLM_EXPORT size_t olm_pk_decryption_size(void); size_t olm_pk_decryption_size(void);
/** Initialise a decryption object using the supplied memory /** Initialise a decryption object using the supplied memory
* The supplied memory must be at least olm_pk_decryption_size() bytes */ * The supplied memory must be at least olm_pk_decryption_size() bytes */
OLM_EXPORT OlmPkDecryption *olm_pk_decryption( OlmPkDecryption *olm_pk_decryption(
void * memory void * memory
); );
/** A null terminated string describing the most recent error to happen to a /** A null terminated string describing the most recent error to happen to a
* decription object */ * decription object */
OLM_EXPORT const char * olm_pk_decryption_last_error( const char * olm_pk_decryption_last_error(
const OlmPkDecryption * decryption OlmPkDecryption * decryption
);
/** An error code describing the most recent error to happen to a decription
* object */
OLM_EXPORT enum OlmErrorCode olm_pk_decryption_last_error_code(
const OlmPkDecryption * decryption
); );
/** Clears the memory used to back this decryption object */ /** Clears the memory used to back this decryption object */
OLM_EXPORT size_t olm_clear_pk_decryption( size_t olm_clear_pk_decryption(
OlmPkDecryption *decryption OlmPkDecryption *decryption
); );
/** Get the number of bytes required to store an olm private key /** Get the number of bytes required to store an olm private key
*/ */
OLM_EXPORT size_t olm_pk_private_key_length(void); size_t olm_pk_private_key_length(void);
/** DEPRECATED: Use olm_pk_private_key_length() /** DEPRECATED: Use olm_pk_private_key_length()
*/ */
OLM_EXPORT size_t olm_pk_generate_key_random_length(void); size_t olm_pk_generate_key_random_length(void);
/** Initialise the key from the private part of a key as returned by /** Initialise the key from the private part of a key as returned by
* olm_pk_get_private_key(). The associated public key will be written to the * olm_pk_get_private_key(). The associated public key will be written to the
@ -146,7 +130,7 @@ OLM_EXPORT size_t olm_pk_generate_key_random_length(void);
* Note that the pubkey is a base64 encoded string, but the private key is * Note that the pubkey is a base64 encoded string, but the private key is
* an unencoded byte array * an unencoded byte array
*/ */
OLM_EXPORT size_t olm_pk_key_from_private( size_t olm_pk_key_from_private(
OlmPkDecryption * decryption, OlmPkDecryption * decryption,
void * pubkey, size_t pubkey_length, void * pubkey, size_t pubkey_length,
const void * privkey, size_t privkey_length const void * privkey, size_t privkey_length
@ -154,15 +138,15 @@ OLM_EXPORT size_t olm_pk_key_from_private(
/** DEPRECATED: Use olm_pk_key_from_private /** DEPRECATED: Use olm_pk_key_from_private
*/ */
OLM_EXPORT size_t olm_pk_generate_key( size_t olm_pk_generate_key(
OlmPkDecryption * decryption, OlmPkDecryption * decryption,
void * pubkey, size_t pubkey_length, void * pubkey, size_t pubkey_length,
const void * privkey, size_t privkey_length const void * privkey, size_t privkey_length
); );
/** Returns the number of bytes needed to store a decryption object. */ /** Returns the number of bytes needed to store a decryption object. */
OLM_EXPORT size_t olm_pickle_pk_decryption_length( size_t olm_pickle_pk_decryption_length(
const OlmPkDecryption * decryption OlmPkDecryption * decryption
); );
/** Stores decryption object as a base64 string. Encrypts the object using the /** Stores decryption object as a base64 string. Encrypts the object using the
@ -170,7 +154,7 @@ OLM_EXPORT size_t olm_pickle_pk_decryption_length(
* Returns olm_error() on failure. If the pickle output buffer * Returns olm_error() on failure. If the pickle output buffer
* is smaller than olm_pickle_pk_decryption_length() then * is smaller than olm_pickle_pk_decryption_length() then
* olm_pk_decryption_last_error() will be "OUTPUT_BUFFER_TOO_SMALL" */ * olm_pk_decryption_last_error() will be "OUTPUT_BUFFER_TOO_SMALL" */
OLM_EXPORT size_t olm_pickle_pk_decryption( size_t olm_pickle_pk_decryption(
OlmPkDecryption * decryption, OlmPkDecryption * decryption,
void const * key, size_t key_length, void const * key, size_t key_length,
void *pickled, size_t pickled_length void *pickled, size_t pickled_length
@ -183,7 +167,7 @@ OLM_EXPORT size_t olm_pickle_pk_decryption(
* will be "BAD_ACCOUNT_KEY". If the base64 couldn't be decoded then * will be "BAD_ACCOUNT_KEY". If the base64 couldn't be decoded then
* olm_pk_decryption_last_error() will be "INVALID_BASE64". The input pickled * olm_pk_decryption_last_error() will be "INVALID_BASE64". The input pickled
* buffer is destroyed */ * buffer is destroyed */
OLM_EXPORT size_t olm_unpickle_pk_decryption( size_t olm_unpickle_pk_decryption(
OlmPkDecryption * decryption, OlmPkDecryption * decryption,
void const * key, size_t key_length, void const * key, size_t key_length,
void *pickled, size_t pickled_length, void *pickled, size_t pickled_length,
@ -192,8 +176,8 @@ OLM_EXPORT size_t olm_unpickle_pk_decryption(
/** Get the length of the plaintext that will correspond to a ciphertext of the /** Get the length of the plaintext that will correspond to a ciphertext of the
* given length. */ * given length. */
OLM_EXPORT size_t olm_pk_max_plaintext_length( size_t olm_pk_max_plaintext_length(
const OlmPkDecryption * decryption, OlmPkDecryption * decryption,
size_t ciphertext_length size_t ciphertext_length
); );
@ -202,7 +186,7 @@ OLM_EXPORT size_t olm_pk_max_plaintext_length(
* arguments. Returns the length of the plaintext on success. Returns * arguments. Returns the length of the plaintext on success. Returns
* olm_error() on failure. If the plaintext buffer is too small then * olm_error() on failure. If the plaintext buffer is too small then
* olm_pk_encryption_last_error() will be "OUTPUT_BUFFER_TOO_SMALL". */ * olm_pk_encryption_last_error() will be "OUTPUT_BUFFER_TOO_SMALL". */
OLM_EXPORT size_t olm_pk_decrypt( size_t olm_pk_decrypt(
OlmPkDecryption * decryption, OlmPkDecryption * decryption,
void const * ephemeral_key, size_t ephemeral_key_length, void const * ephemeral_key, size_t ephemeral_key_length,
void const * mac, size_t mac_length, void const * mac, size_t mac_length,
@ -218,7 +202,7 @@ OLM_EXPORT size_t olm_pk_decrypt(
* and olm_pk_encryption_last_error() will be "OUTPUT_BUFFER_TOO_SMALL". * and olm_pk_encryption_last_error() will be "OUTPUT_BUFFER_TOO_SMALL".
* Returns the number of bytes written. * Returns the number of bytes written.
*/ */
OLM_EXPORT size_t olm_pk_get_private_key( size_t olm_pk_get_private_key(
OlmPkDecryption * decryption, OlmPkDecryption * decryption,
void *private_key, size_t private_key_length void *private_key, size_t private_key_length
); );
@ -226,28 +210,22 @@ OLM_EXPORT size_t olm_pk_get_private_key(
typedef struct OlmPkSigning OlmPkSigning; typedef struct OlmPkSigning OlmPkSigning;
/* The size of a signing object in bytes */ /* The size of a signing object in bytes */
OLM_EXPORT size_t olm_pk_signing_size(void); size_t olm_pk_signing_size(void);
/** Initialise a signing object using the supplied memory /** Initialise a signing object using the supplied memory
* The supplied memory must be at least olm_pk_signing_size() bytes */ * The supplied memory must be at least olm_pk_signing_size() bytes */
OLM_EXPORT OlmPkSigning *olm_pk_signing( OlmPkSigning *olm_pk_signing(
void * memory void * memory
); );
/** A null terminated string describing the most recent error to happen to a /** A null terminated string describing the most recent error to happen to a
* signing object */ * signing object */
OLM_EXPORT const char * olm_pk_signing_last_error( const char * olm_pk_signing_last_error(
const OlmPkSigning * sign OlmPkSigning * sign
);
/** A null terminated string describing the most recent error to happen to a
* signing object */
OLM_EXPORT enum OlmErrorCode olm_pk_signing_last_error_code(
const OlmPkSigning * sign
); );
/** Clears the memory used to back this signing object */ /** Clears the memory used to back this signing object */
OLM_EXPORT size_t olm_clear_pk_signing( size_t olm_clear_pk_signing(
OlmPkSigning *sign OlmPkSigning *sign
); );
@ -259,7 +237,7 @@ OLM_EXPORT size_t olm_clear_pk_signing(
* buffer is too small then olm_pk_signing_last_error() will be * buffer is too small then olm_pk_signing_last_error() will be
* "INPUT_BUFFER_TOO_SMALL". * "INPUT_BUFFER_TOO_SMALL".
*/ */
OLM_EXPORT size_t olm_pk_signing_key_from_seed( size_t olm_pk_signing_key_from_seed(
OlmPkSigning * sign, OlmPkSigning * sign,
void * pubkey, size_t pubkey_length, void * pubkey, size_t pubkey_length,
const void * seed, size_t seed_length const void * seed, size_t seed_length
@ -268,24 +246,24 @@ OLM_EXPORT size_t olm_pk_signing_key_from_seed(
/** /**
* The size required for the seed for initialising a signing object. * The size required for the seed for initialising a signing object.
*/ */
OLM_EXPORT size_t olm_pk_signing_seed_length(void); size_t olm_pk_signing_seed_length(void);
/** /**
* The size of the public key of a signing object. * The size of the public key of a signing object.
*/ */
OLM_EXPORT size_t olm_pk_signing_public_key_length(void); size_t olm_pk_signing_public_key_length(void);
/** /**
* The size of a signature created by a signing object. * The size of a signature created by a signing object.
*/ */
OLM_EXPORT size_t olm_pk_signature_length(void); size_t olm_pk_signature_length(void);
/** /**
* Sign a message. The signature will be written to the signature * Sign a message. The signature will be written to the signature
* buffer. Returns olm_error() on failure. If the signature buffer is too * buffer. Returns olm_error() on failure. If the signature buffer is too
* small, olm_pk_signing_last_error() will be "OUTPUT_BUFFER_TOO_SMALL". * small, olm_pk_signing_last_error() will be "OUTPUT_BUFFER_TOO_SMALL".
*/ */
OLM_EXPORT size_t olm_pk_sign( size_t olm_pk_sign(
OlmPkSigning *sign, OlmPkSigning *sign,
uint8_t const * message, size_t message_length, uint8_t const * message, size_t message_length,
uint8_t * signature, size_t signature_length uint8_t * signature, size_t signature_length

View file

@ -19,10 +19,6 @@
#include "olm/list.hh" #include "olm/list.hh"
#include "olm/error.h" #include "olm/error.h"
// Note: exports in this file are only for unit tests. Nobody else should be
// using this externally
#include "olm/olm_export.h"
struct _olm_cipher; struct _olm_cipher;
namespace olm { namespace olm {
@ -76,7 +72,7 @@ struct KdfInfo {
}; };
struct OLM_EXPORT Ratchet { struct Ratchet {
Ratchet( Ratchet(
KdfInfo const & kdf_info, KdfInfo const & kdf_info,
@ -128,12 +124,12 @@ struct OLM_EXPORT Ratchet {
* a given message length. */ * a given message length. */
std::size_t encrypt_output_length( std::size_t encrypt_output_length(
std::size_t plaintext_length std::size_t plaintext_length
) const; );
/** The number of bytes of random data the encrypt method will need to /** The number of bytes of random data the encrypt method will need to
* encrypt a message. This will be 32 bytes if the session needs to * encrypt a message. This will be 32 bytes if the session needs to
* generate a new ephemeral key, or will be 0 bytes otherwise.*/ * generate a new ephemeral key, or will be 0 bytes otherwise.*/
std::size_t encrypt_random_length() const; std::size_t encrypt_random_length();
/** Encrypt some plain-text. Returns the length of the encrypted message /** Encrypt some plain-text. Returns the length of the encrypted message
* or std::size_t(-1) on failure. On failure last_error will be set with * or std::size_t(-1) on failure. On failure last_error will be set with

View file

@ -19,10 +19,6 @@
#include <stddef.h> #include <stddef.h>
#include "olm/error.h"
#include "olm/olm_export.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -37,33 +33,27 @@ typedef struct OlmSAS OlmSAS;
/** A null terminated string describing the most recent error to happen to an /** A null terminated string describing the most recent error to happen to an
* SAS object. */ * SAS object. */
OLM_EXPORT const char * olm_sas_last_error( const char * olm_sas_last_error(
const OlmSAS * sas OlmSAS * sas
);
/** An error code describing the most recent error to happen to an SAS
* object. */
OLM_EXPORT enum OlmErrorCode olm_sas_last_error_code(
const OlmSAS * sas
); );
/** The size of an SAS object in bytes. */ /** The size of an SAS object in bytes. */
OLM_EXPORT size_t olm_sas_size(void); size_t olm_sas_size(void);
/** Initialize an SAS object using the supplied memory. /** Initialize an SAS object using the supplied memory.
* The supplied memory must be at least `olm_sas_size()` bytes. */ * The supplied memory must be at least `olm_sas_size()` bytes. */
OLM_EXPORT OlmSAS * olm_sas( OlmSAS * olm_sas(
void * memory void * memory
); );
/** Clears the memory used to back an SAS object. */ /** Clears the memory used to back an SAS object. */
OLM_EXPORT size_t olm_clear_sas( size_t olm_clear_sas(
OlmSAS * sas OlmSAS * sas
); );
/** The number of random bytes needed to create an SAS object. */ /** The number of random bytes needed to create an SAS object. */
OLM_EXPORT size_t olm_create_sas_random_length( size_t olm_create_sas_random_length(
const OlmSAS * sas OlmSAS * sas
); );
/** Creates a new SAS object. /** Creates a new SAS object.
@ -77,13 +67,13 @@ OLM_EXPORT size_t olm_create_sas_random_length(
* @return `olm_error()` on failure. If there weren't enough random bytes then * @return `olm_error()` on failure. If there weren't enough random bytes then
* `olm_sas_last_error()` will be `NOT_ENOUGH_RANDOM`. * `olm_sas_last_error()` will be `NOT_ENOUGH_RANDOM`.
*/ */
OLM_EXPORT size_t olm_create_sas( size_t olm_create_sas(
OlmSAS * sas, OlmSAS * sas,
void * random, size_t random_length void * random, size_t random_length
); );
/** The size of a public key in bytes. */ /** The size of a public key in bytes. */
OLM_EXPORT size_t olm_sas_pubkey_length(const OlmSAS * sas); size_t olm_sas_pubkey_length(OlmSAS * sas);
/** Get the public key for the SAS object. /** Get the public key for the SAS object.
* *
@ -95,7 +85,7 @@ OLM_EXPORT size_t olm_sas_pubkey_length(const OlmSAS * sas);
* @return `olm_error()` on failure. If the `pubkey` buffer is too small, then * @return `olm_error()` on failure. If the `pubkey` buffer is too small, then
* `olm_sas_last_error()` will be `OUTPUT_BUFFER_TOO_SMALL`. * `olm_sas_last_error()` will be `OUTPUT_BUFFER_TOO_SMALL`.
*/ */
OLM_EXPORT size_t olm_sas_get_pubkey( size_t olm_sas_get_pubkey(
OlmSAS * sas, OlmSAS * sas,
void * pubkey, size_t pubkey_length void * pubkey, size_t pubkey_length
); );
@ -110,7 +100,7 @@ OLM_EXPORT size_t olm_sas_get_pubkey(
* @return `olm_error()` on failure. If the `their_key` buffer is too small, * @return `olm_error()` on failure. If the `their_key` buffer is too small,
* then `olm_sas_last_error()` will be `INPUT_BUFFER_TOO_SMALL`. * then `olm_sas_last_error()` will be `INPUT_BUFFER_TOO_SMALL`.
*/ */
OLM_EXPORT size_t olm_sas_set_their_key( size_t olm_sas_set_their_key(
OlmSAS *sas, OlmSAS *sas,
void * their_key, size_t their_key_length void * their_key, size_t their_key_length
); );
@ -120,8 +110,8 @@ OLM_EXPORT size_t olm_sas_set_their_key(
* @param[in] sas the SAS object. * @param[in] sas the SAS object.
* *
*/ */
OLM_EXPORT int olm_sas_is_their_key_set( int olm_sas_is_their_key_set(
const OlmSAS *sas OlmSAS *sas
); );
/** Generate bytes to use for the short authentication string. /** Generate bytes to use for the short authentication string.
@ -137,7 +127,7 @@ OLM_EXPORT int olm_sas_is_their_key_set(
* @return `olm_error()` on failure. If their key wasn't set then * @return `olm_error()` on failure. If their key wasn't set then
* `olm_sas_last_error()` will be `SAS_THEIR_KEY_NOT_SET`. * `olm_sas_last_error()` will be `SAS_THEIR_KEY_NOT_SET`.
*/ */
OLM_EXPORT size_t olm_sas_generate_bytes( size_t olm_sas_generate_bytes(
OlmSAS * sas, OlmSAS * sas,
const void * info, size_t info_length, const void * info, size_t info_length,
void * output, size_t output_length void * output, size_t output_length
@ -145,8 +135,8 @@ OLM_EXPORT size_t olm_sas_generate_bytes(
/** The size of the message authentication code generated by /** The size of the message authentication code generated by
* olm_sas_calculate_mac()`. */ * olm_sas_calculate_mac()`. */
OLM_EXPORT size_t olm_sas_mac_length( size_t olm_sas_mac_length(
const OlmSAS *sas OlmSAS *sas
); );
/** Generate a message authentication code (MAC) based on the shared secret. /** Generate a message authentication code (MAC) based on the shared secret.
@ -164,7 +154,7 @@ OLM_EXPORT size_t olm_sas_mac_length(
* @return `olm_error()` on failure. If the `mac` buffer is too small, then * @return `olm_error()` on failure. If the `mac` buffer is too small, then
* `olm_sas_last_error()` will be `OUTPUT_BUFFER_TOO_SMALL`. * `olm_sas_last_error()` will be `OUTPUT_BUFFER_TOO_SMALL`.
*/ */
OLM_EXPORT size_t olm_sas_calculate_mac( size_t olm_sas_calculate_mac(
OlmSAS * sas, OlmSAS * sas,
const void * input, size_t input_length, const void * input, size_t input_length,
const void * info, size_t info_length, const void * info, size_t info_length,
@ -173,7 +163,7 @@ OLM_EXPORT size_t olm_sas_calculate_mac(
// A version of the calculate mac function that produces base64 strings that are // A version of the calculate mac function that produces base64 strings that are
// compatible with other base64 implementations. // compatible with other base64 implementations.
OLM_EXPORT size_t olm_sas_calculate_mac_fixed_base64( size_t olm_sas_calculate_mac_fixed_base64(
OlmSAS * sas, OlmSAS * sas,
const void * input, size_t input_length, const void * input, size_t input_length,
const void * info, size_t info_length, const void * info, size_t info_length,
@ -181,7 +171,7 @@ OLM_EXPORT size_t olm_sas_calculate_mac_fixed_base64(
); );
// for compatibility with an old version of Riot // for compatibility with an old version of Riot
OLM_EXPORT size_t olm_sas_calculate_mac_long_kdf( size_t olm_sas_calculate_mac_long_kdf(
OlmSAS * sas, OlmSAS * sas,
const void * input, size_t input_length, const void * input, size_t input_length,
const void * info, size_t info_length, const void * info, size_t info_length,

View file

@ -17,10 +17,6 @@
#include "olm/ratchet.hh" #include "olm/ratchet.hh"
// Note: exports in this file are only for unit tests. Nobody else should be
// using this externally
#include "olm/olm_export.h"
namespace olm { namespace olm {
struct Account; struct Account;
@ -30,7 +26,7 @@ enum struct MessageType {
MESSAGE = 1, MESSAGE = 1,
}; };
struct OLM_EXPORT Session { struct Session {
Session(); Session();
@ -45,7 +41,7 @@ struct OLM_EXPORT Session {
/** The number of random bytes that are needed to create a new outbound /** The number of random bytes that are needed to create a new outbound
* session. This will be 64 bytes since two ephemeral keys are needed. */ * session. This will be 64 bytes since two ephemeral keys are needed. */
std::size_t new_outbound_session_random_length() const; std::size_t new_outbound_session_random_length();
/** Start a new outbound session. Returns std::size_t(-1) on failure. On /** Start a new outbound session. Returns std::size_t(-1) on failure. On
* failure last_error will be set with an error code. The last_error will be * failure last_error will be set with an error code. The last_error will be
@ -68,7 +64,7 @@ struct OLM_EXPORT Session {
); );
/** The number of bytes written by session_id() */ /** The number of bytes written by session_id() */
std::size_t session_id_length() const; std::size_t session_id_length();
/** An identifier for this session. Generated by hashing the public keys /** An identifier for this session. Generated by hashing the public keys
* used to create the session. Returns the length of the session id on * used to create the session. Returns the length of the session id on
@ -88,21 +84,21 @@ struct OLM_EXPORT Session {
bool matches_inbound_session( bool matches_inbound_session(
_olm_curve25519_public_key const * their_identity_key, _olm_curve25519_public_key const * their_identity_key,
std::uint8_t const * pre_key_message, std::size_t message_length std::uint8_t const * pre_key_message, std::size_t message_length
) const; );
/** Whether the next message will be a pre-key message or a normal message. /** Whether the next message will be a pre-key message or a normal message.
* An outbound session will send pre-key messages until it receives a * An outbound session will send pre-key messages until it receives a
* message with a ratchet key. */ * message with a ratchet key. */
MessageType encrypt_message_type() const; MessageType encrypt_message_type();
std::size_t encrypt_message_length( std::size_t encrypt_message_length(
std::size_t plaintext_length std::size_t plaintext_length
) const; );
/** The number of bytes of random data the encrypt method will need to /** The number of bytes of random data the encrypt method will need to
* encrypt a message. This will be 32 bytes if the session needs to * encrypt a message. This will be 32 bytes if the session needs to
* generate a new ephemeral key, or will be 0 bytes otherwise. */ * generate a new ephemeral key, or will be 0 bytes otherwise. */
std::size_t encrypt_random_length() const; std::size_t encrypt_random_length();
/** Encrypt some plain-text. Returns the length of the encrypted message /** Encrypt some plain-text. Returns the length of the encrypted message
* or std::size_t(-1) on failure. On failure last_error will be set with * or std::size_t(-1) on failure. On failure last_error will be set with
@ -157,7 +153,7 @@ std::uint8_t * pickle(
); );
OLM_EXPORT std::uint8_t const * unpickle( std::uint8_t const * unpickle(
std::uint8_t const * pos, std::uint8_t const * end, std::uint8_t const * pos, std::uint8_t const * end,
Session & value Session & value
); );

View file

@ -32,7 +32,7 @@ struct Utility {
OlmErrorCode last_error; OlmErrorCode last_error;
/** The length of a SHA-256 hash in bytes. */ /** The length of a SHA-256 hash in bytes. */
std::size_t sha256_length() const; std::size_t sha256_length();
/** Compute a SHA-256 hash. Returns the length of the SHA-256 hash in bytes /** Compute a SHA-256 hash. Returns the length of the SHA-256 hash in bytes
* on success. Returns std::size_t(-1) on failure. On failure last_error * on success. Returns std::size_t(-1) on failure. On failure last_error

View file

@ -1,29 +0,0 @@
default:
image: docker.io/emscripten/emsdk:latest
stages:
- build
- test
build:js:
stage: build
script:
- ln -sf $(which python3) /usr/local/bin/python
- make js
artifacts:
paths:
- build/javascript
- javascript/olm.js
- javascript/olm.wasm
- javascript/olm_legacy.js
- javascript/index.d.ts
- javascript/exported_functions.json
test:js:
stage: test
needs:
- build:js
script:
- pushd javascript
- npm i
- npm run test

View file

@ -5,11 +5,6 @@ Note: before using any of the olm functions, you must call `Olm.init()`, and
wait for the promise to resolve, otherwise you will get errors like: wait for the promise to resolve, otherwise you will get errors like:
`Uncaught TypeError: Olm.Account is not a constructor` `Uncaught TypeError: Olm.Account is not a constructor`
If you get errors about failure to compile the wasm file, it is likely that Olm
is not locating the wasm file properly. You can tell Olm where the wasm file
is by passing a `locateFile` parameter to `Olm.init()`, for example:
`Olm.init({locateFile: () => pathToWasmFile})`.
Example: Example:
var alice = new Olm.Account(); var alice = new Olm.Account();

39
javascript/index.d.ts vendored
View file

@ -18,28 +18,26 @@ export as namespace Olm;
declare class Account { declare class Account {
constructor(); constructor();
free(): void; free();
create(): void; create();
identity_keys(): string; identity_keys(): string;
sign(message: string | Uint8Array): string; sign(message: string | Uint8Array): string;
one_time_keys(): string; one_time_keys(): string;
mark_keys_as_published(): void; mark_keys_as_published();
max_number_of_one_time_keys(): number; max_number_of_one_time_keys(): number;
generate_one_time_keys(number_of_keys: number): void; generate_one_time_keys(number_of_keys: number);
remove_one_time_keys(session: Session): void; remove_one_time_keys(session: Session);
generate_fallback_key(): void; generate_fallback_key();
fallback_key(): string; fallback_key(): string;
unpublished_fallback_key(): string;
forget_old_fallback_key(): void;
pickle(key: string | Uint8Array): string; pickle(key: string | Uint8Array): string;
unpickle(key: string | Uint8Array, pickle: string): void; unpickle(key: string | Uint8Array, pickle: string);
} }
declare class Session { declare class Session {
constructor(); constructor();
free(): void; free(): void;
pickle(key: string | Uint8Array): string; pickle(key: string | Uint8Array): string;
unpickle(key: string | Uint8Array, pickle: string): void; unpickle(key: string | Uint8Array, pickle: string);
create_outbound( create_outbound(
account: Account, their_identity_key: string, their_one_time_key: string, account: Account, their_identity_key: string, their_one_time_key: string,
): void; ): void;
@ -51,10 +49,7 @@ declare class Session {
has_received_message(): boolean; has_received_message(): boolean;
matches_inbound(one_time_key_message: string): boolean; matches_inbound(one_time_key_message: string): boolean;
matches_inbound_from(identity_key: string, one_time_key_message: string): boolean; matches_inbound_from(identity_key: string, one_time_key_message: string): boolean;
encrypt(plaintext: string): { encrypt(plaintext: string): object;
type: 0 | 1; // 0: PreKey, 1: Message
body: string;
};
decrypt(message_type: number, message: string): string; decrypt(message_type: number, message: string): string;
describe(): string; describe(): string;
} }
@ -70,13 +65,10 @@ declare class InboundGroupSession {
constructor(); constructor();
free(): void; free(): void;
pickle(key: string | Uint8Array): string; pickle(key: string | Uint8Array): string;
unpickle(key: string | Uint8Array, pickle: string): void; unpickle(key: string | Uint8Array, pickle: string);
create(session_key: string): string; create(session_key: string): string;
import_session(session_key: string): string; import_session(session_key: string): string;
decrypt(message: string): { decrypt(message: string): object;
message_index: number;
plaintext: string;
};
session_id(): string; session_id(): string;
first_known_index(): number; first_known_index(): number;
export_session(message_index: number): string; export_session(message_index: number): string;
@ -86,7 +78,7 @@ declare class OutboundGroupSession {
constructor(); constructor();
free(): void; free(): void;
pickle(key: string | Uint8Array): string; pickle(key: string | Uint8Array): string;
unpickle(key: string | Uint8Array, pickle: string): void; unpickle(key: string | Uint8Array, pickle: string);
create(): void; create(): void;
encrypt(plaintext: string): string; encrypt(plaintext: string): string;
session_id(): string; session_id(): string;
@ -98,11 +90,7 @@ declare class PkEncryption {
constructor(); constructor();
free(): void; free(): void;
set_recipient_key(key: string): void; set_recipient_key(key: string): void;
encrypt(plaintext: string): { encrypt(plaintext: string): object;
ciphertext: string;
mac: string;
ephemeral: string;
};
} }
declare class PkDecryption { declare class PkDecryption {
@ -131,7 +119,6 @@ declare class SAS {
set_their_key(their_key: string): void; set_their_key(their_key: string): void;
generate_bytes(info: string, length: number): Uint8Array; generate_bytes(info: string, length: number): Uint8Array;
calculate_mac(input: string, info: string): string; calculate_mac(input: string, info: string): string;
calculate_mac_fixed_base64(input: string, info: string): string;
calculate_mac_long_kdf(input: string, info: string): string; calculate_mac_long_kdf(input: string, info: string): string;
} }

View file

@ -1,4 +1,3 @@
/** @constructor */
function InboundGroupSession() { function InboundGroupSession() {
var size = Module['_olm_inbound_group_session_size'](); var size = Module['_olm_inbound_group_session_size']();
this.buf = malloc(size); this.buf = malloc(size);

View file

@ -1,4 +1,3 @@
/** @constructor */
function OutboundGroupSession() { function OutboundGroupSession() {
var size = Module['_olm_outbound_group_session_size'](); var size = Module['_olm_outbound_group_session_size']();
this.buf = malloc(size); this.buf = malloc(size);
@ -68,14 +67,9 @@ OutboundGroupSession.prototype['create'] = restore_stack(function() {
Module['_olm_init_outbound_group_session_random_length'] Module['_olm_init_outbound_group_session_random_length']
)(this.ptr); )(this.ptr);
var random = random_stack(random_length); var random = random_stack(random_length);
try {
outbound_group_session_method(Module['_olm_init_outbound_group_session'])( outbound_group_session_method(Module['_olm_init_outbound_group_session'])(
this.ptr, random, random_length this.ptr, random, random_length
); );
} finally {
// clear the random buffer
bzero(random, random_length);
}
}); });
OutboundGroupSession.prototype['encrypt'] = function(plaintext) { OutboundGroupSession.prototype['encrypt'] = function(plaintext) {

View file

@ -1,4 +1,3 @@
/** @constructor */
function PkEncryption() { function PkEncryption() {
var size = Module['_olm_pk_encryption_size'](); var size = Module['_olm_pk_encryption_size']();
this.buf = malloc(size); this.buf = malloc(size);
@ -99,7 +98,6 @@ PkEncryption.prototype['encrypt'] = restore_stack(function(
}); });
/** @constructor */
function PkDecryption() { function PkDecryption() {
var size = Module['_olm_pk_decryption_size'](); var size = Module['_olm_pk_decryption_size']();
this.buf = malloc(size); this.buf = malloc(size);
@ -275,7 +273,6 @@ PkDecryption.prototype['decrypt'] = restore_stack(function (
}) })
/** @constructor */
function PkSigning() { function PkSigning() {
var size = Module['_olm_pk_signing_size'](); var size = Module['_olm_pk_signing_size']();
this.buf = malloc(size); this.buf = malloc(size);

View file

@ -44,7 +44,6 @@ function bzero(ptr, n) {
} }
} }
/** @constructor */
function Account() { function Account() {
var size = Module['_olm_account_size'](); var size = Module['_olm_account_size']();
this.buf = malloc(size); this.buf = malloc(size);
@ -74,14 +73,9 @@ Account.prototype['create'] = restore_stack(function() {
Module['_olm_create_account_random_length'] Module['_olm_create_account_random_length']
)(this.ptr); )(this.ptr);
var random = random_stack(random_length); var random = random_stack(random_length);
try {
account_method(Module['_olm_create_account'])( account_method(Module['_olm_create_account'])(
this.ptr, random, random_length this.ptr, random, random_length
); );
} finally {
// clear the random buffer
bzero(random, random_length);
}
}); });
Account.prototype['identity_keys'] = restore_stack(function() { Account.prototype['identity_keys'] = restore_stack(function() {
@ -146,14 +140,9 @@ Account.prototype['generate_one_time_keys'] = restore_stack(function(
Module['_olm_account_generate_one_time_keys_random_length'] Module['_olm_account_generate_one_time_keys_random_length']
)(this.ptr, number_of_keys); )(this.ptr, number_of_keys);
var random = random_stack(random_length); var random = random_stack(random_length);
try {
account_method(Module['_olm_account_generate_one_time_keys'])( account_method(Module['_olm_account_generate_one_time_keys'])(
this.ptr, number_of_keys, random, random_length this.ptr, number_of_keys, random, random_length
); );
} finally {
// clear the random buffer
bzero(random, random_length);
}
}); });
Account.prototype['remove_one_time_keys'] = restore_stack(function(session) { Account.prototype['remove_one_time_keys'] = restore_stack(function(session) {
@ -167,14 +156,9 @@ Account.prototype['generate_fallback_key'] = restore_stack(function() {
Module['_olm_account_generate_fallback_key_random_length'] Module['_olm_account_generate_fallback_key_random_length']
)(this.ptr); )(this.ptr);
var random = random_stack(random_length); var random = random_stack(random_length);
try {
account_method(Module['_olm_account_generate_fallback_key'])( account_method(Module['_olm_account_generate_fallback_key'])(
this.ptr, random, random_length this.ptr, random, random_length
); );
} finally {
// clear the random buffer
bzero(random, random_length);
}
}); });
Account.prototype['fallback_key'] = restore_stack(function() { Account.prototype['fallback_key'] = restore_stack(function() {
@ -188,23 +172,6 @@ Account.prototype['fallback_key'] = restore_stack(function() {
return UTF8ToString(keys, keys_length); return UTF8ToString(keys, keys_length);
}); });
Account.prototype['unpublished_fallback_key'] = restore_stack(function() {
var keys_length = account_method(
Module['_olm_account_unpublished_fallback_key_length']
)(this.ptr);
var keys = stack(keys_length + NULL_BYTE_PADDING_LENGTH);
account_method(Module['_olm_account_unpublished_fallback_key'])(
this.ptr, keys, keys_length
);
return UTF8ToString(keys, keys_length);
});
Account.prototype['forget_old_fallback_key'] = restore_stack(function() {
account_method(Module['_olm_account_forget_old_fallback_key'])(
this.ptr
);
});
Account.prototype['pickle'] = restore_stack(function(key) { Account.prototype['pickle'] = restore_stack(function(key) {
var key_array = array_from_string(key); var key_array = array_from_string(key);
var pickle_length = account_method( var pickle_length = account_method(
@ -245,7 +212,6 @@ Account.prototype['unpickle'] = restore_stack(function(key, pickle) {
} }
}); });
/** @constructor */
function Session() { function Session() {
var size = Module['_olm_session_size'](); var size = Module['_olm_session_size']();
this.buf = malloc(size); this.buf = malloc(size);
@ -532,7 +498,6 @@ Session.prototype['describe'] = restore_stack(function() {
} }
}); });
/** @constructor */
function Utility() { function Utility() {
var size = Module['_olm_utility_size'](); var size = Module['_olm_utility_size']();
this.buf = malloc(size); this.buf = malloc(size);

View file

@ -14,6 +14,7 @@ if (typeof(window) !== 'undefined') {
var bytes = nodeCrypto['randomBytes'](buf.length); var bytes = nodeCrypto['randomBytes'](buf.length);
buf.set(bytes); buf.set(bytes);
}; };
process = global["process"];
} else { } else {
throw new Error("Cannot find global to attach library to"); throw new Error("Cannot find global to attach library to");
} }

View file

@ -1,4 +1,3 @@
/** @constructor */
function SAS() { function SAS() {
var size = Module['_olm_sas_size'](); var size = Module['_olm_sas_size']();
var random_length = Module['_olm_create_sas_random_length'](); var random_length = Module['_olm_create_sas_random_length']();
@ -83,22 +82,6 @@ SAS.prototype['calculate_mac'] = restore_stack(function(input, info) {
return UTF8ToString(mac_buffer, mac_length); return UTF8ToString(mac_buffer, mac_length);
}); });
SAS.prototype['calculate_mac_fixed_base64'] = restore_stack(function(input, info) {
var input_array = array_from_string(input);
var input_buffer = stack(input_array);
var info_array = array_from_string(info);
var info_buffer = stack(info_array);
var mac_length = sas_method(Module['_olm_sas_mac_length'])(this.ptr);
var mac_buffer = stack(mac_length + NULL_BYTE_PADDING_LENGTH);
sas_method(Module['_olm_sas_calculate_mac_fixed_base64'])(
this.ptr,
input_buffer, input_array.length,
info_buffer, info_array.length,
mac_buffer, mac_length
);
return UTF8ToString(mac_buffer, mac_length);
});
SAS.prototype['calculate_mac_long_kdf'] = restore_stack(function(input, info) { SAS.prototype['calculate_mac_long_kdf'] = restore_stack(function(input, info) {
var input_array = array_from_string(input); var input_array = array_from_string(input);
var input_buffer = stack(input_array); var input_buffer = stack(input_array);

View file

@ -1,241 +0,0 @@
{
"name": "@matrix-org/olm",
"version": "3.2.11",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@matrix-org/olm",
"version": "3.2.11",
"license": "Apache-2.0",
"devDependencies": {
"jasmine": "^3.0.0"
}
},
"node_modules/balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
"dev": true
},
"node_modules/brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"dependencies": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
"dev": true
},
"node_modules/fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
"dev": true
},
"node_modules/glob": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz",
"integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==",
"dev": true,
"dependencies": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
},
"engines": {
"node": "*"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"dev": true,
"dependencies": {
"once": "^1.3.0",
"wrappy": "1"
}
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"dev": true
},
"node_modules/jasmine": {
"version": "3.99.0",
"resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.99.0.tgz",
"integrity": "sha512-YIThBuHzaIIcjxeuLmPD40SjxkEcc8i//sGMDKCgkRMVgIwRJf5qyExtlJpQeh7pkeoBSOe6lQEdg+/9uKg9mw==",
"dev": true,
"dependencies": {
"glob": "^7.1.6",
"jasmine-core": "~3.99.0"
},
"bin": {
"jasmine": "bin/jasmine.js"
}
},
"node_modules/jasmine-core": {
"version": "3.99.1",
"resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.99.1.tgz",
"integrity": "sha512-Hu1dmuoGcZ7AfyynN3LsfruwMbxMALMka+YtZeGoLuDEySVmVAPaonkNoBRIw/ectu8b9tVQCJNgp4a4knp+tg==",
"dev": true
},
"node_modules/minimatch": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
"dev": true,
"dependencies": {
"brace-expansion": "^1.1.7"
},
"engines": {
"node": "*"
}
},
"node_modules/once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"dev": true,
"dependencies": {
"wrappy": "1"
}
},
"node_modules/path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
"dev": true,
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"dev": true
}
},
"dependencies": {
"balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
"dev": true
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
"dev": true
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
"dev": true
},
"glob": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz",
"integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"dev": true,
"requires": {
"once": "^1.3.0",
"wrappy": "1"
}
},
"inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"dev": true
},
"jasmine": {
"version": "3.99.0",
"resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.99.0.tgz",
"integrity": "sha512-YIThBuHzaIIcjxeuLmPD40SjxkEcc8i//sGMDKCgkRMVgIwRJf5qyExtlJpQeh7pkeoBSOe6lQEdg+/9uKg9mw==",
"dev": true,
"requires": {
"glob": "^7.1.6",
"jasmine-core": "~3.99.0"
}
},
"jasmine-core": {
"version": "3.99.1",
"resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.99.1.tgz",
"integrity": "sha512-Hu1dmuoGcZ7AfyynN3LsfruwMbxMALMka+YtZeGoLuDEySVmVAPaonkNoBRIw/ectu8b9tVQCJNgp4a4knp+tg==",
"dev": true
},
"minimatch": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
"dev": true,
"requires": {
"brace-expansion": "^1.1.7"
}
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"dev": true,
"requires": {
"wrappy": "1"
}
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
"dev": true
},
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"dev": true
}
}
}

View file

@ -1,6 +1,6 @@
{ {
"name": "@matrix-org/olm", "name": "@matrix-org/olm",
"version": "3.2.16", "version": "3.2.2",
"description": "An implementation of the Double Ratchet cryptographic ratchet", "description": "An implementation of the Double Ratchet cryptographic ratchet",
"main": "olm.js", "main": "olm.js",
"files": [ "files": [
@ -14,7 +14,7 @@
], ],
"scripts": { "scripts": {
"build": "make -C .. js", "build": "make -C .. js",
"test": "jasmine --config=test/jasmine.json" "test": "jasmine-node test --verbose --junitreport --captureExceptions"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -30,6 +30,9 @@
}, },
"homepage": "https://gitlab.matrix.org/matrix-org/olm", "homepage": "https://gitlab.matrix.org/matrix-org/olm",
"devDependencies": { "devDependencies": {
"jasmine": "^3.0.0" "jasmine-node": "^1.14.5"
},
"publishConfig": {
"@matrix-org:registry":"https://gitlab.matrix.org/api/v4/projects/27/packages/npm/"
} }
} }

View file

@ -1,6 +0,0 @@
{
"spec_dir": "test",
"spec_files": [
"**/*.spec.js"
]
}

View file

@ -19,7 +19,7 @@ var Olm = require('../olm');
describe("sas", function() { describe("sas", function() {
var alice, bob; var alice, bob;
beforeEach(function(done) { beforeEach(async function(done) {
Olm.init().then(function() { Olm.init().then(function() {
alice = new Olm.SAS(); alice = new Olm.SAS();
bob = new Olm.SAS(); bob = new Olm.SAS();

View file

@ -442,161 +442,6 @@ JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env,
} }
} }
/**
* Generate "fallback key".
* An exception is thrown if the operation fails.
**/
JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(generateFallbackKeyJni)(JNIEnv *env, jobject thiz)
{
const char* errorMessage = NULL;
OlmAccount *accountPtr = getAccountInstanceId(env, thiz);
if (!accountPtr)
{
LOGE("## generateFallbackKeyJni(): failure - invalid Account ptr");
errorMessage = "invalid Account ptr";
}
else
{
// keys memory allocation
size_t randomLength = olm_account_generate_fallback_key_random_length(accountPtr);
LOGD("## generateFallbackKeyJni(): randomLength=%lu", static_cast<long unsigned int>(randomLength));
uint8_t *randomBufferPtr = NULL;
if ((0 != randomLength) && !setRandomInBuffer(env, &randomBufferPtr, randomLength))
{
LOGE("## generateFallbackKeyJni(): failure - random buffer init");
errorMessage = "random buffer init";
}
else
{
LOGD("## generateFallbackKeyJni(): accountPtr =%p", accountPtr);
// retrieve key pairs in keysBytesPtr
size_t result = olm_account_generate_fallback_key(accountPtr, (void*)randomBufferPtr, randomLength);
if (result == olm_error())
{
errorMessage = olm_account_last_error(accountPtr);
LOGE("## generateFallbackKeyJni(): failure - error generating fallback keys Msg=%s", errorMessage);
}
else
{
LOGD("## generateFallbackKeyJni(): success - result=%lu", static_cast<long unsigned int>(result));
}
}
if (randomBufferPtr)
{
memset(randomBufferPtr, 0, randomLength);
free(randomBufferPtr);
}
}
if (errorMessage)
{
env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
}
}
/**
* Get "fallback key".<br>
* Return the public parts of the unpublished "fallback key" for the account
* @return a valid byte array if operation succeed, null otherwise
**/
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(fallbackKeyJni)(JNIEnv *env, jobject thiz)
{
const char* errorMessage = NULL;
jbyteArray byteArrayRetValue = NULL;
OlmAccount* accountPtr = getAccountInstanceId(env, thiz);
LOGD("## fallbackKeyJni(): IN");
if (!accountPtr)
{
LOGE("## fallbackKeyJni(): failure - invalid Account ptr");
errorMessage = "invalid Account ptr";
}
else
{
// keys memory allocation
size_t keysLength = olm_account_unpublished_fallback_key_length(accountPtr);
uint8_t *keysBytesPtr = (uint8_t *)malloc(keysLength*sizeof(uint8_t));
if (!keysBytesPtr)
{
LOGE("## fallbackKeyJni(): failure - fallback key OOM");
errorMessage = "fallback key OOM";
}
else
{
// retrieve key pairs in keysBytesPtr
size_t keysResult = olm_account_unpublished_fallback_key(accountPtr, keysBytesPtr, keysLength);
if (keysResult == olm_error()) {
LOGE("## fallbackKeyJni(): failure - error getting fallback key Msg=%s",(const char *)olm_account_last_error(accountPtr));
errorMessage = (const char *)olm_account_last_error(accountPtr);
}
else
{
// allocate the byte array to be returned to java
byteArrayRetValue = env->NewByteArray(keysLength);
if (!byteArrayRetValue)
{
LOGE("## fallbackKeyJni(): failure - return byte array OOM");
errorMessage = "return byte array OOM";
}
else
{
env->SetByteArrayRegion(byteArrayRetValue, 0/*offset*/, keysLength, (const jbyte*)keysBytesPtr);
LOGD("## fallbackKeyJni(): success");
}
}
free(keysBytesPtr);
}
}
if (errorMessage)
{
env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
}
return byteArrayRetValue;
}
/**
* Forget about the old fallback key.
*
* This should be called once you are reasonably certain that you will not
* receive any more messages that use the old fallback key (e.g. 5 minutes
* after the new fallback key has been published).
**/
JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(forgetFallbackKeyJni)(JNIEnv *env, jobject thiz)
{
const char* errorMessage = NULL;
OlmAccount *accountPtr = getAccountInstanceId(env, thiz);
if (!accountPtr)
{
LOGE("## forgetFallbackKeyJni(): failure - invalid Account ptr");
errorMessage = "invalid Account ptr";
}
else
{
olm_account_forget_old_fallback_key(accountPtr);
}
if (errorMessage)
{
env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
}
}
/** /**
* Sign a message with the ed25519 key (fingerprint) for this account.<br> * Sign a message with the ed25519 key (fingerprint) for this account.<br>
* The signed message is returned by the function. * The signed message is returned by the function.

View file

@ -42,11 +42,6 @@ JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(generateOneTimeKeysJni)(JNIEnv *env, jobject
JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(removeOneTimeKeysJni)(JNIEnv *env, jobject thiz, jlong aNativeOlmSessionId); JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(removeOneTimeKeysJni)(JNIEnv *env, jobject thiz, jlong aNativeOlmSessionId);
JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env, jobject thiz); JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env, jobject thiz);
// fallback keys
JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(generateFallbackKeyJni)(JNIEnv *env, jobject thiz);
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(fallbackKeyJni)(JNIEnv *env, jobject thiz);
JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(forgetFallbackKeyJni)(JNIEnv *env, jobject thiz);
// signing // signing
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aMessage); JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aMessage);

View file

@ -309,86 +309,6 @@ JNIEXPORT jbyteArray OLM_SAS_FUNC_DEF(calculateMacJni)(JNIEnv *env, jobject thiz
return returnValue; return returnValue;
} }
JNIEXPORT jbyteArray OLM_SAS_FUNC_DEF(calculateMacFixedBase64Jni)(JNIEnv *env, jobject thiz,jbyteArray messageBuffer,jbyteArray infoBuffer) {
LOGD("## calculateMacFixedBase64Jni(): IN");
const char* errorMessage = NULL;
jbyteArray returnValue = 0;
OlmSAS* sasPtr = getOlmSasInstanceId(env, thiz);
jbyte *messagePtr = NULL;
jboolean messageWasCopied = JNI_FALSE;
jbyte *infoPtr = NULL;
jboolean infoWasCopied = JNI_FALSE;
if (!sasPtr)
{
LOGE("## calculateMacFixedBase64Jni(): failure - invalid SAS ptr=NULL");
errorMessage = "invalid SAS ptr=NULL";
} else if(!messageBuffer) {
LOGE("## calculateMacFixedBase64Jni(): failure - invalid message");
errorMessage = "invalid info";
}
else if (!(messagePtr = env->GetByteArrayElements(messageBuffer, &messageWasCopied)))
{
LOGE(" ## calculateMacFixedBase64Jni(): failure - message JNI allocation OOM");
errorMessage = "message JNI allocation OOM";
}
else if (!(infoPtr = env->GetByteArrayElements(infoBuffer, &infoWasCopied)))
{
LOGE(" ## calculateMacFixedBase64Jni(): failure - info JNI allocation OOM");
errorMessage = "info JNI allocation OOM";
} else {
size_t infoLength = (size_t)env->GetArrayLength(infoBuffer);
size_t messageLength = (size_t)env->GetArrayLength(messageBuffer);
size_t macLength = olm_sas_mac_length(sasPtr);
void *macPtr = malloc(macLength*sizeof(uint8_t));
size_t result = olm_sas_calculate_mac_fixed_base64(sasPtr,messagePtr,messageLength,infoPtr,infoLength,macPtr,macLength);
if (result == olm_error())
{
errorMessage = (const char *)olm_sas_last_error(sasPtr);
LOGE("## calculateMacFixedBase64Jni(): failure - error calculating SAS mac Msg=%s", errorMessage);
}
else
{
returnValue = env->NewByteArray(macLength);
env->SetByteArrayRegion(returnValue, 0 , macLength, (jbyte*)macPtr);
}
if (macPtr) {
free(macPtr);
}
}
// free alloc
if (infoPtr)
{
if (infoWasCopied)
{
memset(infoPtr, 0, (size_t)env->GetArrayLength(infoBuffer));
}
env->ReleaseByteArrayElements(infoBuffer, infoPtr, JNI_ABORT);
}
if (messagePtr)
{
if (messageWasCopied)
{
memset(messagePtr, 0, (size_t)env->GetArrayLength(messageBuffer));
}
env->ReleaseByteArrayElements(messageBuffer, messagePtr, JNI_ABORT);
}
if (errorMessage)
{
env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
}
return returnValue;
}
JNIEXPORT jbyteArray OLM_SAS_FUNC_DEF(calculateMacLongKdfJni)(JNIEnv *env, jobject thiz,jbyteArray messageBuffer,jbyteArray infoBuffer) { JNIEXPORT jbyteArray OLM_SAS_FUNC_DEF(calculateMacLongKdfJni)(JNIEnv *env, jobject thiz,jbyteArray messageBuffer,jbyteArray infoBuffer) {
LOGD("## calculateMacLongKdfJni(): IN"); LOGD("## calculateMacLongKdfJni(): IN");
const char* errorMessage = NULL; const char* errorMessage = NULL;

View file

@ -32,7 +32,6 @@ JNIEXPORT jbyteArray OLM_SAS_FUNC_DEF(getPubKeyJni)(JNIEnv *env, jobject thiz);
JNIEXPORT void OLM_SAS_FUNC_DEF(setTheirPubKey)(JNIEnv *env, jobject thiz,jbyteArray pubKey); JNIEXPORT void OLM_SAS_FUNC_DEF(setTheirPubKey)(JNIEnv *env, jobject thiz,jbyteArray pubKey);
JNIEXPORT jbyteArray OLM_SAS_FUNC_DEF(generateShortCodeJni)(JNIEnv *env, jobject thiz, jbyteArray infoStringBytes, jint byteNb); JNIEXPORT jbyteArray OLM_SAS_FUNC_DEF(generateShortCodeJni)(JNIEnv *env, jobject thiz, jbyteArray infoStringBytes, jint byteNb);
JNIEXPORT jbyteArray OLM_SAS_FUNC_DEF(calculateMacJni)(JNIEnv *env, jobject thiz, jbyteArray messageBuffer, jbyteArray infoBuffer); JNIEXPORT jbyteArray OLM_SAS_FUNC_DEF(calculateMacJni)(JNIEnv *env, jobject thiz, jbyteArray messageBuffer, jbyteArray infoBuffer);
JNIEXPORT jbyteArray OLM_SAS_FUNC_DEF(calculateMacFixedBase64Jni)(JNIEnv *env, jobject thiz, jbyteArray messageBuffer, jbyteArray infoBuffer);
JNIEXPORT jbyteArray OLM_SAS_FUNC_DEF(calculateMacLongKdfJni)(JNIEnv *env, jobject thiz, jbyteArray messageBuffer, jbyteArray infoBuffer); JNIEXPORT jbyteArray OLM_SAS_FUNC_DEF(calculateMacLongKdfJni)(JNIEnv *env, jobject thiz, jbyteArray messageBuffer, jbyteArray infoBuffer);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -798,58 +798,6 @@ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env,
return returnValue; return returnValue;
} }
JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(olmSessionDescribeJni(JNIEnv *env, jobject thiz))
{
const char* errorMessage = NULL;
jbyteArray returnValue = 0;
LOGD("## olmSessionDescribeJni(): IN ");
OlmSession *sessionPtr = getSessionInstanceId(env, thiz);
if (!sessionPtr)
{
LOGE("## olmSessionDescribeJni(): failure - invalid Session ptr=NULL");
errorMessage = "invalid Session ptr=NULL";
}
else
{
int maxLength = 600;
char* describePtr = NULL;
describePtr = (char*) malloc(maxLength * sizeof *describePtr);
if (!describePtr)
{
LOGE("## olmSessionDescribeJni(): failure - describe allocation OOM");
errorMessage = "describe allocation OOM";
}
else
{
olm_session_describe(sessionPtr, describePtr, maxLength);
int length = strlen(describePtr);
if (length == 0)
{
LOGE("## olmSessionDescribeJni(): failure - get session describe");
}
else
{
LOGD("## olmSessionDescribeJni(): success - describe=%.*s", (char*)describePtr);
returnValue = env->NewByteArray(length);
env->SetByteArrayRegion(returnValue, 0, length, (jbyte*)describePtr);
}
free(describePtr);
}
}
if (errorMessage)
{
env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
}
return returnValue;
}
/** /**
* Serialize and encrypt session instance.<br> * Serialize and encrypt session instance.<br>
* An exception is thrown if the operation fails. * An exception is thrown if the operation fails.

View file

@ -47,7 +47,6 @@ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobjec
JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jobject aEncryptedMsg); JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jobject aEncryptedMsg);
JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env, jobject thiz); JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env, jobject thiz);
JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(olmSessionDescribeJni)(JNIEnv *env, jobject thiz);
// serialization // serialization
JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKey); JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKey);

Some files were not shown because too many files have changed in this diff Show more