Blame lib/debug.c

Packit 549fdc
/*
Packit 549fdc
 * Copyright (C) 2001-2012 Free Software Foundation, Inc.
Packit 549fdc
 *
Packit 549fdc
 * Author: Nikos Mavrogiannopoulos
Packit 549fdc
 *
Packit 549fdc
 * This file is part of GnuTLS.
Packit 549fdc
 *
Packit 549fdc
 * The GnuTLS is free software; you can redistribute it and/or
Packit 549fdc
 * modify it under the terms of the GNU Lesser General Public License
Packit 549fdc
 * as published by the Free Software Foundation; either version 2.1 of
Packit 549fdc
 * the License, or (at your option) any later version.
Packit 549fdc
 *
Packit 549fdc
 * This library is distributed in the hope that it will be useful, but
Packit 549fdc
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 549fdc
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 549fdc
 * Lesser General Public License for more details.
Packit 549fdc
 *
Packit 549fdc
 * You should have received a copy of the GNU Lesser General Public License
Packit 549fdc
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
Packit 549fdc
 *
Packit 549fdc
 */
Packit 549fdc
Packit 549fdc
#include "gnutls_int.h"
Packit 549fdc
#include "errors.h"
Packit 549fdc
#include <stdio.h>
Packit 549fdc
#include <stdlib.h>
Packit 549fdc
#include "debug.h"
Packit 549fdc
#include <mpi.h>
Packit 549fdc
Packit 549fdc
#ifdef DEBUG
Packit 549fdc
void _gnutls_dump_mpi(const char *prefix, bigint_t a)
Packit 549fdc
{
Packit 549fdc
	char buf[400];
Packit 549fdc
	char buf_hex[2 * sizeof(buf) + 1];
Packit 549fdc
	size_t n = sizeof buf;
Packit 549fdc
Packit 549fdc
	if (_gnutls_mpi_print(a, buf, &n))
Packit 549fdc
		strcpy(buf, "[can't print value]");	/* Flawfinder: ignore */
Packit 549fdc
	_gnutls_debug_log("MPI: length: %d\n\t%s%s\n", (int) n, prefix,
Packit 549fdc
			  _gnutls_bin2hex(buf, n, buf_hex, sizeof(buf_hex),
Packit 549fdc
					  NULL));
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
void
Packit 549fdc
_gnutls_dump_vector(const char *prefix, const uint8_t * a, size_t a_size)
Packit 549fdc
{
Packit 549fdc
	char buf_hex[2 * a_size + 1];
Packit 549fdc
Packit 549fdc
	_gnutls_debug_log("Vector: length: %d\n\t%s%s\n", (int) a_size,
Packit 549fdc
			  prefix, _gnutls_bin2hex(a, a_size, buf_hex,
Packit 549fdc
						  sizeof(buf_hex), NULL));
Packit 549fdc
}
Packit 549fdc
#endif
Packit 549fdc
Packit 549fdc
const char *_gnutls_packet2str(content_type_t packet)
Packit 549fdc
{
Packit 549fdc
	switch (packet) {
Packit 549fdc
	case GNUTLS_CHANGE_CIPHER_SPEC:
Packit 549fdc
		return "ChangeCipherSpec";
Packit 549fdc
	case GNUTLS_ALERT:
Packit 549fdc
		return "Alert";
Packit 549fdc
	case GNUTLS_HANDSHAKE:
Packit 549fdc
		return "Handshake";
Packit 549fdc
	case GNUTLS_APPLICATION_DATA:
Packit 549fdc
		return "Application Data";
Packit 549fdc
	case GNUTLS_HEARTBEAT:
Packit 549fdc
		return "HeartBeat";
Packit 549fdc
	default:
Packit 549fdc
		return "Unknown Packet";
Packit 549fdc
	}
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_handshake_description_get_name:
Packit 549fdc
 * @type: is a handshake message description
Packit 549fdc
 *
Packit 549fdc
 * Convert a #gnutls_handshake_description_t value to a string.
Packit 549fdc
 *
Packit 549fdc
 * Returns: a string that contains the name of the specified handshake
Packit 549fdc
 *   message or %NULL.
Packit 549fdc
 **/
Packit 549fdc
const char
Packit 549fdc
    *gnutls_handshake_description_get_name(gnutls_handshake_description_t
Packit 549fdc
					   type)
Packit 549fdc
{
Packit 549fdc
	switch (type) {
Packit 549fdc
	case GNUTLS_HANDSHAKE_HELLO_REQUEST:
Packit 549fdc
		return "HELLO REQUEST";
Packit 549fdc
		break;
Packit 549fdc
	case GNUTLS_HANDSHAKE_CLIENT_HELLO:
Packit 549fdc
		return "CLIENT HELLO";
Packit 549fdc
		break;
Packit 549fdc
#ifdef ENABLE_SSL2
Packit 549fdc
	case GNUTLS_HANDSHAKE_CLIENT_HELLO_V2:
Packit 549fdc
		return "SSL2 CLIENT HELLO";
Packit 549fdc
		break;
Packit 549fdc
#endif
Packit 549fdc
	case GNUTLS_HANDSHAKE_SERVER_HELLO:
Packit 549fdc
		return "SERVER HELLO";
Packit 549fdc
		break;
Packit 549fdc
	case GNUTLS_HANDSHAKE_HELLO_VERIFY_REQUEST:
Packit 549fdc
		return "HELLO VERIFY REQUEST";
Packit 549fdc
		break;
Packit 549fdc
	case GNUTLS_HANDSHAKE_CERTIFICATE_PKT:
Packit 549fdc
		return "CERTIFICATE";
Packit 549fdc
		break;
Packit 549fdc
	case GNUTLS_HANDSHAKE_SERVER_KEY_EXCHANGE:
Packit 549fdc
		return "SERVER KEY EXCHANGE";
Packit 549fdc
		break;
Packit 549fdc
	case GNUTLS_HANDSHAKE_CERTIFICATE_REQUEST:
Packit 549fdc
		return "CERTIFICATE REQUEST";
Packit 549fdc
		break;
Packit 549fdc
	case GNUTLS_HANDSHAKE_SERVER_HELLO_DONE:
Packit 549fdc
		return "SERVER HELLO DONE";
Packit 549fdc
		break;
Packit 549fdc
	case GNUTLS_HANDSHAKE_CERTIFICATE_VERIFY:
Packit 549fdc
		return "CERTIFICATE VERIFY";
Packit 549fdc
		break;
Packit 549fdc
	case GNUTLS_HANDSHAKE_CLIENT_KEY_EXCHANGE:
Packit 549fdc
		return "CLIENT KEY EXCHANGE";
Packit 549fdc
		break;
Packit 549fdc
	case GNUTLS_HANDSHAKE_FINISHED:
Packit 549fdc
		return "FINISHED";
Packit 549fdc
		break;
Packit 549fdc
	case GNUTLS_HANDSHAKE_SUPPLEMENTAL:
Packit 549fdc
		return "SUPPLEMENTAL";
Packit 549fdc
		break;
Packit 549fdc
	case GNUTLS_HANDSHAKE_CERTIFICATE_STATUS:
Packit 549fdc
		return "CERTIFICATE STATUS";
Packit 549fdc
		break;
Packit 549fdc
	case GNUTLS_HANDSHAKE_NEW_SESSION_TICKET:
Packit 549fdc
		return "NEW SESSION TICKET";
Packit 549fdc
		break;
Packit 549fdc
	case GNUTLS_HANDSHAKE_CHANGE_CIPHER_SPEC:
Packit 549fdc
		return "CHANGE CIPHER SPEC";
Packit 549fdc
		break;
Packit 549fdc
	default:
Packit 549fdc
		return "Unknown Handshake packet";
Packit 549fdc
	}
Packit 549fdc
}