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 <http://www.gnu.org/licenses/> |
20 | * |
21 | */ |
22 | |
23 | #include "gnutls_int.h" |
24 | #include "gnutls_errors.h" |
25 | #include <stdio.h> |
26 | #include <stdlib.h> |
27 | #include "debug.h" |
28 | #include <gnutls_mpi.h> |
29 | |
30 | #ifdef DEBUG |
31 | void |
32 | _gnutls_dump_mpi (const char *prefix, bigint_t a) |
33 | { |
34 | char buf[400]; |
35 | char buf_hex[2 * sizeof (buf)]; |
36 | size_t n = sizeof buf; |
37 | |
38 | if (_gnutls_mpi_print (a, buf, &n)) |
39 | strcpy (buf, "[can't print value]" ); /* Flawfinder: ignore */ |
40 | _gnutls_debug_log ("MPI: length: %d\n\t%s%s\n" , (int) n, prefix, |
41 | _gnutls_bin2hex (buf, n, buf_hex, sizeof (buf_hex), |
42 | NULL)); |
43 | } |
44 | |
45 | void |
46 | _gnutls_dump_vector (const char *prefix, const uint8_t *a, size_t a_size) |
47 | { |
48 | char buf_hex[2 * a_size]; |
49 | |
50 | _gnutls_debug_log ("Vector: length: %d\n\t%s%s\n" , (int) a_size, prefix, |
51 | _gnutls_bin2hex (a, a_size, buf_hex, sizeof (buf_hex), |
52 | NULL)); |
53 | } |
54 | #endif |
55 | |
56 | const char * |
57 | _gnutls_packet2str (content_type_t packet) |
58 | { |
59 | switch (packet) |
60 | { |
61 | case GNUTLS_CHANGE_CIPHER_SPEC: |
62 | return "ChangeCipherSpec" ; |
63 | case GNUTLS_ALERT: |
64 | return "Alert" ; |
65 | case GNUTLS_HANDSHAKE: |
66 | return "Handshake" ; |
67 | case GNUTLS_APPLICATION_DATA: |
68 | return "Application Data" ; |
69 | case GNUTLS_HEARTBEAT: |
70 | return "HeartBeat" ; |
71 | default: |
72 | return "Unknown Packet" ; |
73 | } |
74 | } |
75 | |
76 | /** |
77 | * gnutls_handshake_description_get_name: |
78 | * @type: is a handshake message description |
79 | * |
80 | * Convert a #gnutls_handshake_description_t value to a string. |
81 | * |
82 | * Returns: a string that contains the name of the specified handshake |
83 | * message or %NULL. |
84 | **/ |
85 | const char * |
86 | gnutls_handshake_description_get_name (gnutls_handshake_description_t type) |
87 | { |
88 | switch (type) |
89 | { |
90 | case GNUTLS_HANDSHAKE_HELLO_REQUEST: |
91 | return "HELLO REQUEST" ; |
92 | break; |
93 | case GNUTLS_HANDSHAKE_CLIENT_HELLO: |
94 | return "CLIENT HELLO" ; |
95 | break; |
96 | case GNUTLS_HANDSHAKE_CLIENT_HELLO_V2: |
97 | return "SSL2 CLIENT HELLO" ; |
98 | break; |
99 | case GNUTLS_HANDSHAKE_SERVER_HELLO: |
100 | return "SERVER HELLO" ; |
101 | break; |
102 | case GNUTLS_HANDSHAKE_HELLO_VERIFY_REQUEST: |
103 | return "HELLO VERIFY REQUEST" ; |
104 | break; |
105 | case GNUTLS_HANDSHAKE_CERTIFICATE_PKT: |
106 | return "CERTIFICATE" ; |
107 | break; |
108 | case GNUTLS_HANDSHAKE_SERVER_KEY_EXCHANGE: |
109 | return "SERVER KEY EXCHANGE" ; |
110 | break; |
111 | case GNUTLS_HANDSHAKE_CERTIFICATE_REQUEST: |
112 | return "CERTIFICATE REQUEST" ; |
113 | break; |
114 | case GNUTLS_HANDSHAKE_SERVER_HELLO_DONE: |
115 | return "SERVER HELLO DONE" ; |
116 | break; |
117 | case GNUTLS_HANDSHAKE_CERTIFICATE_VERIFY: |
118 | return "CERTIFICATE VERIFY" ; |
119 | break; |
120 | case GNUTLS_HANDSHAKE_CLIENT_KEY_EXCHANGE: |
121 | return "CLIENT KEY EXCHANGE" ; |
122 | break; |
123 | case GNUTLS_HANDSHAKE_FINISHED: |
124 | return "FINISHED" ; |
125 | break; |
126 | case GNUTLS_HANDSHAKE_SUPPLEMENTAL: |
127 | return "SUPPLEMENTAL" ; |
128 | break; |
129 | case GNUTLS_HANDSHAKE_CERTIFICATE_STATUS: |
130 | return "CERTIFICATE STATUS" ; |
131 | break; |
132 | case GNUTLS_HANDSHAKE_NEW_SESSION_TICKET: |
133 | return "NEW SESSION TICKET" ; |
134 | break; |
135 | case GNUTLS_HANDSHAKE_CHANGE_CIPHER_SPEC: |
136 | return "CHANGE CIPHER SPEC" ; |
137 | break; |
138 | default: |
139 | return "Unknown Handshake packet" ; |
140 | } |
141 | } |
142 | |