Commit dbd36afa authored by filatov's avatar filatov
Browse files

add support for relative time and position in certificate profiles

parent b638d5b1
Loading
Loading
Loading
Loading
+21 −20
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@
#include "../cshared/copts.h"
#include "../cshared/cserialize.h"
#include "../cxml/cxml.h"
#include "../generator/mkgmtime.h"
#include "mkgmtime.h"

static size_t load_certificate(const char * path, char ** p);
static EC_KEY * load_public_key(const char* path, const EC_GROUP * group);
@@ -169,13 +169,13 @@ char * _es_bufs[8][64];
int _es_bufs_idx = 0;
static const char * _enumstring(int value, const char ** names, int nsize)
{
	const char * ret;
	char * ret;
	if (!_numeric && value >= 0 && value < nsize && names[value]){
		return names[value];
	}
	ret = _es_bufs[(++_es_bufs_idx) & 7];
	ret = (char*)_es_bufs[(++_es_bufs_idx) & 7];
	sprintf(ret, "%d", value);
	return ret;
	return (const char*)ret;
}
#define ENUMSTRING(V,L) _enumstring(V, L, sizeof(L)/sizeof(L[0]))

@@ -187,10 +187,10 @@ static int EccPoint_Size(const EccPoint * p){
static void EccPoint_Print(FILE * f, const char * prefix, const EccPoint * const p)
{
	fprintf(f, "%s<ecc_point type=\"%s\">\n%s\t", prefix, ENUMSTRING(p->type, _point_types), prefix);
	print_x(f, p->x, 32);
	print_x(f, (const char*)p->x, 32);
	if (p->type == 4){
		fprintf(f, "\n%s\t", prefix);
		print_x(f, p->y, 32);
		print_x(f, (const char*)p->y, 32);
	}
	fprintf(f, "\n%s</ecc_point>\n", prefix);
}
@@ -240,7 +240,7 @@ int main(int argc, char ** argv)
	}

	if (_xmlOutput){
		int length;
		uint32_t length;
		char digest[8];
		const char * p = cert;
		const char * e = cert + certlen;
@@ -278,11 +278,11 @@ int main(int argc, char ** argv)
		}
		fprintf(stdout, ">\n");
		p += 2 + si->name_length;
		length = cintx_read(&p, e, NULL);
		length = (uint32_t)cintx_read(&p, e, NULL);
		print_attributes(&p, p + length);
		fprintf(stdout, "\t</subject>\n");

		length = cintx_read(&p, e, NULL);
		length = (uint32_t)cintx_read(&p, e, NULL);
		fprintf(stdout, "\t<validity>\n");
		print_validity(&p, p + length);
		fprintf(stdout, "\t</validity>\n");
