Compare Revisions

The credentials to download the source code are:
 Username: svnusers
 Password: svnusers

Ignore whitespace Rev 1910 → Rev 1911

/branches/Security/tools/itscertgen/certgen.c
192,7 → 192,6
static char *_profileName = NULL;
static const char *_signerName = NULL;
static unsigned int _defaultTime = 0;
static unsigned int _createChain = 0;
static unsigned int _outFormat = 0; // binary by default
static const char * _outExtensions[] = {
"bin", "hex", "pem"
209,13 → 208,13
{
_outFormat = STR2ENUM(_outExtensions, opt->lopt);
if (_outFormat >= 0){
printf("OutFormat=%s\n", _outExtensions[_outFormat]);
// printf("OutFormat=%s\n", _outExtensions[_outFormat]);
return 0;
}
return -1;
}
 
static const copt_t options [] = {
static copt_t options [] = {
{ "h?", "help", COPT_HELP, NULL, "Print this help page" },
{ "i", "in", COPT_STR, &_searchPath, "Certificates search path [Output path by default]" },
{ "o", "out", COPT_STR, &_outPath, "Output path [current dir by default]" },
280,10 → 279,6
}
fclose(f);
 
if (_createChain){
 
}
 
ecc_api_done();
}
return 0;
1075,15 → 1070,29
return -1;
}
// load signer certificate
char * binkey;
int plen = strlen(_searchPath) + strlen(h->signer);
char * path = malloc(plen + 16);
cvstrncpy(path, plen + 16, _searchPath, "/", h->signer, ".v.pem", NULL);
key = ecc_api_key_private_load(path);
if (!key){
fprintf(stderr, "%s: Could not load issuing private key from file\n", path);
free(path);
return -1;
 
cvstrncpy(path, plen + 16, _searchPath, "/", h->signer, ".v.bin", NULL);
if (cstraload(&binkey, path)){
key = ecc_api_key_init(ecdsa_nistp256_with_sha256, aes_128_ccm, binkey);
if (key == NULL){
fprintf(stderr, "%s: Could not load issuing private key from binary file\n", path);
free(path);
free(binkey);
return -1;
}
}
else {
cvstrncpy(path, plen + 16, _searchPath, "/", h->signer, ".v.pem", NULL);
key = ecc_api_key_private_load(path);
if (!key){
fprintf(stderr, "%s: Could not load issuing private key from file\n", path);
free(path);
return -1;
}
}
}
const char * v = cxml_tag_attr_value(tag, "algorithm");
if(v){
/branches/Security/tools/itscertgen/cshared/cstr.c
137,14 → 137,14
FILE * f = fopen(path, "rb");
unsigned long len;
unsigned long ms = max_size;
if(!f) return NULL;
if (!f) return NULL;
fseek(f, 0, SEEK_END);
len = ftell(f);
fseek(f, 0, SEEK_SET);
if(len > ms) len = ms;
if (len > ms) len = ms;
ms = fread(dst, 1, len, f);
fclose(f);
if((int)ms < 0){
if ((int)ms < 0){
return NULL;
}
dst[len] = 0;
151,6 → 151,34
return dst + len;
}
 
char * cstraload(char ** p, const char * path)
{
char * ret = NULL;
FILE * f = fopen(path, "rb");
int len;
if (f){
fseek(f, 0, SEEK_END);
len = ftell(f);
fseek(f, 0, SEEK_SET);
if (len > 0){
ret = malloc(len);
if (ret){
int ms = fread(ret, 1, len, f);
if (ms < len){
free(ret);
*p = ret = NULL;
}
else{
*p = ret;
ret += len;
}
}
}
fclose(f);
}
return ret;
}
 
const char * cstrlastpathelement(const char * str)
{
const char * p = strrchr(str, '/');
/branches/Security/tools/itscertgen/cshared/cstr.h
25,6 → 25,7
char * cvstrdup(const char * ptr, ...);
 
char * cstrnload(char * dst, int max_size, const char * path);
char * cstraload(char ** p, const char * path);
 
const char * cstrlastpathelement(const char * str);
 
/branches/Security/tools/itscertgen/ecc_api.h
19,6 → 19,7
}ecc_sym_algorithm;
 
void * ecc_api_key_gen (ecc_pk_algorithm pk_alg, ecc_sym_algorithm sym_alg);
void * ecc_api_key_init(ecc_pk_algorithm pk_alg, ecc_sym_algorithm sym_alg, const char* pkey);
void ecc_api_key_free(void*);
int ecc_api_key_private(void*, char* buf);
int ecc_api_key_public(void*, char* x, char* y);
/branches/Security/tools/itscertgen/ecc_openssl.c
11,28 → 11,28
NID_secp256k1,
NID_secp256k1
};
static EVP_PKEY_CTX *pctx [sizeof(_NIDS)/sizeof(_NIDS[0])] = {NULL};
static EVP_PKEY_CTX *kctx [sizeof(_NIDS)/sizeof(_NIDS[0])] = {NULL};
static EVP_PKEY *params[sizeof(_NIDS)/sizeof(_NIDS[0])] = {NULL};
 
