Session key is required when calculating message signature. Save the session key in authorizer, this avoid lookup ticket handler for each message
Unified · Split
| @@ -293,6 +293,11 @@ static int ceph_x_build_authorizer(struct ceph_auth_client *ac, · 292 unmodified lines | ||
| 293 | 293 | dout("build_authorizer for %s %p\n", |
| 294 | 294 | ceph_entity_type_name(th->service), au); |
| 295 | 295 | |
| 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 | + | |
| 296 | 301 | maxlen = sizeof(*msg_a) + sizeof(msg_b) + |
| 297 | 302 | ceph_x_encrypt_buflen(ticket_blob_len); |
| 298 | 303 | dout(" need len %d\n", maxlen); |
| @@ -302,8 +307,10 @@ static int ceph_x_build_authorizer(struct ceph_auth_client *ac, · 3 unmodified lines | ||
| 302 | 307 | } |
| 303 | 308 | if (!au->buf) { |
| 304 | 309 | au->buf = ceph_buffer_new(maxlen, GFP_NOFS); |
| 305 | − if (!au->buf) | |
| 310 | + if (!au->buf) { | |
| 311 | + ceph_crypto_key_destroy(&au->session_key); | |
| 306 | 312 | return -ENOMEM; |
| 313 | + } | |
| 307 | 314 | } |
| 308 | 315 | au->service = th->service; |
| 309 | 316 | au->secret_id = th->secret_id; |
| @@ -329,7 +336,7 @@ static int ceph_x_build_authorizer(struct ceph_auth_client *ac, · 19 unmodified lines | ||
| 329 | 336 | get_random_bytes(&au->nonce, sizeof(au->nonce)); |
| 330 | 337 | msg_b.struct_v = 1; |
| 331 | 338 | 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), | |
| 333 | 340 | p, end - p); |
| 334 | 341 | if (ret < 0) |
| 335 | 342 | goto out_buf; |
| @@ -588,17 +595,13 @@ static int ceph_x_verify_authorizer_reply(struct ceph_auth_client *ac, · 252 unmodified lines | ||
| 588 | 595 | struct ceph_authorizer *a, size_t len) |
| 589 | 596 | { |
| 590 | 597 | struct ceph_x_authorizer *au = (void *)a; |
| 591 | − struct ceph_x_ticket_handler *th; | |
| 592 | 598 | int ret = 0; |
| 593 | 599 | struct ceph_x_authorize_reply reply; |
| 594 | 600 | void *preply = &reply; |
| 595 | 601 | void *p = au->reply_buf; |
| 596 | 602 | void *end = p + sizeof(au->reply_buf); |
| 597 | 603 | |
| 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)); | |
| 602 | 605 | if (ret < 0) |
| 603 | 606 | return ret; |
| 604 | 607 | if (ret != sizeof(reply)) |
| @@ -618,6 +621,7 @@ static void ceph_x_destroy_authorizer(struct ceph_auth_client *ac, · 13 unmodified lines | ||
| 618 | 621 | { |
| 619 | 622 | struct ceph_x_authorizer *au = (void *)a; |
| 620 | 623 | |
| 624 | + ceph_crypto_key_destroy(&au->session_key); | |
| 621 | 625 | ceph_buffer_put(au->buf); |
| 622 | 626 | kfree(au); |
| 623 | 627 | } |
| @@ -26,6 +26,7 @@ struct ceph_x_ticket_handler { · 25 unmodified lines | ||
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | struct ceph_x_authorizer { |
| 29 | + struct ceph_crypto_key session_key; | |
| 29 | 30 | struct ceph_buffer *buf; |
| 30 | 31 | unsigned int service; |
| 31 | 32 | u64 nonce; |