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

pkcs11: Add TEE Identity based authentication support #236

Merged
merged 6 commits into from
Jan 7, 2021

Conversation

vesajaaskelainen
Copy link
Contributor

Please see OP-TEE/optee_os#4222 for testing and usage instructions.

Implements:
OP-TEE/optee_os#3946

Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

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

Only minor comments.
For both commits, prefer start log header line with libckteec: and add () to function labels. Also add a description line between header line and S-o-b tag in commit "C_Login: Allow NULL_PTR PIN entry.". i.e.

libckteec: Allow NULL_PTR PIN entry in C_Login()

Allow C_Login() to transport a null PIN reference as when protected
authentication path is used.

Signed-off-by: Vesa Jääskeläinen <[email protected]>

@vesajaaskelainen
Copy link
Contributor Author

Only minor comments.
For both commits, prefer start log header line with libckteec: and add () to function labels. Also add a description line between header line and S-o-b tag in commit "C_Login: Allow NULL_PTR PIN entry.". i.e.

libckteec: Allow NULL_PTR PIN entry in C_Login()

Allow C_Login() to transport a null PIN reference as when protected
authentication path is used.

Signed-off-by: Vesa Jääskeläinen <[email protected]>

OK

@vesajaaskelainen
Copy link
Contributor Author

Only minor comments.
For both commits, prefer start log header line with libckteec: and add () to function labels. Also add a description line between header line and S-o-b tag in commit "C_Login: Allow NULL_PTR PIN entry.". i.e.

libckteec: Allow NULL_PTR PIN entry in C_Login()

Allow C_Login() to transport a null PIN reference as when protected
authentication path is used.

Signed-off-by: Vesa Jääskeläinen <[email protected]>

OK

Updated commit messages.

@vesajaaskelainen
Copy link
Contributor Author

@etienne-lms I believe I have addressed all your comments.

Also tested (and fixed) PIN == NULL_PTR cases for methods that use PIN as input.

@vesajaaskelainen
Copy link
Contributor Author

I was thinking about could xtest be used here somehow but seems rather challenging as there is no API to reset the token back to initial state without performing clearing secure storage and reboot 😞. Also switching to different identities and somehow having common identities can be a bit of problem.

@etienne-lms
Copy link
Contributor

Maybe a debug command to reset a token even without the SO credentials?
The TA supports multi tokens, a token could be reserved for debug purpose, identified from its token label.

@vesajaaskelainen
Copy link
Contributor Author

Maybe a debug command to reset a token even without the SO credentials?
The TA supports multi tokens, a token could be reserved for debug purpose, identified from its token label.

If it would have some magic name then perhaps that could enable reset token feature. This magic name would just be something that normally would not be used.

What I would like to have is that we can run xtest (and other tests) on to be released TA binaries to verify that everything is still looking good and if automated tests pass then mark release gate for those TA's as tests has passed. Eg. so that the binary would be intact and no need to compile it differently.

@etienne-lms
Copy link
Contributor

Currently xtest lists the slots and picks the last last to run its tests.
We could have xtest to check the token label is "Test token for OP-TEE xtest " so we can safely scratch all even without rights.

Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

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

@ruchi393, does this change look ok to you?
@vesajaaskelainen, LGTM (with checkpatch report addressed) but I wait for OP-TEE/optee_os#4222 before posting my R-b tag.
I think this is a nice feature, thanks for sharing.

