Commit 2f2a19f2 authored by Hubert Chathi's avatar Hubert Chathi
Browse files

add Android bindings for PK signing

parent 0348f06a
Loading
Loading
Loading
Loading
+62 −1
Original line number Diff line number Diff line
/*
 * Copyright 2018 New Vector Ltd
 * Copyright 2018,2019 New Vector Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@ public class OlmPkTest {

    private static OlmPkEncryption mOlmPkEncryption;
    private static OlmPkDecryption mOlmPkDecryption;
    private static OlmPkSigning mOlmPkSigning;

    @Test
    public void test01EncryptAndDecrypt() {
@@ -137,4 +138,64 @@ public class OlmPkTest {
        mOlmPkDecryption.releaseDecryption();
        assertTrue(mOlmPkDecryption.isReleased());
    }

    @Test
    public void test03Signing() {
        try {
            mOlmPkSigning = new OlmPkSigning();
        } catch (OlmException e) {
            e.printStackTrace();
            assertTrue("OlmPkSigning failed " + e.getMessage(), false);
        }

        assertNotNull(mOlmPkSigning);

        byte[] seed = null;
        try {
            seed = OlmPkSigning.generateSeed();
        } catch (OlmException e) {
            e.printStackTrace();
            assertTrue("generateSeed failed " + e.getMessage(), false);
        }

        assertTrue(seed.length == OlmPkSigning.seedLength());

        String pubkey = null;
        try {
            pubkey = mOlmPkSigning.initWithSeed(seed);
        } catch (OlmException e) {
            e.printStackTrace();
            assertTrue("initWithSeed failed " + e.getMessage(), false);
        }

        String message = "We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness.";

        String signature = null;
        try {
            signature = mOlmPkSigning.sign(message);
        } catch (OlmException e) {
            e.printStackTrace();
            assertTrue("sign failed " + e.getMessage(), false);
        }

        OlmUtility olmUtility = null;
        try {
            olmUtility = new OlmUtility();
        } catch (OlmException e) {
            e.printStackTrace();
            assertTrue("olmUtility failed " + e.getMessage(), false);
        }

        try {
            olmUtility.verifyEd25519Signature(signature, pubkey, message);
        } catch (OlmException e) {
            e.printStackTrace();
            assertTrue("Signature verification failed " + e.getMessage(), false);
        }

        mOlmPkSigning.releaseSigning();
        assertTrue(mOlmPkSigning.isReleased());

        olmUtility.releaseUtility();
    }
}
+6 −1
Original line number Diff line number Diff line
/*
 * Copyright 2017 OpenMarket Ltd
 * Copyright 2017 Vector Creations Ltd
 * Copyright 2017-2019 Vector Creations Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -71,6 +71,11 @@ public class OlmException extends IOException {
    public static final int EXCEPTION_CODE_PK_DECRYPTION_SET_PRIVATE_KEY = 703;
    public static final int EXCEPTION_CODE_PK_DECRYPTION_PRIVATE_KEY = 704;

    public static final int EXCEPTION_CODE_PK_SIGNING_CREATION = 800;
    public static final int EXCEPTION_CODE_PK_SIGNING_GENERATE_SEED = 801;
    public static final int EXCEPTION_CODE_PK_SIGNING_INIT_WITH_SEED = 802;
    public static final int EXCEPTION_CODE_PK_SIGNING_SIGN = 803;

    // exception human readable messages
    public static final String EXCEPTION_MSG_INVALID_PARAMS_DESERIALIZATION = "invalid de-serialized parameters";

+2 −1
Original line number Diff line number Diff line
/*
 * Copyright 2016 OpenMarket Ltd
 * Copyright 2016 Vector Creations Ltd
 * Copyright 2016,2018,2019 Vector Creations Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -72,6 +72,7 @@ struct OlmOutboundGroupSession* getOutboundGroupSessionInstanceId(JNIEnv* aJniEn
struct OlmUtility* getUtilityInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
struct OlmPkDecryption* getPkDecryptionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
struct OlmPkEncryption* getPkEncryptionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
struct OlmPkSigning* getPkSigningInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);

#ifdef __cplusplus
}
+6 −1
Original line number Diff line number Diff line
/*
 * Copyright 2016 OpenMarket Ltd
 * Copyright 2016 Vector Creations Ltd
 * Copyright 2016,2018,2019 Vector Creations Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -222,3 +222,8 @@ struct OlmPkEncryption* getPkEncryptionInstanceId(JNIEnv* aJniEnv, jobject aJava
{
    return (struct OlmPkEncryption*)getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_PK_ENCRYPTION);
}

struct OlmPkSigning* getPkSigningInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
{
    return (struct OlmPkSigning*)getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_PK_SIGNING);
}
+2 −1
Original line number Diff line number Diff line
/*
 * Copyright 2016 OpenMarket Ltd
 * Copyright 2016 Vector Creations Ltd
 * Copyright 2016,2018,2019 Vector Creations Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -27,4 +27,5 @@ namespace AndroidOlmSdk
    static const char *CLASS_OLM_UTILITY = "org/matrix/olm/OlmUtility";
    static const char *CLASS_OLM_PK_ENCRYPTION = "org/matrix/olm/OlmPkEncryption";
    static const char *CLASS_OLM_PK_DECRYPTION = "org/matrix/olm/OlmPkDecryption";
    static const char *CLASS_OLM_PK_SIGNING = "org/matrix/olm/OlmPkSigning";
}
Loading