Skip to content
GitLab
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
ITS - Intelligent Transport Systems
ItsCertGen
Compare revisions
5ddd1f4cc7f1ecbed4a77d51d6b295f8f4c67e93...00864af03a09f56cacd592e014a3bea246b79907
Commits (2)
add id=>filename mode
· cd319b09
ASN.1 Documenter
authored
Jun 13, 2022
cd319b09
remove commented out code
· 00864af0
ASN.1 Documenter
authored
Jun 13, 2022
00864af0
Hide whitespace changes
Inline
Side-by-side
certgen/certidx.c
View file @
00864af0
...
@@ -33,12 +33,14 @@ int glob_pattern_p (const char *, int);
...
@@ -33,12 +33,14 @@ int glob_pattern_p (const char *, int);
static
const
char
*
_outPath
=
"-"
;
static
const
char
*
_outPath
=
"-"
;
static
int
_canonicalize
=
1
;
static
int
_canonicalize
=
1
;
static
int
_fnames
=
0
;
static
FILE
*
_out
;
static
FILE
*
_out
;
static
copt_t
_options
[]
=
{
static
copt_t
_options
[]
=
{
{
"h?"
,
"help"
,
COPT_HELP
,
NULL
,
"Print this help page"
},
{
"h?"
,
"help"
,
COPT_HELP
,
NULL
,
"Print this help page"
},
{
"o"
,
"out"
,
COPT_STR
,
(
void
*
)
&
_outPath
,
"Output path [stdout by default]"
},
{
"o"
,
"out"
,
COPT_STR
,
(
void
*
)
&
_outPath
,
"Output path [stdout by default]"
},
{
"c"
,
"no-canonicalize"
,
COPT_BOOLI
,
(
void
*
)
&
_canonicalize
,
"No canonicalize"
},
{
"C"
,
"no-canonicalize"
,
COPT_BOOLI
,
(
void
*
)
&
_canonicalize
,
"No canonicalize"
},
{
"n"
,
"fnames"
,
COPT_BOOL
,
(
void
*
)
&
_fnames
,
"Use file names instead of IDs"
},
{
NULL
,
NULL
,
COPT_END
,
NULL
,
NULL
}
{
NULL
,
NULL
,
COPT_END
,
NULL
,
NULL
}
};
};
...
@@ -54,41 +56,7 @@ static ecc_curve_id _pk_type_to_curveid[] = {
...
@@ -54,41 +56,7 @@ static ecc_curve_id _pk_type_to_curveid[] = {
ecies_brainpoolp256r
,
//Signature_PR_ecdsaBrainpoolP256r1Signature,
ecies_brainpoolp256r
,
//Signature_PR_ecdsaBrainpoolP256r1Signature,
ecies_brainpoolp384r
//Signature_PR_ecdsaBrainpoolP384r1Signature
ecies_brainpoolp384r
//Signature_PR_ecdsaBrainpoolP384r1Signature
};
};
/*
static const char * _pk_curve_names[] = {
"nistp256",
"brainpoolp256r",
"brainpoolp384r",
"unsupported"
};
static ecc_curve_id _pk_type_to_hashid[] = {
0,
sha_256, //Signature_PR_ecdsaNistP256Signature,
sha_256, //Signature_PR_ecdsaBrainpoolP256r1Signature,
sha_384 //Signature_PR_ecdsaBrainpoolP384r1Signature
};
static size_t _pk_type_to_hashsize[] = {
0,
sha256_hash_size, //Signature_PR_ecdsaNistP256Signature,
sha256_hash_size, //Signature_PR_ecdsaBrainpoolP256r1Signature,
sha384_hash_size //Signature_PR_ecdsaBrainpoolP384r1Signature
};
static asn_dec_rval_t Signature_oer_decoder(const struct asn_codec_ctx_s *opt_codec_ctx,
const struct asn_TYPE_descriptor_s *td, const asn_oer_constraints_t *constraints,
void **struct_ptr, const void *buf_ptr, size_t size);
static asn_dec_rval_t EcdsaSignature_oer_decoder(const struct asn_codec_ctx_s *opt_codec_ctx,
const struct asn_TYPE_descriptor_s *td, const asn_oer_constraints_t *constraints,
void **struct_ptr, const void *buf_ptr, size_t size);
static asn_dec_rval_t EccCurvePoint_oer_decoder(const struct asn_codec_ctx_s *opt_codec_ctx,
const struct asn_TYPE_descriptor_s *td, const asn_oer_constraints_t *constraints,
void **struct_ptr, const void *buf_ptr, size_t size);
static asn_dec_rval_t PublicKey_oer_decoder(const struct asn_codec_ctx_s* opt_codec_ctx,
const struct asn_TYPE_descriptor_s* td, const asn_oer_constraints_t* constraints,
void** struct_ptr, const void* buf_ptr, size_t size);
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
//parse options
//parse options
...
@@ -117,31 +85,6 @@ int main(int argc, char ** argv)
...
@@ -117,31 +85,6 @@ int main(int argc, char ** argv)
}
else
{
}
else
{
_out
=
stdout
;
_out
=
stdout
;
}
}
/*
static asn_TYPE_operation_t signatureOps, ecdsaSignatureOps, eccCurvePointOps,
verificationKeyOps, encryptionKeyOps;
signatureOps = *asn_DEF_Signature.op;
asn_DEF_Signature.op = &signatureOps;
signatureOps.oer_decoder = Signature_oer_decoder;
ecdsaSignatureOps = *asn_DEF_EcdsaP256Signature.op;
asn_DEF_EcdsaP256Signature.op = &ecdsaSignatureOps;
asn_DEF_EcdsaP384Signature.op = &ecdsaSignatureOps;
ecdsaSignatureOps.oer_decoder = EcdsaSignature_oer_decoder;
eccCurvePointOps = *asn_DEF_EccP256CurvePoint.op;
asn_DEF_EccP256CurvePoint.op = &eccCurvePointOps;
asn_DEF_EccP384CurvePoint.op = &eccCurvePointOps;
eccCurvePointOps.oer_decoder = EccCurvePoint_oer_decoder;
verificationKeyOps = *asn_DEF_PublicVerificationKey.op;
asn_DEF_PublicVerificationKey.op = &verificationKeyOps;
verificationKeyOps.oer_decoder = PublicKey_oer_decoder;
encryptionKeyOps = *asn_DEF_BasePublicEncryptionKey.op;
asn_DEF_BasePublicEncryptionKey.op = &encryptionKeyOps;
encryptionKeyOps.oer_decoder = PublicKey_oer_decoder;
*/
char
*
buf
=
malloc
(
CERT_MAX_SIZE
);
char
*
buf
=
malloc
(
CERT_MAX_SIZE
);
char
*
ebuf
;
char
*
ebuf
;
...
@@ -150,7 +93,7 @@ int main(int argc, char ** argv)
...
@@ -150,7 +93,7 @@ int main(int argc, char ** argv)
ebuf
=
cstrnload
(
buf
,
CERT_MAX_SIZE
,
argv
[
argi
]);
ebuf
=
cstrnload
(
buf
,
CERT_MAX_SIZE
,
argv
[
argi
]);
if
(
ebuf
&&
(
ebuf
-
buf
)
>
0
){
if
(
ebuf
&&
(
ebuf
-
buf
)
>
0
){
const
pchar_t
*
fname
=
cstrlastpathelement
(
argv
[
argi
]);
const
pchar_t
*
fname
=
cstrlastpathelement
(
argv
[
argi
]);
*
cstrpathextension
(
fname
)
=
0
;
if
(
!
_fnames
)
*
cstrpathextension
(
fname
)
=
0
;
process_cert
(
fname
,
buf
,
ebuf
);
process_cert
(
fname
,
buf
,
ebuf
);
}
else
{
}
else
{
// check if it is a mask
// check if it is a mask
...
@@ -161,7 +104,7 @@ int main(int argc, char ** argv)
...
@@ -161,7 +104,7 @@ int main(int argc, char ** argv)
ebuf
=
cstrnload
(
buf
,
CERT_MAX_SIZE
,
gl
.
gl_pathv
[
i
]);
ebuf
=
cstrnload
(
buf
,
CERT_MAX_SIZE
,
gl
.
gl_pathv
[
i
]);
if
(
ebuf
&&
(
ebuf
-
buf
)
>
0
)
{
if
(
ebuf
&&
(
ebuf
-
buf
)
>
0
)
{
const
pchar_t
*
fname
=
cstrlastpathelement
(
gl
.
gl_pathv
[
i
]);
const
pchar_t
*
fname
=
cstrlastpathelement
(
gl
.
gl_pathv
[
i
]);
*
cstrpathextension
(
fname
)
=
0
;
if
(
!
_fnames
)
*
cstrpathextension
(
fname
)
=
0
;
process_cert
(
fname
,
buf
,
ebuf
);
process_cert
(
fname
,
buf
,
ebuf
);
}
}
}
}
...
@@ -179,7 +122,7 @@ int main(int argc, char ** argv)
...
@@ -179,7 +122,7 @@ int main(int argc, char ** argv)
cstrcpy
(
fname
,
fd
.
cFileName
);
cstrcpy
(
fname
,
fd
.
cFileName
);
ebuf
=
cstrnload
(
buf
,
CERT_MAX_SIZE
,
path
);
ebuf
=
cstrnload
(
buf
,
CERT_MAX_SIZE
,
path
);
if
(
ebuf
&&
(
ebuf
-
buf
)
>
0
){
if
(
ebuf
&&
(
ebuf
-
buf
)
>
0
){
*
cstrpathextension
(
fname
)
=
0
;
if
(
!
_fnames
)
*
cstrpathextension
(
fname
)
=
0
;
process_cert
(
fname
,
buf
,
ebuf
);
process_cert
(
fname
,
buf
,
ebuf
);
}
}
}
while
(
FindNextFile
(
h
,
&
fd
));
}
while
(
FindNextFile
(
h
,
&
fd
));
...
@@ -271,7 +214,7 @@ int process_cert(const pchar_t * name, uint8_t * buf, const uint8_t * ebuf)
...
@@ -271,7 +214,7 @@ int process_cert(const pchar_t * name, uint8_t * buf, const uint8_t * ebuf)
uint8_t
hash
[
256
];
uint8_t
hash
[
256
];
uint8_t
*
digest
;
uint8_t
*
digest
;
switch
(
halg
){
switch
(
halg
)
{
case
HashAlgorithm_sha256
:
case
HashAlgorithm_sha256
:
sha256_calculate
(
&
hash
[
0
],
buf
,
rc_d
.
consumed
);
sha256_calculate
(
&
hash
[
0
],
buf
,
rc_d
.
consumed
);
digest
=
&
hash
[
32
-
8
];
digest
=
&
hash
[
32
-
8
];
...
@@ -288,64 +231,3 @@ int process_cert(const pchar_t * name, uint8_t * buf, const uint8_t * ebuf)
...
@@ -288,64 +231,3 @@ int process_cert(const pchar_t * name, uint8_t * buf, const uint8_t * ebuf)
fprintf
(
_out
,
"%s %s
\n
"
,
hex
,
name
);
fprintf
(
_out
,
"%s %s
\n
"
,
hex
,
name
);
return
0
;
return
0
;
}
}
/*
static asn_dec_rval_t Signature_oer_decoder(const struct asn_codec_ctx_s *opt_codec_ctx,
const struct asn_TYPE_descriptor_s *td, const asn_oer_constraints_t *constraints,
void **struct_ptr, const void *buf_ptr, size_t size)
{
its_asn_codec_ctx_t * ctx = (its_asn_codec_ctx_t *)opt_codec_ctx;
ctx->curve = (*((uint8_t*) buf_ptr)) - 0x80;
return asn_OP_CHOICE.oer_decoder(opt_codec_ctx, td, constraints, struct_ptr, buf_ptr, size);
}
static asn_dec_rval_t PublicKey_oer_decoder(const struct asn_codec_ctx_s* opt_codec_ctx,
const struct asn_TYPE_descriptor_s* td, const asn_oer_constraints_t* constraints,
void** struct_ptr, const void* buf_ptr, size_t size)
{
its_asn_codec_ctx_t* ctx = (its_asn_codec_ctx_t*)opt_codec_ctx;
ctx->curve = (*((uint8_t*)buf_ptr)) - 0x80;
return asn_OP_CHOICE.oer_decoder(opt_codec_ctx, td, constraints, struct_ptr, buf_ptr, size);
}
static asn_dec_rval_t EcdsaSignature_oer_decoder(const struct asn_codec_ctx_s *opt_codec_ctx,
const struct asn_TYPE_descriptor_s *td, const asn_oer_constraints_t *constraints,
void **struct_ptr, const void *buf_ptr, size_t size)
{
uint8_t * b = (uint8_t*) buf_ptr;
asn_dec_rval_t rc = asn_OP_SEQUENCE.oer_decoder(opt_codec_ctx, td, constraints, struct_ptr, buf_ptr, size);
// set to x_only
*b = 0x80;
return rc;
}
static asn_dec_rval_t EccCurvePoint_oer_decoder(const struct asn_codec_ctx_s *opt_codec_ctx,
const struct asn_TYPE_descriptor_s *td, const asn_oer_constraints_t *constraints,
void **struct_ptr, const void *buf_ptr, size_t size)
{
uint8_t * b = (uint8_t*) buf_ptr;
asn_dec_rval_t rc = asn_OP_CHOICE.oer_decoder(opt_codec_ctx, td, constraints, struct_ptr, buf_ptr, size);
EccP256CurvePoint_t * p = (EccP256CurvePoint_t*)*struct_ptr;
its_asn_codec_ctx_t * ctx = (its_asn_codec_ctx_t *)opt_codec_ctx;
size_t psize = (td == &asn_DEF_EccP256CurvePoint) ? 32 : 48;
if(p->present == EccP256CurvePoint_PR_uncompressedP256 || p->present == EccP256CurvePoint_PR_x_only){
void * key = ecc_key_public_set(ctx->curve, p->present-1, p->choice.uncompressedP256.x.buf, p->choice.uncompressedP256.y.buf);
if(!key){
rc.code = RC_FAIL;
}else{
int sign;
char x[48], y[48];
ecc_key_public(key, &x[0], &y[0], &sign);
*b = 0x81 + (sign?1:0);
ecc_key_free(key);
if(p->present == EccP256CurvePoint_PR_uncompressedP256){
// move the rest of the buffer
ctx->move[ctx->mcount].ptr = b + rc.consumed;
ctx->move[ctx->mcount].shift = psize;
ctx->mcount++;
}
}
}
return rc;
}
*/
\ No newline at end of file