All of lore.kernel.org
 help / color / mirror / Atom feed
* [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms
@ 2022-04-28 16:33 Sievert, James
  0 siblings, 0 replies; 13+ messages in thread
From: Sievert, James @ 2022-04-28 16:33 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 830 bytes --]

> Could you please build tpm2-openssl with "./configure --enable-debug"?

Here ya go:

$ openssl cms -encrypt -provider tpm2 -provider default -in file.txt -recip signer.pem -aes128
PROVIDER INIT
RAND NEW
RAND NEW
RAND GET_CTX_PARAMS [ max_request ]
RAND GENERATE
EC NEW
EC IMPORT [ point-format encoding group pub priv point-format group-check use-cofactor-flag ]
KEYEXCH NEW
KEYEXCH INIT
RAND NEW
RAND GET_CTX_PARAMS [ max_request ]
RAND GENERATE
RAND GET_CTX_PARAMS [ max_request ]
RAND GENERATE
400CF680FA7F0000:error:17000074:CMS routines:cms_EnvelopedData_Encryption_init_bio:error setting recipientinfo:../crypto/cms/cms_env.c:1142:
400CF680FA7F0000:error:17000068:CMS routines:CMS_final:cms lib:../crypto/cms/cms_smime.c:881:
KEYEXCH FREE
EC FREE
RAND FREE
RAND FREE
RAND FREE
PROVIDER TEARDOWN

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms
@ 2022-04-28 17:39 Petr Gotthard
  0 siblings, 0 replies; 13+ messages in thread
From: Petr Gotthard @ 2022-04-28 17:39 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 1357 bytes --]

Thanks. The issue is related to the KDF parameters. The CMS wants to get/set a number of KDF related parameters, which are not (yet) supported by the tpm2-provider. I will try to fix this in the coming days.

Petr

______________________________________________________________
> Od: "Sievert, James" <james.sievert(a)bsci.com>
> Komu: "tpm2(a)lists.01.org" <tpm2(a)lists.01.org>
> Datum: 28.04.2022 18:34
> Předmět: [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms
>
>> Could you please build tpm2-openssl with "./configure --enable-debug"?
>
>Here ya go:
>
>$ openssl cms -encrypt -provider tpm2 -provider default -in file.txt -recip signer.pem -aes128
>PROVIDER INIT
>RAND NEW
>RAND NEW
>RAND GET_CTX_PARAMS [ max_request ]
>RAND GENERATE
>EC NEW
>EC IMPORT [ point-format encoding group pub priv point-format group-check use-cofactor-flag ]
>KEYEXCH NEW
>KEYEXCH INIT
>RAND NEW
>RAND GET_CTX_PARAMS [ max_request ]
>RAND GENERATE
>RAND GET_CTX_PARAMS [ max_request ]
>RAND GENERATE
>400CF680FA7F0000:error:17000074:CMS routines:cms_EnvelopedData_Encryption_init_bio:error setting recipientinfo:../crypto/cms/cms_env.c:1142:
>400CF680FA7F0000:error:17000068:CMS routines:CMS_final:cms lib:../crypto/cms/cms_smime.c:881:
>KEYEXCH FREE
>EC FREE
>RAND FREE
>RAND FREE
>RAND FREE
>PROVIDER TEARDOWN

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms
@ 2022-04-28 16:26 Petr Gotthard
  0 siblings, 0 replies; 13+ messages in thread
From: Petr Gotthard @ 2022-04-28 16:26 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 3328 bytes --]

I have no idea, unfortunately. I don't think the tpm was invoked, because there is no error message from the tpm libraries. It feels more like if openssl had not the right fields populated.

Could you please build tpm2-openssl with "./configure --enable-debug"? The openssl commands will then print tracing information about TPM functions being called. This could give us some indication on what could be wrong.

Another idea: Could you send me (privately) the "signer.pem"? If it fails on my machine as well it will be easier to track and fix.


