security/manager/ssl/tests/unit/tlsserver/lib/TLSServer.h

branch
TOR_BUG_3246
changeset 6
8bccb770b82d
equal deleted inserted replaced
-1:000000000000 0:db7015f484a5
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 #ifndef mozilla_test__TLSServer_h
6 #define mozilla_test__TLSServer_h
7
8 // This is a standalone server for testing SSL features of Gecko.
9 // The client is expected to connect and initiate an SSL handshake (with SNI
10 // to indicate which "server" to connect to). If all is good, the client then
11 // sends one encrypted byte and receives that same byte back.
12 // This server also has the ability to "call back" another process waiting on
13 // it. That is, when the server is all set up and ready to receive connections,
14 // it will connect to a specified port and issue a simple HTTP request.
15
16 #include <stdint.h>
17 #include "prio.h"
18 #include "ScopedNSSTypes.h"
19 #include "secerr.h"
20 #include "ssl.h"
21
22 namespace mozilla { namespace test {
23
24 enum DebugLevel
25 {
26 DEBUG_ERRORS = 1,
27 DEBUG_WARNINGS = 2,
28 DEBUG_VERBOSE = 3
29 };
30
31 extern DebugLevel gDebugLevel;
32
33 void PrintPRError(const char *aPrefix);
34
35 // The default certificate is trusted for localhost and *.example.com
36 extern const char DEFAULT_CERT_NICKNAME[];
37
38 // Pass DEFAULT_CERT_NICKNAME as certName unless you need a specific
39 // certificate.
40 SECStatus
41 ConfigSecureServerWithNamedCert(PRFileDesc *fd, const char *certName,
42 /*optional*/ ScopedCERTCertificate *cert,
43 /*optional*/ SSLKEAType *kea);
44
45 int
46 StartServer(const char *nssCertDBDir, SSLSNISocketConfig sniSocketConfig,
47 void *sniSocketConfigArg);
48
49 template <typename Host>
50 inline const Host *
51 GetHostForSNI(const SECItem *aSrvNameArr, uint32_t aSrvNameArrSize,
52 const Host *hosts)
53 {
54 for (uint32_t i = 0; i < aSrvNameArrSize; i++) {
55 for (const Host *host = hosts; host->mHostName; ++host) {
56 SECItem hostName;
57 hostName.data = reinterpret_cast<uint8_t*>(const_cast<char*>(host->mHostName));
58 hostName.len = strlen(host->mHostName);
59 if (SECITEM_ItemsAreEqual(&hostName, &aSrvNameArr[i])) {
60 if (gDebugLevel >= DEBUG_VERBOSE) {
61 fprintf(stderr, "found pre-defined host '%s'\n", host->mHostName);
62 }
63 return host;
64 }
65 }
66 }
67
68 if (gDebugLevel >= DEBUG_VERBOSE) {
69 fprintf(stderr, "could not find host info from SNI\n");
70 }
71
72 PR_SetError(SEC_ERROR_INVALID_ARGS, 0);
73 return nullptr;
74 }
75
76 } } // namespace mozilla::test
77
78 #endif // mozilla_test__TLSServer_h

mercurial