auth.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #ifndef _FS_CEPH_AUTH_H
  2. #define _FS_CEPH_AUTH_H
  3. #include <linux/ceph/types.h>
  4. #include <linux/ceph/buffer.h>
  5. /*
  6. * Abstract interface for communicating with the authenticate module.
  7. * There is some handshake that takes place between us and the monitor
  8. * to acquire the necessary keys. These are used to generate an
  9. * 'authorizer' that we use when connecting to a service (mds, osd).
  10. */
  11. struct ceph_auth_client;
  12. struct ceph_msg;
  13. struct ceph_authorizer {
  14. void (*destroy)(struct ceph_authorizer *);
  15. };
  16. struct ceph_auth_handshake {
  17. struct ceph_authorizer *authorizer;
  18. void *authorizer_buf;
  19. size_t authorizer_buf_len;
  20. void *authorizer_reply_buf;
  21. size_t authorizer_reply_buf_len;
  22. int (*sign_message)(struct ceph_auth_handshake *auth,
  23. struct ceph_msg *msg);
  24. int (*check_message_signature)(struct ceph_auth_handshake *auth,
  25. struct ceph_msg *msg);
  26. };
  27. struct ceph_auth_client_ops {
  28. const char *name;
  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, int result,
  46. void *buf, void *end);
  47. /*
  48. * Create authorizer for connecting to a service, and verify
  49. * the response to authenticate the service.
  50. */
  51. int (*create_authorizer)(struct ceph_auth_client *ac, int peer_type,
  52. struct ceph_auth_handshake *auth);
  53. /* ensure that an existing authorizer is up to date */
  54. int (*update_authorizer)(struct ceph_auth_client *ac, int peer_type,
  55. struct ceph_auth_handshake *auth);
  56. int (*verify_authorizer_reply)(struct ceph_auth_client *ac,
  57. struct ceph_authorizer *a, size_t len);
  58. void (*invalidate_authorizer)(struct ceph_auth_client *ac,
  59. int peer_type);
  60. /* reset when we (re)connect to a monitor */
  61. void (*reset)(struct ceph_auth_client *ac);
  62. void (*destroy)(struct ceph_auth_client *ac);
  63. int (*sign_message)(struct ceph_auth_handshake *auth,
  64. struct ceph_msg *msg);
  65. int (*check_message_signature)(struct ceph_auth_handshake *auth,
  66. struct ceph_msg *msg);
  67. };
  68. struct ceph_auth_client {
  69. u32 protocol; /* CEPH_AUTH_* */
  70. void *private; /* for use by protocol implementation */
  71. const struct ceph_auth_client_ops *ops; /* null iff protocol==0 */
  72. bool negotiating; /* true if negotiating protocol */
  73. const char *name; /* entity name */
  74. u64 global_id; /* our unique id in system */
  75. const struct ceph_crypto_key *key; /* our secret key */
  76. unsigned want_keys; /* which services we want */
  77. struct mutex mutex;
  78. };
  79. extern struct ceph_auth_client *ceph_auth_init(const char *name,
  80. const struct ceph_crypto_key *key);
  81. extern void ceph_auth_destroy(struct ceph_auth_client *ac);
  82. extern void ceph_auth_reset(struct ceph_auth_client *ac);
  83. extern int ceph_auth_build_hello(struct ceph_auth_client *ac,
  84. void *buf, size_t len);
  85. extern int ceph_handle_auth_reply(struct ceph_auth_client *ac,
  86. void *buf, size_t len,
  87. void *reply_buf, size_t reply_len);
  88. int ceph_auth_entity_name_encode(const char *name, void **p, void *end);
  89. extern int ceph_build_auth(struct ceph_auth_client *ac,
  90. void *msg_buf, size_t msg_len);
  91. extern int ceph_auth_is_authenticated(struct ceph_auth_client *ac);
  92. extern int ceph_auth_create_authorizer(struct ceph_auth_client *ac,
  93. int peer_type,
  94. struct ceph_auth_handshake *auth);
  95. void ceph_auth_destroy_authorizer(struct ceph_authorizer *a);
  96. extern int ceph_auth_update_authorizer(struct ceph_auth_client *ac,
  97. int peer_type,
  98. struct ceph_auth_handshake *a);
  99. extern int ceph_auth_verify_authorizer_reply(struct ceph_auth_client *ac,
  100. struct ceph_authorizer *a,
  101. size_t len);
  102. extern void ceph_auth_invalidate_authorizer(struct ceph_auth_client *ac,
  103. int peer_type);
  104. static inline int ceph_auth_sign_message(struct ceph_auth_handshake *auth,
  105. struct ceph_msg *msg)
  106. {
  107. if (auth->sign_message)
  108. return auth->sign_message(auth, msg);
  109. return 0;
  110. }
  111. static inline
  112. int ceph_auth_check_message_signature(struct ceph_auth_handshake *auth,
  113. struct ceph_msg *msg)
  114. {
  115. if (auth->check_message_signature)
  116. return auth->check_message_signature(auth, msg);
  117. return 0;
  118. }
  119. #endif