-static int custom_ext_0_cli_first_cb(SSL *s, unsigned short ext_type,
- const unsigned char **out,
- unsigned short *outlen, int *al, void *arg)
- {
- if (ext_type != CUSTOM_EXT_TYPE_0)
- custom_ext_error = 1;
- return -1; /* Don't send an extension */
- }
-
-static int custom_ext_0_cli_second_cb(SSL *s, unsigned short ext_type,
- const unsigned char *in,
- unsigned short inlen, int *al,
- void *arg)
- {
- return 1;
- }
-
-static int custom_ext_1_cli_first_cb(SSL *s, unsigned short ext_type,
- const unsigned char **out,
- unsigned short *outlen, int *al, void *arg)
- {
- if (ext_type != CUSTOM_EXT_TYPE_1)
- custom_ext_error = 1;
- *out = (const unsigned char*)custom_ext_cli_string;
- *outlen = strlen(custom_ext_cli_string);
- return 1; /* Send "abc" */
- }
-
-static int custom_ext_1_cli_second_cb(SSL *s, unsigned short ext_type,
- const unsigned char *in,
- unsigned short inlen, int *al,
- void *arg)
- {
- return 1;
- }
-
-static int custom_ext_2_cli_first_cb(SSL *s, unsigned short ext_type,
- const unsigned char **out,
- unsigned short *outlen, int *al, void *arg)
- {
- if (ext_type != CUSTOM_EXT_TYPE_2)
- custom_ext_error = 1;
- *out = (const unsigned char*)custom_ext_cli_string;
- *outlen = strlen(custom_ext_cli_string);
- return 1; /* Send "abc" */
- }
-
-static int custom_ext_2_cli_second_cb(SSL *s, unsigned short ext_type,
- const unsigned char *in,
- unsigned short inlen, int *al,
- void *arg)
- {
- if (ext_type != CUSTOM_EXT_TYPE_2)
- custom_ext_error = 1;
- if (inlen != 0)
- custom_ext_error = 1; /* Should be empty response */
- return 1;
- }
-
-static int custom_ext_3_cli_first_cb(SSL *s, unsigned short ext_type,
- const unsigned char **out,
- unsigned short *outlen, int *al, void *arg)
- {
- if (ext_type != CUSTOM_EXT_TYPE_3)
- custom_ext_error = 1;
- *out = (const unsigned char*)custom_ext_cli_string;
- *outlen = strlen(custom_ext_cli_string);
- return 1; /* Send "abc" */
- }
-
-static int custom_ext_3_cli_second_cb(SSL *s, unsigned short ext_type,
- const unsigned char *in,
- unsigned short inlen, int *al,
- void *arg)
- {
- if (ext_type != CUSTOM_EXT_TYPE_3)
- custom_ext_error = 1;
- if (inlen != strlen(custom_ext_srv_string))
- custom_ext_error = 1;
- if (memcmp(custom_ext_srv_string, in, inlen) != 0)
- custom_ext_error = 1; /* Check for "defg" */
- return 1;
- }
-
-/* custom_ext_0_cli_first_cb returns -1 - the server won't receive a callback for this extension */
-static int custom_ext_0_srv_first_cb(SSL *s, unsigned short ext_type,
- const unsigned char *in,
- unsigned short inlen, int *al,
- void *arg)
- {
- return 1;
- }
-
-/* 'generate' callbacks are always called, even if the 'receive' callback isn't called */
-static int custom_ext_0_srv_second_cb(SSL *s, unsigned short ext_type,
- const unsigned char **out,
- unsigned short *outlen, int *al, void *arg)
- {
- return -1; /* Don't send an extension */
- }
-
-static int custom_ext_1_srv_first_cb(SSL *s, unsigned short ext_type,
- const unsigned char *in,
- unsigned short inlen, int *al,
- void *arg)
- {
- if (ext_type != CUSTOM_EXT_TYPE_1)
- custom_ext_error = 1;
- /* Check for "abc" */
- if (inlen != strlen(custom_ext_cli_string))
- custom_ext_error = 1;
- if (memcmp(in, custom_ext_cli_string, inlen) != 0)
- custom_ext_error = 1;
- return 1;
- }
-
-static int custom_ext_1_srv_second_cb(SSL *s, unsigned short ext_type,
- const unsigned char **out,
- unsigned short *outlen, int *al, void *arg)
- {
- return -1; /* Don't send an extension */
- }
-
-static int custom_ext_2_srv_first_cb(SSL *s, unsigned short ext_type,
- const unsigned char *in,
- unsigned short inlen, int *al,
- void *arg)
- {
- if (ext_type != CUSTOM_EXT_TYPE_2)
- custom_ext_error = 1;
- /* Check for "abc" */
- if (inlen != strlen(custom_ext_cli_string))
- custom_ext_error = 1;
- if (memcmp(in, custom_ext_cli_string, inlen) != 0)
- custom_ext_error = 1;
- return 1;
- }
-
-static int custom_ext_2_srv_second_cb(SSL *s, unsigned short ext_type,
- const unsigned char **out,
- unsigned short *outlen, int *al, void *arg)
- {
- *out = NULL;
- *outlen = 0;
- return 1; /* Send empty extension */
- }
-
-static int custom_ext_3_srv_first_cb(SSL *s, unsigned short ext_type,
- const unsigned char *in,
- unsigned short inlen, int *al,
- void *arg)
- {
- if (ext_type != CUSTOM_EXT_TYPE_3)
- custom_ext_error = 1;
- /* Check for "abc" */
- if (inlen != strlen(custom_ext_cli_string))
- custom_ext_error = 1;
- if (memcmp(in, custom_ext_cli_string, inlen) != 0)
- custom_ext_error = 1;
- return 1;
- }
-
-static int custom_ext_3_srv_second_cb(SSL *s, unsigned short ext_type,
- const unsigned char **out,
- unsigned short *outlen, int *al, void *arg)
- {
- *out = (const unsigned char*)custom_ext_srv_string;
- *outlen = strlen(custom_ext_srv_string);
- return 1; /* Send "defg" */
- }
-
-static int supp_data_0_srv_first_cb(SSL *s, unsigned short supp_data_type,
- const unsigned char **out,
- unsigned short *outlen, int *al, void *arg)
- {
- *out = (const unsigned char*)supp_data_0_string;
- *outlen = strlen(supp_data_0_string);
- if (arg != s)
- suppdata_error = 1;
- return 1;
- }
-
-static int supp_data_0_srv_second_cb(SSL *s, unsigned short supp_data_type,
- const unsigned char *in,
- unsigned short inlen, int *al,
- void *arg)
- {
- if (supp_data_type != CUSTOM_SUPP_DATA_TYPE_0)
- suppdata_error = 1;
- if (inlen != strlen(supp_data_0_string))
- suppdata_error = 1;
- if (memcmp(in, supp_data_0_string, inlen) != 0)
- suppdata_error = 1;
- if (arg != s)
- suppdata_error = 1;
- return 1;
- }
-
-static int supp_data_1_srv_first_cb(SSL *s, unsigned short supp_data_type,
- const unsigned char **out,
- unsigned short *outlen, int *al, void *arg)
- {
- return -1;
- }
-
-static int supp_data_1_srv_second_cb(SSL *s, unsigned short supp_data_type,
- const unsigned char *in,
- unsigned short inlen, int *al,
- void *arg)
- {
- suppdata_error = 1;
- return 1;
- }
-
-static int supp_data_2_srv_second_cb(SSL *s, unsigned short supp_data_type,
- const unsigned char *in,
- unsigned short inlen, int *al,
- void *arg)
- {
- suppdata_error = 1;
- return 1;
- }
-
-static int supp_data_0_cli_first_cb(SSL *s, unsigned short supp_data_type,
- const unsigned char *in,
- unsigned short inlen, int *al,
- void *arg)
- {
- if (supp_data_type != CUSTOM_SUPP_DATA_TYPE_0)
- suppdata_error = 1;
- if (inlen != strlen(supp_data_0_string))
- suppdata_error = 1;
- if (memcmp(in, supp_data_0_string, inlen) != 0)
- suppdata_error = 1;
- if (arg != s)
- suppdata_error = 1;
- return 1;
- }
-
-static int supp_data_0_cli_second_cb(SSL *s, unsigned short supp_data_type,
- const unsigned char **out,
- unsigned short *outlen, int *al, void *arg)
- {
- *out = (const unsigned char*)supp_data_0_string;
- *outlen = strlen(supp_data_0_string);
- if (arg != s)
- suppdata_error = 1;
- return 1;
- }
-
-static int supp_data_1_cli_first_cb(SSL *s, unsigned short supp_data_type,
- const unsigned char *in,
- unsigned short inlen, int *al,
- void *arg)
- {
- suppdata_error = 1;
- return 1;
- }
-
-static int supp_data_1_cli_second_cb(SSL *s, unsigned short supp_data_type,
- const unsigned char **out,
- unsigned short *outlen, int *al, void *arg)
- {
- return -1;
- }
-
-static int supp_data_2_cli_first_cb(SSL *s, unsigned short supp_data_type,
- const unsigned char *in,
- unsigned short inlen, int *al,
- void *arg)
- {
- suppdata_error = 1;
- return 1;
- }
-
-static char *cipher=NULL;
-static int verbose=0;
-static int debug=0;
+static int custom_ext_0_cli_add_cb(SSL *s, unsigned int ext_type,
+ const unsigned char **out,
+ size_t *outlen, int *al, void *arg)
+{
+ if (ext_type != CUSTOM_EXT_TYPE_0)
+ custom_ext_error = 1;
+ return 0; /* Don't send an extension */
+}
+
+static int custom_ext_0_cli_parse_cb(SSL *s, unsigned int ext_type,
+ const unsigned char *in,
+ size_t inlen, int *al, void *arg)
+{
+ return 1;
+}
+
+static int custom_ext_1_cli_add_cb(SSL *s, unsigned int ext_type,
+ const unsigned char **out,
+ size_t *outlen, int *al, void *arg)
+{
+ if (ext_type != CUSTOM_EXT_TYPE_1)
+ custom_ext_error = 1;
+ *out = (const unsigned char *)custom_ext_cli_string;
+ *outlen = strlen(custom_ext_cli_string);
+ return 1; /* Send "abc" */
+}
+
+static int custom_ext_1_cli_parse_cb(SSL *s, unsigned int ext_type,
+ const unsigned char *in,
+ size_t inlen, int *al, void *arg)
+{
+ return 1;
+}
+
+static int custom_ext_2_cli_add_cb(SSL *s, unsigned int ext_type,
+ const unsigned char **out,
+ size_t *outlen, int *al, void *arg)
+{
+ if (ext_type != CUSTOM_EXT_TYPE_2)
+ custom_ext_error = 1;
+ *out = (const unsigned char *)custom_ext_cli_string;
+ *outlen = strlen(custom_ext_cli_string);
+ return 1; /* Send "abc" */
+}
+
+static int custom_ext_2_cli_parse_cb(SSL *s, unsigned int ext_type,
+ const unsigned char *in,
+ size_t inlen, int *al, void *arg)
+{
+ if (ext_type != CUSTOM_EXT_TYPE_2)
+ custom_ext_error = 1;
+ if (inlen != 0)
+ custom_ext_error = 1; /* Should be empty response */
+ return 1;
+}
+
+static int custom_ext_3_cli_add_cb(SSL *s, unsigned int ext_type,
+ const unsigned char **out,
+ size_t *outlen, int *al, void *arg)
+{
+ if (ext_type != CUSTOM_EXT_TYPE_3)
+ custom_ext_error = 1;
+ *out = (const unsigned char *)custom_ext_cli_string;
+ *outlen = strlen(custom_ext_cli_string);
+ return 1; /* Send "abc" */
+}
+
+static int custom_ext_3_cli_parse_cb(SSL *s, unsigned int ext_type,
+ const unsigned char *in,
+ size_t inlen, int *al, void *arg)
+{
+ if (ext_type != CUSTOM_EXT_TYPE_3)
+ custom_ext_error = 1;
+ if (inlen != strlen(custom_ext_srv_string))
+ custom_ext_error = 1;
+ if (memcmp(custom_ext_srv_string, in, inlen) != 0)
+ custom_ext_error = 1; /* Check for "defg" */
+ return 1;
+}
+
+/*
+ * custom_ext_0_cli_add_cb returns 0 - the server won't receive a callback
+ * for this extension
+ */
+static int custom_ext_0_srv_parse_cb(SSL *s, unsigned int ext_type,
+ const unsigned char *in,
+ size_t inlen, int *al, void *arg)
+{
+ custom_ext_error = 1;
+ return 1;
+}
+
+/* 'add' callbacks are only called if the 'parse' callback is called */
+static int custom_ext_0_srv_add_cb(SSL *s, unsigned int ext_type,
+ const unsigned char **out,
+ size_t *outlen, int *al, void *arg)
+{
+ /* Error: should not have been called */
+ custom_ext_error = 1;
+ return 0; /* Don't send an extension */
+}
+
+static int custom_ext_1_srv_parse_cb(SSL *s, unsigned int ext_type,
+ const unsigned char *in,
+ size_t inlen, int *al, void *arg)
+{
+ if (ext_type != CUSTOM_EXT_TYPE_1)
+ custom_ext_error = 1;
+ /* Check for "abc" */
+ if (inlen != strlen(custom_ext_cli_string))
+ custom_ext_error = 1;
+ if (memcmp(in, custom_ext_cli_string, inlen) != 0)
+ custom_ext_error = 1;
+ return 1;
+}
+
+static int custom_ext_1_srv_add_cb(SSL *s, unsigned int ext_type,
+ const unsigned char **out,
+ size_t *outlen, int *al, void *arg)
+{
+ return 0; /* Don't send an extension */
+}
+
+static int custom_ext_2_srv_parse_cb(SSL *s, unsigned int ext_type,
+ const unsigned char *in,
+ size_t inlen, int *al, void *arg)
+{
+ if (ext_type != CUSTOM_EXT_TYPE_2)
+ custom_ext_error = 1;
+ /* Check for "abc" */
+ if (inlen != strlen(custom_ext_cli_string))
+ custom_ext_error = 1;
+ if (memcmp(in, custom_ext_cli_string, inlen) != 0)
+ custom_ext_error = 1;
+ return 1;
+}
+
+static int custom_ext_2_srv_add_cb(SSL *s, unsigned int ext_type,
+ const unsigned char **out,
+ size_t *outlen, int *al, void *arg)
+{
+ *out = NULL;
+ *outlen = 0;
+ return 1; /* Send empty extension */
+}
+
+static int custom_ext_3_srv_parse_cb(SSL *s, unsigned int ext_type,
+ const unsigned char *in,
+ size_t inlen, int *al, void *arg)
+{
+ if (ext_type != CUSTOM_EXT_TYPE_3)
+ custom_ext_error = 1;
+ /* Check for "abc" */
+ if (inlen != strlen(custom_ext_cli_string))
+ custom_ext_error = 1;
+ if (memcmp(in, custom_ext_cli_string, inlen) != 0)
+ custom_ext_error = 1;
+ return 1;
+}
+
+static int custom_ext_3_srv_add_cb(SSL *s, unsigned int ext_type,
+ const unsigned char **out,
+ size_t *outlen, int *al, void *arg)
+{
+ *out = (const unsigned char *)custom_ext_srv_string;
+ *outlen = strlen(custom_ext_srv_string);
+ return 1; /* Send "defg" */
+}
+
+static char *cipher = NULL;
+static int verbose = 0;
+static int debug = 0;