mirror of
https://github.com/kakwa/uts-server
synced 2024-11-05 01:08:51 +01:00
code cleaning an reorganization
This commit is contained in:
parent
064f0f8161
commit
eb2b6ae66e
@ -1,4 +1,8 @@
|
||||
#include <stdbool.h>
|
||||
#include "utils.h"
|
||||
|
||||
struct tuser_data {
|
||||
char *first_message;
|
||||
};
|
||||
|
||||
int http_server_start(char *conffile, char *conf_wd, bool stdout_dbg);
|
||||
|
@ -13,7 +13,10 @@
|
||||
#include "context.h"
|
||||
|
||||
/* Name of config entry that defines the OID file. */
|
||||
#define ENV_OID_FILE "oid_file"
|
||||
#define OID_SECTION "oids"
|
||||
|
||||
// number of char we get to log for the serial
|
||||
#define SERIAL_ID_SIZE 8
|
||||
|
||||
#define B_FORMAT_TEXT 0x8000
|
||||
#define FORMAT_UNDEF 0
|
||||
@ -23,11 +26,7 @@
|
||||
static ASN1_OBJECT *txt2obj(const char *oid);
|
||||
|
||||
/* Reply related functions. */
|
||||
static int reply_command(CONF *conf, char *section, char *engine, char *query,
|
||||
char *passin, char *inkey, const EVP_MD *md,
|
||||
char *signer, char *chain, const char *policy,
|
||||
char *in, int token_in, char *out, int token_out,
|
||||
int text);
|
||||
static ASN1_INTEGER *serial_cb(TS_RESP_CTX *ctx, void *data);
|
||||
static TS_RESP *read_PKCS7(BIO *in_bio);
|
||||
int create_response(rfc3161_context *ct, char *query, int query_len,
|
||||
TS_RESP_CTX *resp_ctx, size_t *resp_size,
|
||||
|
@ -1,5 +1,12 @@
|
||||
#include "rfc3161.h"
|
||||
|
||||
typedef struct _code {
|
||||
char *c_name;
|
||||
int c_val;
|
||||
} CODE;
|
||||
|
||||
static void signal_handler_general(int sig_num);
|
||||
static void signal_handler_up(int sig_num);
|
||||
void skeleton_daemon();
|
||||
int init_pid(char *pidfile_path);
|
||||
int write_pid(char *pidfile_path);
|
||||
@ -9,5 +16,7 @@ void log_hex(rfc3161_context *ct, int priority, char *id,
|
||||
int set_params(rfc3161_context *ct, char *conf_file, char *conf_wd);
|
||||
static char *rand_string(char *str, size_t size);
|
||||
void free_uts_context(rfc3161_context *ct);
|
||||
|
||||
// some global variable to handle signals
|
||||
int g_uts_sig_up;
|
||||
int g_uts_sig;
|
||||
|
@ -1,8 +1,3 @@
|
||||
/*
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -16,10 +11,6 @@
|
||||
#include <time.h>
|
||||
#include "http.h"
|
||||
|
||||
struct tuser_data {
|
||||
char *first_message;
|
||||
};
|
||||
|
||||
static char *rand_string(char *str, size_t size) {
|
||||
const char charset[] = "1234567890ABCDEF";
|
||||
if (size) {
|
||||
@ -83,12 +74,6 @@ void log_request_debug(const struct mg_request_info *request_info,
|
||||
request_id, request_info->content_length);
|
||||
uts_logger(context, LOG_DEBUG, "Request[%s], remote_port: %d", request_id,
|
||||
request_info->remote_port);
|
||||
// uts_logger(context, LOG_DEBUG, "Request[%d], user_data: %s",
|
||||
// request_id,
|
||||
// request_info->user_data);
|
||||
// uts_logger(context, LOG_DEBUG, "Request[%d], conn_data: %s",
|
||||
// request_id,
|
||||
// request_info->conn_data);
|
||||
}
|
||||
|
||||
void log_request(const struct mg_request_info *request_info, char *request_id,
|
||||
|
@ -23,28 +23,6 @@
|
||||
#include <syslog.h>
|
||||
#include "utils.h"
|
||||
|
||||
#define OID_SECTION "oids"
|
||||
|
||||
// number of char we get to log for the serial
|
||||
#define SERIAL_ID_SIZE 8
|
||||
|
||||
/* Reply related functions. */
|
||||
static int reply_command(CONF *conf, char *section, char *engine, char *query,
|
||||
char *passin, char *inkey, const EVP_MD *md,
|
||||
char *signer, char *chain, const char *policy,
|
||||
char *in, int token_in, char *out, int token_out,
|
||||
int text);
|
||||
static ASN1_INTEGER *serial_cb(TS_RESP_CTX *ctx, void *data);
|
||||
|
||||
#define B_FORMAT_TEXT 0x8000
|
||||
#define FORMAT_UNDEF 0
|
||||
#define FORMAT_TEXT (1 | B_FORMAT_TEXT) /* Generic text */
|
||||
#define FORMAT_ASN1 4 /* ASN.1/DER */
|
||||
|
||||
/*
|
||||
* Reply-related method definitions.
|
||||
*/
|
||||
|
||||
int add_oid_section(rfc3161_context *ct, CONF *conf) {
|
||||
char *p;
|
||||
STACK_OF(CONF_VALUE) * sktmp;
|
||||
@ -113,6 +91,27 @@ ts_resp_ctx_wrapper *get_ctxw(rfc3161_context *ct) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Build a random serial for each request.
|
||||
// It's less painful to manage than an incremental serial stored in a file
|
||||
// and a 150 bits size is more than enough to prevent collision.
|
||||
static ASN1_INTEGER *serial_cb(TS_RESP_CTX *ctx, void *data42) {
|
||||
unsigned char data[20] = {0};
|
||||
RAND_bytes(data, sizeof(data));
|
||||
// data[0] &= 0x7F;
|
||||
|
||||
// build big number from our bytes
|
||||
BIGNUM *bn = BN_new();
|
||||
BN_bin2bn(data, sizeof(data), bn);
|
||||
|
||||
// build the ASN1_INTEGER from our BIGNUM
|
||||
ASN1_INTEGER *asnInt = ASN1_INTEGER_new();
|
||||
BN_to_ASN1_INTEGER(bn, asnInt);
|
||||
|
||||
// cleanup
|
||||
BN_free(bn);
|
||||
return asnInt;
|
||||
}
|
||||
|
||||
// create a TS_RESP_CTX (OpenSSL Time-Stamp Response Context)
|
||||
TS_RESP_CTX *create_tsctx(rfc3161_context *ct, CONF *conf, const char *section,
|
||||
const char *policy) {
|
||||
@ -353,24 +352,3 @@ end:
|
||||
TS_RESP_free(ts_response);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Build a random serial for each request.
|
||||
// It's less painful to manage than an incremental serial stored in a file
|
||||
// and a 150 bits size is more than enough to prevent collision.
|
||||
static ASN1_INTEGER *serial_cb(TS_RESP_CTX *ctx, void *data42) {
|
||||
unsigned char data[20] = {0};
|
||||
RAND_bytes(data, sizeof(data));
|
||||
// data[0] &= 0x7F;
|
||||
|
||||
// build big number from our bytes
|
||||
BIGNUM *bn = BN_new();
|
||||
BN_bin2bn(data, sizeof(data), bn);
|
||||
|
||||
// build the ASN1_INTEGER from our BIGNUM
|
||||
ASN1_INTEGER *asnInt = ASN1_INTEGER_new();
|
||||
BN_to_ASN1_INTEGER(bn, asnInt);
|
||||
|
||||
// cleanup
|
||||
BN_free(bn);
|
||||
return asnInt;
|
||||
}
|
||||
|
@ -14,10 +14,13 @@
|
||||
#include <fcntl.h>
|
||||
#include "utils.h"
|
||||
|
||||
typedef struct _code {
|
||||
char *c_name;
|
||||
int c_val;
|
||||
} CODE;
|
||||
static void signal_handler_general(int sig_num) {
|
||||
g_uts_sig = sig_num;
|
||||
}
|
||||
|
||||
static void signal_handler_up(int sig_num) {
|
||||
g_uts_sig_up = sig_num;
|
||||
}
|
||||
|
||||
CODE prioritynames[] = {{"alert", LOG_ALERT},
|
||||
{"crit", LOG_CRIT},
|
||||
@ -32,14 +35,6 @@ CODE prioritynames[] = {{"alert", LOG_ALERT},
|
||||
{"warning", LOG_WARNING},
|
||||
{NULL, -1}};
|
||||
|
||||
static void signal_handler_general(int sig_num) {
|
||||
g_uts_sig = sig_num;
|
||||
}
|
||||
|
||||
static void signal_handler_up(int sig_num) {
|
||||
g_uts_sig_up = sig_num;
|
||||
}
|
||||
|
||||
int init_pid(char *pidfile_path) {
|
||||
// if pidfile_path is null, the user did not request one
|
||||
// exit success
|
||||
@ -381,6 +376,7 @@ end:
|
||||
return 0;
|
||||
}
|
||||
|
||||
// free the rfc3161_context structure
|
||||
void free_uts_context(rfc3161_context *ct) {
|
||||
for (int i = 0; i < ct->numthreads; i++) {
|
||||
TS_RESP_CTX_free(ct->ts_ctx_pool[i].ts_ctx);
|
||||
|
Loading…
Reference in New Issue
Block a user