/src/nss/fuzz/tls_common.cc
Line | Count | Source (jump to first uncovered line) |
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/. */ |
4 | | |
5 | | #include <assert.h> |
6 | | |
7 | | #include "ssl.h" |
8 | | #include "sslexp.h" |
9 | | |
10 | | #include "tls_common.h" |
11 | | |
12 | 10.1k | static PRTime FixedTime(void*) { return 1234; } |
13 | | |
14 | | // Fix the time input, to avoid any time-based variation. |
15 | 9.71k | void FixTime(PRFileDesc* fd) { |
16 | 9.71k | SECStatus rv = SSL_SetTimeFunc(fd, FixedTime, nullptr); |
17 | 9.71k | assert(rv == SECSuccess); |
18 | 9.71k | } |
19 | | |
20 | 9.71k | PRStatus EnableAllProtocolVersions() { |
21 | 9.71k | SSLVersionRange supported; |
22 | | |
23 | 9.71k | SECStatus rv = SSL_VersionRangeGetSupported(ssl_variant_stream, &supported); |
24 | 9.71k | assert(rv == SECSuccess); |
25 | | |
26 | 9.71k | rv = SSL_VersionRangeSetDefault(ssl_variant_stream, &supported); |
27 | 9.71k | assert(rv == SECSuccess); |
28 | | |
29 | 9.71k | return PR_SUCCESS; |
30 | 9.71k | } |
31 | | |
32 | 9.71k | void EnableAllCipherSuites(PRFileDesc* fd) { |
33 | 699k | for (uint16_t i = 0; i < SSL_NumImplementedCiphers; ++i) { |
34 | 689k | SECStatus rv = SSL_CipherPrefSet(fd, SSL_ImplementedCiphers[i], true); |
35 | 689k | assert(rv == SECSuccess); |
36 | 689k | } |
37 | 9.71k | } |
38 | | |
39 | 9.71k | void DoHandshake(PRFileDesc* fd, bool isServer) { |
40 | 9.71k | SECStatus rv = SSL_ResetHandshake(fd, isServer); |
41 | 9.71k | assert(rv == SECSuccess); |
42 | | |
43 | 9.71k | do { |
44 | 9.71k | rv = SSL_ForceHandshake(fd); |
45 | 9.71k | } while (rv != SECSuccess && PR_GetError() == PR_WOULD_BLOCK_ERROR); |
46 | | |
47 | | // If the handshake succeeds, let's read some data from the server, if any. |
48 | 9.71k | if (rv == SECSuccess) { |
49 | 190 | uint8_t block[1024]; |
50 | 190 | int32_t nb; |
51 | | |
52 | | // Read application data and echo it back. |
53 | 190 | while ((nb = PR_Read(fd, block, sizeof(block))) > 0) { |
54 | 0 | PR_Write(fd, block, nb); |
55 | 0 | } |
56 | 190 | } |
57 | 9.71k | } |