diff --git a/mozilla/security/nss/cmd/strsclnt/strsclnt.c b/mozilla/security/nss/cmd/strsclnt/strsclnt.c index 9efc9928c9d..2dc48771598 100644 --- a/mozilla/security/nss/cmd/strsclnt/strsclnt.c +++ b/mozilla/security/nss/cmd/strsclnt/strsclnt.c @@ -144,20 +144,23 @@ static PRLock * threadLock; /* protects the global variables below */ static PRTime lastConnectFailure; static PRTime lastConnectSuccess; static PRTime lastThrottleUp; -static int remaining_connections; /* number of connections left */ +static PRInt32 remaining_connections; /* number of connections left */ static int active_threads = 8; /* number of threads currently trying to ** connect */ -static int numUsed; +static PRInt32 numUsed; /* end of variables protected by threadLock */ static SSL3Statistics * ssl3stats; static int failed_already = 0; +static PRBool disableSSL2 = PR_FALSE; static PRBool disableSSL3 = PR_FALSE; static PRBool disableTLS = PR_FALSE; static PRBool bypassPKCS11 = PR_FALSE; static PRBool disableLocking = PR_FALSE; +static PRBool ignoreErrors = PR_FALSE; +PRIntervalTime maxInterval = PR_INTERVAL_NO_TIMEOUT; char * ownPasswd( PK11SlotInfo *slot, PRBool retry, void *arg) { @@ -182,7 +185,7 @@ Usage(const char *progName) { fprintf(stderr, "Usage: %s [-n nickname] [-p port] [-d dbdir] [-c connections]\n" - " [-3BDNTovqs] [-2 filename] [-P fullhandshakespercentage | -N]\n" + " [-23BDNTovqs] [-f filename] [-N | -P percentage]\n" " [-w dbpasswd] [-C cipher(s)] [-t threads] hostname\n" " where -v means verbose\n" " -o flag is interpreted as follows:\n" @@ -193,6 +196,7 @@ Usage(const char *progName) " -s means disable SSL socket locking\n" " -N means no session reuse\n" " -P means do a specified percentage of full handshakes (0-100)\n" + " -2 means disable SSL2\n" " -3 means disable SSL3\n" " -T means disable TLS\n" " -U means enable throttling up threads\n" @@ -382,7 +386,7 @@ void thread_wrapper(void * arg) { perThread * slot = (perThread *)arg; - PRBool die = PR_FALSE; + PRBool done = PR_FALSE; do { PRBool doop = PR_FALSE; @@ -394,7 +398,7 @@ thread_wrapper(void * arg) /* this thread isn't supposed to be running */ if (!ThrottleUp) { /* we'll never need this thread again, so abort it */ - die = PR_TRUE; + done = PR_TRUE; } else if (remaining_connections > 0) { /* we may still need this thread, so just sleep for 1s */ dosleep = PR_TRUE; @@ -417,14 +421,14 @@ thread_wrapper(void * arg) } } else { /* no more connections left, we are done */ - die = PR_TRUE; + done = PR_TRUE; } } else { /* this thread should run */ - if (--remaining_connections >= 0) { + if (--remaining_connections >= 0) { /* protected by threadLock */ doop = PR_TRUE; } else { - die = PR_TRUE; + done = PR_TRUE; } } PR_Unlock(threadLock); @@ -436,7 +440,7 @@ thread_wrapper(void * arg) if (dosleep) { PR_Sleep(PR_SecondsToInterval(1)); } - } while (!die); + } while (!done && (!failed_already || ignoreErrors)); } SECStatus @@ -457,8 +461,8 @@ launch_thread( return SECFailure; } - i = numUsed; - slot = &threads[numUsed++]; + i = numUsed++; + slot = &threads[i]; slot->a = a; slot->b = b; slot->tid = tid; @@ -486,7 +490,6 @@ launch_thread( int reap_threads(void) { - perThread * slot; int i; for (i = 0; i < MAX_THREADS; ++i) { @@ -595,12 +598,13 @@ do_writes( while (sent < bigBuf.len) { - count = PR_Write(ssl_sock, bigBuf.data + sent, bigBuf.len - sent); + count = PR_Send(ssl_sock, bigBuf.data + sent, bigBuf.len - sent, + 0, maxInterval); if (count < 0) { - errWarn("PR_Write bigBuf"); + errWarn("PR_Send bigBuf"); break; } - FPRINTF(stderr, "strsclnt: PR_Write wrote %d bytes from bigBuf\n", + FPRINTF(stderr, "strsclnt: PR_Send wrote %d bytes from bigBuf\n", count ); sent += count; } @@ -639,9 +643,9 @@ handle_fdx_connection( PRFileDesc * ssl_sock, int connection) /* do reads here. */ PRInt32 count; - count = PR_Read(ssl_sock, buf, RD_BUF_SIZE); + count = PR_Recv(ssl_sock, buf, RD_BUF_SIZE, 0, maxInterval); if (count < 0) { - errWarn("PR_Read"); + errWarn("PR_Recv"); break; } countRead += count; @@ -686,9 +690,9 @@ handle_connection( PRFileDesc *ssl_sock, int tid) /* compose the http request here. */ - rv = PR_Write(ssl_sock, request, strlen(request)); + rv = PR_Send(ssl_sock, request, strlen(request), 0, maxInterval); if (rv <= 0) { - errWarn("PR_Write"); + errWarn("PR_Send"); PR_Free(buf); buf = 0; failed_already = 1; @@ -698,12 +702,13 @@ handle_connection( PRFileDesc *ssl_sock, int tid) /* read until EOF */ while (1) { - rv = PR_Read(ssl_sock, buf, RD_BUF_SIZE); + rv = PR_Recv(ssl_sock, buf, RD_BUF_SIZE, 0, maxInterval); if (rv == 0) { break; /* EOF */ } if (rv < 0) { - errWarn("PR_Read"); + errWarn("PR_Recv"); + failed_already = 1; break; } @@ -1191,6 +1196,12 @@ client_main( errExit("SSL_OptionSet SSL_SECURITY"); } + /* disabling SSL2 compatible hellos also disables SSL2 */ + rv = SSL_OptionSet(model_sock, SSL_V2_COMPATIBLE_HELLO, !disableSSL2); + if (rv != SECSuccess) { + errExit("error enabling SSLv2 compatible hellos "); + } + rv = SSL_OptionSet(model_sock, SSL_ENABLE_SSL3, !disableSSL3); if (rv != SECSuccess) { errExit("error enabling SSLv3 "); @@ -1335,11 +1346,11 @@ main(int argc, char **argv) progName = progName ? progName + 1 : tmp; - optstate = PL_CreateOptState(argc, argv, "2:3BC:DNP:TUc:d:n:op:qst:vw:"); + optstate = PL_CreateOptState(argc, argv, "23BC:DNP:TUc:d:f:in:op:qst:vw:"); while ((status = PL_GetNextOpt(optstate)) == PL_OPT_OK) { switch(optstate->option) { - case '2': fileName = optstate->value; break; + case '2': disableSSL2 = PR_TRUE; break; case '3': disableSSL3 = PR_TRUE; break; @@ -1361,6 +1372,10 @@ main(int argc, char **argv) case 'd': dir = optstate->value; break; + case 'f': fileName = optstate->value; break; + + case 'i': ignoreErrors = PR_TRUE; break; + case 'n': nickName = PL_strdup(optstate->value); break; case 'o': MakeCertOK++; break; @@ -1414,6 +1429,14 @@ main(int argc, char **argv) PK11_SetPasswordFunc(SECU_GetModulePassword); } + tmp = PR_GetEnv("NSS_DEBUG_TIMEOUT"); + if (tmp && tmp[0]) { + int sec = PORT_Atoi(tmp); + if (sec > 0) { + maxInterval = PR_SecondsToInterval(sec); + } + } + /* Call the libsec initialization routines */ rv = NSS_Initialize(dir, "", "", SECMOD_DB, NSS_INIT_READONLY); if (rv != SECSuccess) {