sniffer.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* sniffer.h
  2. *
  3. * Copyright (C) 2006-2019 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_SetNamedPrivateKey(const char* name,
  45. const char* address, int port,
  46. const char* keyFile, int typeK,
  47. const char* password, char* error);
  48. WOLFSSL_API
  49. SSL_SNIFFER_API int ssl_DecodePacket(const unsigned char* packet, int length,
  50. unsigned char** data, char* error);
  51. WOLFSSL_API
  52. SSL_SNIFFER_API int ssl_FreeDecodeBuffer(unsigned char** data, char* error);
  53. WOLFSSL_API
  54. SSL_SNIFFER_API int ssl_FreeZeroDecodeBuffer(unsigned char** data, int sz,
  55. char* error);
  56. WOLFSSL_API
  57. SSL_SNIFFER_API int ssl_Trace(const char* traceFile, char* error);
  58. WOLFSSL_API
  59. SSL_SNIFFER_API int ssl_EnableRecovery(int onOff, int maxMemory, char* error);
  60. WOLFSSL_API
  61. SSL_SNIFFER_API int ssl_GetSessionStats(unsigned int* active,
  62. unsigned int* total,
  63. unsigned int* peak,
  64. unsigned int* maxSessions,
  65. unsigned int* missedData,
  66. unsigned int* reassemblyMemory,
  67. char* error);
  68. WOLFSSL_API void ssl_InitSniffer(void);
  69. WOLFSSL_API void ssl_FreeSniffer(void);
  70. /* ssl_SetPrivateKey typeKs */
  71. enum {
  72. FILETYPE_PEM = 1,
  73. FILETYPE_DER = 2,
  74. };
  75. /*
  76. * New Sniffer API that provides read-only access to the TLS and cipher
  77. * information associated with the SSL session.
  78. */
  79. #if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__)
  80. #define WOLFSSL_PACK __attribute__ ((packed))
  81. #else
  82. #define WOLFSSL_PACK
  83. #endif
  84. typedef struct SSLInfo
  85. {
  86. unsigned char isValid;
  87. /* indicates if the info in this struct is valid: 0 = no, 1 = yes */
  88. unsigned char protocolVersionMajor; /* SSL Version: major */
  89. unsigned char protocolVersionMinor; /* SSL Version: minor */
  90. unsigned char serverCipherSuite0; /* first byte, normally 0 */
  91. unsigned char serverCipherSuite; /* second byte, actual suite */
  92. unsigned char serverCipherSuiteName[256];
  93. /* cipher name, e.g., "TLS_RSA_..." */
  94. unsigned char serverNameIndication[128];
  95. unsigned int keySize;
  96. } WOLFSSL_PACK SSLInfo;
  97. WOLFSSL_API
  98. SSL_SNIFFER_API int ssl_DecodePacketWithSessionInfo(
  99. const unsigned char* packet, int length,
  100. unsigned char** data, SSLInfo* sslInfo, char* error);
  101. typedef void (*SSLConnCb)(const void* session, SSLInfo* info, void* ctx);
  102. WOLFSSL_API
  103. SSL_SNIFFER_API int ssl_SetConnectionCb(SSLConnCb cb);
  104. WOLFSSL_API
  105. SSL_SNIFFER_API int ssl_SetConnectionCtx(void* ctx);
  106. typedef struct SSLStats
  107. {
  108. unsigned long int sslStandardConns;
  109. unsigned long int sslClientAuthConns;
  110. unsigned long int sslResumedConns;
  111. unsigned long int sslEphemeralMisses;
  112. unsigned long int sslResumeMisses;
  113. unsigned long int sslCiphersUnsupported;
  114. unsigned long int sslKeysUnmatched;
  115. unsigned long int sslKeyFails;
  116. unsigned long int sslDecodeFails;
  117. unsigned long int sslAlerts;
  118. unsigned long int sslDecryptedBytes;
  119. unsigned long int sslEncryptedBytes;
  120. unsigned long int sslEncryptedPackets;
  121. unsigned long int sslDecryptedPackets;
  122. unsigned long int sslKeyMatches;
  123. unsigned long int sslEncryptedConns;
  124. unsigned long int sslResumptionValid;
  125. unsigned long int sslResumptionInserts;
  126. } SSLStats;
  127. WOLFSSL_API
  128. SSL_SNIFFER_API int ssl_ResetStatistics(void);
  129. WOLFSSL_API
  130. SSL_SNIFFER_API int ssl_ReadStatistics(SSLStats* stats);
  131. WOLFSSL_API
  132. SSL_SNIFFER_API int ssl_ReadResetStatistics(SSLStats* stats);
  133. typedef int (*SSLWatchCb)(void* vSniffer,
  134. const unsigned char* certHash,
  135. unsigned int certHashSz,
  136. const unsigned char* certChain,
  137. unsigned int certChainSz,
  138. void* ctx, char* error);
  139. WOLFSSL_API
  140. SSL_SNIFFER_API int ssl_SetWatchKeyCallback(SSLWatchCb cb, char* error);
  141. WOLFSSL_API
  142. SSL_SNIFFER_API int ssl_SetWatchKeyCtx(void* ctx, char* error);
  143. WOLFSSL_API
  144. SSL_SNIFFER_API int ssl_SetWatchKey_buffer(void* vSniffer,
  145. const unsigned char* key, unsigned int keySz,
  146. int keyType, char* error);
  147. WOLFSSL_API
  148. SSL_SNIFFER_API int ssl_SetWatchKey_file(void* vSniffer,
  149. const char* keyFile, int keyType,
  150. const char* password, char* error);
  151. typedef int (*SSLStoreDataCb)(const unsigned char* decryptBuf,
  152. unsigned int decryptBufSz, unsigned int decryptBufOffset, void* ctx);
  153. WOLFSSL_API
  154. SSL_SNIFFER_API int ssl_SetStoreDataCallback(SSLStoreDataCb cb);
  155. WOLFSSL_API
  156. SSL_SNIFFER_API int ssl_DecodePacketWithSessionInfoStoreData(
  157. const unsigned char* packet, int length, void* ctx,
  158. SSLInfo* sslInfo, char* error);
  159. WOLFSSL_API
  160. SSL_SNIFFER_API int ssl_DecodePacketWithChain(void* vChain,
  161. unsigned int chainSz, unsigned char** data, char* error);
  162. WOLFSSL_API
  163. SSL_SNIFFER_API int ssl_DecodePacketWithChainSessionInfoStoreData(
  164. void* vChain, unsigned int chainSz, void* ctx, SSLInfo* sslInfo,
  165. char* error);
  166. #ifdef __cplusplus
  167. } /* extern "C" */
  168. #endif
  169. #endif /* wolfSSL_SNIFFER_H */