Skip to content

Commit dc29ee1

Browse files
authored
Merge pull request #1 from dongbeiouba/feature/ntls
Support TLCP based on Tongsuo
2 parents 6b6667c + 012fdcd commit dc29ee1

20 files changed

+436
-40
lines changed

.github/workflows/linux.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ jobs:
101101
configure: CC=icc --enable-debug --with-openssl
102102

103103
- name: NSS
104-
install_packages: clang-9 libnss3-dev libpsl-dev libbrotli-dev libzstd-dev libnghttp2-dev nss-plugin-pem
105-
configure: CC=clang-9 CPPFLAGS="-isystem /usr/include/nss" --with-nss --enable-debug --with-nss-deprecated
104+
install_packages: clang libnss3-dev libpsl-dev libbrotli-dev libzstd-dev libnghttp2-dev nss-plugin-pem
105+
configure: CC=clang CPPFLAGS="-isystem /usr/include/nss" --with-nss --enable-debug --with-nss-deprecated
106106

107107
steps:
108108
- run: |

.github/workflows/tongsuo.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright (C) 2022
2+
#
3+
# SPDX-License-Identifier: curl
4+
5+
name: build-with-tongsuo
6+
7+
on: [workflow_dispatch, pull_request, push]
8+
9+
jobs:
10+
autotools:
11+
runs-on: 'ubuntu-latest'
12+
timeout-minutes: 60
13+
14+
steps:
15+
- name: checkout tongsuo
16+
uses: actions/checkout@v2
17+
with:
18+
repository: Tongsuo-Project/Tongsuo
19+
path: Tongsuo
20+
- name: install Tongsuo
21+
working-directory: ./Tongsuo
22+
run: |
23+
./config --banner=Configured --prefix=${GITHUB_WORKSPACE}/install enable-ntls
24+
make -s -j4
25+
make install
26+
27+
- uses: actions/checkout@v3
28+
with:
29+
path: curl
30+
31+
- name: build curl
32+
working-directory: ./curl
33+
run: |
34+
autoreconf -fi
35+
LDFLAGS=-Wl,-rpath=${GITHUB_WORKSPACE}/install/lib64/ ./configure --enable-warnings --enable-werror --with-openssl=${GITHUB_WORKSPACE}/install
36+
make V=1
37+
make V=1 examples
38+
make V=1 -C tests
39+
make V=1 test-ci
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/***************************************************************************
2+
* _ _ ____ _
3+
* Project ___| | | | _ \| |
4+
* / __| | | | |_) | |
5+
* | (__| |_| | _ <| |___
6+
* \___|\___/|_| \_\_____|
7+
*
8+
* Copyright (C) 2022
9+
*
10+
* This software is licensed as described in the file COPYING, which
11+
* you should have received as part of this distribution. The terms
12+
* are also available at https://curl.se/docs/copyright.html.
13+
*
14+
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
15+
* copies of the Software, and permit persons to whom the Software is
16+
* furnished to do so, under the terms of the COPYING file.
17+
*
18+
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19+
* KIND, either express or implied.
20+
*
21+
* SPDX-License-Identifier: curl
22+
*
23+
***************************************************************************/
24+
/* <DESC>
25+
* HTTP over TLCP with double certificates
26+
* </DESC>
27+
*/
28+
#include <stdio.h>
29+
#include <curl/curl.h>
30+
31+
int main(int argc, char **argv)
32+
{
33+
CURL *curl;
34+
CURLcode res;
35+
36+
curl = curl_easy_init();
37+
if (curl) {
38+
curl_easy_setopt(curl, CURLOPT_URL, "https://127.0.0.1:443");
39+
curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_NTLSv1_1);
40+
curl_easy_setopt(curl, CURLOPT_SSL_CIPHER_LIST,
41+
"ECDHE-SM2-SM4-CBC-SM3");
42+
43+
curl_easy_setopt(curl, CURLOPT_SSLSIGNCERT, "sm2_sign.crt");
44+
curl_easy_setopt(curl, CURLOPT_SSLSIGNKEY, "sm2_sign.key");
45+
curl_easy_setopt(curl, CURLOPT_SSLENCCERT, "sm2_enc.crt");
46+
curl_easy_setopt(curl, CURLOPT_SSLENCKEY, "sm2_enc.key");
47+
48+
/* optional */
49+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
50+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
51+
52+
res = curl_easy_perform(curl);
53+
54+
if(res != CURLE_OK)
55+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
56+
curl_easy_strerror(res));
57+
58+
curl_easy_cleanup(curl);
59+
}
60+
61+
return 0;
62+
}
63+
// gcc https-tlcp-doublecerts.c -o https-tlcp-doublecerts -I/usr/local/curl/include -lcurl -L/usr/local/curl/lib -Wl,-rpath=/usr/local/curl/lib

