-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Symmetric Encryption #77
Conversation
5f4b457
to
125dd34
Compare
f4354ae
to
e6dc877
Compare
Codecov Report
@@ Coverage Diff @@
## master #77 +/- ##
==========================================
+ Coverage 66.13% 67.88% +1.75%
==========================================
Files 9 10 +1
Lines 1134 1308 +174
==========================================
+ Hits 750 888 +138
- Misses 384 420 +36
Continue to review full report at Codecov.
|
After having some trouble with sserver.sh, clang, openssl 1.0.2 ... I resolved the bugs Finally, CI is passing. @AndreasFuchsSIT Can it be merged ? |
Glad you could make it work, I know the hassle... ;-) I'll have a closer look over it after the 1.0 engine release. And queue it up for the 1.1 release... From a first look, I think this still lacks tpm2tss-genkey support and loading of these, documentation in man-pages and bash-completion. |
I didn't find a way to use tpm2tss-genkey. Because of the interface openssl enc which does not have options to read a key from a file. From the man pages of openssl (also source code here) :
All it can do is derived a key from a password from a file. I was only able to use the option -K to pass a persistent handle of the TPM. Still looking for solutions ... |
Hmmmm..... If |
I did that because we were doing the same with RSA. See this test : |
I know, and I only justify it due to |
I have made a working function tpm2tss_sym_genkey(), and write manual. |
91618eb
to
f5a4ef9
Compare
@AndreasFuchsSIT I have rebased and squashed, is that ok for you ? |
Yes, that's great... |
Currently, I don't think that the openssl app can pass file. Maybe that in the meantime that openssl developpers find a solution, if there is one, shouldn't we merge this PR ? However, I think it would be possible to use our key file through openssl API : EVP_Encrypt(...). Maybe, one solution would be to get our filename, open and read it in our engine. But the filename need to be a hexadecimal string because of that function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be fine with merging this feature for persistent keys only then, until upstream openssl picked up on the new structure.
Since we cannot use file-based keys now, all references to that should be removed.
I've made some comments in this regard and also 2 more.
With that, I'd be happy to merge...
P.S. But keep the current code around somewhere, so we can recycle it once upstream is ready.
6bed34d
to
2121588
Compare
CFB and OFB are now the two symmetric modes available. CBC was apparently causing troubles with openssl sserver & sclient. However if a mode is already defined within the TPM persistent key, it will use it. |
😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the rework.
Sorry for taking so long.
I've posted a few more things that I encountered when looking at the code.
man/tpm2tss-genkey.1.md
Outdated
@@ -93,4 +93,3 @@ Technologies AG. License BSD 3-clause. | |||
## SEE ALSO | |||
|
|||
openssl(1) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a non-change, please revert it
/* Get App Data */ | ||
tpm2Data = EVP_CIPHER_CTX_get_app_data(ctx); | ||
if (tpm2Data == NULL || tpm2Data->pub.size == 0 || inl == 0) { | ||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If tpm2Data is NULL, I think we want to call openSSL's standard cipher engine, right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmmh don't know how to do that here.
And if tpm2Data is NULL, tpm2_cipher_init_key() function should have failed before.
src/tpm2-tss-engine-ciphers.c
Outdated
TSS2_RC ret; | ||
ESYS_AUXCONTEXT eactx = (ESYS_AUXCONTEXT){ NULL, NULL}; | ||
ESYS_TR keyHandle = ESYS_TR_NONE; | ||
TPM2B_MAX_BUFFER *out_data, *in_data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in_data is never freed.
Also you don't have to malloc it, you could just declare TPM2_MAX_BUFFER in_data;
on stack instead of a pointer.
} | ||
|
||
#if OPENSSL_VERSION_NUMBER < 0x10100000 | ||
static EVP_CIPHER tpm2_aes_256_ofb = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for being so ignorant, but could you explain the 256 and ofb128 to me ?
I don't know what they mean.
Does that mean that aes 128 is not supported ?
I guess a comment in code would also be good...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is about the selector function and NIDS, I guess. So will try to explain my understanding of it.
So at first, you can try to type a openssl enc -ciphers
on your machine. You will see there the different openssl symmetric encryption available. We have to define which algos of this list , our engine will implement. Currently, I have defined these two :
static int tpm2_cipher_nids[] = {
NID_aes_256_cfb128,
NID_aes_256_ofb128,
0
};
Which are defined by AES algorithm, 256 bits key size and cfb/ofb encryption mode.
When someone call openssl enc -aes-256-cfb -e -engine tpm2tss ...
, our engine implementation will be used. However by using a persistent handle, the key already exist so in case of creating it using AES and a 256 bits size, we are currently retrieving it from the tpm in the tpm2_cipher_init_key
function, then we choose either the encryption mode asked or either the one already existing in the key.
Moreover, IDs are defined here in the openssl repo.
As i said before I took the gost engine as example, we can see here the implementation of its cipher selector. Also another really simple cipher engine exits here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have other question, don't hesistate. I will try to be the clearest possible and explain my understanding.
tpm2_cipher_init_key, // Init key | ||
tpm2_do_cipher, // Encrypt/Decrypt | ||
tpm2_cipher_cleanup, // Cleanup | ||
sizeof(TPM2_DATA), // Context size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct. The man-page says EVP_CIPHER_meth_set_impl_ctx_size() sets the size of the EVP_CIPHER's implementation context so that it can be automatically allocated.
but we are malloc'ing it ourselves. But I also don't know what this is really for and how we should use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I don't fully understand this stuff neither.
I based my code by taking the gost engine as example. In there code, we can see that there are doing a EVP_CIPHER_meth_set_impl_ctx_size(_hidden_magma_cbc, sizeof(struct ossl_gost_cipher_ctx))
here and then struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_get_cipher_data(ctx);
here.
So maybe I should put a 0 value here, I tried and it does not seem to change anything. I can change it if you want ?
I guess that had to do with the comment I posted here: #77 (diff) Please see that we enable CBC mode for the TPM and still have sserver running. It's basically the counter test that the engine does not interfere with any other operations; especially if the engine shall only be used for asymmetric operations. |
As a final comment: Since only very few TPMs support symmetric operations, I'd like to wrap support for it in a configure parameter |
I have done some changes that you requested. However can you relaunch my CI build ? a weird error appeared, CI was not able to clone openssl. |
You can't but I did |
Since tpm2-software/tpm2-tools#1476 I'll retrigger the CI... |
32efe28
to
33f681e
Compare
Signed-off-by: Gael Guegan <[email protected]>
Looks very much stalled. So closing |
Description
Adding Symmetric Encryption : tpm2-tss-engine-ciphers.c. (Issue #70)
This is done by handling structure EVP_CIPHER_meth_new.
How to use ?
See the shell script : ciphers.sh.
See official wiki.
Problems
For now, it is only working with persistent handle. We cannot passed key file through the openssl app (Doc), only hex string.
Signed-off-by: Gael Guegan [email protected]