Petr
______________________________________________________________
> Od: "Sievert, James" <james.sievert(a)bsci.com>
> Komu: "tpm2(a)lists.01.org" <tpm2(a)lists.01.org>
> Datum: 28.04.2022 17:46
> Předmět: [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms
>
>Actually here the error is different:
>
>bsci(a)ip-10-132-42-225:~$ openssl cms -encrypt -provider tpm2 -provider default -in file.txt -recip handle:0x01000013 -aes128
>409CFA23377F0000:error:17000074:CMS routines:cms_EnvelopedData_Encryption_init_bio:error setting recipientinfo:../crypto/cms/cms_env.c:1142:
>409CFA23377F0000:error:17000068:CMS routines:CMS_final:cms lib:../crypto/cms/cms_smime.c:881:
>
>I was thinking that perhaps the cert. didn't permit encryption, so I read handle 0x01000013 into a file -- signer.pem and took the tpm2 provider completely out of the picture:
>
>$ openssl cms -encrypt -in file.txt -recip signer.pem -aes128 -out file.cipher -outform der
>
>This works.  So, it doesn't seem to be a problem with the recipient certificate.  I also tried this essentially making no _explicit_ use of the tpm2, but specifying the provider anyway:
>
>$ openssl cms -encrypt -provider tpm2 -provider default -in file.txt -recip signer.pem -aes128
>40BCDCB85F7F0000:error:17000074:CMS routines:cms_EnvelopedData_Encryption_init_bio:error setting recipientinfo:../crypto/cms/cms_env.c:1142:
>40BCDCB85F7F0000:error:17000068:CMS routines:CMS_final:cms lib:../crypto/cms/cms_smime.c:881:
>
>For this encryption, there's a DH operation taking place under the covers to come up with an encryption key.  I'm thinking the TPM might be coming into play for that?
>
>-----Original Message-----
>From: Petr Gotthard <petr.gotthard(a)centrum.cz> 
>Sent: Thursday, April 28, 2022 11:11 AM
>To: Sievert, James <james.sievert(a)bsci.com>; tpm2(a)lists.01.org
>Subject: Re: [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms
>
>>I also tried this:  
>>
>>openssl cms -encrypt -provider tpm2 -provider base -propquery ?provider=tpm2,tpm2.cipher!=yes -in file.txt -recip handle:0x01000013 -aes128
>>
>>Same result...
>
>That should work as well. Have you tried "-provider default" instead of "-provider base"?
>
>Openssl should be able to combine algorithms from different providers and the tpm2-openssl provider announces to openssl only those algorithms that are supported by the tpm2 chip itself. The only tricky bit is when the same algorithm is implemented twice, which is not your case... yet ;-).
>
>
>Petr
>_______________________________________________
>tpm2 mailing list -- tpm2(a)lists.01.org
>To unsubscribe send an email to tpm2-leave(a)lists.01.org
>%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
>
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms
@ 2022-04-28 15:46 Sievert, James
  0 siblings, 0 replies; 13+ messages in thread
From: Sievert, James @ 2022-04-28 15:46 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 2234 bytes --]

Actually here the error is different:

bsci(a)ip-10-132-42-225:~$ openssl cms -encrypt -provider tpm2 -provider default -in file.txt -recip handle:0x01000013 -aes128
409CFA23377F0000:error:17000074:CMS routines:cms_EnvelopedData_Encryption_init_bio:error setting recipientinfo:../crypto/cms/cms_env.c:1142:
409CFA23377F0000:error:17000068:CMS routines:CMS_final:cms lib:../crypto/cms/cms_smime.c:881:

I was thinking that perhaps the cert. didn't permit encryption, so I read handle 0x01000013 into a file -- signer.pem and took the tpm2 provider completely out of the picture:

$ openssl cms -encrypt -in file.txt -recip signer.pem -aes128 -out file.cipher -outform der

This works.  So, it doesn't seem to be a problem with the recipient certificate.  I also tried this essentially making no _explicit_ use of the tpm2, but specifying the provider anyway:

$ openssl cms -encrypt -provider tpm2 -provider default -in file.txt -recip signer.pem -aes128
40BCDCB85F7F0000:error:17000074:CMS routines:cms_EnvelopedData_Encryption_init_bio:error setting recipientinfo:../crypto/cms/cms_env.c:1142:
40BCDCB85F7F0000:error:17000068:CMS routines:CMS_final:cms lib:../crypto/cms/cms_smime.c:881:

For this encryption, there's a DH operation taking place under the covers to come up with an encryption key.  I'm thinking the TPM might be coming into play for that?