docs/examples/https-tlcp.c

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/***************************************************************************
2+
* _ _ ____ _
3+
* Project ___| | | | _ \| |
4+
* / __| | | | |_) | |
5+
* | (__| |_| | _ <| |___
6+
* \___|\___/|_| \_\_____|
7+
*
8+
* Copyright (C) 2022
9+
*
10+
* This software is licensed as described in the file COPYING, which
11+
* you should have received as part of this distribution. The terms
12+
* are also available at https://curl.se/docs/copyright.html.
13+
*
14+
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
15+
* copies of the Software, and permit persons to whom the Software is
16+
* furnished to do so, under the terms of the COPYING file.
17+
*
18+
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19+
* KIND, either express or implied.
20+
*
21+
* SPDX-License-Identifier: curl
22+
*
23+
***************************************************************************/
24+
/* <DESC>
25+
* HTTP over TLCP
26+
* </DESC>
27+
*/
28+
#include <stdio.h>
29+
#include <curl/curl.h>
30+
31+
int main(int argc, char **argv)
32+
{
33+
CURL *curl;
34+
CURLcode res;
35+
36+
curl = curl_easy_init();
37+
if (curl) {
38+
curl_easy_setopt(curl, CURLOPT_URL, "https://127.0.0.1:443");
39+
curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_NTLSv1_1);
40+
curl_easy_setopt(curl, CURLOPT_SSL_CIPHER_LIST, "ECC-SM2-SM4-CBC-SM3");
41+
42+
/* optional */
43+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
44+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
45+
46+
res = curl_easy_perform(curl);
47+
48+
if(res != CURLE_OK)
49+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
50+
curl_easy_strerror(res));
51+
52+
curl_easy_cleanup(curl);
53+
}
54+
55+
return 0;
56+
}
57+
// gcc https-tlcp.c -o https-tlcp -I/usr/local/curl/include -lcurl -L/usr/local/curl/lib -Wl,-rpath=/usr/local/curl/lib

docs/libcurl/symbols-in-versions

+5
Original file line numberDiff line numberDiff line change
@@ -1123,3 +1123,8 @@ LIBCURL_VERSION_MAJOR 7.11.0
11231123
LIBCURL_VERSION_MINOR 7.11.0
11241124
LIBCURL_VERSION_NUM 7.11.0
11251125
LIBCURL_VERSION_PATCH 7.11.0
1126+
CURLOPT_SSLENCCERT 1 - 1
1127+
CURLOPT_SSLENCKEY 1 - 1
1128+
CURLOPT_SSLSIGNCERT 1 - 1
1129+
CURLOPT_SSLSIGNKEY 1 - 1
1130+
CURL_SSLVERSION_NTLSv1_1 1 - 1

include/curl/curl.h

+13
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,18 @@ typedef enum {
21572157
/* websockets options */
21582158
CURLOPT(CURLOPT_WS_OPTIONS, CURLOPTTYPE_LONG, 320),
21592159

2160+
/* name of the file keeping your SSL sign certificate */
2161+
CURLOPT(CURLOPT_SSLSIGNCERT, CURLOPTTYPE_STRINGPOINT, 321),
2162+
2163+
/* name of the file keeping your SSL sign key */
2164+
CURLOPT(CURLOPT_SSLSIGNKEY, CURLOPTTYPE_STRINGPOINT, 322),
2165+
2166+
/* name of the file keeping your SSL enc certificate */
2167+
CURLOPT(CURLOPT_SSLENCCERT, CURLOPTTYPE_STRINGPOINT, 323),
2168+
2169+
/* name of the file keeping your SSL enc key */
2170+
CURLOPT(CURLOPT_SSLENCKEY, CURLOPTTYPE_STRINGPOINT, 324),
2171+
21602172
CURLOPT_LASTENTRY /* the last unused */
21612173
} CURLoption;
21622174

