From 15cb4ec0c0c6b2205e5d3ba0b59c09dd20b4bab5 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 24 May 2016 14:36:07 +0100 Subject: Build the crypto libs as C99 Some of the crypto libs rely on UINT64_C, which in glibc 2.17 and earlier was not defined for C++ code (see https://sourceware.org/bugzilla/show_bug.cgi?id=15366). --- Makefile | 3 ++- src/libs.c | 25 +++++++++++++++++++++++++ src/libs.cpp | 27 --------------------------- 3 files changed, 27 insertions(+), 28 deletions(-) create mode 100644 src/libs.c delete mode 100644 src/libs.cpp diff --git a/Makefile b/Makefile index cbdb948..4bc6c3f 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,8 @@ JS_PRE := $(wildcard javascript/*pre.js) JS_POST := $(wildcard javascript/*post.js) CPPFLAGS += -Iinclude -Ilib -CFLAGS += -Wall -Werror -std=c89 -fPIC +# we rely on , which was introduced in C99 +CFLAGS += -Wall -Werror -std=c99 -fPIC CXXFLAGS += -Wall -Werror -std=c++11 -fPIC LDFLAGS += -Wall -Werror diff --git a/src/libs.c b/src/libs.c new file mode 100644 index 0000000..4304354 --- /dev/null +++ b/src/libs.c @@ -0,0 +1,25 @@ +/* Copyright 2015-6 OpenMarket Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "crypto-algorithms/sha256.c" +#include "crypto-algorithms/aes.c" +#include "curve25519-donna/curve25519-donna.c" +#define select ed25519_select +#include "ed25519/src/fe.c" +#include "ed25519/src/sc.c" +#include "ed25519/src/ge.c" +#include "ed25519/src/sha512.c" +#include "ed25519/src/verify.c" +#include "ed25519/src/sign.c" +#include "ed25519_additions.c" diff --git a/src/libs.cpp b/src/libs.cpp deleted file mode 100644 index 6757574..0000000 --- a/src/libs.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2015 OpenMarket Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -extern "C" { -#include "crypto-algorithms/sha256.c" -#include "crypto-algorithms/aes.c" -#include "curve25519-donna/curve25519-donna.c" -#define select ed25519_select -#include "ed25519/src/fe.c" -#include "ed25519/src/sc.c" -#include "ed25519/src/ge.c" -#include "ed25519/src/sha512.c" -#include "ed25519/src/verify.c" -#include "ed25519/src/sign.c" -#include "ed25519_additions.c" -} -- cgit v1.2.3 From a49d7284f3e1bee5a95eafeab9a816a2fa7112dd Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 24 May 2016 14:45:32 +0100 Subject: add a script for jenkins to run --- jenkins.sh | 9 +++++++++ python/test_olm.sh | 2 ++ 2 files changed, 11 insertions(+) create mode 100755 jenkins.sh diff --git a/jenkins.sh b/jenkins.sh new file mode 100755 index 0000000..c1efcb9 --- /dev/null +++ b/jenkins.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +set -e + +make clean +make lib +make test + +./python/test_olm.sh diff --git a/python/test_olm.sh b/python/test_olm.sh index b575cbf..9c72556 100755 --- a/python/test_olm.sh +++ b/python/test_olm.sh @@ -1,5 +1,7 @@ #! /bin/bash +cd `dirname $0` + OLM="python -m olm" ALICE_ACCOUNT=alice.account -- cgit v1.2.3 From 8d55954ce13b9f93cc220bcbaab56fb236d16c9c Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 24 May 2016 16:50:26 +0100 Subject: Avoid use of jq in test_olm I want to use test_olm.sh on jenkins, which lacks jq. Hence, add support to olm.main to get id and one-time keys individually. --- python/olm/__main__.py | 36 ++++++++++++++++++++++++++++++++++++ python/test_olm.sh | 4 ++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/python/olm/__main__.py b/python/olm/__main__.py index d2b0d38..35ccd01 100755 --- a/python/olm/__main__.py +++ b/python/olm/__main__.py @@ -1,5 +1,7 @@ #! /usr/bin/env python +from __future__ import print_function + import argparse import json import os @@ -8,6 +10,7 @@ import yaml from . import * + if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("--key", help="Account encryption key", default="") @@ -51,6 +54,39 @@ if __name__ == '__main__': keys.set_defaults(func=do_keys) + def do_id_key(args): + account = Account() + with open(args.account_file, "rb") as f: + account.unpickle(args.key, f.read()) + print(account.identity_keys()['curve25519']) + + id_key = commands.add_parser("identity_key", help="Get the identity key for an account") + id_key.add_argument("account_file", help="Local account file") + id_key.set_defaults(func=do_id_key) + + def do_one_time_key(args): + account = Account() + with open(args.account_file, "rb") as f: + account.unpickle(args.key, f.read()) + keys = account.one_time_keys()['curve25519'].values() + key_num = args.key_num + if key_num < 1 or key_num > len(keys): + print( + "Invalid key number %i: %i keys available" % + (key_num, len(keys)), + file=sys.stderr + ) + sys.exit(1) + print (keys[key_num-1]) + + one_time_key = commands.add_parser("one_time_key", + help="Get a one-time key for the account") + one_time_key.add_argument("account_file", help="Local account file") + one_time_key.add_argument("--key-num", "-n", type=int, default=1, + help="Index of key to retrieve (default: 1)") + one_time_key.set_defaults(func=do_one_time_key) + + sign = commands.add_parser("sign", help="Sign a message") sign.add_argument("account_file", help="Local account file") sign.add_argument("message_file", help="Message to sign") diff --git a/python/test_olm.sh b/python/test_olm.sh index 9c72556..916322e 100755 --- a/python/test_olm.sh +++ b/python/test_olm.sh @@ -16,8 +16,8 @@ $OLM create_account $ALICE_ACCOUNT $OLM create_account $BOB_ACCOUNT $OLM generate_keys $BOB_ACCOUNT 1 -BOB_IDENTITY_KEY="$($OLM keys --json $BOB_ACCOUNT | jq -r .account_keys.curve25519)" -BOB_ONE_TIME_KEY="$($OLM keys --json $BOB_ACCOUNT | jq -r '.one_time_keys.curve25519|to_entries[0].value')" +BOB_IDENTITY_KEY="$($OLM identity_key $BOB_ACCOUNT)" +BOB_ONE_TIME_KEY="$($OLM one_time_key $BOB_ACCOUNT)" $OLM outbound $ALICE_ACCOUNT $ALICE_SESSION "$BOB_IDENTITY_KEY" "$BOB_ONE_TIME_KEY" -- cgit v1.2.3