diff --git a/CMakeLists.txt b/CMakeLists.txt
index 22ab3cc..00bf90d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -38,9 +38,15 @@ set(CROSS OFF CACHE BOOL "Cross-compiling?")
 set(CROSS_TARGET OFF CACHE STRING "Cross-compilation target")
 set(SYSTEM_OPENSSL OFF CACHE STRING "Use system-provided openssl libraries (instead of prebuilts or building)")
 
+option(LOCAL_BUILD "Build in the intranet" OFF)
+set(LOCAL_OPENSSL OFF CACHE STRING "The local openssl resource dir")
 # allow including our modules
 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
 
+if(NOT OPENSSL_BUILD_VERSION)
+    set(OPENSSL_BUILD_VERSION "1.1.1t")
+endif()
+
 # mimic system ssl and crypto targets
 add_library(ssl INTERFACE)
 add_library(crypto INTERFACE)
@@ -55,7 +61,7 @@ if (SYSTEM_OPENSSL)
     add_custom_target(openssl)
 else()
     # build our own or use prebuilts
-    
+
     # set up fake targets
     add_library(ssl_lib STATIC IMPORTED GLOBAL)
     add_library(crypto_lib STATIC IMPORTED GLOBAL)
@@ -70,16 +76,16 @@ else()
         set(OPENSSL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/openssl-prefix/src/openssl)
     endif()
 
-    set(OPENSSL_LIBSSL_PATH ${OPENSSL_PREFIX}/usr/local/lib/libssl.a)
-    set(OPENSSL_LIBCRYPTO_PATH ${OPENSSL_PREFIX}/usr/local/lib/libcrypto.a)
-    
+    set(OPENSSL_LIBSSL_PATH ${OPENSSL_PREFIX}/usr/local/lib/libssl.so)
+    set(OPENSSL_LIBCRYPTO_PATH ${OPENSSL_PREFIX}/usr/local/lib/libcrypto.so)
+
     # set up openssl target
     if (BUILD_OPENSSL)
         include(BuildOpenSSL)
     else()
         include(PrebuiltOpenSSL)
     endif()
-    
+
     # set import locations
     set_target_properties(ssl_lib PROPERTIES IMPORTED_LOCATION ${OPENSSL_LIBSSL_PATH})
     set_target_properties(crypto_lib PROPERTIES IMPORTED_LOCATION ${OPENSSL_LIBCRYPTO_PATH})
@@ -91,4 +97,11 @@ else()
     # add fake targets to common target
     add_dependencies(ssl_lib openssl)
     add_dependencies(crypto_lib openssl)
+
+    install(FILES
+        ${OPENSSL_LIBCRYPTO_PATH}.1.1
+        ${OPENSSL_LIBCRYPTO_PATH}
+        ${OPENSSL_LIBSSL_PATH}.1.1
+        ${OPENSSL_LIBSSL_PATH}
+        DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
 endif()
diff --git a/cmake/BuildOpenSSL.cmake b/cmake/BuildOpenSSL.cmake
index e31f4bb..58728eb 100644
--- a/cmake/BuildOpenSSL.cmake
+++ b/cmake/BuildOpenSSL.cmake
@@ -29,7 +29,7 @@ include(ExternalProject)
 
 # find packages
 find_package(Git REQUIRED)
-find_package(PythonInterp 3 REQUIRED)
+find_package(PythonInterp 2 REQUIRED)
 
 # # used to apply various patches to OpenSSL
 find_program(PATCH_PROGRAM patch)
@@ -48,7 +48,7 @@ endif()
 
 # if already built, do not build again
 if ((EXISTS ${OPENSSL_LIBSSL_PATH}) AND (EXISTS ${OPENSSL_LIBCRYPTO_PATH}))
-    message(WARNING "Not building OpenSSL again. Remove ${OPENSSL_LIBSSL_PATH} and ${OPENSSL_LIBCRYPTO_PATH} for rebuild")
+    message(WARNING "Exist ${OPENSSL_LIBSSL_PATH} and ${OPENSSL_LIBCRYPTO_PATH}, Not building OpenSSL again.")
 else()
     if (NOT OPENSSL_BUILD_VERSION)
         message(FATAL_ERROR "You must specify OPENSSL_BUILD_VERSION!")
@@ -56,23 +56,23 @@ else()
 
     if (WIN32 AND NOT CROSS)
         # yep, windows needs special treatment, but neither cygwin nor msys, since they provide an UNIX-like environment
-        
+
         if (MINGW)
             set(OS "WIN32")
             message(WARNING "Building on windows is experimental")
-            
+
             find_program(MSYS_BASH "bash.exe" PATHS "C:/Msys/" "C:/MinGW/msys/" PATH_SUFFIXES "/1.0/bin/" "/bin/"
                     DOC "Path to MSYS installation")
             if (NOT MSYS_BASH)
                 message(FATAL_ERROR "Specify MSYS installation path")
             endif(NOT MSYS_BASH)
-            
+
             set(MINGW_MAKE ${CMAKE_MAKE_PROGRAM})
             message(WARNING "Assuming your make program is a sibling of your compiler (resides in same directory)")
         elseif(NOT (CYGWIN OR MSYS))
             message(FATAL_ERROR "Unsupported compiler infrastructure")
         endif(MINGW)
-        
+
         set(MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM})
     elseif(NOT UNIX)
         message(FATAL_ERROR "Unsupported platform")
