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

ta: pkcs11: Add implementation for random number generation #4383

Merged
merged 2 commits into from
Feb 15, 2021

Conversation

vesajaaskelainen
Copy link
Contributor

Add code for handling C_SeedRandom() and C_GenerateRandom() functionality.

Relates to:
#4283

Goes with:
OP-TEE/optee_client#256
OP-TEE/optee_test#487

if (!buffer)
return PKCS11_CKR_DEVICE_MEMORY;

TEE_GenerateRandom(buffer, out->memref.size);
Copy link
Contributor Author

@vesajaaskelainen vesajaaskelainen Feb 10, 2021

Choose a reason for hiding this comment

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

I did not understand why trusted_keys's TEE_GenerateRandom() doesn't require TEE_Malloc():
https://github.com/OP-TEE/optee_os/blob/master/ta/trusted_keys/entry.c#L45

Tried to observe from GlobalPlatform specification and did not notice why there is required to have ACL check in TEE_GenerateRandom():
https://github.com/OP-TEE/optee_os/blob/master/core/tee/tee_svc_cryp.c#L3200

So should that be relaxed a bit or does trusted_keys also need fixing?

Copy link
Contributor

@jforissier jforissier Feb 10, 2021

Choose a reason for hiding this comment

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

TEE_GenerateRandom() has a [out] annotation on the randomBuffer pointer which means (among other things) that it must reside in shared memory, in other words it must be private to the TA.

So yes I would think trusted_keys needs fixing. How is it tested? It seems not :-/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK found the annotation description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a note about trusted_keys -- Linux kernel has optee-rng driver which when configured should provide additional seed to Linux kernel's already good RNG -- so I don't understand why there is separate entry point for this -- but I leave this to others to resolve.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jforissier

So yes I would think trusted_keys needs fixing. How is it tested? It seems not :-/

Its tested but I don't think its tested after this patch [1] which has switched to stricter memory requirements for randomBuffer to reside in TA private memory only. So will fix it using TEE_Malloc() instead.

[1] e12c9f6

@vesajaaskelainen Trusted Keys in Linux are meant to be generated, sealed and unsealed via trust source only. See this [2] discussion for reference.

[2] https://lore.kernel.org/linux-integrity/CAE=NcrY3BTvD-L2XP6bsO=9oAJLtSD0wYpUymVkAGAnYObsPzQ@mail.gmail.com/T/#t

Copy link
Contributor

@jforissier jforissier Feb 16, 2021

Choose a reason for hiding this comment

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

@b49020 thanks for following up on this. Note, when I wrote it seemed not tested I didn't mean to say you tested poorly 😉 but that we don't have a systematic test in optee_test for instance. Which would be nice to have once all the dependencies are stable.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree to have a systematic test in optee_test. See related discussion here [1].

[1] OP-TEE/optee_test#488

ta/pkcs11/src/pkcs11_token.c Outdated Show resolved Hide resolved
ta/pkcs11/src/pkcs11_token.c Outdated Show resolved Hide resolved
ta/pkcs11/src/pkcs11_token.c Outdated Show resolved Hide resolved
@vesajaaskelainen
Copy link
Contributor Author

Updated with the comments.

@ruchi393
Copy link

Thanks @vesajaaskelainen . Patches LGTM.

ta/pkcs11/src/pkcs11_token.c Outdated Show resolved Hide resolved
ta/pkcs11/src/pkcs11_token.c Outdated Show resolved Hide resolved
ta/pkcs11/src/pkcs11_token.c Outdated Show resolved Hide resolved
ta/pkcs11/src/pkcs11_token.c Outdated Show resolved Hide resolved
ta/pkcs11/src/pkcs11_token.c Outdated Show resolved Hide resolved
@vesajaaskelainen
Copy link
Contributor Author

Updated with the review comments.

@etienne-lms
Copy link
Contributor

Reviewed-by: Etienne Carriere <[email protected]>

@ruchi393
Copy link

Reviewed-by: Ruchika Gupta <[email protected]>

Allocate command IDs for C_SeedRandom() and C_GenerateRandom()
functionality.

Reviewed-by: Ruchika Gupta <[email protected]>
Reviewed-by: Etienne Carriere <[email protected]>
Signed-off-by: Vesa Jääskeläinen <[email protected]>
Add code for handling C_SeedRandom() and C_GenerateRandom() functionality.

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

Thanks!

Tags applied.

@jforissier jforissier merged commit 22587dc into OP-TEE:master Feb 15, 2021
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