Skip to content

Commit 3608618

Browse files
scottdeboybenlaurie
authored andcommitted
Add callbacks supporting generation and retrieval of supplemental data entries, facilitating RFC 5878 (TLS auth extensions)
Removed prior audit proof logic - audit proof support was implemented using the generic TLS extension API Tests exercising the new supplemental data registration and callback api can be found in ssltest.c. Implemented changes to s_server and s_client to exercise supplemental data callbacks via the -auth argument, as well as additional flags to exercise supplemental data being sent only during renegotiation.
1 parent cda01d5 commit 3608618

25 files changed

+914
-804
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
Changes between 1.0.x and 1.1.0 [xx XXX xxxx]
66

7+
*) Add callbacks supporting generation and retrieval of supplemental
8+
data entries.
9+
[Scott Deboy <[email protected]>, Trevor Perrin and Ben Laurie]
10+
711
*) Add EVP support for key wrapping algorithms, to avoid problems with
812
existing code the flag EVP_CIPHER_CTX_WRAP_ALLOW has to be set in
913
the EVP_CIPHER_CTX or an error is returned. Add AES and DES3 wrap

Configure

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ my %table=(
593593
"darwin64-ppc-cc","cc:-arch ppc64 -O3 -DB_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc64_asm}:osx64:dlfcn:darwin-shared:-fPIC -fno-common:-arch ppc64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
594594
"darwin-i386-cc","cc:-arch i386 -O3 -fomit-frame-pointer -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:".eval{my $asm=$x86_asm;$asm=~s/cast\-586\.o//;$asm}.":macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
595595
"debug-darwin-i386-cc","cc:-arch i386 -g3 -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:${x86_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
596+
"debug-darwin64-x86_64-cc","cc:-arch x86_64 -ggdb -g2 -O0 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch x86_64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
596597
"darwin64-x86_64-cc","cc:-arch x86_64 -O3 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch x86_64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
597598
"debug-darwin-ppc-cc","cc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DB_ENDIAN -g -Wall -O::-D_REENTRANT:MACOSX::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc32_asm}:osx32:dlfcn:darwin-shared:-fPIC:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
598599
# iPhoneOS/iOS

apps/s_apps.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx);
156156
int set_cert_stuff(SSL_CTX *ctx, char *cert_file, char *key_file);
157157
int set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key,
158158
STACK_OF(X509) *chain, int build_chain);
159-
# ifndef OPENSSL_NO_TLSEXT
160-
int set_cert_key_and_authz(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key,
161-
unsigned char *authz, size_t authz_length);
162-
# endif
163159
int ssl_print_sigalgs(BIO *out, SSL *s);
164160
int ssl_print_point_formats(BIO *out, SSL *s);
165161
int ssl_print_curves(BIO *out, SSL *s, int noshared);

