210
211
fprintf(stderr, "%-20s Disable SSL v2.\n", "-2");
211
212
fprintf(stderr, "%-20s Disable SSL v3.\n", "-3");
212
213
fprintf(stderr, "%-20s Disable TLS (SSL v3.1).\n", "-T");
214
fprintf(stderr, "%-20s Prints only payload data. Skips HTTP header.\n", "-S");
213
215
fprintf(stderr, "%-20s Client speaks first. \n", "-f");
214
216
fprintf(stderr, "%-20s Override bad server cert. Make it OK.\n", "-o");
215
217
fprintf(stderr, "%-20s Disable SSL socket locking.\n", "-s");
403
* Prints output according to skipProtoHeader flag. If skipProtoHeader
404
* is not set, prints without any changes, otherwise looking
405
* for \n\r\n(empty line sequence: HTTP header separator) and
406
* prints everything after it.
409
separateReqHeader(const PRFileDesc* outFd, const char* buf, const int nb,
410
PRBool *wrStarted, int *ptrnMatched) {
412
/* it is sufficient to look for only "\n\r\n". Hopping that
413
* HTTP response format satisfies the standard */
414
char *ptrnStr = "\n\r\n";
421
if (*ptrnMatched > 0) {
422
/* Get here only if previous separateReqHeader call found
423
* only a fragment of "\n\r\n" in previous buffer. */
424
PORT_Assert(*ptrnMatched < 3);
426
/* the size of fragment of "\n\r\n" what we want to find in this
427
* buffer is equal to *ptrnMatched */
428
if (*ptrnMatched <= nb) {
429
/* move the pointer to the beginning of the fragment */
430
int strSize = *ptrnMatched;
431
char *tmpPtrn = ptrnStr + (3 - strSize);
432
if (PL_strncmp(buf, tmpPtrn, strSize) == 0) {
433
/* print the rest of the buffer(without the fragment) */
434
PR_Write((void*)outFd, buf + strSize, nb - strSize);
435
*wrStarted = PR_TRUE;
439
/* we are here only when nb == 1 && *ptrnMatched == 2 */
448
resPtr = PL_strnstr(buf, ptrnStr, nb);
449
if (resPtr != NULL) {
450
/* if "\n\r\n" was found in the buffer, calculate offset
451
* and print the rest of the buffer */
452
int newBn = nb - (resPtr - buf + 3); /* 3 is the length of "\n\r\n" */
454
PR_Write((void*)outFd, resPtr + 3, newBn);
455
*wrStarted = PR_TRUE;
458
/* try to find a fragment of "\n\r\n" at the end of the buffer.
459
* if found, set *ptrnMatched to the number of chars left to find
460
* in the next buffer.*/
462
for(i = 1 ;i < 3;i++) {
469
bufPrt = (char*)(buf + nb - strSize);
471
if (PL_strncmp(bufPrt, ptrnStr, strSize) == 0) {
400
479
#define SSOCK_FD 0
401
480
#define STDIN_FD 1
436
515
int useExportPolicy = 0;
437
516
PRSocketOptionData opt;
440
518
PRPollDesc pollset[2];
441
519
PRBool useCommandLinePassword = PR_FALSE;
442
520
PRBool pingServerFirst = PR_FALSE;
443
521
PRBool clientSpeaksFirst = PR_FALSE;
522
PRBool wrStarted = PR_FALSE;
523
PRBool skipProtoHeader = PR_FALSE;
524
int headerSeparatorPtrnId = 0;
445
527
PLOptState *optstate;
446
528
PLOptStatus optstatus;
447
529
PRStatus prStatus;
462
optstate = PL_CreateOptState(argc, argv, "23BTfc:h:p:d:m:n:oqsvw:x");
544
optstate = PL_CreateOptState(argc, argv, "23BTSfc:h:p:d:m:n:oqsvw:x");
463
545
while ((optstatus = PL_GetNextOpt(optstate)) == PL_OPT_OK) {
464
546
switch (optstate->option) {
557
642
status = PR_StringToNetAddr(host, &addr);
558
643
if (status == PR_SUCCESS) {
559
int portno = atoi(port);
560
addr.inet.port = PR_htons((PRUint16)portno);
644
addr.inet.port = PR_htons(portno);
562
646
/* Lookup host */
563
char buf[PR_NETDB_BUF_SIZE];
564
status = PR_GetIPNodeByName(host, PR_AF_INET6, PR_AI_DEFAULT,
565
buf, sizeof buf, &hp);
566
if (status != PR_SUCCESS) {
647
PRAddrInfo *addrInfo;
648
void *enumPtr = NULL;
650
addrInfo = PR_GetAddrInfoByName(host, PR_AF_UNSPEC,
651
PR_AI_ADDRCONFIG | PR_AI_NOCANONNAME);
567
653
SECU_PrintError(progName, "error looking up host");
570
if (PR_EnumerateHostEnt(0, &hp, (PRUint16)atoi(port), &addr) == -1) {
657
enumPtr = PR_EnumerateAddrInfo(enumPtr, addrInfo, portno, &addr);
658
} while (enumPtr != NULL &&
659
addr.raw.family != PR_AF_INET &&
660
addr.raw.family != PR_AF_INET6);
661
PR_FreeAddrInfo(addrInfo);
662
if (enumPtr == NULL) {
571
663
SECU_PrintError(progName, "error looking up host address");
576
if (PR_IsNetAddrType(&addr, PR_IpAddrV4Mapped)) {
577
/* convert to IPv4. */
578
addr.inet.family = PR_AF_INET;
579
memcpy(&addr.inet.ip, &addr.ipv6.ip.pr_s6_addr[12], 4);
580
memset(&addr.inet.pad[0], 0, sizeof addr.inet.pad);
583
668
printHostNameAndAddr(host, &addr);
585
670
if (pingServerFirst) {
589
s = PR_NewTCPSocket();
674
s = PR_OpenTCPSocket(addr.raw.family);
591
676
SECU_PrintError(progName, "Failed to create a TCP socket");
940
1025
/* EOF from socket... stop polling socket for read */
941
1026
pollset[SSOCK_FD].in_flags = 0;
943
PR_Write(std_out, buf, nb);
1028
if (skipProtoHeader != PR_TRUE || wrStarted == PR_TRUE) {
1029
PR_Write(std_out, buf, nb);
1031
separateReqHeader(std_out, buf, nb, &wrStarted,
1032
&headerSeparatorPtrnId);
945
1035
fputs("\n\n", stderr);