tpm2-software / tpm2-pkcs11 Goto Github PK
View Code? Open in Web Editor NEWA PKCS#11 interface for TPM2 hardware
Home Page: https://tpm2-software.github.io
License: Other
A PKCS#11 interface for TPM2 hardware
Home Page: https://tpm2-software.github.io
License: Other
Complete the release guidelines.
C_CloseSession or C_CloseAllSessions() should implicitly logout. Also, there's a state in the login/logout tests where test_user_login_logout_good is not logging out and (perhaps) the next passing login (i think test_user_global_login_logout_good) causes the full login code to-rerun without a logout. That code should skip a lot of the login steps if not all of them.
Once tpm2-tss has python bindings, re-write tpm2-ptool in python without the tpm2-tools dependencies.
Modern *nix systems use p11-kit for managing PKCS#11 modules.
Please consider installing the module itself to $(pkg-config --variable=p11_module_path p11-kit-1)
and also installing a p11-kit module file to $(pkg-config --variable=p11_module_configs p11-kit-1)
.
Then, any well-behaved application on the system will be able to use keys from the PKCS#11 token simply by passing it a RFC7512 PKCS#11 URI instead of a filename.
per:
Storing things as a blob in the db should be faster, and will simplify the code and avoid having to deal with creating unique files
I'm not sure why it doesn't trigger in the test,
but I get a deadlock on logout.
I already looked into it and
the problem is session_ctx_logout tries to lock a ctx, which is already held via the session_table_lookup and then fails at
session_ctx_lock(tok->login_session_ctx);
I'll look up the steps to reproduce when I find some time :/
All the current PKCS11 store locations depend on ENV variables, allow an option to use a path and allow configure to over ride that path. The search pattern should be:
Hello!
Is it possible to setup this pkcs11 module to be used with OpenVPN?
I found one comment from January 2018 in SourceForge by somebody that apparently was able to do it with the https://github.com/irtimmer/tpm2-pk11 module (deprecated by this module now?).
A lot have changed since then apparently. An this projects are actively being develop :)
Do you have any hints on how we could use this with OpenVPN?
Thank you in advance!
Travis is uploading builds to coveralls, but the coveralls UI isn't updating with the most recent builds. In fact it only shows the first build.
Currently, if unit tests are not enabled during the initial configure run, but activated later, src/lib/twist.c
is not recompiled automatically by make
or make check
. This causes the unit tests to fail because the necessary #ifdef UNIT_TESTING
block is not included in the compiled file. For example, a sequence like
git clone https://github.com/tpm2-software/tpm2-pkcs11.git
cd tpm2-pkcs11
./bootstrap
./configure
make
./configure --enable-unit
make
make check
fails with the error
make test/unit/test_twist
make[1]: Entering directory '/home/jonas/tpm2-pkcs11'
CC test/unit/test_twist-test_twist.o
CCLD test/unit/test_twist
/usr/bin/ld: test/unit/test_twist-test_twist.o: in function `test_twist_new_bad_alloc':
test_twist.c:(.text.test_twist_new_bad_alloc+0x15): undefined reference to `twist_next_alloc_fails'
/usr/bin/ld: test/unit/test_twist-test_twist.o: in function `test_twist_append_bad_alloc':
test_twist.c:(.text.test_twist_append_bad_alloc+0x40): undefined reference to `twist_next_alloc_fails'
/usr/bin/ld: test/unit/test_twist-test_twist.o: in function `test_twist_truncate_bigger_bad_alloc':
test_twist.c:(.text.test_twist_truncate_bigger_bad_alloc+0x4c): undefined reference to `twist_next_alloc_fails'
/usr/bin/ld: test/unit/test_twist-test_twist.o: in function `test_twist_unhexlify_failed_alloc':
test_twist.c:(.text.test_twist_unhexlify_failed_alloc+0x15): undefined reference to `twist_next_alloc_fails'
/usr/bin/ld: test/unit/test_twist-test_twist.o: in function `test_twist_hexlify_alloc_fail':
test_twist.c:(.text.test_twist_hexlify_alloc_fail+0x34): undefined reference to `twist_next_alloc_fails'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:1196: test/unit/test_twist] Error 1
make[1]: Leaving directory '/home/jonas/tpm2-pkcs11'
make: *** [Makefile:1929: check-am] Error 2
You need to e.g. touch src/lib/twist.c
after the second configure
to force recompilation, afterwards make check
passes.
I do not know whether there is a good way to achieve automatic recompilation when this configure option changes using Autotools, but I at least wanted to document this behaviour.
Setup travis CI
Support RSA and ECC Keypair generation
Store the serialized ESYS TR object vs the raw handle in the DB for the persistent primary key object
C_CloseAllSessions closes all session table handles even if they don't belong to that token.
If I create two sessions,
login to the first one
and try to sign with the second one,
it fails with some esys error.
All character-strings in pkcs#11 must be padded with the blank character ' '.
In most cases the character string SHOULD NOT be NULL terminated.
or in some cases it MUST not be NULL terminated.
-> Fix by applying the correct padding without NULL termination (for all cases).
Luckily pcks11t.h already includes comments which members should be padded.
-> Check all occurrences and fix them as necessary.
Session State is currently not global and it should be. Once a C_Login occurs, all sessions are logged in. Correct this in the implementation and test.
Currently the implementation allows for multiple concurrent operations on a session when the spec doesn't support this. Remove the per-session per-operation state and make it session global. Thus things like C_SignInit followed by C_DigestInit will fail. Add tests.
The LOG macros in the PKCS11.c file can skip the exit LOG statement on error, correct this.
If the Hardware doesn't support a hashing algorithm, synthesize it in software, build the signing structure and call rsa decrypt. Start off by supporting RSA PKCS#1.5.
Some functions are taking things like unsigned char *, unsigned long when they should be using CK_BYTE_PTR and CK_ULONG respectively. Update to the proper CK_ types.
Consult TPM2_PT_CONTEXT_SYM_SIZE to determine how large to make the AES symmetric key wrapping size.
C_OpenSession ends with a deadlock if C_INITIALIZE is called with .flags=CKF_OS_LOCKING_OK
Steps to reproduce:
See example below (modified from test/integration/pkcs-open-close-session.int.c)
CK_C_INITIALIZE_ARGS init_args ={0};
init_args.flags=2;
CK_RV rv = C_Initialize(&init_args);
if(rv != CKR_OK){
LOGE("C_Initialize failed! Response Code %x", rv);
exit(1);
}
CK_SESSION_HANDLE handle;
rv = C_OpenSession(0x01, CKF_SERIAL_SESSION | CKF_RW_SESSION, NULL , NULL, &handle);
// We never get here!
// pkcs-open-close-session.int: src/lib/mutex.h:70: mutex_lock_fatal: Assertion `rv == CKR_OK' failed.
// Abgebrochen
if(rv != CKR_OK){
LOGE("C_OpenSession failed! Response Code %x", rv);
exit(1);
}
[]: The secondary object algorithm should default to rsa2048:aes<key-size>
where keysize is determined by sym_size
[]: To work around bug tpm2-software/tpm2-tools#1206, we should default the parent algorithm to rsa2048:aes<key-size>
like the secondary object above.
These issues came out of the discussion here:
#52
The tests should use cmocka framework so we have the assert macros and failure reporting.
Support RSA decrypt (private key decryption) with OAEP padding.
I have built tpm2_tools, tpm2_tss and tpm2_pkcs11 from the tip of their respective master branches.
When I run ptool init:
$ tpm2_ptool.py init --pobj-pin=mypobjpin --path=/tmp
I get the following error:
Could not execute tpm2_createprimary: ERROR: Tss2_Sys_CreatePrimary(0x2C4) - tpm:parameter(2):value is out of range or is not correct for the context
ERROR: Unable to run tpm2_createprimary
Recreating the cmd line ptool used I get:
$ tpm2_createprimary -p hex:55d15e8bff73005fd860d47191a4192087cfbfa09443c45320e47e4b8e912b64 -o /tmp/tmp4c6Z3M/context.out
This fails with the same error message. However if I specify the algorithm (rsa) the command succeeds
$ tpm2_createprimary -G rsa -p hex:55d15e8bff73005fd860d47191a4192087cfbfa09443c45320e47e4b8e912b64 -o /tmp/tmp4c6Z3M/context.out
Similarly, if I modify the ptool code to add '-G rsa' to the tpm2_createprimary cmd line it works.
The tpm2_createprimary man page suggests the default algorithm will be rsa if it is not specified but the behavior seems different.
Any ideas?
Cat test-suite.log on failure so we have the information in travis on what test failed and why
Support an existing primary object via a -p|--primary=<handle>
option. Allow the <handle>
to be optional and default to 0x81000001
as what is discussed in #30.
Complete the contributing guidelines.
E.g.
https://github.com/tpm2-software/tpm2-pkcs11/blob/master/test/integration/pkcs-find-objects.int.c
shows:
/* SPDX-License-Identifier: BSD-2 */
/*
* Copyright (c) 2018, Intel Corporation
* All rights reserved.
*/
/* SPDX-License-Identifier: BSD-2 */
/***********************************************************************
* Copyright (c) 2017-2018, Intel Corporation
*
* All rights reserved.
***********************************************************************/
--> Are we BSD 2 or 3?
Pull PR #64 in
The token data structure will need locking, identify and lock the structure as appropriate.
I have been trying to get tpm2-pkcs11 to work with GnuTLS's p11tool
, but haven't been successful. Do you happen to have some steps for how to create a TPM 2 key with your tools or p11tool
(better) and use the key with the p11tool
then? Maybe something is wrong with my setup.
I also posted a message with the other PKCS11 TPM 2 module that I couldn't get to work, either: irtimmer/tpm2-pk11#84
Thanks to williamcroberts for bootstrap LD_VERSION issue and now i'm able to do successful bootstrap step with ./bootstrap -I /usr/share/gnulib/m4 .
configure throws below error
pi@raspberrypi:~/tpm2-pkcs11 $ ./configure
configure: error: Invalid policy. Valid policies: git-directory, minor-version.
For more information:
Platform : Raspberry Pi model 3 revB board
OS : Linux version 4.14.72-v7+ (root@raspberrypi) (gcc version 6.3.0 20170516 (Raspbian 6.3.0-18+rpi1+deb9u1)) #8 SMP
When using the TPM2_PKCS11_TCTI
environment variable with custom options, e.g.
export TPM2_PKCS11_TCTI="tabrmd:bus_type=session"
the second session test in test_pkcs11.c
invariably fails, irrespective of the order of the tests.
The problem is caused by this line in tcti_ldr.c
, which ends up modifying the underlying TPM2_PKCS11_TCTI
environment variable (see here for an explanation), dropping the configuration options.
The offending code looks like this:
char *optstr = getenv (TPM2_PKCS11_TCTI);
// ...
char *split = strchr(optstr, ':');
// ...
split[0] = '\0';
Upon execution of the second test, the truncated environment variable will be retrieved, causing the test to fail.
Add design documents and diagrams.
Calling C_Sign/C_SignFinal or C_Verify/C_VerifyFinal with a buffer to small or NULL should result in a CKR_BUFFER_TOO_SMALL|CKR_OK return respectively and the value of the length in the length pointer.
Currently this fails, correct the behavior so it aligns to the specification, notably covered in section 5.2
With the introduction of #72 tpm2-pkcs11 fails for me on the raspberry pi3.
I get either a segfault or a SIGBUS on C_Initialize.
I cannot really debug it at the moment.
If I revert the change it works again.
Because ESAPI requires the context to be the same to use TR_ handles, having per-session ESAPI contexts requires us to stash the login session_ctx * in token to use when unloading things. Just share ESAPI (ie tpm) context as a token level idiom.
./bootstrap -I /usr/share/gnulib/m4
./configure
make
Makefile:2059: *** missing separator. Schluss.
The corresponding line in the makefile is
@CODE_COVERAGE_RULES@
Tested on raspberry pi with raspbian.
It used to work somehow (with the old m4 macros?)
Currently tpm2-pkcs11 depends on tpm2_encryptdecrypt to be able to support a normal user and a security officer as defined by PKCS#11. However doesn't seem to work on TPMs (see also tpm2-software/tpm2-tools#407 ) based on an older revision like mine. So it would be nice if this dependency could be removed. However I'm not sure what would be an acceptable solutions, as I'm not completely sure how tpm2-pkcs11 works internally:
or are there other ideas on having these two users without the usage of tpm2_encryptdecrypt?
The current TPM backend is written using the SAPI, update it to use ESAPI.
The current key_gen returns just two dummy handles, which would confuse an application using this functionality.
Either we should return CKR_FUNCTION_NOT_SUPPORTED for now, or better implement / re-enable the code.
Implement C_InitPin
Full pkcs11 log:
0: C_GetFunctionList
2018-11-15 20:19:38.963
Returned: 0 CKR_OK
1: C_Initialize
2018-11-15 20:19:38.963
[in] pInitArgs = 0x7e8c2d08
flags: 2
CKF_OS_LOCKING_OK
Returned: 0 CKR_OK
2: C_GetSlotList
2018-11-15 20:19:38.972
[in] tokenPresent = 0x1
[out] pSlotList:
Count is 1
[out] *pulCount = 0x1
Returned: 0 CKR_OK
3: C_GetSlotList
2018-11-15 20:19:38.973
[in] tokenPresent = 0x1
[out] pSlotList:
Slot 1
[out] *pulCount = 0x1
Returned: 0 CKR_OK
4: C_GetTokenInfo
2018-11-15 20:19:38.974
[in] slotID = 0x1
[out] pInfo:
label: 'testtokens '
manufacturerID: 'Intel '
model: 'TPM2 PKCS#11 '
serialNumber: '0000000000000000'
ulMaxSessionCount: 1024
ulSessionCount: 0
ulMaxRwSessionCount: 1024
ulRwSessionCount: 0
ulMaxPinLen: 128
ulMinPinLen: 5
ulTotalPublicMemory: -1
ulFreePublicMemory: -1
ulTotalPrivateMemory: -1
ulFreePrivateMemory: -1
hardwareVersion: 0.0
firmwareVersion: 0.0
time: ' 20181115191938'
flags: 405
CKF_RNG
CKF_LOGIN_REQUIRED
CKF_TOKEN_INITIALIZED
Returned: 0 CKR_OK
5: C_OpenSession
2018-11-15 20:19:38.976
[in] slotID = 0x1
[in] flags = 0x6
pApplication=(nil)
Notify=(nil)
[out] *phSession = 0x1000000
Returned: 0 CKR_OK
6: C_Login
2018-11-15 20:19:39.046
[in] hSession = 0x1000000
[in] userType = CKU_USER
[in] pPin[ulPinLen] 01a8ae20 / 6
00000000 31 32 33 34 35 36 123456
Returned: 0 CKR_OK
7: C_GetSlotList
2018-11-15 20:19:40.538
[in] tokenPresent = 0x1
[out] pSlotList:
Count is 1
[out] *pulCount = 0x1
Returned: 0 CKR_OK
8: C_GetSlotList
2018-11-15 20:19:40.538
[in] tokenPresent = 0x1
[out] pSlotList:
Slot 1
[out] *pulCount = 0x1
Returned: 0 CKR_OK
9: C_GetSlotInfo
2018-11-15 20:19:40.539
[in] slotID = 0x1
[out] pInfo:
slotDescription: 'bar '
' '
manufacturerID: 'foo '
hardwareVersion: 42.42
firmwareVersion: 13.13
flags: 5
CKF_TOKEN_PRESENT
CKF_HW_SLOT
Returned: 0 CKR_OK
10: C_GetTokenInfo
2018-11-15 20:19:40.539
[in] slotID = 0x1
[out] pInfo:
label: 'testtokens '
manufacturerID: 'Intel '
model: 'TPM2 PKCS#11 '
serialNumber: '0000000000000000'
ulMaxSessionCount: 1024
ulSessionCount: 1
ulMaxRwSessionCount: 1024
ulRwSessionCount: 1
ulMaxPinLen: 128
ulMinPinLen: 5
ulTotalPublicMemory: -1
ulFreePublicMemory: -1
ulTotalPrivateMemory: -1
ulFreePrivateMemory: -1
hardwareVersion: 0.0
firmwareVersion: 0.0
time: ' 20181115191940'
flags: 405
CKF_RNG
CKF_LOGIN_REQUIRED
CKF_TOKEN_INITIALIZED
Returned: 0 CKR_OK
11: C_OpenSession
2018-11-15 20:19:40.539
[in] slotID = 0x1
[in] flags = 0x6
pApplication=(nil)
Notify=(nil)
[out] *phSession = 0x1000001
Returned: 0 CKR_OK
12: C_Login
2018-11-15 20:19:40.540
[in] hSession = 0x1000001
[in] userType = CKU_USER
[in] pPin[ulPinLen] 01a8ae20 / 6
00000000 31 32 33 34 35 36 123456
pkcs11app: src/lib/session_ctx.c:310: session_ctx_login: Assertion `t->login_session_ctx == NULL' failed.
Any advise? Looks like tpm2-tools for tpm2_createprimary does not have option -p but -P instead?..
$ tpm2_ptool.py init --pobj-pin=mypobjpin --path=~/tmp
Traceback (most recent call last):
File "/home/user/Documents/tpm2-software/tpm2-pkcs11/tools/tpm2_ptool.py", line 686, in call
ctx = tpm2.createprimary(ownerauth, pobjauth)
File "/home/user/Documents/tpm2-software/tpm2-pkcs11/tools/tpm2_ptool.py", line 146, in createprimary
raise RuntimeError("Could not execute tpm2_createprimary: %s" % stderr)
RuntimeError: Could not execute tpm2_createprimary: tpm2_createprimary: invalid option -- 'p'
Could not execute tpm2_createprimary: tpm2_createprimary: invalid option -- 'p'
$ tpm2_createprimary
Usage: tpm2_createprimary []
Where are:
[ -H | --hierarchy=] [ -P | --pwdp=] [ -K | --pwdk=] [ -g | --halg=]
[ -G | --kalg=] [ -C | --context=] [ -L | --policy-file=] [ -A | --object-attributes=]
[ -S | --input-session-handle=] [ - | --(null)]
Some application which use NSS (like Firefox or Chrome) or gnupg-pkcs11-scd only use the keys in conjunction with the certificate provided by the pkcs#11 interface. Therefore support is needed to store certificates in the tpm2-pkcs11 database so they can be queried by the application.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.