You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3265 lines
108 KiB
3265 lines
108 KiB
10 years ago
|
/***************************************************************************
|
||
|
* _ _ ____ _
|
||
|
* Project ___| | | | _ \| |
|
||
|
* / __| | | | |_) | |
|
||
|
* | (__| |_| | _ <| |___
|
||
|
* \___|\___/|_| \_\_____|
|
||
|
*
|
||
7 years ago
|
* Copyright (C) 2012 - 2017, Nick Zitzmann, <nickzman@gmail.com>.
|
||
5 years ago
|
* Copyright (C) 2012 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||
10 years ago
|
*
|
||
|
* This software is licensed as described in the file COPYING, which
|
||
|
* you should have received as part of this distribution. The terms
|
||
8 years ago
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
||
10 years ago
|
*
|
||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||
|
* copies of the Software, and permit persons to whom the Software is
|
||
|
* furnished to do so, under the terms of the COPYING file.
|
||
|
*
|
||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||
|
* KIND, either express or implied.
|
||
|
*
|
||
|
***************************************************************************/
|
||
|
|
||
|
/*
|
||
7 years ago
|
* Source file for all iOS and macOS SecureTransport-specific code for the
|
||
10 years ago
|
* TLS/SSL layer. No code but vtls.c should ever call or use these functions.
|
||
|
*/
|
||
|
|
||
|
#include "curl_setup.h"
|
||
|
|
||
8 years ago
|
#include "urldata.h" /* for the Curl_easy definition */
|
||
10 years ago
|
#include "curl_base64.h"
|
||
|
#include "strtok.h"
|
||
5 years ago
|
#include "multiif.h"
|
||
10 years ago
|
|
||
5 years ago
|
#ifdef USE_SECTRANSP
|
||
10 years ago
|
|
||
7 years ago
|
#ifdef __clang__
|
||
|
#pragma clang diagnostic push
|
||
|
#pragma clang diagnostic ignored "-Wtautological-pointer-compare"
|
||
|
#endif /* __clang__ */
|
||
|
|
||
10 years ago
|
#include <limits.h>
|
||
|
|
||
|
#include <Security/Security.h>
|
||
7 years ago
|
/* For some reason, when building for iOS, the omnibus header above does
|
||
|
* not include SecureTransport.h as of iOS SDK 5.1. */
|
||
10 years ago
|
#include <Security/SecureTransport.h>
|
||
|
#include <CoreFoundation/CoreFoundation.h>
|
||
|
#include <CommonCrypto/CommonDigest.h>
|
||
|
|
||
7 years ago
|
/* The Security framework has changed greatly between iOS and different macOS
|
||
10 years ago
|
versions, and we will try to support as many of them as we can (back to
|
||
|
Leopard and iOS 5) by using macros and weak-linking.
|
||
|
|
||
7 years ago
|
In general, you want to build this using the most recent OS SDK, since some
|
||
|
features require curl to be built against the latest SDK. TLS 1.1 and 1.2
|
||
|
support, for instance, require the macOS 10.8 SDK or later. TLS 1.3
|
||
|
requires the macOS 10.13 or iOS 11 SDK or later. */
|
||
10 years ago
|
#if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
|
||
|
|
||
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050
|
||
5 years ago
|
#error "The Secure Transport back-end requires Leopard or later."
|
||
10 years ago
|
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED < 1050 */
|
||
|
|
||
|
#define CURL_BUILD_IOS 0
|
||
|
#define CURL_BUILD_IOS_7 0
|
||
6 years ago
|
#define CURL_BUILD_IOS_9 0
|
||
7 years ago
|
#define CURL_BUILD_IOS_11 0
|
||
10 years ago
|
#define CURL_BUILD_MAC 1
|
||
|
/* This is the maximum API level we are allowed to use when building: */
|
||
|
#define CURL_BUILD_MAC_10_5 MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
|
||
|
#define CURL_BUILD_MAC_10_6 MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||
|
#define CURL_BUILD_MAC_10_7 MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
||
|
#define CURL_BUILD_MAC_10_8 MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
|
||
|
#define CURL_BUILD_MAC_10_9 MAC_OS_X_VERSION_MAX_ALLOWED >= 1090
|
||
6 years ago
|
#define CURL_BUILD_MAC_10_11 MAC_OS_X_VERSION_MAX_ALLOWED >= 101100
|
||
7 years ago
|
#define CURL_BUILD_MAC_10_13 MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
|
||
10 years ago
|
/* These macros mean "the following code is present to allow runtime backward
|
||
|
compatibility with at least this cat or earlier":
|
||
7 years ago
|
(You set this at build-time using the compiler command line option
|
||
|
"-mmacos-version-min.") */
|
||
10 years ago
|
#define CURL_SUPPORT_MAC_10_5 MAC_OS_X_VERSION_MIN_REQUIRED <= 1050
|
||
|
#define CURL_SUPPORT_MAC_10_6 MAC_OS_X_VERSION_MIN_REQUIRED <= 1060
|
||
|
#define CURL_SUPPORT_MAC_10_7 MAC_OS_X_VERSION_MIN_REQUIRED <= 1070
|
||
|
#define CURL_SUPPORT_MAC_10_8 MAC_OS_X_VERSION_MIN_REQUIRED <= 1080
|
||
|
#define CURL_SUPPORT_MAC_10_9 MAC_OS_X_VERSION_MIN_REQUIRED <= 1090
|
||
|
|
||
|
#elif TARGET_OS_EMBEDDED || TARGET_OS_IPHONE
|
||
|
#define CURL_BUILD_IOS 1
|
||
|
#define CURL_BUILD_IOS_7 __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
|
||
6 years ago
|
#define CURL_BUILD_IOS_9 __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000
|
||
7 years ago
|
#define CURL_BUILD_IOS_11 __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
|
||
10 years ago
|
#define CURL_BUILD_MAC 0
|
||
|
#define CURL_BUILD_MAC_10_5 0
|
||
|
#define CURL_BUILD_MAC_10_6 0
|
||
|
#define CURL_BUILD_MAC_10_7 0
|
||
|
#define CURL_BUILD_MAC_10_8 0
|
||
7 years ago
|
#define CURL_BUILD_MAC_10_9 0
|
||
6 years ago
|
#define CURL_BUILD_MAC_10_11 0
|
||
7 years ago
|
#define CURL_BUILD_MAC_10_13 0
|
||
10 years ago
|
#define CURL_SUPPORT_MAC_10_5 0
|
||
|
#define CURL_SUPPORT_MAC_10_6 0
|
||
|
#define CURL_SUPPORT_MAC_10_7 0
|
||
|
#define CURL_SUPPORT_MAC_10_8 0
|
||
9 years ago
|
#define CURL_SUPPORT_MAC_10_9 0
|
||
10 years ago
|
|
||
|
#else
|
||
5 years ago
|
#error "The Secure Transport back-end requires iOS or macOS."
|
||
10 years ago
|
#endif /* (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) */
|
||
|
|
||
|
#if CURL_BUILD_MAC
|
||
|
#include <sys/sysctl.h>
|
||
|
#endif /* CURL_BUILD_MAC */
|
||
|
|
||
|
#include "urldata.h"
|
||
|
#include "sendf.h"
|
||
|
#include "inet_pton.h"
|
||
|
#include "connect.h"
|
||
|
#include "select.h"
|
||
|
#include "vtls.h"
|
||
5 years ago
|
#include "sectransp.h"
|
||
9 years ago
|
#include "curl_printf.h"
|
||
6 years ago
|
#include "strdup.h"
|
||
10 years ago
|
|
||
|
#include "curl_memory.h"
|
||
|
/* The last #include file should be: */
|
||
|
#include "memdebug.h"
|
||
|
|
||
|
/* From MacTypes.h (which we can't include because it isn't present in iOS: */
|
||
|
#define ioErr -36
|
||
|
#define paramErr -50
|
||
|
|
||
7 years ago
|
struct ssl_backend_data {
|
||
|
SSLContextRef ssl_ctx;
|
||
|
curl_socket_t ssl_sockfd;
|
||
|
bool ssl_direction; /* true if writing, false if reading */
|
||
|
size_t ssl_write_buffered_length;
|
||
|
};
|
||
|
|
||
|
#define BACKEND connssl->backend
|
||
|
|
||
|
/* pinned public key support tests */
|
||
|
|
||
|
/* version 1 supports macOS 10.12+ and iOS 10+ */
|
||
|
#if ((TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000) || \
|
||
|
(!TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200))
|
||
5 years ago
|
#define SECTRANSP_PINNEDPUBKEY_V1 1
|
||
7 years ago
|
#endif
|
||
|
|
||
|
/* version 2 supports MacOSX 10.7+ */
|
||
|
#if (!TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070)
|
||
5 years ago
|
#define SECTRANSP_PINNEDPUBKEY_V2 1
|
||
7 years ago
|
#endif
|
||
|
|
||
5 years ago
|
#if defined(SECTRANSP_PINNEDPUBKEY_V1) || defined(SECTRANSP_PINNEDPUBKEY_V2)
|
||
7 years ago
|
/* this backend supports CURLOPT_PINNEDPUBLICKEY */
|
||
5 years ago
|
#define SECTRANSP_PINNEDPUBKEY 1
|
||
|
#endif /* SECTRANSP_PINNEDPUBKEY */
|
||
7 years ago
|
|
||
5 years ago
|
#ifdef SECTRANSP_PINNEDPUBKEY
|
||
8 years ago
|
/* both new and old APIs return rsa keys missing the spki header (not DER) */
|
||
|
static const unsigned char rsa4096SpkiHeader[] = {
|
||
|
0x30, 0x82, 0x02, 0x22, 0x30, 0x0d,
|
||
|
0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
|
||
|
0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05,
|
||
|
0x00, 0x03, 0x82, 0x02, 0x0f, 0x00};
|
||
|
|
||
|
static const unsigned char rsa2048SpkiHeader[] = {
|
||
|
0x30, 0x82, 0x01, 0x22, 0x30, 0x0d,
|
||
|
0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
|
||
|
0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05,
|
||
|
0x00, 0x03, 0x82, 0x01, 0x0f, 0x00};
|
||
5 years ago
|
#ifdef SECTRANSP_PINNEDPUBKEY_V1
|
||
8 years ago
|
/* the *new* version doesn't return DER encoded ecdsa certs like the old... */
|
||
|
static const unsigned char ecDsaSecp256r1SpkiHeader[] = {
|
||
|
0x30, 0x59, 0x30, 0x13, 0x06, 0x07,
|
||
|
0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,
|
||
|
0x01, 0x06, 0x08, 0x2a, 0x86, 0x48,
|
||
|
0xce, 0x3d, 0x03, 0x01, 0x07, 0x03,
|
||
|
0x42, 0x00};
|
||
|
|
||
|
static const unsigned char ecDsaSecp384r1SpkiHeader[] = {
|
||
|
0x30, 0x76, 0x30, 0x10, 0x06, 0x07,
|
||
|
0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,
|
||
|
0x01, 0x06, 0x05, 0x2b, 0x81, 0x04,
|
||
|
0x00, 0x22, 0x03, 0x62, 0x00};
|
||
5 years ago
|
#endif /* SECTRANSP_PINNEDPUBKEY_V1 */
|
||
|
#endif /* SECTRANSP_PINNEDPUBKEY */
|
||
8 years ago
|
|
||
10 years ago
|
/* The following two functions were ripped from Apple sample code,
|
||
|
* with some modifications: */
|
||
|
static OSStatus SocketRead(SSLConnectionRef connection,
|
||
|
void *data, /* owned by
|
||
|
* caller, data
|
||
|
* RETURNED */
|
||
|
size_t *dataLength) /* IN/OUT */
|
||
|
{
|
||
|
size_t bytesToGo = *dataLength;
|
||
|
size_t initLen = bytesToGo;
|
||
|
UInt8 *currData = (UInt8 *)data;
|
||
|
/*int sock = *(int *)connection;*/
|
||
|
struct ssl_connect_data *connssl = (struct ssl_connect_data *)connection;
|
||
7 years ago
|
int sock = BACKEND->ssl_sockfd;
|
||
10 years ago
|
OSStatus rtn = noErr;
|
||
|
size_t bytesRead;
|
||
|
ssize_t rrtn;
|
||
|
int theErr;
|
||
|
|
||
|
*dataLength = 0;
|
||
|
|
||
|
for(;;) {
|
||
|
bytesRead = 0;
|
||
|
rrtn = read(sock, currData, bytesToGo);
|
||
|
if(rrtn <= 0) {
|
||
|
/* this is guesswork... */
|
||
|
theErr = errno;
|
||
|
if(rrtn == 0) { /* EOF = server hung up */
|
||
|
/* the framework will turn this into errSSLClosedNoNotify */
|
||
|
rtn = errSSLClosedGraceful;
|
||
|
}
|
||
|
else /* do the switch */
|
||
|
switch(theErr) {
|
||
|
case ENOENT:
|
||
|
/* connection closed */
|
||
|
rtn = errSSLClosedGraceful;
|
||
|
break;
|
||
|
case ECONNRESET:
|
||
|
rtn = errSSLClosedAbort;
|
||
|
break;
|
||
|
case EAGAIN:
|
||
|
rtn = errSSLWouldBlock;
|
||
7 years ago
|
BACKEND->ssl_direction = false;
|
||
10 years ago
|
break;
|
||
|
default:
|
||
|
rtn = ioErr;
|
||
|
break;
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
else {
|
||
|
bytesRead = rrtn;
|
||
|
}
|
||
|
bytesToGo -= bytesRead;
|
||
|
currData += bytesRead;
|
||
|
|
||
|
if(bytesToGo == 0) {
|
||
|
/* filled buffer with incoming data, done */
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
*dataLength = initLen - bytesToGo;
|
||
|
|
||
|
return rtn;
|
||
|
}
|
||
|
|
||
|
static OSStatus SocketWrite(SSLConnectionRef connection,
|
||
|
const void *data,
|
||
|
size_t *dataLength) /* IN/OUT */
|
||
|
{
|
||
|
size_t bytesSent = 0;
|
||
|
/*int sock = *(int *)connection;*/
|
||
|
struct ssl_connect_data *connssl = (struct ssl_connect_data *)connection;
|
||
7 years ago
|
int sock = BACKEND->ssl_sockfd;
|
||
10 years ago
|
ssize_t length;
|
||
|
size_t dataLen = *dataLength;
|
||
|
const UInt8 *dataPtr = (UInt8 *)data;
|
||
|
OSStatus ortn;
|
||
|
int theErr;
|
||
|
|
||
|
*dataLength = 0;
|
||
|
|
||
|
do {
|
||
|
length = write(sock,
|
||
8 years ago
|
(char *)dataPtr + bytesSent,
|
||
10 years ago
|
dataLen - bytesSent);
|
||
|
} while((length > 0) &&
|
||
|
( (bytesSent += length) < dataLen) );
|
||
|
|
||
|
if(length <= 0) {
|
||
|
theErr = errno;
|
||
|
if(theErr == EAGAIN) {
|
||
|
ortn = errSSLWouldBlock;
|
||
7 years ago
|
BACKEND->ssl_direction = true;
|
||
10 years ago
|
}
|
||
|
else {
|
||
|
ortn = ioErr;
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
ortn = noErr;
|
||
|
}
|
||
|
*dataLength = bytesSent;
|
||
|
return ortn;
|
||
|
}
|
||
|
|
||
8 years ago
|
#ifndef CURL_DISABLE_VERBOSE_STRINGS
|
||
|
CF_INLINE const char *SSLCipherNameForNumber(SSLCipherSuite cipher)
|
||
|
{
|
||
|
switch(cipher) {
|
||
10 years ago
|
/* SSL version 3.0 */
|
||
|
case SSL_RSA_WITH_NULL_MD5:
|
||
|
return "SSL_RSA_WITH_NULL_MD5";
|
||
|
break;
|
||
|
case SSL_RSA_WITH_NULL_SHA:
|
||
|
return "SSL_RSA_WITH_NULL_SHA";
|
||
|
break;
|
||
|
case SSL_RSA_EXPORT_WITH_RC4_40_MD5:
|
||
|
return "SSL_RSA_EXPORT_WITH_RC4_40_MD5";
|
||
|
break;
|
||
|
case SSL_RSA_WITH_RC4_128_MD5:
|
||
|
return "SSL_RSA_WITH_RC4_128_MD5";
|
||
|
break;
|
||
|
case SSL_RSA_WITH_RC4_128_SHA:
|
||
|
return "SSL_RSA_WITH_RC4_128_SHA";
|
||
|
break;
|
||
|
case SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5:
|
||
|
return "SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5";
|
||
|
break;
|
||
|
case SSL_RSA_WITH_IDEA_CBC_SHA:
|
||
|
return "SSL_RSA_WITH_IDEA_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_RSA_EXPORT_WITH_DES40_CBC_SHA:
|
||
|
return "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_RSA_WITH_DES_CBC_SHA:
|
||
|
return "SSL_RSA_WITH_DES_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_RSA_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "SSL_RSA_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA:
|
||
|
return "SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_DH_DSS_WITH_DES_CBC_SHA:
|
||
|
return "SSL_DH_DSS_WITH_DES_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA:
|
||
|
return "SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_DH_RSA_WITH_DES_CBC_SHA:
|
||
|
return "SSL_DH_RSA_WITH_DES_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA:
|
||
|
return "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_DHE_DSS_WITH_DES_CBC_SHA:
|
||
|
return "SSL_DHE_DSS_WITH_DES_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA:
|
||
|
return "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_DHE_RSA_WITH_DES_CBC_SHA:
|
||
|
return "SSL_DHE_RSA_WITH_DES_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_DH_anon_EXPORT_WITH_RC4_40_MD5:
|
||
|
return "SSL_DH_anon_EXPORT_WITH_RC4_40_MD5";
|
||
|
break;
|
||
|
case SSL_DH_anon_WITH_RC4_128_MD5:
|
||
|
return "SSL_DH_anon_WITH_RC4_128_MD5";
|
||
|
break;
|
||
|
case SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA:
|
||
|
return "SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_DH_anon_WITH_DES_CBC_SHA:
|
||
|
return "SSL_DH_anon_WITH_DES_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_DH_anon_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "SSL_DH_anon_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_FORTEZZA_DMS_WITH_NULL_SHA:
|
||
|
return "SSL_FORTEZZA_DMS_WITH_NULL_SHA";
|
||
|
break;
|
||
|
case SSL_FORTEZZA_DMS_WITH_FORTEZZA_CBC_SHA:
|
||
|
return "SSL_FORTEZZA_DMS_WITH_FORTEZZA_CBC_SHA";
|
||
|
break;
|
||
|
/* TLS 1.0 with AES (RFC 3268)
|
||
|
(Apparently these are used in SSLv3 implementations as well.) */
|
||
|
case TLS_RSA_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_RSA_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DH_DSS_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_DH_DSS_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DH_RSA_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_DH_RSA_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DHE_DSS_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_DHE_DSS_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DHE_RSA_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_DHE_RSA_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DH_anon_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_DH_anon_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_RSA_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_RSA_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DH_DSS_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_DH_DSS_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DH_RSA_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_DH_RSA_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DHE_DSS_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_DHE_DSS_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DHE_RSA_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_DHE_RSA_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DH_anon_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_DH_anon_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
/* SSL version 2.0 */
|
||
|
case SSL_RSA_WITH_RC2_CBC_MD5:
|
||
|
return "SSL_RSA_WITH_RC2_CBC_MD5";
|
||
|
break;
|
||
|
case SSL_RSA_WITH_IDEA_CBC_MD5:
|
||
|
return "SSL_RSA_WITH_IDEA_CBC_MD5";
|
||
|
break;
|
||
|
case SSL_RSA_WITH_DES_CBC_MD5:
|
||
|
return "SSL_RSA_WITH_DES_CBC_MD5";
|
||
|
break;
|
||
|
case SSL_RSA_WITH_3DES_EDE_CBC_MD5:
|
||
|
return "SSL_RSA_WITH_3DES_EDE_CBC_MD5";
|
||
|
break;
|
||
|
}
|
||
|
return "SSL_NULL_WITH_NULL_NULL";
|
||
|
}
|
||
|
|
||
8 years ago
|
CF_INLINE const char *TLSCipherNameForNumber(SSLCipherSuite cipher)
|
||
|
{
|
||
10 years ago
|
switch(cipher) {
|
||
|
/* TLS 1.0 with AES (RFC 3268) */
|
||
|
case TLS_RSA_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_RSA_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DH_DSS_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_DH_DSS_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DH_RSA_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_DH_RSA_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DHE_DSS_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_DHE_DSS_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DHE_RSA_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_DHE_RSA_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DH_anon_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_DH_anon_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_RSA_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_RSA_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DH_DSS_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_DH_DSS_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DH_RSA_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_DH_RSA_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DHE_DSS_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_DHE_DSS_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DHE_RSA_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_DHE_RSA_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DH_anon_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_DH_anon_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
#if CURL_BUILD_MAC_10_6 || CURL_BUILD_IOS
|
||
|
/* TLS 1.0 with ECDSA (RFC 4492) */
|
||
|
case TLS_ECDH_ECDSA_WITH_NULL_SHA:
|
||
|
return "TLS_ECDH_ECDSA_WITH_NULL_SHA";
|
||
|
break;
|
||
|
case TLS_ECDH_ECDSA_WITH_RC4_128_SHA:
|
||
|
return "TLS_ECDH_ECDSA_WITH_RC4_128_SHA";
|
||
|
break;
|
||
|
case TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_ECDHE_ECDSA_WITH_NULL_SHA:
|
||
|
return "TLS_ECDHE_ECDSA_WITH_NULL_SHA";
|
||
|
break;
|
||
|
case TLS_ECDHE_ECDSA_WITH_RC4_128_SHA:
|
||
|
return "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA";
|
||
|
break;
|
||
|
case TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_ECDH_RSA_WITH_NULL_SHA:
|
||
|
return "TLS_ECDH_RSA_WITH_NULL_SHA";
|
||
|
break;
|
||
|
case TLS_ECDH_RSA_WITH_RC4_128_SHA:
|
||
|
return "TLS_ECDH_RSA_WITH_RC4_128_SHA";
|
||
|
break;
|
||
|
case TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_ECDH_RSA_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_ECDH_RSA_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_ECDHE_RSA_WITH_NULL_SHA:
|
||
|
return "TLS_ECDHE_RSA_WITH_NULL_SHA";
|
||
|
break;
|
||
|
case TLS_ECDHE_RSA_WITH_RC4_128_SHA:
|
||
|
return "TLS_ECDHE_RSA_WITH_RC4_128_SHA";
|
||
|
break;
|
||
|
case TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_ECDH_anon_WITH_NULL_SHA:
|
||
|
return "TLS_ECDH_anon_WITH_NULL_SHA";
|
||
|
break;
|
||
|
case TLS_ECDH_anon_WITH_RC4_128_SHA:
|
||
|
return "TLS_ECDH_anon_WITH_RC4_128_SHA";
|
||
|
break;
|
||
|
case TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_ECDH_anon_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_ECDH_anon_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_ECDH_anon_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_ECDH_anon_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
#endif /* CURL_BUILD_MAC_10_6 || CURL_BUILD_IOS */
|
||
|
#if CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS
|
||
|
/* TLS 1.2 (RFC 5246) */
|
||
|
case TLS_RSA_WITH_NULL_MD5:
|
||
|
return "TLS_RSA_WITH_NULL_MD5";
|
||
|
break;
|
||
|
case TLS_RSA_WITH_NULL_SHA:
|
||
|
return "TLS_RSA_WITH_NULL_SHA";
|
||
|
break;
|
||
|
case TLS_RSA_WITH_RC4_128_MD5:
|
||
|
return "TLS_RSA_WITH_RC4_128_MD5";
|
||
|
break;
|
||
|
case TLS_RSA_WITH_RC4_128_SHA:
|
||
|
return "TLS_RSA_WITH_RC4_128_SHA";
|
||
|
break;
|
||
|
case TLS_RSA_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "TLS_RSA_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_RSA_WITH_NULL_SHA256:
|
||
|
return "TLS_RSA_WITH_NULL_SHA256";
|
||
|
break;
|
||
|
case TLS_RSA_WITH_AES_128_CBC_SHA256:
|
||
|
return "TLS_RSA_WITH_AES_128_CBC_SHA256";
|
||
|
break;
|
||
|
case TLS_RSA_WITH_AES_256_CBC_SHA256:
|
||
|
return "TLS_RSA_WITH_AES_256_CBC_SHA256";
|
||
|
break;
|
||
|
case TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DH_DSS_WITH_AES_128_CBC_SHA256:
|
||
|
return "TLS_DH_DSS_WITH_AES_128_CBC_SHA256";
|
||
|
break;
|
||
|
case TLS_DH_RSA_WITH_AES_128_CBC_SHA256:
|
||
|
return "TLS_DH_RSA_WITH_AES_128_CBC_SHA256";
|
||
|
break;
|
||
|
case TLS_DHE_DSS_WITH_AES_128_CBC_SHA256:
|
||
|
return "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256";
|
||
|
break;
|
||
|
case TLS_DHE_RSA_WITH_AES_128_CBC_SHA256:
|
||
|
return "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256";
|
||
|
break;
|
||
|
case TLS_DH_DSS_WITH_AES_256_CBC_SHA256:
|
||
|
return "TLS_DH_DSS_WITH_AES_256_CBC_SHA256";
|
||
|
break;
|
||
|
case TLS_DH_RSA_WITH_AES_256_CBC_SHA256:
|
||
|
return "TLS_DH_RSA_WITH_AES_256_CBC_SHA256";
|
||
|
break;
|
||
|
case TLS_DHE_DSS_WITH_AES_256_CBC_SHA256:
|
||
|
return "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256";
|
||
|
break;
|
||
|
case TLS_DHE_RSA_WITH_AES_256_CBC_SHA256:
|
||
|
return "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256";
|
||
|
break;
|
||
|
case TLS_DH_anon_WITH_RC4_128_MD5:
|
||
|
return "TLS_DH_anon_WITH_RC4_128_MD5";
|
||
|
break;
|
||
|
case TLS_DH_anon_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DH_anon_WITH_AES_128_CBC_SHA256:
|
||
|
return "TLS_DH_anon_WITH_AES_128_CBC_SHA256";
|
||
|
break;
|
||
|
case TLS_DH_anon_WITH_AES_256_CBC_SHA256:
|
||
|
return "TLS_DH_anon_WITH_AES_256_CBC_SHA256";
|
||
|
break;
|
||
|
/* TLS 1.2 with AES GCM (RFC 5288) */
|
||
|
case TLS_RSA_WITH_AES_128_GCM_SHA256:
|
||
|
return "TLS_RSA_WITH_AES_128_GCM_SHA256";
|
||
|
break;
|
||
|
case TLS_RSA_WITH_AES_256_GCM_SHA384:
|
||
|
return "TLS_RSA_WITH_AES_256_GCM_SHA384";
|
||
|
break;
|
||
|
case TLS_DHE_RSA_WITH_AES_128_GCM_SHA256:
|
||
|
return "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256";
|
||
|
break;
|
||
|
case TLS_DHE_RSA_WITH_AES_256_GCM_SHA384:
|
||
|
return "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384";
|
||
|
break;
|
||
|
case TLS_DH_RSA_WITH_AES_128_GCM_SHA256:
|
||
|
return "TLS_DH_RSA_WITH_AES_128_GCM_SHA256";
|
||
|
break;
|
||
|
case TLS_DH_RSA_WITH_AES_256_GCM_SHA384:
|
||
|
return "TLS_DH_RSA_WITH_AES_256_GCM_SHA384";
|
||
|
break;
|
||
|
case TLS_DHE_DSS_WITH_AES_128_GCM_SHA256:
|
||
|
return "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256";
|
||
|
break;
|
||
|
case TLS_DHE_DSS_WITH_AES_256_GCM_SHA384:
|
||
|
return "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384";
|
||
|
break;
|
||
|
case TLS_DH_DSS_WITH_AES_128_GCM_SHA256:
|
||
|
return "TLS_DH_DSS_WITH_AES_128_GCM_SHA256";
|
||
|
break;
|
||
|
case TLS_DH_DSS_WITH_AES_256_GCM_SHA384:
|
||
|
return "TLS_DH_DSS_WITH_AES_256_GCM_SHA384";
|
||
|
break;
|
||
|
case TLS_DH_anon_WITH_AES_128_GCM_SHA256:
|
||
|
return "TLS_DH_anon_WITH_AES_128_GCM_SHA256";
|
||
|
break;
|
||
|
case TLS_DH_anon_WITH_AES_256_GCM_SHA384:
|
||
|
return "TLS_DH_anon_WITH_AES_256_GCM_SHA384";
|
||
|
break;
|
||
|
/* TLS 1.2 with elliptic curve ciphers (RFC 5289) */
|
||
|
case TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256:
|
||
|
return "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256";
|
||
|
break;
|
||
|
case TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384:
|
||
|
return "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384";
|
||
|
break;
|
||
|
case TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256:
|
||
|
return "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256";
|
||
|
break;
|
||
|
case TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384:
|
||
|
return "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384";
|
||
|
break;
|
||
|
case TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256:
|
||
|
return "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256";
|
||
|
break;
|
||
|
case TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384:
|
||
|
return "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384";
|
||
|
break;
|
||
|
case TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256:
|
||
|
return "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256";
|
||
|
break;
|
||
|
case TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384:
|
||
|
return "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384";
|
||
|
break;
|
||
|
case TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256:
|
||
|
return "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256";
|
||
|
break;
|
||
|
case TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384:
|
||
|
return "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384";
|
||
|
break;
|
||
|
case TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256:
|
||
|
return "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256";
|
||
|
break;
|
||
|
case TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384:
|
||
|
return "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384";
|
||
|
break;
|
||
|
case TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:
|
||
|
return "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256";
|
||
|
break;
|
||
|
case TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384:
|
||
|
return "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384";
|
||
|
break;
|
||
|
case TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256:
|
||
|
return "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256";
|
||
|
break;
|
||
|
case TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384:
|
||
|
return "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384";
|
||
|
break;
|
||
|
case TLS_EMPTY_RENEGOTIATION_INFO_SCSV:
|
||
|
return "TLS_EMPTY_RENEGOTIATION_INFO_SCSV";
|
||
|
break;
|
||
|
#else
|
||
|
case SSL_RSA_WITH_NULL_MD5:
|
||
|
return "TLS_RSA_WITH_NULL_MD5";
|
||
|
break;
|
||
|
case SSL_RSA_WITH_NULL_SHA:
|
||
|
return "TLS_RSA_WITH_NULL_SHA";
|
||
|
break;
|
||
|
case SSL_RSA_WITH_RC4_128_MD5:
|
||
|
return "TLS_RSA_WITH_RC4_128_MD5";
|
||
|
break;
|
||
|
case SSL_RSA_WITH_RC4_128_SHA:
|
||
|
return "TLS_RSA_WITH_RC4_128_SHA";
|
||
|
break;
|
||
|
case SSL_RSA_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "TLS_RSA_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case SSL_DH_anon_WITH_RC4_128_MD5:
|
||
|
return "TLS_DH_anon_WITH_RC4_128_MD5";
|
||
|
break;
|
||
|
case SSL_DH_anon_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
#endif /* CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS */
|
||
|
#if CURL_BUILD_MAC_10_9 || CURL_BUILD_IOS_7
|
||
|
/* TLS PSK (RFC 4279): */
|
||
|
case TLS_PSK_WITH_RC4_128_SHA:
|
||
|
return "TLS_PSK_WITH_RC4_128_SHA";
|
||
|
break;
|
||
|
case TLS_PSK_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "TLS_PSK_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_PSK_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_PSK_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_PSK_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_PSK_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DHE_PSK_WITH_RC4_128_SHA:
|
||
|
return "TLS_DHE_PSK_WITH_RC4_128_SHA";
|
||
|
break;
|
||
|
case TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DHE_PSK_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_DHE_PSK_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_DHE_PSK_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_DHE_PSK_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_RSA_PSK_WITH_RC4_128_SHA:
|
||
|
return "TLS_RSA_PSK_WITH_RC4_128_SHA";
|
||
|
break;
|
||
|
case TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA:
|
||
|
return "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_RSA_PSK_WITH_AES_128_CBC_SHA:
|
||
|
return "TLS_RSA_PSK_WITH_AES_128_CBC_SHA";
|
||
|
break;
|
||
|
case TLS_RSA_PSK_WITH_AES_256_CBC_SHA:
|
||
|
return "TLS_RSA_PSK_WITH_AES_256_CBC_SHA";
|
||
|
break;
|
||
|
/* More TLS PSK (RFC 4785): */
|
||
|
case TLS_PSK_WITH_NULL_SHA:
|
||
|
return "TLS_PSK_WITH_NULL_SHA";
|
||
|
break;
|
||
|
case TLS_DHE_PSK_WITH_NULL_SHA:
|
||
|
return "TLS_DHE_PSK_WITH_NULL_SHA";
|
||
|
break;
|
||
|
case TLS_RSA_PSK_WITH_NULL_SHA:
|
||
|
return "TLS_RSA_PSK_WITH_NULL_SHA";
|
||
|
break;
|
||
|
/* Even more TLS PSK (RFC 5487): */
|
||
|
case TLS_PSK_WITH_AES_128_GCM_SHA256:
|
||
|
return "TLS_PSK_WITH_AES_128_GCM_SHA256";
|
||
|
break;
|
||
|
case TLS_PSK_WITH_AES_256_GCM_SHA384:
|
||
|
return "TLS_PSK_WITH_AES_256_GCM_SHA384";
|
||
|
break;
|
||
|
case TLS_DHE_PSK_WITH_AES_128_GCM_SHA256:
|
||
|
return "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256";
|
||
|
break;
|
||
|
case TLS_DHE_PSK_WITH_AES_256_GCM_SHA384:
|
||
|
return "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384";
|
||
|
break;
|
||
|
case TLS_RSA_PSK_WITH_AES_128_GCM_SHA256:
|
||
|
return "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256";
|
||
|
break;
|
||
|
case TLS_RSA_PSK_WITH_AES_256_GCM_SHA384:
|
||
|
return "TLS_PSK_WITH_AES_256_GCM_SHA384";
|
||
|
break;
|
||
|
case TLS_PSK_WITH_AES_128_CBC_SHA256:
|
||
|
return "TLS_PSK_WITH_AES_128_CBC_SHA256";
|
||
|
break;
|
||
|
case TLS_PSK_WITH_AES_256_CBC_SHA384:
|
||
|
return "TLS_PSK_WITH_AES_256_CBC_SHA384";
|
||
|
break;
|
||
|
case TLS_PSK_WITH_NULL_SHA256:
|
||
|
return "TLS_PSK_WITH_NULL_SHA256";
|
||
|
break;
|
||
|
case TLS_PSK_WITH_NULL_SHA384:
|
||
|
return "TLS_PSK_WITH_NULL_SHA384";
|
||
|
break;
|
||
|
case TLS_DHE_PSK_WITH_AES_128_CBC_SHA256:
|
||
|
return "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256";
|
||
|
break;
|
||
|
case TLS_DHE_PSK_WITH_AES_256_CBC_SHA384:
|
||
|
return "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384";
|
||
|
break;
|
||
|
case TLS_DHE_PSK_WITH_NULL_SHA256:
|
||
|
return "TLS_DHE_PSK_WITH_NULL_SHA256";
|
||
|
break;
|
||
|
case TLS_DHE_PSK_WITH_NULL_SHA384:
|
||
|
return "TLS_RSA_PSK_WITH_NULL_SHA384";
|
||
|
break;
|
||
|
case TLS_RSA_PSK_WITH_AES_128_CBC_SHA256:
|
||
|
return "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256";
|
||
|
break;
|
||
|
case TLS_RSA_PSK_WITH_AES_256_CBC_SHA384:
|
||
|
return "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384";
|
||
|
break;
|
||
|
case TLS_RSA_PSK_WITH_NULL_SHA256:
|
||
|
return "TLS_RSA_PSK_WITH_NULL_SHA256";
|
||
|
break;
|
||
|
case TLS_RSA_PSK_WITH_NULL_SHA384:
|
||
|
return "TLS_RSA_PSK_WITH_NULL_SHA384";
|
||
|
break;
|
||
|
#endif /* CURL_BUILD_MAC_10_9 || CURL_BUILD_IOS_7 */
|
||
7 years ago
|
#if CURL_BUILD_MAC_10_13 || CURL_BUILD_IOS_11
|
||
|
/* New ChaCha20+Poly1305 cipher-suites used by TLS 1.3: */
|
||
|
case TLS_AES_128_GCM_SHA256:
|
||
|
return "TLS_AES_128_GCM_SHA256";
|
||
|
break;
|
||
|
case TLS_AES_256_GCM_SHA384:
|
||
|
return "TLS_AES_256_GCM_SHA384";
|
||
|
break;
|
||
|
case TLS_CHACHA20_POLY1305_SHA256:
|
||
|
return "TLS_CHACHA20_POLY1305_SHA256";
|
||
|
break;
|
||
|
case TLS_AES_128_CCM_SHA256:
|
||
|
return "TLS_AES_128_CCM_SHA256";
|
||
|
break;
|
||
|
case TLS_AES_128_CCM_8_SHA256:
|
||
|
return "TLS_AES_128_CCM_8_SHA256";
|
||
|
break;
|
||
|
case TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256:
|
||
|
return "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256";
|
||
|
break;
|
||
|
case TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256:
|
||
|
return "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256";
|
||
|
break;
|
||
|
#endif /* CURL_BUILD_MAC_10_13 || CURL_BUILD_IOS_11 */
|
||
10 years ago
|
}
|
||
|
return "TLS_NULL_WITH_NULL_NULL";
|
||
|
}
|
||
8 years ago
|
#endif /* !CURL_DISABLE_VERBOSE_STRINGS */
|
||
10 years ago
|
|
||
|
#if CURL_BUILD_MAC
|
||
|
CF_INLINE void GetDarwinVersionNumber(int *major, int *minor)
|
||
|
{
|
||
|
int mib[2];
|
||
|
char *os_version;
|
||
|
size_t os_version_len;
|
||
8 years ago
|
char *os_version_major, *os_version_minor;
|
||
10 years ago
|
char *tok_buf;
|
||
|
|
||
|
/* Get the Darwin kernel version from the kernel using sysctl(): */
|
||
|
mib[0] = CTL_KERN;
|
||
|
mib[1] = KERN_OSRELEASE;
|
||
|
if(sysctl(mib, 2, NULL, &os_version_len, NULL, 0) == -1)
|
||
|
return;
|
||
|
os_version = malloc(os_version_len*sizeof(char));
|
||
|
if(!os_version)
|
||
|
return;
|
||
|
if(sysctl(mib, 2, os_version, &os_version_len, NULL, 0) == -1) {
|
||
|
free(os_version);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
/* Parse the version: */
|
||
|
os_version_major = strtok_r(os_version, ".", &tok_buf);
|
||
|
os_version_minor = strtok_r(NULL, ".", &tok_buf);
|
||
|
*major = atoi(os_version_major);
|
||
|
*minor = atoi(os_version_minor);
|
||
|
free(os_version);
|
||
|
}
|
||
|
#endif /* CURL_BUILD_MAC */
|
||
|
|
||
|
/* Apple provides a myriad of ways of getting information about a certificate
|
||
|
into a string. Some aren't available under iOS or newer cats. So here's
|
||
|
a unified function for getting a string describing the certificate that
|
||
|
ought to work in all cats starting with Leopard. */
|
||
7 years ago
|
CF_INLINE CFStringRef getsubject(SecCertificateRef cert)
|
||
10 years ago
|
{
|
||
|
CFStringRef server_cert_summary = CFSTR("(null)");
|
||
|
|
||
|
#if CURL_BUILD_IOS
|
||
|
/* iOS: There's only one way to do this. */
|
||
|
server_cert_summary = SecCertificateCopySubjectSummary(cert);
|
||
|
#else
|
||
|
#if CURL_BUILD_MAC_10_7
|
||
|
/* Lion & later: Get the long description if we can. */
|
||
|
if(SecCertificateCopyLongDescription != NULL)
|
||
|
server_cert_summary =
|
||
|
SecCertificateCopyLongDescription(NULL, cert, NULL);
|
||
|
else
|
||
|
#endif /* CURL_BUILD_MAC_10_7 */
|
||
|
#if CURL_BUILD_MAC_10_6
|
||
|
/* Snow Leopard: Get the certificate summary. */
|
||
|
if(SecCertificateCopySubjectSummary != NULL)
|
||
|
server_cert_summary = SecCertificateCopySubjectSummary(cert);
|
||
|
else
|
||
|
#endif /* CURL_BUILD_MAC_10_6 */
|
||
|
/* Leopard is as far back as we go... */
|
||
|
(void)SecCertificateCopyCommonName(cert, &server_cert_summary);
|
||
|
#endif /* CURL_BUILD_IOS */
|
||
|
return server_cert_summary;
|
||
|
}
|
||
|
|
||
7 years ago
|
static CURLcode CopyCertSubject(struct Curl_easy *data,
|
||
|
SecCertificateRef cert, char **certp)
|
||
|
{
|
||
|
CFStringRef c = getsubject(cert);
|
||
|
CURLcode result = CURLE_OK;
|
||
|
const char *direct;
|
||
|
char *cbuf = NULL;
|
||
|
*certp = NULL;
|
||
|
|
||
|
if(!c) {
|
||
|
failf(data, "SSL: invalid CA certificate subject");
|
||
5 years ago
|
return CURLE_PEER_FAILED_VERIFICATION;
|
||
7 years ago
|
}
|
||
|
|
||
|
/* If the subject is already available as UTF-8 encoded (ie 'direct') then
|
||
|
use that, else convert it. */
|
||
|
direct = CFStringGetCStringPtr(c, kCFStringEncodingUTF8);
|
||
|
if(direct) {
|
||
|
*certp = strdup(direct);
|
||
|
if(!*certp) {
|
||
|
failf(data, "SSL: out of memory");
|
||
|
result = CURLE_OUT_OF_MEMORY;
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
size_t cbuf_size = ((size_t)CFStringGetLength(c) * 4) + 1;
|
||
|
cbuf = calloc(cbuf_size, 1);
|
||
|
if(cbuf) {
|
||
|
if(!CFStringGetCString(c, cbuf, cbuf_size,
|
||
|
kCFStringEncodingUTF8)) {
|
||
|
failf(data, "SSL: invalid CA certificate subject");
|
||
5 years ago
|
result = CURLE_PEER_FAILED_VERIFICATION;
|
||
7 years ago
|
}
|
||
|
else
|
||
|
/* pass back the buffer */
|
||
|
*certp = cbuf;
|
||
|
}
|
||
|
else {
|
||
|
failf(data, "SSL: couldn't allocate %zu bytes of memory", cbuf_size);
|
||
|
result = CURLE_OUT_OF_MEMORY;
|
||
|
}
|
||
|
}
|
||
|
if(result)
|
||
|
free(cbuf);
|
||
|
CFRelease(c);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
10 years ago
|
#if CURL_SUPPORT_MAC_10_6
|
||
|
/* The SecKeychainSearch API was deprecated in Lion, and using it will raise
|
||
|
deprecation warnings, so let's not compile this unless it's necessary: */
|
||
|
static OSStatus CopyIdentityWithLabelOldSchool(char *label,
|
||
|
SecIdentityRef *out_c_a_k)
|
||
|
{
|
||
|
OSStatus status = errSecItemNotFound;
|
||
|
SecKeychainAttributeList attr_list;
|
||
|
SecKeychainAttribute attr;
|
||
|
SecKeychainSearchRef search = NULL;
|
||
|
SecCertificateRef cert = NULL;
|
||
|
|
||
|
/* Set up the attribute list: */
|
||
|
attr_list.count = 1L;
|
||
|
attr_list.attr = &attr;
|
||
|
|
||
|
/* Set up our lone search criterion: */
|
||
|
attr.tag = kSecLabelItemAttr;
|
||
|
attr.data = label;
|
||
|
attr.length = (UInt32)strlen(label);
|
||
|
|
||
|
/* Start searching: */
|
||
|
status = SecKeychainSearchCreateFromAttributes(NULL,
|
||
|
kSecCertificateItemClass,
|
||
|
&attr_list,
|
||
|
&search);
|
||
|
if(status == noErr) {
|
||
|
status = SecKeychainSearchCopyNext(search,
|
||
|
(SecKeychainItemRef *)&cert);
|
||
|
if(status == noErr && cert) {
|
||
|
/* If we found a certificate, does it have a private key? */
|
||
|
status = SecIdentityCreateWithCertificate(NULL, cert, out_c_a_k);
|
||
|
CFRelease(cert);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if(search)
|
||
|
CFRelease(search);
|
||
|
return status;
|
||
|
}
|
||
|
#endif /* CURL_SUPPORT_MAC_10_6 */
|
||
|
|
||
|
static OSStatus CopyIdentityWithLabel(char *label,
|
||
|
SecIdentityRef *out_cert_and_key)
|
||
|
{
|
||
|
OSStatus status = errSecItemNotFound;
|
||
|
|
||
|
#if CURL_BUILD_MAC_10_7 || CURL_BUILD_IOS
|
||
8 years ago
|
CFArrayRef keys_list;
|
||
|
CFIndex keys_list_count;
|
||
|
CFIndex i;
|
||
|
CFStringRef common_name;
|
||
|
|
||
10 years ago
|
/* SecItemCopyMatching() was introduced in iOS and Snow Leopard.
|
||
|
kSecClassIdentity was introduced in Lion. If both exist, let's use them
|
||
|
to find the certificate. */
|
||
|
if(SecItemCopyMatching != NULL && kSecClassIdentity != NULL) {
|
||
8 years ago
|
CFTypeRef keys[5];
|
||
|
CFTypeRef values[5];
|
||
10 years ago
|
CFDictionaryRef query_dict;
|
||
|
CFStringRef label_cf = CFStringCreateWithCString(NULL, label,
|
||
|
kCFStringEncodingUTF8);
|
||
|
|
||
|
/* Set up our search criteria and expected results: */
|
||
|
values[0] = kSecClassIdentity; /* we want a certificate and a key */
|
||
|
keys[0] = kSecClass;
|
||
|
values[1] = kCFBooleanTrue; /* we want a reference */
|
||
|
keys[1] = kSecReturnRef;
|
||
8 years ago
|
values[2] = kSecMatchLimitAll; /* kSecMatchLimitOne would be better if the
|
||
|
* label matching below worked correctly */
|
||
10 years ago
|
keys[2] = kSecMatchLimit;
|
||
|
/* identity searches need a SecPolicyRef in order to work */
|
||
8 years ago
|
values[3] = SecPolicyCreateSSL(false, NULL);
|
||
10 years ago
|
keys[3] = kSecMatchPolicy;
|
||
8 years ago
|
/* match the name of the certificate (doesn't work in macOS 10.12.1) */
|
||
|
values[4] = label_cf;
|
||
|
keys[4] = kSecAttrLabel;
|
||
10 years ago
|
query_dict = CFDictionaryCreate(NULL, (const void **)keys,
|
||
8 years ago
|
(const void **)values, 5L,
|
||
|
&kCFCopyStringDictionaryKeyCallBacks,
|
||
|
&kCFTypeDictionaryValueCallBacks);
|
||
10 years ago
|
CFRelease(values[3]);
|
||
|
|
||
|
/* Do we have a match? */
|
||
8 years ago
|
status = SecItemCopyMatching(query_dict, (CFTypeRef *) &keys_list);
|
||
|
|
||
|
/* Because kSecAttrLabel matching doesn't work with kSecClassIdentity,
|
||
|
* we need to find the correct identity ourselves */
|
||
|
if(status == noErr) {
|
||
|
keys_list_count = CFArrayGetCount(keys_list);
|
||
|
*out_cert_and_key = NULL;
|
||
|
status = 1;
|
||
7 years ago
|
for(i = 0; i<keys_list_count; i++) {
|
||
8 years ago
|
OSStatus err = noErr;
|
||
|
SecCertificateRef cert = NULL;
|
||
|
SecIdentityRef identity =
|
||
|
(SecIdentityRef) CFArrayGetValueAtIndex(keys_list, i);
|
||
|
err = SecIdentityCopyCertificate(identity, &cert);
|
||
|
if(err == noErr) {
|
||
|
#if CURL_BUILD_IOS
|
||
|
common_name = SecCertificateCopySubjectSummary(cert);
|
||
|
#elif CURL_BUILD_MAC_10_7
|
||
|
SecCertificateCopyCommonName(cert, &common_name);
|
||
|
#endif
|
||
|
if(CFStringCompare(common_name, label_cf, 0) == kCFCompareEqualTo) {
|
||
|
CFRelease(cert);
|
||
|
CFRelease(common_name);
|
||
|
CFRetain(identity);
|
||
|
*out_cert_and_key = identity;
|
||
|
status = noErr;
|
||
|
break;
|
||
|
}
|
||
|
CFRelease(common_name);
|
||
|
}
|
||
|
CFRelease(cert);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if(keys_list)
|
||
|
CFRelease(keys_list);
|
||
10 years ago
|
CFRelease(query_dict);
|
||
8 years ago
|
CFRelease(label_cf);
|
||
10 years ago
|
}
|
||
|
else {
|
||
|
#if CURL_SUPPORT_MAC_10_6
|
||
|
/* On Leopard and Snow Leopard, fall back to SecKeychainSearch. */
|
||
|
status = CopyIdentityWithLabelOldSchool(label, out_cert_and_key);
|
||
8 years ago
|
#endif /* CURL_SUPPORT_MAC_10_6 */
|
||
10 years ago
|
}
|
||
|
#elif CURL_SUPPORT_MAC_10_6
|
||
|
/* For developers building on older cats, we have no choice but to fall back
|
||
|
to SecKeychainSearch. */
|
||
|
status = CopyIdentityWithLabelOldSchool(label, out_cert_and_key);
|
||
|
#endif /* CURL_BUILD_MAC_10_7 || CURL_BUILD_IOS */
|
||
|
return status;
|
||
|
}
|
||
|
|
||
|
static OSStatus CopyIdentityFromPKCS12File(const char *cPath,
|
||
|
const char *cPassword,
|
||
|
SecIdentityRef *out_cert_and_key)
|
||
|
{
|
||
|
OSStatus status = errSecItemNotFound;
|
||
|
CFURLRef pkcs_url = CFURLCreateFromFileSystemRepresentation(NULL,
|
||
|
(const UInt8 *)cPath, strlen(cPath), false);
|
||
|
CFStringRef password = cPassword ? CFStringCreateWithCString(NULL,
|
||
|
cPassword, kCFStringEncodingUTF8) : NULL;
|
||
|
CFDataRef pkcs_data = NULL;
|
||
|
|
||
|
/* We can import P12 files on iOS or OS X 10.7 or later: */
|
||
|
/* These constants are documented as having first appeared in 10.6 but they
|
||
|
raise linker errors when used on that cat for some reason. */
|
||
|
#if CURL_BUILD_MAC_10_7 || CURL_BUILD_IOS
|
||
|
if(CFURLCreateDataAndPropertiesFromResource(NULL, pkcs_url, &pkcs_data,
|
||
6 years ago
|
NULL, NULL, &status)) {
|
||
|
CFArrayRef items = NULL;
|
||
|
|
||
|
/* On iOS SecPKCS12Import will never add the client certificate to the
|
||
|
* Keychain.
|
||
|
*
|
||
|
* It gives us back a SecIdentityRef that we can use directly. */
|
||
|
#if CURL_BUILD_IOS
|
||
10 years ago
|
const void *cKeys[] = {kSecImportExportPassphrase};
|
||
|
const void *cValues[] = {password};
|
||
|
CFDictionaryRef options = CFDictionaryCreate(NULL, cKeys, cValues,
|
||
|
password ? 1L : 0L, NULL, NULL);
|
||
|
|
||
6 years ago
|
if(options != NULL) {
|
||
|
status = SecPKCS12Import(pkcs_data, options, &items);
|
||
|
CFRelease(options);
|
||
|
}
|
||
|
|
||
|
|
||
|
/* On macOS SecPKCS12Import will always add the client certificate to
|
||
|
* the Keychain.
|
||
|
*
|
||
|
* As this doesn't match iOS, and apps may not want to see their client
|
||
|
* certificate saved in the the user's keychain, we use SecItemImport
|
||
|
* with a NULL keychain to avoid importing it.
|
||
|
*
|
||
|
* This returns a SecCertificateRef from which we can construct a
|
||
|
* SecIdentityRef.
|
||
|
*/
|
||
|
#elif CURL_BUILD_MAC_10_7
|
||
|
SecItemImportExportKeyParameters keyParams;
|
||
|
SecExternalFormat inputFormat = kSecFormatPKCS12;
|
||
|
SecExternalItemType inputType = kSecItemTypeCertificate;
|
||
10 years ago
|
|
||
6 years ago
|
memset(&keyParams, 0x00, sizeof(keyParams));
|
||
|
keyParams.version = SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION;
|
||
|
keyParams.passphrase = password;
|
||
|
|
||
|
status = SecItemImport(pkcs_data, NULL, &inputFormat, &inputType,
|
||
|
0, &keyParams, NULL, &items);
|
||
|
#endif
|
||
|
|
||
|
|
||
|
/* Extract the SecIdentityRef */
|
||
|
if(status == errSecSuccess && items && CFArrayGetCount(items)) {
|
||
|
CFIndex i, count;
|
||
|
count = CFArrayGetCount(items);
|
||
|
|
||
|
for(i = 0; i < count; i++) {
|
||
|
CFTypeRef item = (CFTypeRef) CFArrayGetValueAtIndex(items, i);
|
||
|
CFTypeID itemID = CFGetTypeID(item);
|
||
|
|
||
|
if(itemID == CFDictionaryGetTypeID()) {
|
||
|
CFTypeRef identity = (CFTypeRef) CFDictionaryGetValue(
|
||
|
(CFDictionaryRef) item,
|
||
|
kSecImportItemIdentity);
|
||
|
CFRetain(identity);
|
||
|
*out_cert_and_key = (SecIdentityRef) identity;
|
||
|
break;
|
||
|
}
|
||
|
#if CURL_BUILD_MAC_10_7
|
||
|
else if(itemID == SecCertificateGetTypeID()) {
|
||
|
status = SecIdentityCreateWithCertificate(NULL,
|
||
|
(SecCertificateRef) item,
|
||
|
out_cert_and_key);
|
||
|
break;
|
||
|
}
|
||
|
#endif
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
|
if(items)
|
||
|
CFRelease(items);
|
||
|
CFRelease(pkcs_data);
|
||
|
}
|
||
|
#endif /* CURL_BUILD_MAC_10_7 || CURL_BUILD_IOS */
|
||
|
if(password)
|
||
|
CFRelease(password);
|
||
|
CFRelease(pkcs_url);
|
||
|
return status;
|
||
|
}
|
||
|
|
||
|
/* This code was borrowed from nss.c, with some modifications:
|
||
|
* Determine whether the nickname passed in is a filename that needs to
|
||
|
* be loaded as a PEM or a regular NSS nickname.
|
||
|
*
|
||
|
* returns 1 for a file
|
||
|
* returns 0 for not a file
|
||
|
*/
|
||
|
CF_INLINE bool is_file(const char *filename)
|
||
|
{
|
||
|
struct_stat st;
|
||
|
|
||
|
if(filename == NULL)
|
||
|
return false;
|
||
|
|
||
|
if(stat(filename, &st) == 0)
|
||
|
return S_ISREG(st.st_mode);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
8 years ago
|
#if CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS
|
||
5 years ago
|
static CURLcode sectransp_version_from_curl(SSLProtocol *darwinver,
|
||
7 years ago
|
long ssl_version)
|
||
8 years ago
|
{
|
||
|
switch(ssl_version) {
|
||
|
case CURL_SSLVERSION_TLSv1_0:
|
||
|
*darwinver = kTLSProtocol1;
|
||
|
return CURLE_OK;
|
||
|
case CURL_SSLVERSION_TLSv1_1:
|
||
|
*darwinver = kTLSProtocol11;
|
||
|
return CURLE_OK;
|
||
|
case CURL_SSLVERSION_TLSv1_2:
|
||
|
*darwinver = kTLSProtocol12;
|
||
|
return CURLE_OK;
|
||
|
case CURL_SSLVERSION_TLSv1_3:
|
||
7 years ago
|
/* TLS 1.3 support first appeared in iOS 11 and macOS 10.13 */
|
||
6 years ago
|
#if (CURL_BUILD_MAC_10_13 || CURL_BUILD_IOS_11) && HAVE_BUILTIN_AVAILABLE == 1
|
||
7 years ago
|
if(__builtin_available(macOS 10.13, iOS 11.0, *)) {
|
||
|
*darwinver = kTLSProtocol13;
|
||
|
return CURLE_OK;
|
||
|
}
|
||
6 years ago
|
#endif /* (CURL_BUILD_MAC_10_13 || CURL_BUILD_IOS_11) &&
|
||
|
HAVE_BUILTIN_AVAILABLE == 1 */
|
||
8 years ago
|
break;
|
||
|
}
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
static CURLcode
|
||
|
set_ssl_version_min_max(struct connectdata *conn, int sockindex)
|
||
|
{
|
||
|
struct Curl_easy *data = conn->data;
|
||
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||
|
long ssl_version = SSL_CONN_CONFIG(version);
|
||
|
long ssl_version_max = SSL_CONN_CONFIG(version_max);
|
||
7 years ago
|
long max_supported_version_by_os;
|
||
|
|
||
|
/* macOS 10.5-10.7 supported TLS 1.0 only.
|
||
|
macOS 10.8 and later, and iOS 5 and later, added TLS 1.1 and 1.2.
|
||
|
macOS 10.13 and later, and iOS 11 and later, added TLS 1.3. */
|
||
6 years ago
|
#if (CURL_BUILD_MAC_10_13 || CURL_BUILD_IOS_11) && HAVE_BUILTIN_AVAILABLE == 1
|
||
7 years ago
|
if(__builtin_available(macOS 10.13, iOS 11.0, *)) {
|
||
|
max_supported_version_by_os = CURL_SSLVERSION_MAX_TLSv1_3;
|
||
|
}
|
||
|
else {
|
||
|
max_supported_version_by_os = CURL_SSLVERSION_MAX_TLSv1_2;
|
||
|
}
|
||
|
#else
|
||
|
max_supported_version_by_os = CURL_SSLVERSION_MAX_TLSv1_2;
|
||
6 years ago
|
#endif /* (CURL_BUILD_MAC_10_13 || CURL_BUILD_IOS_11) &&
|
||
|
HAVE_BUILTIN_AVAILABLE == 1 */
|
||
8 years ago
|
|
||
|
switch(ssl_version) {
|
||
|
case CURL_SSLVERSION_DEFAULT:
|
||
|
case CURL_SSLVERSION_TLSv1:
|
||
|
ssl_version = CURL_SSLVERSION_TLSv1_0;
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
switch(ssl_version_max) {
|
||
|
case CURL_SSLVERSION_MAX_NONE:
|
||
|
case CURL_SSLVERSION_MAX_DEFAULT:
|
||
7 years ago
|
ssl_version_max = max_supported_version_by_os;
|
||
8 years ago
|
break;
|
||
|
}
|
||
|
|
||
|
#if CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS
|
||
|
if(SSLSetProtocolVersionMax != NULL) {
|
||
|
SSLProtocol darwin_ver_min = kTLSProtocol1;
|
||
|
SSLProtocol darwin_ver_max = kTLSProtocol1;
|
||
5 years ago
|
CURLcode result = sectransp_version_from_curl(&darwin_ver_min,
|
||
8 years ago
|
ssl_version);
|
||
|
if(result) {
|
||
|
failf(data, "unsupported min version passed via CURLOPT_SSLVERSION");
|
||
|
return result;
|
||
|
}
|
||
5 years ago
|
result = sectransp_version_from_curl(&darwin_ver_max,
|
||
8 years ago
|
ssl_version_max >> 16);
|
||
|
if(result) {
|
||
|
failf(data, "unsupported max version passed via CURLOPT_SSLVERSION");
|
||
|
return result;
|
||
|
}
|
||
|
|
||
7 years ago
|
(void)SSLSetProtocolVersionMin(BACKEND->ssl_ctx, darwin_ver_min);
|
||
|
(void)SSLSetProtocolVersionMax(BACKEND->ssl_ctx, darwin_ver_max);
|
||
8 years ago
|
return result;
|
||
|
}
|
||
|
else {
|
||
|
#if CURL_SUPPORT_MAC_10_8
|
||
|
long i = ssl_version;
|
||
7 years ago
|
(void)SSLSetProtocolVersionEnabled(BACKEND->ssl_ctx,
|
||
8 years ago
|
kSSLProtocolAll,
|
||
|
false);
|
||
|
for(; i <= (ssl_version_max >> 16); i++) {
|
||
|
switch(i) {
|
||
|
case CURL_SSLVERSION_TLSv1_0:
|
||
7 years ago
|
(void)SSLSetProtocolVersionEnabled(BACKEND->ssl_ctx,
|
||
8 years ago
|
kTLSProtocol1,
|
||
|
true);
|
||
|
break;
|
||
|
case CURL_SSLVERSION_TLSv1_1:
|
||
7 years ago
|
(void)SSLSetProtocolVersionEnabled(BACKEND->ssl_ctx,
|
||
8 years ago
|
kTLSProtocol11,
|
||
|
true);
|
||
|
break;
|
||
|
case CURL_SSLVERSION_TLSv1_2:
|
||
7 years ago
|
(void)SSLSetProtocolVersionEnabled(BACKEND->ssl_ctx,
|
||
8 years ago
|
kTLSProtocol12,
|
||
|
true);
|
||
|
break;
|
||
|
case CURL_SSLVERSION_TLSv1_3:
|
||
7 years ago
|
failf(data, "Your version of the OS does not support TLSv1.3");
|
||
8 years ago
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
|
}
|
||
|
return CURLE_OK;
|
||
|
#endif /* CURL_SUPPORT_MAC_10_8 */
|
||
|
}
|
||
|
#endif /* CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS */
|
||
5 years ago
|
failf(data, "Secure Transport: cannot set SSL protocol");
|
||
8 years ago
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
|
|
||
|
|
||
5 years ago
|
static CURLcode sectransp_connect_step1(struct connectdata *conn,
|
||
10 years ago
|
int sockindex)
|
||
|
{
|
||
8 years ago
|
struct Curl_easy *data = conn->data;
|
||
10 years ago
|
curl_socket_t sockfd = conn->sock[sockindex];
|
||
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||
8 years ago
|
const char * const ssl_cafile = SSL_CONN_CONFIG(CAfile);
|
||
|
const bool verifypeer = SSL_CONN_CONFIG(verifypeer);
|
||
|
char * const ssl_cert = SSL_SET_OPTION(cert);
|
||
|
const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
|
||
|
conn->host.name;
|
||
|
const long int port = SSL_IS_PROXY() ? conn->port : conn->remote_port;
|
||
10 years ago
|
#ifdef ENABLE_IPV6
|
||
|
struct in6_addr addr;
|
||
|
#else
|
||
|
struct in_addr addr;
|
||
|
#endif /* ENABLE_IPV6 */
|
||
|
size_t all_ciphers_count = 0UL, allowed_ciphers_count = 0UL, i;
|
||
|
SSLCipherSuite *all_ciphers = NULL, *allowed_ciphers = NULL;
|
||
|
OSStatus err = noErr;
|
||
|
#if CURL_BUILD_MAC
|
||
|
int darwinver_maj = 0, darwinver_min = 0;
|
||
|
|
||
|
GetDarwinVersionNumber(&darwinver_maj, &darwinver_min);
|
||
|
#endif /* CURL_BUILD_MAC */
|
||
|
|
||
|
#if CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS
|
||
6 years ago
|
if(SSLCreateContext != NULL) { /* use the newer API if available */
|
||
7 years ago
|
if(BACKEND->ssl_ctx)
|
||
|
CFRelease(BACKEND->ssl_ctx);
|
||
|
BACKEND->ssl_ctx = SSLCreateContext(NULL, kSSLClientSide, kSSLStreamType);
|
||
|
if(!BACKEND->ssl_ctx) {
|
||
10 years ago
|
failf(data, "SSL: couldn't create a context!");
|
||
|
return CURLE_OUT_OF_MEMORY;
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
/* The old ST API does not exist under iOS, so don't compile it: */
|
||
|
#if CURL_SUPPORT_MAC_10_8
|
||
7 years ago
|
if(BACKEND->ssl_ctx)
|
||
|
(void)SSLDisposeContext(BACKEND->ssl_ctx);
|
||
|
err = SSLNewContext(false, &(BACKEND->ssl_ctx));
|
||
10 years ago
|
if(err != noErr) {
|
||
|
failf(data, "SSL: couldn't create a context: OSStatus %d", err);
|
||
|
return CURLE_OUT_OF_MEMORY;
|
||
|
}
|
||
|
#endif /* CURL_SUPPORT_MAC_10_8 */
|
||
|
}
|
||
|
#else
|
||
7 years ago
|
if(BACKEND->ssl_ctx)
|
||
|
(void)SSLDisposeContext(BACKEND->ssl_ctx);
|
||
|
err = SSLNewContext(false, &(BACKEND->ssl_ctx));
|
||
10 years ago
|
if(err != noErr) {
|
||
|
failf(data, "SSL: couldn't create a context: OSStatus %d", err);
|
||
|
return CURLE_OUT_OF_MEMORY;
|
||
|
}
|
||
|
#endif /* CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS */
|
||
7 years ago
|
BACKEND->ssl_write_buffered_length = 0UL; /* reset buffered write length */
|
||
10 years ago
|
|
||
|
/* check to see if we've been told to use an explicit SSL/TLS version */
|
||
|
#if CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS
|
||
|
if(SSLSetProtocolVersionMax != NULL) {
|
||
8 years ago
|
switch(conn->ssl_config.version) {
|
||
|
case CURL_SSLVERSION_TLSv1:
|
||
7 years ago
|
(void)SSLSetProtocolVersionMin(BACKEND->ssl_ctx, kTLSProtocol1);
|
||
6 years ago
|
#if (CURL_BUILD_MAC_10_13 || CURL_BUILD_IOS_11) && HAVE_BUILTIN_AVAILABLE == 1
|
||
7 years ago
|
if(__builtin_available(macOS 10.13, iOS 11.0, *)) {
|
||
|
(void)SSLSetProtocolVersionMax(BACKEND->ssl_ctx, kTLSProtocol13);
|
||
|
}
|
||
|
else {
|
||
|
(void)SSLSetProtocolVersionMax(BACKEND->ssl_ctx, kTLSProtocol12);
|
||
|
}
|
||
|
#else
|
||
7 years ago
|
(void)SSLSetProtocolVersionMax(BACKEND->ssl_ctx, kTLSProtocol12);
|
||
6 years ago
|
#endif /* (CURL_BUILD_MAC_10_13 || CURL_BUILD_IOS_11) &&
|
||
|
HAVE_BUILTIN_AVAILABLE == 1 */
|
||
8 years ago
|
break;
|
||
5 years ago
|
case CURL_SSLVERSION_DEFAULT:
|
||
8 years ago
|
case CURL_SSLVERSION_TLSv1_0:
|
||
|
case CURL_SSLVERSION_TLSv1_1:
|
||
|
case CURL_SSLVERSION_TLSv1_2:
|
||
|
case CURL_SSLVERSION_TLSv1_3:
|
||
|
{
|
||
|
CURLcode result = set_ssl_version_min_max(conn, sockindex);
|
||
|
if(result != CURLE_OK)
|
||
|
return result;
|
||
10 years ago
|
break;
|
||
8 years ago
|
}
|
||
|
case CURL_SSLVERSION_SSLv3:
|
||
7 years ago
|
err = SSLSetProtocolVersionMin(BACKEND->ssl_ctx, kSSLProtocol3);
|
||
8 years ago
|
if(err != noErr) {
|
||
|
failf(data, "Your version of the OS does not support SSLv3");
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
7 years ago
|
(void)SSLSetProtocolVersionMax(BACKEND->ssl_ctx, kSSLProtocol3);
|
||
8 years ago
|
break;
|
||
|
case CURL_SSLVERSION_SSLv2:
|
||
7 years ago
|
err = SSLSetProtocolVersionMin(BACKEND->ssl_ctx, kSSLProtocol2);
|
||
8 years ago
|
if(err != noErr) {
|
||
|
failf(data, "Your version of the OS does not support SSLv2");
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
7 years ago
|
(void)SSLSetProtocolVersionMax(BACKEND->ssl_ctx, kSSLProtocol2);
|
||
8 years ago
|
break;
|
||
|
default:
|
||
|
failf(data, "Unrecognized parameter passed via CURLOPT_SSLVERSION");
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
10 years ago
|
}
|
||
|
}
|
||
|
else {
|
||
|
#if CURL_SUPPORT_MAC_10_8
|
||
7 years ago
|
(void)SSLSetProtocolVersionEnabled(BACKEND->ssl_ctx,
|
||
10 years ago
|
kSSLProtocolAll,
|
||
|
false);
|
||
8 years ago
|
switch(conn->ssl_config.version) {
|
||
10 years ago
|
case CURL_SSLVERSION_DEFAULT:
|
||
|
case CURL_SSLVERSION_TLSv1:
|
||
7 years ago
|
(void)SSLSetProtocolVersionEnabled(BACKEND->ssl_ctx,
|
||
10 years ago
|
kTLSProtocol1,
|
||
|
true);
|
||
7 years ago
|
(void)SSLSetProtocolVersionEnabled(BACKEND->ssl_ctx,
|
||
8 years ago
|
kTLSProtocol11,
|
||
|
true);
|
||
7 years ago
|
(void)SSLSetProtocolVersionEnabled(BACKEND->ssl_ctx,
|
||
8 years ago
|
kTLSProtocol12,
|
||
|
true);
|
||
10 years ago
|
break;
|
||
8 years ago
|
case CURL_SSLVERSION_TLSv1_0:
|
||
10 years ago
|
case CURL_SSLVERSION_TLSv1_1:
|
||
|
case CURL_SSLVERSION_TLSv1_2:
|
||
8 years ago
|
case CURL_SSLVERSION_TLSv1_3:
|
||
|
{
|
||
|
CURLcode result = set_ssl_version_min_max(conn, sockindex);
|
||
|
if(result != CURLE_OK)
|
||
|
return result;
|
||
|
break;
|
||
|
}
|
||
|
case CURL_SSLVERSION_SSLv3:
|
||
7 years ago
|
err = SSLSetProtocolVersionEnabled(BACKEND->ssl_ctx,
|
||
8 years ago
|
kSSLProtocol3,
|
||
10 years ago
|
true);
|
||
|
if(err != noErr) {
|
||
8 years ago
|
failf(data, "Your version of the OS does not support SSLv3");
|
||
10 years ago
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
|
break;
|
||
8 years ago
|
case CURL_SSLVERSION_SSLv2:
|
||
7 years ago
|
err = SSLSetProtocolVersionEnabled(BACKEND->ssl_ctx,
|
||
8 years ago
|
kSSLProtocol2,
|
||
10 years ago
|
true);
|
||
9 years ago
|
if(err != noErr) {
|
||
8 years ago
|
failf(data, "Your version of the OS does not support SSLv2");
|
||
9 years ago
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
10 years ago
|
break;
|
||
8 years ago
|
default:
|
||
|
failf(data, "Unrecognized parameter passed via CURLOPT_SSLVERSION");
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
|
#endif /* CURL_SUPPORT_MAC_10_8 */
|
||
|
}
|
||
|
#else
|
||
|
if(conn->ssl_config.version_max != CURL_SSLVERSION_MAX_NONE) {
|
||
|
failf(data, "Your version of the OS does not support to set maximum"
|
||
|
" SSL/TLS version");
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
7 years ago
|
(void)SSLSetProtocolVersionEnabled(BACKEND->ssl_ctx, kSSLProtocolAll, false);
|
||
8 years ago
|
switch(conn->ssl_config.version) {
|
||
|
case CURL_SSLVERSION_DEFAULT:
|
||
|
case CURL_SSLVERSION_TLSv1:
|
||
|
case CURL_SSLVERSION_TLSv1_0:
|
||
7 years ago
|
(void)SSLSetProtocolVersionEnabled(BACKEND->ssl_ctx,
|
||
8 years ago
|
kTLSProtocol1,
|
||
|
true);
|
||
|
break;
|
||
|
case CURL_SSLVERSION_TLSv1_1:
|
||
|
failf(data, "Your version of the OS does not support TLSv1.1");
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
case CURL_SSLVERSION_TLSv1_2:
|
||
|
failf(data, "Your version of the OS does not support TLSv1.2");
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
case CURL_SSLVERSION_TLSv1_3:
|
||
|
failf(data, "Your version of the OS does not support TLSv1.3");
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
case CURL_SSLVERSION_SSLv2:
|
||
7 years ago
|
err = SSLSetProtocolVersionEnabled(BACKEND->ssl_ctx,
|
||
8 years ago
|
kSSLProtocol2,
|
||
|
true);
|
||
|
if(err != noErr) {
|
||
|
failf(data, "Your version of the OS does not support SSLv2");
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
|
break;
|
||
|
case CURL_SSLVERSION_SSLv3:
|
||
7 years ago
|
err = SSLSetProtocolVersionEnabled(BACKEND->ssl_ctx,
|
||
8 years ago
|
kSSLProtocol3,
|
||
|
true);
|
||
|
if(err != noErr) {
|
||
|
failf(data, "Your version of the OS does not support SSLv3");
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
|
break;
|
||
|
default:
|
||
|
failf(data, "Unrecognized parameter passed via CURLOPT_SSLVERSION");
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
10 years ago
|
}
|
||
|
#endif /* CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS */
|
||
|
|
||
6 years ago
|
#if (CURL_BUILD_MAC_10_13 || CURL_BUILD_IOS_11) && HAVE_BUILTIN_AVAILABLE == 1
|
||
|
if(conn->bits.tls_enable_alpn) {
|
||
5 years ago
|
if(__builtin_available(macOS 10.13.4, iOS 11, tvOS 11, *)) {
|
||
6 years ago
|
CFMutableArrayRef alpnArr = CFArrayCreateMutable(NULL, 0,
|
||
|
&kCFTypeArrayCallBacks);
|
||
|
|
||
|
#ifdef USE_NGHTTP2
|
||
|
if(data->set.httpversion >= CURL_HTTP_VERSION_2 &&
|
||
|
(!SSL_IS_PROXY() || !conn->bits.tunnel_proxy)) {
|
||
|
CFArrayAppendValue(alpnArr, CFSTR(NGHTTP2_PROTO_VERSION_ID));
|
||
|
infof(data, "ALPN, offering %s\n", NGHTTP2_PROTO_VERSION_ID);
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
CFArrayAppendValue(alpnArr, CFSTR(ALPN_HTTP_1_1));
|
||
|
infof(data, "ALPN, offering %s\n", ALPN_HTTP_1_1);
|
||
|
|
||
|
/* expects length prefixed preference ordered list of protocols in wire
|
||
|
* format
|
||
|
*/
|
||
|
err = SSLSetALPNProtocols(BACKEND->ssl_ctx, alpnArr);
|
||
|
if(err != noErr)
|
||
|
infof(data, "WARNING: failed to set ALPN protocols; OSStatus %d\n",
|
||
|
err);
|
||
|
CFRelease(alpnArr);
|
||
|
}
|
||
|
}
|
||
|
#endif
|
||
|
|
||
8 years ago
|
if(SSL_SET_OPTION(key)) {
|
||
10 years ago
|
infof(data, "WARNING: SSL: CURLOPT_SSLKEY is ignored by Secure "
|
||
8 years ago
|
"Transport. The private key must be in the Keychain.\n");
|
||
10 years ago
|
}
|
||
|
|
||
8 years ago
|
if(ssl_cert) {
|
||
10 years ago
|
SecIdentityRef cert_and_key = NULL;
|
||
8 years ago
|
bool is_cert_file = is_file(ssl_cert);
|
||
10 years ago
|
|
||
|
/* User wants to authenticate with a client cert. Look for it:
|
||
|
If we detect that this is a file on disk, then let's load it.
|
||
|
Otherwise, assume that the user wants to use an identity loaded
|
||
|
from the Keychain. */
|
||
|
if(is_cert_file) {
|
||
8 years ago
|
if(!SSL_SET_OPTION(cert_type))
|
||
10 years ago
|
infof(data, "WARNING: SSL: Certificate type not set, assuming "
|
||
|
"PKCS#12 format.\n");
|
||
8 years ago
|
else if(strncmp(SSL_SET_OPTION(cert_type), "P12",
|
||
|
strlen(SSL_SET_OPTION(cert_type))) != 0)
|
||
10 years ago
|
infof(data, "WARNING: SSL: The Security framework only supports "
|
||
|
"loading identities that are in PKCS#12 format.\n");
|
||
|
|
||
8 years ago
|
err = CopyIdentityFromPKCS12File(ssl_cert,
|
||
|
SSL_SET_OPTION(key_passwd), &cert_and_key);
|
||
10 years ago
|
}
|
||
|
else
|
||
8 years ago
|
err = CopyIdentityWithLabel(ssl_cert, &cert_and_key);
|
||
10 years ago
|
|
||
8 years ago
|
if(err == noErr && cert_and_key) {
|
||
10 years ago
|
SecCertificateRef cert = NULL;
|
||
|
CFTypeRef certs_c[1];
|
||
|
CFArrayRef certs;
|
||
|
|
||
|
/* If we found one, print it out: */
|
||
|
err = SecIdentityCopyCertificate(cert_and_key, &cert);
|
||
|
if(err == noErr) {
|
||
7 years ago
|
char *certp;
|
||
|
CURLcode result = CopyCertSubject(data, cert, &certp);
|
||
|
if(!result) {
|
||
|
infof(data, "Client certificate: %s\n", certp);
|
||
|
free(certp);
|
||
10 years ago
|
}
|
||
7 years ago
|
|
||
|
CFRelease(cert);
|
||
5 years ago
|
if(result == CURLE_PEER_FAILED_VERIFICATION)
|
||
6 years ago
|
return CURLE_SSL_CERTPROBLEM;
|
||
7 years ago
|
if(result)
|
||
|
return result;
|
||
10 years ago
|
}
|
||
|
certs_c[0] = cert_and_key;
|
||
|
certs = CFArrayCreate(NULL, (const void **)certs_c, 1L,
|
||
|
&kCFTypeArrayCallBacks);
|
||
7 years ago
|
err = SSLSetCertificate(BACKEND->ssl_ctx, certs);
|
||
10 years ago
|
if(certs)
|
||
|
CFRelease(certs);
|
||
|
if(err != noErr) {
|
||
|
failf(data, "SSL: SSLSetCertificate() failed: OSStatus %d", err);
|
||
|
return CURLE_SSL_CERTPROBLEM;
|
||
|
}
|
||
|
CFRelease(cert_and_key);
|
||
|
}
|
||
|
else {
|
||
|
switch(err) {
|
||
8 years ago
|
case errSecAuthFailed: case -25264: /* errSecPkcs12VerifyFailure */
|
||
|
failf(data, "SSL: Incorrect password for the certificate \"%s\" "
|
||
|
"and its private key.", ssl_cert);
|
||
|
break;
|
||
|
case -26275: /* errSecDecode */ case -25257: /* errSecUnknownFormat */
|
||
|
failf(data, "SSL: Couldn't make sense of the data in the "
|
||
|
"certificate \"%s\" and its private key.",
|
||
|
ssl_cert);
|
||
|
break;
|
||
|
case -25260: /* errSecPassphraseRequired */
|
||
|
failf(data, "SSL The certificate \"%s\" requires a password.",
|
||
|
ssl_cert);
|
||
|
break;
|
||
|
case errSecItemNotFound:
|
||
|
failf(data, "SSL: Can't find the certificate \"%s\" and its private "
|
||
|
"key in the Keychain.", ssl_cert);
|
||
|
break;
|
||
|
default:
|
||
|
failf(data, "SSL: Can't load the certificate \"%s\" and its private "
|
||
|
"key: OSStatus %d", ssl_cert, err);
|
||
|
break;
|
||
10 years ago
|
}
|
||
|
return CURLE_SSL_CERTPROBLEM;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* SSL always tries to verify the peer, this only says whether it should
|
||
|
* fail to connect if the verification fails, or if it should continue
|
||
|
* anyway. In the latter case the result of the verification is checked with
|
||
|
* SSL_get_verify_result() below. */
|
||
|
#if CURL_BUILD_MAC_10_6 || CURL_BUILD_IOS
|
||
|
/* Snow Leopard introduced the SSLSetSessionOption() function, but due to
|
||
|
a library bug with the way the kSSLSessionOptionBreakOnServerAuth flag
|
||
8 years ago
|
works, it doesn't work as expected under Snow Leopard, Lion or
|
||
|
Mountain Lion.
|
||
10 years ago
|
So we need to call SSLSetEnableCertVerify() on those older cats in order
|
||
|
to disable certificate validation if the user turned that off.
|
||
|
(SecureTransport will always validate the certificate chain by
|
||
8 years ago
|
default.)
|
||
|
Note:
|
||
|
Darwin 11.x.x is Lion (10.7)
|
||
|
Darwin 12.x.x is Mountain Lion (10.8)
|
||
|
Darwin 13.x.x is Mavericks (10.9)
|
||
|
Darwin 14.x.x is Yosemite (10.10)
|
||
|
Darwin 15.x.x is El Capitan (10.11)
|
||
|
*/
|
||
10 years ago
|
#if CURL_BUILD_MAC
|
||
8 years ago
|
if(SSLSetSessionOption != NULL && darwinver_maj >= 13) {
|
||
10 years ago
|
#else
|
||
|
if(SSLSetSessionOption != NULL) {
|
||
|
#endif /* CURL_BUILD_MAC */
|
||
8 years ago
|
bool break_on_auth = !conn->ssl_config.verifypeer || ssl_cafile;
|
||
7 years ago
|
err = SSLSetSessionOption(BACKEND->ssl_ctx,
|
||
10 years ago
|
kSSLSessionOptionBreakOnServerAuth,
|
||
|
break_on_auth);
|
||
|
if(err != noErr) {
|
||
|
failf(data, "SSL: SSLSetSessionOption() failed: OSStatus %d", err);
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
#if CURL_SUPPORT_MAC_10_8
|
||
7 years ago
|
err = SSLSetEnableCertVerify(BACKEND->ssl_ctx,
|
||
8 years ago
|
conn->ssl_config.verifypeer?true:false);
|
||
10 years ago
|
if(err != noErr) {
|
||
|
failf(data, "SSL: SSLSetEnableCertVerify() failed: OSStatus %d", err);
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
|
#endif /* CURL_SUPPORT_MAC_10_8 */
|
||
|
}
|
||
|
#else
|
||
7 years ago
|
err = SSLSetEnableCertVerify(BACKEND->ssl_ctx,
|
||
8 years ago
|
conn->ssl_config.verifypeer?true:false);
|
||
10 years ago
|
if(err != noErr) {
|
||
|
failf(data, "SSL: SSLSetEnableCertVerify() failed: OSStatus %d", err);
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
|
#endif /* CURL_BUILD_MAC_10_6 || CURL_BUILD_IOS */
|
||
|
|
||
8 years ago
|
if(ssl_cafile && verifypeer) {
|
||
|
bool is_cert_file = is_file(ssl_cafile);
|
||
10 years ago
|
|
||
|
if(!is_cert_file) {
|
||
8 years ago
|
failf(data, "SSL: can't load CA certificate file %s", ssl_cafile);
|
||
10 years ago
|
return CURLE_SSL_CACERT_BADFILE;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* Configure hostname check. SNI is used if available.
|
||
|
* Both hostname check and SNI require SSLSetPeerDomainName().
|
||
|
* Also: the verifyhost setting influences SNI usage */
|
||
8 years ago
|
if(conn->ssl_config.verifyhost) {
|
||
7 years ago
|
err = SSLSetPeerDomainName(BACKEND->ssl_ctx, hostname,
|
||
8 years ago
|
strlen(hostname));
|
||
10 years ago
|
|
||
|
if(err != noErr) {
|
||
|
infof(data, "WARNING: SSL: SSLSetPeerDomainName() failed: OSStatus %d\n",
|
||
|
err);
|
||
|
}
|
||
|
|
||
8 years ago
|
if((Curl_inet_pton(AF_INET, hostname, &addr))
|
||
10 years ago
|
#ifdef ENABLE_IPV6
|
||
8 years ago
|
|| (Curl_inet_pton(AF_INET6, hostname, &addr))
|
||
10 years ago
|
#endif
|
||
|
) {
|
||
8 years ago
|
infof(data, "WARNING: using IP address, SNI is being disabled by "
|
||
|
"the OS.\n");
|
||
10 years ago
|
}
|
||
|
}
|
||
8 years ago
|
else {
|
||
|
infof(data, "WARNING: disabling hostname validation also disables SNI.\n");
|
||
|
}
|
||
10 years ago
|
|
||
|
/* Disable cipher suites that ST supports but are not safe. These ciphers
|
||
|
are unlikely to be used in any case since ST gives other ciphers a much
|
||
|
higher priority, but it's probably better that we not connect at all than
|
||
|
to give the user a false sense of security if the server only supports
|
||
|
insecure ciphers. (Note: We don't care about SSLv2-only ciphers.) */
|
||
6 years ago
|
err = SSLGetNumberSupportedCiphers(BACKEND->ssl_ctx, &all_ciphers_count);
|
||
|
if(err != noErr) {
|
||
|
failf(data, "SSL: SSLGetNumberSupportedCiphers() failed: OSStatus %d",
|
||
|
err);
|
||
|
return CURLE_SSL_CIPHER;
|
||
|
}
|
||
10 years ago
|
all_ciphers = malloc(all_ciphers_count*sizeof(SSLCipherSuite));
|
||
6 years ago
|
if(!all_ciphers) {
|
||
|
failf(data, "SSL: Failed to allocate memory for all ciphers");
|
||
|
return CURLE_OUT_OF_MEMORY;
|
||
10 years ago
|
}
|
||
6 years ago
|
allowed_ciphers = malloc(all_ciphers_count*sizeof(SSLCipherSuite));
|
||
|
if(!allowed_ciphers) {
|
||
10 years ago
|
Curl_safefree(all_ciphers);
|
||
|
failf(data, "SSL: Failed to allocate memory for allowed ciphers");
|
||
|
return CURLE_OUT_OF_MEMORY;
|
||
|
}
|
||
6 years ago
|
err = SSLGetSupportedCiphers(BACKEND->ssl_ctx, all_ciphers,
|
||
|
&all_ciphers_count);
|
||
|
if(err != noErr) {
|
||
|
Curl_safefree(all_ciphers);
|
||
|
Curl_safefree(allowed_ciphers);
|
||
|
return CURLE_SSL_CIPHER;
|
||
|
}
|
||
|
for(i = 0UL ; i < all_ciphers_count ; i++) {
|
||
|
#if CURL_BUILD_MAC
|
||
|
/* There's a known bug in early versions of Mountain Lion where ST's ECC
|
||
|
ciphers (cipher suite 0xC001 through 0xC032) simply do not work.
|
||
|
Work around the problem here by disabling those ciphers if we are
|
||
|
running in an affected version of OS X. */
|
||
|
if(darwinver_maj == 12 && darwinver_min <= 3 &&
|
||
|
all_ciphers[i] >= 0xC001 && all_ciphers[i] <= 0xC032) {
|
||
|
continue;
|
||
|
}
|
||
|
#endif /* CURL_BUILD_MAC */
|
||
|
switch(all_ciphers[i]) {
|
||
|
/* Disable NULL ciphersuites: */
|
||
|
case SSL_NULL_WITH_NULL_NULL:
|
||
|
case SSL_RSA_WITH_NULL_MD5:
|
||
|
case SSL_RSA_WITH_NULL_SHA:
|
||
|
case 0x003B: /* TLS_RSA_WITH_NULL_SHA256 */
|
||
|
case SSL_FORTEZZA_DMS_WITH_NULL_SHA:
|
||
|
case 0xC001: /* TLS_ECDH_ECDSA_WITH_NULL_SHA */
|
||
|
case 0xC006: /* TLS_ECDHE_ECDSA_WITH_NULL_SHA */
|
||
|
case 0xC00B: /* TLS_ECDH_RSA_WITH_NULL_SHA */
|
||
|
case 0xC010: /* TLS_ECDHE_RSA_WITH_NULL_SHA */
|
||
|
case 0x002C: /* TLS_PSK_WITH_NULL_SHA */
|
||
|
case 0x002D: /* TLS_DHE_PSK_WITH_NULL_SHA */
|
||
|
case 0x002E: /* TLS_RSA_PSK_WITH_NULL_SHA */
|
||
|
case 0x00B0: /* TLS_PSK_WITH_NULL_SHA256 */
|
||
|
case 0x00B1: /* TLS_PSK_WITH_NULL_SHA384 */
|
||
|
case 0x00B4: /* TLS_DHE_PSK_WITH_NULL_SHA256 */
|
||
|
case 0x00B5: /* TLS_DHE_PSK_WITH_NULL_SHA384 */
|
||
|
case 0x00B8: /* TLS_RSA_PSK_WITH_NULL_SHA256 */
|
||
|
case 0x00B9: /* TLS_RSA_PSK_WITH_NULL_SHA384 */
|
||
|
/* Disable anonymous ciphersuites: */
|
||
|
case SSL_DH_anon_EXPORT_WITH_RC4_40_MD5:
|
||
|
case SSL_DH_anon_WITH_RC4_128_MD5:
|
||
|
case SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA:
|
||
|
case SSL_DH_anon_WITH_DES_CBC_SHA:
|
||
|
case SSL_DH_anon_WITH_3DES_EDE_CBC_SHA:
|
||
|
case TLS_DH_anon_WITH_AES_128_CBC_SHA:
|
||
|
case TLS_DH_anon_WITH_AES_256_CBC_SHA:
|
||
|
case 0xC015: /* TLS_ECDH_anon_WITH_NULL_SHA */
|
||
|
case 0xC016: /* TLS_ECDH_anon_WITH_RC4_128_SHA */
|
||
|
case 0xC017: /* TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA */
|
||
|
case 0xC018: /* TLS_ECDH_anon_WITH_AES_128_CBC_SHA */
|
||
|
case 0xC019: /* TLS_ECDH_anon_WITH_AES_256_CBC_SHA */
|
||
|
case 0x006C: /* TLS_DH_anon_WITH_AES_128_CBC_SHA256 */
|
||
|
case 0x006D: /* TLS_DH_anon_WITH_AES_256_CBC_SHA256 */
|
||
|
case 0x00A6: /* TLS_DH_anon_WITH_AES_128_GCM_SHA256 */
|
||
|
case 0x00A7: /* TLS_DH_anon_WITH_AES_256_GCM_SHA384 */
|
||
|
/* Disable weak key ciphersuites: */
|
||
|
case SSL_RSA_EXPORT_WITH_RC4_40_MD5:
|
||
|
case SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5:
|
||
|
case SSL_RSA_EXPORT_WITH_DES40_CBC_SHA:
|
||
|
case SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA:
|
||
|
case SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA:
|
||
|
case SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA:
|
||
|
case SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA:
|
||
|
case SSL_RSA_WITH_DES_CBC_SHA:
|
||
|
case SSL_DH_DSS_WITH_DES_CBC_SHA:
|
||
|
case SSL_DH_RSA_WITH_DES_CBC_SHA:
|
||
|
case SSL_DHE_DSS_WITH_DES_CBC_SHA:
|
||
|
case SSL_DHE_RSA_WITH_DES_CBC_SHA:
|
||
|
/* Disable IDEA: */
|
||
|
case SSL_RSA_WITH_IDEA_CBC_SHA:
|
||
|
case SSL_RSA_WITH_IDEA_CBC_MD5:
|
||
|
/* Disable RC4: */
|
||
|
case SSL_RSA_WITH_RC4_128_MD5:
|
||
|
case SSL_RSA_WITH_RC4_128_SHA:
|
||
|
case 0xC002: /* TLS_ECDH_ECDSA_WITH_RC4_128_SHA */
|
||
|
case 0xC007: /* TLS_ECDHE_ECDSA_WITH_RC4_128_SHA*/
|
||
|
case 0xC00C: /* TLS_ECDH_RSA_WITH_RC4_128_SHA */
|
||
|
case 0xC011: /* TLS_ECDHE_RSA_WITH_RC4_128_SHA */
|
||
|
case 0x008A: /* TLS_PSK_WITH_RC4_128_SHA */
|
||
|
case 0x008E: /* TLS_DHE_PSK_WITH_RC4_128_SHA */
|
||
|
case 0x0092: /* TLS_RSA_PSK_WITH_RC4_128_SHA */
|
||
|
break;
|
||
|
default: /* enable everything else */
|
||
|
allowed_ciphers[allowed_ciphers_count++] = all_ciphers[i];
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
err = SSLSetEnabledCiphers(BACKEND->ssl_ctx, allowed_ciphers,
|
||
|
allowed_ciphers_count);
|
||
10 years ago
|
Curl_safefree(all_ciphers);
|
||
|
Curl_safefree(allowed_ciphers);
|
||
6 years ago
|
if(err != noErr) {
|
||
|
failf(data, "SSL: SSLSetEnabledCiphers() failed: OSStatus %d", err);
|
||
|
return CURLE_SSL_CIPHER;
|
||
|
}
|
||
10 years ago
|
|
||
|
#if CURL_BUILD_MAC_10_9 || CURL_BUILD_IOS_7
|
||
|
/* We want to enable 1/n-1 when using a CBC cipher unless the user
|
||
|
specifically doesn't want us doing that: */
|
||
9 years ago
|
if(SSLSetSessionOption != NULL) {
|
||
7 years ago
|
SSLSetSessionOption(BACKEND->ssl_ctx, kSSLSessionOptionSendOneByteRecord,
|
||
8 years ago
|
!data->set.ssl.enable_beast);
|
||
7 years ago
|
SSLSetSessionOption(BACKEND->ssl_ctx, kSSLSessionOptionFalseStart,
|
||
9 years ago
|
data->set.ssl.falsestart); /* false start support */
|
||
|
}
|
||
10 years ago
|
#endif /* CURL_BUILD_MAC_10_9 || CURL_BUILD_IOS_7 */
|
||
|
|
||
|
/* Check if there's a cached ID we can/should use here! */
|
||
8 years ago
|
if(SSL_SET_OPTION(primary.sessionid)) {
|
||
8 years ago
|
char *ssl_sessionid;
|
||
|
size_t ssl_sessionid_len;
|
||
|
|
||
|
Curl_ssl_sessionid_lock(conn);
|
||
|
if(!Curl_ssl_getsessionid(conn, (void **)&ssl_sessionid,
|
||
8 years ago
|
&ssl_sessionid_len, sockindex)) {
|
||
8 years ago
|
/* we got a session id, use it! */
|
||
7 years ago
|
err = SSLSetPeerID(BACKEND->ssl_ctx, ssl_sessionid, ssl_sessionid_len);
|
||
8 years ago
|
Curl_ssl_sessionid_unlock(conn);
|
||
|
if(err != noErr) {
|
||
|
failf(data, "SSL: SSLSetPeerID() failed: OSStatus %d", err);
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
|
/* Informational message */
|
||
|
infof(data, "SSL re-using session ID\n");
|
||
10 years ago
|
}
|
||
8 years ago
|
/* If there isn't one, then let's make one up! This has to be done prior
|
||
|
to starting the handshake. */
|
||
|
else {
|
||
|
CURLcode result;
|
||
|
ssl_sessionid =
|
||
8 years ago
|
aprintf("%s:%d:%d:%s:%hu", ssl_cafile,
|
||
|
verifypeer, SSL_CONN_CONFIG(verifyhost), hostname, port);
|
||
8 years ago
|
ssl_sessionid_len = strlen(ssl_sessionid);
|
||
|
|
||
7 years ago
|
err = SSLSetPeerID(BACKEND->ssl_ctx, ssl_sessionid, ssl_sessionid_len);
|
||
8 years ago
|
if(err != noErr) {
|
||
|
Curl_ssl_sessionid_unlock(conn);
|
||
|
failf(data, "SSL: SSLSetPeerID() failed: OSStatus %d", err);
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
result = Curl_ssl_addsessionid(conn, ssl_sessionid, ssl_sessionid_len,
|
||
|
sockindex);
|
||
8 years ago
|
Curl_ssl_sessionid_unlock(conn);
|
||
|
if(result) {
|
||
|
failf(data, "failed to store ssl session");
|
||
|
return result;
|
||
|
}
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
err = SSLSetIOFuncs(BACKEND->ssl_ctx, SocketRead, SocketWrite);
|
||
10 years ago
|
if(err != noErr) {
|
||
|
failf(data, "SSL: SSLSetIOFuncs() failed: OSStatus %d", err);
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
|
|
||
|
/* pass the raw socket into the SSL layers */
|
||
|
/* We need to store the FD in a constant memory address, because
|
||
|
* SSLSetConnection() will not copy that address. I've found that
|
||
|
* conn->sock[sockindex] may change on its own. */
|
||
7 years ago
|
BACKEND->ssl_sockfd = sockfd;
|
||
|
err = SSLSetConnection(BACKEND->ssl_ctx, connssl);
|
||
10 years ago
|
if(err != noErr) {
|
||
|
failf(data, "SSL: SSLSetConnection() failed: %d", err);
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
|
|
||
|
connssl->connecting_state = ssl_connect_2;
|
||
|
return CURLE_OK;
|
||
|
}
|
||
|
|
||
|
static long pem_to_der(const char *in, unsigned char **out, size_t *outlen)
|
||
|
{
|
||
|
char *sep_start, *sep_end, *cert_start, *cert_end;
|
||
|
size_t i, j, err;
|
||
|
size_t len;
|
||
|
unsigned char *b64;
|
||
|
|
||
|
/* Jump through the separators at the beginning of the certificate. */
|
||
|
sep_start = strstr(in, "-----");
|
||
|
if(sep_start == NULL)
|
||
|
return 0;
|
||
|
cert_start = strstr(sep_start + 1, "-----");
|
||
|
if(cert_start == NULL)
|
||
|
return -1;
|
||
|
|
||
|
cert_start += 5;
|
||
|
|
||
|
/* Find separator after the end of the certificate. */
|
||
|
cert_end = strstr(cert_start, "-----");
|
||
|
if(cert_end == NULL)
|
||
|
return -1;
|
||
|
|
||
|
sep_end = strstr(cert_end + 1, "-----");
|
||
|
if(sep_end == NULL)
|
||
|
return -1;
|
||
|
sep_end += 5;
|
||
|
|
||
|
len = cert_end - cert_start;
|
||
|
b64 = malloc(len + 1);
|
||
|
if(!b64)
|
||
|
return -1;
|
||
|
|
||
|
/* Create base64 string without linefeeds. */
|
||
|
for(i = 0, j = 0; i < len; i++) {
|
||
|
if(cert_start[i] != '\r' && cert_start[i] != '\n')
|
||
|
b64[j++] = cert_start[i];
|
||
|
}
|
||
|
b64[j] = '\0';
|
||
|
|
||
|
err = Curl_base64_decode((const char *)b64, out, outlen);
|
||
|
free(b64);
|
||
|
if(err) {
|
||
|
free(*out);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
return sep_end - in;
|
||
|
}
|
||
|
|
||
|
static int read_cert(const char *file, unsigned char **out, size_t *outlen)
|
||
|
{
|
||
|
int fd;
|
||
|
ssize_t n, len = 0, cap = 512;
|
||
7 years ago
|
unsigned char buf[512], *data;
|
||
10 years ago
|
|
||
|
fd = open(file, 0);
|
||
|
if(fd < 0)
|
||
|
return -1;
|
||
|
|
||
|
data = malloc(cap);
|
||
|
if(!data) {
|
||
|
close(fd);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
for(;;) {
|
||
|
n = read(fd, buf, sizeof(buf));
|
||
|
if(n < 0) {
|
||
|
close(fd);
|
||
|
free(data);
|
||
|
return -1;
|
||
|
}
|
||
|
else if(n == 0) {
|
||
|
close(fd);
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
if(len + n >= cap) {
|
||
|
cap *= 2;
|
||
6 years ago
|
data = Curl_saferealloc(data, cap);
|
||
10 years ago
|
if(!data) {
|
||
|
close(fd);
|
||
|
return -1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
memcpy(data + len, buf, n);
|
||
|
len += n;
|
||
|
}
|
||
|
data[len] = '\0';
|
||
|
|
||
|
*out = data;
|
||
|
*outlen = len;
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
8 years ago
|
static int append_cert_to_array(struct Curl_easy *data,
|
||
10 years ago
|
unsigned char *buf, size_t buflen,
|
||
|
CFMutableArrayRef array)
|
||
|
{
|
||
|
CFDataRef certdata = CFDataCreate(kCFAllocatorDefault, buf, buflen);
|
||
7 years ago
|
char *certp;
|
||
|
CURLcode result;
|
||
10 years ago
|
if(!certdata) {
|
||
|
failf(data, "SSL: failed to allocate array for CA certificate");
|
||
|
return CURLE_OUT_OF_MEMORY;
|
||
|
}
|
||
|
|
||
|
SecCertificateRef cacert =
|
||
|
SecCertificateCreateWithData(kCFAllocatorDefault, certdata);
|
||
|
CFRelease(certdata);
|
||
|
if(!cacert) {
|
||
|
failf(data, "SSL: failed to create SecCertificate from CA certificate");
|
||
6 years ago
|
return CURLE_SSL_CACERT_BADFILE;
|
||
10 years ago
|
}
|
||
|
|
||
|
/* Check if cacert is valid. */
|
||
7 years ago
|
result = CopyCertSubject(data, cacert, &certp);
|
||
6 years ago
|
switch(result) {
|
||
|
case CURLE_OK:
|
||
|
break;
|
||
|
case CURLE_PEER_FAILED_VERIFICATION:
|
||
|
return CURLE_SSL_CACERT_BADFILE;
|
||
|
case CURLE_OUT_OF_MEMORY:
|
||
|
default:
|
||
|
return result;
|
||
|
}
|
||
7 years ago
|
free(certp);
|
||
10 years ago
|
|
||
|
CFArrayAppendValue(array, cacert);
|
||
|
CFRelease(cacert);
|
||
|
|
||
|
return CURLE_OK;
|
||
|
}
|
||
|
|
||
8 years ago
|
static int verify_cert(const char *cafile, struct Curl_easy *data,
|
||
10 years ago
|
SSLContextRef ctx)
|
||
|
{
|
||
|
int n = 0, rc;
|
||
|
long res;
|
||
|
unsigned char *certbuf, *der;
|
||
|
size_t buflen, derlen, offset = 0;
|
||
|
|
||
|
if(read_cert(cafile, &certbuf, &buflen) < 0) {
|
||
|
failf(data, "SSL: failed to read or invalid CA certificate");
|
||
6 years ago
|
return CURLE_SSL_CACERT_BADFILE;
|
||
10 years ago
|
}
|
||
|
|
||
|
/*
|
||
|
* Certbuf now contains the contents of the certificate file, which can be
|
||
|
* - a single DER certificate,
|
||
|
* - a single PEM certificate or
|
||
|
* - a bunch of PEM certificates (certificate bundle).
|
||
|
*
|
||
|
* Go through certbuf, and convert any PEM certificate in it into DER
|
||
|
* format.
|
||
|
*/
|
||
|
CFMutableArrayRef array = CFArrayCreateMutable(kCFAllocatorDefault, 0,
|
||
|
&kCFTypeArrayCallBacks);
|
||
|
if(array == NULL) {
|
||
|
free(certbuf);
|
||
|
failf(data, "SSL: out of memory creating CA certificate array");
|
||
|
return CURLE_OUT_OF_MEMORY;
|
||
|
}
|
||
|
|
||
|
while(offset < buflen) {
|
||
|
n++;
|
||
|
|
||
|
/*
|
||
|
* Check if the certificate is in PEM format, and convert it to DER. If
|
||
|
* this fails, we assume the certificate is in DER format.
|
||
|
*/
|
||
|
res = pem_to_der((const char *)certbuf + offset, &der, &derlen);
|
||
|
if(res < 0) {
|
||
|
free(certbuf);
|
||
|
CFRelease(array);
|
||
|
failf(data, "SSL: invalid CA certificate #%d (offset %d) in bundle",
|
||
|
n, offset);
|
||
6 years ago
|
return CURLE_SSL_CACERT_BADFILE;
|
||
10 years ago
|
}
|
||
|
offset += res;
|
||
|
|
||
|
if(res == 0 && offset == 0) {
|
||
|
/* This is not a PEM file, probably a certificate in DER format. */
|
||
|
rc = append_cert_to_array(data, certbuf, buflen, array);
|
||
|
free(certbuf);
|
||
|
if(rc != CURLE_OK) {
|
||
|
CFRelease(array);
|
||
|
return rc;
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
else if(res == 0) {
|
||
|
/* No more certificates in the bundle. */
|
||
|
free(certbuf);
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
rc = append_cert_to_array(data, der, derlen, array);
|
||
|
free(der);
|
||
|
if(rc != CURLE_OK) {
|
||
|
free(certbuf);
|
||
|
CFRelease(array);
|
||
|
return rc;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
SecTrustRef trust;
|
||
|
OSStatus ret = SSLCopyPeerTrust(ctx, &trust);
|
||
|
if(trust == NULL) {
|
||
|
failf(data, "SSL: error getting certificate chain");
|
||
|
CFRelease(array);
|
||
6 years ago
|
return CURLE_PEER_FAILED_VERIFICATION;
|
||
10 years ago
|
}
|
||
|
else if(ret != noErr) {
|
||
|
CFRelease(array);
|
||
6 years ago
|
failf(data, "SSLCopyPeerTrust() returned error %d", ret);
|
||
|
return CURLE_PEER_FAILED_VERIFICATION;
|
||
10 years ago
|
}
|
||
|
|
||
|
ret = SecTrustSetAnchorCertificates(trust, array);
|
||
|
if(ret != noErr) {
|
||
6 years ago
|
CFRelease(array);
|
||
10 years ago
|
CFRelease(trust);
|
||
6 years ago
|
failf(data, "SecTrustSetAnchorCertificates() returned error %d", ret);
|
||
|
return CURLE_PEER_FAILED_VERIFICATION;
|
||
10 years ago
|
}
|
||
|
ret = SecTrustSetAnchorCertificatesOnly(trust, true);
|
||
|
if(ret != noErr) {
|
||
6 years ago
|
CFRelease(array);
|
||
10 years ago
|
CFRelease(trust);
|
||
6 years ago
|
failf(data, "SecTrustSetAnchorCertificatesOnly() returned error %d", ret);
|
||
|
return CURLE_PEER_FAILED_VERIFICATION;
|
||
10 years ago
|
}
|
||
|
|
||
|
SecTrustResultType trust_eval = 0;
|
||
|
ret = SecTrustEvaluate(trust, &trust_eval);
|
||
|
CFRelease(array);
|
||
|
CFRelease(trust);
|
||
|
if(ret != noErr) {
|
||
6 years ago
|
failf(data, "SecTrustEvaluate() returned error %d", ret);
|
||
|
return CURLE_PEER_FAILED_VERIFICATION;
|
||
10 years ago
|
}
|
||
|
|
||
8 years ago
|
switch(trust_eval) {
|
||
10 years ago
|
case kSecTrustResultUnspecified:
|
||
|
case kSecTrustResultProceed:
|
||
|
return CURLE_OK;
|
||
|
|
||
|
case kSecTrustResultRecoverableTrustFailure:
|
||
|
case kSecTrustResultDeny:
|
||
|
default:
|
||
|
failf(data, "SSL: certificate verification failed (result: %d)",
|
||
|
trust_eval);
|
||
|
return CURLE_PEER_FAILED_VERIFICATION;
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
#ifdef SECTRANSP_PINNEDPUBKEY
|
||
7 years ago
|
static CURLcode pkp_pin_peer_pubkey(struct Curl_easy *data,
|
||
8 years ago
|
SSLContextRef ctx,
|
||
|
const char *pinnedpubkey)
|
||
|
{ /* Scratch */
|
||
|
size_t pubkeylen, realpubkeylen, spkiHeaderLength = 24;
|
||
7 years ago
|
unsigned char *pubkey = NULL, *realpubkey = NULL;
|
||
|
const unsigned char *spkiHeader = NULL;
|
||
8 years ago
|
CFDataRef publicKeyBits = NULL;
|
||
|
|
||
|
/* Result is returned to caller */
|
||
|
CURLcode result = CURLE_SSL_PINNEDPUBKEYNOTMATCH;
|
||
|
|
||
|
/* if a path wasn't specified, don't pin */
|
||
|
if(!pinnedpubkey)
|
||
|
return CURLE_OK;
|
||
|
|
||
|
|
||
|
if(!ctx)
|
||
|
return result;
|
||
|
|
||
|
do {
|
||
|
SecTrustRef trust;
|
||
|
OSStatus ret = SSLCopyPeerTrust(ctx, &trust);
|
||
|
if(ret != noErr || trust == NULL)
|
||
|
break;
|
||
|
|
||
|
SecKeyRef keyRef = SecTrustCopyPublicKey(trust);
|
||
|
CFRelease(trust);
|
||
|
if(keyRef == NULL)
|
||
|
break;
|
||
|
|
||
5 years ago
|
#ifdef SECTRANSP_PINNEDPUBKEY_V1
|
||
8 years ago
|
|
||
|
publicKeyBits = SecKeyCopyExternalRepresentation(keyRef, NULL);
|
||
|
CFRelease(keyRef);
|
||
|
if(publicKeyBits == NULL)
|
||
|
break;
|
||
|
|
||
5 years ago
|
#elif SECTRANSP_PINNEDPUBKEY_V2
|
||
8 years ago
|
|
||
|
OSStatus success = SecItemExport(keyRef, kSecFormatOpenSSL, 0, NULL,
|
||
|
&publicKeyBits);
|
||
|
CFRelease(keyRef);
|
||
|
if(success != errSecSuccess || publicKeyBits == NULL)
|
||
|
break;
|
||
|
|
||
5 years ago
|
#endif /* SECTRANSP_PINNEDPUBKEY_V2 */
|
||
8 years ago
|
|
||
|
pubkeylen = CFDataGetLength(publicKeyBits);
|
||
7 years ago
|
pubkey = (unsigned char *)CFDataGetBytePtr(publicKeyBits);
|
||
8 years ago
|
|
||
|
switch(pubkeylen) {
|
||
|
case 526:
|
||
|
/* 4096 bit RSA pubkeylen == 526 */
|
||
|
spkiHeader = rsa4096SpkiHeader;
|
||
|
break;
|
||
|
case 270:
|
||
|
/* 2048 bit RSA pubkeylen == 270 */
|
||
|
spkiHeader = rsa2048SpkiHeader;
|
||
|
break;
|
||
5 years ago
|
#ifdef SECTRANSP_PINNEDPUBKEY_V1
|
||
8 years ago
|
case 65:
|
||
|
/* ecDSA secp256r1 pubkeylen == 65 */
|
||
|
spkiHeader = ecDsaSecp256r1SpkiHeader;
|
||
|
spkiHeaderLength = 26;
|
||
|
break;
|
||
|
case 97:
|
||
|
/* ecDSA secp384r1 pubkeylen == 97 */
|
||
|
spkiHeader = ecDsaSecp384r1SpkiHeader;
|
||
|
spkiHeaderLength = 23;
|
||
|
break;
|
||
|
default:
|
||
|
infof(data, "SSL: unhandled public key length: %d\n", pubkeylen);
|
||
5 years ago
|
#elif SECTRANSP_PINNEDPUBKEY_V2
|
||
8 years ago
|
default:
|
||
|
/* ecDSA secp256r1 pubkeylen == 91 header already included?
|
||
|
* ecDSA secp384r1 header already included too
|
||
|
* we assume rest of algorithms do same, so do nothing
|
||
|
*/
|
||
|
result = Curl_pin_peer_pubkey(data, pinnedpubkey, pubkey,
|
||
|
pubkeylen);
|
||
5 years ago
|
#endif /* SECTRANSP_PINNEDPUBKEY_V2 */
|
||
8 years ago
|
continue; /* break from loop */
|
||
|
}
|
||
|
|
||
|
realpubkeylen = pubkeylen + spkiHeaderLength;
|
||
|
realpubkey = malloc(realpubkeylen);
|
||
|
if(!realpubkey)
|
||
|
break;
|
||
|
|
||
|
memcpy(realpubkey, spkiHeader, spkiHeaderLength);
|
||
|
memcpy(realpubkey + spkiHeaderLength, pubkey, pubkeylen);
|
||
|
|
||
|
result = Curl_pin_peer_pubkey(data, pinnedpubkey, realpubkey,
|
||
|
realpubkeylen);
|
||
|
|
||
|
} while(0);
|
||
|
|
||
|
Curl_safefree(realpubkey);
|
||
|
if(publicKeyBits != NULL)
|
||
|
CFRelease(publicKeyBits);
|
||
|
|
||
|
return result;
|
||
|
}
|
||
5 years ago
|
#endif /* SECTRANSP_PINNEDPUBKEY */
|
||
8 years ago
|
|
||
10 years ago
|
static CURLcode
|
||
5 years ago
|
sectransp_connect_step2(struct connectdata *conn, int sockindex)
|
||
10 years ago
|
{
|
||
8 years ago
|
struct Curl_easy *data = conn->data;
|
||
10 years ago
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||
|
OSStatus err;
|
||
|
SSLCipherSuite cipher;
|
||
|
SSLProtocol protocol = 0;
|
||
8 years ago
|
const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
|
||
|
conn->host.name;
|
||
10 years ago
|
|
||
|
DEBUGASSERT(ssl_connect_2 == connssl->connecting_state
|
||
|
|| ssl_connect_2_reading == connssl->connecting_state
|
||
|
|| ssl_connect_2_writing == connssl->connecting_state);
|
||
|
|
||
|
/* Here goes nothing: */
|
||
7 years ago
|
err = SSLHandshake(BACKEND->ssl_ctx);
|
||
10 years ago
|
|
||
|
if(err != noErr) {
|
||
8 years ago
|
switch(err) {
|
||
10 years ago
|
case errSSLWouldBlock: /* they're not done with us yet */
|
||
7 years ago
|
connssl->connecting_state = BACKEND->ssl_direction ?
|
||
10 years ago
|
ssl_connect_2_writing : ssl_connect_2_reading;
|
||
|
return CURLE_OK;
|
||
|
|
||
|
/* The below is errSSLServerAuthCompleted; it's not defined in
|
||
|
Leopard's headers */
|
||
|
case -9841:
|
||
8 years ago
|
if(SSL_CONN_CONFIG(CAfile) && SSL_CONN_CONFIG(verifypeer)) {
|
||
|
int res = verify_cert(SSL_CONN_CONFIG(CAfile), data,
|
||
7 years ago
|
BACKEND->ssl_ctx);
|
||
10 years ago
|
if(res != CURLE_OK)
|
||
|
return res;
|
||
|
}
|
||
|
/* the documentation says we need to call SSLHandshake() again */
|
||
5 years ago
|
return sectransp_connect_step2(conn, sockindex);
|
||
10 years ago
|
|
||
6 years ago
|
/* Problem with encrypt / decrypt */
|
||
|
case errSSLPeerDecodeError:
|
||
|
failf(data, "Decode failed");
|
||
|
break;
|
||
|
case errSSLDecryptionFail:
|
||
|
case errSSLPeerDecryptionFail:
|
||
|
failf(data, "Decryption failed");
|
||
|
break;
|
||
|
case errSSLPeerDecryptError:
|
||
|
failf(data, "A decryption error occurred");
|
||
|
break;
|
||
|
case errSSLBadCipherSuite:
|
||
|
failf(data, "A bad SSL cipher suite was encountered");
|
||
|
break;
|
||
|
case errSSLCrypto:
|
||
|
failf(data, "An underlying cryptographic error was encountered");
|
||
|
break;
|
||
|
#if CURL_BUILD_MAC_10_11 || CURL_BUILD_IOS_9
|
||
|
case errSSLWeakPeerEphemeralDHKey:
|
||
|
failf(data, "Indicates a weak ephemeral Diffie-Hellman key");
|
||
|
break;
|
||
|
#endif
|
||
|
|
||
|
/* Problem with the message record validation */
|
||
|
case errSSLBadRecordMac:
|
||
|
case errSSLPeerBadRecordMac:
|
||
|
failf(data, "A record with a bad message authentication code (MAC) "
|
||
|
"was encountered");
|
||
|
break;
|
||
|
case errSSLRecordOverflow:
|
||
|
case errSSLPeerRecordOverflow:
|
||
|
failf(data, "A record overflow occurred");
|
||
|
break;
|
||
|
|
||
|
/* Problem with zlib decompression */
|
||
|
case errSSLPeerDecompressFail:
|
||
|
failf(data, "Decompression failed");
|
||
|
break;
|
||
|
|
||
|
/* Problem with access */
|
||
|
case errSSLPeerAccessDenied:
|
||
|
failf(data, "Access was denied");
|
||
|
break;
|
||
|
case errSSLPeerInsufficientSecurity:
|
||
|
failf(data, "There is insufficient security for this operation");
|
||
|
break;
|
||
|
|
||
10 years ago
|
/* These are all certificate problems with the server: */
|
||
|
case errSSLXCertChainInvalid:
|
||
|
failf(data, "SSL certificate problem: Invalid certificate chain");
|
||
5 years ago
|
return CURLE_PEER_FAILED_VERIFICATION;
|
||
10 years ago
|
case errSSLUnknownRootCert:
|
||
|
failf(data, "SSL certificate problem: Untrusted root certificate");
|
||
5 years ago
|
return CURLE_PEER_FAILED_VERIFICATION;
|
||
10 years ago
|
case errSSLNoRootCert:
|
||
|
failf(data, "SSL certificate problem: No root certificate");
|
||
5 years ago
|
return CURLE_PEER_FAILED_VERIFICATION;
|
||
6 years ago
|
case errSSLCertNotYetValid:
|
||
|
failf(data, "SSL certificate problem: The certificate chain had a "
|
||
|
"certificate that is not yet valid");
|
||
5 years ago
|
return CURLE_PEER_FAILED_VERIFICATION;
|
||
10 years ago
|
case errSSLCertExpired:
|
||
6 years ago
|
case errSSLPeerCertExpired:
|
||
10 years ago
|
failf(data, "SSL certificate problem: Certificate chain had an "
|
||
|
"expired certificate");
|
||
5 years ago
|
return CURLE_PEER_FAILED_VERIFICATION;
|
||
10 years ago
|
case errSSLBadCert:
|
||
6 years ago
|
case errSSLPeerBadCert:
|
||
10 years ago
|
failf(data, "SSL certificate problem: Couldn't understand the server "
|
||
|
"certificate format");
|
||
5 years ago
|
return CURLE_PEER_FAILED_VERIFICATION;
|
||
6 years ago
|
case errSSLPeerUnsupportedCert:
|
||
|
failf(data, "SSL certificate problem: An unsupported certificate "
|
||
|
"format was encountered");
|
||
5 years ago
|
return CURLE_PEER_FAILED_VERIFICATION;
|
||
6 years ago
|
case errSSLPeerCertRevoked:
|
||
|
failf(data, "SSL certificate problem: The certificate was revoked");
|
||
5 years ago
|
return CURLE_PEER_FAILED_VERIFICATION;
|
||
6 years ago
|
case errSSLPeerCertUnknown:
|
||
|
failf(data, "SSL certificate problem: The certificate is unknown");
|
||
5 years ago
|
return CURLE_PEER_FAILED_VERIFICATION;
|
||
10 years ago
|
|
||
|
/* These are all certificate problems with the client: */
|
||
|
case errSecAuthFailed:
|
||
|
failf(data, "SSL authentication failed");
|
||
6 years ago
|
break;
|
||
10 years ago
|
case errSSLPeerHandshakeFail:
|
||
|
failf(data, "SSL peer handshake failed, the server most likely "
|
||
|
"requires a client certificate to connect");
|
||
6 years ago
|
break;
|
||
10 years ago
|
case errSSLPeerUnknownCA:
|
||
|
failf(data, "SSL server rejected the client certificate due to "
|
||
|
"the certificate being signed by an unknown certificate "
|
||
|
"authority");
|
||
6 years ago
|
break;
|
||
10 years ago
|
|
||
|
/* This error is raised if the server's cert didn't match the server's
|
||
|
host name: */
|
||
|
case errSSLHostNameMismatch:
|
||
|
failf(data, "SSL certificate peer verification failed, the "
|
||
|
"certificate did not match \"%s\"\n", conn->host.dispname);
|
||
|
return CURLE_PEER_FAILED_VERIFICATION;
|
||
|
|
||
6 years ago
|
/* Problem with SSL / TLS negotiation */
|
||
|
case errSSLNegotiation:
|
||
|
failf(data, "Could not negotiate an SSL cipher suite with the server");
|
||
|
break;
|
||
|
case errSSLBadConfiguration:
|
||
|
failf(data, "A configuration error occurred");
|
||
|
break;
|
||
|
case errSSLProtocol:
|
||
|
failf(data, "SSL protocol error");
|
||
|
break;
|
||
|
case errSSLPeerProtocolVersion:
|
||
|
failf(data, "A bad protocol version was encountered");
|
||
|
break;
|
||
|
case errSSLPeerNoRenegotiation:
|
||
|
failf(data, "No renegotiation is allowed");
|
||
|
break;
|
||
|
|
||
10 years ago
|
/* Generic handshake errors: */
|
||
|
case errSSLConnectionRefused:
|
||
|
failf(data, "Server dropped the connection during the SSL handshake");
|
||
6 years ago
|
break;
|
||
10 years ago
|
case errSSLClosedAbort:
|
||
|
failf(data, "Server aborted the SSL handshake");
|
||
6 years ago
|
break;
|
||
|
case errSSLClosedGraceful:
|
||
|
failf(data, "The connection closed gracefully");
|
||
|
break;
|
||
|
case errSSLClosedNoNotify:
|
||
|
failf(data, "The server closed the session with no notification");
|
||
|
break;
|
||
10 years ago
|
/* Sometimes paramErr happens with buggy ciphers: */
|
||
6 years ago
|
case paramErr:
|
||
|
case errSSLInternal:
|
||
|
case errSSLPeerInternalError:
|
||
10 years ago
|
failf(data, "Internal SSL engine error encountered during the "
|
||
|
"SSL handshake");
|
||
6 years ago
|
break;
|
||
10 years ago
|
case errSSLFatalAlert:
|
||
|
failf(data, "Fatal SSL engine error encountered during the SSL "
|
||
|
"handshake");
|
||
6 years ago
|
break;
|
||
|
/* Unclassified error */
|
||
|
case errSSLBufferOverflow:
|
||
|
failf(data, "An insufficient buffer was provided");
|
||
|
break;
|
||
|
case errSSLIllegalParam:
|
||
|
failf(data, "An illegal parameter was encountered");
|
||
|
break;
|
||
|
case errSSLModuleAttach:
|
||
|
failf(data, "Module attach failure");
|
||
|
break;
|
||
|
case errSSLSessionNotFound:
|
||
|
failf(data, "An attempt to restore an unknown session failed");
|
||
|
break;
|
||
|
case errSSLPeerExportRestriction:
|
||
|
failf(data, "An export restriction occurred");
|
||
|
break;
|
||
|
case errSSLPeerUserCancelled:
|
||
|
failf(data, "The user canceled the operation");
|
||
|
break;
|
||
|
case errSSLPeerUnexpectedMsg:
|
||
|
failf(data, "Peer rejected unexpected message");
|
||
|
break;
|
||
|
#if CURL_BUILD_MAC_10_11 || CURL_BUILD_IOS_9
|
||
|
/* Treaing non-fatal error as fatal like before */
|
||
|
case errSSLClientHelloReceived:
|
||
|
failf(data, "A non-fatal result for providing a server name "
|
||
|
"indication");
|
||
|
break;
|
||
|
#endif
|
||
|
|
||
|
/* Error codes defined in the enum but should never be returned.
|
||
|
We list them here just in case. */
|
||
|
#if CURL_BUILD_MAC_10_6
|
||
|
/* Only returned when kSSLSessionOptionBreakOnCertRequested is set */
|
||
|
case errSSLClientCertRequested:
|
||
|
failf(data, "The server has requested a client certificate");
|
||
|
break;
|
||
|
#endif
|
||
|
#if CURL_BUILD_MAC_10_9
|
||
|
/* Alias for errSSLLast, end of error range */
|
||
|
case errSSLUnexpectedRecord:
|
||
|
failf(data, "Unexpected (skipped) record in DTLS");
|
||
|
break;
|
||
|
#endif
|
||
10 years ago
|
default:
|
||
6 years ago
|
/* May also return codes listed in Security Framework Result Codes */
|
||
10 years ago
|
failf(data, "Unknown SSL protocol error in connection to %s:%d",
|
||
8 years ago
|
hostname, err);
|
||
6 years ago
|
break;
|
||
10 years ago
|
}
|
||
6 years ago
|
return CURLE_SSL_CONNECT_ERROR;
|
||
10 years ago
|
}
|
||
|
else {
|
||
|
/* we have been connected fine, we're not waiting for anything else. */
|
||
|
connssl->connecting_state = ssl_connect_3;
|
||
|
|
||
5 years ago
|
#ifdef SECTRANSP_PINNEDPUBKEY
|
||
8 years ago
|
if(data->set.str[STRING_SSL_PINNEDPUBLICKEY_ORIG]) {
|
||
7 years ago
|
CURLcode result = pkp_pin_peer_pubkey(data, BACKEND->ssl_ctx,
|
||
8 years ago
|
data->set.str[STRING_SSL_PINNEDPUBLICKEY_ORIG]);
|
||
|
if(result) {
|
||
|
failf(data, "SSL: public key does not match pinned public key!");
|
||
|
return result;
|
||
|
}
|
||
|
}
|
||
5 years ago
|
#endif /* SECTRANSP_PINNEDPUBKEY */
|
||
8 years ago
|
|
||
10 years ago
|
/* Informational message */
|
||
7 years ago
|
(void)SSLGetNegotiatedCipher(BACKEND->ssl_ctx, &cipher);
|
||
|
(void)SSLGetNegotiatedProtocolVersion(BACKEND->ssl_ctx, &protocol);
|
||
8 years ago
|
switch(protocol) {
|
||
10 years ago
|
case kSSLProtocol2:
|
||
|
infof(data, "SSL 2.0 connection using %s\n",
|
||
|
SSLCipherNameForNumber(cipher));
|
||
|
break;
|
||
|
case kSSLProtocol3:
|
||
|
infof(data, "SSL 3.0 connection using %s\n",
|
||
|
SSLCipherNameForNumber(cipher));
|
||
|
break;
|
||
|
case kTLSProtocol1:
|
||
|
infof(data, "TLS 1.0 connection using %s\n",
|
||
|
TLSCipherNameForNumber(cipher));
|
||
|
break;
|
||
|
#if CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS
|
||
|
case kTLSProtocol11:
|
||
|
infof(data, "TLS 1.1 connection using %s\n",
|
||
|
TLSCipherNameForNumber(cipher));
|
||
|
break;
|
||
|
case kTLSProtocol12:
|
||
|
infof(data, "TLS 1.2 connection using %s\n",
|
||
|
TLSCipherNameForNumber(cipher));
|
||
|
break;
|
||
7 years ago
|
#endif /* CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS */
|
||
|
#if CURL_BUILD_MAC_10_13 || CURL_BUILD_IOS_11
|
||
|
case kTLSProtocol13:
|
||
|
infof(data, "TLS 1.3 connection using %s\n",
|
||
|
TLSCipherNameForNumber(cipher));
|
||
|
break;
|
||
|
#endif /* CURL_BUILD_MAC_10_13 || CURL_BUILD_IOS_11 */
|
||
10 years ago
|
default:
|
||
|
infof(data, "Unknown protocol connection\n");
|
||
|
break;
|
||
|
}
|
||
|
|
||
6 years ago
|
#if(CURL_BUILD_MAC_10_13 || CURL_BUILD_IOS_11) && HAVE_BUILTIN_AVAILABLE == 1
|
||
|
if(conn->bits.tls_enable_alpn) {
|
||
5 years ago
|
if(__builtin_available(macOS 10.13.4, iOS 11, tvOS 11, *)) {
|
||
6 years ago
|
CFArrayRef alpnArr = NULL;
|
||
|
CFStringRef chosenProtocol = NULL;
|
||
|
err = SSLCopyALPNProtocols(BACKEND->ssl_ctx, &alpnArr);
|
||
|
|
||
|
if(err == noErr && alpnArr && CFArrayGetCount(alpnArr) >= 1)
|
||
|
chosenProtocol = CFArrayGetValueAtIndex(alpnArr, 0);
|
||
|
|
||
|
#ifdef USE_NGHTTP2
|
||
|
if(chosenProtocol &&
|
||
|
!CFStringCompare(chosenProtocol, CFSTR(NGHTTP2_PROTO_VERSION_ID),
|
||
|
0)) {
|
||
|
conn->negnpn = CURL_HTTP_VERSION_2;
|
||
|
}
|
||
|
else
|
||
|
#endif
|
||
|
if(chosenProtocol &&
|
||
|
!CFStringCompare(chosenProtocol, CFSTR(ALPN_HTTP_1_1), 0)) {
|
||
|
conn->negnpn = CURL_HTTP_VERSION_1_1;
|
||
|
}
|
||
|
else
|
||
|
infof(data, "ALPN, server did not agree to a protocol\n");
|
||
|
|
||
5 years ago
|
Curl_multiuse_state(conn, conn->negnpn == CURL_HTTP_VERSION_2 ?
|
||
|
BUNDLE_MULTIPLEX : BUNDLE_NO_MULTIUSE);
|
||
|
|
||
6 years ago
|
/* chosenProtocol is a reference to the string within alpnArr
|
||
|
and doesn't need to be freed separately */
|
||
|
if(alpnArr)
|
||
|
CFRelease(alpnArr);
|
||
|
}
|
||
|
}
|
||
|
#endif
|
||
|
|
||
10 years ago
|
return CURLE_OK;
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
#ifndef CURL_DISABLE_VERBOSE_STRINGS
|
||
|
/* This should be called during step3 of the connection at the earliest */
|
||
|
static void
|
||
|
show_verbose_server_cert(struct connectdata *conn,
|
||
|
int sockindex)
|
||
10 years ago
|
{
|
||
8 years ago
|
struct Curl_easy *data = conn->data;
|
||
10 years ago
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||
|
CFArrayRef server_certs = NULL;
|
||
|
SecCertificateRef server_cert;
|
||
|
OSStatus err;
|
||
|
CFIndex i, count;
|
||
|
SecTrustRef trust = NULL;
|
||
|
|
||
7 years ago
|
if(!BACKEND->ssl_ctx)
|
||
8 years ago
|
return;
|
||
|
|
||
10 years ago
|
#if CURL_BUILD_MAC_10_7 || CURL_BUILD_IOS
|
||
|
#if CURL_BUILD_IOS
|
||
|
#pragma unused(server_certs)
|
||
7 years ago
|
err = SSLCopyPeerTrust(BACKEND->ssl_ctx, &trust);
|
||
10 years ago
|
/* For some reason, SSLCopyPeerTrust() can return noErr and yet return
|
||
|
a null trust, so be on guard for that: */
|
||
|
if(err == noErr && trust) {
|
||
|
count = SecTrustGetCertificateCount(trust);
|
||
|
for(i = 0L ; i < count ; i++) {
|
||
7 years ago
|
CURLcode result;
|
||
|
char *certp;
|
||
10 years ago
|
server_cert = SecTrustGetCertificateAtIndex(trust, i);
|
||
7 years ago
|
result = CopyCertSubject(data, server_cert, &certp);
|
||
|
if(!result) {
|
||
|
infof(data, "Server certificate: %s\n", certp);
|
||
|
free(certp);
|
||
10 years ago
|
}
|
||
|
}
|
||
|
CFRelease(trust);
|
||
|
}
|
||
|
#else
|
||
|
/* SSLCopyPeerCertificates() is deprecated as of Mountain Lion.
|
||
|
The function SecTrustGetCertificateAtIndex() is officially present
|
||
|
in Lion, but it is unfortunately also present in Snow Leopard as
|
||
|
private API and doesn't work as expected. So we have to look for
|
||
|
a different symbol to make sure this code is only executed under
|
||
|
Lion or later. */
|
||
|
if(SecTrustEvaluateAsync != NULL) {
|
||
|
#pragma unused(server_certs)
|
||
7 years ago
|
err = SSLCopyPeerTrust(BACKEND->ssl_ctx, &trust);
|
||
10 years ago
|
/* For some reason, SSLCopyPeerTrust() can return noErr and yet return
|
||
|
a null trust, so be on guard for that: */
|
||
|
if(err == noErr && trust) {
|
||
|
count = SecTrustGetCertificateCount(trust);
|
||
|
for(i = 0L ; i < count ; i++) {
|
||
7 years ago
|
char *certp;
|
||
|
CURLcode result;
|
||
10 years ago
|
server_cert = SecTrustGetCertificateAtIndex(trust, i);
|
||
7 years ago
|
result = CopyCertSubject(data, server_cert, &certp);
|
||
|
if(!result) {
|
||
|
infof(data, "Server certificate: %s\n", certp);
|
||
|
free(certp);
|
||
10 years ago
|
}
|
||
|
}
|
||
|
CFRelease(trust);
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
#if CURL_SUPPORT_MAC_10_8
|
||
7 years ago
|
err = SSLCopyPeerCertificates(BACKEND->ssl_ctx, &server_certs);
|
||
10 years ago
|
/* Just in case SSLCopyPeerCertificates() returns null too... */
|
||
|
if(err == noErr && server_certs) {
|
||
|
count = CFArrayGetCount(server_certs);
|
||
|
for(i = 0L ; i < count ; i++) {
|
||
7 years ago
|
char *certp;
|
||
|
CURLcode result;
|
||
10 years ago
|
server_cert = (SecCertificateRef)CFArrayGetValueAtIndex(server_certs,
|
||
|
i);
|
||
7 years ago
|
result = CopyCertSubject(data, server_cert, &certp);
|
||
|
if(!result) {
|
||
|
infof(data, "Server certificate: %s\n", certp);
|
||
|
free(certp);
|
||
10 years ago
|
}
|
||
|
}
|
||
|
CFRelease(server_certs);
|
||
|
}
|
||
|
#endif /* CURL_SUPPORT_MAC_10_8 */
|
||
|
}
|
||
|
#endif /* CURL_BUILD_IOS */
|
||
|
#else
|
||
|
#pragma unused(trust)
|
||
7 years ago
|
err = SSLCopyPeerCertificates(BACKEND->ssl_ctx, &server_certs);
|
||
10 years ago
|
if(err == noErr) {
|
||
|
count = CFArrayGetCount(server_certs);
|
||
|
for(i = 0L ; i < count ; i++) {
|
||
7 years ago
|
CURLcode result;
|
||
|
char *certp;
|
||
10 years ago
|
server_cert = (SecCertificateRef)CFArrayGetValueAtIndex(server_certs, i);
|
||
7 years ago
|
result = CopyCertSubject(data, server_cert, &certp);
|
||
|
if(!result) {
|
||
|
infof(data, "Server certificate: %s\n", certp);
|
||
|
free(certp);
|
||
10 years ago
|
}
|
||
|
}
|
||
|
CFRelease(server_certs);
|
||
|
}
|
||
|
#endif /* CURL_BUILD_MAC_10_7 || CURL_BUILD_IOS */
|
||
8 years ago
|
}
|
||
|
#endif /* !CURL_DISABLE_VERBOSE_STRINGS */
|
||
|
|
||
|
static CURLcode
|
||
5 years ago
|
sectransp_connect_step3(struct connectdata *conn,
|
||
8 years ago
|
int sockindex)
|
||
|
{
|
||
|
struct Curl_easy *data = conn->data;
|
||
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||
|
|
||
|
/* There is no step 3!
|
||
|
* Well, okay, if verbose mode is on, let's print the details of the
|
||
|
* server certificates. */
|
||
|
#ifndef CURL_DISABLE_VERBOSE_STRINGS
|
||
|
if(data->set.verbose)
|
||
|
show_verbose_server_cert(conn, sockindex);
|
||
|
#endif
|
||
10 years ago
|
|
||
|
connssl->connecting_state = ssl_connect_done;
|
||
|
return CURLE_OK;
|
||
|
}
|
||
|
|
||
5 years ago
|
static Curl_recv sectransp_recv;
|
||
|
static Curl_send sectransp_send;
|
||
10 years ago
|
|
||
|
static CURLcode
|
||
5 years ago
|
sectransp_connect_common(struct connectdata *conn,
|
||
10 years ago
|
int sockindex,
|
||
|
bool nonblocking,
|
||
|
bool *done)
|
||
|
{
|
||
9 years ago
|
CURLcode result;
|
||
8 years ago
|
struct Curl_easy *data = conn->data;
|
||
10 years ago
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||
|
curl_socket_t sockfd = conn->sock[sockindex];
|
||
|
long timeout_ms;
|
||
|
int what;
|
||
|
|
||
|
/* check if the connection has already been established */
|
||
|
if(ssl_connection_complete == connssl->state) {
|
||
|
*done = TRUE;
|
||
|
return CURLE_OK;
|
||
|
}
|
||
|
|
||
7 years ago
|
if(ssl_connect_1 == connssl->connecting_state) {
|
||
10 years ago
|
/* Find out how much more time we're allowed */
|
||
|
timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
||
|
|
||
|
if(timeout_ms < 0) {
|
||
|
/* no need to continue if time already is up */
|
||
|
failf(data, "SSL connection timeout");
|
||
|
return CURLE_OPERATION_TIMEDOUT;
|
||
|
}
|
||
9 years ago
|
|
||
5 years ago
|
result = sectransp_connect_step1(conn, sockindex);
|
||
9 years ago
|
if(result)
|
||
|
return result;
|
||
10 years ago
|
}
|
||
|
|
||
|
while(ssl_connect_2 == connssl->connecting_state ||
|
||
|
ssl_connect_2_reading == connssl->connecting_state ||
|
||
|
ssl_connect_2_writing == connssl->connecting_state) {
|
||
|
|
||
|
/* check allowed time left */
|
||
|
timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
||
|
|
||
|
if(timeout_ms < 0) {
|
||
|
/* no need to continue if time already is up */
|
||
|
failf(data, "SSL connection timeout");
|
||
|
return CURLE_OPERATION_TIMEDOUT;
|
||
|
}
|
||
|
|
||
|
/* if ssl is expecting something, check if it's available. */
|
||
9 years ago
|
if(connssl->connecting_state == ssl_connect_2_reading ||
|
||
|
connssl->connecting_state == ssl_connect_2_writing) {
|
||
10 years ago
|
|
||
|
curl_socket_t writefd = ssl_connect_2_writing ==
|
||
|
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
|
||
|
curl_socket_t readfd = ssl_connect_2_reading ==
|
||
|
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
|
||
|
|
||
8 years ago
|
what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
|
||
|
nonblocking?0:timeout_ms);
|
||
10 years ago
|
if(what < 0) {
|
||
|
/* fatal error */
|
||
|
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
|
||
|
return CURLE_SSL_CONNECT_ERROR;
|
||
|
}
|
||
|
else if(0 == what) {
|
||
|
if(nonblocking) {
|
||
|
*done = FALSE;
|
||
|
return CURLE_OK;
|
||
|
}
|
||
|
else {
|
||
|
/* timeout */
|
||
|
failf(data, "SSL connection timeout");
|
||
|
return CURLE_OPERATION_TIMEDOUT;
|
||
|
}
|
||
|
}
|
||
|
/* socket is readable or writable */
|
||
|
}
|
||
|
|
||
|
/* Run transaction, and return to the caller if it failed or if this
|
||
|
* connection is done nonblocking and this loop would execute again. This
|
||
|
* permits the owner of a multi handle to abort a connection attempt
|
||
|
* before step2 has completed while ensuring that a client using select()
|
||
|
* or epoll() will always have a valid fdset to wait on.
|
||
|
*/
|
||
5 years ago
|
result = sectransp_connect_step2(conn, sockindex);
|
||
9 years ago
|
if(result || (nonblocking &&
|
||
|
(ssl_connect_2 == connssl->connecting_state ||
|
||
|
ssl_connect_2_reading == connssl->connecting_state ||
|
||
|
ssl_connect_2_writing == connssl->connecting_state)))
|
||
|
return result;
|
||
10 years ago
|
|
||
|
} /* repeat step2 until all transactions are done. */
|
||
|
|
||
|
|
||
9 years ago
|
if(ssl_connect_3 == connssl->connecting_state) {
|
||
5 years ago
|
result = sectransp_connect_step3(conn, sockindex);
|
||
9 years ago
|
if(result)
|
||
|
return result;
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
if(ssl_connect_done == connssl->connecting_state) {
|
||
10 years ago
|
connssl->state = ssl_connection_complete;
|
||
5 years ago
|
conn->recv[sockindex] = sectransp_recv;
|
||
|
conn->send[sockindex] = sectransp_send;
|
||
10 years ago
|
*done = TRUE;
|
||
|
}
|
||
|
else
|
||
|
*done = FALSE;
|
||
|
|
||
|
/* Reset our connect state machine */
|
||
|
connssl->connecting_state = ssl_connect_1;
|
||
|
|
||
|
return CURLE_OK;
|
||
|
}
|
||
|
|
||
5 years ago
|
static CURLcode Curl_sectransp_connect_nonblocking(struct connectdata *conn,
|
||
7 years ago
|
int sockindex, bool *done)
|
||
10 years ago
|
{
|
||
5 years ago
|
return sectransp_connect_common(conn, sockindex, TRUE, done);
|
||
10 years ago
|
}
|
||
|
|
||
5 years ago
|
static CURLcode Curl_sectransp_connect(struct connectdata *conn, int sockindex)
|
||
10 years ago
|
{
|
||
9 years ago
|
CURLcode result;
|
||
10 years ago
|
bool done = FALSE;
|
||
|
|
||
5 years ago
|
result = sectransp_connect_common(conn, sockindex, FALSE, &done);
|
||
10 years ago
|
|
||
9 years ago
|
if(result)
|
||
|
return result;
|
||
10 years ago
|
|
||
|
DEBUGASSERT(done);
|
||
|
|
||
|
return CURLE_OK;
|
||
|
}
|
||
|
|
||
5 years ago
|
static void Curl_sectransp_close(struct connectdata *conn, int sockindex)
|
||
10 years ago
|
{
|
||
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||
|
|
||
7 years ago
|
if(BACKEND->ssl_ctx) {
|
||
|
(void)SSLClose(BACKEND->ssl_ctx);
|
||
10 years ago
|
#if CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS
|
||
|
if(SSLCreateContext != NULL)
|
||
7 years ago
|
CFRelease(BACKEND->ssl_ctx);
|
||
10 years ago
|
#if CURL_SUPPORT_MAC_10_8
|
||
|
else
|
||
7 years ago
|
(void)SSLDisposeContext(BACKEND->ssl_ctx);
|
||
10 years ago
|
#endif /* CURL_SUPPORT_MAC_10_8 */
|
||
|
#else
|
||
7 years ago
|
(void)SSLDisposeContext(BACKEND->ssl_ctx);
|
||
10 years ago
|
#endif /* CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS */
|
||
7 years ago
|
BACKEND->ssl_ctx = NULL;
|
||
10 years ago
|
}
|
||
7 years ago
|
BACKEND->ssl_sockfd = 0;
|
||
10 years ago
|
}
|
||
|
|
||
5 years ago
|
static int Curl_sectransp_shutdown(struct connectdata *conn, int sockindex)
|
||
10 years ago
|
{
|
||
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||
8 years ago
|
struct Curl_easy *data = conn->data;
|
||
10 years ago
|
ssize_t nread;
|
||
|
int what;
|
||
|
int rc;
|
||
|
char buf[120];
|
||
|
|
||
7 years ago
|
if(!BACKEND->ssl_ctx)
|
||
10 years ago
|
return 0;
|
||
|
|
||
5 years ago
|
#ifndef CURL_DISABLE_FTP
|
||
10 years ago
|
if(data->set.ftp_ccc != CURLFTPSSL_CCC_ACTIVE)
|
||
|
return 0;
|
||
5 years ago
|
#endif
|
||
10 years ago
|
|
||
5 years ago
|
Curl_sectransp_close(conn, sockindex);
|
||
10 years ago
|
|
||
|
rc = 0;
|
||
|
|
||
8 years ago
|
what = SOCKET_READABLE(conn->sock[sockindex], SSL_SHUTDOWN_TIMEOUT);
|
||
10 years ago
|
|
||
|
for(;;) {
|
||
|
if(what < 0) {
|
||
|
/* anything that gets here is fatally bad */
|
||
|
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
|
||
|
rc = -1;
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
if(!what) { /* timeout */
|
||
|
failf(data, "SSL shutdown timeout");
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
/* Something to read, let's do it and hope that it is the close
|
||
|
notify alert from the server. No way to SSL_Read now, so use read(). */
|
||
|
|
||
|
nread = read(conn->sock[sockindex], buf, sizeof(buf));
|
||
|
|
||
|
if(nread < 0) {
|
||
|
failf(data, "read: %s", strerror(errno));
|
||
|
rc = -1;
|
||
|
}
|
||
|
|
||
|
if(nread <= 0)
|
||
|
break;
|
||
|
|
||
8 years ago
|
what = SOCKET_READABLE(conn->sock[sockindex], 0);
|
||
10 years ago
|
}
|
||
|
|
||
|
return rc;
|
||
|
}
|
||
|
|
||
5 years ago
|
static void Curl_sectransp_session_free(void *ptr)
|
||
10 years ago
|
{
|
||
|
/* ST, as of iOS 5 and Mountain Lion, has no public method of deleting a
|
||
|
cached session ID inside the Security framework. There is a private
|
||
|
function that does this, but I don't want to have to explain to you why I
|
||
|
got your application rejected from the App Store due to the use of a
|
||
|
private API, so the best we can do is free up our own char array that we
|
||
5 years ago
|
created way back in sectransp_connect_step1... */
|
||
10 years ago
|
Curl_safefree(ptr);
|
||
|
}
|
||
|
|
||
5 years ago
|
static size_t Curl_sectransp_version(char *buffer, size_t size)
|
||
10 years ago
|
{
|
||
5 years ago
|
return msnprintf(buffer, size, "SecureTransport");
|
||
10 years ago
|
}
|
||
|
|
||
|
/*
|
||
|
* This function uses SSLGetSessionState to determine connection status.
|
||
|
*
|
||
|
* Return codes:
|
||
|
* 1 means the connection is still in place
|
||
|
* 0 means the connection has been closed
|
||
|
* -1 means the connection status is unknown
|
||
|
*/
|
||
5 years ago
|
static int Curl_sectransp_check_cxn(struct connectdata *conn)
|
||
10 years ago
|
{
|
||
|
struct ssl_connect_data *connssl = &conn->ssl[FIRSTSOCKET];
|
||
|
OSStatus err;
|
||
|
SSLSessionState state;
|
||
|
|
||
7 years ago
|
if(BACKEND->ssl_ctx) {
|
||
|
err = SSLGetSessionState(BACKEND->ssl_ctx, &state);
|
||
10 years ago
|
if(err == noErr)
|
||
|
return state == kSSLConnected || state == kSSLHandshake;
|
||
|
return -1;
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
5 years ago
|
static bool Curl_sectransp_data_pending(const struct connectdata *conn,
|
||
7 years ago
|
int connindex)
|
||
10 years ago
|
{
|
||
|
const struct ssl_connect_data *connssl = &conn->ssl[connindex];
|
||
|
OSStatus err;
|
||
|
size_t buffer;
|
||
|
|
||
7 years ago
|
if(BACKEND->ssl_ctx) { /* SSL is in use */
|
||
|
err = SSLGetBufferedReadSize(BACKEND->ssl_ctx, &buffer);
|
||
10 years ago
|
if(err == noErr)
|
||
|
return buffer > 0UL;
|
||
|
return false;
|
||
|
}
|
||
|
else
|
||
|
return false;
|
||
|
}
|
||
|
|
||
5 years ago
|
static CURLcode Curl_sectransp_random(struct Curl_easy *data UNUSED_PARAM,
|
||
7 years ago
|
unsigned char *entropy, size_t length)
|
||
10 years ago
|
{
|
||
|
/* arc4random_buf() isn't available on cats older than Lion, so let's
|
||
|
do this manually for the benefit of the older cats. */
|
||
|
size_t i;
|
||
|
u_int32_t random_number = 0;
|
||
|
|
||
7 years ago
|
(void)data;
|
||
|
|
||
10 years ago
|
for(i = 0 ; i < length ; i++) {
|
||
|
if(i % sizeof(u_int32_t) == 0)
|
||
|
random_number = arc4random();
|
||
|
entropy[i] = random_number & 0xFF;
|
||
|
random_number >>= 8;
|
||
|
}
|
||
|
i = random_number = 0;
|
||
8 years ago
|
return CURLE_OK;
|
||
10 years ago
|
}
|
||
|
|
||
5 years ago
|
static CURLcode Curl_sectransp_md5sum(unsigned char *tmp, /* input */
|
||
7 years ago
|
size_t tmplen,
|
||
|
unsigned char *md5sum, /* output */
|
||
|
size_t md5len)
|
||
10 years ago
|
{
|
||
|
(void)md5len;
|
||
|
(void)CC_MD5(tmp, (CC_LONG)tmplen, md5sum);
|
||
7 years ago
|
return CURLE_OK;
|
||
10 years ago
|
}
|
||
|
|
||
5 years ago
|
static CURLcode Curl_sectransp_sha256sum(const unsigned char *tmp, /* input */
|
||
7 years ago
|
size_t tmplen,
|
||
|
unsigned char *sha256sum, /* output */
|
||
|
size_t sha256len)
|
||
8 years ago
|
{
|
||
7 years ago
|
assert(sha256len >= CURL_SHA256_DIGEST_LENGTH);
|
||
8 years ago
|
(void)CC_SHA256(tmp, (CC_LONG)tmplen, sha256sum);
|
||
6 years ago
|
return CURLE_OK;
|
||
8 years ago
|
}
|
||
|
|
||
5 years ago
|
static bool Curl_sectransp_false_start(void)
|
||
8 years ago
|
{
|
||
9 years ago
|
#if CURL_BUILD_MAC_10_9 || CURL_BUILD_IOS_7
|
||
|
if(SSLSetSessionOption != NULL)
|
||
|
return TRUE;
|
||
|
#endif
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
5 years ago
|
static ssize_t sectransp_send(struct connectdata *conn,
|
||
10 years ago
|
int sockindex,
|
||
|
const void *mem,
|
||
|
size_t len,
|
||
|
CURLcode *curlcode)
|
||
|
{
|
||
8 years ago
|
/*struct Curl_easy *data = conn->data;*/
|
||
10 years ago
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||
|
size_t processed = 0UL;
|
||
|
OSStatus err;
|
||
|
|
||
|
/* The SSLWrite() function works a little differently than expected. The
|
||
|
fourth argument (processed) is currently documented in Apple's
|
||
|
documentation as: "On return, the length, in bytes, of the data actually
|
||
|
written."
|
||
|
|
||
|
Now, one could interpret that as "written to the socket," but actually,
|
||
|
it returns the amount of data that was written to a buffer internal to
|
||
|
the SSLContextRef instead. So it's possible for SSLWrite() to return
|
||
|
errSSLWouldBlock and a number of bytes "written" because those bytes were
|
||
|
encrypted and written to a buffer, not to the socket.
|
||
|
|
||
|
So if this happens, then we need to keep calling SSLWrite() over and
|
||
|
over again with no new data until it quits returning errSSLWouldBlock. */
|
||
|
|
||
|
/* Do we have buffered data to write from the last time we were called? */
|
||
7 years ago
|
if(BACKEND->ssl_write_buffered_length) {
|
||
10 years ago
|
/* Write the buffered data: */
|
||
7 years ago
|
err = SSLWrite(BACKEND->ssl_ctx, NULL, 0UL, &processed);
|
||
8 years ago
|
switch(err) {
|
||
10 years ago
|
case noErr:
|
||
|
/* processed is always going to be 0 because we didn't write to
|
||
|
the buffer, so return how much was written to the socket */
|
||
7 years ago
|
processed = BACKEND->ssl_write_buffered_length;
|
||
|
BACKEND->ssl_write_buffered_length = 0UL;
|
||
10 years ago
|
break;
|
||
|
case errSSLWouldBlock: /* argh, try again */
|
||
|
*curlcode = CURLE_AGAIN;
|
||
|
return -1L;
|
||
|
default:
|
||
|
failf(conn->data, "SSLWrite() returned error %d", err);
|
||
|
*curlcode = CURLE_SEND_ERROR;
|
||
|
return -1L;
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
/* We've got new data to write: */
|
||
7 years ago
|
err = SSLWrite(BACKEND->ssl_ctx, mem, len, &processed);
|
||
10 years ago
|
if(err != noErr) {
|
||
8 years ago
|
switch(err) {
|
||
10 years ago
|
case errSSLWouldBlock:
|
||
|
/* Data was buffered but not sent, we have to tell the caller
|
||
|
to try sending again, and remember how much was buffered */
|
||
7 years ago
|
BACKEND->ssl_write_buffered_length = len;
|
||
10 years ago
|
*curlcode = CURLE_AGAIN;
|
||
|
return -1L;
|
||
|
default:
|
||
|
failf(conn->data, "SSLWrite() returned error %d", err);
|
||
|
*curlcode = CURLE_SEND_ERROR;
|
||
|
return -1L;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return (ssize_t)processed;
|
||
|
}
|
||
|
|
||
5 years ago
|
static ssize_t sectransp_recv(struct connectdata *conn,
|
||
10 years ago
|
int num,
|
||
|
char *buf,
|
||
|
size_t buffersize,
|
||
|
CURLcode *curlcode)
|
||
|
{
|
||
8 years ago
|
/*struct Curl_easy *data = conn->data;*/
|
||
10 years ago
|
struct ssl_connect_data *connssl = &conn->ssl[num];
|
||
|
size_t processed = 0UL;
|
||
7 years ago
|
OSStatus err = SSLRead(BACKEND->ssl_ctx, buf, buffersize, &processed);
|
||
10 years ago
|
|
||
|
if(err != noErr) {
|
||
8 years ago
|
switch(err) {
|
||
10 years ago
|
case errSSLWouldBlock: /* return how much we read (if anything) */
|
||
|
if(processed)
|
||
|
return (ssize_t)processed;
|
||
|
*curlcode = CURLE_AGAIN;
|
||
|
return -1L;
|
||
|
break;
|
||
|
|
||
|
/* errSSLClosedGraceful - server gracefully shut down the SSL session
|
||
|
errSSLClosedNoNotify - server hung up on us instead of sending a
|
||
|
closure alert notice, read() is returning 0
|
||
|
Either way, inform the caller that the server disconnected. */
|
||
|
case errSSLClosedGraceful:
|
||
|
case errSSLClosedNoNotify:
|
||
|
*curlcode = CURLE_OK;
|
||
|
return -1L;
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
failf(conn->data, "SSLRead() return error %d", err);
|
||
|
*curlcode = CURLE_RECV_ERROR;
|
||
|
return -1L;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
return (ssize_t)processed;
|
||
|
}
|
||
|
|
||
5 years ago
|
static void *Curl_sectransp_get_internals(struct ssl_connect_data *connssl,
|
||
7 years ago
|
CURLINFO info UNUSED_PARAM)
|
||
|
{
|
||
|
(void)info;
|
||
|
return BACKEND->ssl_ctx;
|
||
|
}
|
||
|
|
||
5 years ago
|
const struct Curl_ssl Curl_ssl_sectransp = {
|
||
|
{ CURLSSLBACKEND_SECURETRANSPORT, "secure-transport" }, /* info */
|
||
7 years ago
|
|
||
5 years ago
|
#ifdef SECTRANSP_PINNEDPUBKEY
|
||
6 years ago
|
SSLSUPP_PINNEDPUBKEY,
|
||
7 years ago
|
#else
|
||
6 years ago
|
0,
|
||
5 years ago
|
#endif /* SECTRANSP_PINNEDPUBKEY */
|
||
7 years ago
|
|
||
|
sizeof(struct ssl_backend_data),
|
||
|
|
||
|
Curl_none_init, /* init */
|
||
|
Curl_none_cleanup, /* cleanup */
|
||
5 years ago
|
Curl_sectransp_version, /* version */
|
||
|
Curl_sectransp_check_cxn, /* check_cxn */
|
||
|
Curl_sectransp_shutdown, /* shutdown */
|
||
|
Curl_sectransp_data_pending, /* data_pending */
|
||
|
Curl_sectransp_random, /* random */
|
||
7 years ago
|
Curl_none_cert_status_request, /* cert_status_request */
|
||
5 years ago
|
Curl_sectransp_connect, /* connect */
|
||
|
Curl_sectransp_connect_nonblocking, /* connect_nonblocking */
|
||
|
Curl_sectransp_get_internals, /* get_internals */
|
||
|
Curl_sectransp_close, /* close_one */
|
||
7 years ago
|
Curl_none_close_all, /* close_all */
|
||
5 years ago
|
Curl_sectransp_session_free, /* session_free */
|
||
7 years ago
|
Curl_none_set_engine, /* set_engine */
|
||
|
Curl_none_set_engine_default, /* set_engine_default */
|
||
|
Curl_none_engines_list, /* engines_list */
|
||
5 years ago
|
Curl_sectransp_false_start, /* false_start */
|
||
|
Curl_sectransp_md5sum, /* md5sum */
|
||
|
Curl_sectransp_sha256sum /* sha256sum */
|
||
7 years ago
|
};
|
||
|
|
||
|
#ifdef __clang__
|
||
|
#pragma clang diagnostic pop
|
||
|
#endif
|
||
|
|
||
5 years ago
|
#endif /* USE_SECTRANSP */
|