Commit 8792d511 authored by Denis Filatov's avatar Denis Filatov
Browse files

bulk AT cert generation

parent f682a912
Loading
Loading
Loading
Loading

certgen/CERT_IUT_C1_AT.xml

deleted100644 → 0
+0 −36
Original line number Original line Diff line number Diff line
<certificate>
	<version>3</version>
	<signer type="digest" name="CERT_IUT_CC_AA"/>
	<subject type="AT" name="">
		<!-- verification_key -->
		<attribute type="verification_key">
			<public_key algorithm="0">
				<ecc_point type="compressed"/>
			</public_key>
		</attribute>
		<!-- encryption_key -->
		<attribute type="encryption_key">
			<public_key sym_alg="0" algorithm="0">
				><ecc_point type="compressed"/>
			</public_key>
		</attribute>
		<!-- assurance_level -->
		<attribute type="assurance_level">
			<assurance level="3"/>
		</attribute>
		<!-- its_aid_ssp_list -->
		<attribute type="its_aid_ssp_list">
			<ssp aid="CAM">01 FF FC</ssp>  <!-- CAM -->
			<ssp aid="DENM">01 FF FF FF</ssp>  <!-- DENM -->
			<ssp aid="GN-MGMT"></ssp> <!--ssp aid="GN-MGMT">00</ssp-->  <!-- GN-MGMT -->
		</attribute>
	</subject>
	<validity>
		<restriction type="time" start="+0d" end="+365d"/>
			<rectangle>
				<location latitude="+10km" longitude="-10km"/>
				<location latitude="+5km" longitude="-5km" />
			</rectangle>
	</validity>
	<signature algorithm="0"/>
</certificate>
+441 −24

File changed.

Preview size limit exceeded, changes collapsed.

+2 −2
Original line number Original line Diff line number Diff line
@@ -29,11 +29,11 @@ HashAlgorithm_t CertificateWholeHashAlgorithm(const EtsiTs103097Certificate_t *
                alg = HashAlgorithm_sha384;
                alg = HashAlgorithm_sha384;
                break;
                break;
            default:
            default:
                if(name) fprintf(stderr, "%s: ERROR: Unknow verification key algorithm\n", name);
                if(name) fprintf(stderr, "%s: ERROR: Unknow verification key algorithm %d\n", name, cert->toBeSigned.verifyKeyIndicator.choice.verificationKey.present);
                return -1;
                return -1;
        }
        }
    } else {
    } else {
        if(name) fprintf(stderr, "%s: ERROR: Unknow certificate type\n", name);
        if(name) fprintf(stderr, "%s: ERROR: Unknow certificate type %d\n", name, (int)cert->type);
        return -1;
        return -1;
    }
    }
    return alg;
    return alg;
+122 −115
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ static const char * _cfgFile = NULL;
static int          _debug = 0;
static int          _debug = 0;
static int          _xer = 0;
static int          _xer = 0;
static int          _view = 0;
static int          _view = 0;
int					_genCount = 1;


EtsiTs103097Certificate_t * _cert = NULL;
EtsiTs103097Certificate_t * _cert = NULL;
EtsiTs103097Certificate_t * _issuer = NULL;
EtsiTs103097Certificate_t * _issuer = NULL;
@@ -69,6 +70,7 @@ static copt_t _options [] = {
	{ "e", "no-generate", COPT_BOOL, (void*)&_no_gen, "Do not generate keys. [generate if necessary by default]" },
	{ "e", "no-generate", COPT_BOOL, (void*)&_no_gen, "Do not generate keys. [generate if necessary by default]" },
	{ "n", "name", COPT_STR, (void*)&_certName, "Certificate name (take from profile by default)" },
	{ "n", "name", COPT_STR, (void*)&_certName, "Certificate name (take from profile by default)" },
	{ "s", "signer", COPT_STR, (void*)&_signerName,   "Signer certificate name [take from profile by default]" },
	{ "s", "signer", COPT_STR, (void*)&_signerName,   "Signer certificate name [take from profile by default]" },
	{ "g", "count", COPT_INT, (void*)&_genCount,      "Generate multiple certificates [generate 1 certificate by default]" },
	{ "D", "debug", COPT_BOOL, (void*)&_debug,        "Dump hashes and other values [false]" },
	{ "D", "debug", COPT_BOOL, (void*)&_debug,        "Dump hashes and other values [false]" },
	{ "v", "view", COPT_BOOL, (void*)&_view,          "View OER certificate [false]" },
	{ "v", "view", COPT_BOOL, (void*)&_view,          "View OER certificate [false]" },
	{ "x", "oxer", COPT_BOOL, (void*)&_xer,           "Decode OER certificate to XER [false]" },
	{ "x", "oxer", COPT_BOOL, (void*)&_xer,           "Decode OER certificate to XER [false]" },
@@ -307,7 +309,7 @@ int main(int argc, char ** argv)
		}
		}
		const char * a = strrchr(argv[0], '/');
		const char * a = strrchr(argv[0], '/');
		if (a == NULL) a = argv[0];
		if (a == NULL) a = argv[0];
		coptions_help(stdout, a, COPT_HELP_NOVALUES, _options, "<profile> [signer]");
		coptions_help(stdout, a, COPT_HELP_NOVALUES, _options, "<xer> [signer] [count]");
		return -1;
		return -1;
	}
	}


