1#ifndef __JBXL_SSL_TOOL_H_
2#define __JBXL_SSL_TOOL_H_
10#ifndef HAVE_OPENSSL_SSL_H
37#define OPENSSL_NO_KRB5
39#include <openssl/crypto.h>
40#include <openssl/x509.h>
41#include <openssl/pem.h>
42#include <openssl/err.h>
44#include <openssl/ssl.h>
45#include <openssl/evp.h>
46#include <openssl/rand.h>
50#pragma comment(lib, "openssl.lib")
60#define SSL_ENC_BLCKSZ 128
63#define SSL_AES128CBC 1
64#define SSL_3DES3CBC 10
69int gen_CRYPT_SharedKey(
int keyex,
Buffer spki,
Buffer* shdkey,
void* ptr);
72int udp_send_crypt_Buffer_sockaddr_in(
int sock,
Buffer* data,
struct sockaddr_in* sv,
Buffer* key, EVP_CIPHER* cipher);
73int udp_recv_crypt_Buffer_sockaddr_in(
int sock,
Buffer* data,
struct sockaddr_in* sv,
Buffer* key, EVP_CIPHER* cipher);
75int udp_send_crypt_Buffer(
int sock,
Buffer* data,
struct addrinfo* sv,
Buffer* key, EVP_CIPHER* cipher);
76int udp_recv_crypt_Buffer(
int sock,
Buffer* data,
struct addrinfo* sv,
Buffer* key, EVP_CIPHER* cipher);
77int tcp_send_crypt_Buffer(
int sock,
Buffer* data,
Buffer* key, EVP_CIPHER* cipher);
78int tcp_recv_crypt_Buffer(
int sock,
Buffer* data,
Buffer* key, EVP_CIPHER* cipher);
84int tcp_send_crypt_mesg (
int sock,
char* mesg,
Buffer* key, EVP_CIPHER* cipher);
85int tcp_send_crypt_sBuffer(
int sock,
Buffer* mesg,
Buffer* key, EVP_CIPHER* cipher);
89Buffer get_plain_message(
char* mesg,
Buffer* key, EVP_CIPHER* cipher);
91Buffer get_crypt_message(
char* mesg,
Buffer* key, EVP_CIPHER* cipher);
93#define get_plain_sBuffer_str(m, k, c) get_plain_message((m), (k), (c));
94#define get_crypt_sBuffer_str(m, k, c) get_crypt_message((m), (k), (c));
98int save_spki_with_ipaddr(
Buffer ipa,
Buffer pki, FILE* fp);
102EVP_CIPHER* init_EVPAPI_Buffer(
int type);
105void free_EVP_CIPHER(EVP_CIPHER** p_cipher);
108SSL_CTX* ssl_client_setup(
char* ca);
109SSL* ssl_client_socket(
int sock, SSL_CTX* ssl_ctx,
int mode);
110#define ssl_client_connect(s, c, m) ssl_client_socket((s), (c), (m))
112SSL_CTX* ssl_server_setup(
char* crt_fn,
char* key_fn,
char* chn_fn);
113SSL* ssl_server_socket(
int sock, SSL_CTX* ssl_ctx);
115int ssl_read_fullchain_cert_file(SSL_CTX* ssl_ctx,
char* file);
116int ssl_add_chain_file(SSL_CTX* ssl_ctx,
char* file);
119void ssl_close(SSL* ssl);
120tList* ssl_get_cert_info(SSL* ssl);
122int ssl_recv(SSL* ssl,
char* rmsg,
int size);
123int ssl_send(SSL* ssl,
char* smsg,
int size);
124int ssl_recv_wait(
int sock, SSL* ssl,
char* mesg,
int sz,
int tm);
125int ssl_send_mesgln(SSL* ssl,
char* mesg);
126int ssl_recv_mstream(
int sock, SSL* ssl,
char* mesg,
int sz,
mstream* sb,
int tm);
128int ssl_tcp_recv(
int sock, SSL* ssl,
char* rmsg,
int size);
129int ssl_tcp_send(
int sock, SSL* ssl,
char* smsg,
int size);
130int ssl_tcp_recv_wait(
int sock, SSL* ssl,
char* mesg,
int sz,
int tm);
131int ssl_tcp_send_mesgln(
int sock, SSL* ssl,
char* mesg);
132int ssl_tcp_recv_mstream(
int sock, SSL* ssl,
char* mesg,
int sz,
mstream* sb,
int tm);
144#define ssl_tcp_send_mesg(sock, ssl, mesg) ssl_tcp_send((sock), (ssl), (mesg), 0)
156#define ssl_send_mesg(ssl, mesg) ssl_send((ssl), (mesg), 0)
160int ssl_recv_Buffer(SSL* ssl,
Buffer* str);
161int ssl_send_Buffer(SSL* ssl,
Buffer* str);
162int ssl_recv_Buffer_wait(
int sock, SSL* ssl,
Buffer* str,
int tm);
163int ssl_send_sBuffer(SSL* ssl,
Buffer* str);
164int ssl_send_sBufferln(SSL* ssl,
Buffer* str);
165int ssl_recv_mstream_Buffer(
int sock, SSL* ssl,
Buffer* mesg,
mstream* sb,
int tm);
166int ssl_recv_lines_Buffer(
int sock, SSL* ssl,
Buffer* mesg,
int tm);
168int ssl_tcp_recv_Buffer(
int sock, SSL* ssl,
Buffer* str);
169int ssl_tcp_send_Buffer(
int sock, SSL* ssl,
Buffer* str);
170int ssl_tcp_recv_Buffer_wait(
int sock, SSL* ssl,
Buffer* str,
int tm);
171int ssl_tcp_send_sBuffer(
int sock, SSL* ssl,
Buffer* str);
172int ssl_tcp_send_sBufferln(
int sock, SSL* ssl,
Buffer* str);
173int ssl_tcp_recv_mstream_Buffer(
int sock, SSL* ssl,
Buffer* mesg,
mstream* sb,
int tm);
174int ssl_tcp_recv_lines_Buffer(
int sock, SSL* ssl,
Buffer* mesg,
int tm);
176int ssl_tcp_recv_Buffer_tosize(
int sock, SSL* ssl,
Buffer* str,
Buffer* mod,
int size);
177int ssl_tcp_recv_Buffer_tosize_wait(
int sock, SSL* ssl,
Buffer* str,
Buffer* mod,
int size,
int tm);