Skip to content

Commit 8a2e892

Browse files
authored
feat: use local open ssl(3.5.1) for android (#114)
1 parent 114798d commit 8a2e892

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+45939
-85
lines changed

android/CMakeLists.txt

Lines changed: 82 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -6,99 +6,101 @@ set(CMAKE_VERBOSE_MAKEFILE ON)
66
set(CMAKE_CXX_STANDARD 17)
77
set(BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
88

9-
if(${REACT_NATIVE_MINOR_VERSION} GREATER_EQUAL 71)
10-
# Consume shared libraries and headers from prefabs
11-
find_package(ReactAndroid REQUIRED CONFIG)
9+
set(CPP_DIR ${CMAKE_SOURCE_DIR}/androidcpp)
1210

13-
include_directories(
14-
${PACKAGE_NAME}
15-
"./androidcpp"
16-
"../cpp"
17-
)
11+
if(${ANDROID_ABI} STREQUAL "arm64-v8a")
12+
set(LIB_ARCH "arm64-v8a")
13+
elseif(${ANDROID_ABI} STREQUAL "armeabi-v7a")
14+
set(LIB_ARCH "armeabi-v7a")
15+
elseif(${ANDROID_ABI} STREQUAL "x86")
16+
set(LIB_ARCH "x86")
17+
elseif(${ANDROID_ABI} STREQUAL "x86_64")
18+
set(LIB_ARCH "x86_64")
19+
else()
20+
set(LIB_ARCH "arm64-v8a") # Default fallback
21+
endif()
1822

19-
file(GLOB LIBRN_DIR "${BUILD_DIR}/react-native-0*/jni/${ANDROID_ABI}")
20-
message(STATUS "LIBRN_DIR: ${LIBRN_DIR}")
23+
set(OPENSSL_LIB_DIR ${CPP_DIR}/libs/${LIB_ARCH})
24+
set(OPENSSL_INCLUDE_DIR ${CPP_DIR}/include)
2125

22-
add_library(
23-
${PACKAGE_NAME}
24-
SHARED
25-
./androidcpp/mediator.cpp
26-
./cpp-adapter.cpp
27-
../cpp/crypto.cpp
28-
../cpp/decryptor.cpp
29-
)
3026

31-
find_library(
32-
LOG_LIB
33-
log
34-
)
27+
add_library(openssl_crypto STATIC IMPORTED)
28+
set_target_properties(openssl_crypto PROPERTIES
29+
IMPORTED_LOCATION ${OPENSSL_LIB_DIR}/libcrypto.a
30+
)
3531

36-
find_library(
37-
REACT_NATIVE_JNI_LIB
38-
reactnativejni
39-
PATHS ${LIBRN_DIR}
40-
NO_CMAKE_FIND_ROOT_PATH
41-
)
32+
find_package(ReactAndroid REQUIRED CONFIG)
4233

43-
set_target_properties(
44-
${PACKAGE_NAME} PROPERTIES
45-
CXX_STANDARD 17
46-
CXX_EXTENSIONS OFF
47-
POSITION_INDEPENDENT_CODE ON
48-
)
34+
include_directories(
35+
${PACKAGE_NAME}
36+
"./androidcpp"
37+
"../cpp"
38+
${OPENSSL_INCLUDE_DIR}
39+
)
4940

50-
find_package(openssl REQUIRED CONFIG)
41+
file(GLOB LIBRN_DIR "${BUILD_DIR}/react-native-0*/jni/${ANDROID_ABI}")
42+
message(STATUS "LIBRN_DIR: ${LIBRN_DIR}")
5143

52-
target_link_libraries(
53-
${PACKAGE_NAME}
54-
${LOG_LIB}
55-
ReactAndroid::jsi
56-
android
57-
openssl::crypto
58-
)
59-
if(${REACT_NATIVE_MINOR_VERSION} GREATER_EQUAL 76)
60-
target_link_libraries(
61-
${PACKAGE_NAME}
62-
ReactAndroid::reactnative
63-
)
64-
else()
65-
target_link_libraries(
66-
${PACKAGE_NAME}
67-
ReactAndroid::reactnativejni
68-
ReactAndroid::react_nativemodule_core
69-
)
70-
endif()
71-
else()
72-
add_library(
73-
${PACKAGE_NAME}
74-
SHARED
75-
../../react-native/ReactCommon/jsi/jsi/jsi.cpp
76-
./androidcpp/mediator.cpp
77-
./cpp-adapter.cpp
78-
../cpp/crypto.cpp
79-
../cpp/decryptor.cpp
80-
)
44+
add_library(
45+
${PACKAGE_NAME}
46+
SHARED
47+
./androidcpp/mediator.cpp
48+
./cpp-adapter.cpp
49+
../cpp/crypto.cpp
50+
../cpp/decryptor.cpp
51+
)
8152

82-
include_directories(
83-
../../react-native/React
84-
../../react-native/React/Base
85-
../../react-native/ReactCommon/jsi
86-
./cpp
87-
../cpp
88-
)
53+
find_library(
54+
LOG_LIB
55+
log
56+
)
8957

90-
set_target_properties(
91-
${PACKAGE_NAME} PROPERTIES
92-
CXX_STANDARD 17
93-
CXX_EXTENSIONS OFF
94-
POSITION_INDEPENDENT_CODE ON
95-
)
58+
find_library(
59+
REACT_NATIVE_JNI_LIB
60+
reactnativejni
61+
PATHS ${LIBRN_DIR}
62+
NO_CMAKE_FIND_ROOT_PATH
63+
)
64+
65+
set_target_properties(
66+
${PACKAGE_NAME} PROPERTIES
67+
CXX_STANDARD 17
68+
CXX_EXTENSIONS OFF
69+
POSITION_INDEPENDENT_CODE ON
70+
)
71+
72+
# Include directories cho target
73+
target_include_directories(${PACKAGE_NAME} PRIVATE
74+
${OPENSSL_INCLUDE_DIR}
75+
${OPENSSL_INCLUDE_DIR}/openssl
76+
${CPP_DIR}
77+
./androidcpp
78+
../cpp
79+
)
9680

97-
find_package(openssl REQUIRED CONFIG)
81+
target_link_libraries(
82+
${PACKAGE_NAME}
83+
${LOG_LIB}
84+
ReactAndroid::jsi
85+
android
86+
openssl_crypto
87+
z
88+
dl
89+
)
9890

91+
if(${REACT_NATIVE_MINOR_VERSION} GREATER_EQUAL 76)
9992
target_link_libraries(
10093
${PACKAGE_NAME}
101-
android
102-
openssl::crypto
94+
ReactAndroid::reactnative
95+
)
96+
else()
97+
target_link_libraries(
98+
${PACKAGE_NAME}
99+
ReactAndroid::reactnativejni
100+
ReactAndroid::react_nativemodule_core
103101
)
104102
endif()
103+
104+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-z,max-page-size=16384")
105+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,max-page-size=16384")
106+
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. You can obtain a copy
6+
* in the file LICENSE in the source distribution or at
7+
* https://www.openssl.org/source/license.html
8+
*/
9+
10+
#ifndef OPENSSL_AES_H
11+
# define OPENSSL_AES_H
12+
# pragma once
13+
14+
# include <openssl/macros.h>
15+
# ifndef OPENSSL_NO_DEPRECATED_3_0
16+
# define HEADER_AES_H
17+
# endif
18+
19+
# include <openssl/opensslconf.h>
20+
21+
# include <stddef.h>
22+
# ifdef __cplusplus
23+
extern "C" {
24+
# endif
25+
26+
# define AES_BLOCK_SIZE 16
27+
28+
# ifndef OPENSSL_NO_DEPRECATED_3_0
29+
30+
# define AES_ENCRYPT 1
31+
# define AES_DECRYPT 0
32+
33+
# define AES_MAXNR 14
34+
35+
36+
/* This should be a hidden type, but EVP requires that the size be known */
37+
struct aes_key_st {
38+
# ifdef AES_LONG
39+
unsigned long rd_key[4 * (AES_MAXNR + 1)];
40+
# else
41+
unsigned int rd_key[4 * (AES_MAXNR + 1)];
42+
# endif
43+
int rounds;
44+
};
45+
typedef struct aes_key_st AES_KEY;
46+
47+
# endif
48+
# ifndef OPENSSL_NO_DEPRECATED_3_0
49+
OSSL_DEPRECATEDIN_3_0 const char *AES_options(void);
50+
OSSL_DEPRECATEDIN_3_0
51+
int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
52+
AES_KEY *key);
53+
OSSL_DEPRECATEDIN_3_0
54+
int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
55+
AES_KEY *key);
56+
OSSL_DEPRECATEDIN_3_0
57+
void AES_encrypt(const unsigned char *in, unsigned char *out,
58+
const AES_KEY *key);
59+
OSSL_DEPRECATEDIN_3_0
60+
void AES_decrypt(const unsigned char *in, unsigned char *out,
61+
const AES_KEY *key);
62+
OSSL_DEPRECATEDIN_3_0
63+
void AES_ecb_encrypt(const unsigned char *in, unsigned char *out,
64+
const AES_KEY *key, const int enc);
65+
OSSL_DEPRECATEDIN_3_0
66+
void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
67+
size_t length, const AES_KEY *key,
68+
unsigned char *ivec, const int enc);
69+
OSSL_DEPRECATEDIN_3_0
70+
void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out,
71+
size_t length, const AES_KEY *key,
72+
unsigned char *ivec, int *num, const int enc);
73+
OSSL_DEPRECATEDIN_3_0
74+
void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out,
75+
size_t length, const AES_KEY *key,
76+
unsigned char *ivec, int *num, const int enc);
77+
OSSL_DEPRECATEDIN_3_0
78+
void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out,
79+
size_t length, const AES_KEY *key,
80+
unsigned char *ivec, int *num, const int enc);
81+
OSSL_DEPRECATEDIN_3_0
82+
void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out,
83+
size_t length, const AES_KEY *key,
84+
unsigned char *ivec, int *num);
85+
86+
/* NB: the IV is _two_ blocks long */
87+
OSSL_DEPRECATEDIN_3_0
88+
void AES_ige_encrypt(const unsigned char *in, unsigned char *out,
89+
size_t length, const AES_KEY *key,
90+
unsigned char *ivec, const int enc);
91+
/* NB: the IV is _four_ blocks long */
92+
OSSL_DEPRECATEDIN_3_0
93+
void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out,
94+
size_t length, const AES_KEY *key, const AES_KEY *key2,
95+
const unsigned char *ivec, const int enc);
96+
OSSL_DEPRECATEDIN_3_0
97+
int AES_wrap_key(AES_KEY *key, const unsigned char *iv,
98+
unsigned char *out, const unsigned char *in,
99+
unsigned int inlen);
100+
OSSL_DEPRECATEDIN_3_0
101+
int AES_unwrap_key(AES_KEY *key, const unsigned char *iv,
102+
unsigned char *out, const unsigned char *in,
103+
unsigned int inlen);
104+
# endif
105+
106+
107+
# ifdef __cplusplus
108+
}
109+
# endif
110+
111+
#endif

0 commit comments

Comments
 (0)