diff options
| -rw-r--r-- | net/ceph/auth_x.c | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/net/ceph/auth_x.c b/net/ceph/auth_x.c index cd1118d106a5..61cccb93f653 100644 --- a/net/ceph/auth_x.c +++ b/net/ceph/auth_x.c | |||
| @@ -290,6 +290,38 @@ bad: | |||
| 290 | return -EINVAL; | 290 | return -EINVAL; |
| 291 | } | 291 | } |
| 292 | 292 | ||
| 293 | /* | ||
| 294 | * Encode and encrypt the second part (ceph_x_authorize_b) of the | ||
| 295 | * authorizer. The first part (ceph_x_authorize_a) should already be | ||
| 296 | * encoded. | ||
| 297 | */ | ||
| 298 | static int encrypt_authorizer(struct ceph_x_authorizer *au) | ||
| 299 | { | ||
| 300 | struct ceph_x_authorize_a *msg_a; | ||
| 301 | struct ceph_x_authorize_b *msg_b; | ||
| 302 | void *p, *end; | ||
| 303 | int ret; | ||
| 304 | |||
| 305 | msg_a = au->buf->vec.iov_base; | ||
| 306 | WARN_ON(msg_a->ticket_blob.secret_id != cpu_to_le64(au->secret_id)); | ||
| 307 | p = (void *)(msg_a + 1) + le32_to_cpu(msg_a->ticket_blob.blob_len); | ||
| 308 | end = au->buf->vec.iov_base + au->buf->vec.iov_len; | ||
| 309 | |||
| 310 | msg_b = p + ceph_x_encrypt_offset(); | ||
| 311 | msg_b->struct_v = 1; | ||
| 312 | msg_b->nonce = cpu_to_le64(au->nonce); | ||
| 313 | |||
| 314 | ret = ceph_x_encrypt(&au->session_key, p, end - p, sizeof(*msg_b)); | ||
| 315 | if (ret < 0) | ||
| 316 | return ret; | ||
| 317 | |||
| 318 | p += ret; | ||
| 319 | WARN_ON(p > end); | ||
| 320 | au->buf->vec.iov_len = p - au->buf->vec.iov_base; | ||
| 321 | |||
| 322 | return 0; | ||
| 323 | } | ||
| 324 | |||
| 293 | static void ceph_x_authorizer_cleanup(struct ceph_x_authorizer *au) | 325 | static void ceph_x_authorizer_cleanup(struct ceph_x_authorizer *au) |
| 294 | { | 326 | { |
| 295 | ceph_crypto_key_destroy(&au->session_key); | 327 | ceph_crypto_key_destroy(&au->session_key); |
| @@ -306,7 +338,6 @@ static int ceph_x_build_authorizer(struct ceph_auth_client *ac, | |||
| 306 | int maxlen; | 338 | int maxlen; |
| 307 | struct ceph_x_authorize_a *msg_a; | 339 | struct ceph_x_authorize_a *msg_a; |
| 308 | struct ceph_x_authorize_b *msg_b; | 340 | struct ceph_x_authorize_b *msg_b; |
| 309 | void *p, *end; | ||
| 310 | int ret; | 341 | int ret; |
| 311 | int ticket_blob_len = | 342 | int ticket_blob_len = |
| 312 | (th->ticket_blob ? th->ticket_blob->vec.iov_len : 0); | 343 | (th->ticket_blob ? th->ticket_blob->vec.iov_len : 0); |
| @@ -350,21 +381,13 @@ static int ceph_x_build_authorizer(struct ceph_auth_client *ac, | |||
| 350 | dout(" th %p secret_id %lld %lld\n", th, th->secret_id, | 381 | dout(" th %p secret_id %lld %lld\n", th, th->secret_id, |
| 351 | le64_to_cpu(msg_a->ticket_blob.secret_id)); | 382 | le64_to_cpu(msg_a->ticket_blob.secret_id)); |
| 352 | 383 | ||
| 353 | p = msg_a + 1; | ||
| 354 | p += ticket_blob_len; | ||
| 355 | end = au->buf->vec.iov_base + au->buf->vec.iov_len; | ||
| 356 | |||
| 357 | msg_b = p + ceph_x_encrypt_offset(); | ||
| 358 | msg_b->struct_v = 1; | ||
| 359 | get_random_bytes(&au->nonce, sizeof(au->nonce)); | 384 | get_random_bytes(&au->nonce, sizeof(au->nonce)); |
| 360 | msg_b->nonce = cpu_to_le64(au->nonce); | 385 | ret = encrypt_authorizer(au); |
| 361 | ret = ceph_x_encrypt(&au->session_key, p, end - p, sizeof(*msg_b)); | 386 | if (ret) { |
| 362 | if (ret < 0) | 387 | pr_err("failed to encrypt authorizer: %d", ret); |
| 363 | goto out_au; | 388 | goto out_au; |
| 389 | } | ||
| 364 | 390 | ||
| 365 | p += ret; | ||
| 366 | WARN_ON(p > end); | ||
| 367 | au->buf->vec.iov_len = p - au->buf->vec.iov_base; | ||
| 368 | dout(" built authorizer nonce %llx len %d\n", au->nonce, | 391 | dout(" built authorizer nonce %llx len %d\n", au->nonce, |
| 369 | (int)au->buf->vec.iov_len); | 392 | (int)au->buf->vec.iov_len); |
| 370 | return 0; | 393 | return 0; |
