@@ -42,7 +42,9 @@ static char certificate[] =
42
42
"WbyxPJNtSlA9GfKBz1INR5cFsOL27VrBoMYHMaolveeslc1AW2HfBtXWXeWSEF7F\n"
43
43
"QNgye8ZDPNzeSWSI0VyK2762wsTgTuUhHAaJ45660eX57+e8IvaM7xOEfBPDKYtU\n"
44
44
"0a28ZuhvSr2akJtGCwcs2J6rs6I+rV84UktDxFC9LUezBo8D9FkMPLoPKKNH1dXR\n"
45
- "6LO8GOkqWUrhPIEmfy9KYes3q2ZX6svk4rwBtommHRv30kPxnnU1YXt52Ri+XczO\n" "wEs=\n" "-----END CERTIFICATE-----\n" ;
45
+ "6LO8GOkqWUrhPIEmfy9KYes3q2ZX6svk4rwBtommHRv30kPxnnU1YXt52Ri+XczO\n"
46
+ "wEs=\n"
47
+ "-----END CERTIFICATE-----\n" ;
46
48
47
49
static char private_key [] =
48
50
"-----BEGIN RSA PRIVATE KEY-----\n"
@@ -69,17 +71,21 @@ static char private_key[] =
69
71
"pRsovQKpiHQNgHizkwM861GqqrfisZZSyKfFlcynkACoVmyu7fv9VoD2VCMiqdUq\n"
70
72
"IvjNmfE5RnXVQwja+668AS+MHi+GF77DTFBxoC5VHDAnXfLyIL9WWh9GEBoNLnKT\n"
71
73
"hVm8RQKBgQCB9Skzdftc+14a4Vj3NCgdHZHz9mcdPhzJXUiQyZ3tYhaytX9E8mWq\n"
72
- "pm/OFqahbxw6EQd86mgANBMKayD6B1Id1INqtXN1XYI50bSs1D2nOGsBM7MK9aWD\n" "JXlJ2hwsIc4q9En/LR3GtBaL84xTHGfznNylNhXi7GbO1wNMJuAukA==\n" "-----END RSA PRIVATE KEY-----\n" ;
74
+ "pm/OFqahbxw6EQd86mgANBMKayD6B1Id1INqtXN1XYI50bSs1D2nOGsBM7MK9aWD\n"
75
+ "JXlJ2hwsIc4q9En/LR3GtBaL84xTHGfznNylNhXi7GbO1wNMJuAukA==\n"
76
+ "-----END RSA PRIVATE KEY-----\n" ;
73
77
74
78
static char dhparams [] =
75
79
"-----BEGIN DH PARAMETERS-----\n"
76
80
"MIIBCAKCAQEAy1+hVWCfNQoPB+NA733IVOONl8fCumiz9zdRRu1hzVa2yvGseUSq\n"
77
81
"Bbn6k0FQ7yMED6w5XWQKDC0z2m0FI/BPE3AjUfuPzEYGqTDf9zQZ2Lz4oAN90Sud\n"
78
82
"luOoEhYR99cEbCn0T4eBvEf9IUtczXUZ/wj7gzGbGG07dLfT+CmCRJxCjhrosenJ\n"
79
83
"gzucyS7jt1bobgU66JKkgMNm7hJY4/nhR5LWTCzZyzYQh2HM2Vk4K5ZqILpj/n0S\n"
80
- "5JYTQ2PVhxP+Uu8+hICs/8VvM72DznjPZzufADipjC7CsQ4S6x/ecZluFtbb+ZTv\n" "HI5CnYmkAwJ6+FSWGaZQDi8bgerFk9RWwwIBAg==\n" "-----END DH PARAMETERS-----\n" ;
84
+ "5JYTQ2PVhxP+Uu8+hICs/8VvM72DznjPZzufADipjC7CsQ4S6x/ecZluFtbb+ZTv\n"
85
+ "HI5CnYmkAwJ6+FSWGaZQDi8bgerFk9RWwwIBAg==\n"
86
+ "-----END DH PARAMETERS-----\n" ;
81
87
82
- int mock_client (int writefd , int readfd )
88
+ void mock_client (int writefd , int readfd )
83
89
{
84
90
char buffer [0xffff ];
85
91
struct s2n_connection * conn ;
@@ -99,10 +105,10 @@ int mock_client(int writefd, int readfd)
99
105
for (int j = 0 ; j < i ; j ++ ) {
100
106
buffer [j ] = 33 ;
101
107
}
102
-
108
+
103
109
s2n_send (conn , buffer , i , & more );
104
110
}
105
-
111
+
106
112
s2n_shutdown (conn , & more );
107
113
s2n_connection_free (conn );
108
114
@@ -127,71 +133,75 @@ int main(int argc, char **argv)
127
133
128
134
/* Create a pipe */
129
135
EXPECT_SUCCESS (s2n_init ());
130
- EXPECT_SUCCESS (pipe (server_to_client ));
131
- EXPECT_SUCCESS (pipe (client_to_server ));
132
-
133
- /* Create a child process */
134
- pid = fork ();
135
- if (pid == 0 ) {
136
- /* This is the child process, close the read end of the pipe */
137
- EXPECT_SUCCESS (close (client_to_server [0 ]));
138
- EXPECT_SUCCESS (close (server_to_client [1 ]));
139
-
140
- /* Write the fragmented hello message */
141
- mock_client (client_to_server [1 ], server_to_client [0 ]);
142
- }
143
136
144
- /* This is the parent */
145
- EXPECT_SUCCESS (close ( client_to_server [ 1 ] ));
146
- EXPECT_SUCCESS (close ( server_to_client [ 0 ] ));
137
+ for ( int is_dh_key_exchange = 0 ; is_dh_key_exchange <= 1 ; is_dh_key_exchange ++ ) {
138
+ EXPECT_SUCCESS (pipe ( server_to_client ));
139
+ EXPECT_SUCCESS (pipe ( client_to_server ));
147
140
148
- EXPECT_NOT_NULL (conn = s2n_connection_new (S2N_SERVER ));
149
- EXPECT_NOT_NULL (config = s2n_config_new ());
141
+ /* Create a child process */
142
+ pid = fork ();
143
+ if (pid == 0 ) {
144
+ /* This is the child process, close the read end of the pipe */
145
+ EXPECT_SUCCESS (close (client_to_server [0 ]));
146
+ EXPECT_SUCCESS (close (server_to_client [1 ]));
150
147
151
- EXPECT_SUCCESS (s2n_config_add_cert_chain_and_key (config , certificate , private_key ));
152
- EXPECT_SUCCESS (s2n_config_add_dhparams (config , dhparams ));
153
-
154
- EXPECT_SUCCESS (s2n_connection_set_config (conn , config ));
148
+ /* Write the fragmented hello message */
149
+ mock_client (client_to_server [1 ], server_to_client [0 ]);
150
+ }
155
151
156
- /* Set up the connection to read from the fd */
157
- EXPECT_SUCCESS (s2n_connection_set_read_fd ( conn , client_to_server [0 ]));
158
- EXPECT_SUCCESS (s2n_connection_set_write_fd ( conn , server_to_client [1 ]));
152
+ /* This is the parent */
153
+ EXPECT_SUCCESS (close ( client_to_server [1 ]));
154
+ EXPECT_SUCCESS (close ( server_to_client [0 ]));
159
155
160
- /* Negotiate the handshake. */
161
- EXPECT_SUCCESS ( s2n_negotiate ( conn , & status ));
156
+ EXPECT_NOT_NULL ( conn = s2n_connection_new ( S2N_SERVER ));
157
+ EXPECT_NOT_NULL ( config = s2n_config_new ( ));
162
158
163
- char buffer [0xffff ];
164
- for (int i = 1 ; i < 0xffff ; i += 100 ) {
165
- char * ptr = buffer ;
166
- int bytes_read = 0 ;
167
- int size = i ;
159
+ EXPECT_SUCCESS (s2n_config_add_cert_chain_and_key (config , certificate , private_key ));
160
+ if (is_dh_key_exchange ) {
161
+ EXPECT_SUCCESS (s2n_config_add_dhparams (config , dhparams ));
162
+ }
168
163
169
- do {
170
- EXPECT_SUCCESS (bytes_read = s2n_recv (conn , ptr , size , & status ));
164
+ EXPECT_SUCCESS (s2n_connection_set_config (conn , config ));
171
165
172
- size -= bytes_read ;
173
- ptr += bytes_read ;
174
- } while ( size );
166
+ /* Set up the connection to read from the fd */
167
+ EXPECT_SUCCESS ( s2n_connection_set_read_fd ( conn , client_to_server [ 0 ])) ;
168
+ EXPECT_SUCCESS ( s2n_connection_set_write_fd ( conn , server_to_client [ 1 ]) );
175
169
176
- for (int j = 0 ; j < i ; j ++ ) {
177
- EXPECT_EQUAL (buffer [j ], 33 );
170
+ /* Negotiate the handshake. */
171
+ EXPECT_SUCCESS (s2n_negotiate (conn , & status ));
172
+
173
+ char buffer [0xffff ];
174
+ for (int i = 1 ; i < 0xffff ; i += 100 ) {
175
+ char * ptr = buffer ;
176
+ int bytes_read = 0 ;
177
+ int size = i ;
178
+
179
+ do {
180
+ EXPECT_SUCCESS (bytes_read = s2n_recv (conn , ptr , size , & status ));
181
+
182
+ size -= bytes_read ;
183
+ ptr += bytes_read ;
184
+ } while (size );
185
+
186
+ for (int j = 0 ; j < i ; j ++ ) {
187
+ EXPECT_EQUAL (buffer [j ], 33 );
188
+ }
178
189
}
179
- }
180
-
181
- /* Verify that read() returns EOF */
182
- EXPECT_SUCCESS (s2n_recv (conn , buffer , 1 , & status ));
183
-
184
- EXPECT_SUCCESS (s2n_shutdown (conn , & status ));
185
-
186
- EXPECT_SUCCESS (s2n_connection_free (conn ));
187
190
188
- EXPECT_SUCCESS (s2n_config_free (config ));
191
+ /* Verify that read() returns EOF */
192
+ EXPECT_SUCCESS (s2n_recv (conn , buffer , 1 , & status ));
189
193
190
- /* Clean up */
191
- EXPECT_EQUAL (waitpid (-1 , & status , 0 ), pid );
192
- EXPECT_EQUAL (status , 0 );
194
+ EXPECT_SUCCESS (s2n_shutdown (conn , & status ));
193
195
194
- END_TEST ( );
196
+ EXPECT_SUCCESS ( s2n_connection_free ( conn ) );
195
197
198
+ EXPECT_SUCCESS (s2n_config_free (config ));
199
+
200
+ /* Clean up */
201
+ EXPECT_EQUAL (waitpid (-1 , & status , 0 ), pid );
202
+ EXPECT_EQUAL (status , 0 );
203
+ }
204
+
205
+ END_TEST ();
196
206
return 0 ;
197
207
}
0 commit comments