Blame lib/debug.c

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