Skip to content

Commit

Permalink
ceph-dencoder: Add missing common types to ceph-dencoder for accurate…
Browse files Browse the repository at this point in the history
… encode-decode comparison

Currently, ceph-dencoder lacks certain common types, preventing us from accurately checking the ceph corpus for encode-decode mismatches.
This pull request aims to address this issue by adding the missing types to ceph-dencoder.

To successfully incorporate these types into ceph-dencoder, we need to introduce the necessary dump and generate_test_instances functions that was missing in some types.
These functions are essential for proper encode and decode of the added types.

This PR will enhance the functionality of ceph-dencoder by including the missing types, enabling a comprehensive analysis of encode-decode consistency.
With the addition of these types, we can ensure the robustness and correctness of the ceph corpus.

This update will significantly contribute to improving the overall reliability and accuracy of ceph-dencoder.
It allows for a more comprehensive assessment of the encode-decode behavior,
leading to enhanced data integrity and stability within the ceph ecosystem.

Fixes: https://tracker.ceph.com/issues/61788
Signed-off-by: Nitzan Mordechai <nmordech@redhat.com>
  • Loading branch information
NitzanMordhai committed Jul 17, 2023
1 parent 923e7ba commit 6a47b20
Show file tree
Hide file tree
Showing 33 changed files with 1,168 additions and 16 deletions.
62 changes: 62 additions & 0 deletions src/auth/Auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ struct AuthCapsInfo {
allow_all = (bool)a;
decode(caps, bl);
}
void dump(ceph::Formatter *f) const {
f->dump_bool("allow_all", allow_all);
f->dump_int("caps", caps.length());
f->open_array_section("caps_list");
for (const auto& node : caps.buffers()) {
f->dump_string("node", node.c_str());
}
f->close_section();
}
static void generate_test_instances(std::list<AuthCapsInfo*>& ls) {
ls.push_back(new AuthCapsInfo);
ls.push_back(new AuthCapsInfo);
ls.back()->allow_all = true;
ls.push_back(new AuthCapsInfo);
ls.back()->caps.append("foo");
ls.back()->caps.append("bar");
}
};
WRITE_CLASS_ENCODER(AuthCapsInfo)

Expand Down Expand Up @@ -147,6 +164,24 @@ struct AuthTicket {
decode(caps, bl);
decode(flags, bl);
}
void dump(ceph::Formatter *f) const {
f->dump_stream("name") << name;
f->dump_unsigned("global_id", global_id);
f->dump_stream("created") << created;
f->dump_stream("renew_after") << renew_after;
f->dump_stream("expires") << expires;
caps.dump(f);
f->dump_unsigned("flags", flags);
}
static void generate_test_instances(std::list<AuthTicket*>& ls) {
ls.push_back(new AuthTicket);
ls.push_back(new AuthTicket);
ls.back()->name.set_type(CEPH_ENTITY_TYPE_OSD);
ls.back()->global_id = 123;
ls.back()->init_timestamps(utime_t(), 100);
ls.back()->caps.allow_all = true;
ls.back()->flags = 0;
}
};
WRITE_CLASS_ENCODER(AuthTicket)

Expand Down Expand Up @@ -231,6 +266,17 @@ struct ExpiringCryptoKey {
decode(key, bl);
decode(expiration, bl);
}
void dump(ceph::Formatter *f) const {
f->dump_stream("key") << key;
f->dump_stream("expiration") << expiration;
}
static void generate_test_instances(std::list<ExpiringCryptoKey*>& ls) {
ls.push_back(new ExpiringCryptoKey);
ls.push_back(new ExpiringCryptoKey);
ls.back()->key.set_secret(CEPH_CRYPTO_AES, bufferptr("1234567890123456", 16),
utime_t(123, 456));
ls.back()->expiration = utime_t(1, 2);
}
};
WRITE_CLASS_ENCODER(ExpiringCryptoKey)

Expand Down Expand Up @@ -295,6 +341,22 @@ struct RotatingSecrets {
}

void dump();
void dump(ceph::Formatter *f) const {
f->open_array_section("secrets");
for (auto& i : secrets) {
f->open_object_section("secret");
f->dump_unsigned("ver", i.first);
i.second.dump(f);
f->close_section();
}
f->close_section();
}
static void generate_test_instances(std::list<RotatingSecrets*>& ls) {
ls.push_back(new RotatingSecrets);
ls.push_back(new RotatingSecrets);
auto expire = new ExpiringCryptoKey;
ls.back()->add(*expire);
}
};
WRITE_CLASS_ENCODER(RotatingSecrets)

Expand Down
17 changes: 17 additions & 0 deletions src/auth/Crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,23 @@ void CryptoKey::decode(bufferlist::const_iterator& bl)
throw ceph::buffer::malformed_input("malformed secret");
}

