Back to index

lightning-sunbird  0.9+nobinonly
sslsample.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 #ifndef SSLSAMPLE_H
00038 #define SSLSAMPLE_H
00039 
00040 /* Generic header files */
00041 
00042 #include <stdio.h>
00043 #include <string.h>
00044 
00045 /* NSPR header files */
00046 
00047 #include "nspr.h"
00048 #include "prerror.h"
00049 #include "prnetdb.h"
00050 
00051 /* NSS header files */
00052 
00053 #include "pk11func.h"
00054 #include "secitem.h"
00055 #include "ssl.h"
00056 #include "certt.h"
00057 #include "nss.h"
00058 #include "secder.h"
00059 #include "key.h"
00060 #include "sslproto.h"
00061 
00062 /* Custom header files */
00063 
00064 /*
00065 #include "sslerror.h"
00066 */
00067 
00068 #define BUFFER_SIZE 10240
00069 
00070 /* Declare SSL cipher suites. */
00071 
00072 extern int cipherSuites[];
00073 extern int ssl2CipherSuites[];
00074 extern int ssl3CipherSuites[];
00075 
00076 /* Data buffer read from a socket. */
00077 typedef struct DataBufferStr {
00078        char data[BUFFER_SIZE];
00079        int  index;
00080        int  remaining;
00081        int  dataStart;
00082        int  dataEnd;
00083 } DataBuffer;
00084 
00085 /* SSL callback routines. */
00086 
00087 char * myPasswd(PK11SlotInfo *info, PRBool retry, void *arg);
00088 
00089 SECStatus myAuthCertificate(void *arg, PRFileDesc *socket,
00090                             PRBool checksig, PRBool isServer);
00091 
00092 SECStatus myBadCertHandler(void *arg, PRFileDesc *socket);
00093 
00094 SECStatus myHandshakeCallback(PRFileDesc *socket, void *arg);
00095 
00096 SECStatus myGetClientAuthData(void *arg, PRFileDesc *socket,
00097                               struct CERTDistNamesStr *caNames,
00098                               struct CERTCertificateStr **pRetCert,
00099                               struct SECKEYPrivateKeyStr **pRetKey);
00100 
00101 /* Disable all v2/v3 SSL ciphers. */
00102 
00103 void disableAllSSLCiphers(void);
00104 
00105 
00106 /* Error and information utilities. */
00107 
00108 void errWarn(char *function);
00109 
00110 void exitErr(char *function);
00111 
00112 void printSecurityInfo(PRFileDesc *fd);
00113 
00114 /* Some simple thread management routines. */
00115 
00116 #define MAX_THREADS 32
00117 
00118 typedef SECStatus startFn(void *a, int b);
00119 
00120 typedef enum { rs_idle = 0, rs_running = 1, rs_zombie = 2 } runState;
00121 
00122 typedef struct perThreadStr {
00123        PRFileDesc *a;
00124        int         b;
00125        int         rv;
00126        startFn    *startFunc;
00127        PRThread   *prThread;
00128        PRBool      inUse;
00129        runState    running;
00130 } perThread;
00131 
00132 typedef struct GlobalThreadMgrStr {
00133        PRLock   *threadLock;
00134        PRCondVar *threadStartQ;
00135        PRCondVar *threadEndQ;
00136        perThread  threads[MAX_THREADS];
00137        int        index;
00138        int        numUsed;
00139        int        numRunning;
00140 } GlobalThreadMgr;
00141 
00142 void thread_wrapper(void * arg);
00143 
00144 SECStatus launch_thread(GlobalThreadMgr *threadMGR, 
00145                         startFn *startFunc, void *a, int b);
00146 
00147 SECStatus reap_threads(GlobalThreadMgr *threadMGR);
00148 
00149 void destroy_thread_data(GlobalThreadMgr *threadMGR);
00150 
00151 /* Management of locked variables. */
00152 
00153 struct lockedVarsStr {
00154        PRLock *    lock;
00155        int         count;
00156        int         waiters;
00157        PRCondVar * condVar;
00158 };
00159 
00160 typedef struct lockedVarsStr lockedVars;
00161 
00162 void lockedVars_Init(lockedVars *lv);
00163 
00164 void lockedVars_Destroy(lockedVars *lv);
00165 
00166 void lockedVars_WaitForDone(lockedVars *lv);
00167 
00168 int lockedVars_AddToCount(lockedVars *lv, int addend);
00169 
00170 /* Buffer stuff. */
00171 
00172 static const char stopCmd[] = { "GET /stop " };
00173 static const char defaultHeader[] = {
00174        "HTTP/1.0 200 OK\r\n"
00175        "Server: SSL sample server\r\n"
00176        "Content-type: text/plain\r\n"
00177        "\r\n"
00178 };
00179 
00180 #endif