Loading tools/itscertgen/checker/certinfo.c +7 −3 Original line number Diff line number Diff line Loading @@ -255,7 +255,11 @@ int main(int argc, char ** argv) cxml_handler_add_default_entities(NULL); fprintf(stdout, "\t<signer type =\"%s\"", ENUMSTRING(*p, _signer_types)); if (*p == si_digest || *p == si_digest_with_other_algorithm){ if (*p == si_self){ p++; fprintf(stdout, "/>\n"); } else if (*p == si_digest || *p == si_digest_with_other_algorithm){ if (*p == si_digest_with_other_algorithm){ p++; fprintf(stdout, " algorithm =\"%s\"", ENUMSTRING(*p, _pk_algorithms)); Loading @@ -269,7 +273,7 @@ int main(int argc, char ** argv) } else{ fprintf(stdout, ">\n"); if (*p == si_certificate_chain || *p >= si_other){ if (*p == si_certificate_chain || *p == si_other){ const char * b = ++p; length = (uint32_t)cintx_read(&p, e, NULL); print_x(stdout, b, length); Loading tools/itscertgen/cshared/cstr.c +28 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,34 @@ char * cstrcpy(char * dst, const char * src) return dst + len; } char * cstrchr(const char * str, int c) { char * ret = (char*)0; if (str) { if (c == 0) ret = cstrend(str); else{ ret = strchr(str, c); if (!ret) ret = cstrend(str); } } return ret; } char * cstrrchr(const char * str, int c) { char * ret = (char*)0; if (str) { if (c == 0) ret = cstrend(str); else{ ret = strrchr(str, c); if (!ret) ret = cstrend(str); } } return ret; } char * cstrrchr(const char * str, int c); /* copy up to maxsize characters from src to dst and return pointer to the next byte after the end */ char * cstrncpy(char * dst, int maxsize, const char * src) { Loading tools/itscertgen/cshared/cstr.h +3 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,9 @@ char * cvstrncpy(char * dst, int maxsize, const char * ptr, ...); int cstrequal(const char * s1, const char * s2); char* cstrisprefix(const char * str, const char * prefix); char * cstrchr(const char * str, int c); char * cstrrchr(const char * str, int c); /* allocate copy of the str */ char * cstralloc(int size); char * cstrdup(const char * str); Loading tools/itscertgen/generator/certgen.c +93 −19 Original line number Diff line number Diff line Loading @@ -15,6 +15,8 @@ #include "../cshared/copts.h" #include "../cshared/cserialize.h" #include "../cshared/cstr.h" #include "../cshared/cring.h" #include "../cshared/cmem.h" #include "ecc_api.h" #include "mkgmtime.h" Loading Loading @@ -258,6 +260,7 @@ static const char * _verificationKey = NULL; static const char * _decriptionKey = NULL; static const char * _keyPath = NULL; static int _reuseKeys = 0; static int _force = 0; static long _refLat = 0; static long _refLon = 0; Loading Loading @@ -304,6 +307,63 @@ static int _refPoint_option(const copt_t * opt, const char * option, const copt_ return -1; } typedef struct macro_item macro_item; struct macro_item { cring_t _ring; const char* name; const char* value; }; static macro_item _default_macro[] = { { { NULL, NULL }, "CAM", "36" }, { { NULL, NULL }, "DENM", "37" }, { { NULL, NULL }, "GENERIC", "38" }, { { NULL, NULL }, "TLM", "137" }, { { NULL, NULL }, "SPAT", "137" }, { { NULL, NULL }, "RLT", "138" }, { { NULL, NULL }, "MAP", "138" }, { { NULL, NULL }, "MAP", "138" }, { { NULL, NULL }, "IVI", "139" }, { { NULL, NULL }, "TLC", "140" }, { { NULL, NULL }, "GN-MGMT", "141" } }; static cring_t _macro = { &_macro, &_macro }; static int _addMacro_option(const copt_t * opt, const char * option, const copt_value_t * value) { macro_item * m; const char * n = value->v_str; char * v = strchr(n, ':'); if (v){ *(v++) = 0; if (0 == *v) v = NULL; } for (m = cring_first_cast(_macro, macro_item); &m->_ring != &_macro && !cstrequal(m->name, n); m = cring_next_cast(m, macro_item)); if (&m->_ring == &_macro){ m = cnew(macro_item); cring_init(&m->_ring); cring_enqueue(&_macro, &m->_ring); m->name = n; } m->value = v; return 0; } static const char * macro_lookup(const char* n) { macro_item * m; for (m = cring_first_cast(_macro, macro_item); &m->_ring != &_macro; m = cring_next_cast(m, macro_item)) { if (cstrequal(m->name, n)){ return m->value; } } return NULL; } static const char * _o_formats[] = { "bin", "hex", "pem", NULL }; Loading @@ -316,13 +376,14 @@ static copt_t options [] = { { "S", "certs", COPT_STR, (void*)&_searchPath, "Certificates search path [Output path by default]" }, { "K", "keys", COPT_STR, (void*)&_keyPath, "Private key storage path [Output path by default]" }, { "R", "reuse", COPT_BOOL, (void*)&_reuseKeys, "Reuse existing key pair [regenerate by default]" }, { "f", "force", COPT_BOOL, (void*)&_force, "Force regenerate existing certificate and keys" }, { "n", "name", COPT_STR, (void*)&_certName, "Certificate name (take from profile by default)" }, { "v", "vkey", COPT_STR, (void*)&_verificationKey, "Verification public key (generate key pair by default)" }, { "e", "ekey", COPT_STR, (void*)&_decriptionKey, "Decription public key (generate key pair if neccessary)" }, { "s", "signer", COPT_STR, (void*)&_signerName, "Signer certificate name [take from profile by default]" }, { "t", "reftime", COPT_STR | COPT_CALLBACK, (void*)&_time_option, "Reference UTC time point (YYY-DD-MM) [current date]" }, { "l", "reflocation", COPT_STR | COPT_CALLBACK, (void*)&_refPoint_option, "Reference location in form <lat>:<lon> [0.0:0.0]" }, // { "c", "chain", COPT_BOOL , &_createChain, "Produce a text file for ITS Test Suite" }, { "m", "macro", COPT_STR | COPT_CALLBACK, (void*)&_addMacro_option, "Add macro in form of name:value to process AID, SSP, etc." }, { NULL, NULL, COPT_END, NULL, NULL } }; Loading @@ -338,6 +399,11 @@ int main(int argc, char ** argv) // set default time to the begining of this year _setup_default_time(); // init default macroses for (rc = 0; rc < sizeof(_default_macro) / sizeof(_default_macro[0]); rc++){ cring_enqueue(&_macro, &_default_macro[rc]._ring); } argc = coptions(argc, argv, COPT_HELP_NOVALUES , options); if(argc < 2){ Loading Loading @@ -412,7 +478,7 @@ static int root_certificate_tag (cxml_handler_t* const _h, cxml_tag_t * const ta } h->ptr = h->buf = malloc(4096); h->end = h->buf + 4096; if (cxml_tag_attr_boolean(tag, "keep-existing")){ if (!_force && cxml_tag_attr_boolean(tag, "keep-existing")){ FILE * f; char * path = h->ptr; cvstrncpy(path, h->end - path, _outPath, "/", _certName, ".crt", NULL); Loading Loading @@ -990,14 +1056,18 @@ static int attribute_aid_tag (cxml_handler_t* const _h, cxml_tag_t * cons uint32_t n; while(cisspace(*v))v++; if (!cisdigit(*v)){ // look in the aid map const char * v1 = macro_lookup(v); if (!v1){ fprintf(stderr, "ERROR: Invalid AID '%s'\n", v); rc = -1; }else{ return -1; } v = v1; } n = strtoul(v, NULL, 0); cintx_write(n, &h->ptr, h->end, &rc); } } } return rc; } Loading @@ -1014,14 +1084,18 @@ static int attribute_ssp_tag (cxml_handler_t* const _h, cxml_tag_t * cons } while(cisspace(*v))v++; if (!cisdigit(*v)){ // look in the aid map const char * v1 = macro_lookup(v); if (!v1){ fprintf(stderr, "ERROR: Invalid AID '%s' in SSP\n", v); return -1; } v = v1; } n = strtoul(v, NULL, 0); cintx_write(n, &h->ptr, h->end, &rc); bookmark_position(h, tag); }else{ // write ssp buffer data apply_bookmark_size(h, tag); } return rc; Loading Loading
tools/itscertgen/checker/certinfo.c +7 −3 Original line number Diff line number Diff line Loading @@ -255,7 +255,11 @@ int main(int argc, char ** argv) cxml_handler_add_default_entities(NULL); fprintf(stdout, "\t<signer type =\"%s\"", ENUMSTRING(*p, _signer_types)); if (*p == si_digest || *p == si_digest_with_other_algorithm){ if (*p == si_self){ p++; fprintf(stdout, "/>\n"); } else if (*p == si_digest || *p == si_digest_with_other_algorithm){ if (*p == si_digest_with_other_algorithm){ p++; fprintf(stdout, " algorithm =\"%s\"", ENUMSTRING(*p, _pk_algorithms)); Loading @@ -269,7 +273,7 @@ int main(int argc, char ** argv) } else{ fprintf(stdout, ">\n"); if (*p == si_certificate_chain || *p >= si_other){ if (*p == si_certificate_chain || *p == si_other){ const char * b = ++p; length = (uint32_t)cintx_read(&p, e, NULL); print_x(stdout, b, length); Loading
tools/itscertgen/cshared/cstr.c +28 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,34 @@ char * cstrcpy(char * dst, const char * src) return dst + len; } char * cstrchr(const char * str, int c) { char * ret = (char*)0; if (str) { if (c == 0) ret = cstrend(str); else{ ret = strchr(str, c); if (!ret) ret = cstrend(str); } } return ret; } char * cstrrchr(const char * str, int c) { char * ret = (char*)0; if (str) { if (c == 0) ret = cstrend(str); else{ ret = strrchr(str, c); if (!ret) ret = cstrend(str); } } return ret; } char * cstrrchr(const char * str, int c); /* copy up to maxsize characters from src to dst and return pointer to the next byte after the end */ char * cstrncpy(char * dst, int maxsize, const char * src) { Loading
tools/itscertgen/cshared/cstr.h +3 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,9 @@ char * cvstrncpy(char * dst, int maxsize, const char * ptr, ...); int cstrequal(const char * s1, const char * s2); char* cstrisprefix(const char * str, const char * prefix); char * cstrchr(const char * str, int c); char * cstrrchr(const char * str, int c); /* allocate copy of the str */ char * cstralloc(int size); char * cstrdup(const char * str); Loading
tools/itscertgen/generator/certgen.c +93 −19 Original line number Diff line number Diff line Loading @@ -15,6 +15,8 @@ #include "../cshared/copts.h" #include "../cshared/cserialize.h" #include "../cshared/cstr.h" #include "../cshared/cring.h" #include "../cshared/cmem.h" #include "ecc_api.h" #include "mkgmtime.h" Loading Loading @@ -258,6 +260,7 @@ static const char * _verificationKey = NULL; static const char * _decriptionKey = NULL; static const char * _keyPath = NULL; static int _reuseKeys = 0; static int _force = 0; static long _refLat = 0; static long _refLon = 0; Loading Loading @@ -304,6 +307,63 @@ static int _refPoint_option(const copt_t * opt, const char * option, const copt_ return -1; } typedef struct macro_item macro_item; struct macro_item { cring_t _ring; const char* name; const char* value; }; static macro_item _default_macro[] = { { { NULL, NULL }, "CAM", "36" }, { { NULL, NULL }, "DENM", "37" }, { { NULL, NULL }, "GENERIC", "38" }, { { NULL, NULL }, "TLM", "137" }, { { NULL, NULL }, "SPAT", "137" }, { { NULL, NULL }, "RLT", "138" }, { { NULL, NULL }, "MAP", "138" }, { { NULL, NULL }, "MAP", "138" }, { { NULL, NULL }, "IVI", "139" }, { { NULL, NULL }, "TLC", "140" }, { { NULL, NULL }, "GN-MGMT", "141" } }; static cring_t _macro = { &_macro, &_macro }; static int _addMacro_option(const copt_t * opt, const char * option, const copt_value_t * value) { macro_item * m; const char * n = value->v_str; char * v = strchr(n, ':'); if (v){ *(v++) = 0; if (0 == *v) v = NULL; } for (m = cring_first_cast(_macro, macro_item); &m->_ring != &_macro && !cstrequal(m->name, n); m = cring_next_cast(m, macro_item)); if (&m->_ring == &_macro){ m = cnew(macro_item); cring_init(&m->_ring); cring_enqueue(&_macro, &m->_ring); m->name = n; } m->value = v; return 0; } static const char * macro_lookup(const char* n) { macro_item * m; for (m = cring_first_cast(_macro, macro_item); &m->_ring != &_macro; m = cring_next_cast(m, macro_item)) { if (cstrequal(m->name, n)){ return m->value; } } return NULL; } static const char * _o_formats[] = { "bin", "hex", "pem", NULL }; Loading @@ -316,13 +376,14 @@ static copt_t options [] = { { "S", "certs", COPT_STR, (void*)&_searchPath, "Certificates search path [Output path by default]" }, { "K", "keys", COPT_STR, (void*)&_keyPath, "Private key storage path [Output path by default]" }, { "R", "reuse", COPT_BOOL, (void*)&_reuseKeys, "Reuse existing key pair [regenerate by default]" }, { "f", "force", COPT_BOOL, (void*)&_force, "Force regenerate existing certificate and keys" }, { "n", "name", COPT_STR, (void*)&_certName, "Certificate name (take from profile by default)" }, { "v", "vkey", COPT_STR, (void*)&_verificationKey, "Verification public key (generate key pair by default)" }, { "e", "ekey", COPT_STR, (void*)&_decriptionKey, "Decription public key (generate key pair if neccessary)" }, { "s", "signer", COPT_STR, (void*)&_signerName, "Signer certificate name [take from profile by default]" }, { "t", "reftime", COPT_STR | COPT_CALLBACK, (void*)&_time_option, "Reference UTC time point (YYY-DD-MM) [current date]" }, { "l", "reflocation", COPT_STR | COPT_CALLBACK, (void*)&_refPoint_option, "Reference location in form <lat>:<lon> [0.0:0.0]" }, // { "c", "chain", COPT_BOOL , &_createChain, "Produce a text file for ITS Test Suite" }, { "m", "macro", COPT_STR | COPT_CALLBACK, (void*)&_addMacro_option, "Add macro in form of name:value to process AID, SSP, etc." }, { NULL, NULL, COPT_END, NULL, NULL } }; Loading @@ -338,6 +399,11 @@ int main(int argc, char ** argv) // set default time to the begining of this year _setup_default_time(); // init default macroses for (rc = 0; rc < sizeof(_default_macro) / sizeof(_default_macro[0]); rc++){ cring_enqueue(&_macro, &_default_macro[rc]._ring); } argc = coptions(argc, argv, COPT_HELP_NOVALUES , options); if(argc < 2){ Loading Loading @@ -412,7 +478,7 @@ static int root_certificate_tag (cxml_handler_t* const _h, cxml_tag_t * const ta } h->ptr = h->buf = malloc(4096); h->end = h->buf + 4096; if (cxml_tag_attr_boolean(tag, "keep-existing")){ if (!_force && cxml_tag_attr_boolean(tag, "keep-existing")){ FILE * f; char * path = h->ptr; cvstrncpy(path, h->end - path, _outPath, "/", _certName, ".crt", NULL); Loading Loading @@ -990,14 +1056,18 @@ static int attribute_aid_tag (cxml_handler_t* const _h, cxml_tag_t * cons uint32_t n; while(cisspace(*v))v++; if (!cisdigit(*v)){ // look in the aid map const char * v1 = macro_lookup(v); if (!v1){ fprintf(stderr, "ERROR: Invalid AID '%s'\n", v); rc = -1; }else{ return -1; } v = v1; } n = strtoul(v, NULL, 0); cintx_write(n, &h->ptr, h->end, &rc); } } } return rc; } Loading @@ -1014,14 +1084,18 @@ static int attribute_ssp_tag (cxml_handler_t* const _h, cxml_tag_t * cons } while(cisspace(*v))v++; if (!cisdigit(*v)){ // look in the aid map const char * v1 = macro_lookup(v); if (!v1){ fprintf(stderr, "ERROR: Invalid AID '%s' in SSP\n", v); return -1; } v = v1; } n = strtoul(v, NULL, 0); cintx_write(n, &h->ptr, h->end, &rc); bookmark_position(h, tag); }else{ // write ssp buffer data apply_bookmark_size(h, tag); } return rc; Loading