@@ -383,6 +383,56 @@ DECLARE_STACK_OF(SRTP_PROTECTION_PROFILE)
383383typedef int (* tls_session_ticket_ext_cb_fn )(SSL * s , const unsigned char * data , int len , void * arg );
384384typedef int (* tls_session_secret_cb_fn )(SSL * s , void * secret , int * secret_len , STACK_OF (SSL_CIPHER ) * peer_ciphers , SSL_CIPHER * * cipher , void * arg );
385385
386+ #ifndef OPENSSL_NO_TLSEXT
387+ /* Callbacks and structures for handling custom TLS Extensions:
388+ * cli_ext_first_cb - sends data for ClientHello TLS Extension
389+ * cli_ext_second_cb - receives data from ServerHello TLS Extension
390+ * srv_ext_first_cb - receives data from ClientHello TLS Extension
391+ * srv_ext_second_cb - sends data for ServerHello TLS Extension
392+ *
393+ * All these functions return nonzero on success. Zero will terminate
394+ * the handshake (and return a specific TLS Fatal alert, if the function
395+ * declaration has an "al" parameter).
396+ *
397+ * "ext_type" is a TLS "ExtensionType" from 0-65535.
398+ * "in" is a pointer to TLS "extension_data" being provided to the cb.
399+ * "out" is used by the callback to return a pointer to "extension data"
400+ * which OpenSSL will later copy into the TLS handshake. The contents
401+ * of this buffer should not be changed until the handshake is complete.
402+ * "inlen" and "outlen" are TLS Extension lengths from 0-65535.
403+ * "al" is a TLS "AlertDescription" from 0-255 which WILL be sent as a
404+ * fatal TLS alert, if the callback returns zero.
405+ */
406+ typedef int (* custom_cli_ext_first_cb_fn )(SSL * s , unsigned short ext_type ,
407+ const unsigned char * * out ,
408+ unsigned short * outlen , void * arg );
409+ typedef int (* custom_cli_ext_second_cb_fn )(SSL * s , unsigned short ext_type ,
410+ const unsigned char * in ,
411+ unsigned short inlen , int * al ,
412+ void * arg );
413+
414+ typedef int (* custom_srv_ext_first_cb_fn )(SSL * s , unsigned short ext_type ,
415+ const unsigned char * in ,
416+ unsigned short inlen , int * al ,
417+ void * arg );
418+ typedef int (* custom_srv_ext_second_cb_fn )(SSL * s , unsigned short ext_type ,
419+ const unsigned char * * out ,
420+ unsigned short * outlen , void * arg );
421+
422+ typedef struct {
423+ unsigned short ext_type ;
424+ custom_cli_ext_first_cb_fn fn1 ;
425+ custom_cli_ext_second_cb_fn fn2 ;
426+ void * arg ;
427+ } custom_cli_ext_record ;
428+
429+ typedef struct {
430+ unsigned short ext_type ;
431+ custom_srv_ext_first_cb_fn fn1 ;
432+ custom_srv_ext_second_cb_fn fn2 ;
433+ void * arg ;
434+ } custom_srv_ext_record ;
435+ #endif
386436
387437#ifndef OPENSSL_NO_SSL_INTERN
388438
@@ -1064,6 +1114,12 @@ struct ssl_ctx_st
10641114# endif /* OPENSSL_NO_EC */
10651115 int (* tlsext_authz_server_audit_proof_cb )(SSL * s , void * arg );
10661116 void * tlsext_authz_server_audit_proof_cb_arg ;
1117+
1118+ /* Arrays containing the callbacks for custom TLS Extensions. */
1119+ custom_cli_ext_record * custom_cli_ext_records ;
1120+ size_t custom_cli_ext_records_count ;
1121+ custom_srv_ext_record * custom_srv_ext_records ;
1122+ size_t custom_srv_ext_records_count ;
10671123 };
10681124
10691125#endif
@@ -1170,6 +1226,33 @@ const char *SSL_get_psk_identity_hint(const SSL *s);
11701226const char * SSL_get_psk_identity (const SSL * s );
11711227#endif
11721228
1229+ #ifndef OPENSSL_NO_TLSEXT
1230+ /* Register callbacks to handle custom TLS Extensions as client or server.
1231+ *
1232+ * Returns nonzero on success. You cannot register twice for the same
1233+ * extension number, and registering for an extension number already
1234+ * handled by OpenSSL will succeed, but the callbacks will not be invoked.
1235+ *
1236+ * NULL can be registered for any callback function. For the client
1237+ * functions, a NULL custom_cli_ext_first_cb_fn sends an empty ClientHello
1238+ * Extension, and a NULL custom_cli_ext_second_cb_fn ignores the ServerHello
1239+ * response (if any).
1240+ *
1241+ * For the server functions, a NULL custom_srv_ext_first_cb_fn means the
1242+ * ClientHello extension's data will be ignored, but the extension will still
1243+ * be noted and custom_srv_ext_second_cb_fn will still be invoked. If
1244+ * custom_srv_ext_second_cb_fn is NULL, an empty ServerHello extension is
1245+ * sent.
1246+ */
1247+ int SSL_CTX_set_custom_cli_ext (SSL_CTX * ctx , unsigned short ext_type ,
1248+ custom_cli_ext_first_cb_fn fn1 ,
1249+ custom_cli_ext_second_cb_fn fn2 , void * arg );
1250+
1251+ int SSL_CTX_set_custom_srv_ext (SSL_CTX * ctx , unsigned short ext_type ,
1252+ custom_srv_ext_first_cb_fn fn1 ,
1253+ custom_srv_ext_second_cb_fn fn2 , void * arg );
1254+ #endif
1255+
11731256#define SSL_NOTHING 1
11741257#define SSL_WRITING 2
11751258#define SSL_READING 3
@@ -1934,6 +2017,14 @@ const unsigned char *SSL_CTX_get_authz_data(SSL_CTX *ctx, unsigned char type,
19342017int SSL_CTX_use_authz_file (SSL_CTX * ctx , const char * file );
19352018int SSL_use_authz_file (SSL * ssl , const char * file );
19362019#endif
2020+
2021+ /* Set serverinfo data for the current active cert. */
2022+ int SSL_CTX_use_serverinfo (SSL_CTX * ctx , const unsigned char * serverinfo ,
2023+ size_t serverinfo_length );
2024+ #ifndef OPENSSL_NO_STDIO
2025+ int SSL_CTX_use_serverinfo_file (SSL_CTX * ctx , const char * file );
2026+ #endif /* NO_STDIO */
2027+
19372028#endif
19382029
19392030#ifndef OPENSSL_NO_STDIO
@@ -2481,6 +2572,8 @@ void ERR_load_SSL_strings(void);
24812572#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY 177
24822573#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1 178
24832574#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE 179
2575+ #define SSL_F_SSL_CTX_USE_SERVERINFO 336
2576+ #define SSL_F_SSL_CTX_USE_SERVERINFO_FILE 337
24842577#define SSL_F_SSL_DO_HANDSHAKE 180
24852578#define SSL_F_SSL_GET_NEW_SESSION 181
24862579#define SSL_F_SSL_GET_PREV_SESSION 217
@@ -2655,6 +2748,7 @@ void ERR_load_SSL_strings(void);
26552748#define SSL_R_INVALID_COMPRESSION_ALGORITHM 341
26562749#define SSL_R_INVALID_NULL_CMD_NAME 385
26572750#define SSL_R_INVALID_PURPOSE 278
2751+ #define SSL_R_INVALID_SERVERINFO_DATA 388
26582752#define SSL_R_INVALID_SRP_USERNAME 357
26592753#define SSL_R_INVALID_STATUS_RESPONSE 328
26602754#define SSL_R_INVALID_TICKET_KEYS_LENGTH 325
0 commit comments