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

framework-pkcs15: Duplicate public key related to private key rather than referencing the framework object #282

Closed
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
3 participants
@CardContact
Copy link
Member

CardContact commented Sep 3, 2014

Referencing the related public key is required to return PKCS#11 attributes for a private key only available in the public key object (i.e. CKA_MODULUS). This patch adds a copy of the public key to the private key object rather than referencing the public key object in the framework. This prevents SEGV when the public key framework object is deleted with C_DestroyObject, but the reference from the public key remains intact.

The bug leads to all kind of stability problems when keys are created and deleted in the same session.

The patch is in particular important if OpenSC is used with EJBCA or any other application using the SUN PKCS#11 provider: When generating key pairs, then the public key object is eventually garbage collected which removes the related object in the PKCS#11 module. Because there is no fixed time for this operation, corruption occurs at random.

In a next step, the remaining related_xxx fields in sc_pkcs11_object should be revised and possibly removed.

Andreas Schwier
framework-pkcs15: Duplicate public key related to private key rather …
…than referencing the framework object

Referencing the related public key is required to return PKCS#11 attributes for a private key only available
in the public key object (i.e. CKA_MODULUS). This patch adds a copy of the public key to the private key object rather than
referencing the public key object in the framework. This prevents SEGV when the public key framework object
is deleted with C_DestroyObject, but the reference from the public key remains intact.

The bug leads to all kind of stability problems when keys are created and deleted in the same session.

The patch is in particular important if OpenSC is used with EJBCA or any other application using the
SUN PKCS#11 provider: When generating key pairs, then the public key object is eventually garbage collected
which removes the related object in the PKCS#11 module. Because there is no fixed time for this operation,
corruption occurs at random.

In a next step, the remaining related_xxx fields in sc_pkcs11_object should be revised and possibly removed.
@frankmorgner

This comment has been minimized.

Copy link

frankmorgner commented on src/pkcs11/framework-pkcs15.c in 9265526 Sep 3, 2014

missing error checking

@frankmorgner

This comment has been minimized.

Copy link

frankmorgner commented on src/libopensc/pkcs15-pubkey.c in 9265526 Sep 3, 2014

dont return here. instead go to the end of this function and clean up pubkey.

the same holds for the return statements below.

@CardContact

This comment has been minimized.

Copy link
Member

CardContact commented Sep 4, 2014

Dear Frank,

thanks for the review. I've added additional error checking.

Andreas

viktorTarasov added a commit to viktorTarasov/OpenSC-SM that referenced this pull request Sep 7, 2014

Merge pull request OpenSC#282 from CardContact/fix-deleted-related-pu…
…blic-key

framework-pkcs15: Duplicate public key related to private key rather than referencing the framework object

Referencing the related public key is required to return PKCS#11 attributes for a private key only available
in the public key object (i.e. CKA_MODULUS). This patch adds a copy of the public key to the private key object rather than
referencing the public key object in the framework. This prevents SEGV when the public key framework object
is deleted with C_DestroyObject, but the reference from the public key remains intact.

The bug leads to all kind of stability problems when keys are created and deleted in the same session.

The patch is in particular important if OpenSC is used with EJBCA or any other application using the
SUN PKCS#11 provider: When generating key pairs, then the public key object is eventually garbage collected
which removes the related object in the PKCS#11 module. Because there is no fixed time for this operation,
corruption occurs at random.

In a next step, the remaining related_xxx fields in sc_pkcs11_object should be revised and possibly removed.

framework: Added more error checking
@viktorTarasov

This comment has been minimized.

Copy link
Member

viktorTarasov commented Sep 7, 2014

Applied in be200ab,
thank you.

@CardContact CardContact deleted the CardContact:fix-deleted-related-public-key branch Sep 8, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment