Commit 8cac6a3f authored by filatov's avatar filatov
Browse files

fix signer hash calculation

add asncodec files
parent a34de1d4
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ bins = asn1certgen
sources       := asn1certgen.c ecc_openssl.c
sources-WIN32 := applink.c
packages      += cshared openssl
predirs       := asncodec
includes      += asncodec
itsLib        := asncodec/libSecItsAsn.a
libs          += $(itsLib)
libs          += $(outdir)/libItsCertAsn.a
include ../common.mk
+41 −6
Original line number Diff line number Diff line
@@ -23,14 +23,25 @@ static const char * _keyPath = NULL;
static int          _force = 0;
static const char * _cfgFile = NULL;

static const char _sha256_emptyString[] = {
	0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24,
	0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55
};

static const char _sha384_emptyString[] = {
	0x38, 0xb0, 0x60, 0xa7, 0x51, 0xac, 0x96, 0x38, 0x4c, 0xd9, 0x32, 0x7e, 0xb1, 0xb1, 0xe3, 0x6a,
	0x21, 0xfd, 0xb7, 0x11, 0x14, 0xbe, 0x07, 0x43, 0x4c, 0x0c, 0xc7, 0xbf, 0x63, 0xf6, 0xe1, 0xda,
	0x27, 0x4e, 0xde, 0xbf, 0xe7, 0x6f, 0x65, 0xfb, 0xd5, 0x1a, 0xd2, 0xf1, 0x48, 0x98, 0xb9, 0x5b
};

EtsiTs103097Certificate_t * _cert = NULL;
EtsiTs103097Certificate_t * _issuer = NULL;

char   _tbsHash[256]; // has space for issuer hash
char    _tbsHash[512]; // has space for issuer hash + signer hash
int     _tbsHashLength = 0;

char   _signerHash[256]; // has space for issuer hash
char    _signerHashBuf[256]; // has space for issuer hash
char*  _signerHash = &_signerHashBuf[0];
int    _signerHashLength = 0;

