auth.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _FS_CEPH_AUTH_H
  3. #define _FS_CEPH_AUTH_H
  4. #include <linux/ceph/types.h>
  5. #include <linux/ceph/buffer.h>
  6. /*
  7. * Abstract interface for communicating with the authenticate module.
  8. * There is some handshake that takes place between us and the monitor
  9. * to acquire the necessary keys. These are used to generate an
  10. * 'authorizer' that we use when connecting to a service (mds, osd).
  11. */
  12. struct ceph_auth_client;
  13. struct ceph_msg;
  14. struct ceph_authorizer {
  15. void (*destroy)(struct ceph_authorizer *);
  16. };
  17. struct ceph_auth_handshake {
  18. struct ceph_authorizer *authorizer;
  19. void *authorizer_buf;
  20. size_t authorizer_buf_len;
  21. void *authorizer_reply_buf;
  22. size_t authorizer_reply_buf_len;
  23. int (*sign_message)(struct ceph_auth_handshake *auth,
  24. struct ceph_msg *msg);
  25. int (*check_message_signature)(struct ceph_auth_handshake *auth,
  26. struct ceph_msg *msg);
  27. };
  28. struct ceph_auth_client_ops {
  29. /*
  30. * true if we are authenticated and can connect to
  31. * services.
  32. */
  33. int (*is_authenticated)(struct ceph_auth_client *ac);
  34. /*
  35. * true if we should (re)authenticate, e.g., when our tickets
  36. * are getting old and crusty.
  37. */
  38. int (*should_authenticate)(struct ceph_auth_client *ac);
  39. /*
  40. * build requests and process replies during monitor
  41. * handshake. if handle_reply returns -EAGAIN, we build
  42. * another request.
  43. */
  44. int (*build_request)(struct ceph_auth_client *ac, void *buf, void *end);
  45. int (*handle_reply)(struct ceph_auth_client *ac, u64 global_id,
  46. void *buf, void *end, u8 *session_key,
  47. int *session_key_len, u8 *con_secret,
  48. int *con_secret_len);
  49. /*
  50. * Create authorizer for connecting to a service, and verify
  51. * the response to authenticate the service.
  52. */
  53. int (*create_authorizer)(struct ceph_auth_client *ac, int peer_type,
  54. struct ceph_auth_handshake *auth);
  55. /* ensure that an existing authorizer is up to date */
  56. int (*update_authorizer)(struct ceph_auth_client *ac, int peer_type,
  57. struct ceph_auth_handshake *auth);
  58. int (*add_authorizer_challenge)(struct ceph_auth_client *ac,
  59. struct ceph_authorizer *a,
  60. void *challenge_buf,
  61. int challenge_buf_len);
  62. int (*verify_authorizer_reply)(struct ceph_auth_client *ac,
  63. struct ceph_authorizer *a,
  64. void *reply, int reply_len,
  65. u8 *session_key, int *session_key_len,
  66. u8 *con_secret, int *con_secret_len);
  67. void (*invalidate_authorizer)(struct ceph_auth_client *ac,
  68. int peer_type);
  69. /* reset when we (re)connect to a monitor */
  70. void (*reset)(struct ceph_auth_client *ac);
  71. void (*destroy)(struct ceph_auth_client *ac);
  72. int (*sign_message)(struct ceph_auth_handshake *auth,
  73. struct ceph_msg *msg);
  74. int (*check_message_signature)(struct ceph_auth_handshake *auth,
  75. struct ceph_msg *msg);
  76. };
  77. struct ceph_auth_client {
  78. u32 protocol; /* CEPH_AUTH_* */
  79. void *private; /* for use by protocol implementation */
  80. const struct ceph_auth_client_ops *ops; /* null iff protocol==0 */
  81. bool negotiating; /* true if negotiating protocol */
  82. const char *name; /* entity name */
  83. u64 global_id; /* our unique id in system */
  84. const struct ceph_crypto_key *key; /* our secret key */
  85. unsigned want_keys; /* which services we want */
  86. int preferred_mode; /* CEPH_CON_MODE_* */
  87. int fallback_mode; /* ditto */
  88. struct mutex mutex;
  89. };
  90. void ceph_auth_set_global_id(struct ceph_auth_client *ac, u64 global_id);
  91. struct ceph_auth_client *ceph_auth_init(const char *name,
  92. const struct ceph_crypto_key *key,
  93. const int *con_modes);
  94. extern void ceph_auth_destroy(struct ceph_auth_client *ac);
  95. extern void ceph_auth_reset(struct ceph_auth_client *ac);
  96. extern int ceph_auth_build_hello(struct ceph_auth_client *ac,
  97. void *buf, size_t len);
  98. extern int ceph_handle_auth_reply(struct ceph_auth_client *ac,
  99. void *buf, size_t len,
  100. void *reply_buf, size_t reply_len);
  101. int ceph_auth_entity_name_encode(const char *name, void **p, void *end);
  102. extern int ceph_build_auth(struct ceph_auth_client *ac,
  103. void *msg_buf, size_t msg_len);
  104. extern int ceph_auth_is_authenticated(struct ceph_auth_client *ac);
  105. int __ceph_auth_get_authorizer(struct ceph_auth_client *ac,
  106. struct ceph_auth_handshake *auth,
  107. int peer_type, bool force_new,
  108. int *proto, int *pref_mode, int *fallb_mode);
  109. void ceph_auth_destroy_authorizer(struct ceph_authorizer *a);
  110. int ceph_auth_add_authorizer_challenge(struct ceph_auth_client *ac,
  111. struct ceph_authorizer *a,
  112. void *challenge_buf,
  113. int challenge_buf_len);
  114. int ceph_auth_verify_authorizer_reply(struct ceph_auth_client *ac,
  115. struct ceph_authorizer *a,
  116. void *reply, int reply_len,
  117. u8 *session_key, int *session_key_len,
  118. u8 *con_secret, int *con_secret_len);
  119. extern void ceph_auth_invalidate_authorizer(struct ceph_auth_client *ac,
  120. int peer_type);
  121. static inline int ceph_auth_sign_message(struct ceph_auth_handshake *auth,
  122. struct ceph_msg *msg)
  123. {
  124. if (auth->sign_message)
  125. return auth->sign_message(auth, msg);
  126. return 0;
  127. }
  128. static inline
  129. int ceph_auth_check_message_signature(struct ceph_auth_handshake *auth,
  130. struct ceph_msg *msg)
  131. {
  132. if (auth->check_message_signature)
  133. return auth->check_message_signature(auth, msg);
  134. return 0;
  135. }
  136. int ceph_auth_get_request(struct ceph_auth_client *ac, void *buf, int buf_len);
  137. int ceph_auth_handle_reply_more(struct ceph_auth_client *ac, void *reply,
  138. int reply_len, void *buf, int buf_len);
  139. int ceph_auth_handle_reply_done(struct ceph_auth_client *ac,
  140. u64 global_id, void *reply, int reply_len,
  141. u8 *session_key, int *session_key_len,
  142. u8 *con_secret, int *con_secret_len);
  143. bool ceph_auth_handle_bad_method(struct ceph_auth_client *ac,
  144. int used_proto, int result,
  145. const int *allowed_protos, int proto_cnt,
  146. const int *allowed_modes, int mode_cnt);
  147. int ceph_auth_get_authorizer(struct ceph_auth_client *ac,
  148. struct ceph_auth_handshake *auth,
  149. int peer_type, void *buf, int *buf_len);
  150. int ceph_auth_handle_svc_reply_more(struct ceph_auth_client *ac,
  151. struct ceph_auth_handshake *auth,
  152. void *reply, int reply_len,
  153. void *buf, int *buf_len);
  154. int ceph_auth_handle_svc_reply_done(struct ceph_auth_client *ac,
  155. struct ceph_auth_handshake *auth,
  156. void *reply, int reply_len,
  157. u8 *session_key, int *session_key_len,
  158. u8 *con_secret, int *con_secret_len);
  159. bool ceph_auth_handle_bad_authorizer(struct ceph_auth_client *ac,
  160. int peer_type, int used_proto, int result,
  161. const int *allowed_protos, int proto_cnt,
  162. const int *allowed_modes, int mode_cnt);
  163. #endif