├── .gitmodules
├── CMakeLists.txt
├── build_all_abi.sh
├── build_libssh_linux.sh
├── readme.txt
└── ssh-boringssl-compat.c
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "libssh"]
2 | path = libssh
3 | url = https://github.com/CanonicalLtd/libssh.git
4 | [submodule "boringssl"]
5 | path = boringssl
6 | url = https://boringssl.googlesource.com/boringssl
7 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright © 2017 Canonical Ltd.
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU General Public License version 3 as
5 | # published by the Free Software Foundation.
6 | #
7 | # This program is distributed in the hope that it will be useful,
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | # GNU General Public License for more details.
11 | #
12 | # You should have received a copy of the GNU General Public License
13 | # along with this program. If not, see .
14 | #
15 | # Authored by: Alberto Aguirre
16 |
17 | cmake_minimum_required(VERSION 3.10)
18 |
19 | set(WITH_EXAMPLES FALSE)
20 | set(CLIENT_TESTING OFF)
21 | set(SERVER_TESTING OFF)
22 | set(WITH_INTERNAL_DOC OFF)
23 |
24 | # We'll link with the boringssl implementation in grpc
25 | set(OPENSSL_FOUND TRUE)
26 | # Lie about the version so that we can do our own crypto-compat layer
27 | set(OPENSSL_VERSION "1.1.1")
28 |
29 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-implicit-function-declaration -Wno-incompatible-pointer-types -Wno-int-conversion")
30 |
31 | set(OPENSSL_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/boringssl/include)
32 | set(LIBSSH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libssh/include)
33 |
34 | # Needed only because of libssh install target
35 | set(LIB_INSTALL_DIR lib)
36 | set(BIN_INSTALL_DIR bin)
37 |
38 | include_directories(${LIBSSH_INCLUDE_DIR})
39 | include_directories(${OPENSSL_INCLUDE_DIR})
40 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/libssh)
41 |
42 | find_package(Threads)
43 |
44 | # libssh source needs the config.h header to be generated
45 | include(libssh/cmake/Modules/AddCCompilerFlag.cmake)
46 | include(libssh/ConfigureChecks.cmake)
47 | configure_file(libssh/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/libssh/config.h)
48 |
49 | # Must be set after configure checks as crypto has not been built yet
50 | # but will be included in the final libssh shared library
51 |
52 | link_directories(${CMAKE_CURRENT_SOURCE_DIR}/${BUILT_LIBS_DIR})
53 |
54 | set(OPENSSL_CRYPTO_LIBRARY crypto decrepit ssh-boringssl-compat)
55 | set(ZLIB_LIBRARY z)
56 |
57 | message(STATUS "Checking for 'libssh' version")
58 |
59 | # Since the main CMake file is bypassed, we have to search that CMake file to determine the proper
60 | # shared library versions
61 | file(STRINGS libssh/CMakeLists.txt LIBRARY_VERSION REGEX "^set\\(LIBRARY_VERSION")
62 | file(STRINGS libssh/CMakeLists.txt LIBRARY_SOVERSION REGEX "^set\\(LIBRARY_SOVERSION")
63 |
64 | string(REGEX REPLACE "^set\\(LIBRARY_VERSION \"(.*)\"\\)$" "\\1"
65 | LIBRARY_VERSION "${LIBRARY_VERSION}")
66 | if (NOT LIBRARY_VERSION)
67 | message(FATAL_ERROR "unable to find libssh library version")
68 | endif()
69 |
70 | string(REGEX REPLACE "^set\\(LIBRARY_SOVERSION \"(.*)\"\\)$" "\\1"
71 | LIBRARY_SOVERSION "${LIBRARY_SOVERSION}")
72 | if (NOT LIBRARY_SOVERSION)
73 | message(FATAL_ERROR "unable to find libssh library soversion")
74 | endif()
75 |
76 | message(STATUS " Found ${LIBRARY_VERSION}, ${LIBRARY_SOVERSION}")
77 |
78 | # We bypass the main CMake file to avoid various package checks which are satisfied manually
79 | # through the configuration above.
80 | add_subdirectory(libssh/src)
81 |
82 | add_library(ssh-boringssl-compat STATIC
83 | ssh-boringssl-compat.c)
84 |
85 | add_library(libssh INTERFACE)
86 |
87 | target_include_directories(libssh INTERFACE ${LIBSSH_INCLUDE_DIR})
88 |
89 | target_link_libraries(libssh INTERFACE ssh_static)
90 |
--------------------------------------------------------------------------------
/build_all_abi.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 |
5 | ./build_libssh_linux.sh armeabi-v7a
6 | ./build_libssh_linux.sh arm64-v8a
7 | ./build_libssh_linux.sh x86
8 | ./build_libssh_linux.sh x86_64
9 |
--------------------------------------------------------------------------------
/build_libssh_linux.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 |
5 | # config
6 | ANDROID_API="arm64-v8a"
7 | API_LEVEL=21
8 | ANDROID_SDK_PATH="/home/andrey/Android/Sdk"
9 | BUILD_SHARED_LIB=0
10 | ANDROID_NDK_ROOT="${ANDROID_SDK_PATH}/ndk/20.0.5594570"
11 | #
12 |
13 | if [[ "$1" != "" ]]; then
14 | ANDROID_API="$1"
15 | fi
16 |
17 | NDK_TOOLCHAIN_PATH="${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake"
18 | OUTPUT_LIBS_DIR="libs/${ANDROID_API}"
19 |
20 | if [[ "$BUILD_SHARED_LIB" -eq "1" ]]
21 | then
22 | libs_files_extension="so"
23 | build_static_libssh=0
24 | else
25 | libs_files_extension="a"
26 | build_static_libssh=1
27 | fi
28 |
29 | rm boringssl_build_dir_${ANDROID_API} -R || true
30 | mkdir boringssl_build_dir_${ANDROID_API}
31 | cd boringssl_build_dir_${ANDROID_API}
32 |
33 | cmake -DANDROID_ABI=${ANDROID_API} \
34 | -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake \
35 | -DANDROID_NATIVE_API_LEVEL=${API_LEVEL} \
36 | -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIB} \
37 | -GNinja \
38 | ../boringssl
39 |
40 | ninja -j4
41 |
42 | cd ..
43 |
44 | mkdir libs || true
45 |
46 | rm ${OUTPUT_LIBS_DIR} -R || true
47 | mkdir ${OUTPUT_LIBS_DIR}
48 |
49 | cp boringssl_build_dir_${ANDROID_API}/crypto/libcrypto.${libs_files_extension} ${OUTPUT_LIBS_DIR}
50 | cp boringssl_build_dir_${ANDROID_API}/decrepit/libdecrepit.${libs_files_extension} ${OUTPUT_LIBS_DIR}
51 | cp boringssl_build_dir_${ANDROID_API}/ssl/libssl.${libs_files_extension} ${OUTPUT_LIBS_DIR}
52 |
53 | rm libssh_build_dir_${ANDROID_API} -R || true
54 | mkdir libssh_build_dir_${ANDROID_API}
55 | cd libssh_build_dir_${ANDROID_API}
56 |
57 | cmake \
58 | -DCMAKE_INSTALL_PREFIX=/opt/libssh-android \
59 | -DWITH_INTERNAL_DOC=OFF \
60 | -DWITH_GSSAPI=OFF \
61 | -DWITH_NACL=OFF \
62 | -DWITH_EXAMPLES=OFF \
63 | -DCMAKE_BUILD_TYPE=Release \
64 | -DCMAKE_TOOLCHAIN_FILE=${NDK_TOOLCHAIN_PATH} \
65 | -DANDROID_NDK=${ANDROID_NDK_ROOT} \
66 | -DANDROID_NATIVE_API_LEVEL=android-${API_LEVEL} \
67 | -DANDROID_ABI=${ANDROID_API} \
68 | -DBUILD_STATIC_LIB=${build_static_libssh} \
69 | -DBUILT_LIBS_DIR=${OUTPUT_LIBS_DIR} \
70 | -DWITH_ZLIB=1 \
71 | -DWITH_SERVER=1 \
72 | -DWITH_SFTP=1 \
73 | ..
74 |
75 | cmake --build .
76 |
77 | cd ..
78 |
79 | cp libssh_build_dir_${ANDROID_API}/libssh-boringssl-compat.a ${OUTPUT_LIBS_DIR}
80 | cp libssh_build_dir_${ANDROID_API}/libssh/src/libssh.${libs_files_extension} ${OUTPUT_LIBS_DIR}
81 |
--------------------------------------------------------------------------------
/readme.txt:
--------------------------------------------------------------------------------
1 | To build the libs:
2 |
3 | #1: Set the correct paths and adjust the config if needed in build_libssh_linux.sh
4 | ANDROID_API="arm64-v8a"
5 | API_LEVEL=21
6 | ANDROID_SDK_PATH="/home/andrey/Android/Sdk"
7 | BUILD_SHARED_LIB=1
8 |
9 | #2: Make sure that boringssl and libssh sources are downloaded, which could be done, for example, by clonning with --recurse-submodules flag:
10 | i.e.
11 | git clone --recurse-submodules https://github.com/egorovandreyrm/libssh_android_build_scripts.git libssh_android_build_scripts
12 |
13 | As soon as compiling is done, libs can be found in the libs directory.
14 |
15 | Linking libssh/boringssl libs can be done by the following way if cmake is used in the project.
16 |
17 | target_link_libraries(yourproject
18 | ${PROJECT_SOURCE_DIR}/ext_libs/${ANDROID_ABI}/libssh.a
19 | ${PROJECT_SOURCE_DIR}/ext_libs/${ANDROID_ABI}/libssl.a
20 | ${PROJECT_SOURCE_DIR}/ext_libs/${ANDROID_ABI}/libcrypto.a
21 | ${PROJECT_SOURCE_DIR}/ext_libs/${ANDROID_ABI}/libdecrepit.a
22 | ${PROJECT_SOURCE_DIR}/ext_libs/${ANDROID_ABI}/libssh-boringssl-compat.a
23 | ${z-lib})
24 |
25 | to build all abi, use build_all_abi.sh
26 |
--------------------------------------------------------------------------------
/ssh-boringssl-compat.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3 | *
4 | * Licensed under the OpenSSL license (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 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | void DSA_SIG_get0(const DSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps)
18 | {
19 | if (pr != NULL)
20 | *pr = sig->r;
21 | if (ps != NULL)
22 | *ps = sig->s;
23 | }
24 |
25 | int DSA_SIG_set0(DSA_SIG *sig, BIGNUM *r, BIGNUM *s)
26 | {
27 | if (r == NULL || s == NULL)
28 | return 0;
29 | BN_clear_free(sig->r);
30 | BN_clear_free(sig->s);
31 | sig->r = r;
32 | sig->s = s;
33 | return 1;
34 | }
35 |
36 | void* EVP_bf_cbc()
37 | {
38 | return NULL;
39 | }
40 |
--------------------------------------------------------------------------------