1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10 #include "tls_common.h"
12 static PRTime
FixedTime(void*) { return 1234; }
14 // Fix the time input, to avoid any time-based variation.
15 void FixTime(PRFileDesc
* fd
) {
16 SECStatus rv
= SSL_SetTimeFunc(fd
, FixedTime
, nullptr);
17 assert(rv
== SECSuccess
);
20 PRStatus
EnableAllProtocolVersions() {
21 SSLVersionRange supported
;
23 SECStatus rv
= SSL_VersionRangeGetSupported(ssl_variant_stream
, &supported
);
24 assert(rv
== SECSuccess
);
26 rv
= SSL_VersionRangeSetDefault(ssl_variant_stream
, &supported
);
27 assert(rv
== SECSuccess
);
32 void EnableAllCipherSuites(PRFileDesc
* fd
) {
33 for (uint16_t i
= 0; i
< SSL_NumImplementedCiphers
; ++i
) {
34 SECStatus rv
= SSL_CipherPrefSet(fd
, SSL_ImplementedCiphers
[i
], true);
35 assert(rv
== SECSuccess
);
39 void DoHandshake(PRFileDesc
* fd
, bool isServer
) {
40 SECStatus rv
= SSL_ResetHandshake(fd
, isServer
);
41 assert(rv
== SECSuccess
);
44 rv
= SSL_ForceHandshake(fd
);
45 } while (rv
!= SECSuccess
&& PR_GetError() == PR_WOULD_BLOCK_ERROR
);
47 // If the handshake succeeds, let's read some data from the server, if any.
48 if (rv
== SECSuccess
) {
52 // Read application data and echo it back.
53 while ((nb
= PR_Read(fd
, block
, sizeof(block
))) > 0) {
54 PR_Write(fd
, block
, nb
);