Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
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 SSLSAMPLE_H
6 #define SSLSAMPLE_H
8 /* Generic header files */
10 #include <stdio.h>
11 #include <string.h>
13 /* NSPR header files */
15 #include "nspr.h"
16 #include "prerror.h"
17 #include "prnetdb.h"
19 /* NSS header files */
21 #include "pk11func.h"
22 #include "secitem.h"
23 #include "ssl.h"
24 #include "certt.h"
25 #include "nss.h"
26 #include "secder.h"
27 #include "key.h"
28 #include "sslproto.h"
30 /* Custom header files */
32 /*
33 #include "sslerror.h"
34 */
36 #define BUFFER_SIZE 10240
38 /* Declare SSL cipher suites. */
40 extern int cipherSuites[];
41 extern int ssl2CipherSuites[];
42 extern int ssl3CipherSuites[];
44 /* Data buffer read from a socket. */
45 typedef struct DataBufferStr {
46 char data[BUFFER_SIZE];
47 int index;
48 int remaining;
49 int dataStart;
50 int dataEnd;
51 } DataBuffer;
53 /* SSL callback routines. */
55 char * myPasswd(PK11SlotInfo *info, PRBool retry, void *arg);
57 SECStatus myAuthCertificate(void *arg, PRFileDesc *socket,
58 PRBool checksig, PRBool isServer);
60 SECStatus myBadCertHandler(void *arg, PRFileDesc *socket);
62 void myHandshakeCallback(PRFileDesc *socket, void *arg);
64 SECStatus myGetClientAuthData(void *arg, PRFileDesc *socket,
65 struct CERTDistNamesStr *caNames,
66 struct CERTCertificateStr **pRetCert,
67 struct SECKEYPrivateKeyStr **pRetKey);
69 /* Disable all v2/v3 SSL ciphers. */
71 void disableAllSSLCiphers(void);
74 /* Error and information utilities. */
76 void errWarn(char *function);
78 void exitErr(char *function);
80 void printSecurityInfo(FILE *outfile, PRFileDesc *fd);
82 /* Some simple thread management routines. */
84 #define MAX_THREADS 32
86 typedef SECStatus startFn(void *a, int b);
88 typedef enum { rs_idle = 0, rs_running = 1, rs_zombie = 2 } runState;
90 typedef struct perThreadStr {
91 PRFileDesc *a;
92 int b;
93 int rv;
94 startFn *startFunc;
95 PRThread *prThread;
96 PRBool inUse;
97 runState running;
98 } perThread;
100 typedef struct GlobalThreadMgrStr {
101 PRLock *threadLock;
102 PRCondVar *threadStartQ;
103 PRCondVar *threadEndQ;
104 perThread threads[MAX_THREADS];
105 int index;
106 int numUsed;
107 int numRunning;
108 } GlobalThreadMgr;
110 void thread_wrapper(void * arg);
112 SECStatus launch_thread(GlobalThreadMgr *threadMGR,
113 startFn *startFunc, void *a, int b);
115 SECStatus reap_threads(GlobalThreadMgr *threadMGR);
117 void destroy_thread_data(GlobalThreadMgr *threadMGR);
119 /* Management of locked variables. */
121 struct lockedVarsStr {
122 PRLock * lock;
123 int count;
124 int waiters;
125 PRCondVar * condVar;
126 };
128 typedef struct lockedVarsStr lockedVars;
130 void lockedVars_Init(lockedVars *lv);
132 void lockedVars_Destroy(lockedVars *lv);
134 void lockedVars_WaitForDone(lockedVars *lv);
136 int lockedVars_AddToCount(lockedVars *lv, int addend);
138 /* Buffer stuff. */
140 static const char stopCmd[] = { "GET /stop " };
141 static const char defaultHeader[] = {
142 "HTTP/1.0 200 OK\r\n"
143 "Server: SSL sample server\r\n"
144 "Content-type: text/plain\r\n"
145 "\r\n"
146 };
148 #endif