Re: [PATCH v2 2/3] ima-evm-utils: Allow manual setting keyid from a cert file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Stefan,

On Tue, May 04, 2021 at 09:04:44AM -0400, Stefan Berger wrote:
> 
> On 5/4/21 12:33 AM, Vitaly Chikunov wrote:
> > Allow user to specify `--keyid @/path/to/cert.pem' to extract keyid from
> > SKID of the certificate file. PEM or DER format is auto-detected.
> > 
> > `--keyid' option is reused instead of adding a new option (like possible
> > `--cert') to signify to the user it's only keyid extraction and nothing
> > more.
> > 
> > Signed-off-by: Vitaly Chikunov <vt@xxxxxxxxxxxx>
> > ---
> >   README                 |  1 +
> >   src/evmctl.c           | 82 +++++++++++++++++++++++++++++++++++++++++++++++---
> >   tests/sign_verify.test |  1 +
> >   3 files changed, 79 insertions(+), 5 deletions(-)
> > 
> > @@ -2567,12 +2571,71 @@ static char *get_password(void)
> > +/* Extract keyid from SKID of the cert. No return on error. */
> > +static unsigned long int extract_keyid(const char *certfile)
> > +{
> > +	uint32_t keyid_raw;
> > +	const ASN1_OCTET_STRING *skid;
> > +	int skid_len;
> > +	X509 *x = NULL;
> > +	int pem;
> > +	FILE *in;
> > +
> > +	if (!(in = fopen(certfile, "r"))) {
> > +		log_err("Cannot open cert file %s: %s\n", certfile,
> > +			strerror(errno));
> > +		exit(1);
> > +	}
> > +	if ((pem = is_encoding_pem(in)))
> 
> 
> I think you should not try to detect PEM by '-----' at the beginning since
> it typically allows other text at the beginning of the file as well, such as
> a text dump of the cert. Instead search for '-----BEGIN CERTIFICATE-----' in
> the whole file or just

> try to read it as PEM first and then fall back to DER decoding if PEM failed.

This is a good idea. I will do it in v3.

Thanks,




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux Kernel]     [Linux Kernel Hardening]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux