-#define MAX_PRINTABLE_CHARACTERS 1024
-
-typedef struct heartbeat_test_fixture
- {
- SSL_CTX *ctx;
- SSL *s;
- const char* test_case_name;
- int (*process_heartbeat)(SSL* s);
- unsigned char* payload;
- int sent_payload_len;
- int expected_return_value;
- int return_payload_offset;
- int expected_payload_len;
- const char* expected_return_payload;
- } HEARTBEAT_TEST_FIXTURE;
-
-static HEARTBEAT_TEST_FIXTURE set_up(const char* const test_case_name,
- const SSL_METHOD* meth)
- {
- HEARTBEAT_TEST_FIXTURE fixture;
- int setup_ok = 1;
- memset(&fixture, 0, sizeof(fixture));
- fixture.test_case_name = test_case_name;
-
- fixture.ctx = SSL_CTX_new(meth);
- if (!fixture.ctx)
- {
- fprintf(stderr, "Failed to allocate SSL_CTX for test: %s\n",
- test_case_name);
- setup_ok = 0;
- goto fail;
- }
-
- fixture.s = SSL_new(fixture.ctx);
- if (!fixture.s)
- {
- fprintf(stderr, "Failed to allocate SSL for test: %s\n", test_case_name);
- setup_ok = 0;
- goto fail;
- }
-
- if (!ssl_init_wbio_buffer(fixture.s, 1))
- {
- fprintf(stderr, "Failed to set up wbio buffer for test: %s\n",
- test_case_name);
- setup_ok = 0;
- goto fail;
- }
-
- if (!ssl3_setup_buffers(fixture.s))
- {
- fprintf(stderr, "Failed to setup buffers for test: %s\n",
- test_case_name);
- setup_ok = 0;
- goto fail;
- }
-
- /* Clear the memory for the return buffer, since this isn't automatically
- * zeroed in opt mode and will cause spurious test failures that will change
- * with each execution.
- */
- memset(fixture.s->s3->wbuf.buf, 0, fixture.s->s3->wbuf.len);
-
- fail:
- if (!setup_ok)
- {
- ERR_print_errors_fp(stderr);
- exit(EXIT_FAILURE);
- }
- return fixture;
- }
-
-static HEARTBEAT_TEST_FIXTURE set_up_dtls(const char* const test_case_name)
- {
- HEARTBEAT_TEST_FIXTURE fixture = set_up(test_case_name,
- DTLSv1_server_method());
- fixture.process_heartbeat = dtls1_process_heartbeat;
-
- /* As per dtls1_get_record(), skipping the following from the beginning of
- * the returned heartbeat message:
- * type-1 byte; version-2 bytes; sequence number-8 bytes; length-2 bytes
- *
- * And then skipping the 1-byte type encoded by process_heartbeat for
- * a total of 14 bytes, at which point we can grab the length and the
- * payload we seek.
- */
- fixture.return_payload_offset = 14;
- return fixture;
- }
+# define MAX_PRINTABLE_CHARACTERS 1024
+
+typedef struct heartbeat_test_fixture {
+ SSL_CTX *ctx;
+ SSL *s;
+ const char *test_case_name;
+ int (*process_heartbeat) (SSL *s, unsigned char *p, unsigned int length);
+ unsigned char *payload;
+ int sent_payload_len;
+ int expected_return_value;
+ int return_payload_offset;
+ int expected_payload_len;
+ const char *expected_return_payload;
+} HEARTBEAT_TEST_FIXTURE;
+
+static HEARTBEAT_TEST_FIXTURE set_up(const char *const test_case_name,
+ const SSL_METHOD *meth)
+{
+ HEARTBEAT_TEST_FIXTURE fixture;
+ int setup_ok = 1;
+ memset(&fixture, 0, sizeof(fixture));
+ fixture.test_case_name = test_case_name;
+
+ fixture.ctx = SSL_CTX_new(meth);
+ if (!fixture.ctx) {
+ fprintf(stderr, "Failed to allocate SSL_CTX for test: %s\n",
+ test_case_name);
+ setup_ok = 0;
+ goto fail;
+ }
+
+ fixture.s = SSL_new(fixture.ctx);
+ if (!fixture.s) {
+ fprintf(stderr, "Failed to allocate SSL for test: %s\n",
+ test_case_name);
+ setup_ok = 0;
+ goto fail;
+ }
+
+ if (!ssl_init_wbio_buffer(fixture.s, 1)) {
+ fprintf(stderr, "Failed to set up wbio buffer for test: %s\n",
+ test_case_name);
+ setup_ok = 0;
+ goto fail;
+ }
+
+ if (!ssl3_setup_buffers(fixture.s)) {
+ fprintf(stderr, "Failed to setup buffers for test: %s\n",
+ test_case_name);
+ setup_ok = 0;
+ goto fail;
+ }
+
+ /*
+ * Clear the memory for the return buffer, since this isn't automatically
+ * zeroed in opt mode and will cause spurious test failures that will
+ * change with each execution.
+ */
+ memset(fixture.s->rlayer.wbuf.buf, 0, fixture.s->rlayer.wbuf.len);
+
+ fail:
+ if (!setup_ok) {
+ ERR_print_errors_fp(stderr);
+ exit(EXIT_FAILURE);
+ }
+ return fixture;
+}
+
+static HEARTBEAT_TEST_FIXTURE set_up_dtls(const char *const test_case_name)
+{
+ HEARTBEAT_TEST_FIXTURE fixture = set_up(test_case_name,
+ DTLSv1_server_method());
+ fixture.process_heartbeat = dtls1_process_heartbeat;
+
+ /*
+ * As per dtls1_get_record(), skipping the following from the beginning
+ * of the returned heartbeat message: type-1 byte; version-2 bytes;
+ * sequence number-8 bytes; length-2 bytes And then skipping the 1-byte
+ * type encoded by process_heartbeat for a total of 14 bytes, at which
+ * point we can grab the length and the payload we seek.
+ */
+ fixture.return_payload_offset = 14;
+ return fixture;
+}