-----Original Message-----
From: Petr Gotthard <petr.gotthard(a)centrum.cz> 
Sent: Thursday, April 28, 2022 11:11 AM
To: Sievert, James <james.sievert(a)bsci.com>; tpm2(a)lists.01.org
Subject: Re: [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms

>I also tried this:  
>
>openssl cms -encrypt -provider tpm2 -provider base -propquery ?provider=tpm2,tpm2.cipher!=yes -in file.txt -recip handle:0x01000013 -aes128
>
>Same result...

That should work as well. Have you tried "-provider default" instead of "-provider base"?

Openssl should be able to combine algorithms from different providers and the tpm2-openssl provider announces to openssl only those algorithms that are supported by the tpm2 chip itself. The only tricky bit is when the same algorithm is implemented twice, which is not your case... yet ;-).


Petr

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms
@ 2022-04-28 15:10 Petr Gotthard
  0 siblings, 0 replies; 13+ messages in thread
From: Petr Gotthard @ 2022-04-28 15:10 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 583 bytes --]

>I also tried this:  
>
>openssl cms -encrypt -provider tpm2 -provider base -propquery ?provider=tpm2,tpm2.cipher!=yes -in file.txt -recip handle:0x01000013 -aes128
>
>Same result...

That should work as well. Have you tried "-provider default" instead of "-provider base"?

Openssl should be able to combine algorithms from different providers and the tpm2-openssl provider announces to openssl only those algorithms that are supported by the tpm2 chip itself. The only tricky bit is when the same algorithm is implemented twice, which is not your case... yet ;-).


Petr

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms
@ 2022-04-28 15:07 Sievert, James
  0 siblings, 0 replies; 13+ messages in thread
From: Sievert, James @ 2022-04-28 15:07 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 1372 bytes --]

I also tried this:  

openssl cms -encrypt -provider tpm2 -provider base -propquery ?provider=tpm2,tpm2.cipher!=yes -in file.txt -recip handle:0x01000013 -aes128

Same result...

-----Original Message-----
From: Petr Gotthard <petr.gotthard(a)centrum.cz> 
Sent: Wednesday, April 27, 2022 1:38 PM
To: tpm2(a)lists.01.org
Subject: [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms

>CMS encryption fails as follows:
>
>$ openssl cms -encrypt -provider tpm2 -provider base -in file.txt 
>-recip handle:0x01000013
>WARNING:esys:src/tss2-esys/api/Esys_CreateLoaded.c:368:Esys_CreateLoade
>d_Finish() Received TPM Error
>ERROR:esys:src/tss2-esys/api/Esys_CreateLoaded.c:129:Esys_CreateLoaded(
>) Esys Finish ErrorCode (0x000b0143) 
>40FCFCC0017F0000:error:4000000B:tpm2::cannot create key::-1:721219 
>rmt:error(2.0): command code not supported
>
>This looks like https://github.com/tpm2-software/tpm2-openssl/issues/29.
> For my use case, support for TPMs without the CreateLoaded command will be essential.  My machines have an OPTIGA TPM2.

The CreateLoaded issue should be fixed now (in the latest master branch).


Petr
_______________________________________________
tpm2 mailing list -- tpm2(a)lists.01.org
To unsubscribe send an email to tpm2-leave(a)lists.01.org %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms
@ 2022-04-28 14:42 Sievert, James
  0 siblings, 0 replies; 13+ messages in thread
From: Sievert, James @ 2022-04-28 14:42 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 2032 bytes --]

I've tested cms signing without specifying the -md option with the EC key.  That now works.

I also tested cms encryption.  I'm getting a different error:

$ openssl cms -encrypt -provider tpm2 -provider base -in file.txt -recip handle:0x01000013 -aes128 
409C92EDC37F0000:error:0308010C:digital envelope routines:inner_evp_generic_fetch:unsupported:../crypto/evp/evp_fetch.c:349:Global default library context, Algorithm (AES-128-CBC : 62), Properties ()
409C92EDC37F0000:error:17000065:CMS routines:ossl_cms_EncryptedContent_init_bio:cipher initialisation error:../crypto/cms/cms_enc.c:78:
409C92EDC37F0000:error:17000068:CMS routines:CMS_final:cms lib:../crypto/cms/cms_smime.c:881:

I suspect that the command is attempting to perform AES encryption using the TPM.  My particular TPM doesn't support symmetric encryption.

Jim