void CryptoKey::dump(Formatter *f) const
{
f->dump_int("type", type);
f->dump_stream("created") << created;
f->dump_int("secret.length", secret.length());
}

void CryptoKey::generate_test_instances(std::list<CryptoKey*>& ls)
{
ls.push_back(new CryptoKey);
ls.push_back(new CryptoKey);
ls.back()->type = CEPH_CRYPTO_AES;
ls.back()->set_secret(CEPH_CRYPTO_AES, bufferptr("1234567890123456", 16),
utime_t(123, 456));
ls.back()->created = utime_t(123, 456);
}

int CryptoKey::set_secret(int type, const bufferptr& s, utime_t c)
{
int r = _set_secret(type, s);
Expand Down
2 changes: 2 additions & 0 deletions src/auth/Crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class CryptoKey {

void encode(ceph::buffer::list& bl) const;
void decode(ceph::buffer::list::const_iterator& bl);
void dump(ceph::Formatter *f) const;
static void generate_test_instances(std::list<CryptoKey*>& ls);

void clear() {
*this = CryptoKey();
Expand Down
128 changes: 128 additions & 0 deletions src/auth/cephx/CephxProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ struct CephXServerChallenge {
decode(struct_v, bl);
decode(server_challenge, bl);
}
void dump(ceph::Formatter *f) const {
f->dump_unsigned("server_challenge", server_challenge);
}
static void generate_test_instances(std::list<CephXServerChallenge*>& ls) {
ls.push_back(new CephXServerChallenge);
ls.push_back(new CephXServerChallenge);
ls.back()->server_challenge = 1;
}
};
WRITE_CLASS_ENCODER(CephXServerChallenge)

Expand All @@ -72,6 +80,14 @@ struct CephXRequestHeader {
using ceph::decode;
decode(request_type, bl);
}
void dump(ceph::Formatter *f) const {
f->dump_unsigned("request_type", request_type);
}
static void generate_test_instances(std::list<CephXRequestHeader*>& ls) {
ls.push_back(new CephXRequestHeader);
ls.push_back(new CephXRequestHeader);
ls.back()->request_type = 1;
}
};
WRITE_CLASS_ENCODER(CephXRequestHeader)

Expand All @@ -89,6 +105,16 @@ struct CephXResponseHeader {
decode(request_type, bl);
decode(status, bl);
}
void dump(ceph::Formatter *f) const {
f->dump_unsigned("request_type", request_type);
f->dump_int("status", status);
}
static void generate_test_instances(std::list<CephXResponseHeader*>& ls) {
ls.push_back(new CephXResponseHeader);
ls.push_back(new CephXResponseHeader);
ls.back()->request_type = 1;
ls.back()->status = 0;
}
};
WRITE_CLASS_ENCODER(CephXResponseHeader)

Expand All @@ -113,6 +139,18 @@ struct CephXTicketBlob {
decode(secret_id, bl);
decode(blob, bl);
}

void dump(ceph::Formatter *f) const {
f->dump_unsigned("secret_id", secret_id);
f->dump_unsigned("blob_len", blob.length());
}

static void generate_test_instances(std::list<CephXTicketBlob*>& ls) {
ls.push_back(new CephXTicketBlob);
ls.push_back(new CephXTicketBlob);
ls.back()->secret_id = 123;
ls.back()->blob.append("this is a blob", 14);
}
};
WRITE_CLASS_ENCODER(CephXTicketBlob)

Expand Down Expand Up @@ -152,6 +190,23 @@ struct CephXAuthenticate {
// old_ticket both on reconnects and renewals
old_ticket_may_be_omitted = struct_v < 3;
}
void dump(ceph::Formatter *f) const {
f->dump_unsigned("client_challenge", client_challenge);
f->dump_unsigned("key", key);
f->open_object_section("old_ticket");
old_ticket.dump(f);
f->close_section();
f->dump_unsigned("other_keys", other_keys);
}
static void generate_test_instances(std::list<CephXAuthenticate*>& ls) {
ls.push_back(new CephXAuthenticate);
ls.push_back(new CephXAuthenticate);
ls.back()->client_challenge = 1;
ls.back()->key = 2;
ls.back()->old_ticket.secret_id = 3;
ls.back()->old_ticket.blob.append("this is a blob", 14);
ls.back()->other_keys = 4;
}
};
WRITE_CLASS_ENCODER(CephXAuthenticate)

