auth_x.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. #include <linux/ceph/ceph_debug.h>
  2. #include <linux/err.h>
  3. #include <linux/module.h>
  4. #include <linux/random.h>
  5. #include <linux/slab.h>
  6. #include <linux/ceph/decode.h>
  7. #include <linux/ceph/auth.h>
  8. #include "crypto.h"
  9. #include "auth_x.h"
  10. #include "auth_x_protocol.h"
  11. #define TEMP_TICKET_BUF_LEN 256
  12. static void ceph_x_validate_tickets(struct ceph_auth_client *ac, int *pneed);
  13. static int ceph_x_is_authenticated(struct ceph_auth_client *ac)
  14. {
  15. struct ceph_x_info *xi = ac->private;
  16. int need;
  17. ceph_x_validate_tickets(ac, &need);
  18. dout("ceph_x_is_authenticated want=%d need=%d have=%d\n",
  19. ac->want_keys, need, xi->have_keys);
  20. return (ac->want_keys & xi->have_keys) == ac->want_keys;
  21. }
  22. static int ceph_x_should_authenticate(struct ceph_auth_client *ac)
  23. {
  24. struct ceph_x_info *xi = ac->private;
  25. int need;
  26. ceph_x_validate_tickets(ac, &need);
  27. dout("ceph_x_should_authenticate want=%d need=%d have=%d\n",
  28. ac->want_keys, need, xi->have_keys);
  29. return need != 0;
  30. }
  31. static int ceph_x_encrypt_buflen(int ilen)
  32. {
  33. return sizeof(struct ceph_x_encrypt_header) + ilen + 16 +
  34. sizeof(u32);
  35. }
  36. static int ceph_x_encrypt(struct ceph_crypto_key *secret,
  37. void *ibuf, int ilen, void *obuf, size_t olen)
  38. {
  39. struct ceph_x_encrypt_header head = {
  40. .struct_v = 1,
  41. .magic = cpu_to_le64(CEPHX_ENC_MAGIC)
  42. };
  43. size_t len = olen - sizeof(u32);
  44. int ret;
  45. ret = ceph_encrypt2(secret, obuf + sizeof(u32), &len,
  46. &head, sizeof(head), ibuf, ilen);
  47. if (ret)
  48. return ret;
  49. ceph_encode_32(&obuf, len);
  50. return len + sizeof(u32);
  51. }
  52. static int ceph_x_decrypt(struct ceph_crypto_key *secret,
  53. void **p, void *end, void *obuf, size_t olen)
  54. {
  55. struct ceph_x_encrypt_header head;
  56. size_t head_len = sizeof(head);
  57. int len, ret;
  58. len = ceph_decode_32(p);
  59. if (*p + len > end)
  60. return -EINVAL;
  61. dout("ceph_x_decrypt len %d\n", len);
  62. ret = ceph_decrypt2(secret, &head, &head_len, obuf, &olen,
  63. *p, len);
  64. if (ret)
  65. return ret;
  66. if (head.struct_v != 1 || le64_to_cpu(head.magic) != CEPHX_ENC_MAGIC)
  67. return -EPERM;
  68. *p += len;
  69. return olen;
  70. }
  71. /*
  72. * get existing (or insert new) ticket handler
  73. */
  74. static struct ceph_x_ticket_handler *
  75. get_ticket_handler(struct ceph_auth_client *ac, int service)
  76. {
  77. struct ceph_x_ticket_handler *th;
  78. struct ceph_x_info *xi = ac->private;
  79. struct rb_node *parent = NULL, **p = &xi->ticket_handlers.rb_node;
  80. while (*p) {
  81. parent = *p;
  82. th = rb_entry(parent, struct ceph_x_ticket_handler, node);
  83. if (service < th->service)
  84. p = &(*p)->rb_left;
  85. else if (service > th->service)
  86. p = &(*p)->rb_right;
  87. else
  88. return th;
  89. }
  90. /* add it */
  91. th = kzalloc(sizeof(*th), GFP_NOFS);
  92. if (!th)
  93. return ERR_PTR(-ENOMEM);
  94. th->service = service;
  95. rb_link_node(&th->node, parent, p);
  96. rb_insert_color(&th->node, &xi->ticket_handlers);
  97. return th;
  98. }
  99. static void remove_ticket_handler(struct ceph_auth_client *ac,
  100. struct ceph_x_ticket_handler *th)
  101. {
  102. struct ceph_x_info *xi = ac->private;
  103. dout("remove_ticket_handler %p %d\n", th, th->service);
  104. rb_erase(&th->node, &xi->ticket_handlers);
  105. ceph_crypto_key_destroy(&th->session_key);
  106. if (th->ticket_blob)
  107. ceph_buffer_put(th->ticket_blob);
  108. kfree(th);
  109. }
  110. static int ceph_x_proc_ticket_reply(struct ceph_auth_client *ac,
  111. struct ceph_crypto_key *secret,
  112. void *buf, void *end)
  113. {
  114. struct ceph_x_info *xi = ac->private;
  115. int num;
  116. void *p = buf;
  117. int ret;
  118. char *dbuf;
  119. char *ticket_buf;
  120. u8 reply_struct_v;
  121. dbuf = kmalloc(TEMP_TICKET_BUF_LEN, GFP_NOFS);
  122. if (!dbuf)
  123. return -ENOMEM;
  124. ret = -ENOMEM;
  125. ticket_buf = kmalloc(TEMP_TICKET_BUF_LEN, GFP_NOFS);
  126. if (!ticket_buf)
  127. goto out_dbuf;
  128. ceph_decode_need(&p, end, 1 + sizeof(u32), bad);
  129. reply_struct_v = ceph_decode_8(&p);
  130. if (reply_struct_v != 1)
  131. goto bad;
  132. num = ceph_decode_32(&p);
  133. dout("%d tickets\n", num);
  134. while (num--) {
  135. int type;
  136. u8 tkt_struct_v, blob_struct_v;
  137. struct ceph_x_ticket_handler *th;
  138. void *dp, *dend;
  139. int dlen;
  140. char is_enc;
  141. struct timespec validity;
  142. struct ceph_crypto_key old_key;
  143. void *tp, *tpend;
  144. struct ceph_timespec new_validity;
  145. struct ceph_crypto_key new_session_key;
  146. struct ceph_buffer *new_ticket_blob;
  147. unsigned long new_expires, new_renew_after;
  148. u64 new_secret_id;
  149. ceph_decode_need(&p, end, sizeof(u32) + 1, bad);
  150. type = ceph_decode_32(&p);
  151. dout(" ticket type %d %s\n", type, ceph_entity_type_name(type));
  152. tkt_struct_v = ceph_decode_8(&p);
  153. if (tkt_struct_v != 1)
  154. goto bad;
  155. th = get_ticket_handler(ac, type);
  156. if (IS_ERR(th)) {
  157. ret = PTR_ERR(th);
  158. goto out;
  159. }
  160. /* blob for me */
  161. dlen = ceph_x_decrypt(secret, &p, end, dbuf,
  162. TEMP_TICKET_BUF_LEN);
  163. if (dlen <= 0) {
  164. ret = dlen;
  165. goto out;
  166. }
  167. dout(" decrypted %d bytes\n", dlen);
  168. dend = dbuf + dlen;
  169. dp = dbuf;
  170. tkt_struct_v = ceph_decode_8(&dp);
  171. if (tkt_struct_v != 1)
  172. goto bad;
  173. memcpy(&old_key, &th->session_key, sizeof(old_key));
  174. ret = ceph_crypto_key_decode(&new_session_key, &dp, dend);
  175. if (ret)
  176. goto out;
  177. ceph_decode_copy(&dp, &new_validity, sizeof(new_validity));
  178. ceph_decode_timespec(&validity, &new_validity);
  179. new_expires = get_seconds() + validity.tv_sec;
  180. new_renew_after = new_expires - (validity.tv_sec / 4);
  181. dout(" expires=%lu renew_after=%lu\n", new_expires,
  182. new_renew_after);
  183. /* ticket blob for service */
  184. ceph_decode_8_safe(&p, end, is_enc, bad);
  185. tp = ticket_buf;
  186. if (is_enc) {
  187. /* encrypted */
  188. dout(" encrypted ticket\n");
  189. dlen = ceph_x_decrypt(&old_key, &p, end, ticket_buf,
  190. TEMP_TICKET_BUF_LEN);
  191. if (dlen < 0) {
  192. ret = dlen;
  193. goto out;
  194. }
  195. dlen = ceph_decode_32(&tp);
  196. } else {
  197. /* unencrypted */
  198. ceph_decode_32_safe(&p, end, dlen, bad);
  199. ceph_decode_need(&p, end, dlen, bad);
  200. ceph_decode_copy(&p, ticket_buf, dlen);
  201. }
  202. tpend = tp + dlen;
  203. dout(" ticket blob is %d bytes\n", dlen);
  204. ceph_decode_need(&tp, tpend, 1 + sizeof(u64), bad);
  205. blob_struct_v = ceph_decode_8(&tp);
  206. new_secret_id = ceph_decode_64(&tp);
  207. ret = ceph_decode_buffer(&new_ticket_blob, &tp, tpend);
  208. if (ret)
  209. goto out;
  210. /* all is well, update our ticket */
  211. ceph_crypto_key_destroy(&th->session_key);
  212. if (th->ticket_blob)
  213. ceph_buffer_put(th->ticket_blob);
  214. th->session_key = new_session_key;
  215. th->ticket_blob = new_ticket_blob;
  216. th->validity = new_validity;
  217. th->secret_id = new_secret_id;
  218. th->expires = new_expires;
  219. th->renew_after = new_renew_after;
  220. dout(" got ticket service %d (%s) secret_id %lld len %d\n",
  221. type, ceph_entity_type_name(type), th->secret_id,
  222. (int)th->ticket_blob->vec.iov_len);
  223. xi->have_keys |= th->service;
  224. }
  225. ret = 0;
  226. out:
  227. kfree(ticket_buf);
  228. out_dbuf:
  229. kfree(dbuf);
  230. return ret;
  231. bad:
  232. ret = -EINVAL;
  233. goto out;
  234. }
  235. static int ceph_x_build_authorizer(struct ceph_auth_client *ac,
  236. struct ceph_x_ticket_handler *th,
  237. struct ceph_x_authorizer *au)
  238. {
  239. int maxlen;
  240. struct ceph_x_authorize_a *msg_a;
  241. struct ceph_x_authorize_b msg_b;
  242. void *p, *end;
  243. int ret;
  244. int ticket_blob_len =
  245. (th->ticket_blob ? th->ticket_blob->vec.iov_len : 0);
  246. dout("build_authorizer for %s %p\n",
  247. ceph_entity_type_name(th->service), au);
  248. maxlen = sizeof(*msg_a) + sizeof(msg_b) +
  249. ceph_x_encrypt_buflen(ticket_blob_len);
  250. dout(" need len %d\n", maxlen);
  251. if (au->buf && au->buf->alloc_len < maxlen) {
  252. ceph_buffer_put(au->buf);
  253. au->buf = NULL;
  254. }
  255. if (!au->buf) {
  256. au->buf = ceph_buffer_new(maxlen, GFP_NOFS);
  257. if (!au->buf)
  258. return -ENOMEM;
  259. }
  260. au->service = th->service;
  261. msg_a = au->buf->vec.iov_base;
  262. msg_a->struct_v = 1;
  263. msg_a->global_id = cpu_to_le64(ac->global_id);
  264. msg_a->service_id = cpu_to_le32(th->service);
  265. msg_a->ticket_blob.struct_v = 1;
  266. msg_a->ticket_blob.secret_id = cpu_to_le64(th->secret_id);
  267. msg_a->ticket_blob.blob_len = cpu_to_le32(ticket_blob_len);
  268. if (ticket_blob_len) {
  269. memcpy(msg_a->ticket_blob.blob, th->ticket_blob->vec.iov_base,
  270. th->ticket_blob->vec.iov_len);
  271. }
  272. dout(" th %p secret_id %lld %lld\n", th, th->secret_id,
  273. le64_to_cpu(msg_a->ticket_blob.secret_id));
  274. p = msg_a + 1;
  275. p += ticket_blob_len;
  276. end = au->buf->vec.iov_base + au->buf->vec.iov_len;
  277. get_random_bytes(&au->nonce, sizeof(au->nonce));
  278. msg_b.struct_v = 1;
  279. msg_b.nonce = cpu_to_le64(au->nonce);
  280. ret = ceph_x_encrypt(&th->session_key, &msg_b, sizeof(msg_b),
  281. p, end - p);
  282. if (ret < 0)
  283. goto out_buf;
  284. p += ret;
  285. au->buf->vec.iov_len = p - au->buf->vec.iov_base;
  286. dout(" built authorizer nonce %llx len %d\n", au->nonce,
  287. (int)au->buf->vec.iov_len);
  288. BUG_ON(au->buf->vec.iov_len > maxlen);
  289. return 0;
  290. out_buf:
  291. ceph_buffer_put(au->buf);
  292. au->buf = NULL;
  293. return ret;
  294. }
  295. static int ceph_x_encode_ticket(struct ceph_x_ticket_handler *th,
  296. void **p, void *end)
  297. {
  298. ceph_decode_need(p, end, 1 + sizeof(u64), bad);
  299. ceph_encode_8(p, 1);
  300. ceph_encode_64(p, th->secret_id);
  301. if (th->ticket_blob) {
  302. const char *buf = th->ticket_blob->vec.iov_base;
  303. u32 len = th->ticket_blob->vec.iov_len;
  304. ceph_encode_32_safe(p, end, len, bad);
  305. ceph_encode_copy_safe(p, end, buf, len, bad);
  306. } else {
  307. ceph_encode_32_safe(p, end, 0, bad);
  308. }
  309. return 0;
  310. bad:
  311. return -ERANGE;
  312. }
  313. static void ceph_x_validate_tickets(struct ceph_auth_client *ac, int *pneed)
  314. {
  315. int want = ac->want_keys;
  316. struct ceph_x_info *xi = ac->private;
  317. int service;
  318. *pneed = ac->want_keys & ~(xi->have_keys);
  319. for (service = 1; service <= want; service <<= 1) {
  320. struct ceph_x_ticket_handler *th;
  321. if (!(ac->want_keys & service))
  322. continue;
  323. if (*pneed & service)
  324. continue;
  325. th = get_ticket_handler(ac, service);
  326. if (IS_ERR(th)) {
  327. *pneed |= service;
  328. continue;
  329. }
  330. if (get_seconds() >= th->renew_after)
  331. *pneed |= service;
  332. if (get_seconds() >= th->expires)
  333. xi->have_keys &= ~service;
  334. }
  335. }
  336. static int ceph_x_build_request(struct ceph_auth_client *ac,
  337. void *buf, void *end)
  338. {
  339. struct ceph_x_info *xi = ac->private;
  340. int need;
  341. struct ceph_x_request_header *head = buf;
  342. int ret;
  343. struct ceph_x_ticket_handler *th =
  344. get_ticket_handler(ac, CEPH_ENTITY_TYPE_AUTH);
  345. if (IS_ERR(th))
  346. return PTR_ERR(th);
  347. ceph_x_validate_tickets(ac, &need);
  348. dout("build_request want %x have %x need %x\n",
  349. ac->want_keys, xi->have_keys, need);
  350. if (need & CEPH_ENTITY_TYPE_AUTH) {
  351. struct ceph_x_authenticate *auth = (void *)(head + 1);
  352. void *p = auth + 1;
  353. struct ceph_x_challenge_blob tmp;
  354. char tmp_enc[40];
  355. u64 *u;
  356. if (p > end)
  357. return -ERANGE;
  358. dout(" get_auth_session_key\n");
  359. head->op = cpu_to_le16(CEPHX_GET_AUTH_SESSION_KEY);
  360. /* encrypt and hash */
  361. get_random_bytes(&auth->client_challenge, sizeof(u64));
  362. tmp.client_challenge = auth->client_challenge;
  363. tmp.server_challenge = cpu_to_le64(xi->server_challenge);
  364. ret = ceph_x_encrypt(&xi->secret, &tmp, sizeof(tmp),
  365. tmp_enc, sizeof(tmp_enc));
  366. if (ret < 0)
  367. return ret;
  368. auth->struct_v = 1;
  369. auth->key = 0;
  370. for (u = (u64 *)tmp_enc; u + 1 <= (u64 *)(tmp_enc + ret); u++)
  371. auth->key ^= *(__le64 *)u;
  372. dout(" server_challenge %llx client_challenge %llx key %llx\n",
  373. xi->server_challenge, le64_to_cpu(auth->client_challenge),
  374. le64_to_cpu(auth->key));
  375. /* now encode the old ticket if exists */
  376. ret = ceph_x_encode_ticket(th, &p, end);
  377. if (ret < 0)
  378. return ret;
  379. return p - buf;
  380. }
  381. if (need) {
  382. void *p = head + 1;
  383. struct ceph_x_service_ticket_request *req;
  384. if (p > end)
  385. return -ERANGE;
  386. head->op = cpu_to_le16(CEPHX_GET_PRINCIPAL_SESSION_KEY);
  387. ret = ceph_x_build_authorizer(ac, th, &xi->auth_authorizer);
  388. if (ret)
  389. return ret;
  390. ceph_encode_copy(&p, xi->auth_authorizer.buf->vec.iov_base,
  391. xi->auth_authorizer.buf->vec.iov_len);
  392. req = p;
  393. req->keys = cpu_to_le32(need);
  394. p += sizeof(*req);
  395. return p - buf;
  396. }
  397. return 0;
  398. }
  399. static int ceph_x_handle_reply(struct ceph_auth_client *ac, int result,
  400. void *buf, void *end)
  401. {
  402. struct ceph_x_info *xi = ac->private;
  403. struct ceph_x_reply_header *head = buf;
  404. struct ceph_x_ticket_handler *th;
  405. int len = end - buf;
  406. int op;
  407. int ret;
  408. if (result)
  409. return result; /* XXX hmm? */
  410. if (xi->starting) {
  411. /* it's a hello */
  412. struct ceph_x_server_challenge *sc = buf;
  413. if (len != sizeof(*sc))
  414. return -EINVAL;
  415. xi->server_challenge = le64_to_cpu(sc->server_challenge);
  416. dout("handle_reply got server challenge %llx\n",
  417. xi->server_challenge);
  418. xi->starting = false;
  419. xi->have_keys &= ~CEPH_ENTITY_TYPE_AUTH;
  420. return -EAGAIN;
  421. }
  422. op = le16_to_cpu(head->op);
  423. result = le32_to_cpu(head->result);
  424. dout("handle_reply op %d result %d\n", op, result);
  425. switch (op) {
  426. case CEPHX_GET_AUTH_SESSION_KEY:
  427. /* verify auth key */
  428. ret = ceph_x_proc_ticket_reply(ac, &xi->secret,
  429. buf + sizeof(*head), end);
  430. break;
  431. case CEPHX_GET_PRINCIPAL_SESSION_KEY:
  432. th = get_ticket_handler(ac, CEPH_ENTITY_TYPE_AUTH);
  433. if (IS_ERR(th))
  434. return PTR_ERR(th);
  435. ret = ceph_x_proc_ticket_reply(ac, &th->session_key,
  436. buf + sizeof(*head), end);
  437. break;
  438. default:
  439. return -EINVAL;
  440. }
  441. if (ret)
  442. return ret;
  443. if (ac->want_keys == xi->have_keys)
  444. return 0;
  445. return -EAGAIN;
  446. }
  447. static int ceph_x_create_authorizer(
  448. struct ceph_auth_client *ac, int peer_type,
  449. struct ceph_authorizer **a,
  450. void **buf, size_t *len,
  451. void **reply_buf, size_t *reply_len)
  452. {
  453. struct ceph_x_authorizer *au;
  454. struct ceph_x_ticket_handler *th;
  455. int ret;
  456. th = get_ticket_handler(ac, peer_type);
  457. if (IS_ERR(th))
  458. return PTR_ERR(th);
  459. au = kzalloc(sizeof(*au), GFP_NOFS);
  460. if (!au)
  461. return -ENOMEM;
  462. ret = ceph_x_build_authorizer(ac, th, au);
  463. if (ret) {
  464. kfree(au);
  465. return ret;
  466. }
  467. *a = (struct ceph_authorizer *)au;
  468. *buf = au->buf->vec.iov_base;
  469. *len = au->buf->vec.iov_len;
  470. *reply_buf = au->reply_buf;
  471. *reply_len = sizeof(au->reply_buf);
  472. return 0;
  473. }
  474. static int ceph_x_verify_authorizer_reply(struct ceph_auth_client *ac,
  475. struct ceph_authorizer *a, size_t len)
  476. {
  477. struct ceph_x_authorizer *au = (void *)a;
  478. struct ceph_x_ticket_handler *th;
  479. int ret = 0;
  480. struct ceph_x_authorize_reply reply;
  481. void *p = au->reply_buf;
  482. void *end = p + sizeof(au->reply_buf);
  483. th = get_ticket_handler(ac, au->service);
  484. if (IS_ERR(th))
  485. return PTR_ERR(th);
  486. ret = ceph_x_decrypt(&th->session_key, &p, end, &reply, sizeof(reply));
  487. if (ret < 0)
  488. return ret;
  489. if (ret != sizeof(reply))
  490. return -EPERM;
  491. if (au->nonce + 1 != le64_to_cpu(reply.nonce_plus_one))
  492. ret = -EPERM;
  493. else
  494. ret = 0;
  495. dout("verify_authorizer_reply nonce %llx got %llx ret %d\n",
  496. au->nonce, le64_to_cpu(reply.nonce_plus_one), ret);
  497. return ret;
  498. }
  499. static void ceph_x_destroy_authorizer(struct ceph_auth_client *ac,
  500. struct ceph_authorizer *a)
  501. {
  502. struct ceph_x_authorizer *au = (void *)a;
  503. ceph_buffer_put(au->buf);
  504. kfree(au);
  505. }
  506. static void ceph_x_reset(struct ceph_auth_client *ac)
  507. {
  508. struct ceph_x_info *xi = ac->private;
  509. dout("reset\n");
  510. xi->starting = true;
  511. xi->server_challenge = 0;
  512. }
  513. static void ceph_x_destroy(struct ceph_auth_client *ac)
  514. {
  515. struct ceph_x_info *xi = ac->private;
  516. struct rb_node *p;
  517. dout("ceph_x_destroy %p\n", ac);
  518. ceph_crypto_key_destroy(&xi->secret);
  519. while ((p = rb_first(&xi->ticket_handlers)) != NULL) {
  520. struct ceph_x_ticket_handler *th =
  521. rb_entry(p, struct ceph_x_ticket_handler, node);
  522. remove_ticket_handler(ac, th);
  523. }
  524. if (xi->auth_authorizer.buf)
  525. ceph_buffer_put(xi->auth_authorizer.buf);
  526. kfree(ac->private);
  527. ac->private = NULL;
  528. }
  529. static void ceph_x_invalidate_authorizer(struct ceph_auth_client *ac,
  530. int peer_type)
  531. {
  532. struct ceph_x_ticket_handler *th;
  533. th = get_ticket_handler(ac, peer_type);
  534. if (!IS_ERR(th))
  535. remove_ticket_handler(ac, th);
  536. }
  537. static const struct ceph_auth_client_ops ceph_x_ops = {
  538. .name = "x",
  539. .is_authenticated = ceph_x_is_authenticated,
  540. .should_authenticate = ceph_x_should_authenticate,
  541. .build_request = ceph_x_build_request,
  542. .handle_reply = ceph_x_handle_reply,
  543. .create_authorizer = ceph_x_create_authorizer,
  544. .verify_authorizer_reply = ceph_x_verify_authorizer_reply,
  545. .destroy_authorizer = ceph_x_destroy_authorizer,
  546. .invalidate_authorizer = ceph_x_invalidate_authorizer,
  547. .reset = ceph_x_reset,
  548. .destroy = ceph_x_destroy,
  549. };
  550. int ceph_x_init(struct ceph_auth_client *ac)
  551. {
  552. struct ceph_x_info *xi;
  553. int ret;
  554. dout("ceph_x_init %p\n", ac);
  555. ret = -ENOMEM;
  556. xi = kzalloc(sizeof(*xi), GFP_NOFS);
  557. if (!xi)
  558. goto out;
  559. ret = -EINVAL;
  560. if (!ac->key) {
  561. pr_err("no secret set (for auth_x protocol)\n");
  562. goto out_nomem;
  563. }
  564. ret = ceph_crypto_key_clone(&xi->secret, ac->key);
  565. if (ret < 0) {
  566. pr_err("cannot clone key: %d\n", ret);
  567. goto out_nomem;
  568. }
  569. xi->starting = true;
  570. xi->ticket_handlers = RB_ROOT;
  571. ac->protocol = CEPH_AUTH_CEPHX;
  572. ac->private = xi;
  573. ac->ops = &ceph_x_ops;
  574. return 0;
  575. out_nomem:
  576. kfree(xi);
  577. out:
  578. return ret;
  579. }