-----Original Message-----
From: Petr Gotthard <petr.gotthard(a)centrum.cz> 
Sent: Wednesday, April 27, 2022 1:38 PM
To: tpm2(a)lists.01.org
Subject: [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms

>CMS encryption fails as follows:
>
>$ openssl cms -encrypt -provider tpm2 -provider base -in file.txt 
>-recip handle:0x01000013
>WARNING:esys:src/tss2-esys/api/Esys_CreateLoaded.c:368:Esys_CreateLoade
>d_Finish() Received TPM Error
>ERROR:esys:src/tss2-esys/api/Esys_CreateLoaded.c:129:Esys_CreateLoaded(
>) Esys Finish ErrorCode (0x000b0143) 
>40FCFCC0017F0000:error:4000000B:tpm2::cannot create key::-1:721219 
>rmt:error(2.0): command code not supported
>
>This looks like https://github.com/tpm2-software/tpm2-openssl/issues/29.
> For my use case, support for TPMs without the CreateLoaded command will be essential.  My machines have an OPTIGA TPM2.

The CreateLoaded issue should be fixed now (in the latest master branch).


Petr
_______________________________________________
tpm2 mailing list -- tpm2(a)lists.01.org
To unsubscribe send an email to tpm2-leave(a)lists.01.org %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms
@ 2022-04-27 17:37 Petr Gotthard
  0 siblings, 0 replies; 13+ messages in thread
From: Petr Gotthard @ 2022-04-27 17:37 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 742 bytes --]

>CMS encryption fails as follows:
>
>$ openssl cms -encrypt -provider tpm2 -provider base -in file.txt -recip handle:0x01000013
>WARNING:esys:src/tss2-esys/api/Esys_CreateLoaded.c:368:Esys_CreateLoaded_Finish() Received TPM Error
>ERROR:esys:src/tss2-esys/api/Esys_CreateLoaded.c:129:Esys_CreateLoaded() Esys Finish ErrorCode (0x000b0143)
>40FCFCC0017F0000:error:4000000B:tpm2::cannot create key::-1:721219 rmt:error(2.0): command code not supported
>
>This looks like https://github.com/tpm2-software/tpm2-openssl/issues/29.
> For my use case, support for TPMs without the CreateLoaded command will be essential.  My machines have an OPTIGA TPM2.

The CreateLoaded issue should be fixed now (in the latest master branch).


Petr

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms
@ 2022-04-27 15:20 Sievert, James
  0 siblings, 0 replies; 13+ messages in thread
From: Sievert, James @ 2022-04-27 15:20 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 2568 bytes --]

Okay, Petr, I've added -md sha256 to the command line, and both signing and verification now work:

$ echo "hi there" >file.txt
$ openssl cms -sign -provider tpm2 -provider base -in file.txt -inkey handle:0x81800002 -signer handle:0x01000013 -md sha256 -out file.sig -outform der
$ echo $?
0
$ openssl cms -verify -content file.txt -in file.sig -inform der -CApath /run/user/201/trustStore/
hi there
CMS Verification successful

So, that's great!

CMS encryption fails as follows:

$ openssl cms -encrypt -provider tpm2 -provider base -in file.txt -recip handle:0x01000013
WARNING:esys:src/tss2-esys/api/Esys_CreateLoaded.c:368:Esys_CreateLoaded_Finish() Received TPM Error
ERROR:esys:src/tss2-esys/api/Esys_CreateLoaded.c:129:Esys_CreateLoaded() Esys Finish ErrorCode (0x000b0143)
40FCFCC0017F0000:error:4000000B:tpm2::cannot create key::-1:721219 rmt:error(2.0): command code not supported

This looks like https://github.com/tpm2-software/tpm2-openssl/issues/29.  For my use case, support for TPMs without the CreateLoaded command will be essential.  My machines have an OPTIGA TPM2.

Thanks!

-----Original Message-----
From: Petr Gotthard <petr.gotthard(a)centrum.cz> 
Sent: Tuesday, April 26, 2022 5:55 PM
To: tpm2(a)lists.01.org
Subject: [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms

>> Debugging openssl is tricky when it fails without any error message
>
>Sorry about that.  ☹

No problem. I am glad you are trying the tpm2 provider in your environment. :-)

>> If you create e.g. a RSA-PSS key restricted to a specific 
>> hash-algorithm you shouldn't need this extra argument
>
>I was under the impression that the key was created using the sha256 hashing algorithm.  Here's the command used for creating the key:
>
>tpm2_create -C /run/user/201/platform.ctx -G ecc256:ecdsa-sha256 -r /run/user/201/private -u /run/user/201/public -a 'fixedtpm|fixedparent|sensitivedataorigin|sign|userwithauth|noda'
>
>Here's the result:
>
>$ tpm2_readpublic -c 0x81800002
>scheme:
>  value: ecdsa
>  raw: 0x18
>scheme-halg:
>  value: sha256
>  raw: 0xb

