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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     5 #ifndef mozilla_test__TLSServer_h
     6 #define mozilla_test__TLSServer_h
     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.
    16 #include <stdint.h>
    17 #include "prio.h"
    18 #include "ScopedNSSTypes.h"
    19 #include "secerr.h"
    20 #include "ssl.h"
    22 namespace mozilla { namespace test {
    24 enum DebugLevel
    25 {
    26   DEBUG_ERRORS = 1,
    27   DEBUG_WARNINGS  = 2,
    28   DEBUG_VERBOSE = 3
    29 };
    31 extern DebugLevel gDebugLevel;
    33 void PrintPRError(const char *aPrefix);
    35 // The default certificate is trusted for localhost and *.example.com
    36 extern const char DEFAULT_CERT_NICKNAME[];
    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);
    45 int
    46 StartServer(const char *nssCertDBDir, SSLSNISocketConfig sniSocketConfig,
    47             void *sniSocketConfigArg);
    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   }
    68   if (gDebugLevel >= DEBUG_VERBOSE) {
    69     fprintf(stderr, "could not find host info from SNI\n");
    70   }
    72   PR_SetError(SEC_ERROR_INVALID_ARGS, 0);
    73   return nullptr;
    74 }
    76 } } // namespace mozilla::test
    78 #endif // mozilla_test__TLSServer_h

mercurial