2017-04-19 07:56:45 +00:00
|
|
|
/*
|
|
|
|
* Functions to trace SSL protocol behavior in DEBUG builds.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "cert.h"
|
2020-01-24 01:47:36 +00:00
|
|
|
#include "pk11func.h"
|
2017-04-19 07:56:45 +00:00
|
|
|
#include "ssl.h"
|
|
|
|
#include "sslimpl.h"
|
|
|
|
#include "sslproto.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
|
|
|
|
#if defined(DEBUG) || defined(TRACE)
|
|
|
|
static const char *hex = "0123456789abcdef";
|
|
|
|
|
|
|
|
static const char printable[257] = {
|
2020-01-24 01:47:36 +00:00
|
|
|
"................" /* 0x */
|
|
|
|
"................" /* 1x */
|
|
|
|
" !\"#$%&'()*+,-./" /* 2x */
|
|
|
|
"0123456789:;<=>?" /* 3x */
|
|
|
|
"@ABCDEFGHIJKLMNO" /* 4x */
|
|
|
|
"PQRSTUVWXYZ[\\]^_" /* 5x */
|
|
|
|
"`abcdefghijklmno" /* 6x */
|
|
|
|
"pqrstuvwxyz{|}~." /* 7x */
|
|
|
|
"................" /* 8x */
|
|
|
|
"................" /* 9x */
|
|
|
|
"................" /* ax */
|
|
|
|
"................" /* bx */
|
|
|
|
"................" /* cx */
|
|
|
|
"................" /* dx */
|
|
|
|
"................" /* ex */
|
|
|
|
"................" /* fx */
|
2017-04-19 07:56:45 +00:00
|
|
|
};
|
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
void
|
|
|
|
ssl_PrintBuf(const sslSocket *ss, const char *msg, const void *vp, int len)
|
2017-04-19 07:56:45 +00:00
|
|
|
{
|
|
|
|
const unsigned char *cp = (const unsigned char *)vp;
|
|
|
|
char buf[80];
|
|
|
|
char *bp;
|
|
|
|
char *ap;
|
|
|
|
|
|
|
|
if (ss) {
|
2020-01-24 01:47:36 +00:00
|
|
|
SSL_TRACE(("%d: SSL[%d]: %s [Len: %d]", SSL_GETPID(), ss->fd,
|
|
|
|
msg, len));
|
2017-04-19 07:56:45 +00:00
|
|
|
} else {
|
2020-01-24 01:47:36 +00:00
|
|
|
SSL_TRACE(("%d: SSL: %s [Len: %d]", SSL_GETPID(), msg, len));
|
2017-04-19 07:56:45 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
if (!cp) {
|
|
|
|
SSL_TRACE((" <NULL>"));
|
|
|
|
return;
|
2017-04-19 07:56:45 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
memset(buf, ' ', sizeof buf);
|
2017-04-19 07:56:45 +00:00
|
|
|
bp = buf;
|
2020-01-24 01:47:36 +00:00
|
|
|
ap = buf + 50;
|
2017-04-19 07:56:45 +00:00
|
|
|
while (--len >= 0) {
|
2020-01-24 01:47:36 +00:00
|
|
|
unsigned char ch = *cp++;
|
|
|
|
*bp++ = hex[(ch >> 4) & 0xf];
|
|
|
|
*bp++ = hex[ch & 0xf];
|
|
|
|
*bp++ = ' ';
|
|
|
|
*ap++ = printable[ch];
|
|
|
|
if (ap - buf >= 66) {
|
|
|
|
*ap = 0;
|
|
|
|
SSL_TRACE((" %s", buf));
|
|
|
|
memset(buf, ' ', sizeof buf);
|
|
|
|
bp = buf;
|
|
|
|
ap = buf + 50;
|
|
|
|
}
|
2017-04-19 07:56:45 +00:00
|
|
|
}
|
|
|
|
if (bp > buf) {
|
2020-01-24 01:47:36 +00:00
|
|
|
*ap = 0;
|
|
|
|
SSL_TRACE((" %s", buf));
|
2017-04-19 07:56:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
void
|
|
|
|
ssl_Trace(const char *format, ...)
|
2017-04-19 07:56:45 +00:00
|
|
|
{
|
2020-01-24 01:47:36 +00:00
|
|
|
char buf[2000];
|
|
|
|
va_list args;
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
if (ssl_trace_iob) {
|
|
|
|
va_start(args, format);
|
|
|
|
PR_vsnprintf(buf, sizeof(buf), format, args);
|
|
|
|
va_end(args);
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
fputs(buf, ssl_trace_iob);
|
|
|
|
fputs("\n", ssl_trace_iob);
|
2017-04-19 07:56:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-01-24 01:47:36 +00:00
|
|
|
ssl_PrintKey(const sslSocket *ss, const char *msg, PK11SymKey *key)
|
2017-04-19 07:56:45 +00:00
|
|
|
{
|
2020-01-24 01:47:36 +00:00
|
|
|
SECStatus rv;
|
|
|
|
SECItem *rawkey;
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
rv = PK11_ExtractKeyValue(key);
|
|
|
|
if (rv != SECSuccess) {
|
|
|
|
ssl_Trace("Could not extract key for %s", msg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rawkey = PK11_GetKeyData(key);
|
|
|
|
if (!rawkey) {
|
|
|
|
ssl_Trace("Could not extract key for %s", msg);
|
|
|
|
return;
|
2017-04-19 07:56:45 +00:00
|
|
|
}
|
2020-01-24 01:47:36 +00:00
|
|
|
ssl_PrintBuf(ss, msg, rawkey->data, rawkey->len);
|
2017-04-19 07:56:45 +00:00
|
|
|
}
|
|
|
|
#endif
|