linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vitaly Chikunov <vt@altlinux.org>
To: Mimi Zohar <zohar@linux.ibm.com>
Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>,
	Dmitry Kasatkin <dmitry.kasatkin@gmail.com>,
	linux-integrity@vger.kernel.org
Subject: Re: [PATCH v7 2/3] ima-evm-utils: Allow manual setting keyid from a cert file
Date: Mon, 5 Jul 2021 23:50:08 +0300	[thread overview]
Message-ID: <20210705205008.olof3kyfh32atgjc@altlinux.org> (raw)
In-Reply-To: <e80ebe2bfb2e5bd9bf83153789ad9bbcfe5cf916.camel@linux.ibm.com>

Mimi,

On Mon, Jul 05, 2021 at 03:59:02PM -0400, Mimi Zohar wrote:
> On Thu, 2021-07-01 at 04:13 +0300, Vitaly Chikunov wrote:
> 
> > @@ -2805,6 +2811,14 @@ int main(int argc, char *argv[])
> >  			}
> >  			imaevm_params.keyid = keyid;
> >  			break;
> > +		case 145:
> > +			keyid = imaevm_read_keyid(optarg);
> > +			if (keyid == 0) {
> 
> The function comment indicates zero is returned on error, which is
> normally true, but -1 is returned to indicate reading the cert failed. 

Ah, bug.

Thanks!

> 
> > +				log_err("Error reading keyid.\n");
> > +				exit(1);
> > +			}
> > +			imaevm_params.keyid = keyid;
> 
> As a result, imaevm_params.keyid is set to -1, which the "--keyid="
> case would detect, but isn't detected here.
> 
> > +			break;
> >  		case '?':
> >  			exit(1);
> >  			break;
> > diff --git a/src/imaevm.h b/src/imaevm.h
> > index fe244f1..491f136 100644
> > --- a/src/imaevm.h
> > +++ b/src/imaevm.h
> > 
> > +/**
> 
> kernel doc?  :)
> 
> > + * imaevm_read_keyid() - Read 32-bit keyid from the cert file
> > + * @certfile:	File with certificate in PEM or DER form.
> > + *
> > + * Try to read keyid from Subject Key Identifier (SKID) of x509 certificate.
> > + * Autodetect if cert is in PEM (tried first) or DER encoding.
> > + *
> > + * Return: 0 on error, logged error message;
> > + *         32-bit keyid in host order.
> 
> As mentioned above, -1 could be returned.
> 
> > + */
> > +uint32_t imaevm_read_keyid(const char *certfile)
> > +{
> > +	uint32_t keyid_be = 0;
> > +	X509 *x;
> > +
> > +	/* true: to load in DER form too. */
> > +	if (!(x = read_cert(certfile, true)))
> > +		return -1;
> > +	extract_keyid(&keyid_be, x, certfile);
> > +	/* On error keyid_be will not be set, returning 0. */
> 
> Ok
> 
> thanks,
> 
> Mimi
> 
> > +	X509_free(x);
> > +	return ntohl(keyid_be);
> > +}
> > +
> >  static EVP_PKEY *read_priv_pkey(const char *keyfile, const char *keypass)
> >  {
> >  	FILE *fp;

  reply	other threads:[~2021-07-05 20:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-01  1:13 [PATCH v7 0/3] ima-evm-utils: Add --keyid option Vitaly Chikunov
2021-07-01  1:13 ` [PATCH v7 1/3] ima-evm-utils: Allow manual setting keyid for signing Vitaly Chikunov
2021-07-01  1:13 ` [PATCH v7 2/3] ima-evm-utils: Allow manual setting keyid from a cert file Vitaly Chikunov
2021-07-05 19:59   ` Mimi Zohar
2021-07-05 20:50     ` Vitaly Chikunov [this message]
2021-07-01  1:13 ` [PATCH v7 3/3] ima-evm-utils: Read keyid from the cert appended to the key file Vitaly Chikunov
2021-07-05 20:04   ` Mimi Zohar
2021-07-05 21:15     ` Vitaly Chikunov
2021-07-06 16:23 ` [PATCH v7 0/3] ima-evm-utils: Add --keyid option Mimi Zohar
2021-07-06 21:13   ` Vitaly Chikunov
2021-07-08 15:37     ` Mimi Zohar
2021-07-08 15:46       ` Vitaly Chikunov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210705205008.olof3kyfh32atgjc@altlinux.org \
    --to=vt@altlinux.org \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=linux-integrity@vger.kernel.org \
    --cc=zohar@linux.ibm.com \
    --cc=zohar@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).