12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #ifndef BELL_TLS_SOCKET_H
- #define BELL_TLS_SOCKET_H
- #include "BellLogger.h"
- #include "BellSocket.h"
- #include <cstring>
- #include <ctype.h>
- #include <fstream>
- #include <iostream>
- #include <memory>
- #ifdef _WIN32
- #include <winsock2.h>
- #include <ws2tcpip.h>
- #else
- #include <netdb.h>
- #include <netinet/in.h>
- #include <netinet/tcp.h>
- #include <sys/socket.h>
- #include <unistd.h>
- #endif
- #include <sstream>
- #include <stdlib.h>
- #include <string>
- #include <sys/types.h>
- #include <vector>
- #include "mbedtls/net_sockets.h"
- #include "mbedtls/ssl.h"
- #include "mbedtls/entropy.h"
- #include "mbedtls/ctr_drbg.h"
- #include "mbedtls/debug.h"
- namespace bell {
- class TLSSocket : public bell::Socket {
- private:
- mbedtls_net_context server_fd;
- mbedtls_entropy_context entropy;
- mbedtls_ctr_drbg_context ctr_drbg;
- mbedtls_ssl_context ssl;
- mbedtls_ssl_config conf;
- bool isClosed = false;
- public:
- TLSSocket();
- ~TLSSocket() { close(); };
- void open(std::string host, uint16_t port);
- size_t read(uint8_t *buf, size_t len);
- size_t write(uint8_t *buf, size_t len);
- size_t poll();
- void close();
- };
- } // namespace bell
- #endif
|