static EVP_PKEY_CTX *pctx[sizeof(_NIDS) / sizeof(_NIDS[0])] = { NULL };
static EVP_PKEY_CTX *kctx[sizeof(_NIDS) / sizeof(_NIDS[0])] = { NULL };
static EVP_PKEY *params[sizeof(_NIDS) / sizeof(_NIDS[0])] = { NULL };
 
int ecc_api_init()
{
int i;
int rc = -1;
for(i=0; i<sizeof(_NIDS)/sizeof(_NIDS[0]); i++){
for (i = 0; i < sizeof(_NIDS) / sizeof(_NIDS[0]); i++){
/* Create the context for generating the parameters */
pctx[i] = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL);
if(pctx[i]){
if(EVP_PKEY_paramgen_init(pctx[i])){
if (pctx[i]){
if (EVP_PKEY_paramgen_init(pctx[i])){
/* Set the paramgen parameters according to the type */
if(EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx[i], _NIDS[i])){
if (EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx[i], _NIDS[i])){
/* Generate parameters */
if (EVP_PKEY_paramgen(pctx[i], &params[i])) {
/* Create context for the key generation */
kctx[i] = EVP_PKEY_CTX_new(params[i], NULL);
if(kctx[i]){
if(EVP_PKEY_keygen_init(kctx[i])){
if (kctx[i]){
if (EVP_PKEY_keygen_init(kctx[i])){
rc = 0;
continue;
}
42,9 → 42,9
}
}
ERR_print_errors_fp(stderr);
if(kctx[i])EVP_PKEY_CTX_free(kctx[i]);kctx[i] = NULL;
if(params[i])EVP_PKEY_free(params[i]);params[i] = NULL;
if(pctx[i])EVP_PKEY_CTX_free(pctx[i]);pctx[i] = NULL;
if (kctx[i])EVP_PKEY_CTX_free(kctx[i]); kctx[i] = NULL;
if (params[i])EVP_PKEY_free(params[i]); params[i] = NULL;
if (pctx[i])EVP_PKEY_CTX_free(pctx[i]); pctx[i] = NULL;
}
return rc;
}
52,22 → 52,52
int ecc_api_done()
{
int i;
for(i=0; i<sizeof(_NIDS)/sizeof(_NIDS[0]); i++){
if(kctx[i])EVP_PKEY_CTX_free(kctx[i]);kctx[i] = NULL;
if(params[i])EVP_PKEY_free(params[i]);params[i] = NULL;
if(pctx[i])EVP_PKEY_CTX_free(pctx[i]);pctx[i] = NULL;
for (i = 0; i < sizeof(_NIDS) / sizeof(_NIDS[0]); i++){
if (kctx[i])EVP_PKEY_CTX_free(kctx[i]); kctx[i] = NULL;
if (params[i])EVP_PKEY_free(params[i]); params[i] = NULL;
if (pctx[i])EVP_PKEY_CTX_free(pctx[i]); pctx[i] = NULL;
}
return 0;
}
 
void * ecc_api_key_gen (ecc_pk_algorithm pk_alg, ecc_sym_algorithm sym_alg)
void * ecc_api_key_gen(ecc_pk_algorithm pk_alg, ecc_sym_algorithm sym_alg)
{
EVP_PKEY * key = NULL;
if(!EVP_PKEY_keygen(kctx[pk_alg], &key)){
if (!EVP_PKEY_keygen(kctx[pk_alg], &key)){
ERR_print_errors_fp(stderr);
}
return (void*)key;
}
 
void * ecc_api_key_init(ecc_pk_algorithm pk_alg, ecc_sym_algorithm sym_alg, const char* pkey)
{
EVP_PKEY * key = NULL;
BIGNUM * bn = BN_new();
if (BN_bin2bn(pkey, 32, bn)){
EC_KEY * eckey = EC_KEY_new_by_curve_name(_NIDS[pk_alg]);
if (eckey){
if (EC_KEY_set_private_key(eckey, bn)){
EC_POINT * point;
EC_GROUP * group;
group = EC_KEY_get0_group(eckey);
point = EC_POINT_new(group);
if (EC_POINT_mul(group, point, bn, NULL, NULL, NULL)){
EC_KEY_set_public_key(eckey, point);
key = EVP_PKEY_new();
EVP_PKEY_set1_EC_KEY(key, eckey);
eckey = NULL;
}
EC_POINT_free(point);
}
if (eckey){
EC_KEY_free(eckey);
}
}
}
BN_free(bn);
return (void*)key;
}
 
void ecc_api_key_free(void* key)
{
EVP_PKEY_free((EVP_PKEY*)key);
/branches/Security/tools/itscertgen
Property changes:
Modified: svn:ignore
## -1 +1,2 ##
mingw32-d
+msvc