5 #include <linux/module.h>
6 #include <linux/random.h>
7 #include <linux/slab.h>
16 #define TEMP_TICKET_BUF_LEN 256
25 ceph_x_validate_tickets(ac, &need);
26 dout(
"ceph_x_is_authenticated want=%d need=%d have=%d\n",
36 ceph_x_validate_tickets(ac, &need);
37 dout(
"ceph_x_should_authenticate want=%d need=%d have=%d\n",
42 static int ceph_x_encrypt_buflen(
int ilen)
49 void *ibuf,
int ilen,
void *obuf,
size_t olen)
55 size_t len = olen -
sizeof(
u32);
59 &head,
sizeof(head), ibuf, ilen);
62 ceph_encode_32(&obuf, len);
63 return len +
sizeof(
u32);
67 void **
p,
void *
end,
void *obuf,
size_t olen)
70 size_t head_len =
sizeof(
head);
73 len = ceph_decode_32(p);
77 dout(
"ceph_x_decrypt len %d\n", len);
101 if (service < th->service)
103 else if (service > th->
service)
110 th = kzalloc(
sizeof(*th),
GFP_NOFS);
114 rb_link_node(&th->
node, parent, p);
124 dout(
"remove_ticket_handler %p %d\n", th, th->
service);
134 void *
buf,
void *end)
154 reply_struct_v = ceph_decode_8(&p);
155 if (reply_struct_v != 1)
157 num = ceph_decode_32(&p);
158 dout(
"%d tickets\n", num);
161 u8 tkt_struct_v, blob_struct_v;
172 unsigned long new_expires, new_renew_after;
177 type = ceph_decode_32(&p);
180 tkt_struct_v = ceph_decode_8(&p);
181 if (tkt_struct_v != 1)
184 th = get_ticket_handler(ac, type);
191 dlen = ceph_x_decrypt(secret, &p, end, dbuf,
197 dout(
" decrypted %d bytes\n", dlen);
201 tkt_struct_v = ceph_decode_8(&dp);
202 if (tkt_struct_v != 1)
210 ceph_decode_copy(&dp, &new_validity,
sizeof(new_validity));
211 ceph_decode_timespec(&
validity, &new_validity);
213 new_renew_after = new_expires - (
validity.tv_sec / 4);
214 dout(
" expires=%lu renew_after=%lu\n", new_expires,
222 dout(
" encrypted ticket\n");
223 dlen = ceph_x_decrypt(&old_key, &p, end, ticket_buf,
229 dlen = ceph_decode_32(&tp);
234 ceph_decode_copy(&p, ticket_buf, dlen);
237 dout(
" ticket blob is %d bytes\n", dlen);
239 blob_struct_v = ceph_decode_8(&tp);
240 new_secret_id = ceph_decode_64(&tp);
255 dout(
" got ticket service %d (%s) secret_id %lld len %d\n",
282 int ticket_blob_len =
285 dout(
"build_authorizer for %s %p\n",
288 maxlen =
sizeof(*msg_a) +
sizeof(msg_b) +
289 ceph_x_encrypt_buflen(ticket_blob_len);
290 dout(
" need len %d\n", maxlen);
291 if (au->
buf && au->
buf->alloc_len < maxlen) {
292 ceph_buffer_put(au->
buf);
302 msg_a = au->
buf->vec.iov_base;
309 if (ticket_blob_len) {
317 p += ticket_blob_len;
318 end = au->
buf->vec.iov_base + au->
buf->vec.iov_len;
323 ret = ceph_x_encrypt(&th->
session_key, &msg_b,
sizeof(msg_b),
328 au->
buf->vec.iov_len = p - au->
buf->vec.iov_base;
329 dout(
" built authorizer nonce %llx len %d\n", au->
nonce,
330 (
int)au->
buf->vec.iov_len);
335 ceph_buffer_put(au->
buf);
361 static void ceph_x_validate_tickets(
struct ceph_auth_client *ac,
int *pneed)
369 for (service = 1; service <= want; service <<= 1) {
375 if (*pneed & service)
378 th = get_ticket_handler(ac, service);
394 void *buf,
void *end)
406 ceph_x_validate_tickets(ac, &need);
408 dout(
"build_request want %x have %x need %x\n",
421 dout(
" get_auth_session_key\n");
429 tmp_enc,
sizeof(tmp_enc));
435 for (u = (
u64 *)tmp_enc; u + 1 <= (
u64 *)(tmp_enc + ret); u++)
437 dout(
" server_challenge %llx client_challenge %llx key %llx\n",
442 ret = ceph_x_encode_ticket(th, &p, end);
473 void *buf,
void *end)
489 if (len !=
sizeof(*sc))
492 dout(
"handle_reply got server challenge %llx\n",
501 dout(
"handle_reply op %d result %d\n", op, result);
505 ret = ceph_x_proc_ticket_reply(ac, &xi->
secret,
506 buf +
sizeof(*head), end);
510 th = get_ticket_handler(ac, CEPH_ENTITY_TYPE_AUTH);
513 ret = ceph_x_proc_ticket_reply(ac, &th->
session_key,
514 buf +
sizeof(*head), end);
527 static int ceph_x_create_authorizer(
535 th = get_ticket_handler(ac, peer_type);
539 au = kzalloc(
sizeof(*au),
GFP_NOFS);
543 ret = ceph_x_build_authorizer(ac, th, au);
549 auth->
authorizer = (
struct ceph_authorizer *) au;
559 struct ceph_authorizer *
a,
size_t len)
568 th = get_ticket_handler(ac, au->
service);
571 ret = ceph_x_decrypt(&th->session_key, &p, end, &reply,
sizeof(reply));
574 if (ret !=
sizeof(reply))
581 dout(
"verify_authorizer_reply nonce %llx got %llx ret %d\n",
587 struct ceph_authorizer *a)
591 ceph_buffer_put(au->
buf);
610 dout(
"ceph_x_destroy %p\n", ac);
611 ceph_crypto_key_destroy(&xi->
secret);
616 remove_ticket_handler(ac, th);
631 th = get_ticket_handler(ac, peer_type);
633 remove_ticket_handler(ac, th);
639 .is_authenticated = ceph_x_is_authenticated,
640 .should_authenticate = ceph_x_should_authenticate,
641 .build_request = ceph_x_build_request,
642 .handle_reply = ceph_x_handle_reply,
643 .create_authorizer = ceph_x_create_authorizer,
644 .verify_authorizer_reply = ceph_x_verify_authorizer_reply,
645 .destroy_authorizer = ceph_x_destroy_authorizer,
646 .invalidate_authorizer = ceph_x_invalidate_authorizer,
647 .reset = ceph_x_reset,
648 .destroy = ceph_x_destroy,
657 dout(
"ceph_x_init %p\n", ac);
659 xi = kzalloc(
sizeof(*xi),
GFP_NOFS);
665 pr_err(
"no secret set (for auth_x protocol)\n");
671 pr_err(
"cannot clone key: %d\n", ret);
680 ac->
ops = &ceph_x_ops;