sniffer.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /* 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. #ifndef WOLFSSL_SNIFFER_H
  22. #define WOLFSSL_SNIFFER_H
  23. #include <wolfssl/wolfcrypt/settings.h>
  24. #ifdef _WIN32
  25. #ifdef SSL_SNIFFER_EXPORTS
  26. #define SSL_SNIFFER_API __declspec(dllexport)
  27. #else
  28. #define SSL_SNIFFER_API __declspec(dllimport)
  29. #endif
  30. #else
  31. #define SSL_SNIFFER_API
  32. #endif /* _WIN32 */
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* @param typeK: (formerly keyType) was shadowing a global declaration in
  37. * wolfssl/wolfcrypt/asn.h line 175
  38. */
  39. WOLFSSL_API
  40. SSL_SNIFFER_API int ssl_SetPrivateKey(const char* address, int port,
  41. const char* keyFile, int typeK,
  42. const char* password, char* error);
  43. WOLFSSL_API
  44. SSL_SNIFFER_API int ssl_SetPrivateKeyBuffer(const char* address, int port,
  45. const char* keyBuf, int keySz,
  46. int typeK, const char* password,
  47. char* error);
  48. WOLFSSL_API
  49. SSL_SNIFFER_API int ssl_SetNamedPrivateKey(const char* name,
  50. const char* address, int port,
  51. const char* keyFile, int typeK,
  52. const char* password, char* error);
  53. WOLFSSL_API
  54. SSL_SNIFFER_API int ssl_SetNamedPrivateKeyBuffer(const char* name,
  55. const char* address, int port,
  56. const char* keyBuf, int keySz,
  57. int typeK, const char* password,
  58. char* error);
  59. WOLFSSL_API
  60. SSL_SNIFFER_API int ssl_SetEphemeralKey(const char* address, int port,
  61. const char* keyFile, int typeKey,
  62. const char* password, char* error);
  63. WOLFSSL_API
  64. SSL_SNIFFER_API int ssl_SetEphemeralKeyBuffer(const char* address, int port,
  65. const char* keyBuf, int keySz, int typeKey,
  66. const char* password, char* error);
  67. WOLFSSL_API
  68. SSL_SNIFFER_API int ssl_SetNamedEphemeralKey(const char* name,
  69. const char* address, int port,
  70. const char* keyFile, int typeKey,
  71. const char* password, char* error);
  72. WOLFSSL_API
  73. SSL_SNIFFER_API int ssl_SetNamedEphemeralKeyBuffer(const char* name,
  74. const char* address, int port,
  75. const char* keyBuf, int keySz, int typeKey,
  76. const char* password, char* error);
  77. WOLFSSL_API
  78. SSL_SNIFFER_API int ssl_DecodePacket(const unsigned char* packet, int length,
  79. unsigned char** data, char* error);
  80. WOLFSSL_API
  81. SSL_SNIFFER_API int ssl_FreeDecodeBuffer(unsigned char** data, char* error);
  82. WOLFSSL_API
  83. SSL_SNIFFER_API int ssl_FreeZeroDecodeBuffer(unsigned char** data, int sz,
  84. char* error);
  85. WOLFSSL_API
  86. SSL_SNIFFER_API int ssl_Trace(const char* traceFile, char* error);
  87. WOLFSSL_API
  88. SSL_SNIFFER_API int ssl_EnableRecovery(int onOff, int maxMemory, char* error);
  89. WOLFSSL_API
  90. SSL_SNIFFER_API int ssl_GetSessionStats(unsigned int* active,
  91. unsigned int* total,
  92. unsigned int* peak,
  93. unsigned int* maxSessions,
  94. unsigned int* missedData,
  95. unsigned int* reassemblyMemory,
  96. char* error);
  97. WOLFSSL_API void ssl_InitSniffer(void);
  98. WOLFSSL_API void ssl_FreeSniffer(void);
  99. /* ssl_SetPrivateKey typeKs */
  100. enum {
  101. FILETYPE_PEM = 1,
  102. FILETYPE_DER = 2,
  103. };
  104. /*
  105. * New Sniffer API that provides read-only access to the TLS and cipher
  106. * information associated with the SSL session.
  107. */
  108. typedef struct SSLInfo
  109. {
  110. unsigned char isValid;
  111. /* indicates if the info in this struct is valid: 0 = no, 1 = yes */
  112. unsigned char protocolVersionMajor; /* SSL Version: major */
  113. unsigned char protocolVersionMinor; /* SSL Version: minor */
  114. unsigned char serverCipherSuite0; /* first byte, normally 0 */
  115. unsigned char serverCipherSuite; /* second byte, actual suite */
  116. unsigned char serverCipherSuiteName[256];
  117. /* cipher name, e.g., "TLS_RSA_..." */
  118. unsigned char serverNameIndication[128];
  119. unsigned int keySize;
  120. } SSLInfo;
  121. WOLFSSL_API
  122. SSL_SNIFFER_API int ssl_DecodePacketWithSessionInfo(
  123. const unsigned char* packet, int length,
  124. unsigned char** data, SSLInfo* sslInfo, char* error);
  125. typedef void (*SSLConnCb)(const void* session, SSLInfo* info, void* ctx);
  126. WOLFSSL_API
  127. SSL_SNIFFER_API int ssl_SetConnectionCb(SSLConnCb cb);
  128. WOLFSSL_API
  129. SSL_SNIFFER_API int ssl_SetConnectionCtx(void* ctx);
  130. typedef struct SSLStats
  131. {
  132. unsigned long int sslStandardConns;
  133. unsigned long int sslClientAuthConns;
  134. unsigned long int sslResumedConns;
  135. unsigned long int sslEphemeralMisses;
  136. unsigned long int sslResumeMisses;
  137. unsigned long int sslCiphersUnsupported;
  138. unsigned long int sslKeysUnmatched;
  139. unsigned long int sslKeyFails;
  140. unsigned long int sslDecodeFails;
  141. unsigned long int sslAlerts;
  142. unsigned long int sslDecryptedBytes;
  143. unsigned long int sslEncryptedBytes;
  144. unsigned long int sslEncryptedPackets;
  145. unsigned long int sslDecryptedPackets;
  146. unsigned long int sslKeyMatches;
  147. unsigned long int sslEncryptedConns;
  148. unsigned long int sslResumptionValid;
  149. unsigned long int sslResumptionInserts;
  150. } SSLStats;
  151. WOLFSSL_API
  152. SSL_SNIFFER_API int ssl_ResetStatistics(void);
  153. WOLFSSL_API
  154. SSL_SNIFFER_API int ssl_ReadStatistics(SSLStats* stats);
  155. WOLFSSL_API
  156. SSL_SNIFFER_API int ssl_ReadResetStatistics(SSLStats* stats);
  157. typedef int (*SSLWatchCb)(void* vSniffer,
  158. const unsigned char* certHash,
  159. unsigned int certHashSz,
  160. const unsigned char* certChain,
  161. unsigned int certChainSz,
  162. void* ctx, char* error);
  163. WOLFSSL_API
  164. SSL_SNIFFER_API int ssl_SetWatchKeyCallback(SSLWatchCb cb, char* error);
  165. WOLFSSL_API
  166. SSL_SNIFFER_API int ssl_SetWatchKeyCallback_ex(SSLWatchCb cb, int devId,
  167. char* error);
  168. WOLFSSL_API
  169. SSL_SNIFFER_API int ssl_SetWatchKeyCtx(void* ctx, char* error);
  170. WOLFSSL_API
  171. SSL_SNIFFER_API int ssl_SetWatchKey_buffer(void* vSniffer,
  172. const unsigned char* key, unsigned int keySz,
  173. int keyType, char* error);
  174. WOLFSSL_API
  175. SSL_SNIFFER_API int ssl_SetWatchKey_file(void* vSniffer,
  176. const char* keyFile, int keyType,
  177. const char* password, char* error);
  178. typedef int (*SSLStoreDataCb)(const unsigned char* decryptBuf,
  179. unsigned int decryptBufSz, unsigned int decryptBufOffset, void* ctx);
  180. WOLFSSL_API
  181. SSL_SNIFFER_API int ssl_SetStoreDataCallback(SSLStoreDataCb cb);
  182. WOLFSSL_API
  183. SSL_SNIFFER_API int ssl_DecodePacketWithSessionInfoStoreData(
  184. const unsigned char* packet, int length, void* ctx,
  185. SSLInfo* sslInfo, char* error);
  186. WOLFSSL_API
  187. SSL_SNIFFER_API int ssl_DecodePacketWithChain(void* vChain,
  188. unsigned int chainSz, unsigned char** data, char* error);
  189. WOLFSSL_API
  190. SSL_SNIFFER_API int ssl_DecodePacketWithChainSessionInfoStoreData(
  191. void* vChain, unsigned int chainSz, void* ctx, SSLInfo* sslInfo,
  192. char* error);
  193. #ifdef __cplusplus
  194. } /* extern "C" */
  195. #endif
  196. #endif /* wolfSSL_SNIFFER_H */