1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
/*
* Copyright (C) 2000 Nikos Mavroyanopoulos
*
* This file is part of GNUTLS.
*
* GNUTLS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GNUTLS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <defines.h>
#include "gnutls_int.h"
#include "gnutls_errors.h"
#ifdef DEBUG
void _gnutls_dump_mpi(char* prefix, MPI a)
{
char buf[400];
size_t n = sizeof buf;
if (gcry_mpi_print(GCRYMPI_FMT_HEX, buf, &n, a))
strcpy(buf, "[can't print value]");
fprintf(stderr, "MPI: length: %d\n\t%s%s\n", (n-1)/2, prefix, buf);
}
char *_gnutls_bin2hex(const unsigned char *old, const size_t oldlen)
{
unsigned char *new = NULL;
int i, j;
new = calloc(1, oldlen * 2 * sizeof(char) + 1);
if (!new)
return (new);
for (i = j = 0; i < oldlen; j+=2) {
sprintf(&new[j], "%.2x", old[i]);
i++;
}
new[j] = '\0';
return (new);
}
void _gnutls_print_state(GNUTLS_STATE state)
{
fprintf(stderr, "GNUTLS State:\n");
fprintf(stderr, "Connection End: %d\n",
state->security_parameters.entity);
fprintf(stderr, "Cipher Algorithm: %d\n",
state->security_parameters.bulk_cipher_algorithm);
fprintf(stderr, "Cipher Type: %d\n",
state->security_parameters.cipher_type);
fprintf(stderr, "Key Size: %d\n",
state->security_parameters.key_size);
fprintf(stderr, "Key Material: %d\n",
state->security_parameters.key_material_length);
fprintf(stderr, "MAC algorithm: %d\n",
state->security_parameters.mac_algorithm);
fprintf(stderr, "Hash size: %d\n",
state->security_parameters.hash_size);
fprintf(stderr, "Compression Algorithm: %d\n",
state->security_parameters.compression_algorithm);
fprintf(stderr, "\n");
}
void _gnutls_print_TLSCompressed(GNUTLSCompressed * compressed)
{
fprintf(stderr, "TLSCompressed packet:\n");
fprintf(stderr, "type: %d\n", compressed->type);
fprintf(stderr, "version: %d,%d\n", compressed->version.major,
compressed->version.minor);
fprintf(stderr, "length: %d\n", compressed->length);
fprintf(stderr, "fragment: %s\n",
_gnutls_bin2hex(compressed->fragment, compressed->length));
fprintf(stderr, "\n");
}
void _gnutls_print_TLSPlaintext(GNUTLSPlaintext * plaintext)
{
fprintf(stderr, "TLSPlaintext packet:\n");
fprintf(stderr, "type: %d\n", plaintext->type);
fprintf(stderr, "version: %d,%d\n", plaintext->version.major,
plaintext->version.minor);
fprintf(stderr, "length: %d\n", plaintext->length);
fprintf(stderr, "fragment: %s\n",
_gnutls_bin2hex(plaintext->fragment, plaintext->length));
fprintf(stderr, "\n");
}
void _gnutls_print_TLSCiphertext(GNUTLSCiphertext * ciphertext)
{
fprintf(stderr, "TLSCiphertext packet:\n");
fprintf(stderr, "type: %d\n", ciphertext->type);
fprintf(stderr, "version: %d,%d\n", ciphertext->version.major,
ciphertext->version.minor);
fprintf(stderr, "length: %d\n", ciphertext->length);
fprintf(stderr, "fragment: %s\n",
_gnutls_bin2hex(ciphertext->fragment, ciphertext->length));
fprintf(stderr, "\n");
}
char* _gnutls_alert2str( int alert) {
static char str[512];
switch(alert) {
case GNUTLS_CLOSE_NOTIFY:
strcpy(str, "Close Notify");
break;
case GNUTLS_UNEXPECTED_MESSAGE:
strcpy(str, "Unexpected message");
break;
case GNUTLS_BAD_RECORD_MAC:
strcpy(str, "Bad record MAC");
break;
case GNUTLS_DECRYPTION_FAILED:
strcpy(str, "Decryption Failed");
break;
case GNUTLS_RECORD_OVERFLOW:
strcpy(str, "Record Overflow");
break;
case GNUTLS_DECOMPRESSION_FAILURE:
strcpy(str, "Decompression Failed");
break;
case GNUTLS_HANDSHAKE_FAILURE:
strcpy(str, "Handshake failed");
break;
case GNUTLS_BAD_CERTIFICATE:
strcpy(str, "Certificate is bad");
break;
case GNUTLS_UNSUPPORTED_CERTIFICATE:
strcpy(str, "Certificate is not supported");
break;
case GNUTLS_CERTIFICATE_REVOKED:
strcpy(str, "Certificate was revoked");
break;
case GNUTLS_CERTIFICATE_EXPIRED:
strcpy(str, "Certificate is expired");
break;
case GNUTLS_CERTIFICATE_UNKNOWN:
strcpy(str, "Unknown Certificate");
break;
case GNUTLS_ILLEGAL_PARAMETER:
strcpy(str, "Illegal Parameter");
break;
case GNUTLS_UNKNOWN_CA:
strcpy(str, "CA is not known");
break;
case GNUTLS_ACCESS_DENIED:
strcpy(str, "Access was denied");
break;
case GNUTLS_DECODE_ERROR:
strcpy(str, "Decode error");
break;
case GNUTLS_DECRYPT_ERROR:
strcpy(str, "Decrypt error");
break;
case GNUTLS_EXPORT_RESTRICTION:
strcpy(str, "Export Restriction");
break;
case GNUTLS_PROTOCOL_VERSION:
strcpy(str, "Error in protocol version");
break;
case GNUTLS_INSUFFICIENT_SECURITY:
strcpy(str, "Insufficient Security");
break;
case GNUTLS_USER_CANCELED:
strcpy(str, "User Canceled");
break;
case GNUTLS_NO_RENEGOTIATION:
strcpy(str, "No renegotiation is allowed");
break;
default:
strcpy(str, "Unknown Alert");
}
return str;
}
char* _gnutls_packet2str( int packet) {
static char str[512];
switch(packet) {
case GNUTLS_CHANGE_CIPHER_SPEC:
strcpy(str, "Change Cipher Spec");
break;
case GNUTLS_ALERT:
strcpy(str, "Alert");
break;
case GNUTLS_HANDSHAKE:
strcpy(str, "Handshake");
break;
case GNUTLS_APPLICATION_DATA:
strcpy(str, "Application Data");
break;
default:
strcpy(str, "Unknown Packet");
}
return str;
}
char* _gnutls_handshake2str( int handshake) {
static char str[512];
switch(handshake) {
case GNUTLS_HELLO_REQUEST:
strcpy(str, "HELLO REQUEST");
break;
case GNUTLS_CLIENT_HELLO:
strcpy(str, "CLIENT HELLO");
break;
case GNUTLS_SERVER_HELLO:
strcpy(str, "SERVER HELLO");
break;
case GNUTLS_CERTIFICATE:
strcpy(str, "CERTIFICATE");
break;
case GNUTLS_SERVER_KEY_EXCHANGE:
strcpy(str, "SERVER KEY EXCHANGE");
break;
case GNUTLS_CERTIFICATE_REQUEST:
strcpy(str, "CERTIFICATE REQUEST");
break;
case GNUTLS_SERVER_HELLO_DONE:
strcpy(str, "SERVER HELLO DONE");
break;
case GNUTLS_CERTIFICATE_VERIFY:
strcpy(str, "CERTIFICATE VERIFY");
break;
case GNUTLS_CLIENT_KEY_EXCHANGE:
strcpy(str, "CLIENT KEY EXCHANGE");
break;
case GNUTLS_FINISHED:
strcpy(str, "FINISHED");
break;
default:
strcpy(str, "Unknown Handshake");
}
return str;
}
#endif
|