2009-11-19 08:19:57 +08:00
|
|
|
#ifndef _FS_CEPH_AUTH_H
|
|
|
|
#define _FS_CEPH_AUTH_H
|
|
|
|
|
2010-04-07 06:14:15 +08:00
|
|
|
#include <linux/ceph/types.h>
|
|
|
|
#include <linux/ceph/buffer.h>
|
2009-11-19 08:19:57 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Abstract interface for communicating with the authenticate module.
|
|
|
|
* There is some handshake that takes place between us and the monitor
|
|
|
|
* to acquire the necessary keys. These are used to generate an
|
|
|
|
* 'authorizer' that we use when connecting to a service (mds, osd).
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ceph_auth_client;
|
|
|
|
struct ceph_authorizer;
|
2014-11-04 16:33:37 +08:00
|
|
|
struct ceph_msg;
|
2009-11-19 08:19:57 +08:00
|
|
|
|
2012-05-17 04:16:38 +08:00
|
|
|
struct ceph_auth_handshake {
|
|
|
|
struct ceph_authorizer *authorizer;
|
|
|
|
void *authorizer_buf;
|
|
|
|
size_t authorizer_buf_len;
|
|
|
|
void *authorizer_reply_buf;
|
|
|
|
size_t authorizer_reply_buf_len;
|
2014-11-04 16:33:37 +08:00
|
|
|
int (*sign_message)(struct ceph_auth_handshake *auth,
|
|
|
|
struct ceph_msg *msg);
|
|
|
|
int (*check_message_signature)(struct ceph_auth_handshake *auth,
|
|
|
|
struct ceph_msg *msg);
|
2012-05-17 04:16:38 +08:00
|
|
|
};
|
|
|
|
|
2009-11-19 08:19:57 +08:00
|
|
|
struct ceph_auth_client_ops {
|
2010-05-15 00:55:18 +08:00
|
|
|
const char *name;
|
|
|
|
|
2009-11-19 08:19:57 +08:00
|
|
|
/*
|
|
|
|
* true if we are authenticated and can connect to
|
|
|
|
* services.
|
|
|
|
*/
|
|
|
|
int (*is_authenticated)(struct ceph_auth_client *ac);
|
|
|
|
|
2010-05-26 06:39:06 +08:00
|
|
|
/*
|
|
|
|
* true if we should (re)authenticate, e.g., when our tickets
|
|
|
|
* are getting old and crusty.
|
|
|
|
*/
|
|
|
|
int (*should_authenticate)(struct ceph_auth_client *ac);
|
|
|
|
|
2009-11-19 08:19:57 +08:00
|
|
|
/*
|
|
|
|
* build requests and process replies during monitor
|
|
|
|
* handshake. if handle_reply returns -EAGAIN, we build
|
|
|
|
* another request.
|
|
|
|
*/
|
|
|
|
int (*build_request)(struct ceph_auth_client *ac, void *buf, void *end);
|
|
|
|
int (*handle_reply)(struct ceph_auth_client *ac, int result,
|
|
|
|
void *buf, void *end);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create authorizer for connecting to a service, and verify
|
|
|
|
* the response to authenticate the service.
|
|
|
|
*/
|
|
|
|
int (*create_authorizer)(struct ceph_auth_client *ac, int peer_type,
|
2012-05-17 04:16:39 +08:00
|
|
|
struct ceph_auth_handshake *auth);
|
2013-03-26 01:26:01 +08:00
|
|
|
/* ensure that an existing authorizer is up to date */
|
|
|
|
int (*update_authorizer)(struct ceph_auth_client *ac, int peer_type,
|
|
|
|
struct ceph_auth_handshake *auth);
|
2009-11-19 08:19:57 +08:00
|
|
|
int (*verify_authorizer_reply)(struct ceph_auth_client *ac,
|
|
|
|
struct ceph_authorizer *a, size_t len);
|
|
|
|
void (*destroy_authorizer)(struct ceph_auth_client *ac,
|
|
|
|
struct ceph_authorizer *a);
|
2010-02-03 08:21:06 +08:00
|
|
|
void (*invalidate_authorizer)(struct ceph_auth_client *ac,
|
|
|
|
int peer_type);
|
2009-11-19 08:19:57 +08:00
|
|
|
|
|
|
|
/* reset when we (re)connect to a monitor */
|
|
|
|
void (*reset)(struct ceph_auth_client *ac);
|
|
|
|
|
|
|
|
void (*destroy)(struct ceph_auth_client *ac);
|
2014-11-04 16:33:37 +08:00
|
|
|
|
|
|
|
int (*sign_message)(struct ceph_auth_handshake *auth,
|
|
|
|
struct ceph_msg *msg);
|
|
|
|
int (*check_message_signature)(struct ceph_auth_handshake *auth,
|
|
|
|
struct ceph_msg *msg);
|
2009-11-19 08:19:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ceph_auth_client {
|
|
|
|
u32 protocol; /* CEPH_AUTH_* */
|
|
|
|
void *private; /* for use by protocol implementation */
|
|
|
|
const struct ceph_auth_client_ops *ops; /* null iff protocol==0 */
|
|
|
|
|
|
|
|
bool negotiating; /* true if negotiating protocol */
|
|
|
|
const char *name; /* entity name */
|
|
|
|
u64 global_id; /* our unique id in system */
|
2011-03-26 07:32:57 +08:00
|
|
|
const struct ceph_crypto_key *key; /* our secret key */
|
2009-11-19 08:19:57 +08:00
|
|
|
unsigned want_keys; /* which services we want */
|
2013-03-26 01:26:30 +08:00
|
|
|
|
|
|
|
struct mutex mutex;
|
2009-11-19 08:19:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct ceph_auth_client *ceph_auth_init(const char *name,
|
2011-03-26 07:32:57 +08:00
|
|
|
const struct ceph_crypto_key *key);
|
2009-11-19 08:19:57 +08:00
|
|
|
extern void ceph_auth_destroy(struct ceph_auth_client *ac);
|
|
|
|
|
|
|
|
extern void ceph_auth_reset(struct ceph_auth_client *ac);
|
|
|
|
|
|
|
|
extern int ceph_auth_build_hello(struct ceph_auth_client *ac,
|
|
|
|
void *buf, size_t len);
|
|
|
|
extern int ceph_handle_auth_reply(struct ceph_auth_client *ac,
|
|
|
|
void *buf, size_t len,
|
|
|
|
void *reply_buf, size_t reply_len);
|
|
|
|
extern int ceph_entity_name_encode(const char *name, void **p, void *end);
|
|
|
|
|
2010-02-03 08:21:06 +08:00
|
|
|
extern int ceph_build_auth(struct ceph_auth_client *ac,
|
|
|
|
void *msg_buf, size_t msg_len);
|
|
|
|
|
|
|
|
extern int ceph_auth_is_authenticated(struct ceph_auth_client *ac);
|
2013-03-26 01:26:14 +08:00
|
|
|
extern int ceph_auth_create_authorizer(struct ceph_auth_client *ac,
|
|
|
|
int peer_type,
|
|
|
|
struct ceph_auth_handshake *auth);
|
|
|
|
extern void ceph_auth_destroy_authorizer(struct ceph_auth_client *ac,
|
|
|
|
struct ceph_authorizer *a);
|
|
|
|
extern int ceph_auth_update_authorizer(struct ceph_auth_client *ac,
|
|
|
|
int peer_type,
|
|
|
|
struct ceph_auth_handshake *a);
|
|
|
|
extern int ceph_auth_verify_authorizer_reply(struct ceph_auth_client *ac,
|
|
|
|
struct ceph_authorizer *a,
|
|
|
|
size_t len);
|
|
|
|
extern void ceph_auth_invalidate_authorizer(struct ceph_auth_client *ac,
|
|
|
|
int peer_type);
|
2010-02-03 08:21:06 +08:00
|
|
|
|
2014-11-04 16:33:37 +08:00
|
|
|
static inline int ceph_auth_sign_message(struct ceph_auth_handshake *auth,
|
|
|
|
struct ceph_msg *msg)
|
|
|
|
{
|
|
|
|
if (auth->sign_message)
|
|
|
|
return auth->sign_message(auth, msg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline
|
|
|
|
int ceph_auth_check_message_signature(struct ceph_auth_handshake *auth,
|
|
|
|
struct ceph_msg *msg)
|
|
|
|
{
|
|
|
|
if (auth->check_message_signature)
|
|
|
|
return auth->check_message_signature(auth, msg);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-11-19 08:19:57 +08:00
|
|
|
#endif
|