static const char * const _key_formats[] = {
@@ -156,7 +167,7 @@ static asn_enc_rval_t Signature_oer_encoder(const asn_TYPE_descriptor_t *td,
			char h[48];
			int hl = 0;
			// calculate joint hash
			memcpy(_tbsHash, _signerHash, _signerHashLength);
			memcpy(_tbsHash+_tbsHashLength, _signerHash, _signerHashLength);
			switch (hashId)
			{
			case sha_256:
@@ -242,6 +253,7 @@ int main(int argc, char ** argv)
	tbsOps.oer_encoder = ToBeSignedCertificate_oer_encoder;
	signatureOps.oer_encoder = Signature_oer_encoder;

	PublicVerificationKey_PR hashType = PublicVerificationKey_PR_NOTHING;

	rc_d = asn_decode(NULL, ATS_BASIC_XER, &asn_DEF_EtsiTs103097Certificate, (void**)&cert, buf, ebuf - buf);
	if (rc_d.code != RC_OK){
@@ -255,8 +267,6 @@ int main(int argc, char ** argv)
		return -1;
	}
	if (_signerName){
		PublicVerificationKey_PR hashType = PublicVerificationKey_PR_NOTHING;

		cvstrncpy(buf, CERT_MAX_SIZE, _searchPath, "/", _signerName, ".oer", NULL);
		ebuf = cstrnload(buf, CERT_MAX_SIZE, buf);
		if (ebuf == NULL){
@@ -300,6 +310,31 @@ int main(int argc, char ** argv)
		if (signer){
			ASN_STRUCT_FREE(asn_DEF_EtsiTs103097Certificate, signer);
		}
	} else  {
		// self-signed
		// use hash(empty string)
		switch (cert->toBeSigned.verifyKeyIndicator.present){
		case VerificationKeyIndicator_PR_verificationKey:
			hashType = cert->toBeSigned.verifyKeyIndicator.choice.verificationKey.present;
			break;
		case VerificationKeyIndicator_PR_reconstructionValue:
			hashType = PublicVerificationKey_PR_ecdsaNistP256;
			break;
		}
		switch (hashType) {
		case PublicVerificationKey_PR_ecdsaBrainpoolP256r1:
		case PublicVerificationKey_PR_ecdsaNistP256:
			_signerHash = &_sha256_emptyString[0];
			_signerHashLength = sha256_hash_size;
			break;
		case PublicVerificationKey_PR_ecdsaBrainpoolP384r1:
			_signerHash = &_sha384_emptyString[0];
			_signerHashLength = sha384_hash_size;
			break;
		default:
			fprintf(stderr, "Unknown verification key curve type\n");
			return -1;
		}
	}

	// generate keys if necessary
+60 −0
Original line number Diff line number Diff line
/*
 * Generated by asn1c-0.9.29 (http://lionet.info/asn1c)
 * From ASN.1 module "EtsiTs102941TrustLists"
 * 	found in "../asn1/EtsiTs102941/EtsiTs102941TrustLists.asn"
 * 	`asn1c -S ../../asn1c/skeletons -fcompound-names -no-gen-PER -gen-autotools -pdu=EtsiTs103097Data -pdu=EnrolmentRequestMessage -pdu=EnrolmentResponseMessage -pdu=AuthorizationRequestMessage -pdu=AuthorizationRequestMessageWithPop -pdu=AuthorizationResponseMessage -pdu=CertificateRevocationListMessage -pdu=TlmCertificateTrustListMessage -pdu=RcaCertificateTrustListMessage -pdu=AuthorizationValidationRequestMessage -pdu=AuthorizationValidationResponseMessage -pdu=CaCertificateRequestMessage`
 */

#include "AaEntry.h"

asn_TYPE_member_t asn_MBR_AaEntry_1[] = {
	{ ATF_NOFLAGS, 0, offsetof(struct AaEntry, aaCertificate),
		(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
		-1,	/* IMPLICIT tag at current level */
		&asn_DEF_EtsiTs103097Certificate,
		0,
		{ 0, 0, 0 },
		0, 0, /* No default value */
		"aaCertificate"
		},
	{ ATF_NOFLAGS, 0, offsetof(struct AaEntry, accessPoint),
		(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
		-1,	/* IMPLICIT tag at current level */
		&asn_DEF_Url,
		0,
		{ 0, 0, 0 },
		0, 0, /* No default value */
		"accessPoint"
		},
};
static const ber_tlv_tag_t asn_DEF_AaEntry_tags_1[] = {
	(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static const asn_TYPE_tag2member_t asn_MAP_AaEntry_tag2el_1[] = {
    { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* aaCertificate */
    { (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 } /* accessPoint */
};
asn_SEQUENCE_specifics_t asn_SPC_AaEntry_specs_1 = {
	sizeof(struct AaEntry),
	offsetof(struct AaEntry, _asn_ctx),
	asn_MAP_AaEntry_tag2el_1,
	2,	/* Count of tags in the map */
	0, 0, 0,	/* Optional elements (not needed) */
	-1,	/* First extension addition */
};
asn_TYPE_descriptor_t asn_DEF_AaEntry = {
	"AaEntry",
	"AaEntry",
	&asn_OP_SEQUENCE,
	asn_DEF_AaEntry_tags_1,
	sizeof(asn_DEF_AaEntry_tags_1)
		/sizeof(asn_DEF_AaEntry_tags_1[0]), /* 1 */
	asn_DEF_AaEntry_tags_1,	/* Same as above */
	sizeof(asn_DEF_AaEntry_tags_1)
		/sizeof(asn_DEF_AaEntry_tags_1[0]), /* 1 */
	{ 0, 0, SEQUENCE_constraint },
	asn_MBR_AaEntry_1,
	2,	/* Elements count */
	&asn_SPC_AaEntry_specs_1	/* Additional specs */
};
+42 −0
Original line number Diff line number Diff line
/*
 * Generated by asn1c-0.9.29 (http://lionet.info/asn1c)
 * From ASN.1 module "EtsiTs102941TrustLists"
 * 	found in "../asn1/EtsiTs102941/EtsiTs102941TrustLists.asn"
 * 	`asn1c -S ../../asn1c/skeletons -fcompound-names -no-gen-PER -gen-autotools -pdu=EtsiTs103097Data -pdu=EnrolmentRequestMessage -pdu=EnrolmentResponseMessage -pdu=AuthorizationRequestMessage -pdu=AuthorizationRequestMessageWithPop -pdu=AuthorizationResponseMessage -pdu=CertificateRevocationListMessage -pdu=TlmCertificateTrustListMessage -pdu=RcaCertificateTrustListMessage -pdu=AuthorizationValidationRequestMessage -pdu=AuthorizationValidationResponseMessage -pdu=CaCertificateRequestMessage`
 */

#ifndef	_AaEntry_H_
#define	_AaEntry_H_


#include <asn_application.h>

/* Including external dependencies */
#include "EtsiTs103097Certificate.h"
#include "Url.h"
#include <constr_SEQUENCE.h>

#ifdef __cplusplus
extern "C" {
#endif

/* AaEntry */
typedef struct AaEntry {
	EtsiTs103097Certificate_t	 aaCertificate;
	Url_t	 accessPoint;
	
	/* Context for parsing across buffer boundaries */
	asn_struct_ctx_t _asn_ctx;
} AaEntry_t;

/* Implementation */
extern asn_TYPE_descriptor_t asn_DEF_AaEntry;
extern asn_SEQUENCE_specifics_t asn_SPC_AaEntry_specs_1;
extern asn_TYPE_member_t asn_MBR_AaEntry_1[2];

#ifdef __cplusplus
}
#endif

#endif	/* _AaEntry_H_ */
#include <asn_internal.h>
+89 −0
Original line number Diff line number Diff line
/*
 * Generated by asn1c-0.9.29 (http://lionet.info/asn1c)
 * From ASN.1 module "IEEE1609dot2"
 * 	found in "../asn1/1609Dot2-ASN1/asn1c/IEEE1609dot2.asn"
 * 	`asn1c -S ../../asn1c/skeletons -fcompound-names -no-gen-PER -gen-autotools -pdu=EtsiTs103097Data -pdu=EnrolmentRequestMessage -pdu=EnrolmentResponseMessage -pdu=AuthorizationRequestMessage -pdu=AuthorizationRequestMessageWithPop -pdu=AuthorizationResponseMessage -pdu=CertificateRevocationListMessage -pdu=TlmCertificateTrustListMessage -pdu=RcaCertificateTrustListMessage -pdu=AuthorizationValidationRequestMessage -pdu=AuthorizationValidationResponseMessage -pdu=CaCertificateRequestMessage`
 */

#include "AesCcmCiphertext.h"

static int
memb_nonce_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr,
			asn_app_constraint_failed_f *ctfailcb, void *app_key) {
	const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
	size_t size;
	
	if(!sptr) {
		ASN__CTFAIL(app_key, td, sptr,
			"%s: value not given (%s:%d)",
			td->name, __FILE__, __LINE__);
		return -1;
	}
	
	size = st->size;
	
	if((size == 12)) {
		/* Constraint check succeeded */
		return 0;
	} else {
		ASN__CTFAIL(app_key, td, sptr,
			"%s: constraint failed (%s:%d)",
			td->name, __FILE__, __LINE__);
		return -1;
	}
}

static asn_oer_constraints_t asn_OER_memb_nonce_constr_2 CC_NOTUSED = {
	{ 0, 0 },
	12	/* (SIZE(12..12)) */};
asn_TYPE_member_t asn_MBR_AesCcmCiphertext_1[] = {
	{ ATF_NOFLAGS, 0, offsetof(struct AesCcmCiphertext, nonce),
		(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
		-1,	/* IMPLICIT tag at current level */
		&asn_DEF_OCTET_STRING,
		0,
		{ &asn_OER_memb_nonce_constr_2, 0,  memb_nonce_constraint_1 },
		0, 0, /* No default value */
		"nonce"
		},
	{ ATF_NOFLAGS, 0, offsetof(struct AesCcmCiphertext, ccmCiphertext),
		(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
		-1,	/* IMPLICIT tag at current level */
		&asn_DEF_Opaque,
		0,
		{ 0, 0, 0 },
		0, 0, /* No default value */
		"ccmCiphertext"
		},
};
static const ber_tlv_tag_t asn_DEF_AesCcmCiphertext_tags_1[] = {
	(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static const asn_TYPE_tag2member_t asn_MAP_AesCcmCiphertext_tag2el_1[] = {
    { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* nonce */
    { (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 } /* ccmCiphertext */
};
asn_SEQUENCE_specifics_t asn_SPC_AesCcmCiphertext_specs_1 = {
	sizeof(struct AesCcmCiphertext),
	offsetof(struct AesCcmCiphertext, _asn_ctx),
	asn_MAP_AesCcmCiphertext_tag2el_1,
	2,	/* Count of tags in the map */
	0, 0, 0,	/* Optional elements (not needed) */
	-1,	/* First extension addition */
};
asn_TYPE_descriptor_t asn_DEF_AesCcmCiphertext = {
	"AesCcmCiphertext",
	"AesCcmCiphertext",
	&asn_OP_SEQUENCE,
	asn_DEF_AesCcmCiphertext_tags_1,
	sizeof(asn_DEF_AesCcmCiphertext_tags_1)
		/sizeof(asn_DEF_AesCcmCiphertext_tags_1[0]), /* 1 */
	asn_DEF_AesCcmCiphertext_tags_1,	/* Same as above */
	sizeof(asn_DEF_AesCcmCiphertext_tags_1)
		/sizeof(asn_DEF_AesCcmCiphertext_tags_1[0]), /* 1 */
	{ 0, 0, SEQUENCE_constraint },
	asn_MBR_AesCcmCiphertext_1,
	2,	/* Elements count */
	&asn_SPC_AesCcmCiphertext_specs_1	/* Additional specs */
};
Loading