blob: fb48498a4907eb2ca1b35f12eb9eab2bbcb0d641 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* sniffer.h
2 *
3 * Copyright (C) 2006-2021 wolfSSL Inc.
4 *
5 * This file is part of wolfSSL.
6 *
7 * wolfSSL is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * wolfSSL is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20 */
21
22
23
24#ifndef WOLFSSL_SNIFFER_H
25#define WOLFSSL_SNIFFER_H
26
27#include <wolfssl/wolfcrypt/settings.h>
28
29#ifdef _WIN32
30 #ifdef SSL_SNIFFER_EXPORTS
31 #define SSL_SNIFFER_API __declspec(dllexport)
32 #else
33 #define SSL_SNIFFER_API __declspec(dllimport)
34 #endif
35#else
36 #define SSL_SNIFFER_API
37#endif /* _WIN32 */
38
39
40#ifdef __cplusplus
41 extern "C" {
42#endif
43
44/* @param typeK: (formerly keyType) was shadowing a global declaration in
45 * wolfssl/wolfcrypt/asn.h line 175
46 */
47WOLFSSL_API
48SSL_SNIFFER_API int ssl_SetPrivateKey(const char* address, int port,
49 const char* keyFile, int typeK,
50 const char* password, char* error);
51
52WOLFSSL_API
53SSL_SNIFFER_API int ssl_SetPrivateKeyBuffer(const char* address, int port,
54 const char* keyBuf, int keySz,
55 int typeK, const char* password,
56 char* error);
57
58
59WOLFSSL_API
60SSL_SNIFFER_API int ssl_SetNamedPrivateKey(const char* name,
61 const char* address, int port,
62 const char* keyFile, int typeK,
63 const char* password, char* error);
64
65WOLFSSL_API
66SSL_SNIFFER_API int ssl_SetNamedPrivateKeyBuffer(const char* name,
67 const char* address, int port,
68 const char* keyBuf, int keySz,
69 int typeK, const char* password,
70 char* error);
71
72WOLFSSL_API
73SSL_SNIFFER_API int ssl_SetEphemeralKey(const char* address, int port,
74 const char* keyFile, int typeKey,
75 const char* password, char* error);
76
77WOLFSSL_API
78SSL_SNIFFER_API int ssl_SetEphemeralKeyBuffer(const char* address, int port,
79 const char* keyBuf, int keySz, int typeKey,
80 const char* password, char* error);
81
82
83WOLFSSL_API
84SSL_SNIFFER_API int ssl_SetNamedEphemeralKey(const char* name,
85 const char* address, int port,
86 const char* keyFile, int typeKey,
87 const char* password, char* error);
88
89WOLFSSL_API
90SSL_SNIFFER_API int ssl_SetNamedEphemeralKeyBuffer(const char* name,
91 const char* address, int port,
92 const char* keyBuf, int keySz, int typeKey,
93 const char* password, char* error);
94
95WOLFSSL_API
96SSL_SNIFFER_API int ssl_DecodePacket(const unsigned char* packet, int length,
97 unsigned char** data, char* error);
98
99WOLFSSL_API
100SSL_SNIFFER_API int ssl_FreeDecodeBuffer(unsigned char** data, char* error);
101
102WOLFSSL_API
103SSL_SNIFFER_API int ssl_FreeZeroDecodeBuffer(unsigned char** data, int sz,
104 char* error);
105
106WOLFSSL_API
107SSL_SNIFFER_API int ssl_Trace(const char* traceFile, char* error);
108
109WOLFSSL_API
110SSL_SNIFFER_API int ssl_EnableRecovery(int onOff, int maxMemory, char* error);
111
112WOLFSSL_API
113SSL_SNIFFER_API int ssl_GetSessionStats(unsigned int* active,
114 unsigned int* total,
115 unsigned int* peak,
116 unsigned int* maxSessions,
117 unsigned int* missedData,
118 unsigned int* reassemblyMemory,
119 char* error);
120
121WOLFSSL_API void ssl_InitSniffer(void);
122
123WOLFSSL_API void ssl_FreeSniffer(void);
124
125
126/* ssl_SetPrivateKey typeKs */
127enum {
128 FILETYPE_PEM = 1,
129 FILETYPE_DER = 2,
130};
131
132
133/*
134 * New Sniffer API that provides read-only access to the TLS and cipher
135 * information associated with the SSL session.
136 */
137
138typedef struct SSLInfo
139{
140 unsigned char isValid;
141 /* indicates if the info in this struct is valid: 0 = no, 1 = yes */
142 unsigned char protocolVersionMajor; /* SSL Version: major */
143 unsigned char protocolVersionMinor; /* SSL Version: minor */
144 unsigned char serverCipherSuite0; /* first byte, normally 0 */
145 unsigned char serverCipherSuite; /* second byte, actual suite */
146 unsigned char serverCipherSuiteName[256];
147 /* cipher name, e.g., "TLS_RSA_..." */
148 unsigned char serverNameIndication[128];
149 unsigned int keySize;
150} SSLInfo;
151
152
153WOLFSSL_API
154SSL_SNIFFER_API int ssl_DecodePacketWithSessionInfo(
155 const unsigned char* packet, int length,
156 unsigned char** data, SSLInfo* sslInfo, char* error);
157
158typedef void (*SSLConnCb)(const void* session, SSLInfo* info, void* ctx);
159
160WOLFSSL_API
161SSL_SNIFFER_API int ssl_SetConnectionCb(SSLConnCb cb);
162
163WOLFSSL_API
164SSL_SNIFFER_API int ssl_SetConnectionCtx(void* ctx);
165
166
167typedef struct SSLStats
168{
169 unsigned long int sslStandardConns;
170 unsigned long int sslClientAuthConns;
171 unsigned long int sslResumedConns;
172 unsigned long int sslEphemeralMisses;
173 unsigned long int sslResumeMisses;
174 unsigned long int sslCiphersUnsupported;
175 unsigned long int sslKeysUnmatched;
176 unsigned long int sslKeyFails;
177 unsigned long int sslDecodeFails;
178 unsigned long int sslAlerts;
179 unsigned long int sslDecryptedBytes;
180 unsigned long int sslEncryptedBytes;
181 unsigned long int sslEncryptedPackets;
182 unsigned long int sslDecryptedPackets;
183 unsigned long int sslKeyMatches;
184 unsigned long int sslEncryptedConns;
185
186 unsigned long int sslResumptionValid;
187 unsigned long int sslResumptionInserts;
188} SSLStats;
189
190
191WOLFSSL_API
192SSL_SNIFFER_API int ssl_ResetStatistics(void);
193
194
195WOLFSSL_API
196SSL_SNIFFER_API int ssl_ReadStatistics(SSLStats* stats);
197
198
199WOLFSSL_API
200SSL_SNIFFER_API int ssl_ReadResetStatistics(SSLStats* stats);
201
202
203typedef int (*SSLWatchCb)(void* vSniffer,
204 const unsigned char* certHash,
205 unsigned int certHashSz,
206 const unsigned char* certChain,
207 unsigned int certChainSz,
208 void* ctx, char* error);
209
210WOLFSSL_API
211SSL_SNIFFER_API int ssl_SetWatchKeyCallback(SSLWatchCb cb, char* error);
212
213WOLFSSL_API
214SSL_SNIFFER_API int ssl_SetWatchKeyCallback_ex(SSLWatchCb cb, int devId,
215 char* error);
216
217WOLFSSL_API
218SSL_SNIFFER_API int ssl_SetWatchKeyCtx(void* ctx, char* error);
219
220WOLFSSL_API
221SSL_SNIFFER_API int ssl_SetWatchKey_buffer(void* vSniffer,
222 const unsigned char* key, unsigned int keySz,
223 int keyType, char* error);
224
225WOLFSSL_API
226SSL_SNIFFER_API int ssl_SetWatchKey_file(void* vSniffer,
227 const char* keyFile, int keyType,
228 const char* password, char* error);
229
230
231typedef int (*SSLStoreDataCb)(const unsigned char* decryptBuf,
232 unsigned int decryptBufSz, unsigned int decryptBufOffset, void* ctx);
233
234WOLFSSL_API
235SSL_SNIFFER_API int ssl_SetStoreDataCallback(SSLStoreDataCb cb);
236
237WOLFSSL_API
238SSL_SNIFFER_API int ssl_DecodePacketWithSessionInfoStoreData(
239 const unsigned char* packet, int length, void* ctx,
240 SSLInfo* sslInfo, char* error);
241
242
243WOLFSSL_API
244SSL_SNIFFER_API int ssl_DecodePacketWithChain(void* vChain,
245 unsigned int chainSz, unsigned char** data, char* error);
246
247
248WOLFSSL_API
249SSL_SNIFFER_API int ssl_DecodePacketWithChainSessionInfoStoreData(
250 void* vChain, unsigned int chainSz, void* ctx, SSLInfo* sslInfo,
251 char* error);
252
253#ifdef __cplusplus
254 } /* extern "C" */
255#endif
256
257#endif /* wolfSSL_SNIFFER_H */
258