~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to extra/yassl/src/yassl_error.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
3
 
 
4
   This program is free software; you can redistribute it and/or modify
 
5
   it under the terms of the GNU General Public License as published by
 
6
   the Free Software Foundation; version 2 of the License.
 
7
 
 
8
   This program is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
   GNU General Public License for more details.
 
12
 
 
13
   You should have received a copy of the GNU General Public License
 
14
   along with this program; see the file COPYING. If not, write to the
 
15
   Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
 
16
   MA  02110-1301  USA.
 
17
*/
 
18
 
 
19
 
 
20
/* yaSSL error implements and an exception class
 
21
 */
 
22
 
 
23
#include "runtime.hpp"
 
24
#include "yassl_error.hpp"
 
25
#include "error.hpp"        // TaoCrypt error numbers
 
26
#include "openssl/ssl.h"    // SSL_ERROR_WANT_READ
 
27
#include <string.h>         // strncpy
 
28
 
 
29
#ifdef _MSC_VER
 
30
    // 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy
 
31
    #pragma warning(disable: 4996)
 
32
#endif
 
33
 
 
34
namespace yaSSL {
 
35
 
 
36
 
 
37
/* may bring back in future
 
38
Error::Error(const char* s, YasslError e, Library l) 
 
39
    : mySTL::runtime_error(s), error_(e), lib_(l) 
 
40
{
 
41
}
 
42
 
 
43
 
 
44
YasslError Error::get_number() const
 
45
{
 
46
    return error_;
 
47
}
 
48
 
 
49
 
 
50
Library Error::get_lib() const
 
51
{
 
52
 
 
53
    return lib_;
 
54
}
 
55
*/
 
56
 
 
57
 
 
58
void SetErrorString(unsigned long error, char* buffer)
 
59
{
 
60
    using namespace TaoCrypt;
 
61
    const int max = MAX_ERROR_SZ;  // shorthand
 
62
 
 
63
    switch (error) {
 
64
 
 
65
        // yaSSL proper errors
 
66
    case range_error :
 
67
        strncpy(buffer, "buffer index error, out of range", max);
 
68
        break; 
 
69
 
 
70
    case realloc_error :
 
71
        strncpy(buffer, "trying to realloc a fixed buffer", max);
 
72
        break; 
 
73
 
 
74
    case factory_error : 
 
75
        strncpy(buffer, "unknown factory create request", max);
 
76
        break; 
 
77
 
 
78
    case unknown_cipher :
 
79
        strncpy(buffer, "trying to use an unknown cipher", max);
 
80
        break; 
 
81
 
 
82
    case prefix_error : 
 
83
        strncpy(buffer, "bad master secret derivation, prefix too big", max);
 
84
        break; 
 
85
 
 
86
    case record_layer : 
 
87
        strncpy(buffer, "record layer not ready yet", max);
 
88
        break; 
 
89
        
 
90
    case handshake_layer :
 
91
        strncpy(buffer, "handshake layer not ready yet", max);
 
92
        break; 
 
93
 
 
94
    case out_of_order :
 
95
        strncpy(buffer, "handshake message received in wrong order", max);
 
96
        break; 
 
97
 
 
98
    case bad_input : 
 
99
        strncpy(buffer, "bad cipher suite input", max);
 
100
        break; 
 
101
 
 
102
    case match_error :
 
103
        strncpy(buffer, "unable to match a supported cipher suite", max);
 
104
        break; 
 
105
 
 
106
    case no_key_file : 
 
107
        strncpy(buffer, "the server needs a private key file", max);
 
108
        break; 
 
109
 
 
110
    case verify_error :
 
111
        strncpy(buffer, "unable to verify peer checksum", max);
 
112
        break; 
 
113
 
 
114
    case send_error :
 
115
        strncpy(buffer, "socket layer send error", max);
 
116
        break; 
 
117
 
 
118
    case receive_error :
 
119
        strncpy(buffer, "socket layer receive error", max);
 
120
        break; 
 
121
 
 
122
    case certificate_error :
 
123
        strncpy(buffer, "unable to proccess cerificate", max);
 
124
        break; 
 
125
 
 
126
    case privateKey_error :
 
127
        strncpy(buffer, "unable to proccess private key, bad format", max);
 
128
        break;
 
129
 
 
130
    case badVersion_error :
 
131
        strncpy(buffer, "protocl version mismatch", max);
 
132
        break;
 
133
        
 
134
    case compress_error :
 
135
        strncpy(buffer, "compression error", max);
 
136
        break;
 
137
 
 
138
    case decompress_error :
 
139
        strncpy(buffer, "decompression error", max);
 
140
        break;
 
141
 
 
142
    case pms_version_error :
 
143
        strncpy(buffer, "bad PreMasterSecret version error", max);
 
144
        break;
 
145
 
 
146
        // openssl errors
 
147
    case SSL_ERROR_WANT_READ :
 
148
        strncpy(buffer, "the read operation would block", max);
 
149
        break;
 
150
 
 
151
    case CERTFICATE_ERROR :
 
152
        strncpy(buffer, "Unable to verify certificate", max);
 
153
        break;
 
154
 
 
155
        // TaoCrypt errors
 
156
    case NO_ERROR_E :
 
157
        strncpy(buffer, "not in error state", max);
 
158
        break;
 
159
 
 
160
    case WINCRYPT_E :
 
161
        strncpy(buffer, "bad wincrypt acquire", max);
 
162
        break;
 
163
 
 
164
    case CRYPTGEN_E :
 
165
        strncpy(buffer, "CryptGenRandom error", max);
 
166
        break;
 
167
 
 
168
    case OPEN_RAN_E :
 
169
        strncpy(buffer, "unable to use random device", max);
 
170
        break;
 
171
 
 
172
    case READ_RAN_E :
 
173
        strncpy(buffer, "unable to use random device", max);
 
174
        break;
 
175
 
 
176
    case INTEGER_E :
 
177
        strncpy(buffer, "ASN: bad DER Integer Header", max);
 
178
        break;
 
179
 
 
180
    case SEQUENCE_E :
 
181
        strncpy(buffer, "ASN: bad Sequence Header", max);
 
182
        break;
 
183
 
 
184
    case SET_E :
 
185
        strncpy(buffer, "ASN: bad Set Header", max);
 
186
        break;
 
187
 
 
188
    case VERSION_E :
 
189
        strncpy(buffer, "ASN: version length not 1", max);
 
190
        break;
 
191
 
 
192
    case SIG_OID_E :
 
193
        strncpy(buffer, "ASN: signature OID mismatch", max);
 
194
        break;
 
195
 
 
196
    case BIT_STR_E :
 
197
        strncpy(buffer, "ASN: bad BitString Header", max);
 
198
        break;
 
199
 
 
200
    case UNKNOWN_OID_E :
 
201
        strncpy(buffer, "ASN: unknown key OID type", max);
 
202
        break;
 
203
 
 
204
    case OBJECT_ID_E :
 
205
        strncpy(buffer, "ASN: bad Ojbect ID Header", max);
 
206
        break;
 
207
 
 
208
    case TAG_NULL_E :
 
209
        strncpy(buffer, "ASN: expected TAG NULL", max);
 
210
        break;
 
211
 
 
212
    case EXPECT_0_E :
 
213
        strncpy(buffer, "ASN: expected 0", max);
 
214
        break;
 
215
 
 
216
    case OCTET_STR_E :
 
217
        strncpy(buffer, "ASN: bad Octet String Header", max);
 
218
        break;
 
219
 
 
220
    case TIME_E :
 
221
        strncpy(buffer, "ASN: bad TIME", max);
 
222
        break;
 
223
 
 
224
    case DATE_SZ_E :
 
225
        strncpy(buffer, "ASN: bad Date Size", max);
 
226
        break;
 
227
 
 
228
    case SIG_LEN_E :
 
229
        strncpy(buffer, "ASN: bad Signature Length", max);
 
230
        break;
 
231
 
 
232
    case UNKOWN_SIG_E :
 
233
        strncpy(buffer, "ASN: unknown signature OID", max);
 
234
        break;
 
235
 
 
236
    case UNKOWN_HASH_E :
 
237
        strncpy(buffer, "ASN: unknown hash OID", max);
 
238
        break;
 
239
 
 
240
    case DSA_SZ_E :
 
241
        strncpy(buffer, "ASN: bad DSA r or s size", max);
 
242
        break;
 
243
 
 
244
    case BEFORE_DATE_E :
 
245
        strncpy(buffer, "ASN: before date in the future", max);
 
246
        break;
 
247
 
 
248
    case AFTER_DATE_E :
 
249
        strncpy(buffer, "ASN: after date in the past", max);
 
250
        break;
 
251
 
 
252
    case SIG_CONFIRM_E :
 
253
        strncpy(buffer, "ASN: bad self signature confirmation", max);
 
254
        break;
 
255
 
 
256
    case SIG_OTHER_E :
 
257
        strncpy(buffer, "ASN: bad other signature confirmation", max);
 
258
        break;
 
259
 
 
260
    case CONTENT_E :
 
261
        strncpy(buffer, "bad content processing", max);
 
262
        break;
 
263
 
 
264
    case PEM_E :
 
265
        strncpy(buffer, "bad PEM format processing", max);
 
266
        break;
 
267
 
 
268
    default :
 
269
        strncpy(buffer, "unknown error number", max);
 
270
    }
 
271
}
 
272
 
 
273
 
 
274
 
 
275
}  // namespace yaSSL