@@ -2263,6 +2275,7 @@ enum {
22632275
CURL_SSLVERSION_TLSv1_1,
22642276
CURL_SSLVERSION_TLSv1_2,
22652277
CURL_SSLVERSION_TLSv1_3,
2278+
CURL_SSLVERSION_NTLSv1_1,
22662279

22672280
CURL_SSLVERSION_LAST /* never use, keep last */
22682281
};

include/curl/typecheck-gcc.h

+4
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ CURLWARNING(_curl_easy_getinfo_err_curl_off_t,
343343
(option) == CURLOPT_USERPWD || \
344344
(option) == CURLOPT_XOAUTH2_BEARER || \
345345
(option) == CURLOPT_SSL_EC_CURVES || \
346+
(option) == CURLOPT_SSLSIGNCERT || \
347+
(option) == CURLOPT_SSLSIGNKEY || \
348+
(option) == CURLOPT_SSLENCCERT || \
349+
(option) == CURLOPT_SSLENCKEY || \
346350
0)
347351

348352
/* evaluates to true if option takes a curl_write_callback argument */

lib/c-hyper.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,10 @@ CURLcode Curl_hyper_stream(struct Curl_easy *data,
415415
break;
416416
}
417417
else if(h->endtask == task) {
418-
/* end of transfer */
418+
/* end of transfer, forget the task handled, we might get a
419+
* new one with the same address in the future. */
419420
*done = TRUE;
421+
h->endtask = NULL;
420422
infof(data, "hyperstream is done");
421423
if(!k->bodywrites) {
422424
/* hyper doesn't always call the body write callback */

lib/easyoptions.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,17 @@ struct curl_easyoption Curl_easyopts[] = {
293293
{"SSLCERTPASSWD", CURLOPT_KEYPASSWD, CURLOT_STRING, CURLOT_FLAG_ALIAS},
294294
{"SSLCERTTYPE", CURLOPT_SSLCERTTYPE, CURLOT_STRING, 0},
295295
{"SSLCERT_BLOB", CURLOPT_SSLCERT_BLOB, CURLOT_BLOB, 0},
296+
{"SSLENCCERT", CURLOPT_SSLENCCERT, CURLOT_STRING, 0},
297+
{"SSLENCKEY", CURLOPT_SSLENCKEY, CURLOT_STRING, 0},
296298
{"SSLENGINE", CURLOPT_SSLENGINE, CURLOT_STRING, 0},
297299
{"SSLENGINE_DEFAULT", CURLOPT_SSLENGINE_DEFAULT, CURLOT_LONG, 0},
298300
{"SSLKEY", CURLOPT_SSLKEY, CURLOT_STRING, 0},
299301
{"SSLKEYPASSWD", CURLOPT_KEYPASSWD, CURLOT_STRING, CURLOT_FLAG_ALIAS},
300302
{"SSLKEYTYPE", CURLOPT_SSLKEYTYPE, CURLOT_STRING, 0},
301303
{"SSLKEY_BLOB", CURLOPT_SSLKEY_BLOB, CURLOT_BLOB, 0},
302304
{"SSLVERSION", CURLOPT_SSLVERSION, CURLOT_VALUES, 0},
305+
{"SSLSIGNCERT", CURLOPT_SSLSIGNCERT, CURLOT_STRING, 0},
306+
{"SSLSIGNKEY", CURLOPT_SSLSIGNKEY, CURLOT_STRING, 0},
303307
{"SSL_CIPHER_LIST", CURLOPT_SSL_CIPHER_LIST, CURLOT_STRING, 0},
304308
{"SSL_CTX_DATA", CURLOPT_SSL_CTX_DATA, CURLOT_CBPTR, 0},
305309
{"SSL_CTX_FUNCTION", CURLOPT_SSL_CTX_FUNCTION, CURLOT_FUNCTION, 0},
@@ -368,6 +372,6 @@ struct curl_easyoption Curl_easyopts[] = {
368372
*/
369373
int Curl_easyopts_check(void)
370374
{
371-
return ((CURLOPT_LASTENTRY%10000) != (320 + 1));
375+
return ((CURLOPT_LASTENTRY%10000) != (324 + 1));
372376
}
373377
#endif

lib/setopt.c

+30
Original file line numberDiff line numberDiff line change
@@ -3106,6 +3106,36 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
31063106
data->set.ws_raw_mode = raw;
31073107
break;
31083108
}
3109+
#endif
3110+
#ifdef HAVE_NTLS
3111+
case CURLOPT_SSLSIGNCERT:
3112+
/*
3113+
* String that holds file name of the SSL sign certificate to use
3114+
*/
3115+
result = Curl_setstropt(&data->set.str[STRING_SIGN_CERT],
3116+
va_arg(param, char *));
3117+
break;
3118+
case CURLOPT_SSLSIGNKEY:
3119+
/*
3120+
* String that holds file name of the SSL sign key to use
3121+
*/
3122+
result = Curl_setstropt(&data->set.str[STRING_SIGN_KEY],
3123+
va_arg(param, char *));
3124+
break;
3125+
case CURLOPT_SSLENCCERT:
3126+
/*
3127+
* String that holds file name of the SSL enc certificate to use
3128+
*/
3129+
result = Curl_setstropt(&data->set.str[STRING_ENC_CERT],
3130+
va_arg(param, char *));
3131+
break;
3132+
case CURLOPT_SSLENCKEY:
3133+
/*
3134+
* String that holds file name of the SSL enc key to use
3135+
*/
3136+
result = Curl_setstropt(&data->set.str[STRING_ENC_KEY],
3137+
va_arg(param, char *));
3138+
break;
31093139
#endif
31103140
default:
31113141
/* unknown tag and its companion, just ignore: */

lib/url.c

+6
Original file line numberDiff line numberDiff line change
@@ -3868,6 +3868,12 @@ static CURLcode create_conn(struct Curl_easy *data,
38683868
data->set.ssl.key_type = data->set.str[STRING_KEY_TYPE];
38693869
data->set.ssl.key_passwd = data->set.str[STRING_KEY_PASSWD];
38703870
data->set.ssl.primary.clientcert = data->set.str[STRING_CERT];
3871+
#ifdef HAVE_NTLS
3872+
data->set.ssl.sign_cert = data->set.str[STRING_SIGN_CERT];
3873+
data->set.ssl.sign_key = data->set.str[STRING_SIGN_KEY];
3874+
data->set.ssl.enc_cert = data->set.str[STRING_ENC_CERT];
3875+
data->set.ssl.enc_key = data->set.str[STRING_ENC_KEY];
3876+
#endif
38713877
#ifdef USE_TLS_SRP
38723878
data->set.ssl.primary.username = data->set.str[STRING_TLSAUTH_USERNAME];
38733879
data->set.ssl.primary.password = data->set.str[STRING_TLSAUTH_PASSWORD];

lib/urldata.h

+10
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ struct ssl_config_data {
299299
struct curl_blob *key_blob;
300300
char *key_type; /* format for private key (default: PEM) */
301301
char *key_passwd; /* plain text private key password */
302+
#ifdef HAVE_NTLS
303+
char *sign_cert;
304+
char *sign_key;
305+
char *enc_cert;
306+
char *enc_key;
307+
#endif
302308
BIT(certinfo); /* gather lots of certificate info */
303309
BIT(falsestart);
304310
BIT(enable_beast); /* allow this flaw for interoperability's sake */
@@ -1621,6 +1627,10 @@ enum dupstring {
16211627
STRING_DNS_LOCAL_IP6,
16221628
STRING_SSL_EC_CURVES,
16231629

1630+
STRING_SIGN_CERT,
1631+
STRING_SIGN_KEY,
1632+
STRING_ENC_CERT,
1633+
STRING_ENC_KEY,
16241634
/* -- end of null-terminated strings -- */
16251635

16261636
STRING_LASTZEROTERMINATED,

0 commit comments

Comments
 (0)