2018-06-19 11:32:16 +08:00
|
|
|
/*************************************************************************
|
|
|
|
|
> File Name: cert_session.c
|
|
|
|
|
> Author:
|
|
|
|
|
> Mail:
|
|
|
|
|
> Created Time: Fri 01 Jun 2018 02:00:56 AM PDT
|
|
|
|
|
************************************************************************/
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
#include <unistd.h>
|
2018-09-20 10:11:15 +08:00
|
|
|
#include <assert.h>
|
2019-11-05 11:38:40 +08:00
|
|
|
#include <fcntl.h>
|
2019-01-21 15:32:34 +06:00
|
|
|
#include <uuid/uuid.h>
|
|
|
|
|
|
2018-06-19 11:32:16 +08:00
|
|
|
#include "rt_string.h"
|
|
|
|
|
#include "rt_common.h"
|
|
|
|
|
#include "rt_stdlib.h"
|
|
|
|
|
#include "rt_file.h"
|
2018-07-09 14:32:41 +08:00
|
|
|
#include "rt_time.h"
|
2018-10-22 11:15:57 +08:00
|
|
|
#include "rt_tmr.h"
|
2018-09-06 19:51:23 +08:00
|
|
|
#include "json.h"
|
|
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
/* openssl**/
|
|
|
|
|
#include <openssl/opensslv.h>
|
|
|
|
|
#include <openssl/ssl.h>
|
|
|
|
|
#include <openssl/err.h>
|
|
|
|
|
#include <openssl/rand.h>
|
|
|
|
|
#include <openssl/x509.h>
|
|
|
|
|
#include <openssl/x509v3.h>
|
|
|
|
|
#include <openssl/crypto.h>
|
|
|
|
|
#include <openssl/engine.h>
|
|
|
|
|
#include <openssl/pkcs12.h>
|
|
|
|
|
#include <openssl/rsa.h>
|
|
|
|
|
|
|
|
|
|
#include <event2/listener.h>
|
|
|
|
|
#include <event2/http.h>
|
|
|
|
|
#include <event2/buffer.h>
|
|
|
|
|
|
|
|
|
|
#include <async.h>
|
|
|
|
|
#include <MESA/Maat_rule.h>
|
|
|
|
|
#include <field_stat2.h>
|
|
|
|
|
#include <MESA/MESA_prof_load.h>
|
|
|
|
|
#include <MESA/MESA_htable.h>
|
|
|
|
|
|
2018-09-06 19:51:23 +08:00
|
|
|
#include "cert_conf.h"
|
2018-06-19 11:32:16 +08:00
|
|
|
#include "libevent.h"
|
|
|
|
|
#include "cert_session.h"
|
|
|
|
|
#include "logging.h"
|
|
|
|
|
|
2018-09-06 19:51:23 +08:00
|
|
|
#define WAIT_FOR_EFFECTIVE_US 1000*1000
|
|
|
|
|
|
2018-10-23 11:31:57 +08:00
|
|
|
#define SG_DATA_SIZE 10240
|
2018-06-19 11:32:16 +08:00
|
|
|
|
2018-10-22 11:15:57 +08:00
|
|
|
#define LOCAL_USER_PEN 1
|
|
|
|
|
#define LOCAL_USER_DER 2
|
|
|
|
|
#define LOCAL_USER_P12 3
|
|
|
|
|
|
|
|
|
|
#define CM_UPDATE_TYPE_FULL 1
|
|
|
|
|
#define CM_UPDATE_TYPE_INC 2
|
2018-06-19 11:32:16 +08:00
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
static x509_forge_thread *threads;
|
2018-06-29 17:18:33 +08:00
|
|
|
|
2019-08-21 14:03:53 +08:00
|
|
|
enum http_action
|
|
|
|
|
{
|
|
|
|
|
HTTP_ACTION_REQ = 0,
|
|
|
|
|
HTTP_ACTION_SQL,
|
|
|
|
|
HTTP_ACTION_SIGN,
|
|
|
|
|
HTTP_ACTION_ERR,
|
|
|
|
|
HTTP_ACTION_TIME,
|
|
|
|
|
__HTTP_ACTION_MAX
|
|
|
|
|
};
|
|
|
|
|
|
2018-07-05 14:05:28 +08:00
|
|
|
struct fs_stats_t{
|
2019-08-21 14:03:53 +08:00
|
|
|
int line_ids[__HTTP_ACTION_MAX];
|
2018-07-05 14:05:28 +08:00
|
|
|
screen_stat_handle_t handle;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct fs_stats_t SGstats = {
|
|
|
|
|
.line_ids = {0},
|
|
|
|
|
.handle = NULL,
|
|
|
|
|
};
|
|
|
|
|
|
2018-06-29 17:18:33 +08:00
|
|
|
#define sizeof_seconds(x) (x * 24 * 60 * 60)
|
2019-08-07 17:50:24 +08:00
|
|
|
#define half_hours(x) (x * 1800)
|
2018-06-29 17:18:33 +08:00
|
|
|
|
2018-06-19 11:32:16 +08:00
|
|
|
void connectCallback(const struct redisAsyncContext *c, int status) {
|
|
|
|
|
if (status != REDIS_OK) {
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Redis connect error : %s", c->errstr);
|
2018-06-19 11:32:16 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "Redis server connected...");
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void disconnectCallback(const struct redisAsyncContext *c, int status) {
|
|
|
|
|
if (status != REDIS_OK) {
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Redis disconnect error: %s", c->errstr);
|
2018-06-19 11:32:16 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Redis server disconnected...");
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
|
|
|
|
|
2018-09-06 19:51:23 +08:00
|
|
|
void x509_get_private_key(EVP_PKEY *pkey, char *pubkey)
|
|
|
|
|
{
|
|
|
|
|
BIO *bp = NULL;
|
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
|
|
if ( (bp=BIO_new(BIO_s_mem())) == NULL){
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "unable to create BIO for output");
|
2018-09-06 19:51:23 +08:00
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
PEM_write_bio_PrivateKey(bp, pkey, NULL, NULL, 0, NULL, NULL);
|
|
|
|
|
len = BIO_read(bp, pubkey, SG_DATA_SIZE);
|
|
|
|
|
if(len <= 0) {
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Error reading signature file");
|
|
|
|
|
goto free_err;
|
|
|
|
|
}
|
|
|
|
|
pubkey[len] = '\0';
|
|
|
|
|
|
|
|
|
|
free_err:
|
|
|
|
|
BIO_free(bp);
|
|
|
|
|
finish:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 14:03:53 +08:00
|
|
|
static int x509_public_str2idx(const char *public_algo)
|
|
|
|
|
{
|
|
|
|
|
int bits = 1024;
|
2019-10-12 16:37:04 +08:00
|
|
|
|
|
|
|
|
if (public_algo != NULL && strcasestr(public_algo, "1024") != NULL)
|
2019-08-21 14:03:53 +08:00
|
|
|
{
|
|
|
|
|
bits = 1024;
|
|
|
|
|
}
|
2019-10-12 16:37:04 +08:00
|
|
|
if (public_algo != NULL && strcasestr(public_algo, "2048") != NULL)
|
2019-08-21 14:03:53 +08:00
|
|
|
{
|
|
|
|
|
bits = 2048;
|
|
|
|
|
}
|
2019-10-12 16:37:04 +08:00
|
|
|
if (public_algo != NULL && strcasestr(public_algo, "4096") != NULL)
|
2019-08-21 14:03:53 +08:00
|
|
|
{
|
|
|
|
|
bits = 4096;
|
|
|
|
|
}
|
|
|
|
|
return bits;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-06 19:51:23 +08:00
|
|
|
static
|
2019-11-05 11:38:40 +08:00
|
|
|
int ssl_key_genrsa(EVP_PKEY** pkey, char *pubkey, char *public_algo)
|
2018-09-06 19:51:23 +08:00
|
|
|
{
|
|
|
|
|
RSA *rsa = NULL;
|
|
|
|
|
EVP_PKEY *pk = NULL;
|
|
|
|
|
|
|
|
|
|
if((pk = EVP_PKEY_new()) == NULL){
|
2019-11-05 11:38:40 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "ssl_key_genrsa, gen new key failed!");
|
2018-09-06 19:51:23 +08:00
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 14:03:53 +08:00
|
|
|
rsa = RSA_generate_key(x509_public_str2idx(public_algo), RSA_F4, NULL, NULL);
|
2018-09-06 19:51:23 +08:00
|
|
|
if(!EVP_PKEY_assign_RSA(pk, rsa)){
|
2019-11-05 11:38:40 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "ssl_key_genrsa, assign key failed!");
|
2018-09-06 19:51:23 +08:00
|
|
|
EVP_PKEY_free(pk);
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
x509_get_private_key(pk, pubkey);
|
|
|
|
|
rsa = NULL;
|
|
|
|
|
|
|
|
|
|
*pkey = pk;
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
err:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:15:57 +08:00
|
|
|
static X509* base_load_pkcs12(BIO *in, EVP_PKEY **pkey, X509 **x, STACK_OF(X509) **ca)
|
|
|
|
|
{
|
2019-04-28 17:01:27 +08:00
|
|
|
PKCS12 *p12 = NULL;
|
2018-10-22 11:15:57 +08:00
|
|
|
const char *pass = "";
|
|
|
|
|
|
|
|
|
|
X509 *_x = NULL;
|
|
|
|
|
EVP_PKEY *_pkey;
|
|
|
|
|
STACK_OF(X509) *_ca = NULL;
|
|
|
|
|
|
|
|
|
|
OpenSSL_add_all_algorithms();
|
|
|
|
|
ERR_load_crypto_strings();
|
|
|
|
|
|
|
|
|
|
p12 = d2i_PKCS12_bio(in, NULL);
|
|
|
|
|
if (p12 == NULL) {
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Error loading PKCS12 file");
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
if (!PKCS12_parse(p12, pass, &_pkey, &_x, &_ca)) {
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Error parsing PKCS#12 file");
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (x)
|
|
|
|
|
*x = _x;
|
|
|
|
|
if (pkey)
|
|
|
|
|
*pkey = _pkey;
|
|
|
|
|
if (ca)
|
|
|
|
|
*ca = _ca;
|
|
|
|
|
|
|
|
|
|
finish:
|
|
|
|
|
if (p12)
|
|
|
|
|
PKCS12_free(p12);
|
|
|
|
|
return _x;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-12 16:37:04 +08:00
|
|
|
int x509_get_last_ca(char *file, X509 *cx509)
|
|
|
|
|
{
|
|
|
|
|
int last = 0;
|
|
|
|
|
X509 *x = NULL;
|
|
|
|
|
BIO *bio = NULL;
|
|
|
|
|
|
|
|
|
|
if ((bio = BIO_new(BIO_s_file())) == NULL)
|
|
|
|
|
{
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
if (BIO_read_filename(bio, file) <= 0)
|
|
|
|
|
{
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
while(NULL!=(x=PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL)))
|
|
|
|
|
{
|
|
|
|
|
if (0 == X509_NAME_cmp(X509_get_issuer_name(x), X509_get_subject_name(cx509)))
|
|
|
|
|
{
|
|
|
|
|
last = 1;
|
|
|
|
|
X509_free(x);
|
|
|
|
|
break;
|
|
|
|
|
};
|
|
|
|
|
X509_free(x);
|
|
|
|
|
}
|
|
|
|
|
BIO_free (bio);
|
|
|
|
|
finish:
|
|
|
|
|
return last;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
X509* x509_get_root_ca(char *file, STACK_OF(X509) **stack_ca)
|
|
|
|
|
{
|
|
|
|
|
int x509_cnt = 0;
|
|
|
|
|
BIO *bio = NULL;
|
2019-10-12 18:10:56 +08:00
|
|
|
STACK_OF(X509) *stack_x509 = NULL;
|
|
|
|
|
X509 *x = NULL, *node = NULL, *root = NULL;
|
2019-10-12 16:37:04 +08:00
|
|
|
|
|
|
|
|
if(!file){
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Input cert file is empty.");
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((bio = BIO_new(BIO_s_file())) == NULL) {
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Bio malloc failed.");
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
if (BIO_read_filename(bio, file) <= 0) {
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Error opening %s", file);
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
if ((stack_x509 = sk_X509_new_null()) == NULL)
|
|
|
|
|
{
|
|
|
|
|
X509err(X509_F_X509_VERIFY_CERT, ERR_R_MALLOC_FAILURE);
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while(NULL!=(x=PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL))){
|
|
|
|
|
if (0 == X509_NAME_cmp(X509_get_issuer_name(x), X509_get_subject_name(x))){
|
|
|
|
|
/*This is root ca**/
|
2019-10-12 18:10:56 +08:00
|
|
|
root = x;
|
2019-10-12 16:37:04 +08:00
|
|
|
continue;
|
|
|
|
|
};
|
|
|
|
|
/*This is last ca*/
|
|
|
|
|
if (x509_get_last_ca(file, x) == 0){
|
2019-10-12 18:10:56 +08:00
|
|
|
node = x;
|
2019-10-12 16:37:04 +08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
sk_X509_push(stack_x509, x);
|
|
|
|
|
x509_cnt++;
|
|
|
|
|
}
|
|
|
|
|
if (x509_cnt >= 1)
|
|
|
|
|
*stack_ca = stack_x509;
|
2019-10-12 18:10:56 +08:00
|
|
|
if (node != NULL)
|
|
|
|
|
X509_free(root);
|
|
|
|
|
else
|
|
|
|
|
node = root;
|
2019-10-12 16:37:04 +08:00
|
|
|
BIO_free (bio);
|
|
|
|
|
finish:
|
2019-10-12 18:10:56 +08:00
|
|
|
return node;
|
2019-10-12 16:37:04 +08:00
|
|
|
}
|
|
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
EVP_PKEY * cert_base_key_x509 (BIO * bio, int iFormat, const char *strPwd)
|
2018-10-22 11:15:57 +08:00
|
|
|
{
|
|
|
|
|
EVP_PKEY *pkey = NULL;
|
|
|
|
|
|
|
|
|
|
switch (iFormat){
|
|
|
|
|
case LOCAL_USER_PEN:
|
2019-11-05 11:38:40 +08:00
|
|
|
pkey = PEM_read_bio_PrivateKey (bio, NULL, NULL, (char *)strPwd);
|
2018-10-22 11:15:57 +08:00
|
|
|
break;
|
|
|
|
|
case LOCAL_USER_P12:
|
|
|
|
|
base_load_pkcs12(bio, &pkey, NULL, NULL);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pkey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EVP_PKEY * cert_load_key(char *keyfile)
|
|
|
|
|
{
|
|
|
|
|
EVP_PKEY *pkey = NULL;
|
|
|
|
|
BIO *in = NULL;
|
|
|
|
|
|
|
|
|
|
if(!keyfile){
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Input key file is empty.");
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
if ((in = BIO_new(BIO_s_file())) == NULL) {
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Bio malloc failed.");
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
if (BIO_read_filename(in, keyfile) <= 0) {
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Error opening %s\n", keyfile);
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((pkey = cert_base_key_x509 (in, LOCAL_USER_PEN, "")) != NULL)
|
|
|
|
|
goto finish;
|
|
|
|
|
(void)BIO_reset (in);
|
|
|
|
|
if ((pkey = cert_base_key_x509 (in, LOCAL_USER_P12, "")) != NULL)
|
|
|
|
|
goto finish;
|
|
|
|
|
finish:
|
|
|
|
|
if (in != NULL)
|
|
|
|
|
BIO_free (in);
|
|
|
|
|
return pkey;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-06 19:51:23 +08:00
|
|
|
static void key_ring_free(void *data)
|
|
|
|
|
{
|
|
|
|
|
struct pxy_obj_keyring *pxy_obj = NULL;
|
|
|
|
|
pxy_obj = (struct pxy_obj_keyring *)data;
|
|
|
|
|
|
|
|
|
|
X509_free(pxy_obj->root);
|
|
|
|
|
EVP_PKEY_free(pxy_obj->key);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-10 10:01:27 +08:00
|
|
|
void key_ring_list_destroy(MESA_htable_handle *htable)
|
2018-09-06 19:51:23 +08:00
|
|
|
{
|
2018-09-10 10:01:27 +08:00
|
|
|
MESA_htable_destroy(*htable, key_ring_free);
|
|
|
|
|
*htable = NULL;
|
|
|
|
|
return;
|
2018-09-06 19:51:23 +08:00
|
|
|
}
|
|
|
|
|
|
2019-01-22 14:08:13 +06:00
|
|
|
void uuid_squeeze(char *s,int c)
|
2018-06-19 11:32:16 +08:00
|
|
|
{
|
2019-01-22 14:08:13 +06:00
|
|
|
int i,j;
|
|
|
|
|
for (i = 0, j = 0; s[i] != '\0'; i++)
|
|
|
|
|
{
|
|
|
|
|
if (s[i] != c)
|
|
|
|
|
{
|
|
|
|
|
s[j++] = s[i];
|
|
|
|
|
}
|
2019-01-21 15:32:34 +06:00
|
|
|
}
|
2019-01-22 14:08:13 +06:00
|
|
|
s[j] = '\0';
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2019-01-22 14:08:13 +06:00
|
|
|
ssl_x509_set_serial(ASN1_INTEGER *ai)
|
2018-06-19 11:32:16 +08:00
|
|
|
{
|
2019-01-22 14:08:13 +06:00
|
|
|
int ret = -1;
|
|
|
|
|
uuid_t uu;
|
|
|
|
|
char buf[64] = {0};
|
|
|
|
|
BIGNUM *bignum = NULL;
|
2018-06-19 11:32:16 +08:00
|
|
|
|
2019-01-22 14:08:13 +06:00
|
|
|
uuid_generate(uu);
|
|
|
|
|
uuid_unparse(uu, buf);
|
|
|
|
|
uuid_squeeze(buf, '-');
|
|
|
|
|
|
|
|
|
|
BN_hex2bn(&bignum, buf);
|
|
|
|
|
|
|
|
|
|
if (ai && !BN_to_ASN1_INTEGER(bignum, ai))
|
|
|
|
|
goto error;
|
|
|
|
|
ret = 1;
|
|
|
|
|
error:
|
2019-04-28 17:01:27 +08:00
|
|
|
if (bignum)
|
2019-01-22 14:08:13 +06:00
|
|
|
BN_free(bignum);
|
|
|
|
|
return ret;
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
|
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
/*
|
|
|
|
|
* Add a X509v3 extension to a cert and handle errors.
|
|
|
|
|
* Returns -1 on errors, 0 on success.
|
|
|
|
|
*/
|
|
|
|
|
int ssl_x509_v3ext_add(X509V3_CTX * ctx, X509 * crt, const char *k, const char *v)
|
2018-06-19 11:32:16 +08:00
|
|
|
{
|
2019-11-05 11:38:40 +08:00
|
|
|
X509_EXTENSION * ext;
|
2018-06-19 11:32:16 +08:00
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
if (!(ext = X509V3_EXT_conf(NULL, ctx, k, v)))
|
|
|
|
|
{
|
2018-06-19 11:32:16 +08:00
|
|
|
return -1;
|
|
|
|
|
}
|
2019-11-05 11:38:40 +08:00
|
|
|
if (X509_add_ext(crt, ext, -1) != 1)
|
|
|
|
|
{
|
2018-06-19 11:32:16 +08:00
|
|
|
X509_EXTENSION_free(ext);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
X509_EXTENSION_free(ext);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
int ssl_x509_v3ext_copy_by_nid(X509 *crt, X509 *origcrt, int nid)
|
2018-06-19 11:32:16 +08:00
|
|
|
{
|
|
|
|
|
X509_EXTENSION *ext;
|
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
|
|
pos = X509_get_ext_by_NID(origcrt, nid, -1);
|
|
|
|
|
if (pos == -1)
|
|
|
|
|
return 0;
|
|
|
|
|
ext = X509_get_ext(origcrt, pos);
|
|
|
|
|
if (!ext)
|
|
|
|
|
return -1;
|
2018-09-10 18:20:24 +08:00
|
|
|
|
2018-06-19 11:32:16 +08:00
|
|
|
if (X509_add_ext(crt, ext, -1) != 1)
|
|
|
|
|
return -1;
|
2018-09-10 18:20:24 +08:00
|
|
|
|
2018-06-19 11:32:16 +08:00
|
|
|
return 1;
|
|
|
|
|
}
|
2018-09-10 18:20:24 +08:00
|
|
|
/*
|
|
|
|
|
* Add extension using V3 code: we can set the config file as NULL because we
|
|
|
|
|
* wont reference any other sections.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int add_ext(X509 *cacrt, X509 *cert, int nid, char *value)
|
|
|
|
|
{
|
|
|
|
|
X509_EXTENSION *ex;
|
|
|
|
|
X509V3_CTX ctx;
|
|
|
|
|
/* This sets the 'context' of the extensions. */
|
|
|
|
|
/* No configuration database */
|
|
|
|
|
X509V3_set_ctx_nodb(&ctx);
|
|
|
|
|
/*
|
|
|
|
|
* Issuer and subject certs: both the target since it is self signed, no
|
|
|
|
|
* request and no CRL
|
|
|
|
|
*/
|
|
|
|
|
X509V3_set_ctx(&ctx, cacrt, cert, NULL, NULL, 0);
|
|
|
|
|
ex = X509V3_EXT_conf_nid(NULL, &ctx, nid, value);
|
|
|
|
|
if (!ex)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
X509_add_ext(cert, ex, -1);
|
|
|
|
|
X509_EXTENSION_free(ex);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 15:49:38 +08:00
|
|
|
static time_t ASN1_GetTimeT(ASN1_TIME* time)
|
|
|
|
|
{
|
|
|
|
|
struct tm t;
|
|
|
|
|
const char* str = (const char*) time->data;
|
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
|
|
|
|
memset(&t, 0, sizeof(t));
|
|
|
|
|
|
|
|
|
|
if (time->type == V_ASN1_UTCTIME) {/* two digit year */
|
|
|
|
|
t.tm_year = (str[i++] - '0') * 10;
|
|
|
|
|
t.tm_year += (str[i++] - '0');
|
|
|
|
|
if (t.tm_year < 70)
|
|
|
|
|
t.tm_year += 100;
|
|
|
|
|
} else if (time->type == V_ASN1_GENERALIZEDTIME) {/* four digit year */
|
|
|
|
|
t.tm_year = (str[i++] - '0') * 1000;
|
|
|
|
|
t.tm_year+= (str[i++] - '0') * 100;
|
|
|
|
|
t.tm_year+= (str[i++] - '0') * 10;
|
|
|
|
|
t.tm_year+= (str[i++] - '0');
|
|
|
|
|
t.tm_year -= 1900;
|
|
|
|
|
}
|
|
|
|
|
t.tm_mon = (str[i++] - '0') * 10;
|
|
|
|
|
t.tm_mon += (str[i++] - '0') - 1; // -1 since January is 0 not 1.
|
|
|
|
|
t.tm_mday = (str[i++] - '0') * 10;
|
|
|
|
|
t.tm_mday+= (str[i++] - '0');
|
|
|
|
|
t.tm_hour = (str[i++] - '0') * 10;
|
|
|
|
|
t.tm_hour+= (str[i++] - '0');
|
|
|
|
|
t.tm_min = (str[i++] - '0') * 10;
|
|
|
|
|
t.tm_min += (str[i++] - '0');
|
|
|
|
|
t.tm_sec = (str[i++] - '0') * 10;
|
|
|
|
|
t.tm_sec += (str[i++] - '0');
|
|
|
|
|
|
|
|
|
|
/* Note: we did not adjust the time based on time zone information */
|
|
|
|
|
setenv("TZ", "UTC", 1);
|
|
|
|
|
return mktime(&t);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-19 11:32:16 +08:00
|
|
|
X509 *
|
2019-11-05 11:38:40 +08:00
|
|
|
ssl_x509_forge(X509 *cacrt, EVP_PKEY *cakey, X509 *origcrt, char *pkey, int *expire_time, char *crlurl, char *public_algo)
|
2018-06-19 11:32:16 +08:00
|
|
|
{
|
|
|
|
|
int rv;
|
2018-09-06 19:51:23 +08:00
|
|
|
X509 *crt = NULL;
|
|
|
|
|
EVP_PKEY* key = NULL;
|
|
|
|
|
X509_NAME *subject = NULL, *issuer = NULL;
|
|
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
if(!ssl_key_genrsa(&key, pkey, public_algo)){
|
2018-09-06 19:51:23 +08:00
|
|
|
goto err;
|
|
|
|
|
}
|
2019-11-05 11:38:40 +08:00
|
|
|
//subjectname,issuername
|
2018-06-19 11:32:16 +08:00
|
|
|
subject = X509_get_subject_name(origcrt);
|
|
|
|
|
issuer = X509_get_subject_name(cacrt);
|
|
|
|
|
if (!subject || !issuer)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
crt = X509_new();
|
|
|
|
|
if (!crt)
|
|
|
|
|
return NULL;
|
2019-11-05 11:38:40 +08:00
|
|
|
//version,subjectname,issuername,serialnum,time,pubkey
|
2018-06-19 11:32:16 +08:00
|
|
|
if (!X509_set_version(crt, 0x02) ||
|
|
|
|
|
!X509_set_subject_name(crt, subject) ||
|
|
|
|
|
!X509_set_issuer_name(crt, issuer) ||
|
2019-01-22 14:08:13 +06:00
|
|
|
ssl_x509_set_serial(X509_get_serialNumber(crt)) == -1 ||
|
2018-06-19 11:32:16 +08:00
|
|
|
!X509_set_pubkey(crt, key))
|
|
|
|
|
goto errout;
|
|
|
|
|
|
2019-08-21 14:03:53 +08:00
|
|
|
if (*expire_time <= 0)
|
2019-08-07 17:50:24 +08:00
|
|
|
{
|
|
|
|
|
int day = 0, sec = 0;
|
|
|
|
|
ASN1_TIME_set(X509_get_notBefore(crt), ASN1_GetTimeT(X509_get_notBefore(origcrt)));
|
|
|
|
|
ASN1_TIME_set(X509_get_notAfter(crt), ASN1_GetTimeT(X509_get_notAfter(origcrt)));
|
|
|
|
|
ASN1_TIME_diff(&day, &sec, X509_get_notBefore(crt), X509_get_notAfter(crt));
|
|
|
|
|
*expire_time = MIN(sizeof_seconds(day) + sec, sizeof_seconds(1));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(!X509_gmtime_adj(X509_get_notBefore(crt), (long)(0 - half_hours(*expire_time))) ||
|
|
|
|
|
!X509_gmtime_adj(X509_get_notAfter(crt), (long)(half_hours(*expire_time))))
|
|
|
|
|
{
|
|
|
|
|
goto errout;
|
|
|
|
|
}
|
2019-08-21 14:03:53 +08:00
|
|
|
*expire_time = half_hours(*expire_time);
|
2019-08-07 17:50:24 +08:00
|
|
|
}
|
2019-08-07 15:49:38 +08:00
|
|
|
|
2018-11-30 19:24:44 +08:00
|
|
|
EVP_PKEY_free(key);
|
2018-06-19 11:32:16 +08:00
|
|
|
//extensions
|
|
|
|
|
X509V3_CTX ctx;
|
|
|
|
|
X509V3_set_ctx(&ctx, cacrt, crt, NULL, NULL, 0);
|
|
|
|
|
|
|
|
|
|
if (ssl_x509_v3ext_add(&ctx, crt, "subjectKeyIdentifier",
|
|
|
|
|
"hash") == -1 ||
|
|
|
|
|
ssl_x509_v3ext_add(&ctx, crt, "authorityKeyIdentifier",
|
|
|
|
|
"keyid,issuer:always") == -1)
|
|
|
|
|
goto errout;
|
|
|
|
|
|
|
|
|
|
rv = ssl_x509_v3ext_copy_by_nid(crt, origcrt,
|
|
|
|
|
NID_basic_constraints);
|
|
|
|
|
if (rv == 0)
|
|
|
|
|
rv = ssl_x509_v3ext_add(&ctx, crt, "basicConstraints",
|
|
|
|
|
"CA:FALSE");
|
|
|
|
|
if (rv == -1)
|
|
|
|
|
goto errout;
|
|
|
|
|
|
2019-06-22 00:25:28 +08:00
|
|
|
rv = ssl_x509_v3ext_add(&ctx, crt, "keyUsage",
|
|
|
|
|
"digitalSignature,"
|
|
|
|
|
"keyEncipherment");
|
2018-06-19 11:32:16 +08:00
|
|
|
if (rv == -1)
|
|
|
|
|
goto errout;
|
|
|
|
|
|
|
|
|
|
rv = ssl_x509_v3ext_copy_by_nid(crt, origcrt,
|
|
|
|
|
NID_ext_key_usage);
|
|
|
|
|
if (rv == 0)
|
|
|
|
|
rv = ssl_x509_v3ext_add(&ctx, crt, "extendedKeyUsage",
|
|
|
|
|
"serverAuth");
|
|
|
|
|
if (rv == -1)
|
|
|
|
|
goto errout;
|
|
|
|
|
|
2019-08-07 17:50:24 +08:00
|
|
|
if (crlurl != NULL && strcasecmp(crlurl, "null")){
|
|
|
|
|
mesa_runtime_log(RLOG_LV_DEBUG, MODULE_NAME, "Sign certificate the CRL is %s", crlurl);
|
|
|
|
|
char * crlurlval;
|
|
|
|
|
if (asprintf(&crlurlval, "URI:%s", crlurl) < 0)
|
|
|
|
|
goto errout;
|
|
|
|
|
if (ssl_x509_v3ext_add(&ctx, crt, "crlDistributionPoints", crlurlval) == -1)
|
|
|
|
|
{
|
|
|
|
|
free(crlurlval);
|
2018-06-19 11:32:16 +08:00
|
|
|
goto errout;
|
|
|
|
|
}
|
2019-08-07 17:50:24 +08:00
|
|
|
free(crlurlval);
|
2018-09-20 10:11:15 +08:00
|
|
|
}
|
2019-06-18 20:45:00 +08:00
|
|
|
/* no extraname provided: copy original subjectAltName ext */
|
|
|
|
|
if (ssl_x509_v3ext_copy_by_nid(crt, origcrt,
|
|
|
|
|
NID_subject_alt_name) == -1)
|
|
|
|
|
{
|
|
|
|
|
goto errout;
|
|
|
|
|
}
|
2018-06-19 11:32:16 +08:00
|
|
|
#ifdef DEBUG_CERTIFICATE
|
|
|
|
|
ssl_x509_v3ext_add(&ctx, crt, "nsComment", "Generated by " PKGLABEL);
|
|
|
|
|
#endif /* DEBUG_CERTIFICATE */
|
|
|
|
|
|
|
|
|
|
const EVP_MD *md;
|
|
|
|
|
switch (EVP_PKEY_type(EVP_PKEY_base_id(cakey))) {
|
|
|
|
|
#ifndef OPENSSL_NO_RSA
|
|
|
|
|
case EVP_PKEY_RSA:
|
|
|
|
|
switch (X509_get_signature_nid(origcrt)) {
|
|
|
|
|
case NID_md5WithRSAEncryption:
|
|
|
|
|
md = EVP_md5();
|
|
|
|
|
break;
|
|
|
|
|
case NID_ripemd160WithRSA:
|
|
|
|
|
md = EVP_ripemd160();
|
|
|
|
|
break;
|
|
|
|
|
case NID_sha1WithRSAEncryption:
|
|
|
|
|
md = EVP_sha1();
|
|
|
|
|
break;
|
|
|
|
|
case NID_sha224WithRSAEncryption:
|
|
|
|
|
md = EVP_sha224();
|
|
|
|
|
break;
|
|
|
|
|
case NID_sha256WithRSAEncryption:
|
|
|
|
|
md = EVP_sha256();
|
|
|
|
|
break;
|
|
|
|
|
case NID_sha384WithRSAEncryption:
|
|
|
|
|
md = EVP_sha384();
|
|
|
|
|
break;
|
|
|
|
|
case NID_sha512WithRSAEncryption:
|
|
|
|
|
md = EVP_sha512();
|
|
|
|
|
break;
|
|
|
|
|
#ifndef OPENSSL_NO_SHA0
|
|
|
|
|
case NID_shaWithRSAEncryption:
|
|
|
|
|
md = EVP_sha();
|
|
|
|
|
break;
|
|
|
|
|
#endif /* !OPENSSL_NO_SHA0 */
|
|
|
|
|
default:
|
|
|
|
|
md = EVP_sha256();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
#endif /* !OPENSSL_NO_RSA */
|
|
|
|
|
#ifndef OPENSSL_NO_DSA
|
|
|
|
|
case EVP_PKEY_DSA:
|
|
|
|
|
switch (X509_get_signature_nid(origcrt)) {
|
|
|
|
|
case NID_dsaWithSHA1:
|
|
|
|
|
case NID_dsaWithSHA1_2:
|
|
|
|
|
md = EVP_sha1();
|
|
|
|
|
break;
|
|
|
|
|
case NID_dsa_with_SHA224:
|
|
|
|
|
md = EVP_sha224();
|
|
|
|
|
break;
|
|
|
|
|
case NID_dsa_with_SHA256:
|
|
|
|
|
md = EVP_sha256();
|
|
|
|
|
break;
|
|
|
|
|
#ifndef OPENSSL_NO_SHA0
|
|
|
|
|
case NID_dsaWithSHA:
|
|
|
|
|
md = EVP_sha();
|
|
|
|
|
break;
|
|
|
|
|
#endif /* !OPENSSL_NO_SHA0 */
|
|
|
|
|
default:
|
|
|
|
|
md = EVP_sha256();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
#endif /* !OPENSSL_NO_DSA */
|
|
|
|
|
#ifndef OPENSSL_NO_ECDSA
|
|
|
|
|
case EVP_PKEY_EC:
|
|
|
|
|
switch (X509_get_signature_nid(origcrt)) {
|
|
|
|
|
case NID_ecdsa_with_SHA1:
|
|
|
|
|
md = EVP_sha1();
|
|
|
|
|
break;
|
|
|
|
|
case NID_ecdsa_with_SHA224:
|
|
|
|
|
md = EVP_sha224();
|
|
|
|
|
break;
|
|
|
|
|
case NID_ecdsa_with_SHA256:
|
|
|
|
|
md = EVP_sha256();
|
|
|
|
|
break;
|
|
|
|
|
case NID_ecdsa_with_SHA384:
|
|
|
|
|
md = EVP_sha384();
|
|
|
|
|
break;
|
|
|
|
|
case NID_ecdsa_with_SHA512:
|
|
|
|
|
md = EVP_sha512();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
md = EVP_sha256();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
#endif /* !OPENSSL_NO_ECDSA */
|
|
|
|
|
default:
|
|
|
|
|
goto errout;
|
|
|
|
|
}
|
|
|
|
|
if (!X509_sign(crt, cakey, md))
|
|
|
|
|
goto errout;
|
|
|
|
|
|
|
|
|
|
return crt;
|
|
|
|
|
errout:
|
|
|
|
|
X509_free(crt);
|
2018-11-30 19:24:44 +08:00
|
|
|
EVP_PKEY_free(key);
|
2018-09-06 19:51:23 +08:00
|
|
|
err:
|
2018-06-19 11:32:16 +08:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-16 16:22:35 +06:00
|
|
|
void x509_get_msg_from_ca(X509 *x509, char **root)
|
2018-06-19 11:32:16 +08:00
|
|
|
{
|
2018-06-28 11:05:53 +08:00
|
|
|
BIO *bp = NULL;
|
2018-06-19 11:32:16 +08:00
|
|
|
int len = 0;
|
2019-10-12 16:37:04 +08:00
|
|
|
|
2018-06-19 11:32:16 +08:00
|
|
|
if ( (bp=BIO_new(BIO_s_mem())) == NULL){
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "unable to create BIO for output");
|
2019-11-05 11:38:40 +08:00
|
|
|
return;
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
2018-06-28 11:05:53 +08:00
|
|
|
PEM_write_bio_X509(bp, x509);
|
2019-01-16 16:22:35 +06:00
|
|
|
|
|
|
|
|
char *p = NULL;
|
|
|
|
|
len = BIO_get_mem_data(bp, &p);
|
|
|
|
|
*root = (char*)malloc(len + 1);
|
|
|
|
|
memset(*root, 0, len + 1);
|
|
|
|
|
|
|
|
|
|
len = BIO_read(bp, *root, len);
|
2018-06-19 11:32:16 +08:00
|
|
|
if(len <= 0) {
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Error reading signature file");
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
err:
|
|
|
|
|
BIO_free(bp);
|
2018-06-28 11:05:53 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-06 19:51:23 +08:00
|
|
|
X509 *
|
|
|
|
|
x509_get_ca_from_msg(const char *cert, int len)
|
2018-06-28 11:05:53 +08:00
|
|
|
{
|
2018-09-06 19:51:23 +08:00
|
|
|
BIO *bp;
|
2018-09-20 10:11:15 +08:00
|
|
|
char *in = NULL;
|
2018-09-06 19:51:23 +08:00
|
|
|
X509* x509 = NULL;
|
2018-09-20 10:11:15 +08:00
|
|
|
|
|
|
|
|
in = (char *)kmalloc(len, MPF_CLR, -1);
|
|
|
|
|
assert(in);
|
2018-09-06 19:51:23 +08:00
|
|
|
|
|
|
|
|
strncpy(in, cert, len);
|
2018-06-28 11:05:53 +08:00
|
|
|
|
|
|
|
|
if ( (bp=BIO_new(BIO_s_mem())) == NULL){
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "unable to create BIO for output");
|
2018-06-28 11:05:53 +08:00
|
|
|
goto finish;
|
|
|
|
|
}
|
2018-09-06 19:51:23 +08:00
|
|
|
BIO_printf(bp, "%s", in);
|
|
|
|
|
x509 = PEM_read_bio_X509(bp, NULL, NULL, NULL);
|
|
|
|
|
if(NULL == x509) {
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Failed to read pem file");
|
2018-09-06 19:51:23 +08:00
|
|
|
goto err;
|
2018-06-28 11:05:53 +08:00
|
|
|
}
|
2018-09-06 19:51:23 +08:00
|
|
|
err:
|
|
|
|
|
BIO_free(bp);
|
2018-06-28 11:05:53 +08:00
|
|
|
finish:
|
2018-09-20 10:11:15 +08:00
|
|
|
free(in);
|
2018-09-06 19:51:23 +08:00
|
|
|
return x509;
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-08 16:06:23 +08:00
|
|
|
void request_destroy(struct request_t *request)
|
|
|
|
|
{
|
|
|
|
|
if (request->odata)
|
|
|
|
|
{
|
|
|
|
|
free(request->odata);
|
|
|
|
|
request->odata=NULL;
|
|
|
|
|
}
|
|
|
|
|
if (request->sni)
|
|
|
|
|
{
|
|
|
|
|
free(request->sni);
|
|
|
|
|
request->sni=NULL;
|
|
|
|
|
}
|
|
|
|
|
free(request);
|
|
|
|
|
request = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-26 17:18:00 +08:00
|
|
|
static
|
2018-07-09 14:32:41 +08:00
|
|
|
int redis_rsync_init(struct event_base *base, struct redisAsyncContext **cl_ctx)
|
2018-06-19 11:32:16 +08:00
|
|
|
{
|
|
|
|
|
int xret = -1;
|
|
|
|
|
struct config_bucket_t *redis = cert_default_config();
|
|
|
|
|
|
2018-10-22 11:15:57 +08:00
|
|
|
*cl_ctx = redisAsyncConnect(redis->addr_t.store_ip, redis->addr_t.store_port);
|
2018-07-05 14:05:28 +08:00
|
|
|
if((*cl_ctx)->err ) {
|
2018-06-29 17:18:33 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Redis Connect error : %s", (*cl_ctx)->errstr);
|
2018-06-19 11:32:16 +08:00
|
|
|
goto finish;
|
|
|
|
|
}
|
2018-06-29 17:18:33 +08:00
|
|
|
redisLibeventAttach((*cl_ctx), base);
|
|
|
|
|
redisAsyncSetConnectCallback((*cl_ctx), connectCallback);
|
|
|
|
|
redisAsyncSetDisconnectCallback((*cl_ctx), disconnectCallback);
|
2018-07-18 10:47:45 +08:00
|
|
|
|
2018-06-19 11:32:16 +08:00
|
|
|
xret = 0;
|
|
|
|
|
|
|
|
|
|
finish:
|
|
|
|
|
return xret;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 14:03:53 +08:00
|
|
|
static int
|
|
|
|
|
evhttp_socket_send_error(struct evhttp_request *req, int id, int error)
|
|
|
|
|
{
|
2019-11-05 11:38:40 +08:00
|
|
|
FS_operate(SGstats.handle, id, SGstats.line_ids[HTTP_ACTION_ERR], FS_OP_ADD, 1);
|
2019-08-21 14:03:53 +08:00
|
|
|
evhttp_send_error(req, error, 0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-19 11:32:16 +08:00
|
|
|
/* Callback used for the /dump URI, and for every non-GET request:
|
|
|
|
|
* dumps all information to stdout and gives back a trivial 200 ok */
|
|
|
|
|
static int
|
2018-06-28 11:05:53 +08:00
|
|
|
evhttp_socket_send(struct evhttp_request *req, char *sendbuf)
|
2018-06-19 11:32:16 +08:00
|
|
|
{
|
|
|
|
|
struct evbuffer *evb = NULL;
|
|
|
|
|
|
|
|
|
|
/* This holds the content we're sending. */
|
|
|
|
|
evb = evbuffer_new();
|
|
|
|
|
|
2018-06-29 17:18:33 +08:00
|
|
|
if (sendbuf[0] == '\0' && req == NULL){
|
2018-06-19 11:32:16 +08:00
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req),
|
2019-08-21 14:03:53 +08:00
|
|
|
"Content-Type", "text/html");
|
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Connection", "keep-alive");
|
2018-06-28 11:05:53 +08:00
|
|
|
evbuffer_add_printf(evb, "%s", sendbuf);
|
2018-07-18 10:47:45 +08:00
|
|
|
evhttp_send_reply(req, HTTP_OK, "OK", evb);
|
2018-06-19 11:32:16 +08:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
|
|
err:
|
2018-07-18 10:47:45 +08:00
|
|
|
evhttp_send_error(req, HTTP_NOTFOUND, "Document was not found");
|
2018-06-19 11:32:16 +08:00
|
|
|
done:
|
|
|
|
|
evbuffer_free(evb);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-27 10:58:23 +08:00
|
|
|
static void
|
2018-07-18 10:47:45 +08:00
|
|
|
redis_reget_callback(redisAsyncContext __attribute__((__unused__))*cl_ctx,
|
|
|
|
|
void *r, void *privdata)
|
2018-06-27 10:58:23 +08:00
|
|
|
{
|
2018-07-18 10:47:45 +08:00
|
|
|
redisReply *reply = (redisReply*)r;
|
2018-06-27 10:58:23 +08:00
|
|
|
|
2018-07-18 10:47:45 +08:00
|
|
|
struct request_t *request = (struct request_t *)privdata;
|
|
|
|
|
|
|
|
|
|
struct evhttp_request *evh_req = request->evh_req;
|
|
|
|
|
evhttp_socket_send(evh_req, reply->str);
|
2019-08-08 16:06:23 +08:00
|
|
|
request_destroy(request);
|
2018-07-18 10:47:45 +08:00
|
|
|
return;
|
2018-06-27 10:58:23 +08:00
|
|
|
}
|
|
|
|
|
|
2019-05-28 19:12:21 +08:00
|
|
|
void keyring_table_free_cb(int __attribute__((__unused__))table_id, MAAT_PLUGIN_EX_DATA* ad,
|
|
|
|
|
long __attribute__((__unused__))argl, void __attribute__((__unused__))*argp)
|
|
|
|
|
{
|
2019-06-18 20:45:00 +08:00
|
|
|
if (*ad == NULL)
|
2019-06-14 13:25:46 +08:00
|
|
|
return;
|
2019-11-05 11:38:40 +08:00
|
|
|
struct pxy_obj_keyring* pxy_obj=(struct pxy_obj_keyring*)(*ad);
|
2019-06-14 20:18:19 +08:00
|
|
|
atomic64_dec(&pxy_obj->ref_cnt);
|
2019-06-14 13:25:46 +08:00
|
|
|
if (atomic64_read(&pxy_obj->ref_cnt) == 0)
|
2019-05-28 19:12:21 +08:00
|
|
|
{
|
2019-11-05 11:38:40 +08:00
|
|
|
#ifdef RT_REDIS_ADVANCED
|
|
|
|
|
int xret; char *command;
|
|
|
|
|
asprintf(&command, "redis-cli keys \"%d*\" | xargs redis-cli del", pxy_obj->keyring_id);
|
|
|
|
|
xret = system(command);
|
|
|
|
|
if ((-1 == xret) || (!WIFEXITED(xret)) || (0 != WEXITSTATUS(xret))){
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "del keyringid %d failed", pxy_obj->keyring_id);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2019-06-01 17:39:12 +08:00
|
|
|
if (pxy_obj->root)
|
|
|
|
|
X509_free(pxy_obj->root);
|
|
|
|
|
if (pxy_obj->key)
|
|
|
|
|
EVP_PKEY_free(pxy_obj->key);
|
2019-06-18 20:45:00 +08:00
|
|
|
free(pxy_obj);
|
|
|
|
|
pxy_obj = NULL;
|
2019-05-28 19:12:21 +08:00
|
|
|
*ad=NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void keyring_table_free(struct pxy_obj_keyring* pxy_obj)
|
|
|
|
|
{
|
|
|
|
|
keyring_table_free_cb(0, (void **)&pxy_obj, 0, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-26 17:18:00 +08:00
|
|
|
int add_cert_ctx(X509_NAME* name, char* ctx[], int num)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
int max = 0;
|
|
|
|
|
|
|
|
|
|
int item[] = {NID_commonName, NID_countryName,
|
|
|
|
|
NID_stateOrProvinceName, NID_localityName,
|
|
|
|
|
NID_organizationName, NID_organizationalUnitName,
|
|
|
|
|
NID_pkcs9_emailAddress};
|
|
|
|
|
|
|
|
|
|
max = sizeof(item)/sizeof(item[0]);
|
|
|
|
|
max = max > num ? num : max;
|
|
|
|
|
|
|
|
|
|
for(i = 0; i< max; ++i){
|
|
|
|
|
if(!X509_NAME_add_entry_by_NID(name, item[i], MBSTRING_UTF8, (unsigned char *)ctx[i], -1, -1, 0)){
|
|
|
|
|
mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "add_cert_ctx, add entry:%d to %s failed!", item[i], ctx[i]);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rand_serial(BIGNUM *b, ASN1_INTEGER *ai)
|
|
|
|
|
{
|
|
|
|
|
#define SERIAL_RAND_BITS 124
|
|
|
|
|
BIGNUM *btmp;
|
|
|
|
|
int ret = 0;
|
|
|
|
|
if (b)
|
|
|
|
|
btmp = b;
|
|
|
|
|
else
|
|
|
|
|
btmp = BN_new();
|
|
|
|
|
if (!btmp)
|
|
|
|
|
return 0;
|
|
|
|
|
if (!BN_pseudo_rand(btmp, SERIAL_RAND_BITS, 0, 0))
|
|
|
|
|
goto error;
|
|
|
|
|
if (ai && !BN_to_ASN1_INTEGER(btmp, ai))
|
|
|
|
|
goto error;
|
|
|
|
|
ret = 1;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
if (!b)
|
|
|
|
|
BN_free(btmp);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-22 14:08:13 +06:00
|
|
|
char *x509_get_sn(X509 *x509)
|
|
|
|
|
{
|
|
|
|
|
ASN1_INTEGER *asn1_i = NULL;
|
|
|
|
|
BIGNUM *bignum = NULL;
|
|
|
|
|
char *serial = NULL;
|
|
|
|
|
|
|
|
|
|
asn1_i = X509_get_serialNumber(x509);
|
|
|
|
|
bignum = ASN1_INTEGER_to_BN(asn1_i, NULL);
|
|
|
|
|
if (bignum == NULL) {
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
serial = BN_bn2hex(bignum);
|
|
|
|
|
if (serial == NULL) {
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
BN_free(bignum);
|
|
|
|
|
finish:
|
|
|
|
|
return serial;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-24 15:09:34 +08:00
|
|
|
static struct pxy_obj_keyring* get_obj_for_id(int keyring_id)
|
|
|
|
|
{
|
|
|
|
|
struct pxy_obj_keyring *pxy_obj=NULL;
|
|
|
|
|
|
|
|
|
|
struct config_bucket_t *rte = cert_default_config();
|
|
|
|
|
|
2019-05-28 19:12:21 +08:00
|
|
|
char cfg_id_str[16] = {0};
|
|
|
|
|
snprintf(cfg_id_str, sizeof(cfg_id_str), "%d", keyring_id);
|
2019-05-24 15:09:34 +08:00
|
|
|
|
|
|
|
|
int tables_id = rte->table_id;
|
2019-11-05 11:38:40 +08:00
|
|
|
pxy_obj = (struct pxy_obj_keyring*)Maat_plugin_get_EX_data(rte->feather, tables_id, (const char*)cfg_id_str);
|
2019-05-24 15:09:34 +08:00
|
|
|
return pxy_obj;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 17:50:24 +08:00
|
|
|
static int x509_online_append(struct x509_object_ctx *def, struct request_t *request,
|
2019-08-07 15:49:38 +08:00
|
|
|
char **root, char **sign, char *pkey,
|
|
|
|
|
STACK_OF(X509) **stack_ca)
|
2018-06-27 10:58:23 +08:00
|
|
|
{
|
2018-11-13 10:31:21 +08:00
|
|
|
X509* x509 = NULL;
|
2019-08-08 17:12:18 +08:00
|
|
|
int is_valid = request->is_valid; int keyring_id = request->keyring_id;
|
2019-08-21 14:03:53 +08:00
|
|
|
int expire_time = 0; char *crlurl = NULL;
|
|
|
|
|
char *serial = NULL, *public_algo = NULL;
|
2019-08-07 17:50:24 +08:00
|
|
|
X509 *cacrt = NULL; EVP_PKEY *cakey = NULL;
|
2018-06-27 10:58:23 +08:00
|
|
|
|
2019-05-24 15:09:34 +08:00
|
|
|
struct config_bucket_t *rte = cert_default_config();
|
|
|
|
|
|
|
|
|
|
if (is_valid == 0 && keyring_id != 0) keyring_id = 0;
|
|
|
|
|
if (is_valid == 1 && keyring_id == 0) keyring_id = 1;
|
|
|
|
|
|
|
|
|
|
struct pxy_obj_keyring *pxy_obj = get_obj_for_id(keyring_id);
|
|
|
|
|
if (NULL == pxy_obj)
|
|
|
|
|
{
|
|
|
|
|
if (!rte->local_debug)
|
|
|
|
|
{
|
|
|
|
|
if (1==is_valid)
|
|
|
|
|
{
|
|
|
|
|
pxy_obj = get_obj_for_id(1);
|
2018-09-10 10:01:27 +08:00
|
|
|
}
|
2019-05-24 15:09:34 +08:00
|
|
|
if (0==is_valid)
|
|
|
|
|
{
|
|
|
|
|
pxy_obj = get_obj_for_id(0);
|
2018-10-22 11:15:57 +08:00
|
|
|
}
|
2019-05-28 19:12:21 +08:00
|
|
|
assert(pxy_obj!=NULL);
|
2019-05-24 15:09:34 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_DEBUG, MODULE_NAME, "Certificate issued by table id %d", keyring_id);
|
2018-09-10 10:01:27 +08:00
|
|
|
}
|
2019-05-24 15:09:34 +08:00
|
|
|
else
|
|
|
|
|
{
|
2019-08-07 17:50:24 +08:00
|
|
|
cacrt = (is_valid == 1) ? def->root : def->insec_root;
|
|
|
|
|
cakey = (is_valid == 1) ? def->key : def->insec_key;
|
|
|
|
|
expire_time = cert_default_config()->expire_after;
|
2019-05-24 15:09:34 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_DEBUG, MODULE_NAME, "Certificate issued by local cert");
|
|
|
|
|
goto modify;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!STRCMP(pxy_obj->keyring_type, "end-entity"))
|
|
|
|
|
{
|
|
|
|
|
mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "The certificate(%d) type is an entity certificate",
|
|
|
|
|
keyring_id);
|
|
|
|
|
*stack_ca = pxy_obj->stack_ca;
|
|
|
|
|
x509_get_msg_from_ca(pxy_obj->root, sign);
|
|
|
|
|
x509_get_private_key(pxy_obj->key, pkey);
|
|
|
|
|
goto finish;
|
2018-06-27 10:58:23 +08:00
|
|
|
}
|
2019-05-24 15:09:34 +08:00
|
|
|
if (!STRCMP(pxy_obj->keyring_type, "intermediate"))
|
|
|
|
|
{
|
|
|
|
|
mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "The certificate(%d) type is intermediate, chain address %p",
|
|
|
|
|
keyring_id, pxy_obj->stack_ca);
|
|
|
|
|
*stack_ca = pxy_obj->stack_ca;
|
|
|
|
|
}
|
2019-08-07 17:50:24 +08:00
|
|
|
cacrt = pxy_obj->root;
|
|
|
|
|
cakey = pxy_obj->key;
|
2019-08-08 17:12:18 +08:00
|
|
|
expire_time = pxy_obj->expire_time;
|
2019-08-07 17:50:24 +08:00
|
|
|
crlurl = pxy_obj->v3_ctl;
|
2019-08-21 14:03:53 +08:00
|
|
|
public_algo = pxy_obj->public_algo;
|
2018-11-13 10:31:21 +08:00
|
|
|
modify:
|
2019-11-05 11:38:40 +08:00
|
|
|
x509 = ssl_x509_forge(cacrt, cakey, request->origin, pkey, &expire_time, crlurl, public_algo);
|
2018-09-10 10:01:27 +08:00
|
|
|
if (!x509){
|
2018-09-06 19:51:23 +08:00
|
|
|
goto finish;
|
|
|
|
|
}
|
2019-04-28 17:01:27 +08:00
|
|
|
serial = x509_get_sn(x509);
|
2019-08-07 17:50:24 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_DEBUG, MODULE_NAME, "The certificate serial number is %s", serial);
|
2019-04-28 17:01:27 +08:00
|
|
|
OPENSSL_free(serial);
|
2019-01-22 14:08:13 +06:00
|
|
|
|
2018-09-10 10:01:27 +08:00
|
|
|
x509_get_msg_from_ca(x509, sign);
|
2019-08-07 17:50:24 +08:00
|
|
|
x509_get_msg_from_ca(cacrt, root);
|
2018-09-06 19:51:23 +08:00
|
|
|
|
2018-11-30 19:24:44 +08:00
|
|
|
if (request->origin)
|
|
|
|
|
X509_free(request->origin);
|
2018-09-10 10:01:27 +08:00
|
|
|
X509_free(x509);
|
2018-06-27 10:58:23 +08:00
|
|
|
finish:
|
2019-05-28 19:12:21 +08:00
|
|
|
if (pxy_obj)
|
|
|
|
|
keyring_table_free(pxy_obj);
|
2019-08-07 17:50:24 +08:00
|
|
|
return expire_time;
|
2018-06-27 10:58:23 +08:00
|
|
|
}
|
|
|
|
|
|
2018-07-18 10:47:45 +08:00
|
|
|
static char readBytes(char *str)
|
2018-07-09 14:32:41 +08:00
|
|
|
{
|
2018-07-18 10:47:45 +08:00
|
|
|
char c;
|
2018-07-09 14:32:41 +08:00
|
|
|
|
2018-07-18 10:47:45 +08:00
|
|
|
if (str && STRCMP(str, "OK") == 0)
|
|
|
|
|
c = '+';
|
|
|
|
|
if (!str)
|
|
|
|
|
c= '$';
|
2018-07-09 14:32:41 +08:00
|
|
|
|
2018-07-18 10:47:45 +08:00
|
|
|
return c;
|
|
|
|
|
}
|
2018-07-09 14:32:41 +08:00
|
|
|
|
2019-08-21 14:03:53 +08:00
|
|
|
static void
|
|
|
|
|
redis_sync_reget_callback(struct request_t *request, struct redisContext *sync)
|
|
|
|
|
{
|
|
|
|
|
struct evhttp_request *evh_req = request->evh_req;
|
|
|
|
|
|
|
|
|
|
redisReply *reply = (redisReply *)redisCommand(sync, "GET %s", request->rkey);
|
|
|
|
|
if (NULL == reply)
|
|
|
|
|
{
|
|
|
|
|
goto free;
|
|
|
|
|
}
|
|
|
|
|
switch (readBytes(reply->str))
|
|
|
|
|
{
|
|
|
|
|
case '+' :
|
|
|
|
|
evhttp_socket_send(evh_req, reply->str);
|
|
|
|
|
break;
|
|
|
|
|
default :
|
|
|
|
|
evhttp_send_error(request->evh_req, HTTP_NOTFOUND, 0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
free:
|
|
|
|
|
freeReplyObject(reply);
|
|
|
|
|
request_destroy(request);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-18 10:47:45 +08:00
|
|
|
static int
|
2019-08-21 14:03:53 +08:00
|
|
|
rediSyncCommand(redisContext *sync, struct request_t *request, char *odata, int expire_after)
|
2018-07-18 10:47:45 +08:00
|
|
|
{
|
|
|
|
|
int xret = -1;
|
|
|
|
|
redisReply *reply;
|
2019-11-05 11:38:40 +08:00
|
|
|
|
|
|
|
|
struct config_bucket_t *config = cert_default_config();;
|
|
|
|
|
x509_forge_thread *thread = threads + request->thread_id;
|
2018-07-18 10:47:45 +08:00
|
|
|
struct evhttp_request *evh_req = request->evh_req;
|
|
|
|
|
|
2019-08-07 15:49:38 +08:00
|
|
|
reply = (redisReply *)redisCommand(thread->sync, "set %s %s ex %d nx", request->rkey, odata, expire_after);
|
2018-07-18 10:47:45 +08:00
|
|
|
if (NULL == reply)
|
|
|
|
|
goto free;
|
|
|
|
|
|
|
|
|
|
switch (readBytes(reply->str)) {
|
|
|
|
|
case '+' :
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "Writing data(%s) to redis successfully", request->rkey);
|
2019-11-05 11:38:40 +08:00
|
|
|
FS_operate(SGstats.handle, thread->column_ids, SGstats.line_ids[HTTP_ACTION_SIGN], FS_OP_ADD, 1);
|
2018-07-18 10:47:45 +08:00
|
|
|
|
2018-09-06 19:51:23 +08:00
|
|
|
evhttp_socket_send(evh_req, request->odata);
|
2018-07-18 10:47:45 +08:00
|
|
|
goto free;
|
|
|
|
|
case '$' :
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "Writing data(%s) to redis failed", request->rkey);
|
2019-11-05 11:38:40 +08:00
|
|
|
FS_operate(SGstats.handle, thread->column_ids, SGstats.line_ids[HTTP_ACTION_SQL], FS_OP_ADD, 1);
|
2019-08-21 14:03:53 +08:00
|
|
|
if (config->mode){
|
|
|
|
|
redisAsyncCommand(thread->cl_ctx, redis_reget_callback, request, "GET %s", request->rkey);
|
|
|
|
|
}else{
|
|
|
|
|
redis_sync_reget_callback(request, sync);
|
|
|
|
|
}
|
2018-07-18 10:47:45 +08:00
|
|
|
freeReplyObject(reply);
|
|
|
|
|
goto finish;
|
2019-11-05 11:38:40 +08:00
|
|
|
default:
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "Read redis data(%s) return code failed", request->rkey);
|
2019-08-21 14:03:53 +08:00
|
|
|
evhttp_socket_send_error(request->evh_req, thread->column_ids, HTTP_NOTFOUND);
|
2018-07-18 10:47:45 +08:00
|
|
|
goto free;
|
|
|
|
|
}
|
|
|
|
|
xret = 0;
|
|
|
|
|
|
|
|
|
|
free:
|
|
|
|
|
freeReplyObject(reply);
|
2019-08-08 16:06:23 +08:00
|
|
|
request_destroy(request);
|
2018-07-09 14:32:41 +08:00
|
|
|
finish:
|
2018-07-18 10:47:45 +08:00
|
|
|
return xret;
|
2018-07-09 14:32:41 +08:00
|
|
|
}
|
|
|
|
|
|
2018-09-06 19:51:23 +08:00
|
|
|
static inline json_object *
|
|
|
|
|
web_json_record_array_add_string(char **chain)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
json_object *sample_array;
|
|
|
|
|
|
|
|
|
|
sample_array = json_object_new_array();
|
|
|
|
|
if (sample_array == NULL)
|
|
|
|
|
goto finish;
|
|
|
|
|
|
|
|
|
|
for(i = 0; chain[i] != '\0'; i++){
|
|
|
|
|
json_object_array_add(sample_array, json_object_new_string(chain[i]));
|
|
|
|
|
}
|
|
|
|
|
finish:
|
|
|
|
|
return sample_array;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
json_data_rebuild(const char *data,
|
|
|
|
|
size_t size,
|
|
|
|
|
char **odata,
|
|
|
|
|
size_t *osize)
|
|
|
|
|
{
|
|
|
|
|
size_t real_size = size + 1; /** 2, '\n' + '\0' */
|
|
|
|
|
|
|
|
|
|
if (!data || !size)
|
|
|
|
|
return -1;
|
|
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
*odata = (char *)malloc (real_size);
|
2018-09-06 19:51:23 +08:00
|
|
|
if (!*odata)
|
|
|
|
|
return -1;
|
|
|
|
|
memset (*odata, 0, real_size);
|
|
|
|
|
snprintf(*odata, real_size, "%s", data);
|
|
|
|
|
|
|
|
|
|
*osize = real_size;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
web_json_table_add(char *privatekey, char *sign,
|
|
|
|
|
char **chain, char **data)
|
|
|
|
|
{
|
2019-01-16 16:22:35 +06:00
|
|
|
int i = 0;
|
2018-09-06 19:51:23 +08:00
|
|
|
size_t osize = 0;
|
|
|
|
|
const char *jstr = NULL;
|
|
|
|
|
struct json_object *outline = json_object_new_object();
|
|
|
|
|
|
|
|
|
|
json_object_object_add(outline, "CERTIFICATE_CHAIN", web_json_record_array_add_string(chain));
|
|
|
|
|
json_object_object_add(outline, "PRIVATE_KEY", json_object_new_string(privatekey));
|
|
|
|
|
json_object_object_add(outline, "CERTIFICATE", json_object_new_string(sign));
|
|
|
|
|
|
|
|
|
|
jstr = json_object_to_json_string (outline);
|
|
|
|
|
|
|
|
|
|
json_data_rebuild(jstr, strlen(jstr), data, &osize);
|
|
|
|
|
|
|
|
|
|
json_object_put(outline);
|
|
|
|
|
|
2019-01-16 16:22:35 +06:00
|
|
|
kfree(sign);
|
|
|
|
|
for (i = 0; i < 6; i ++){
|
|
|
|
|
if (chain[i] != NULL)
|
|
|
|
|
kfree(chain[i]);
|
|
|
|
|
}
|
2018-09-06 19:51:23 +08:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-05 14:05:28 +08:00
|
|
|
static int
|
2019-08-21 14:03:53 +08:00
|
|
|
redis_clnt_pdu_send(struct request_t *request)
|
2018-06-19 11:32:16 +08:00
|
|
|
{
|
2019-01-16 16:22:35 +06:00
|
|
|
#define MAX_CHAIN_LEN 6
|
2018-10-22 11:15:57 +08:00
|
|
|
int xret = -1, i = 0;
|
|
|
|
|
STACK_OF(X509) *stack_ca = NULL;
|
2019-11-05 11:38:40 +08:00
|
|
|
x509_forge_thread *thread = threads + request->thread_id;
|
2019-01-16 16:22:35 +06:00
|
|
|
char *sign = NULL, pkey[SG_DATA_SIZE] = {0};
|
|
|
|
|
char *root = NULL;
|
2018-06-19 11:32:16 +08:00
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
uint64_t expire_time = x509_online_append(&thread->def, request, &root, &sign, pkey, &stack_ca);
|
|
|
|
|
if (sign == NULL && pkey[0] == '\0')
|
|
|
|
|
{
|
2019-08-21 14:03:53 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Failed to sign certificate");
|
2019-11-05 11:38:40 +08:00
|
|
|
evhttp_socket_send_error(request->evh_req, thread->column_ids, HTTP_NOTFOUND);
|
|
|
|
|
return xret;
|
2018-06-29 17:18:33 +08:00
|
|
|
}
|
2019-11-05 11:38:40 +08:00
|
|
|
FS_operate(SGstats.handle, thread->column_ids, SGstats.line_ids[HTTP_ACTION_TIME], FS_OP_SET, thread->diffTime);
|
|
|
|
|
FS_operate(SGstats.handle, thread->field_ids, 0, FS_OP_ADD, 1);
|
2018-06-28 11:05:53 +08:00
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
char *single = NULL; char *chain[MAX_CHAIN_LEN] = {0};
|
|
|
|
|
if (stack_ca)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < sk_X509_num(stack_ca); i++)
|
|
|
|
|
{
|
2019-01-16 16:22:35 +06:00
|
|
|
x509_get_msg_from_ca(sk_X509_value(stack_ca, i), &single);
|
|
|
|
|
chain[i] = single;
|
2018-10-22 11:15:57 +08:00
|
|
|
}
|
2019-11-05 11:38:40 +08:00
|
|
|
if (root != NULL)
|
|
|
|
|
{
|
2018-10-22 11:15:57 +08:00
|
|
|
chain[i] = root;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2019-11-05 11:38:40 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-10-22 11:15:57 +08:00
|
|
|
chain[0] = root;
|
2019-08-08 17:12:18 +08:00
|
|
|
}
|
2018-09-06 19:51:23 +08:00
|
|
|
web_json_table_add(pkey, sign, chain, &request->odata);
|
2018-09-20 10:11:15 +08:00
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
if (thread->sync == NULL)
|
|
|
|
|
{
|
2018-09-20 10:11:15 +08:00
|
|
|
struct evhttp_request *evh_req = request->evh_req;
|
2019-11-05 11:38:40 +08:00
|
|
|
FS_operate(SGstats.handle, thread->column_ids, SGstats.line_ids[HTTP_ACTION_SIGN], FS_OP_ADD, 1);
|
2018-09-20 10:11:15 +08:00
|
|
|
evhttp_socket_send(evh_req, request->odata);
|
2019-08-08 16:06:23 +08:00
|
|
|
request_destroy(request);
|
2018-09-20 10:11:15 +08:00
|
|
|
xret = 0;
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
2019-11-05 11:38:40 +08:00
|
|
|
xret = rediSyncCommand(thread->sync, request, request->odata, expire_time);
|
|
|
|
|
if (xret < 0)
|
|
|
|
|
{
|
2018-06-29 17:18:33 +08:00
|
|
|
goto finish;
|
|
|
|
|
}
|
2018-07-05 14:05:28 +08:00
|
|
|
xret = 0;
|
2018-06-29 17:18:33 +08:00
|
|
|
finish:
|
|
|
|
|
return xret;
|
|
|
|
|
}
|
2018-06-28 11:05:53 +08:00
|
|
|
|
2018-07-05 14:05:28 +08:00
|
|
|
static int
|
2018-09-06 19:51:23 +08:00
|
|
|
redis_clnt_send(struct request_t *request, redisReply *reply)
|
2018-07-05 14:05:28 +08:00
|
|
|
{
|
2018-07-18 10:47:45 +08:00
|
|
|
int xret = -1;
|
2018-07-05 14:05:28 +08:00
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
x509_forge_thread *thread = threads + request->thread_id;
|
2018-07-09 14:32:41 +08:00
|
|
|
|
2018-07-18 10:47:45 +08:00
|
|
|
if (!reply && !reply->str){
|
2019-08-21 14:03:53 +08:00
|
|
|
evhttp_socket_send_error(request->evh_req, thread->column_ids, HTTP_NOTFOUND);
|
2018-07-18 10:47:45 +08:00
|
|
|
goto finish;
|
2018-07-05 14:05:28 +08:00
|
|
|
}
|
2019-11-05 11:38:40 +08:00
|
|
|
FS_operate(SGstats.handle, thread->column_ids, SGstats.line_ids[HTTP_ACTION_SQL], FS_OP_ADD, 1);
|
2018-07-18 10:47:45 +08:00
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
FS_operate(SGstats.handle, thread->field_ids, 0, FS_OP_ADD, 1);
|
2018-07-18 10:47:45 +08:00
|
|
|
|
2018-10-23 11:31:57 +08:00
|
|
|
evhttp_socket_send(request->evh_req, reply->str);
|
2018-07-18 10:47:45 +08:00
|
|
|
|
|
|
|
|
finish:
|
2018-11-30 19:24:44 +08:00
|
|
|
if (request->origin)
|
|
|
|
|
X509_free(request->origin);
|
2019-08-08 16:06:23 +08:00
|
|
|
request_destroy(request);
|
2018-07-05 14:05:28 +08:00
|
|
|
return xret;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 14:03:53 +08:00
|
|
|
void redis_get_callback(redisAsyncContext __attribute__((__unused__))*c, void *r, void *privdata)
|
2018-06-29 17:18:33 +08:00
|
|
|
{
|
2018-07-26 17:18:00 +08:00
|
|
|
int __attribute__((__unused__))xret = -1;
|
2018-06-20 16:24:49 +08:00
|
|
|
|
2018-07-12 10:56:13 +08:00
|
|
|
redisReply *reply = (redisReply*)r;
|
|
|
|
|
struct request_t *request = (struct request_t *)privdata;
|
|
|
|
|
|
2018-06-29 17:18:33 +08:00
|
|
|
switch(reply->type){
|
|
|
|
|
case REDIS_REPLY_STRING:
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_DEBUG, MODULE_NAME, "Sends the certificate information to the requestor");
|
2018-07-05 14:05:28 +08:00
|
|
|
|
2018-09-06 19:51:23 +08:00
|
|
|
xret = redis_clnt_send(request, reply);
|
2018-06-29 17:18:33 +08:00
|
|
|
break;
|
2018-07-05 14:05:28 +08:00
|
|
|
|
2018-06-29 17:18:33 +08:00
|
|
|
case REDIS_REPLY_NIL:
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_DEBUG, MODULE_NAME, "Generating certificate information");
|
2018-07-05 14:05:28 +08:00
|
|
|
|
2019-08-21 14:03:53 +08:00
|
|
|
xret = redis_clnt_pdu_send(request);
|
2018-06-29 17:18:33 +08:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-14 13:25:46 +08:00
|
|
|
int x509_key_pair_init(char *ca_file, EVP_PKEY **key, X509 **root)
|
2018-06-19 11:32:16 +08:00
|
|
|
{
|
2018-07-26 17:18:00 +08:00
|
|
|
int xret = -1;
|
2018-06-19 11:32:16 +08:00
|
|
|
FILE *fp; RSA *rsa = NULL;
|
|
|
|
|
|
2018-06-29 17:18:33 +08:00
|
|
|
*key = EVP_PKEY_new();
|
|
|
|
|
if (NULL == *key){
|
2018-06-19 11:32:16 +08:00
|
|
|
goto finish;
|
|
|
|
|
}
|
2018-06-27 10:58:23 +08:00
|
|
|
|
2018-06-19 11:32:16 +08:00
|
|
|
rsa = RSA_new();
|
|
|
|
|
if (NULL == rsa){
|
|
|
|
|
goto pkey_free;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-13 10:12:24 +08:00
|
|
|
fp = fopen(ca_file, "r");
|
2018-06-19 11:32:16 +08:00
|
|
|
if (NULL == fp){
|
2018-12-13 10:12:24 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Failed to open file(%s)", ca_file);
|
2018-06-27 10:58:23 +08:00
|
|
|
RSA_free(rsa);
|
|
|
|
|
goto pkey_free;
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
2018-06-29 17:18:33 +08:00
|
|
|
if ( !PEM_read_RSAPrivateKey(fp, &rsa, NULL, NULL) || !EVP_PKEY_assign_RSA(*key,rsa))
|
2018-06-19 11:32:16 +08:00
|
|
|
{
|
2018-06-20 16:24:49 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Private key read failed");
|
2018-06-27 10:58:23 +08:00
|
|
|
goto pkey_free;
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
2018-07-26 17:18:00 +08:00
|
|
|
BIO *in;
|
2018-12-13 10:12:24 +08:00
|
|
|
in = BIO_new_file(ca_file, "r");
|
2018-07-26 17:18:00 +08:00
|
|
|
if (!in){
|
2018-12-13 10:12:24 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Failed to open file(%s)", ca_file);
|
2018-06-27 10:58:23 +08:00
|
|
|
goto pkey_free;
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
|
|
|
|
|
2018-07-26 17:18:00 +08:00
|
|
|
if ((*root = PEM_read_bio_X509(in, NULL, 0, NULL)) == NULL )
|
2018-06-19 11:32:16 +08:00
|
|
|
{
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Application for x509 failed");
|
2018-06-27 10:58:23 +08:00
|
|
|
goto pkey_free;
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
2018-07-26 17:18:00 +08:00
|
|
|
BIO_free(in);
|
|
|
|
|
|
2018-06-19 11:32:16 +08:00
|
|
|
xret = 0;
|
2018-06-20 16:24:49 +08:00
|
|
|
goto finish;
|
2018-06-19 11:32:16 +08:00
|
|
|
|
|
|
|
|
pkey_free:
|
2018-06-29 17:18:33 +08:00
|
|
|
EVP_PKEY_free(*key);
|
2018-06-19 11:32:16 +08:00
|
|
|
finish:
|
|
|
|
|
return xret;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-06 19:51:23 +08:00
|
|
|
int hex2dec(char c)
|
|
|
|
|
{
|
|
|
|
|
if ('0' <= c && c <= '9') {
|
|
|
|
|
return c - '0';
|
|
|
|
|
} else if ('a' <= c && c <= 'f') {
|
|
|
|
|
return c - 'a' + 10;
|
|
|
|
|
} else if ('A' <= c && c <= 'F') {
|
|
|
|
|
return c - 'A' + 10;
|
|
|
|
|
} else {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _urldecode(char url[])
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
int len = strlen(url);
|
|
|
|
|
int res_len = 0;
|
2018-10-23 11:31:57 +08:00
|
|
|
char *res = NULL;
|
|
|
|
|
|
|
|
|
|
res = (char *)malloc(len + 1);
|
|
|
|
|
if (!res){
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Url alloc faild");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-09-06 19:51:23 +08:00
|
|
|
|
|
|
|
|
if(!strchr(url, '%'))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
|
char c = url[i];
|
|
|
|
|
if (c != '%') {
|
|
|
|
|
res[res_len++] = c;
|
|
|
|
|
} else {
|
|
|
|
|
char c1 = url[++i];
|
|
|
|
|
char c0 = url[++i];
|
|
|
|
|
int num = 0;
|
|
|
|
|
num = hex2dec(c1) * 16 + hex2dec(c0);
|
|
|
|
|
res[res_len++] = num;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
res[res_len] = '\0';
|
|
|
|
|
strcpy(url, res);
|
2018-10-23 11:31:57 +08:00
|
|
|
|
|
|
|
|
free(res);
|
2018-09-06 19:51:23 +08:00
|
|
|
}
|
|
|
|
|
|
2019-08-08 16:06:23 +08:00
|
|
|
static int http_decode_uri(struct evhttp_request *evh_req, struct request_t *request)
|
2018-09-06 19:51:23 +08:00
|
|
|
{
|
2019-08-08 16:06:23 +08:00
|
|
|
int rv = 0;
|
2018-06-28 17:49:13 +08:00
|
|
|
struct evkeyvalq params;
|
2018-06-19 11:32:16 +08:00
|
|
|
|
2019-08-08 16:06:23 +08:00
|
|
|
const char *uri = evhttp_request_get_uri(evh_req);
|
|
|
|
|
char *decoded_uri = evhttp_decode_uri(uri);
|
|
|
|
|
if (!decoded_uri)
|
|
|
|
|
{
|
2019-11-05 11:38:40 +08:00
|
|
|
return 0;
|
2019-08-08 16:06:23 +08:00
|
|
|
}
|
|
|
|
|
rv = evhttp_parse_query(uri, ¶ms);
|
|
|
|
|
if (rv != 0)
|
|
|
|
|
{
|
2019-11-05 11:38:40 +08:00
|
|
|
return 0;
|
2019-08-08 16:06:23 +08:00
|
|
|
}
|
|
|
|
|
const char *keyring_id = evhttp_find_header(¶ms, "keyring_id");
|
|
|
|
|
if (keyring_id)
|
|
|
|
|
{
|
|
|
|
|
request->keyring_id = atoi(keyring_id);
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
2019-08-08 16:06:23 +08:00
|
|
|
const char *is_valid = evhttp_find_header(¶ms, "is_valid");
|
|
|
|
|
if (is_valid)
|
|
|
|
|
{
|
|
|
|
|
request->is_valid = atoi(is_valid);
|
|
|
|
|
}
|
|
|
|
|
const char *sni = evhttp_find_header(¶ms, "sni");
|
|
|
|
|
if (sni)
|
|
|
|
|
{
|
|
|
|
|
request->sni = strdup(sni);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
|
|
|
|
|
2018-07-05 14:05:28 +08:00
|
|
|
static void
|
|
|
|
|
evhttp_socket_close_cb(struct evhttp_connection *evcon,
|
|
|
|
|
void __attribute__((__unused__))*arg)
|
|
|
|
|
{
|
|
|
|
|
if (NULL == evcon){
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
2018-11-30 19:24:44 +08:00
|
|
|
|
2018-07-05 14:05:28 +08:00
|
|
|
finish:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-10 10:01:27 +08:00
|
|
|
static int
|
2019-05-24 15:09:34 +08:00
|
|
|
x509_get_rkey(X509 *origin, int keyring_id, char *rkey, int is_valid)
|
2018-09-10 10:01:27 +08:00
|
|
|
{
|
|
|
|
|
unsigned int len = 0, i = 0;
|
|
|
|
|
char hex[EVP_MAX_MD_SIZE] = {0};
|
|
|
|
|
unsigned char fdig[EVP_MAX_MD_SIZE] = {0};
|
|
|
|
|
|
|
|
|
|
X509_digest(origin, EVP_sha1(), fdig, &len);
|
|
|
|
|
for (i = 0; i < len ; ++i){
|
|
|
|
|
sprintf(hex + i * sizeof(unsigned char) * 2, "%02x", fdig[i]);
|
|
|
|
|
}
|
2019-05-24 15:09:34 +08:00
|
|
|
/** keyrind_id is 0, sign x509 by default */
|
|
|
|
|
/** 0 uninsec, 1 insec*/
|
|
|
|
|
if (is_valid && keyring_id == 0) keyring_id = 1;
|
2019-05-14 10:25:00 +08:00
|
|
|
|
2019-05-24 15:09:34 +08:00
|
|
|
struct pxy_obj_keyring *pxy_obj = get_obj_for_id(keyring_id);
|
|
|
|
|
if (pxy_obj != NULL)
|
|
|
|
|
{
|
|
|
|
|
snprintf(rkey, DATALEN, "%d:%s:%s:%d", keyring_id, hex, pxy_obj->finger, is_valid);
|
|
|
|
|
goto finish;
|
2019-05-14 10:25:00 +08:00
|
|
|
}
|
2019-05-24 15:09:34 +08:00
|
|
|
snprintf(rkey, DATALEN, "%d:%s:%d", keyring_id, hex, is_valid);
|
2019-05-14 10:25:00 +08:00
|
|
|
finish:
|
2019-11-05 11:38:40 +08:00
|
|
|
if (pxy_obj)
|
|
|
|
|
keyring_table_free(pxy_obj);
|
2018-09-10 10:01:27 +08:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 14:03:53 +08:00
|
|
|
static int
|
|
|
|
|
redis_sync_command(struct request_t *request, struct redisContext __attribute__((__unused__))*c)
|
|
|
|
|
{
|
|
|
|
|
int xret = -1;
|
|
|
|
|
redisReply *reply;
|
|
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
x509_forge_thread *thread_ctx = threads + request->thread_id;
|
2019-08-21 14:03:53 +08:00
|
|
|
|
|
|
|
|
reply = (redisReply *)redisCommand(thread_ctx->sync, "GET %s", request->rkey);
|
|
|
|
|
if (NULL == reply)
|
|
|
|
|
goto free;
|
|
|
|
|
|
|
|
|
|
switch (readBytes(reply->str)) {
|
|
|
|
|
case '+' :
|
|
|
|
|
mesa_runtime_log(RLOG_LV_DEBUG, MODULE_NAME, "Sends the certificate information to the requestor");
|
|
|
|
|
xret = redis_clnt_send(request, reply);
|
|
|
|
|
break;
|
|
|
|
|
case '$' :
|
|
|
|
|
mesa_runtime_log(RLOG_LV_DEBUG, MODULE_NAME, "Generating certificate information");
|
|
|
|
|
xret = redis_clnt_pdu_send(request);
|
|
|
|
|
goto finish;
|
|
|
|
|
default :
|
|
|
|
|
mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "Read redis data(%s) return code failed", request->rkey);
|
|
|
|
|
evhttp_send_error(request->evh_req, HTTP_NOTFOUND, 0);
|
|
|
|
|
goto free;
|
|
|
|
|
}
|
|
|
|
|
xret = 0;
|
|
|
|
|
|
|
|
|
|
free:
|
|
|
|
|
freeReplyObject(reply);
|
|
|
|
|
|
|
|
|
|
finish:
|
|
|
|
|
return xret;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-08 16:06:23 +08:00
|
|
|
void http_get_cb(struct evhttp_request *evh_req, void *arg)
|
2018-06-19 11:32:16 +08:00
|
|
|
{
|
2019-08-08 16:06:23 +08:00
|
|
|
int xret = -1;
|
2019-11-05 11:38:40 +08:00
|
|
|
struct request_t *request = NULL;
|
|
|
|
|
struct evbuffer * evbuf_body = NULL;
|
|
|
|
|
char *input = NULL; ssize_t inputlen=0;
|
|
|
|
|
x509_forge_thread *info = (x509_forge_thread *)arg;
|
2019-08-21 14:03:53 +08:00
|
|
|
struct config_bucket_t *config = cert_default_config();
|
2018-07-05 14:05:28 +08:00
|
|
|
|
2019-08-08 16:06:23 +08:00
|
|
|
if (evhttp_request_get_command(evh_req) != EVHTTP_REQ_POST) {
|
|
|
|
|
mesa_runtime_log(RLOG_LV_DEBUG, MODULE_NAME, "FAILED (post type)");
|
2018-06-29 17:18:33 +08:00
|
|
|
goto error;
|
|
|
|
|
}
|
2019-11-05 11:38:40 +08:00
|
|
|
request = (struct request_t *) kmalloc (sizeof(struct request_t), MPF_CLR, -1);
|
2019-08-08 16:06:23 +08:00
|
|
|
request->keyring_id = 0;
|
|
|
|
|
request->thread_id = info->id;
|
|
|
|
|
request->evh_req = evh_req;
|
|
|
|
|
|
|
|
|
|
http_decode_uri(evh_req, request);
|
2019-08-21 14:03:53 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "[Thread %d]Received request for uri, kering_id:%d, sni:%s, valid:%d",
|
2019-08-08 16:06:23 +08:00
|
|
|
request->thread_id, request->keyring_id, request->sni, request->is_valid);
|
|
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
evbuf_body = evhttp_request_get_input_buffer(evh_req);
|
2019-08-08 16:06:23 +08:00
|
|
|
if (!evbuf_body || 0==(inputlen = evbuffer_get_length(evbuf_body))
|
|
|
|
|
||!(input = (char *)evbuffer_pullup(evbuf_body,inputlen)))
|
|
|
|
|
{
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Failed to get certificate information.");
|
|
|
|
|
goto error;
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
2019-08-08 16:06:23 +08:00
|
|
|
request->origin = x509_get_ca_from_msg(input, inputlen + 1);
|
|
|
|
|
if (request->origin == NULL){
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "The certificate is invalid.");
|
|
|
|
|
request_destroy(request);
|
2018-06-29 17:18:33 +08:00
|
|
|
goto error;
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
2019-05-24 15:09:34 +08:00
|
|
|
x509_get_rkey(request->origin, request->keyring_id, request->rkey, request->is_valid);
|
2018-09-10 10:01:27 +08:00
|
|
|
if (request->rkey[0] == '\0'){
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Get the redis key from the certificate failed");
|
2018-09-10 10:01:27 +08:00
|
|
|
goto error;
|
|
|
|
|
}
|
2019-08-08 16:06:23 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_DEBUG, MODULE_NAME, "Redis key is %s", request->rkey);
|
2019-11-05 11:38:40 +08:00
|
|
|
FS_operate(SGstats.handle, info->column_ids, SGstats.line_ids[HTTP_ACTION_REQ], FS_OP_ADD, 1);
|
2019-08-08 16:06:23 +08:00
|
|
|
|
|
|
|
|
/* we want to know if this connection closes on us */
|
|
|
|
|
evhttp_connection_set_closecb(evhttp_request_get_connection(evh_req), evhttp_socket_close_cb, NULL);
|
2019-11-05 11:38:40 +08:00
|
|
|
if (info->sync == NULL)
|
|
|
|
|
{
|
2019-08-21 14:03:53 +08:00
|
|
|
xret = redis_clnt_pdu_send(request);
|
2018-09-20 10:11:15 +08:00
|
|
|
if (xret < 0)
|
2019-11-05 11:38:40 +08:00
|
|
|
{
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Local sign certificate failed");
|
2019-11-05 11:38:40 +08:00
|
|
|
}
|
|
|
|
|
goto free;
|
2018-09-20 10:11:15 +08:00
|
|
|
}else{
|
2019-11-05 11:38:40 +08:00
|
|
|
if(config->mode)
|
2019-08-21 14:03:53 +08:00
|
|
|
{
|
|
|
|
|
xret = redisAsyncCommand(info->cl_ctx, redis_get_callback, request, "GET %s", request->rkey);
|
|
|
|
|
if (xret < 0)
|
2019-11-05 11:38:40 +08:00
|
|
|
{
|
2019-08-21 14:03:53 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Failed to get information from redis server");
|
2019-11-05 11:38:40 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-08-21 14:03:53 +08:00
|
|
|
xret = redis_sync_command(request, info->sync);
|
|
|
|
|
if (xret < 0)
|
2019-11-05 11:38:40 +08:00
|
|
|
{
|
2019-08-21 14:03:53 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Failed to get information from redis server");
|
2019-11-05 11:38:40 +08:00
|
|
|
}
|
2019-08-21 14:03:53 +08:00
|
|
|
}
|
2018-09-20 10:11:15 +08:00
|
|
|
}
|
|
|
|
|
free:
|
2018-06-29 17:18:33 +08:00
|
|
|
goto finish;
|
|
|
|
|
|
|
|
|
|
error:
|
2019-08-21 14:03:53 +08:00
|
|
|
evhttp_socket_send_error(evh_req, info->column_ids, HTTP_BADREQUEST);
|
2018-06-19 11:32:16 +08:00
|
|
|
finish:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-22 14:03:27 +08:00
|
|
|
int redis_sync_init(struct redisContext **c)
|
2018-07-18 10:47:45 +08:00
|
|
|
{
|
2018-08-22 14:03:27 +08:00
|
|
|
int xret = -1;
|
2018-07-18 10:47:45 +08:00
|
|
|
struct config_bucket_t *redis = cert_default_config();
|
|
|
|
|
|
|
|
|
|
struct timeval timeout = { 1, 500000 }; // 1.5 seconds
|
|
|
|
|
|
2018-10-22 11:15:57 +08:00
|
|
|
*c = redisConnectWithTimeout(redis->addr_t.store_ip, redis->addr_t.store_port, timeout);
|
2018-08-22 14:03:27 +08:00
|
|
|
if (*c == NULL || (*c)->err) {
|
|
|
|
|
if (*c) {
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Sync connection error: %s", (*c)->errstr);
|
2018-08-22 14:03:27 +08:00
|
|
|
redisFree(*c);
|
|
|
|
|
*c = NULL;
|
|
|
|
|
} else {
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Connection error: can't allocate redis context");
|
2018-08-22 14:03:27 +08:00
|
|
|
}
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
xret = 0;
|
|
|
|
|
finish:
|
|
|
|
|
return xret;
|
2018-07-18 10:47:45 +08:00
|
|
|
}
|
|
|
|
|
|
2018-06-29 17:18:33 +08:00
|
|
|
static int
|
2019-11-05 11:38:40 +08:00
|
|
|
worker_private_init(struct event_base *base, x509_forge_thread *thread)
|
2018-06-19 11:32:16 +08:00
|
|
|
{
|
|
|
|
|
int xret = -1;
|
2018-12-13 10:12:24 +08:00
|
|
|
struct config_bucket_t *config = cert_default_config();
|
2018-06-19 11:32:16 +08:00
|
|
|
|
|
|
|
|
/* Initialize the redis connection*/
|
2019-11-05 11:38:40 +08:00
|
|
|
if (config->mode)
|
|
|
|
|
{
|
|
|
|
|
xret = redis_rsync_init(base, &thread->cl_ctx);
|
|
|
|
|
if (xret < 0 || !thread->cl_ctx){
|
2019-08-21 14:03:53 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Initialize the redis connection is failure");
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-05 11:38:40 +08:00
|
|
|
xret = redis_sync_init(&thread->sync);
|
|
|
|
|
if (xret < 0 || !thread->sync)
|
|
|
|
|
{
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Initialize the sync redis connection is failure");
|
2018-08-22 14:03:27 +08:00
|
|
|
}
|
2018-07-09 14:32:41 +08:00
|
|
|
|
2019-05-24 15:09:34 +08:00
|
|
|
if (config->local_debug)
|
|
|
|
|
{
|
|
|
|
|
/* Initialize the X509 CA*/
|
2019-11-05 11:38:40 +08:00
|
|
|
xret = x509_key_pair_init(config->ca_path, &thread->def.key, &thread->def.root);
|
|
|
|
|
if (xret < 0 || !(thread->def.key) || !(thread->def.root))
|
|
|
|
|
{
|
2019-05-24 15:09:34 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Failed to initialize the x509 certificate");
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
2018-10-23 11:31:57 +08:00
|
|
|
|
2019-05-24 15:09:34 +08:00
|
|
|
/* Initialize the insec CA*/
|
2019-11-05 11:38:40 +08:00
|
|
|
xret = x509_key_pair_init(config->uninsec_path, &thread->def.insec_key, &thread->def.insec_root);
|
|
|
|
|
if (xret < 0 || !(thread->def.key) || !(thread->def.root))
|
|
|
|
|
{
|
2019-05-24 15:09:34 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Failed to initialize the insec x509 certificate");
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
2018-10-23 11:31:57 +08:00
|
|
|
}
|
2018-06-19 11:32:16 +08:00
|
|
|
finish:
|
2018-06-29 17:18:33 +08:00
|
|
|
return xret;
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void *pthread_worker_libevent(void *arg)
|
|
|
|
|
{
|
2018-07-12 10:56:13 +08:00
|
|
|
int xret = -1;
|
2018-06-19 11:32:16 +08:00
|
|
|
struct evhttp_bound_socket *bound = NULL;
|
2019-11-05 11:38:40 +08:00
|
|
|
x509_forge_thread *thread_ctx = (x509_forge_thread *)arg;
|
2018-06-19 11:32:16 +08:00
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
struct event_base *base = event_base_new();
|
2018-06-19 11:32:16 +08:00
|
|
|
if (! base) {
|
2019-08-08 16:06:23 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Can'thread_ctx allocate event base");
|
2019-11-05 11:38:40 +08:00
|
|
|
return NULL;
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
2019-11-05 11:38:40 +08:00
|
|
|
struct evhttp *http = evhttp_new(base);
|
2018-06-19 11:32:16 +08:00
|
|
|
if (!http) {
|
2019-08-08 16:06:23 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "couldn'thread_ctx create evhttp. Exiting.");
|
2018-06-19 11:32:16 +08:00
|
|
|
goto error;
|
|
|
|
|
}
|
2019-08-08 16:06:23 +08:00
|
|
|
thread_ctx->base = base;
|
2018-06-19 11:32:16 +08:00
|
|
|
|
|
|
|
|
/* Context initialization */
|
2019-11-05 11:38:40 +08:00
|
|
|
xret = worker_private_init(base, thread_ctx);
|
|
|
|
|
if (xret < 0)
|
|
|
|
|
{
|
2018-06-19 11:32:16 +08:00
|
|
|
goto error;
|
|
|
|
|
}
|
2019-08-08 16:06:23 +08:00
|
|
|
evhttp_set_cb(http, "/ca", http_get_cb, thread_ctx);
|
2018-06-19 11:32:16 +08:00
|
|
|
|
2019-08-08 16:06:23 +08:00
|
|
|
bound = evhttp_accept_socket_with_handle(http, thread_ctx->accept_fd);
|
2018-06-19 11:32:16 +08:00
|
|
|
if (bound != NULL) {
|
2018-07-18 10:47:45 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "Bound(%p) to port %d - Awaiting connections ... ", bound,
|
2018-09-10 10:01:27 +08:00
|
|
|
cert_default_config()->addr_t.e_port);
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
2019-08-21 14:03:53 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "Work thread %u is run...", thread_ctx->id);
|
|
|
|
|
|
2018-07-12 10:56:13 +08:00
|
|
|
event_base_dispatch(base);
|
2018-06-19 11:32:16 +08:00
|
|
|
error:
|
|
|
|
|
event_base_free(base);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
#ifdef SOCK_NONBLOCK
|
|
|
|
|
#define EVUTIL_SOCK_NONBLOCK SOCK_NONBLOCK
|
|
|
|
|
#else
|
|
|
|
|
#define EVUTIL_SOCK_NONBLOCK 0x4000000
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef SOCK_CLOEXEC
|
|
|
|
|
#define EVUTIL_SOCK_CLOEXEC SOCK_CLOEXEC
|
|
|
|
|
#else
|
|
|
|
|
#define EVUTIL_SOCK_CLOEXEC 0x80000000
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef EFD_NONBLOCK
|
|
|
|
|
#define EVUTIL_EFD_NONBLOCK EFD_NONBLOCK
|
|
|
|
|
#else
|
|
|
|
|
#define EVUTIL_EFD_NONBLOCK 0x4000
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef EFD_CLOEXEC
|
|
|
|
|
#define EVUTIL_EFD_CLOEXEC EFD_CLOEXEC
|
|
|
|
|
#else
|
|
|
|
|
#define EVUTIL_EFD_CLOEXEC 0x8000
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
evutil_fast_socket_nonblocking(evutil_socket_t fd)
|
|
|
|
|
{
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
return evutil_make_socket_nonblocking(fd);
|
|
|
|
|
#else
|
|
|
|
|
if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
evutil_fast_socket_closeonexec(evutil_socket_t fd)
|
|
|
|
|
{
|
|
|
|
|
#if !defined(_WIN32) && defined(EVENT__HAVE_SETFD)
|
|
|
|
|
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
evutil_socket_t
|
|
|
|
|
evutil_socket_(int domain, int type, int protocol)
|
|
|
|
|
{
|
|
|
|
|
evutil_socket_t r;
|
|
|
|
|
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
|
|
|
|
|
r = socket(domain, type, protocol);
|
|
|
|
|
if (r >= 0)
|
|
|
|
|
return r;
|
|
|
|
|
else if ((type & (SOCK_NONBLOCK|SOCK_CLOEXEC)) == 0)
|
|
|
|
|
return -1;
|
|
|
|
|
#endif
|
|
|
|
|
#define SOCKET_TYPE_MASK (~(EVUTIL_SOCK_NONBLOCK|EVUTIL_SOCK_CLOEXEC))
|
|
|
|
|
r = socket(domain, type & SOCKET_TYPE_MASK, protocol);
|
|
|
|
|
if (r < 0)
|
|
|
|
|
return -1;
|
|
|
|
|
if (type & EVUTIL_SOCK_NONBLOCK) {
|
|
|
|
|
if (evutil_fast_socket_nonblocking(r) < 0) {
|
|
|
|
|
evutil_closesocket(r);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (type & EVUTIL_SOCK_CLOEXEC) {
|
|
|
|
|
if (evutil_fast_socket_closeonexec(r) < 0) {
|
|
|
|
|
evutil_closesocket(r);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-19 11:32:16 +08:00
|
|
|
static evutil_socket_t
|
|
|
|
|
evhttp_listen_socket_byuser(const struct sockaddr *sa, int socklen,
|
|
|
|
|
unsigned flags, int backlog)
|
|
|
|
|
{
|
|
|
|
|
evutil_socket_t fd;
|
|
|
|
|
int on = 1;
|
|
|
|
|
int family = sa ? sa->sa_family : AF_UNSPEC;
|
|
|
|
|
int socktype = SOCK_STREAM | EVUTIL_SOCK_NONBLOCK;
|
2019-11-05 11:38:40 +08:00
|
|
|
|
2018-06-19 11:32:16 +08:00
|
|
|
if (flags & LEV_OPT_CLOSE_ON_EXEC)
|
|
|
|
|
socktype |= EVUTIL_SOCK_CLOEXEC;
|
|
|
|
|
|
|
|
|
|
fd = evutil_socket_(family, socktype, 0);
|
|
|
|
|
if (fd == -1)
|
|
|
|
|
return fd;
|
|
|
|
|
|
|
|
|
|
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&on, sizeof(on))<0)
|
|
|
|
|
goto err;
|
|
|
|
|
if (flags & LEV_OPT_REUSEABLE) {
|
|
|
|
|
if (evutil_make_listen_socket_reuseable(fd) < 0)
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
if (flags & LEV_OPT_REUSEABLE_PORT) {
|
2018-06-20 16:24:49 +08:00
|
|
|
if (evutil_make_listen_socket_reuseable_port(fd) < 0){
|
2018-06-19 11:32:16 +08:00
|
|
|
goto err;
|
2018-06-20 16:24:49 +08:00
|
|
|
}
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
|
|
|
|
if (sa) {
|
|
|
|
|
if (bind(fd, sa, socklen)<0)
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
if (listen(fd, backlog) == -1) {
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
return fd;
|
|
|
|
|
err:
|
|
|
|
|
evutil_closesocket(fd);
|
|
|
|
|
return fd;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-05 14:05:28 +08:00
|
|
|
static int
|
2019-11-05 11:38:40 +08:00
|
|
|
fs_screen_preview(x509_forge_thread *thread)
|
2018-06-28 11:05:53 +08:00
|
|
|
{
|
2018-07-05 14:05:28 +08:00
|
|
|
char buff[128] = {0};
|
2018-06-28 11:05:53 +08:00
|
|
|
|
2018-07-05 14:05:28 +08:00
|
|
|
snprintf(buff, sizeof(buff),"Thread_%02d", thread->id);
|
2019-11-05 11:38:40 +08:00
|
|
|
thread->field_ids = FS_register(SGstats.handle, FS_STYLE_FIELD, FS_CALC_CURRENT, buff);
|
2018-06-28 11:05:53 +08:00
|
|
|
|
2018-07-05 14:05:28 +08:00
|
|
|
snprintf(buff, sizeof(buff),"Thread_%d", thread->id);
|
2019-11-05 11:38:40 +08:00
|
|
|
thread->column_ids = FS_register(SGstats.handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff);
|
2018-06-28 11:05:53 +08:00
|
|
|
|
2018-07-05 14:05:28 +08:00
|
|
|
return 0;
|
2018-06-28 11:05:53 +08:00
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:15:57 +08:00
|
|
|
static void
|
|
|
|
|
redis_link_detection(uint32_t __attribute__((__unused__)) uid,
|
|
|
|
|
int __attribute__((__unused__))argc,
|
|
|
|
|
char **argv)
|
|
|
|
|
{
|
|
|
|
|
int tid = 0, xret = 0;
|
2019-11-05 11:38:40 +08:00
|
|
|
x509_forge_thread *info = NULL;
|
|
|
|
|
x509_forge_thread *threads = (x509_forge_thread *)argv;
|
2018-10-22 11:15:57 +08:00
|
|
|
|
|
|
|
|
unsigned int thread_nu = cert_default_config()->thread_nu;
|
|
|
|
|
for (tid = 0; tid < (int)thread_nu; tid++) {
|
|
|
|
|
info = threads + tid;
|
2019-08-21 14:03:53 +08:00
|
|
|
if(info->sync == NULL){
|
|
|
|
|
redisFree(info->sync);
|
2018-10-22 11:15:57 +08:00
|
|
|
xret = redis_sync_init(&info->sync);
|
|
|
|
|
if (xret < 0 || !info->sync){
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "[%d]trying to connect sync redis failed", tid);
|
|
|
|
|
continue;
|
|
|
|
|
}else{
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "[%d]trying to connect sync redis success", tid);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 14:03:53 +08:00
|
|
|
if(cert_default_config()->mode)
|
|
|
|
|
{
|
|
|
|
|
xret = redis_rsync_init(info->base, &info->cl_ctx);
|
|
|
|
|
if (xret < 0 || !info->cl_ctx){
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "[%d]trying to connect rsync redis failed", tid);
|
|
|
|
|
}else{
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "[%d]trying to connect rsync redis success", tid);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-22 11:15:57 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-05 14:05:28 +08:00
|
|
|
static int
|
|
|
|
|
libevent_socket_init()
|
2018-06-19 11:32:16 +08:00
|
|
|
{
|
2018-07-18 10:47:45 +08:00
|
|
|
int xret = -1;
|
|
|
|
|
unsigned int tid = 0;
|
2019-11-05 11:38:40 +08:00
|
|
|
x509_forge_thread *thread = NULL;
|
|
|
|
|
uint32_t tm_link_detetion = 0;
|
2018-06-19 11:32:16 +08:00
|
|
|
|
2018-07-18 10:47:45 +08:00
|
|
|
unsigned int thread_nu = cert_default_config()->thread_nu;
|
2018-06-19 11:32:16 +08:00
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
/* Create a new evhttp object to handle requests. */
|
|
|
|
|
struct sockaddr_in sin;
|
2018-06-19 11:32:16 +08:00
|
|
|
memset(&sin, 0, sizeof(struct sockaddr_in));
|
|
|
|
|
sin.sin_family = AF_INET;
|
2018-09-10 10:01:27 +08:00
|
|
|
sin.sin_port = htons(cert_default_config()->addr_t.e_port);
|
2019-11-05 11:38:40 +08:00
|
|
|
evutil_socket_t accept_fd = evhttp_listen_socket_byuser((struct sockaddr*)&sin, sizeof(struct sockaddr_in), LEV_OPT_REUSEABLE_PORT|LEV_OPT_CLOSE_ON_FREE, -1);
|
|
|
|
|
if (accept_fd < 0)
|
|
|
|
|
{
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Could not create a listen!");
|
2018-06-19 11:32:16 +08:00
|
|
|
goto finish;
|
|
|
|
|
}
|
2019-11-05 11:38:40 +08:00
|
|
|
threads = (x509_forge_thread *)calloc(thread_nu, sizeof(x509_forge_thread));
|
|
|
|
|
if (! threads)
|
|
|
|
|
{
|
2018-07-18 10:47:45 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Can't allocate thread descriptors");
|
2018-06-19 11:32:16 +08:00
|
|
|
goto finish;
|
|
|
|
|
}
|
2019-11-05 11:38:40 +08:00
|
|
|
memset(threads, 0, thread_nu * sizeof(x509_forge_thread));
|
2018-06-19 11:32:16 +08:00
|
|
|
|
|
|
|
|
/* Create threads after we've done all the libevent setup. */
|
2019-11-05 11:38:40 +08:00
|
|
|
for (tid = 0; tid < thread_nu; tid++)
|
|
|
|
|
{
|
2018-07-12 10:56:13 +08:00
|
|
|
thread = threads + tid;
|
2018-06-19 11:32:16 +08:00
|
|
|
|
2018-07-12 10:56:13 +08:00
|
|
|
thread->id = tid;
|
2018-06-19 11:32:16 +08:00
|
|
|
thread->accept_fd = accept_fd;
|
2018-07-12 10:56:13 +08:00
|
|
|
thread->routine = pthread_worker_libevent;
|
2018-06-19 11:32:16 +08:00
|
|
|
|
2018-07-05 14:05:28 +08:00
|
|
|
fs_screen_preview(thread);
|
2018-06-19 11:32:16 +08:00
|
|
|
if (pthread_create(&thread->pid, thread->attr, thread->routine, &threads[tid])){
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "%s", strerror(errno));
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
if (pthread_detach(thread->pid)){
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "%s", strerror(errno));
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-22 11:15:57 +08:00
|
|
|
#ifdef RT_TMR_ADVANCED
|
|
|
|
|
/*Create timers to monitor redis connections **/
|
|
|
|
|
tm_link_detetion = tmr_create(1, "Redis link detection",
|
|
|
|
|
redis_link_detection, 1, (char **)threads, 5);
|
|
|
|
|
if (((int32_t)tm_link_detetion < 0)){
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "%s",
|
|
|
|
|
"Can not create link-detection timer for redis\n");
|
|
|
|
|
}
|
|
|
|
|
tmr_start(tm_link_detetion);
|
|
|
|
|
#endif
|
2018-06-19 11:32:16 +08:00
|
|
|
FOREVER{
|
|
|
|
|
sleep(1);
|
|
|
|
|
}
|
|
|
|
|
finish:
|
|
|
|
|
return xret;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-05 14:05:28 +08:00
|
|
|
static void
|
|
|
|
|
rt_get_pname_by_pid(pid_t pid, char *task_name)
|
|
|
|
|
{
|
|
|
|
|
#define BUF_SIZE 1024
|
|
|
|
|
char proc_pid_path[BUF_SIZE];
|
|
|
|
|
char buf[BUF_SIZE];
|
|
|
|
|
sprintf(proc_pid_path, "/proc/%d/status", pid);
|
|
|
|
|
FILE* fp = fopen(proc_pid_path, "r");
|
|
|
|
|
if(NULL != fp){
|
|
|
|
|
if( fgets(buf, BUF_SIZE-1, fp)== NULL ){
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
sscanf(buf, "%*s %s", task_name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-12 10:56:13 +08:00
|
|
|
void sigproc(int __attribute__((__unused__))sig)
|
|
|
|
|
{
|
2018-07-18 10:47:45 +08:00
|
|
|
unsigned int tid = 0;
|
2019-11-05 11:38:40 +08:00
|
|
|
x509_forge_thread *thread = NULL;
|
2018-07-12 10:56:13 +08:00
|
|
|
|
|
|
|
|
struct config_bucket_t *rte = cert_default_config();
|
|
|
|
|
|
|
|
|
|
for (tid = 0; tid < rte->thread_nu; tid++) {
|
|
|
|
|
thread = threads + tid;
|
2018-08-22 14:03:27 +08:00
|
|
|
if (thread->sync){
|
2018-07-12 10:56:13 +08:00
|
|
|
redisAsyncDisconnect(thread->cl_ctx);
|
2018-10-22 11:15:57 +08:00
|
|
|
free(thread->cl_ctx);
|
2018-07-18 10:47:45 +08:00
|
|
|
redisFree(thread->sync);
|
2018-08-22 14:03:27 +08:00
|
|
|
}
|
2018-10-22 11:15:57 +08:00
|
|
|
event_base_free(thread->base);
|
2018-07-12 10:56:13 +08:00
|
|
|
}
|
|
|
|
|
kfree(threads);
|
|
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-06 19:51:23 +08:00
|
|
|
static int
|
|
|
|
|
MESA_internal_set_para(screen_stat_handle_t handle, enum FS_option type, unsigned value)
|
|
|
|
|
{
|
2019-11-05 11:38:40 +08:00
|
|
|
int ret = FS_set_para(handle, type, &value, (int)(sizeof(value)));
|
2018-09-06 19:51:23 +08:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int mesa_fiel_stat_init()
|
2018-07-05 14:05:28 +08:00
|
|
|
{
|
2018-09-18 14:48:55 +08:00
|
|
|
char stat_path[128] = {0};
|
2018-07-05 14:05:28 +08:00
|
|
|
char pname[32]= {0}, buff[128] = {0};
|
|
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
SGstats.handle = FS_create_handle();
|
2018-07-05 14:05:28 +08:00
|
|
|
|
|
|
|
|
rt_get_pname_by_pid(getpid(), &pname[0]);
|
2019-11-05 11:38:40 +08:00
|
|
|
FS_set_para(SGstats.handle, APP_NAME, pname, strlen(pname)+1);
|
2018-09-18 14:48:55 +08:00
|
|
|
snprintf(stat_path, 128, "%s/fs2_%s.status", logging_sc_lid.run_log_path, pname);
|
2019-11-05 11:38:40 +08:00
|
|
|
FS_set_para(SGstats.handle, OUTPUT_DEVICE, stat_path, strlen(stat_path)+1);
|
2018-09-06 19:51:23 +08:00
|
|
|
|
|
|
|
|
MESA_internal_set_para(SGstats.handle, FLUSH_BY_DATE, 0);
|
|
|
|
|
MESA_internal_set_para(SGstats.handle, PRINT_MODE, 1);
|
|
|
|
|
MESA_internal_set_para(SGstats.handle, CREATE_THREAD, 1);
|
|
|
|
|
MESA_internal_set_para(SGstats.handle, STAT_CYCLE, 3);
|
2018-07-05 14:05:28 +08:00
|
|
|
|
2019-08-21 14:03:53 +08:00
|
|
|
snprintf(buff,sizeof(buff),"%s", "REQ");
|
2019-11-05 11:38:40 +08:00
|
|
|
SGstats.line_ids[HTTP_ACTION_REQ] = FS_register(SGstats.handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff);
|
2019-08-21 14:03:53 +08:00
|
|
|
snprintf(buff,sizeof(buff),"%s", "SQL");
|
2019-11-05 11:38:40 +08:00
|
|
|
SGstats.line_ids[HTTP_ACTION_SQL] = FS_register(SGstats.handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff);
|
2019-08-21 14:03:53 +08:00
|
|
|
snprintf(buff,sizeof(buff),"%s", "SIGN");
|
2019-11-05 11:38:40 +08:00
|
|
|
SGstats.line_ids[HTTP_ACTION_SIGN] = FS_register(SGstats.handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff);
|
2019-08-21 14:03:53 +08:00
|
|
|
snprintf(buff,sizeof(buff),"%s", "ERR");
|
2019-11-05 11:38:40 +08:00
|
|
|
SGstats.line_ids[HTTP_ACTION_ERR] = FS_register(SGstats.handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff);
|
2018-07-10 10:53:10 +08:00
|
|
|
snprintf(buff,sizeof(buff),"%s", "take-time");
|
2019-11-05 11:38:40 +08:00
|
|
|
SGstats.line_ids[HTTP_ACTION_TIME] = FS_register(SGstats.handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff);
|
2018-07-09 14:32:41 +08:00
|
|
|
|
2019-08-21 14:03:53 +08:00
|
|
|
MESA_internal_set_para(SGstats.handle, ID_INVISBLE, SGstats.line_ids[HTTP_ACTION_TIME]);
|
2018-07-18 10:47:45 +08:00
|
|
|
snprintf(buff,sizeof(buff),"Cert/Nsec");
|
2019-11-05 11:38:40 +08:00
|
|
|
FS_register_ratio(SGstats.handle, SGstats.line_ids[HTTP_ACTION_TIME],
|
2019-08-21 14:03:53 +08:00
|
|
|
SGstats.line_ids[HTTP_ACTION_SIGN], 1,
|
2018-07-10 10:53:10 +08:00
|
|
|
FS_STYLE_COLUMN, FS_CALC_CURRENT,
|
|
|
|
|
buff);
|
2019-11-05 11:38:40 +08:00
|
|
|
FS_start(SGstats.handle);
|
2018-07-05 14:05:28 +08:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 10:25:00 +08:00
|
|
|
static void
|
2019-05-24 15:09:34 +08:00
|
|
|
x509_get_fingerprint(X509 *x509, char *finger)
|
2019-05-14 10:25:00 +08:00
|
|
|
{
|
2019-05-24 15:09:34 +08:00
|
|
|
int xret = -1;
|
2019-05-14 10:25:00 +08:00
|
|
|
unsigned int len = 0, i = 0;
|
|
|
|
|
unsigned char fdig[EVP_MAX_MD_SIZE] = {0};
|
|
|
|
|
|
2019-05-24 15:09:34 +08:00
|
|
|
xret = X509_digest(x509, EVP_sha1(), fdig, &len);
|
|
|
|
|
if (xret != 1)
|
|
|
|
|
goto finish;
|
2019-05-14 10:25:00 +08:00
|
|
|
for (i = 0; i < len ; ++i){
|
2019-05-24 15:09:34 +08:00
|
|
|
sprintf(finger + i * sizeof(unsigned char) * 2, "%02x", fdig[i]);
|
2019-05-14 10:25:00 +08:00
|
|
|
}
|
2019-05-24 15:09:34 +08:00
|
|
|
finish:
|
2019-05-14 10:25:00 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-24 15:09:34 +08:00
|
|
|
void keyring_table_new_cb(int __attribute__((__unused__))table_id, const char __attribute__((__unused__))*key,
|
|
|
|
|
const char* table_line, MAAT_PLUGIN_EX_DATA* ad, long __attribute__((__unused__))argl, void __attribute__((__unused__))* argp)
|
2018-09-06 19:51:23 +08:00
|
|
|
{
|
2019-05-24 15:09:34 +08:00
|
|
|
char profile_name[CT_ARRARY_LEN]={0};
|
|
|
|
|
char private_file[CT_STRING_MAX] = {0}, public_file[CT_STRING_MAX]={0};
|
|
|
|
|
char __attribute__((__unused__))_priv_file[CT_PATH_MAX] = {0};
|
|
|
|
|
char __attribute__((__unused__))_publi_file[CT_PATH_MAX] = {0};
|
2019-06-01 17:39:12 +08:00
|
|
|
int ret=0;
|
2018-09-06 19:51:23 +08:00
|
|
|
|
2019-05-24 15:09:34 +08:00
|
|
|
struct pxy_obj_keyring *pxy_obj = NULL;
|
2018-09-06 19:51:23 +08:00
|
|
|
|
|
|
|
|
pxy_obj = (struct pxy_obj_keyring *)malloc(sizeof(struct pxy_obj_keyring));
|
2019-05-24 15:09:34 +08:00
|
|
|
if (!pxy_obj)
|
|
|
|
|
{
|
2018-09-20 10:11:15 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "Can not alloc, %s", strerror(errno));
|
2018-09-06 19:51:23 +08:00
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
memset(pxy_obj, 0, sizeof(struct pxy_obj_keyring));
|
2019-06-14 13:25:46 +08:00
|
|
|
atomic64_set(&pxy_obj->ref_cnt, 1);
|
2019-06-14 20:18:19 +08:00
|
|
|
|
2019-09-16 10:45:42 +08:00
|
|
|
ret=sscanf(table_line, "%d\t%s\t%s\t%s\t%s\t%lu\t%s\t%s\t%d", &pxy_obj->keyring_id, profile_name,
|
|
|
|
|
pxy_obj->keyring_type, private_file, public_file, &pxy_obj->expire_time, pxy_obj->public_algo,
|
|
|
|
|
pxy_obj->v3_ctl, &pxy_obj->is_valid);
|
2019-08-21 14:03:53 +08:00
|
|
|
if(ret!=9)
|
2019-05-24 15:09:34 +08:00
|
|
|
{
|
2019-09-16 10:45:42 +08:00
|
|
|
kfree(pxy_obj);
|
2019-05-24 15:09:34 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "certstore parse config failed: %s", table_line);
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
2018-10-22 11:15:57 +08:00
|
|
|
|
2019-06-14 13:25:46 +08:00
|
|
|
/*Load PUBLICKEY***/
|
2019-10-12 16:37:04 +08:00
|
|
|
if ((pxy_obj->root = x509_get_root_ca(public_file, &pxy_obj->stack_ca)) == NULL ){
|
2019-06-14 13:25:46 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "initialize the x509 publickey failed, the keyring id is %d",
|
|
|
|
|
pxy_obj->keyring_id);
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
/*Load PRIVATEKEY**/
|
|
|
|
|
if ((pxy_obj->key = cert_load_key(private_file)) == NULL){
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "initialize the x509 privatekey failed, the keyring id is %d",
|
2019-05-24 15:09:34 +08:00
|
|
|
pxy_obj->keyring_id);
|
|
|
|
|
goto finish;
|
2018-10-22 11:15:57 +08:00
|
|
|
}
|
2019-05-24 15:09:34 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "initialize the x509 certificate, the keyring id is %d",
|
2019-06-14 13:25:46 +08:00
|
|
|
pxy_obj->keyring_id);
|
2019-05-24 15:09:34 +08:00
|
|
|
x509_get_fingerprint(pxy_obj->root, pxy_obj->finger);
|
2018-09-06 19:51:23 +08:00
|
|
|
|
2019-05-24 15:09:34 +08:00
|
|
|
*ad = pxy_obj;
|
2018-09-06 19:51:23 +08:00
|
|
|
finish:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-24 15:09:34 +08:00
|
|
|
void keyring_table_dup_cb(int __attribute__((__unused__))table_id, MAAT_PLUGIN_EX_DATA *to, MAAT_PLUGIN_EX_DATA *from,
|
|
|
|
|
long __attribute__((__unused__))argl, void __attribute__((__unused__))*argp)
|
2018-09-06 19:51:23 +08:00
|
|
|
{
|
2019-05-24 15:09:34 +08:00
|
|
|
struct pxy_obj_keyring* pxy_obj=(struct pxy_obj_keyring*)(*from);
|
2019-06-18 20:45:00 +08:00
|
|
|
if(pxy_obj==NULL)
|
|
|
|
|
{
|
|
|
|
|
*to=NULL;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-06-14 13:25:46 +08:00
|
|
|
atomic64_inc (&pxy_obj->ref_cnt);
|
2019-06-18 20:45:00 +08:00
|
|
|
*((struct pxy_obj_keyring**)to)=pxy_obj;
|
2019-05-24 15:09:34 +08:00
|
|
|
}
|
2018-09-06 19:51:23 +08:00
|
|
|
|
2019-05-24 15:09:34 +08:00
|
|
|
int maat_table_ex_init(const char* table_name,
|
|
|
|
|
Maat_plugin_EX_new_func_t* new_func,
|
|
|
|
|
Maat_plugin_EX_free_func_t* free_func,
|
|
|
|
|
Maat_plugin_EX_dup_func_t* dup_func)
|
|
|
|
|
{
|
|
|
|
|
int table_id = 0;
|
2018-09-06 19:51:23 +08:00
|
|
|
|
2019-05-24 15:09:34 +08:00
|
|
|
struct config_bucket_t *rte = cert_default_config();
|
|
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
table_id= rte->table_id = Maat_table_register(rte->feather, table_name);
|
2019-05-24 15:09:34 +08:00
|
|
|
if(table_id<0)
|
|
|
|
|
{
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
2019-11-05 11:38:40 +08:00
|
|
|
table_id=Maat_plugin_EX_register(rte->feather,
|
2019-05-24 15:09:34 +08:00
|
|
|
table_id,
|
|
|
|
|
new_func,free_func,
|
|
|
|
|
dup_func,NULL,0,NULL);
|
|
|
|
|
finish:
|
|
|
|
|
return table_id;
|
2018-09-06 19:51:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int maat_feather_init()
|
|
|
|
|
{
|
2019-05-24 15:09:34 +08:00
|
|
|
int ret = -1;
|
2018-09-06 19:51:23 +08:00
|
|
|
Maat_feather_t feather = NULL;
|
2018-10-22 11:15:57 +08:00
|
|
|
int scan_interval_ms = 1000;
|
2018-09-06 19:51:23 +08:00
|
|
|
|
|
|
|
|
struct config_bucket_t *rte = cert_default_config();
|
2018-09-18 14:48:55 +08:00
|
|
|
struct ntc_maat_t *maat_t = &rte->maat_t;
|
2018-09-06 19:51:23 +08:00
|
|
|
|
2018-10-22 11:15:57 +08:00
|
|
|
int effective_interval_ms = maat_t->effective_interval_s * 1000;
|
|
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
feather = Maat_feather(rte->thread_nu, maat_t->info_path, logging_sc_lid.run_log_handle);
|
2018-09-06 19:51:23 +08:00
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
Maat_set_feather_opt(feather, MAAT_OPT_INSTANCE_NAME, "certstore", strlen("certstore") + 1);
|
2018-09-18 14:48:55 +08:00
|
|
|
|
|
|
|
|
if (maat_t->maat_json_switch == 1){
|
2019-11-05 11:38:40 +08:00
|
|
|
Maat_set_feather_opt(feather, MAAT_OPT_JSON_FILE_PATH, maat_t->pxy_path, strlen(maat_t->pxy_path)+1);
|
2018-09-18 14:48:55 +08:00
|
|
|
}
|
|
|
|
|
if (maat_t->maat_json_switch == 0){
|
2019-11-05 11:38:40 +08:00
|
|
|
Maat_set_feather_opt(feather, MAAT_OPT_FULL_CFG_DIR, maat_t->full_cfg_dir, strlen(maat_t->full_cfg_dir)+1);
|
|
|
|
|
Maat_set_feather_opt(feather, MAAT_OPT_INC_CFG_DIR, maat_t->inc_cfg_dir, strlen(maat_t->inc_cfg_dir)+1);
|
2018-10-22 11:15:57 +08:00
|
|
|
}
|
|
|
|
|
if (maat_t->maat_json_switch == 2){
|
2019-11-05 11:38:40 +08:00
|
|
|
Maat_set_feather_opt(feather, MAAT_OPT_REDIS_IP, rte->addr_t.maat_ip, strlen(rte->addr_t.maat_ip)+1);
|
|
|
|
|
Maat_set_feather_opt(feather, MAAT_OPT_REDIS_PORT, &rte->addr_t.maat_port, sizeof(rte->addr_t.maat_port));
|
|
|
|
|
Maat_set_feather_opt(feather, MAAT_OPT_REDIS_INDEX, &rte->addr_t.dbindex, sizeof(rte->addr_t.dbindex));
|
2018-09-18 14:48:55 +08:00
|
|
|
}
|
|
|
|
|
|
2019-11-05 11:38:40 +08:00
|
|
|
Maat_set_feather_opt(feather, MAAT_OPT_SCANDIR_INTERVAL_MS,&scan_interval_ms, sizeof(scan_interval_ms));
|
|
|
|
|
Maat_set_feather_opt(feather, MAAT_OPT_EFFECT_INVERVAL_MS,&effective_interval_ms, sizeof(effective_interval_ms));
|
2018-10-22 11:15:57 +08:00
|
|
|
/***/
|
|
|
|
|
const char* foregin_dir="./foreign_files/";
|
2019-11-05 11:38:40 +08:00
|
|
|
Maat_set_feather_opt(feather, MAAT_OPT_FOREIGN_CONT_DIR,foregin_dir, strlen(foregin_dir)+1);
|
|
|
|
|
ret = Maat_initiate_feather(feather);
|
2019-05-24 15:09:34 +08:00
|
|
|
if (ret < 0)
|
|
|
|
|
{
|
|
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "%s MAAT init failed.", __FUNCTION__);
|
|
|
|
|
}
|
|
|
|
|
rte->feather = feather;
|
|
|
|
|
|
2019-05-27 13:33:40 +08:00
|
|
|
int table_id = maat_table_ex_init("PXY_PROFILE_KEYRING",
|
2019-05-24 15:09:34 +08:00
|
|
|
keyring_table_new_cb,
|
|
|
|
|
keyring_table_free_cb,
|
|
|
|
|
keyring_table_dup_cb);
|
|
|
|
|
if(table_id<0)
|
|
|
|
|
{
|
2019-05-28 19:12:21 +08:00
|
|
|
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "certstore register table PXY_PROFILE_KEYRING failed");
|
2019-05-24 15:09:34 +08:00
|
|
|
}
|
|
|
|
|
|
2018-09-06 19:51:23 +08:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int cert_session_init()
|
|
|
|
|
{
|
|
|
|
|
mesa_fiel_stat_init();
|
|
|
|
|
|
|
|
|
|
maat_feather_init();
|
|
|
|
|
|
|
|
|
|
libevent_socket_init();
|
2018-09-10 10:01:27 +08:00
|
|
|
|
2018-09-06 19:51:23 +08:00
|
|
|
return 0;
|
2018-06-19 11:32:16 +08:00
|
|
|
}
|
|
|
|
|
|