apps/s_cb.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,9 @@ void MS_CALLBACK msg_cb(int write_p, int version, int content_type, const void *
876876
case 16:
877877
str_details1 = ", ClientKeyExchange";
878878
break;
879+
case 23:
880+
str_details1 = ", SupplementalData";
881+
break;
879882
case 20:
880883
str_details1 = ", Finished";
881884
break;

apps/s_client.c

Lines changed: 109 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ static int c_debug=0;
203203
#ifndef OPENSSL_NO_TLSEXT
204204
static int c_tlsextdebug=0;
205205
static int c_status_req=0;
206-
static int c_proof_debug=0;
207206
#endif
208207
static int c_msg=0;
209208
static int c_showcerts=0;
@@ -215,14 +214,44 @@ static void sc_usage(void);
215214
static void print_stuff(BIO *berr,SSL *con,int full);
216215
#ifndef OPENSSL_NO_TLSEXT
217216
static int ocsp_resp_cb(SSL *s, void *arg);
218-
static int audit_proof_cb(SSL *s, void *arg);
217+
static int c_auth = 0;
218+
static int c_auth_require_reneg = 0;
219219
#endif
220220
static BIO *bio_c_out=NULL;
221221
static BIO *bio_c_msg=NULL;
222222
static int c_quiet=0;
223223
static int c_ign_eof=0;
224224
static int c_brief=0;
225225

226+
#ifndef OPENSSL_NO_TLSEXT
227+
228+
static const unsigned char *most_recent_supplemental_data;
229+
static size_t most_recent_supplemental_data_length;
230+
231+
static int server_provided_server_authz = 0;
232+
static int server_provided_client_authz = 0;
233+
234+
static const unsigned char auth_ext_data[]={TLSEXT_AUTHZDATAFORMAT_dtcp};
235+
236+
static int suppdata_cb(SSL *s, unsigned short supp_data_type,
237+
const unsigned char *in,
238+
unsigned short inlen, int *al,
239+
void *arg);
240+
241+
static int auth_suppdata_generate_cb(SSL *s, unsigned short supp_data_type,
242+
const unsigned char **out,
243+
unsigned short *outlen, void *arg);
244+
245+
static int authz_tlsext_generate_cb(SSL *s, unsigned short ext_type,
246+
const unsigned char **out, unsigned short *outlen,
247+
void *arg);
248+
249+
static int authz_tlsext_cb(SSL *s, unsigned short ext_type,
250+
const unsigned char *in,
251+
unsigned short inlen, int *al,
252+
void *arg);
253+
#endif
254+
226255
#ifndef OPENSSL_NO_PSK
227256
/* Default PSK identity and key */
228257
static char *psk_identity="Client_identity";
@@ -362,14 +391,13 @@ static void sc_usage(void)
362391
BIO_printf(bio_err," -tlsextdebug - hex dump of all TLS extensions received\n");
363392
BIO_printf(bio_err," -status - request certificate status from server\n");
364393
BIO_printf(bio_err," -no_ticket - disable use of RFC4507bis session tickets\n");
365-
BIO_printf(bio_err," -proof_debug - request an audit proof and print its hex dump\n");
394+
BIO_printf(bio_err," -serverinfo types - send empty ClientHello extensions (comma-separated numbers)\n");
395+
BIO_printf(bio_err," -auth - send and receive RFC 5878 TLS auth extensions and supplemental data\n");
396+
BIO_printf(bio_err," -auth_require_reneg - Do not send TLS auth extensions until renegotiation\n");
366397
# ifndef OPENSSL_NO_NEXTPROTONEG
367398
BIO_printf(bio_err," -nextprotoneg arg - enable NPN extension, considering named protocols supported (comma-separated list)\n");
368399
BIO_printf(bio_err," -alpn arg - enable ALPN extension, considering named protocols supported (comma-separated list)\n");
369400
# endif
370-
#ifndef OPENSSL_NO_TLSEXT
371-
BIO_printf(bio_err," -serverinfo types - send empty ClientHello extensions (comma-separated numbers)\n");
372-
#endif
373401
#endif
374402
BIO_printf(bio_err," -legacy_renegotiation - enable use of legacy renegotiation (dangerous)\n");
375403
BIO_printf(bio_err," -use_srtp profiles - Offer SRTP key management with a colon-separated profile list\n");
@@ -823,8 +851,10 @@ static char *jpake_secret = NULL;
823851
c_tlsextdebug=1;
824852
else if (strcmp(*argv,"-status") == 0)
825853
c_status_req=1;
826-
else if (strcmp(*argv,"-proof_debug") == 0)
827-
c_proof_debug=1;
854+
else if (strcmp(*argv,"-auth") == 0)
855+
c_auth = 1;
856+
else if (strcmp(*argv,"-auth_require_reneg") == 0)
857+
c_auth_require_reneg = 1;
828858
#endif
829859
#ifdef WATT32
830860
else if (strcmp(*argv,"-wdebug") == 0)
@@ -1399,9 +1429,12 @@ static char *jpake_secret = NULL;
13991429
}
14001430