Yeah. What I wrote was apparently true for RSA keys only. The EC keys do not correctly supply the hash algorithm. That is a bug that will be fixed in the coming days: https://github.com/tpm2-software/tpm2-openssl/issues/34


Petr
_______________________________________________
tpm2 mailing list -- tpm2(a)lists.01.org
To unsubscribe send an email to tpm2-leave(a)lists.01.org %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms
@ 2022-04-27 14:46 Petr Gotthard
  0 siblings, 0 replies; 13+ messages in thread
From: Petr Gotthard @ 2022-04-27 14:46 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 466 bytes --]

>Yeah. What I wrote was apparently true for RSA keys only. The EC keys do not correctly supply the hash algorithm. That is a bug that will be fixed in the coming days: https://github.com/tpm2-software/tpm2-openssl/issues/34

The bug has been fixed in the latest master branch.

A new test shows openssl cms -sign with an EC key without the -md parameter.
https://github.com/tpm2-software/tpm2-openssl/blob/master/test/ec_createak_x509_cms.sh


regards,
Petr

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms
@ 2022-04-26 21:54 Petr Gotthard
  0 siblings, 0 replies; 13+ messages in thread
From: Petr Gotthard @ 2022-04-26 21:54 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 1011 bytes --]

>> Debugging openssl is tricky when it fails without any error message
>
>Sorry about that.  ☹

No problem. I am glad you are trying the tpm2 provider in your environment. :-)

>> If you create e.g. a RSA-PSS key restricted to a specific hash-algorithm you shouldn't need this extra argument
>
>I was under the impression that the key was created using the sha256 hashing algorithm.  Here's the command used for creating the key:
>
>tpm2_create -C /run/user/201/platform.ctx -G ecc256:ecdsa-sha256 -r /run/user/201/private -u /run/user/201/public -a 'fixedtpm|fixedparent|sensitivedataorigin|sign|userwithauth|noda'
>
>Here's the result:
>
>$ tpm2_readpublic -c 0x81800002
>scheme:
>  value: ecdsa
>  raw: 0x18
>scheme-halg:
>  value: sha256
>  raw: 0xb

Yeah. What I wrote was apparently true for RSA keys only. The EC keys do not correctly supply the hash algorithm. That is a bug that will be fixed in the coming days: https://github.com/tpm2-software/tpm2-openssl/issues/34


Petr

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms
@ 2022-04-26 21:43 Sievert, James
  0 siblings, 0 replies; 13+ messages in thread
From: Sievert, James @ 2022-04-26 21:43 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 1501 bytes --]

> Debugging openssl is tricky when it fails without any error message

Sorry about that.  ☹

> If you create e.g. a RSA-PSS key restricted to a specific hash-algorithm you shouldn't need this extra argument

I was under the impression that the key was created using the sha256 hashing algorithm.  Here's the command used for creating the key:

tpm2_create -C /run/user/201/platform.ctx -G ecc256:ecdsa-sha256 -r /run/user/201/private -u /run/user/201/public -a 'fixedtpm|fixedparent|sensitivedataorigin|sign|userwithauth|noda'

Here's the result:

$ tpm2_readpublic -c 0x81800002
name: 000bb512ddf666370d1d957955207a3159f07a499acdb36a43b5bb928000874aff0e
qualified name: 000b087ef34ba32025d7430d242d5b95813935c8b0c66983bf0107b63fdf00e62b07
name-alg:
  value: sha256
  raw: 0xb
attributes:
  value: fixedtpm|fixedparent|sensitivedataorigin|userwithauth|noda|sign
  raw: 0x40472
type:
  value: ecc
  raw: 0x23
curve-id:
  value: NIST p256
  raw: 0x3
kdfa-alg:
  value: null
  raw: 0x10
kdfa-halg:
  value: (null)
  raw: 0x0
scheme:
  value: ecdsa
  raw: 0x18
scheme-halg:
  value: sha256
  raw: 0xb
sym-alg:
  value: null
  raw: 0x10
sym-mode:
  value: (null)
  raw: 0x0
sym-keybits: 0
x: b326cf2f3088979065d64f692dabb8e72384cd480738325a92ec6e0af3ad066d
y: 7147de064a9b5d438b3e5c4f64f9437eec64816f1c3ddc21b0b194ab620706d1

> Adding "-md sha256" fixed the issue for me.

I'm unable to test at the moment.  I'll hopefully be able to confirm tomorrow.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms
@ 2022-04-26 20:22 Petr Gotthard
  0 siblings, 0 replies; 13+ messages in thread
From: Petr Gotthard @ 2022-04-26 20:22 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 3268 bytes --]

Thank you, James.

Debugging openssl is tricky when it fails without any error message. :-/ This happens especially when the provider does not supply openssl with something that the default provider usually supplies-- in this case the MD algorithm.

The command
> openssl cms -sign -provider tpm2 -provider default -in file.txt -inkey handle:0x81800002 -signer handle:0x01000013
was failing because the key had no mandatory digest and there was no digest specified via the command line.

Adding "-md sha256" fixed the issue for me. If you create e.g. a RSA-PSS key restricted to a specific hash-algorithm you shouldn't need this extra argument, because openssl will ask the key for the digest algorithm.

Based on the commands you sent I made a new test for 'openssl cms'. Have a look here:
https://github.com/tpm2-software/tpm2-openssl/blob/master/test/rsa_genpkey_x509_cms.sh
This should show a full test scenario for CMS. I can add more if you think something is missing, or when you encounter another weird behaviour.


Regards,
Petr
______________________________________________________________
> Od: "Sievert, James" <james.sievert(a)bsci.com>
> Komu: "tpm2(a)lists.01.org" <tpm2(a)lists.01.org>
> Datum: 26.04.2022 16:24
> Předmět: [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider...
>
>> Could you please suggest a sequence of openssl (and other commands) to verify all required CMS functions?
>
>Tell you what, I'll frame the test sequences in terms of the tpm2tss engine commands as I can verify correct syntax and command operation.  I'll assume for the time being that the necessary keys and certs are stored in TPM NVRAM through tpm2_* commands.
>
>The a good start to testing would be something to the effect:
>
>	echo "this is some text" >file.txt
>
>	openssl cms -sign -engine tpm2tss -keyform engine -inkey 0x81800002 -signer signer.pem -in file.txt -binary -nodetach -out file.sig
>
>	(note that although the tpm2tss engine doesn't support it, the signer could also be given as a handle to the tpm2 provider)
>
>	openssl cms -verify -in file.sig -binary -noverify
>
>	(note that you can remove the -noverify and point to a truststore if necessary with -CApath /somewhere/truststore)
>
>	openssl cms -encrypt -recip signer.pem -in file.txt -out file.enc
>
>	(note that although the tpm2tss engine doesn't support it, the recip could also be given as a handle to the tpm2 provider)
>
>	openssl cms -decrypt -engine tpm2tss -keyform engine -inkey 0x81800002 -in file.enc -recip signer.pem
>
>	(note that this command doesn't work with the tpm2tss engine.  See:  https://bugs.launchpad.net/ubuntu/+source/openssl/+bug/1962549.)
>
>	openssl cms  -encrypt  -sign...
>
>	(the cms command can encrypt, sign, and bundle everything into an output with a single command -- the syntax is a combination of what's above)
>
>	openssl cms -verify -decrypt ...
>
>	(the cms command can verify and decrypt an input with a single command -- the syntax is a combination of what's above)
>
>	 
>_______________________________________________
>tpm2 mailing list -- tpm2(a)lists.01.org
>To unsubscribe send an email to tpm2-leave(a)lists.01.org
>%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
>
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-04-28 17:39 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-28 16:33 [tpm2] Re: {External} Re: OpenSSL 3 and tpm2 provider... / openssl cms Sievert, James
  -- strict thread matches above, loose matches on Subject: below --
2022-04-28 17:39 Petr Gotthard
2022-04-28 16:26 Petr Gotthard
2022-04-28 15:46 Sievert, James
2022-04-28 15:10 Petr Gotthard
2022-04-28 15:07 Sievert, James
2022-04-28 14:42 Sievert, James
2022-04-27 17:37 Petr Gotthard
2022-04-27 15:20 Sievert, James
2022-04-27 14:46 Petr Gotthard
2022-04-26 21:54 Petr Gotthard
2022-04-26 21:43 Sievert, James
2022-04-26 20:22 Petr Gotthard

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.