Comment on lines 267 to 268
if ((errno == ERANGE) || (tmpconv > (gid_t)-1) ||
(login_gid_env + strlen(login_gid_env) != endp)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

CI/checkpatch issue report:

4e56bdb libckteec: Use environment variables to determine OP-TEE TA login
CHECK: Unnecessary parentheses around 'errno == ERANGE'
#68: FILE: libckteec/src/invoke_ta.c:267:
+			if ((errno == ERANGE) || (tmpconv > (gid_t)-1) ||
+			    (login_gid_env + strlen(login_gid_env) != endp)) {
total: 0 errors, 0 warnings, 1 checks, 63 lines checked

I.e.:

			if (errno == ERANGE || tmpconv > (gid_t)-1 ||
			    (login_gid_env + strlen(login_gid_env) != endp)) {
				...
			}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

$ CHECKPATCH=../linux/scripts/checkpatch.pl ../optee_os/scripts/checkpatch.sh 0eaddfc570b557c39148ff2e7faccaba8e07d55a
Checking commit(s):
0eaddfc libckteec: Use environment variables to determine OP-TEE TA login
total: 0 errors, 0 warnings, 110 lines checked

"[PATCH] libckteec: Use environment variables to determine OP-TEE TA" has no obvious style problems and is ready for submission.

Where as linux == v5.10-rc1.

Then wondering the difference:

$ cp ../optee_os/scripts/checkpatch.sh scripts/
$ CHECKPATCH=../linux/scripts/checkpatch.pl scripts/checkpatch.sh 0eaddfc570b557c39148ff2e7faccaba8e07d55a
Checking commit(s):
0eaddfc libckteec: Use environment variables to determine OP-TEE TA login
CHECK: Unnecessary parentheses around 'errno == ERANGE'
#121: FILE: libckteec/src/invoke_ta.c:267:
+			if ((errno == ERANGE) || (tmpconv > (gid_t)-1) ||
+			    (login_gid_env + strlen(login_gid_env) != endp)) {

total: 0 errors, 0 warnings, 1 checks, 110 lines checked

Shall we copy the checkpatch.sh also to this repo?

@vesajaaskelainen
Copy link
Contributor Author

Just rebased on top of master.

Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

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

Reviewed-by: Etienne Carriere <[email protected]> with comment on 1st commit.

It would be nice we have something in optee_test/host/xtest/pkcts11_1000.c to test a bit this but it may tricky to test invalid identities.

Add initialization for variables as required by coding convention.

Reviewed-by: Etienne Carriere <[email protected]>
Signed-off-by: Vesa Jääskeläinen <[email protected]>
C_Initialize() needs to know what kind of OP-TEE TA login is needed.

CKTEEC_LOGIN_TYPE is used to specify login type:
 - "public" -> TEEC_LOGIN_PUBLIC
 - "user" -> TEEC_LOGIN_USER
 - "group" -> TEEC_LOGIN_GROUP

When login type is "group" then CKTEEC_LOGIN_GID must be numerical group
id.

Reviewed-by: Etienne Carriere <[email protected]>
Signed-off-by: Vesa Jääskeläinen <[email protected]>
Allow C_InitToken() to transport a null PIN reference as when protected
authentication path is used.

Specified in:

PKCS OP-TEE#11 Cryptographic Token Interface Base Specification Version 2.40
Plus Errata 01
C_InitPIN

Reviewed-by: Etienne Carriere <[email protected]>
Signed-off-by: Vesa Jääskeläinen <[email protected]>
Allow C_Login() to transport a null PIN reference as when protected
authentication path is used.

Specified in:

PKCS OP-TEE#11 Cryptographic Token Interface Base Specification Version 2.40
Plus Errata 01
C_Login

Reviewed-by: Etienne Carriere <[email protected]>
Signed-off-by: Vesa Jääskeläinen <[email protected]>
Allow C_InitPIN() to transport a null PIN reference as when protected
authentication path is used.

Specified in:

PKCS OP-TEE#11 Cryptographic Token Interface Base Specification Version 2.40
Plus Errata 01
C_InitPIN

Reviewed-by: Etienne Carriere <[email protected]>
Signed-off-by: Vesa Jääskeläinen <[email protected]>
Allow C_SetPIN() to transport a null PIN reference as when protected
authentication path is used.

Specified in:

PKCS OP-TEE#11 Cryptographic Token Interface Base Specification Version 2.40
Plus Errata 01
C_SetPIN

Reviewed-by: Etienne Carriere <[email protected]>
Signed-off-by: Vesa Jääskeläinen <[email protected]>
@vesajaaskelainen
Copy link
Contributor Author

Reviewed-by: Etienne Carriere <[email protected]> with comment on 1st commit.

Thanks for the review!

Fixed and applied tags.

@vesajaaskelainen
Copy link
Contributor Author

It would be nice we have something in optee_test/host/xtest/pkcts11_1000.c to test a bit this but it may tricky to test invalid identities.

I believe we need to improve the testing support for tokens in overall first and then we can try to add tests also for these. This is kinda integration testing not unit testing level problem as we would need to navigate to different identities in a way that people can still run xtest successfully.

I would prefer that we do these as separate things.

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.

3 participants