Expand All @@ -168,6 +223,16 @@ struct CephXChallengeBlob {
decode(server_challenge, bl);
decode(client_challenge, bl);
}
void dump(ceph::Formatter *f) const {
f->dump_unsigned("server_challenge", server_challenge);
f->dump_unsigned("client_challenge", client_challenge);
}
static void generate_test_instances(std::list<CephXChallengeBlob*>& ls) {
ls.push_back(new CephXChallengeBlob);
ls.push_back(new CephXChallengeBlob);
ls.back()->server_challenge = 123;
ls.back()->client_challenge = 456;
}
};
WRITE_CLASS_ENCODER(CephXChallengeBlob)

Expand Down Expand Up @@ -218,6 +283,16 @@ struct CephXServiceTicketRequest {
decode(struct_v, bl);
decode(keys, bl);
}

void dump(ceph::Formatter *f) const {
f->dump_unsigned("keys", keys);
}

static void generate_test_instances(std::list<CephXServiceTicketRequest*>& ls) {
ls.push_back(new CephXServiceTicketRequest);
ls.push_back(new CephXServiceTicketRequest);
ls.back()->keys = 123;
}
};
WRITE_CLASS_ENCODER(CephXServiceTicketRequest)

Expand Down Expand Up @@ -251,6 +326,16 @@ struct CephXAuthorizeReply {
decode(connection_secret, bl);
}
}
void dump(ceph::Formatter *f) const {
f->dump_unsigned("nonce_plus_one", nonce_plus_one);
f->dump_string("connection_secret", connection_secret);
}
static void generate_test_instances(std::list<CephXAuthorizeReply*>& ls) {
ls.push_back(new CephXAuthorizeReply);
ls.push_back(new CephXAuthorizeReply);
ls.back()->nonce_plus_one = 123;
ls.back()->connection_secret = "secret";
}
};
WRITE_CLASS_ENCODER(CephXAuthorizeReply)

Expand Down Expand Up @@ -353,6 +438,17 @@ struct CephXServiceTicket {
decode(session_key, bl);
decode(validity, bl);
}
void dump(ceph::Formatter *f) const {
session_key.dump(f);
validity.dump(f);
}
static void generate_test_instances(std::list<CephXServiceTicket*>& ls) {
ls.push_back(new CephXServiceTicket);
ls.push_back(new CephXServiceTicket);
ls.back()->session_key.set_secret(CEPH_CRYPTO_AES, bufferptr("1234567890123456", 16),
utime_t(123, 456));
ls.back()->validity = utime_t(123, 456);
}
};
WRITE_CLASS_ENCODER(CephXServiceTicket)

Expand All @@ -375,6 +471,18 @@ struct CephXServiceTicketInfo {
decode(ticket, bl);
decode(session_key, bl);
}
void dump(ceph::Formatter *f) const {
ticket.dump(f);
session_key.dump(f);
}
static void generate_test_instances(std::list<CephXServiceTicketInfo*>& ls) {
ls.push_back(new CephXServiceTicketInfo);
ls.push_back(new CephXServiceTicketInfo);
ls.back()->ticket.global_id = 1234;
ls.back()->ticket.init_timestamps(utime_t(123, 456), utime_t(123, 456));
ls.back()->session_key.set_secret(CEPH_CRYPTO_AES, bufferptr("1234567890123456", 16),
utime_t(123, 456));
}
};
WRITE_CLASS_ENCODER(CephXServiceTicketInfo)

Expand All @@ -392,6 +500,14 @@ struct CephXAuthorizeChallenge : public AuthAuthorizerChallenge {
decode(struct_v, bl);
decode(server_challenge, bl);
}
void dump(ceph::Formatter *f) const {
f->dump_unsigned("server_challenge", server_challenge);
}
static void generate_test_instances(std::list<CephXAuthorizeChallenge*>& ls) {
ls.push_back(new CephXAuthorizeChallenge);
ls.push_back(new CephXAuthorizeChallenge);
ls.back()->server_challenge = 1234;
}
};
WRITE_CLASS_ENCODER(CephXAuthorizeChallenge)

Expand All @@ -417,6 +533,18 @@ struct CephXAuthorize {
decode(server_challenge_plus_one, bl);
}
}
void dump(ceph::Formatter *f) const {
f->dump_unsigned("nonce", nonce);
f->dump_unsigned("have_challenge", have_challenge);
f->dump_unsigned("server_challenge_plus_one", server_challenge_plus_one);
}
static void generate_test_instances(std::list<CephXAuthorize*>& ls) {
ls.push_back(new CephXAuthorize);
ls.push_back(new CephXAuthorize);
ls.back()->nonce = 1234;
ls.back()->have_challenge = true;
ls.back()->server_challenge_plus_one = 1234;
}
};
WRITE_CLASS_ENCODER(CephXAuthorize)

Expand Down

0 comments on commit 6a47b20

Please sign in to comment.