14011431
#endif
1402-
if (c_proof_debug)
1403-
SSL_CTX_set_tlsext_authz_server_audit_proof_cb(ctx,
1404-
audit_proof_cb);
1432+
if (c_auth)
1433+
{
1434+
SSL_CTX_set_custom_cli_ext(ctx, TLSEXT_TYPE_client_authz, authz_tlsext_generate_cb, authz_tlsext_cb, bio_err);
1435+
SSL_CTX_set_custom_cli_ext(ctx, TLSEXT_TYPE_server_authz, authz_tlsext_generate_cb, authz_tlsext_cb, bio_err);
1436+
SSL_CTX_set_cli_supp_data(ctx, TLSEXT_SUPPLEMENTALDATATYPE_authz_data, suppdata_cb, auth_suppdata_generate_cb, bio_err);
1437+
}
14051438
#endif
14061439

14071440
con=SSL_new(ctx);
@@ -2395,26 +2428,76 @@ static int ocsp_resp_cb(SSL *s, void *arg)
23952428
return 1;
23962429
}
23972430

2398-
static int audit_proof_cb(SSL *s, void *arg)
2431+
static int authz_tlsext_cb(SSL *s, unsigned short ext_type,
2432+
const unsigned char *in,
2433+
unsigned short inlen, int *al,
2434+
void *arg)
23992435
{
2400-
const unsigned char *proof;
2401-
size_t proof_len;
2402-
size_t i;
2403-
SSL_SESSION *sess = SSL_get_session(s);
2404-
2405-
proof = SSL_SESSION_get_tlsext_authz_server_audit_proof(sess,
2406-
&proof_len);
2407-
if (proof != NULL)
2436+
if (TLSEXT_TYPE_server_authz == ext_type)
24082437
{
2409-
BIO_printf(bio_c_out, "Audit proof: ");
2410-
for (i = 0; i < proof_len; ++i)
2411-
BIO_printf(bio_c_out, "%02X", proof[i]);
2412-
BIO_printf(bio_c_out, "\n");
2438+
server_provided_server_authz = (memchr(in,
2439+
TLSEXT_AUTHZDATAFORMAT_dtcp,
2440+
inlen) != NULL);
24132441
}
2414-
else
2442+
2443+
if (TLSEXT_TYPE_client_authz == ext_type)
2444+
{
2445+
server_provided_client_authz = (memchr(in,
2446+
TLSEXT_AUTHZDATAFORMAT_dtcp,
2447+
inlen) != NULL);
2448+
}
2449+
2450+
return 1;
2451+
}
2452+
2453+
static int authz_tlsext_generate_cb(SSL *s, unsigned short ext_type,
2454+
const unsigned char **out, unsigned short *outlen,
2455+
void *arg)
2456+
{
2457+
if (c_auth)
24152458
{
2416-
BIO_printf(bio_c_out, "No audit proof found.\n");
2459+
if (!c_auth_require_reneg || (c_auth_require_reneg && SSL_num_renegotiations(s)))
2460+
{
2461+
*out = auth_ext_data;
2462+
*outlen = 1;
2463+
return 1;
2464+
}
2465+
}
2466+
//no auth extension to send
2467+
return -1;
2468+
}
2469+
2470+
static int suppdata_cb(SSL *s, unsigned short supp_data_type,
2471+
const unsigned char *in,
2472+
unsigned short inlen, int *al,
2473+
void *arg)
2474+
{
2475+
if (supp_data_type == TLSEXT_SUPPLEMENTALDATATYPE_authz_data)
2476+
{
2477+
most_recent_supplemental_data = in;
2478+
most_recent_supplemental_data_length = inlen;
24172479
}
24182480
return 1;
24192481
}
2482+
2483+
static int auth_suppdata_generate_cb(SSL *s, unsigned short supp_data_type,
2484+
const unsigned char **out,
2485+
unsigned short *outlen, void *arg)
2486+
{
2487+
unsigned char *result;
2488+
if (c_auth && server_provided_client_authz && server_provided_server_authz)
2489+
{
2490+
if (!c_auth_require_reneg || (c_auth_require_reneg && SSL_num_renegotiations(s)))
2491+
{
2492+
result = OPENSSL_malloc(10);
2493+
memcpy(result, "5432154321", 10);
2494+
*out = result;
2495+
*outlen = 10;
2496+
return 1;
2497+
}
2498+
}
2499+
//no supplemental data to send
2500+
return -1;
2501+
}
2502+
24202503
#endif

0 commit comments

Comments
 (0)