2 Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
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.
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.
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,
20 /* yaSSL error implements and an exception class
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
30 // 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy
31 #pragma warning(disable: 4996)
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)
44 YasslError Error::get_number() const
50 Library Error::get_lib() const
58 void SetErrorString(YasslError error
, char* buffer
)
60 using namespace TaoCrypt
;
61 const int max
= MAX_ERROR_SZ
; // shorthand
62 int localError
= error
; // errors from a few enums
66 // yaSSL proper errors
68 strncpy(buffer
, "buffer index error, out of range", max
);
72 strncpy(buffer
, "trying to realloc a fixed buffer", max
);
76 strncpy(buffer
, "unknown factory create request", max
);
80 strncpy(buffer
, "trying to use an unknown cipher", max
);
84 strncpy(buffer
, "bad master secret derivation, prefix too big", max
);
88 strncpy(buffer
, "record layer not ready yet", max
);
91 case handshake_layer
:
92 strncpy(buffer
, "handshake layer not ready yet", max
);
96 strncpy(buffer
, "handshake message received in wrong order", max
);
100 strncpy(buffer
, "bad cipher suite input", max
);
104 strncpy(buffer
, "unable to match a supported cipher suite", max
);
108 strncpy(buffer
, "the server needs a private key file", max
);
112 strncpy(buffer
, "unable to verify peer checksum", max
);
116 strncpy(buffer
, "socket layer send error", max
);
120 strncpy(buffer
, "socket layer receive error", max
);
123 case certificate_error
:
124 strncpy(buffer
, "unable to proccess cerificate", max
);
127 case privateKey_error
:
128 strncpy(buffer
, "unable to proccess private key, bad format", max
);
131 case badVersion_error
:
132 strncpy(buffer
, "protocol version mismatch", max
);
135 case compress_error
:
136 strncpy(buffer
, "compression error", max
);
139 case decompress_error
:
140 strncpy(buffer
, "decompression error", max
);
143 case pms_version_error
:
144 strncpy(buffer
, "bad PreMasterSecret version error", max
);
147 case sanityCipher_error
:
148 strncpy(buffer
, "sanity check on cipher text size error", max
);
152 case SSL_ERROR_WANT_READ
:
153 strncpy(buffer
, "the read operation would block", max
);
156 case SSL_ERROR_WANT_WRITE
:
157 strncpy(buffer
, "the write operation would block", max
);
160 case CERTFICATE_ERROR
:
161 strncpy(buffer
, "Unable to verify certificate", max
);
166 strncpy(buffer
, "not in error state", max
);
170 strncpy(buffer
, "bad wincrypt acquire", max
);
174 strncpy(buffer
, "CryptGenRandom error", max
);
178 strncpy(buffer
, "unable to use random device", max
);
182 strncpy(buffer
, "unable to use random device", max
);
186 strncpy(buffer
, "ASN: bad DER Integer Header", max
);
190 strncpy(buffer
, "ASN: bad Sequence Header", max
);
194 strncpy(buffer
, "ASN: bad Set Header", max
);
198 strncpy(buffer
, "ASN: version length not 1", max
);
202 strncpy(buffer
, "ASN: signature OID mismatch", max
);
206 strncpy(buffer
, "ASN: bad BitString Header", max
);
210 strncpy(buffer
, "ASN: unknown key OID type", max
);
214 strncpy(buffer
, "ASN: bad Ojbect ID Header", max
);
218 strncpy(buffer
, "ASN: expected TAG NULL", max
);
222 strncpy(buffer
, "ASN: expected 0", max
);
226 strncpy(buffer
, "ASN: bad Octet String Header", max
);
230 strncpy(buffer
, "ASN: bad TIME", max
);
234 strncpy(buffer
, "ASN: bad Date Size", max
);
238 strncpy(buffer
, "ASN: bad Signature Length", max
);
242 strncpy(buffer
, "ASN: unknown signature OID", max
);
246 strncpy(buffer
, "ASN: unknown hash OID", max
);
250 strncpy(buffer
, "ASN: bad DSA r or s size", max
);
254 strncpy(buffer
, "ASN: before date in the future", max
);
258 strncpy(buffer
, "ASN: after date in the past", max
);
262 strncpy(buffer
, "ASN: bad self signature confirmation", max
);
266 strncpy(buffer
, "ASN: bad other signature confirmation", max
);
270 strncpy(buffer
, "bad content processing", max
);
274 strncpy(buffer
, "bad PEM format processing", max
);
278 strncpy(buffer
, "unknown error number", max
);