curl-7.70.0 --with-ssl

openssl的官网

https://www.openssl.org/source/

[ Old Releases ] - /source/old/index.html

curl的官网

https://curl.haxx.se/download.html

curl downloads

如果想要调试源码 

./configure --disable-shared --without-zlib --enable-static --enable-ipv6 --host="${HOST}" --prefix=${PREFIX} ${Openssl_With_SSL} && make && make install

添加--enable-debug --enable-maintainer-mode,改为

./configure --disable-shared --without-zlib --enable-static --enable-ipv6 --host="${HOST}" --prefix=${PREFIX} ${Openssl_With_SSL} --enable-debug --enable-maintainer-mode && make && make install

build.sh

  

#!/usr/bin/env bash
#./build.sh 1 生成 openssl
#./build.sh 2 生成 curl
#./build.sh 3 同时生成 curl openssl
Build_Type=$1
parentDir=$(pwd)
set -x
if [[ $Build_Type == "1" || $Build_Type == "3" ]];then
    OpensslName="openssl-1.1.0g"
  if [ -f ${OpensslName}.tar.gz ]; then
    echo ${OpensslName}.tar.gz
    if [ -d $OpensslName ]; then
    rm -rf $OpensslName
  fi
  else
    #下载
    curl -O https://www.openssl.org/source/${OpensslName}.tar.gz
  fi
  #解压
  tar xf ${OpensslName}.tar.gz


  #变更工作目录
  cd ${OpensslName}
  
  #!/bin/bash
  sed -i '' 's/use if \$\^O ne "VMS", '\''File::Glob'\'' => qw\/glob\/;/use if \$\^O ne "VMS", '\''File::Glob'\'' => qw\/:glob\/;/' $(pwd)/Configure

  sed -i '' 's/use if \$\^O ne "VMS", '\''File::Glob'\'' => qw\/glob\/;/use if \$\^O ne "VMS", '\''File::Glob'\'' => qw\/:glob\/;/' $(pwd)/test/build.info

  make claen
  #编译目录
  Openssl_Build_Dir=$parentDir/build_openssl
  if [ -d $Openssl_Build_Dir ]; then
    rm -rf $Openssl_Build_Dir
  fi

  CROSS_TOP_SIM="`xcode-select --print-path`/Platforms/iPhoneSimulator.platform/Developer"
  CROSS_SDK_SIM="iPhoneSimulator.sdk"

  CROSS_TOP_IOS="`xcode-select --print-path`/Platforms/iPhoneOS.platform/Developer"
  CROSS_SDK_IOS="iPhoneOS.sdk"

  export CROSS_COMPILE=`xcode-select --print-path`/Toolchains/XcodeDefault.xctoolchain/usr/bin/

  function build_for ()
  {
    PLATFORM=$1
    ARCH=$2
    CROSS_TOP_ENV=CROSS_TOP_$3
    CROSS_SDK_ENV=CROSS_SDK_$3

    make clean

    export CROSS_TOP="${!CROSS_TOP_ENV}"
    export CROSS_SDK="${!CROSS_SDK_ENV}"
    ./Configure $PLATFORM "-arch $ARCH -fembed-bitcode" enable-srp no-asm no-shared no-hw no-async --prefix=${Openssl_Build_Dir}/${ARCH} || exit 1
    # problem of concurrent build; make -j8
    make && make install_sw || exit 2
    unset CROSS_TOP
    unset CROSS_SDK
  }

  function pack_for ()
  {
    LIBNAME=$1
    mkdir -p ${Openssl_Build_Dir}/lib/
    ${DEVROOT}/usr/bin/lipo \
    ${Openssl_Build_Dir}/x86_64/lib/lib${LIBNAME}.a \
    ${Openssl_Build_Dir}/arm64/lib/lib${LIBNAME}.a \
    -output ${Openssl_Build_Dir}/lib/lib${LIBNAME}.a -create
  }
  #配置编译架构
  patch Configurations/10-main.conf < $parentDir/patch-conf.patch

  build_for ios64sim-cross x86_64 SIM || exit 2
  build_for ios64-cross arm64 IOS || exit 5

  pack_for ssl || exit 6
  pack_for crypto || exit 7
  #配置架构宏定义
  cp -r ${Openssl_Build_Dir}/arm64/include ${Openssl_Build_Dir}/
  patch -p3 ${Openssl_Build_Dir}/include/openssl/opensslconf.h < $parentDir/patch-include.patch

  #合并的最终库
  Openssl_Product_Dir="$parentDir/openssl-ios"
  if [ -d $Openssl_Product_Dir ]; then
    rm -rf $Openssl_Product_Dir
  fi
  mkdir -p ${Openssl_Product_Dir}
  cp -r ${Openssl_Build_Dir}/include ${Openssl_Build_Dir}/lib ${Openssl_Product_Dir}
  cd ..
fi

if [[ $Build_Type == "2" || $Build_Type == "3" ]];then
  #liburl
  versionCurl="curl-7.70.0"
  if [ -f ${versionCurl}.tar.gz ]; then
    echo ${versionCurl}.tar.gz
    if [ -d $versionCurl ]; then
    rm -rf $versionCurl
  fi
  else
    #下载
    curl -O https://curl.se/download/${versionCurl}.tar.gz
  fi
  #解压
  tar xf ${versionCurl}.tar.gz
  #变更工作目录
  cd ${versionCurl}

  readonly XCODE_DEV="$(xcode-select -p)"
  export DEVROOT="${XCODE_DEV}/Toolchains/XcodeDefault.xctoolchain"

  function build_for_arch() {
    ARCH=$1
    HOST=$2
    SYSROOT=$3
    PREFIX=$4
    IPHONEOS_DEPLOYMENT_TARGET="12.0"
    export PATH="${DEVROOT}/usr/bin/:${PATH}"
    export CFLAGS="-DCURL_BUILD_IOS -arch ${ARCH} -pipe -Os -gdwarf-2 -isysroot ${SYSROOT} -miphoneos-version-min=${IPHONEOS_DEPLOYMENT_TARGET} -fembed-bitcode"
    export LDFLAGS="-arch ${ARCH} -isysroot ${SYSROOT}"
    ./configure --disable-shared --without-zlib --enable-static --enable-ipv6 --host="${HOST}" --prefix=${PREFIX} ${Openssl_With_SSL} && make && make install
  }
  
  Openssl_With_SSL="--without-ssl"
  if [ -d "$Openssl_Product_Dir" ]; then
    export CFLAGS="-I${Openssl_Product_Dir}/include"
    export LDFLAGS="-L${Openssl_Product_Dir}/lib"
    export LD_LIBRARY_PATH="${Openssl_Product_Dir}/lib:$LD_LIBRARY_PATH"
    Openssl_With_SSL="--with-ssl=${Openssl_Product_Dir}"
  fi
  
  #编译目录
  Curl_Build_DIR="$parentDir/build_curl"
  if [ -d $Curl_Build_DIR ]; then
    rm -rf $Curl_Build_DIR
  fi
  mkdir -p ${Curl_Build_DIR}

  build_for_arch x86_64 x86_64-apple-darwin ${XCODE_DEV}/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk ${Curl_Build_DIR}/x86_64 || exit 1
  build_for_arch arm64 arm-apple-darwin ${XCODE_DEV}/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk $Curl_Build_DIR/arm64|| exit 2

  mkdir -p ${Curl_Build_DIR}/lib/
  ${DEVROOT}/usr/bin/lipo \
    -arch x86_64 ${Curl_Build_DIR}/x86_64/lib/libcurl.a \
    -arch arm64 ${Curl_Build_DIR}/arm64/lib/libcurl.a \
    -output ${Curl_Build_DIR}/lib/libcurl.a -create

  cp -r ${Curl_Build_DIR}/arm64/include ${Curl_Build_DIR}/

  #合并的最终库
  Curl_Product_Dir="$parentDir/curl-ios"
  if [ -d $Curl_Product_Dir ]; then
    rm -rf $Curl_Product_Dir
  fi
  mkdir -p ${Curl_Product_Dir}
  cp -r ${Curl_Build_DIR}/include ${Curl_Build_DIR}/lib ${Curl_Product_Dir}

fi


patch-conf.patch

diff --git a/Configurations/10-main.conf b/Configurations/10-main.conf
--- a/Configurations/10-main.conf
+++ b/Configurations/10-main.conf
@@ -1640,6 +1640,13 @@ my %targets = (
         sys_id           => "VXWORKS",
         lflags           => add("-r"),
     },
+    "ios64sim-cross" => {
+        inherit_from     => [ "darwin-common", asm("no_asm") ],
+        cflags           => add("-arch x86_64 -DOPENSSL_NO_ASM -mios-version-min=7.0.0 -isysroot \$(CROSS_TOP)/SDKs/\$(CROSS_SDK) -fno-common"),
+        sys_id           => "iOS",
+        bn_ops           => "SIXTY_FOUR_BIT_LONG RC4_CHAR",
+        perlasm_scheme   => "ios64",
+    },
     "vxworks-simlinux" => {
         inherit_from     => [ "BASE_unix" ],
         CC               => "ccpentium",

patch-include.patch

--- armv7s/include/openssl/opensslconf.h	2017-01-08 02:25:43.000000000 -0800
+++ arm64/include/openssl/opensslconf.h	2017-01-08 03:44:44.000000000 -0800
@@ -158,11 +158,21 @@
  * The following are cipher-specific, but are part of the public API.
  */
 #if !defined(OPENSSL_SYS_UEFI)
-# define BN_LLONG
+# ifdef __LP64__
+#  undef BN_LLONG
+# else
+#  define BN_LLONG
+# endif
 /* Only one for the following should be defined */
-# undef SIXTY_FOUR_BIT_LONG
-# undef SIXTY_FOUR_BIT
-# define THIRTY_TWO_BIT
+# ifdef __LP64__
+#  define SIXTY_FOUR_BIT_LONG
+#  undef SIXTY_FOUR_BIT
+#  undef THIRTY_TWO_BIT
+# else
+#  undef SIXTY_FOUR_BIT_LONG
+#  undef SIXTY_FOUR_BIT
+#  define THIRTY_TWO_BIT
+# endif
 #endif
 
 #define RC4_INT unsigned char

报错 

vtls/openssl.c:2704:9: error: call to undeclared function 'SSL_CTX_set_srp_username'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    if(!SSL_CTX_set_srp_username(backend->ctx, ssl_username)) {
        ^
vtls/openssl.c:2708:9: error: call to undeclared function 'SSL_CTX_set_srp_password'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    if(!SSL_CTX_set_srp_password(backend->ctx, SSL_SET_OPTION(password))) {
        ^
2 errors generated.
make[2]: *** [vtls/libcurl_la-openssl.lo] Error 1
make[1]: *** [all] Error 2
make: *** [all-recursive] Error 1
+ exit 1

加下面代码解决上面报错 

export LD_LIBRARY_PATH="${Openssl_Product_Dir}/lib:$LD_LIBRARY_PATH"

你可能感兴趣的:(ssl,linux,网络协议)