JunkBox_Lib++ (for Windows) 1.10.1
Loading...
Searching...
No Matches
ssl_tool.h
Go to the documentation of this file.
1#ifndef __JBXL_SSL_TOOL_H_
2#define __JBXL_SSL_TOOL_H_
3
4#include "xtools.h"
5#include "asn1_tool.h"
6
7//#include "dh_tool.h"
8
9
10#ifndef HAVE_OPENSSL_SSL_H
11#ifndef DISABLE_SSL
12#define DISABLE_SSL
13#endif
14#endif
15
16#ifdef DISABLE_SSL
17#undef ENABLE_SSL
18#endif
19
20
21#ifdef ENABLE_SSL
22
37#define OPENSSL_NO_KRB5
38
39#include <openssl/crypto.h>
40#include <openssl/x509.h>
41#include <openssl/pem.h>
42#include <openssl/err.h>
43
44#include <openssl/ssl.h>
45#include <openssl/evp.h>
46#include <openssl/rand.h>
47
48
49#ifdef WIN32
50#pragma comment(lib, "openssl.lib")
51#endif
52
53
54// Key Exchange Algorism
55#define SSL_DH 1
56#define SSL_RSA 2
57
58
59//
60#define SSL_ENC_BLCKSZ 128 // ブロック暗号化のブロックサイズ
61
62// CRYPT Algorism
63#define SSL_AES128CBC 1
64#define SSL_3DES3CBC 10
65
66#define SSL_IV_SIZE 16
67
68//
69int gen_CRYPT_SharedKey(int keyex, Buffer spki, Buffer* shdkey, void* ptr);
70
71// データ(含むバイナリ)送受信用(IPv4)(暗号+復号)
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);
74
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);
79
80Buffer get_plain_Buffer(Buffer data, Buffer* key, EVP_CIPHER* cipher);
81Buffer get_crypt_Buffer(Buffer data, Buffer* key, EVP_CIPHER* cipher);
82
83// メッセージ(テキスト)送信用(暗号+Base64)
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);
86
87// メッセージ(テキスト)変換用(暗号化+Base64)
88// get_plain_ は tcp_send_crypt_, udp_send_crypt_ のデータ受信にも使用可.
89Buffer get_plain_message(char* mesg, Buffer* key, EVP_CIPHER* cipher);
90Buffer get_plain_sBuffer(Buffer mesg, Buffer* key, EVP_CIPHER* cipher);
91Buffer get_crypt_message(char* mesg, Buffer* key, EVP_CIPHER* cipher);
92Buffer get_crypt_sBuffer(Buffer 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));
95
96// Client's Side Check
97int check_server_spki(Buffer ip, Buffer spki, char* fn);
98int save_spki_with_ipaddr(Buffer ipa, Buffer pki, FILE* fp);
99Buffer read_spki_with_ipaddr(Buffer ipa, FILE* fp);
100
101// EVP
102EVP_CIPHER* init_EVPAPI_Buffer(int type);
103Buffer decode_EVPAPI_Buffer(Buffer buf, Buffer shkey, EVP_CIPHER* cipher);
104Buffer encode_EVPAPI_Buffer(Buffer buf, Buffer shkey, EVP_CIPHER* cipher);
105void free_EVP_CIPHER(EVP_CIPHER** p_cipher);
106
107// SSL/TLS
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))
111
112SSL_CTX* ssl_server_setup(char* crt_fn, char* key_fn, char* chn_fn);
113SSL* ssl_server_socket(int sock, SSL_CTX* ssl_ctx);
114
115int ssl_read_fullchain_cert_file(SSL_CTX* ssl_ctx, char* file);
116int ssl_add_chain_file(SSL_CTX* ssl_ctx, char* file);
117
118void ssl_init(void);
119void ssl_close(SSL* ssl);
120tList* ssl_get_cert_info(SSL* ssl);
121
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);
127
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);
133
144#define ssl_tcp_send_mesg(sock, ssl, mesg) ssl_tcp_send((sock), (ssl), (mesg), 0)
145
146
156#define ssl_send_mesg(ssl, mesg) ssl_send((ssl), (mesg), 0)
157
158
159// SSL/TLS with Buffer
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);
167
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);
175
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);
178
179
180#endif // DISABLE_SSL
181
182#endif // __JBXL_SSL_TOOL_H_
183
ASN.1/DER 用ライブラリヘッダ
#define mstream
バイト型 メッセージストリーム
Definition tools.h:167
汎用拡張ツールヘッダ