Skip to content

Commit

Permalink
rpc: Fix serialization of NULL mechanism pointer
Browse files Browse the repository at this point in the history
A NULL mechanism pointer is valid for C_*Init functions to cancel the
operation.  Since 852ccd8 we encoded it with a CK_MECHANISM_TYPE 0 as
an indicator, though it clashes with CKM_RSA_PKCS_KEY_PAIR_GEN (0).
This patch changes the encoding to use a special value (0xffffffff) to
indicate that and also properly advance the offset when reading.

Signed-off-by: Daiki Ueno <[email protected]>
  • Loading branch information
ueno committed Nov 14, 2023
1 parent 66d6b42 commit 36da777
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions p11-kit/rpc-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,12 @@ proto_write_mechanism (p11_rpc_message *msg,
/* Make sure this is in the right order */
assert (!msg->signature || p11_rpc_message_verify_part (msg, "M"));

/* This case is valid for C_*Init () functions to cancel operation */
/*
* The NULL mech is used for C_*Init () functions to cancel operation.
* We use 0xffffffff as a marker to indicate that.
*/
if (mech == NULL) {
p11_rpc_buffer_add_uint32 (msg->output, 0);
p11_rpc_buffer_add_uint32 (msg->output, 0xffffffff);
return p11_buffer_failed (msg->output) ? CKR_HOST_MEMORY : CKR_OK;
}

Expand Down
7 changes: 6 additions & 1 deletion p11-kit/rpc-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,13 @@ proto_read_mechanism (p11_rpc_message *msg,
return PARSE_ERROR;
}

if (temp.mechanism == 0) {
/*
* The NULL mech is used for C_*Init () functions to cancel operation.
* We use 0xffffffff as a marker to indicate that.
*/
if (temp.mechanism == 0xffffffff) {
*mech = NULL;
msg->parsed = offset;
return CKR_OK;
}

Expand Down

0 comments on commit 36da777

Please sign in to comment.