Skip to content

Commit ae385ea

Browse files
ukernelidryomov
authored andcommitted
libceph: store session key in cephx authorizer
Session key is required when calculating message signature. Save the session key in authorizer, this avoid lookup ticket handler for each message Signed-off-by: Yan, Zheng <zyan@redhat.com>
1 parent e96a650 commit ae385ea

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

‎net/ceph/auth_x.c‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,11 @@ static int ceph_x_build_authorizer(struct ceph_auth_client *ac,
293293
dout("build_authorizer for %s %p\n",
294294
ceph_entity_type_name(th->service), au);
295295

296+
ceph_crypto_key_destroy(&au->session_key);
297+
ret = ceph_crypto_key_clone(&au->session_key, &th->session_key);
298+
if (ret)
299+
return ret;
300+
296301
maxlen = sizeof(*msg_a) + sizeof(msg_b) +
297302
ceph_x_encrypt_buflen(ticket_blob_len);
298303
dout(" need len %d\n", maxlen);
@@ -302,8 +307,10 @@ static int ceph_x_build_authorizer(struct ceph_auth_client *ac,
302307
}
303308
if (!au->buf) {
304309
au->buf = ceph_buffer_new(maxlen, GFP_NOFS);
305-
if (!au->buf)
310+
if (!au->buf) {
311+
ceph_crypto_key_destroy(&au->session_key);
306312
return -ENOMEM;
313+
}
307314
}
308315
au->service = th->service;
309316
au->secret_id = th->secret_id;
@@ -329,7 +336,7 @@ static int ceph_x_build_authorizer(struct ceph_auth_client *ac,
329336
get_random_bytes(&au->nonce, sizeof(au->nonce));
330337
msg_b.struct_v = 1;
331338
msg_b.nonce = cpu_to_le64(au->nonce);
332-
ret = ceph_x_encrypt(&th->session_key, &msg_b, sizeof(msg_b),
339+
ret = ceph_x_encrypt(&au->session_key, &msg_b, sizeof(msg_b),
333340
p, end - p);
334341
if (ret < 0)
335342
goto out_buf;
@@ -588,17 +595,13 @@ static int ceph_x_verify_authorizer_reply(struct ceph_auth_client *ac,
588595
struct ceph_authorizer *a, size_t len)
589596
{
590597
struct ceph_x_authorizer *au = (void *)a;
591-
struct ceph_x_ticket_handler *th;
592598
int ret = 0;
593599
struct ceph_x_authorize_reply reply;
594600
void *preply = &reply;
595601
void *p = au->reply_buf;
596602
void *end = p + sizeof(au->reply_buf);
597603

598-
th = get_ticket_handler(ac, au->service);
599-
if (IS_ERR(th))
600-
return PTR_ERR(th);
601-
ret = ceph_x_decrypt(&th->session_key, &p, end, &preply, sizeof(reply));
604+
ret = ceph_x_decrypt(&au->session_key, &p, end, &preply, sizeof(reply));
602605
if (ret < 0)
603606
return ret;
604607
if (ret != sizeof(reply))
@@ -618,6 +621,7 @@ static void ceph_x_destroy_authorizer(struct ceph_auth_client *ac,
618621
{
619622
struct ceph_x_authorizer *au = (void *)a;
620623

624+
ceph_crypto_key_destroy(&au->session_key);
621625
ceph_buffer_put(au->buf);
622626
kfree(au);
623627
}

‎net/ceph/auth_x.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct ceph_x_ticket_handler {
2626

2727

2828
struct ceph_x_authorizer {
29+
struct ceph_crypto_key session_key;
2930
struct ceph_buffer *buf;
3031
unsigned int service;
3132
u64 nonce;

0 commit comments

Comments
 (0)