Skip to content
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

[RFC] libsks for Pkcs#11 services through OP-TEE SKS TA #138

Merged
merged 8 commits into from
Jan 31, 2020

Conversation

etienne-lms
Copy link
Contributor

@etienne-lms etienne-lms commented Jan 11, 2019

This change introduces an implementation of the Pkcs#11 Cryptoki library that interface a specific trusted application in the secure side provided by the optee_os source tree.

This P-R implements the basics for the client library. The effective implementation of the services will come later. However this P-R still introduces a first TA command for this initial P-R to at least invoke the SKS TA to check it is available when library is initialized.

This P-R does not introduce the full TA API itself that is being reviewed through (edited: OP-TEE/optee_os#2732). The client library will integrate the released TA API once its is approved and merged in optee_os mainline.

This P-R replaces #121.

edited, url of TA API P-R and below
#139 proposes the first commits of this RFC.

libsks/src/invoke_ta.c Outdated Show resolved Hide resolved
@etienne-lms etienne-lms changed the title libsks for Pkcs#11 services through OP-TEE SKS TA [RFC] libsks for Pkcs#11 services through OP-TEE SKS TA Jan 23, 2019
Copy link

@wamserma wamserma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit more review

libsks/CMakeLists.txt Outdated Show resolved Hide resolved
libsks/include/sks_ta.h Outdated Show resolved Hide resolved
Copy link

@wamserma wamserma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general, possible errors in the function parameters can still be weeded out when the functions are actually implemented.

libsks/Makefile Outdated Show resolved Hide resolved
libsks/include/pkcs11.h Outdated Show resolved Hide resolved
libsks/src/pkcs11_api.c Outdated Show resolved Hide resolved
libsks/src/pkcs11_api.c Outdated Show resolved Hide resolved
libsks/src/pkcs11_api.c Outdated Show resolved Hide resolved
libsks/src/pkcs11_api.c Outdated Show resolved Hide resolved
libsks/src/pkcs11_api.c Outdated Show resolved Hide resolved
@etienne-lms
Copy link
Contributor Author

Minor question but to be clarified asap if possible: since removing the SKS meaningless acronym, I'm looking for a nice name for the client library. Not too small, not too long, to address a cryptoki integration ina GTD TEE env (as OP-TEE is).
I am thinking of libcryptokioptee, libckteec, libckoptee. Any other artistic idea?

@etienne-lms
Copy link
Contributor Author

Refer to OP-TEE/optee_test#281 (comment) for running the basic test.

@jenswi-linaro
Copy link
Contributor

I'd prefer libckteec, but I don't have a strong opinion on this.

@etienne-lms
Copy link
Contributor Author

let's go for libckteec. short and still refers to both libteec and cryptoki/ck.

Copy link
Contributor

@jenswi-linaro jenswi-linaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments for the commit "libckteec: Introduce PKCS#11 API (2.40-e01) header"

libckteec/include/pkcs11.h Outdated Show resolved Hide resolved
libckteec/include/pkcs11.h Outdated Show resolved Hide resolved
Copy link
Contributor

@jenswi-linaro jenswi-linaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments for the commit "libckteec: fully stubbed cryptoki API"

Makefile Outdated Show resolved Hide resolved
libckteec/CMakeLists.txt Show resolved Hide resolved
libckteec/Makefile Show resolved Hide resolved
libckteec/CMakeLists.txt Show resolved Hide resolved
Copy link
Contributor

@jenswi-linaro jenswi-linaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment for the commit "libckteec: local utilities":

There's no ASSERT defined in this commit, please update the commit message.

libckteec/src/local_utils.h Outdated Show resolved Hide resolved
Copy link
Contributor

@jenswi-linaro jenswi-linaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the commit "libckteec: implement C_GetFunctionList()":
Acked-by: Jens Wiklander <[email protected]>

Copy link
Contributor

@jenswi-linaro jenswi-linaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment for "libckteec: introduce minimal PKCS11 TA API"

libckteec/include/pkcs11_ta.h Show resolved Hide resolved
Copy link
Contributor

@jenswi-linaro jenswi-linaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment for the commit "libckteec: helpers for Cryptoki/PKCS11 TA IDs conversion"

libckteec/src/ck_helpers.h Outdated Show resolved Hide resolved
Copy link
Contributor

@jenswi-linaro jenswi-linaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment for the commit "libckteec: debug helpers for PKCS#11 IDs as strings"

libckteec/src/ck_debug.c Outdated Show resolved Hide resolved
Copy link
Contributor

@jenswi-linaro jenswi-linaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments for commit "libckteec: generic invocation of the PKCS11 TA"

libckteec/src/invoke_ta.c Outdated Show resolved Hide resolved
libckteec/src/invoke_ta.c Outdated Show resolved Hide resolved
libckteec/src/invoke_ta.h Outdated Show resolved Hide resolved
libckteec/src/invoke_ta.c Outdated Show resolved Hide resolved
libckteec/src/invoke_ta.h Outdated Show resolved Hide resolved
Copy link
Contributor

@jenswi-linaro jenswi-linaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments for "libckteec: sanity on APIs regarding library initialization"

libckteec/src/pkcs11_api.c Outdated Show resolved Hide resolved
libckteec/src/pkcs11_api.c Show resolved Hide resolved
libckteec/src/invoke_ta.c Outdated Show resolved Hide resolved
@etienne-lms
Copy link
Contributor Author

Hello,
I will submit soon an update of this P-R. Syncing with TA API exported from OP-TEE/optee_os#2733, I must discard few commits about ID conversions originally in this optee_client series. Also I will fully rewrite commit 'libckteec: generic invocation of the PKCS11 TA", not append fixup commit on top of it, since it needed lot of changes.

@jenswi-linaro
Copy link
Contributor

For commit "libckteec: local utilities" + fixup:
Reviewed-by: Jens Wiklander <[email protected]>

@jenswi-linaro
Copy link
Contributor

For commit "libckteec: generic invocation of the PKCS11 TA":
Reviewed-by: Jens Wiklander <[email protected]>

@jenswi-linaro
Copy link
Contributor

For commit "libckteec: sanity on APIs regarding library initialization":
Reviewed-by: Jens Wiklander <[email protected]>

@etienne-lms
Copy link
Contributor Author

Added late fixup on top of the series for an issue reported by Travis.
Also saw few issues (missing #include <> and few commit messages to be updated).
Here is the new series with tags applied where applicable.

@jenswi-linaro
Copy link
Contributor

Please rebase on master to include checkpatch in the review.

@etienne-lms
Copy link
Contributor Author

Update for checkpatch compliance. I squashed all fixup related to checkpatch complains in "libckteec: Introduce PKCS#11 API (2.40-e01) header …".

I see there are still failures. Most I'll fix. But there ar esome I don't understand what wring with:

  • ARRAY_SIZE. What wrong with the label?
total: 0 errors, 0 warnings, 1 checks, 96 lines checked
47f5399 libckteec: local utilities
WARNING: Prefer ARRAY_SIZE(array)
#29: FILE: libckteec/src/local_utils.h:9:
+#define ARRAY_SIZE(array)	(sizeof(array) / sizeof(array[0]))
  • BIT() macro. There is no standard header file for BIT() hence I prefer to not rely on BIT in the user client API header file.
total: 0 errors, 0 warnings, 3 checks, 1020 lines checked
a86e8c1 libckteec: Introduce PKCS#11 API (2.40-e01) header
CHECK: Prefer using the BIT macro
#158: FILE: libckteec/include/pkcs11.h:93:
+#define CKF_ARRAY_ATTRIBUTE		(1U << 30)

@jenswi-linaro
Copy link
Contributor

I'm fine with ignoring the BIT() and ARRAY_SIZE() warnings.

@jenswi-linaro
Copy link
Contributor

Let me know when you're done with the current updates and I'll go through it once more.

@etienne-lms
Copy link
Contributor Author

Another fixup commit for "libckteec: implement C_GetFunctionList()" (R-b tagged). b16330b simplifies the code the comply with checkpatch.
I will squash the 2 fixup commits (b16330b and a9bc912) if you agree.

@etienne-lms
Copy link
Contributor Author

I am done with the updates.

@jenswi-linaro
Copy link
Contributor

Looks good to me.
Acked-by: Jens Wiklander <[email protected]>

Library ckteec will implement the PKCS#11 API using the PKCS11 trusted
application executing in OP-TEE as backend token.

Implement  pkcs11.h header file that partially covers the PKCS#11
specification. Resources initially planned to be supported are defined.
The header will need to be updated with remaining PKCS#11 definition
when related support will be implemented.

Signed-off-by: Etienne Carriere <[email protected]>
Acked-by: Jens Wiklander <[email protected]>
Define the few platform macros expected by the cryptolib header files.
Initial source file: the API functions from pkcs11_api.c.

Builds from Makefile or from CMake.

Signed-off-by: Etienne Carriere <[email protected]>
Acked-by: Jens Wiklander <[email protected]>
Define ARRAY_SIZE() helper macros for library internal purposes.

Signed-off-by: Etienne Carriere <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
C_GetFunctionList() returns the list of the functions supported by
the PKCS#11 implementation.

Signed-off-by: Etienne Carriere <[email protected]>
Acked-by: Jens Wiklander <[email protected]>
Introduce the PKCS11 TA API (pkcs11_ta.h) with only 1 command defined
and the PKCS11 return code values.

Command PKCS11_CMD_PING is used when initializing the library to check
PKCS11 TA availability and compatibility (version info).

Signed-off-by: Etienne Carriere <[email protected]>
Acked-by: Jens Wiklander <[email protected]>
The PKCS11 TA uses IDs that mostly relate to defined PKCS#11 IDs
but with different numerical value. These helpers convert PKCS#11
IDs into/from PKCS11 TA IDs.

This change introduces conversion from GPD TEE Client error codes
into CryptoKi return values.

Signed-off-by: Etienne Carriere <[email protected]>
Acked-by: Jens Wiklander <[email protected]>
Library opens a single TEE session against the PKCS11 TA regardless of
the PKCS#11 token reached in the TA.

Signed-off-by: Etienne Carriere <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
PKCS#11 specifies library must be initialized prior being used
but for 2 API functions, C_Initialize() and C_GetFunctionList().

Library initialization first invokes the PKCS11 TA and check its
availability and version information.

Signed-off-by: Etienne Carriere <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
@etienne-lms
Copy link
Contributor Author

squashed. tags applied.

@jbech-linaro
Copy link
Contributor

FYI, I've noticed that this PR breaks the make optee-client-common in build.git. Haven't checked if it is just a missing flag or if it's actually broken. Looks like CMake files have been updated, but not the GNU make files.

$ cd build && make -j`nproc` optee-client-common                                         
make -C /home/jbech/devel/optee_projects/qemu/build/../optee_client CROSS_COMPILE="/usr/bin/ccache /home/jbech/devel/optee_projects/qemu/build/../toolchains/aarch32/bin/arm-linux-gnueabihf-
" CFG_TEE_BENCHMARK=n CFG_TA_TEST_PATH=y          
make[1]: Entering directory '/home/jbech/devel/optee_projects/qemu/optee_client'
Building libteec.so                                                     
Building libckteec.so                 
  CC      src/ck_helpers.c                                     
  CC      src/pkcs11_api.c                                 
  CC      src/invoke_ta.c
  CC      src/tee_client_api.c                                          
  CC      src/teec_trace.c                                                
  LINK    /home/jbech/devel/optee_projects/qemu/optee_client/libckteec/../out/libckteec/libckteec.so.0.1.0
  AR      /home/jbech/devel/optee_projects/qemu/optee_client/libckteec/../out/libckteec/libckteec.a
/home/jbech/devel/optee_projects/reference/toolchains/aarch32/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lteec
collect2: error: ld returned 1 exit status                            
Makefile:47: recipe for target '/home/jbech/devel/optee_projects/qemu/optee_client/libckteec/../out/libckteec/libckteec.so.0.1.0' failed
make[2]: *** [/home/jbech/devel/optee_projects/qemu/optee_client/libckteec/../out/libckteec/libckteec.so.0.1.0] Error 1
Makefile:40: recipe for target 'build-libckteec' failed                  
make[1]: *** [build-libckteec] Error 2     
make[1]: *** Waiting for unfinished jobs....                     
  AR      /home/jbech/devel/optee_projects/qemu/optee_client/libteec/../out/libteec/libteec.a
  LINK    /home/jbech/devel/optee_projects/qemu/optee_client/libteec/../out/libteec/libteec.so.1.0.0
                                                       
make[1]: Leaving directory '/home/jbech/devel/optee_projects/qemu/optee_client'
common.mk:413: recipe for target 'optee-client-common' failed
make: *** [optee-client-common] Error 2

@jforissier
Copy link
Contributor

@jbech-linaro I've noticed that too, does not happen every time. Now I have double checked, it's just a missing dependency. I'll create a PR.

@jforissier
Copy link
Contributor

#183

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants