auth.h 4.6 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_authorizer;
  13. struct ceph_msg;
  14. struct ceph_auth_handshake {
  15. struct ceph_authorizer *authorizer;
  16. void *authorizer_buf;
  17. size_t authorizer_buf_len;
  18. void *authorizer_reply_buf;
  19. size_t authorizer_reply_buf_len;
  20. int (*sign_message)(struct ceph_auth_handshake *auth,
  21. struct ceph_msg *msg);
  22. int (*check_message_signature)(struct ceph_auth_handshake *auth,
  23. struct ceph_msg *msg);
  24. };
  25. struct ceph_auth_client_ops {
  26. const char *name;
  27. /*
  28. * true if we are authenticated and can connect to
  29. * services.
  30. */
  31. int (*is_authenticated)(struct ceph_auth_client *ac);
  32. /*
  33. * true if we should (re)authenticate, e.g., when our tickets
  34. * are getting old and crusty.
  35. */
  36. int (*should_authenticate)(struct ceph_auth_client *ac);
  37. /*
  38. * build requests and process replies during monitor
  39. * handshake. if handle_reply returns -EAGAIN, we build
  40. * another request.
  41. */
  42. int (*build_request)(struct ceph_auth_client *ac, void *buf, void *end);
  43. int (*handle_reply)(struct ceph_auth_client *ac, int result,
  44. void *buf, void *end);
  45. /*
  46. * Create authorizer for connecting to a service, and verify
  47. * the response to authenticate the service.
  48. */
  49. int (*create_authorizer)(struct ceph_auth_client *ac, int peer_type,
  50. struct ceph_auth_handshake *auth);
  51. /* ensure that an existing authorizer is up to date */
  52. int (*update_authorizer)(struct ceph_auth_client *ac, int peer_type,
  53. struct ceph_auth_handshake *auth);
  54. int (*verify_authorizer_reply)(struct ceph_auth_client *ac,
  55. struct ceph_authorizer *a, size_t len);
  56. void (*destroy_authorizer)(struct ceph_auth_client *ac,
  57. struct ceph_authorizer *a);
  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. extern int ceph_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. extern void ceph_auth_destroy_authorizer(struct ceph_auth_client *ac,
  96. struct ceph_authorizer *a);
  97. extern int ceph_auth_update_authorizer(struct ceph_auth_client *ac,
  98. int peer_type,
  99. struct ceph_auth_handshake *a);
  100. extern int ceph_auth_verify_authorizer_reply(struct ceph_auth_client *ac,
  101. struct ceph_authorizer *a,
  102. size_t len);
  103. extern void ceph_auth_invalidate_authorizer(struct ceph_auth_client *ac,
  104. int peer_type);
  105. static inline int ceph_auth_sign_message(struct ceph_auth_handshake *auth,
  106. struct ceph_msg *msg)
  107. {
  108. if (auth->sign_message)
  109. return auth->sign_message(auth, msg);
  110. return 0;
  111. }
  112. static inline
  113. int ceph_auth_check_message_signature(struct ceph_auth_handshake *auth,
  114. struct ceph_msg *msg)
  115. {
  116. if (auth->check_message_signature)
  117. return auth->check_message_signature(auth, msg);
  118. return 0;
  119. }
  120. #endif