summaryrefslogtreecommitdiff
path: root/main/src/main/java/de/blinkt/openvpn/core/NativeUtils.java
blob: 470ec6d69763c4d664a3202c6b98e59b2f26bad6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * Copyright (c) 2012-2016 Arne Schwabe
 * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
 */

package de.blinkt.openvpn.core;

import android.os.Build;
import de.blinkt.openvpn.BuildConfig;

import java.security.InvalidKeyException;

public class NativeUtils {
    public static native byte[] rsasign(byte[] input, int pkey, boolean pkcs1padding) throws InvalidKeyException;

    public static native String[] getIfconfig() throws IllegalArgumentException;

    static native void jniclose(int fdint);

    public static String getNativeAPI() {
        if (isRoboUnitTest())
            return "ROBO";
        else
            return getJNIAPI();
    }

    private static native String getJNIAPI();

    public static native String getOpenVPN2GitVersion();

    public static native String getOpenVPN3GitVersion();

    static boolean rsspssloaded = false;

    public static byte[] addRssPssPadding(int hashtype, int MSBits, int rsa_size, byte[] from)
    {
        if (!rsspssloaded) {
            rsspssloaded = true;
            System.loadLibrary("rsapss");
        }

        return rsapss(hashtype, MSBits, rsa_size, from);
    }

    private static native byte[] rsapss(int hashtype, int MSBits, int rsa_size, byte[] from);

    public final static int[] openSSLlengths = {
        16, 64, 256, 1024, 1500, 8 * 1024, 16 * 1024
    };

    public static native double[] getOpenSSLSpeed(String algorithm, int testnum);

    static {
        if (!isRoboUnitTest()) {
            System.loadLibrary("ovpnutil");
            if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN)
                System.loadLibrary("jbcrypto");


            if (!BuildConfig.FLAVOR.equals("skeleton")) {
                System.loadLibrary("osslspeedtest");
            }
        }
    }

    public static boolean isRoboUnitTest() {
        return "robolectric".equals(Build.FINGERPRINT); }

}