2019-12-17 18:30:49 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
#include "../acl_cpp_define.hpp"
|
2019-12-18 11:22:54 +08:00
|
|
|
|
#include "sslbase_io.hpp"
|
2019-12-17 18:30:49 +08:00
|
|
|
|
|
|
|
|
|
struct ACL_VSTREAM;
|
|
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
|
|
|
|
class mbedtls_conf;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* stream/aio_stream <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD> IO <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>࣬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĶ<EFBFBD>д<EFBFBD>Ĺ<EFBFBD><EFBFBD>̽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* stream/aio_stream <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ĭ<EFBFBD>ϵĵײ<EFBFBD> IO <EFBFBD><EFBFBD><EFBFBD>̣<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>Ϊ<EFBFBD>Ѷ<EFBFBD><EFBFBD><EFBFBD>)<EFBFBD><EFBFBD>
|
|
|
|
|
* stream/aio_stream <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> destroy()<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷű<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
2022-08-19 10:28:04 +08:00
|
|
|
|
class ACL_CPP_API mbedtls_io : public sslbase_io {
|
2019-12-17 18:30:49 +08:00
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD>
|
|
|
|
|
* @param conf {mbedtls_conf&} <EFBFBD><EFBFBD>ÿһ<EFBFBD><EFBFBD> SSL <EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param server_side {bool} <EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD>˲<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param nblock {bool} <EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
|
|
|
|
*/
|
|
|
|
|
mbedtls_io(mbedtls_conf& conf, bool server_side, bool nblock = false);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-12-18 11:22:54 +08:00
|
|
|
|
* @override stream_hook
|
2019-12-17 18:30:49 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> SSL IO <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
2019-12-18 11:22:54 +08:00
|
|
|
|
void destroy(void);
|
2019-12-17 18:30:49 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-12-18 11:22:54 +08:00
|
|
|
|
* @override sslbase_io
|
2019-12-17 18:30:49 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ô˷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> SSL <EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD><EFBFBD>ڷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IO ģʽ<EFBFBD>¸ú<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD> handshake_ok()
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD> SSL <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
* @return {bool}
|
|
|
|
|
* 1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EF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FBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool check_peer(void);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
~mbedtls_io(void);
|
|
|
|
|
|
|
|
|
|
// ʵ<><CAB5> stream_hook <20><><EFBFBD><EFBFBD><EFBFBD>鷽<EFBFBD><E9B7BD>
|
|
|
|
|
|
2019-12-18 11:22:54 +08:00
|
|
|
|
// @override stream_hook
|
|
|
|
|
bool open(ACL_VSTREAM* s);
|
|
|
|
|
|
|
|
|
|
// @override stream_hook
|
|
|
|
|
bool on_close(bool alive);
|
|
|
|
|
|
|
|
|
|
// @override stream_hook
|
|
|
|
|
int read(void* buf, size_t len);
|
|
|
|
|
|
|
|
|
|
// @override stream_hook
|
|
|
|
|
int send(const void* buf, size_t len);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
mbedtls_conf& conf_;
|
|
|
|
|
void* ssl_;
|
|
|
|
|
void* ssn_;
|
2022-08-21 22:01:51 +08:00
|
|
|
|
char* ebf_;
|
|
|
|
|
|
|
|
|
|
const char* ssl_strerror(int err);
|
2019-12-17 18:30:49 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
static int sock_read(void *ctx, unsigned char *buf, size_t len);
|
|
|
|
|
static int sock_send(void *ctx, const unsigned char *buf, size_t len);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|