@@ -113,12 +113,12 @@ else()
     if (OPENSSL_DEBUG_BUILD)
         set(CONFIGURE_OPENSSL_PARAMS "${CONFIGURE_OPENSSL_PARAMS} no-asm -g3 -O0 -fno-omit-frame-pointer -fno-inline-functions")
     endif()
-    
+
     # set install command depending of choice on man page generation
     if (OPENSSL_INSTALL_MAN)
         set(INSTALL_OPENSSL_MAN "install_docs")
     endif()
-    
+
     # disable building tests
     if (NOT OPENSSL_ENABLE_TESTS)
         set(CONFIGURE_OPENSSL_MODULES ${CONFIGURE_OPENSSL_MODULES} no-tests)
@@ -130,19 +130,19 @@ else()
         set(COMMAND_CONFIGURE ./Configure ${CONFIGURE_OPENSSL_PARAMS} --cross-compile-prefix=${CROSS_PREFIX} ${CROSS_TARGET} ${CONFIGURE_OPENSSL_MODULES} --prefix=/usr/local/)
         set(COMMAND_TEST "true")
     elseif(CROSS_ANDROID)
-        
+
         # Android specific configuration options
         set(CONFIGURE_OPENSSL_MODULES ${CONFIGURE_OPENSSL_MODULES} no-hw)