@@ -390,7 +390,7 @@ static size_t load_certificate(const char * path, char ** p)
	}
	if (cert[0] != 2) {
		// try hexadecimal
		int i;
		size_t i;
		for (i = 0; i < size; i++){
			char ch1 = cert[i];
			if (ch1 < '0'
@@ -513,9 +513,10 @@ static void calculate_certificate_digest(const char* data, int length, char

static void print_x(FILE * f, const char * ptr, int len)
{
	const unsigned char * e = (const unsigned char *)(ptr + len);
	for (; ptr < e; ptr++){
		unsigned char c = *ptr;
	const unsigned char * p = (const unsigned char *)ptr;
	const unsigned char * e = p + len;
	for (; p < e; p++){
		unsigned char c = *p;
		fprintf(f, "%02X", c);
	}
}
@@ -528,7 +529,7 @@ static int print_attributes(const char ** pp, const char * e)
	int rc = 0;
	const char * p = *pp;
	unsigned char atype;
	int length;
	uint32_t length;
	while (rc == 0 && p < e){
		const PublicKey * key;
		const EccPoint *  point;
@@ -577,11 +578,11 @@ static int print_attributes(const char ** pp, const char * e)
			p += EccPoint_Size(point);
			break;
		case its_aid_list:
			length = cintx_read(&p, e, NULL);
			length = (uint32_t)cintx_read(&p, e, NULL);
			rc = print_aid_list(&p, p + length);
			break;
		case its_aid_ssp_list:
			length = cintx_read(&p, e, NULL);
			length = (uint32_t)cintx_read(&p, e, NULL);
			rc = print_aid_ssp_list(&p, p + length);
			break;
		default:
@@ -600,7 +601,7 @@ static int print_aid_list(const char ** pp, const char * e)
	int rc = 0;
	const char *p = *pp;
	while (rc == 0 && p < e){
		int n = cintx_read(&p, e, &rc);
		uint32_t n = (uint32_t)cintx_read(&p, e, &rc);
		fprintf(stdout, "\t\t\t<aid value=\"%d\"/>\n", n);
	}
	*pp = e;
@@ -613,8 +614,8 @@ static int print_aid_ssp_list(const char ** pp, const char * e)
	const char *p = *pp;
	while (rc == 0 && p < e){
		char * data;
		int n = cintx_read(&p, e, &rc);
		int len = cintx_read(&p, e, &rc);
		uint32_t n = (uint32_t)cintx_read(&p, e, &rc);
		uint32_t len = (uint32_t)cintx_read(&p, e, &rc);
		fprintf(stdout, "\t\t\t<ssp aid=\"%d\"/>", n);
		if (len){
			int r = cxml_text_encode(NULL, &data, p, len);
@@ -726,7 +727,7 @@ static int print_validity(const char ** pp, const char * e)
					if (rc == 0){
						uint16_t id = cint16_read(&p, e, &rc);
						if (rc == 0){
							int local = cintx_read(&p, e, &rc);
							uint32_t local = (uint32_t)cintx_read(&p, e, &rc);
							if (rc == 0){
								fprintf(stdout, "\t\t\t<id dictionary=\"%s\" id=\"%u\" local=\"%u\"/>\n",
									ENUMSTRING(dict, _id_region_dicts), id, local);
+15 −14
Original line number Diff line number Diff line
PROJECTROOT  = ..
BUILDROOT    = ../build
BUILDROOT    = ../build/
PROJECT      = cshared
DEBUG        = yes
testdir      = tests
@@ -7,8 +7,9 @@ testdir = tests
alibs        = $(PROJECT)
solibs       = $(PROJECT)

sources       := copts.c cserialize.c cstr.c
headers       := copts.h cserialize.h cstr.h
sources       := copts.c cserialize.c cstr.c cring.c e4c_lite.c
sources-WIN32 := cdir_win.c
headers       := copts.h cserialize.h cstr.h cdir.h cring.h cmem.h e4c_lite.h
tests         := test_copts.c

include ../common.mk
+33 −0
Original line number Diff line number Diff line
#ifndef cdir_h
#define cdir_h
#include "cstr.h"
#include "cserialize.h"
#ifdef __cplusplus
extern "C" {
#endif

typedef struct cdir_t cdir_t;
enum {
	e_cdir_recursive = 1,
	e_cdir_nofiles   = 4,
	e_cdir_nodirs    = 8,
};

typedef struct {
	const char * path;
	const char * fname;
	int          flags;
	uint64_t     size;
}cdir_stat_t;

cdir_t *            cdir_open(const pchar_t * path, const char * mask, int flags);
void                cdir_close(cdir_t * dir);
cdir_t *            cdir_rewind(cdir_t * dir);
const cdir_stat_t * cdir_next(cdir_t * dir);

int             cdir_glob(const char * mask, const char * fname);
#ifdef __cplusplus
}
#endif
#endif
+104 −0
Original line number Diff line number Diff line
#define _CRT_SECURE_NO_WARNINGS
#include "cdir.h"
#include "cmem.h"
#include "cstr.h"
#include <windows.h>


struct cdir_t {
	WIN32_FIND_DATA fd;
	HANDLE      h;
	int         flags;
	char *      path;
	char *      fname;
	cdir_stat_t st;
};

static void _cdir_apply_filter(cdir_t * dir)
{
	do {
		if (dir->fd.dwFileAttributes &  FILE_ATTRIBUTE_DIRECTORY) {
			if (strcmp(".", dir->fd.cFileName) && strcmp("..", dir->fd.cFileName)){
				if (0 == (dir->flags & e_cdir_nodirs)) return;
			}
		}
		else {
			if (0 == (dir->flags & e_cdir_nofiles)) return;
		}
		//skip this file
	} while (FindNextFile(dir->h, &dir->fd));
	FindClose(dir->h);
	dir->h = INVALID_HANDLE_VALUE;
}

cdir_t * cdir_open(const pchar_t * path, const char * mask, int flags)
{
	cdir_t * dir;
	int plen = path ? pchar_len(path) : 0;
	dir = cnew(cdir_t);
	dir->path = pchar_alloc(plen + MAX_PATH + 1);
	pchar_cpy(dir->path, path);
	while (plen > 0 && (dir->path[plen - 1] == '/' || dir->path[plen - 1] == '\\'))plen--;
	if (plen > 0) {
		dir->path[plen] = '\\';
		dir->fname = dir->path + plen + 1;
	}
	else{
		dir->fname = dir->path;
	}
	dir->flags = flags;
	if (mask == NULL) mask = "*";
	strcpy(dir->fname, mask);
	dir->h = FindFirstFile(dir->path, &dir->fd);
	if (INVALID_HANDLE_VALUE == dir->h){
		cfree(dir);
		return NULL;
	}
	_cdir_apply_filter(dir);
	dir->st.path = dir->path;
	dir->st.fname = dir->fname;
	return dir;
}

void cdir_close(cdir_t * dir)
{
	if(dir){
		if(dir->h != INVALID_HANDLE_VALUE){
			FindClose(dir->h);
		}
		cfree(dir);
	}
}

cdir_t * cdir_rewind(cdir_t * dir)
{
	if(dir){
		if(dir->h != INVALID_HANDLE_VALUE){
			FindClose(dir->h);
		}
		*dir->fname  = 0;
		dir->h = FindFirstFile(dir->path, &dir->fd);
		if(INVALID_HANDLE_VALUE == dir->h){
			cfree(dir);
			dir = NULL;
		}
	}
	return dir;
}

const cdir_stat_t* cdir_next(cdir_t * dir)
{
	if (dir && dir->h != INVALID_HANDLE_VALUE){
		pchar_cpy(dir->fname, dir->fd.cFileName);
		dir->st.size = dir->fd.nFileSizeHigh;
		dir->st.size = (dir->st.size << 32) | dir->fd.nFileSizeLow;
		if (FindNextFile(dir->h, &dir->fd)){
			_cdir_apply_filter(dir);
		}else {
			FindClose(dir->h);
			dir->h = INVALID_HANDLE_VALUE;
		}
		return &dir->st;
	}
	return NULL;
}
+109 −0
Original line number Diff line number Diff line
/*********************************************************************
######################################################################
##
##  Created by: Denis Filatov
##  Date      : 10.11.2005
##
##  Copyleft (c) 2003 - 2015
##  This code is provided under the CeCill-C license agreement.
######################################################################
*********************************************************************/
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "clog.h"

static int _clog_level = CLOG_INFO;
static FILE * _clog_out[CLOG_LASTLEVEL];
static const char * _clog_lnames[CLOG_LASTLEVEL] = {
    "FATAL",
    "ERROR",
    "WARNING",
    "INFO",
    "DEBUG",
};

static int _clog_out_initialized = 0;

static void _clog_out_initialize(void)
{
    int i;
    _clog_out[CLOG_FATAL]   = stderr;
    _clog_out[CLOG_ERROR]   = stderr;
    _clog_out[CLOG_WARNING] = stderr;
    for(i=CLOG_INFO; i<CLOG_LASTLEVEL; i++){
        _clog_out[i] = stdout;
    }
    _clog_out_initialized = 1;
}

int  clog_level(void)
{
    return _clog_level;
}

void clog_set_level(int const level)
{
    if(level >= 0 && level <= CLOG_DEBUG){
        _clog_level = level;
    }
}
const char * clog_level_name(int const level)
{
    const char * ret = NULL;
    if(level < CLOG_LASTLEVEL)
        ret = _clog_lnames[level];
    return ret ? ret : CLOG_DEFAULT_LEVEL_NAME;
}

void clog_set_level_name(int const level, const char * const name)
{
    if(level < CLOG_LASTLEVEL)
        _clog_lnames[level] = name;
}

void clog_set_output(int const level, void * const out)
{
    if(0 == _clog_out_initialized){
        _clog_out_initialize();
    }
    if(level < 0){
        int i;
        for(i=0; i<sizeof(_clog_out)/sizeof(_clog_out[0]); i++){
            _clog_out[i] = (FILE*)out;
        }
    }else if(level < sizeof(_clog_out)/sizeof(_clog_out[0])){
        _clog_out[level] = (FILE*)out;
    }
}

void clog_fprintf(void * const f, int const level, const char * format, ...)
{
    if(level <= _clog_level){
        FILE * out;
        va_list ap;
        if(f){
            out = (FILE*)f;
        }else{
            if(0 == _clog_out_initialized){
                _clog_out_initialize();
            }
            if(level >= sizeof(_clog_out)/sizeof(_clog_out[0])){
                out = _clog_out[sizeof(_clog_out)/sizeof(_clog_out[0]) - 1];
            }else{
                out = _clog_out[level];
            }
        }
        if(out){
            va_start(ap, format);
            vfprintf(out, format, ap);
            va_end(ap);
            {
                int l = strlen(format);
                if(l == 0 || format[l-1]!= '\n'){
                    fprintf(out, "\n");
                }
            }
        }
    }
}
Loading