Skip to content

Conversation

@frankmorgner
Copy link
Member

Fixes #2300

Note, that I've used sc_mem_secure_alloc() for saving the input data.

Checklist
  • PKCS#11 module is tested
  • Windows minidriver is tested
  • macOS tokend is tested


sc_mem_clear(buf, sizeof(buf));
err:
sc_mem_secure_free(buf, buflen);
Copy link
Member

Choose a reason for hiding this comment

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

would it make sense to keep the sc_mem_clear() here to zeroize the memory before freeing?

if (inlen < modlen) {
if (modlen > sizeof(buf))
if (modlen > buflen)
return SC_ERROR_BUFFER_TOO_SMALL;
Copy link
Member

Choose a reason for hiding this comment

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

goto err;

if (!data)
return;
sc_pkcs11_release_operation(&data->md);
sc_mem_secure_free(data->buffer, data->buffer_len);
Copy link
Member

Choose a reason for hiding this comment

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

would it make sense to do sc_mem_clear() here too as it was in the previous implementation or using the secure memory implies this somehow (might be worth mentioning in comment?)?

@Jakuje
Copy link
Member

Jakuje commented Aug 24, 2021

@frankmorgner did you get back to my review comments?

@frankmorgner
Copy link
Member Author

Thanks for the reminder, all comments should be fixed now.

There isn't a single case where we should call sc_secure_free without the need for clearing the memory. Therefor I've added sc_secure_clear_free(), which is used instead.

@frankmorgner frankmorgner merged commit 6d580ac into OpenSC:master Aug 31, 2021
@Jakuje
Copy link
Member

Jakuje commented Aug 31, 2021

I got back to this to verify it works as expected. I am able to sign arbitrary sizes with SoftHSM, but with Nitrokey (through OpenSC), I get only up to 256 bytes, for 384 and 512 bytes, I am getting CKR_FUNCTION_FAILED and for 640 and larger, I have just CKR_GENERAL_ERROR.

I was not able to figure out if the gnuk/nitrokey is supposed to support chaining or not from its source code. Certainly the card response weirdly to the chained APDUs, which is something I would like to investigate later.

But this PR is fine anyway.

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.

[RFC] OpenSC should allow to sign data with length more than 512 bytes.

2 participants