-                
+
         # silence warnings about unused arguments (Clang specific)
         set(CFLAGS "${CMAKE_C_FLAGS} -Qunused-arguments")
         set(CXXFLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments")
-    
+
         # required environment configuration is already set (by e.g. ndk) so no need to fiddle around with all the OpenSSL options ...
         if (NOT ANDROID)
             message(FATAL_ERROR "Use NDK cmake toolchain or cmake android autoconfig")
         endif()
-        
+
         if (ARMEABI_V7A)
             set(OPENSSL_PLATFORM "arm")
             set(CONFIGURE_OPENSSL_PARAMS ${CONFIGURE_OPENSSL_PARAMS} "-march=armv7-a")
@@ -153,42 +153,64 @@ else()
                 set(OPENSSL_PLATFORM ${CMAKE_ANDROID_ARCH_ABI})
             endif()
         endif()
-                
+
         # ... but we have to convert all the CMake options to environment variables!
         set(PATH "${ANDROID_TOOLCHAIN_ROOT}/bin/:${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_NAME}/bin/")
         set(LDFLAGS ${CMAKE_MODULE_LINKER_FLAGS})
-        
+
         set(COMMAND_CONFIGURE ./Configure android-${OPENSSL_PLATFORM} ${CONFIGURE_OPENSSL_PARAMS} ${CONFIGURE_OPENSSL_MODULES})
         set(COMMAND_TEST "true")
     else()                   # detect host system automatically
         set(COMMAND_CONFIGURE ./config ${CONFIGURE_OPENSSL_PARAMS} ${CONFIGURE_OPENSSL_MODULES})
-        
+
         if (NOT COMMAND_TEST)
             set(COMMAND_TEST ${BUILD_ENV_TOOL} <SOURCE_DIR> ${MAKE_PROGRAM} test)
         endif()
     endif()
-    
+
     # add openssl target
-    ExternalProject_Add(openssl
-        URL https://mirror.viaduck.org/openssl/openssl-${OPENSSL_BUILD_VERSION}.tar.gz
-        ${OPENSSL_CHECK_HASH}
-        UPDATE_COMMAND ""
+    if(LOCAL_BUILD)
+        ExternalProject_Add(openssl
+            SOURCE_DIR ${LOCAL_OPENSSL}
+            UPDATE_COMMAND ${GIT_EXECUTABLE} clean -dfx -e buildenv.txt && ${GIT_EXECUTABLE} stash && ${GIT_EXECUTABLE} checkout OpenSSL_1_1_1t
 
-        CONFIGURE_COMMAND ${BUILD_ENV_TOOL} <SOURCE_DIR> ${COMMAND_CONFIGURE}
-        PATCH_COMMAND ${PATCH_PROGRAM} -p1 --forward -r - < ${CMAKE_CURRENT_SOURCE_DIR}/patches/0001-Fix-failing-cms-test-when-no-des-is-used.patch || echo
+            CONFIGURE_COMMAND ${BUILD_ENV_TOOL} <SOURCE_DIR> ${COMMAND_CONFIGURE}
+            PATCH_COMMAND ${PATCH_PROGRAM} -p1 --forward -r - < ${CMAKE_CURRENT_SOURCE_DIR}/patches/0001-Fix-failing-cms-test-when-no-des-is-used.patch || echo
 
-        BUILD_COMMAND ${BUILD_ENV_TOOL} <SOURCE_DIR> ${MAKE_PROGRAM} -j ${NUM_JOBS}
-        BUILD_BYPRODUCTS ${OPENSSL_LIBSSL_PATH} ${OPENSSL_LIBCRYPTO_PATH}
+            BUILD_COMMAND ${BUILD_ENV_TOOL} <SOURCE_DIR> ${MAKE_PROGRAM} -j ${NUM_JOBS}
+            BUILD_BYPRODUCTS ${OPENSSL_LIBSSL_PATH} ${OPENSSL_LIBCRYPTO_PATH}
 
-        TEST_BEFORE_INSTALL 1
-        TEST_COMMAND ${COMMAND_TEST}
+            TEST_BEFORE_INSTALL 0
+            TEST_COMMAND ${COMMAND_TEST}
 
-        INSTALL_COMMAND ${BUILD_ENV_TOOL} <SOURCE_DIR> ${PERL_PATH_FIX_INSTALL}
-        COMMAND ${BUILD_ENV_TOOL} <SOURCE_DIR> ${MAKE_PROGRAM} DESTDIR=${CMAKE_CURRENT_BINARY_DIR} install_sw ${INSTALL_OPENSSL_MAN}
-        COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} ${CMAKE_BINARY_DIR}                    # force CMake-reload
+            INSTALL_COMMAND ${BUILD_ENV_TOOL} <SOURCE_DIR> ${PERL_PATH_FIX_INSTALL}
+            COMMAND ${BUILD_ENV_TOOL} <SOURCE_DIR> ${MAKE_PROGRAM} DESTDIR=${CMAKE_CURRENT_BINARY_DIR} install_sw ${INSTALL_OPENSSL_MAN}
+            COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} ${CMAKE_BINARY_DIR}                    # force CMake-reload
 
-        LOG_INSTALL 1
-    )
+            LOG_INSTALL 1
+        )
+    else()
+        ExternalProject_Add(openssl
+            URL https://mirror.viaduck.org/openssl/openssl-${OPENSSL_BUILD_VERSION}.tar.gz
+            ${OPENSSL_CHECK_HASH}
+            UPDATE_COMMAND ""
+
+            CONFIGURE_COMMAND ${BUILD_ENV_TOOL} <SOURCE_DIR> ${COMMAND_CONFIGURE}
+            PATCH_COMMAND ${PATCH_PROGRAM} -p1 --forward -r - < ${CMAKE_CURRENT_SOURCE_DIR}/patches/0001-Fix-failing-cms-test-when-no-des-is-used.patch || echo
+
+            BUILD_COMMAND ${BUILD_ENV_TOOL} <SOURCE_DIR> ${MAKE_PROGRAM} -j ${NUM_JOBS}
+            BUILD_BYPRODUCTS ${OPENSSL_LIBSSL_PATH} ${OPENSSL_LIBCRYPTO_PATH}
+
+            TEST_BEFORE_INSTALL 1
+            TEST_COMMAND ${COMMAND_TEST}
+
+            INSTALL_COMMAND ${BUILD_ENV_TOOL} <SOURCE_DIR> ${PERL_PATH_FIX_INSTALL}
+            COMMAND ${BUILD_ENV_TOOL} <SOURCE_DIR> ${MAKE_PROGRAM} DESTDIR=${CMAKE_CURRENT_BINARY_DIR} install_sw ${INSTALL_OPENSSL_MAN}
+            COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} ${CMAKE_BINARY_DIR}                    # force CMake-reload
+
+            LOG_INSTALL 1
+        )
+    endif()
 
     # set git config values to openssl requirements (no impact on linux though)
     ExternalProject_Add_Step(openssl setGitConfig
@@ -230,12 +252,17 @@ else()
     # write environment to file, is picked up by python script
     get_cmake_property(_variableNames VARIABLES)
     foreach (_variableName ${_variableNames})
-        if (NOT _variableName MATCHES "lines")
+        if ((NOT _variableName MATCHES "lines") OR (NOT _variableName MATCHES "CMAKE_CXX_COMPILER_ID_PLATFORM_CONTENT"))
             set(OUT_FILE "${OUT_FILE}${_variableName}=\"${${_variableName}}\"\n")
         endif()
     endforeach()
-    file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/buildenv.txt ${OUT_FILE})
-
+    if (NOT LOCAL_OPENSSL)
+        # Write in openssl-cmake-build/, because the file will be overwritten when the download is performed later
+        file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/buildenv.txt ${OUT_FILE})
+    else()
+        # Write in specified dir LOCAL_OPENSSL
+        file(WRITE ${LOCAL_OPENSSL}/buildenv.txt ${OUT_FILE})
+    endif()
     set_target_properties(ssl_lib PROPERTIES IMPORTED_LOCATION ${OPENSSL_LIBSSL_PATH})
     set_target_properties(crypto_lib PROPERTIES IMPORTED_LOCATION ${OPENSSL_LIBCRYPTO_PATH})
-endif()
+endif()
\ No newline at end of file
diff --git a/scripts/building_env.py b/scripts/building_env.py
index aab2f42..4a7c932 100644
--- a/scripts/building_env.py
+++ b/scripts/building_env.py
@@ -28,6 +28,7 @@
 from subprocess import PIPE, Popen
 from sys import argv, exit
 import os, re
+import os.path
 
 env = os.environ
 l = []
@@ -57,23 +58,24 @@ l.extend(argv[offset+1:])                             # routed commands
 
 l[0] = '"'+l[0]+'"'
 
-# ensure target dir exists for mingw cross
-target_dir = binary_openssl_dir_source+"/../../../usr/local/bin"
-if not os.path.exists(target_dir):
-    os.makedirs(target_dir)
-
 # read environment from file if cross-compiling
 if os_s == "LINUX_CROSS_ANDROID":
     expr = re.compile('^(.*?)="(.*?)"', re.MULTILINE | re.DOTALL)
-    f = open(binary_openssl_dir_source+"/../../../buildenv.txt", "r")
+    if not os.path.exists(binary_openssl_dir_source+"buildenv.txt"):
+        f = open(binary_openssl_dir_source+"../../../buildenv.txt", "r")
+    else:
+        f = open(binary_openssl_dir_source+"buildenv.txt", "r")
     content = f.read()
     f.close()
 
     for k, v in expr.findall(content):
-        if k != "PATH":
-            env[k] = v.replace('"', '')
-        else:
-            env[k] = v.replace('"', '')+":"+env[k]
+        try:
+            if k != "PATH":
+                env[k] = v.replace('"', '')
+            else:
+                env[k] = v.replace('"', '')+":"+env[k]
+        except:
+            pass
 
 proc = None
 if os_s == "WIN32":