@@ -529,10 +531,15 @@ int main(int argc, char ** argv)
		}
		}
	}
	}


	char gSuffix[8] = { 0x00 };
	for (int gi = 1; gi <= _genCount; gi++) {
		if (_genCount > 1) {
			sprintf(gSuffix, ".%03d", gi);
		}
		// generate keys if necessary
		// generate keys if necessary
		// buf = name of private key file
		// buf = name of private key file
		int rc = -1;
		int rc = -1;
	cvstrncpy(buf, CERT_MAX_SIZE, _keyPath, "/", _certName, EXT_VKEY, NULL);
		cvstrncpy(buf, CERT_MAX_SIZE, _keyPath, "/", _certName, gSuffix, EXT_VKEY, NULL);
		switch (cert->toBeSigned.verifyKeyIndicator.present) {
		switch (cert->toBeSigned.verifyKeyIndicator.present) {
		case VerificationKeyIndicator_PR_verificationKey:
		case VerificationKeyIndicator_PR_verificationKey:
			switch (cert->toBeSigned.verifyKeyIndicator.choice.verificationKey.present) {
			switch (cert->toBeSigned.verifyKeyIndicator.choice.verificationKey.present) {
@@ -581,7 +588,7 @@ int main(int argc, char ** argv)
		}
		}
		if (cert->toBeSigned.encryptionKey) {
		if (cert->toBeSigned.encryptionKey) {
			rc = -1;
			rc = -1;
		cvstrncpy(buf, CERT_MAX_SIZE, _keyPath, "/", _certName, EXT_EKEY, NULL);
			cvstrncpy(buf, CERT_MAX_SIZE, _keyPath, "/", _certName, gSuffix, EXT_EKEY, NULL);
			switch (cert->toBeSigned.encryptionKey->publicKey.present) {
			switch (cert->toBeSigned.encryptionKey->publicKey.present) {
			case BasePublicEncryptionKey_PR_NOTHING:
			case BasePublicEncryptionKey_PR_NOTHING:
				cert->toBeSigned.encryptionKey->publicKey.present = BasePublicEncryptionKey_PR_eciesNistP256;
				cert->toBeSigned.encryptionKey->publicKey.present = BasePublicEncryptionKey_PR_eciesNistP256;
@@ -601,7 +608,7 @@ int main(int argc, char ** argv)
			}
			}
		}
		}


	cvstrncpy(buf, CERT_MAX_SIZE, _outPath, "/", _certName, EXT_CERT, NULL);
		cvstrncpy(buf, CERT_MAX_SIZE, _outPath, "/", _certName, gSuffix, EXT_CERT, NULL);
		f = fopen(buf, "wb");
		f = fopen(buf, "wb");
		if (f == NULL) {
		if (f == NULL) {
			perror(buf);
			perror(buf);
@@ -651,7 +658,7 @@ int main(int argc, char ** argv)
			ecc_key_free(rv_eph_key);
			ecc_key_free(rv_eph_key);
			ecc_key_free(rv_req_key);
			ecc_key_free(rv_req_key);
		}
		}

	}
	if (cert) {
	if (cert) {
		ASN_STRUCT_FREE(asn_DEF_EtsiTs103097Certificate, cert);
		ASN_STRUCT_FREE(asn_DEF_EtsiTs103097Certificate, cert);
	}
	}
@@ -705,7 +712,7 @@ static void * gen_or_load_public_key(ecc_curve_id curveType, char * keyPath)
			}    
			}    
			ecc_key_private_save(key, keyPath, _outKeyFormat);
			ecc_key_private_save(key, keyPath, _outKeyFormat);
			strcpy(e_pub, EXT_PUB);
			strcpy(e_pub, EXT_PUB);
			ecc_key_public_save(key, keyPath, _outKeyFormat);
			ecc_key_public_save(key, keyPath, _outKeyFormat, 0);
		} else {
		} else {
			if (_debug){
			if (_debug){
				fprintf(stderr, "DEBUG: use pre-generated key %s\n", keyPath);
				fprintf(stderr, "DEBUG: use pre-generated key %s\n", keyPath);
@@ -780,7 +787,7 @@ static void process_reconstruction_value(void * r_key, void * eph, void * ca, un
		e = cstrcpy(e, EXT_VKEY);
		e = cstrcpy(e, EXT_VKEY);
		ecc_key_private_save(u_key, keyPath, _outKeyFormat);
		ecc_key_private_save(u_key, keyPath, _outKeyFormat);
		strcpy(e, EXT_PUB);
		strcpy(e, EXT_PUB);
		ecc_key_public_save(u_key, keyPath, _outKeyFormat);
		ecc_key_public_save(u_key, keyPath, _outKeyFormat, 0);
		ecc_key_free(u_key);
		ecc_key_free(u_key);
	}
	}
}
}
+65 −844

File changed.

Preview size limit exceeded, changes collapsed.

Loading