Line data Source code
1 : /* 2 : * Copyright (C) 2001-2012 Free Software Foundation, Inc. 3 : * 4 : * Author: Nikos Mavrogiannopoulos 5 : * 6 : * This file is part of GnuTLS. 7 : * 8 : * The GnuTLS is free software; you can redistribute it and/or 9 : * modify it under the terms of the GNU Lesser General Public License 10 : * as published by the Free Software Foundation; either version 2.1 of 11 : * the License, or (at your option) any later version. 12 : * 13 : * This library is distributed in the hope that it will be useful, but 14 : * WITHOUT ANY WARRANTY; without even the implied warranty of 15 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 : * Lesser General Public License for more details. 17 : * 18 : * You should have received a copy of the GNU Lesser General Public License 19 : * along with this program. If not, see <https://www.gnu.org/licenses/> 20 : * 21 : */ 22 : 23 : #include "gnutls_int.h" 24 : #include "errors.h" 25 : #include <stdio.h> 26 : #include <stdlib.h> 27 : #include "debug.h" 28 : #include <mpi.h> 29 : 30 : #ifdef DEBUG 31 : void _gnutls_dump_mpi(const char *prefix, bigint_t a) 32 : { 33 : char buf[400]; 34 : char buf_hex[2 * sizeof(buf) + 1]; 35 : size_t n = sizeof buf; 36 : 37 : if (_gnutls_mpi_print(a, buf, &n)) 38 : strcpy(buf, "[can't print value]"); /* Flawfinder: ignore */ 39 : _gnutls_debug_log("MPI: length: %d\n\t%s%s\n", (int) n, prefix, 40 : _gnutls_bin2hex(buf, n, buf_hex, sizeof(buf_hex), 41 : NULL)); 42 : } 43 : 44 : void 45 : _gnutls_dump_vector(const char *prefix, const uint8_t * a, size_t a_size) 46 : { 47 : char buf_hex[2 * a_size + 1]; 48 : 49 : _gnutls_debug_log("Vector: length: %d\n\t%s%s\n", (int) a_size, 50 : prefix, _gnutls_bin2hex(a, a_size, buf_hex, 51 : sizeof(buf_hex), NULL)); 52 : } 53 : #endif 54 : 55 254186 : const char *_gnutls_packet2str(content_type_t packet) 56 : { 57 254186 : switch (packet) { 58 : case GNUTLS_CHANGE_CIPHER_SPEC: 59 : return "ChangeCipherSpec"; 60 18661 : case GNUTLS_ALERT: 61 18661 : return "Alert"; 62 170870 : case GNUTLS_HANDSHAKE: 63 170870 : return "Handshake"; 64 40614 : case GNUTLS_APPLICATION_DATA: 65 40614 : return "Application Data"; 66 21 : case GNUTLS_HEARTBEAT: 67 21 : return "HeartBeat"; 68 0 : default: 69 0 : return "Unknown Packet"; 70 : } 71 : } 72 : 73 : /** 74 : * gnutls_handshake_description_get_name: 75 : * @type: is a handshake message description 76 : * 77 : * Convert a #gnutls_handshake_description_t value to a string. 78 : * 79 : * Returns: a string that contains the name of the specified handshake 80 : * message or %NULL. 81 : **/ 82 : const char 83 66191 : *gnutls_handshake_description_get_name(gnutls_handshake_description_t 84 : type) 85 : { 86 66191 : switch (type) { 87 : case GNUTLS_HANDSHAKE_END_OF_EARLY_DATA: 88 : return "END OF EARLY DATA"; 89 16 : case GNUTLS_HANDSHAKE_HELLO_RETRY_REQUEST: 90 16 : return "HELLO RETRY REQUEST"; 91 2 : case GNUTLS_HANDSHAKE_HELLO_REQUEST: 92 2 : return "HELLO REQUEST"; 93 8866 : case GNUTLS_HANDSHAKE_CLIENT_HELLO: 94 8866 : return "CLIENT HELLO"; 95 : #ifdef ENABLE_SSL2 96 521 : case GNUTLS_HANDSHAKE_CLIENT_HELLO_V2: 97 521 : return "SSL2 CLIENT HELLO"; 98 : #endif 99 8301 : case GNUTLS_HANDSHAKE_SERVER_HELLO: 100 8301 : return "SERVER HELLO"; 101 1 : case GNUTLS_HANDSHAKE_HELLO_VERIFY_REQUEST: 102 1 : return "HELLO VERIFY REQUEST"; 103 10466 : case GNUTLS_HANDSHAKE_CERTIFICATE_PKT: 104 10466 : return "CERTIFICATE"; 105 3074 : case GNUTLS_HANDSHAKE_ENCRYPTED_EXTENSIONS: 106 3074 : return "ENCRYPTED EXTENSIONS"; 107 2084 : case GNUTLS_HANDSHAKE_SERVER_KEY_EXCHANGE: 108 2084 : return "SERVER KEY EXCHANGE"; 109 2215 : case GNUTLS_HANDSHAKE_CERTIFICATE_REQUEST: 110 2215 : return "CERTIFICATE REQUEST"; 111 5222 : case GNUTLS_HANDSHAKE_SERVER_HELLO_DONE: 112 5222 : return "SERVER HELLO DONE"; 113 3599 : case GNUTLS_HANDSHAKE_CERTIFICATE_VERIFY: 114 3599 : return "CERTIFICATE VERIFY"; 115 3516 : case GNUTLS_HANDSHAKE_CLIENT_KEY_EXCHANGE: 116 3516 : return "CLIENT KEY EXCHANGE"; 117 12007 : case GNUTLS_HANDSHAKE_FINISHED: 118 12007 : return "FINISHED"; 119 7 : case GNUTLS_HANDSHAKE_KEY_UPDATE: 120 7 : return "KEY_UPDATE"; 121 1 : case GNUTLS_HANDSHAKE_SUPPLEMENTAL: 122 1 : return "SUPPLEMENTAL"; 123 1 : case GNUTLS_HANDSHAKE_CERTIFICATE_STATUS: 124 1 : return "CERTIFICATE STATUS"; 125 6053 : case GNUTLS_HANDSHAKE_NEW_SESSION_TICKET: 126 6053 : return "NEW SESSION TICKET"; 127 0 : case GNUTLS_HANDSHAKE_CHANGE_CIPHER_SPEC: 128 0 : return "CHANGE CIPHER SPEC"; 129 238 : default: 130 238 : return "Unknown Handshake packet"; 131 : } 132 : }