]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #include "auth/cephx/CephxKeyServer.h" |
2 | #include "common/ceph_argparse.h" | |
3 | #include "global/global_init.h" | |
4 | #include "common/config.h" | |
5 | #include "common/debug.h" | |
6 | ||
7 | #define dout_context g_ceph_context | |
8 | ||
9 | #define AES_KEY_LEN 16 | |
10 | ||
20effc67 TL |
11 | using namespace std; |
12 | ||
7c673cae FG |
13 | int main(int argc, const char **argv) |
14 | { | |
20effc67 | 15 | auto args = argv_to_vec(argc, argv); |
7c673cae FG |
16 | |
17 | auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, | |
11fdf7f2 TL |
18 | CODE_ENVIRONMENT_UTILITY, |
19 | CINIT_FLAG_NO_DEFAULT_CONFIG_FILE); | |
7c673cae FG |
20 | common_init_finish(g_ceph_context); |
21 | KeyRing extra; | |
22 | KeyServer server(g_ceph_context, &extra); | |
23 | ||
24 | generic_dout(0) << "server created" << dendl; | |
25 | ||
26 | getchar(); | |
27 | ||
28 | #if 0 | |
29 | char aes_key[AES_KEY_LEN]; | |
30 | memset(aes_key, 0x77, sizeof(aes_key)); | |
31 | bufferptr keybuf(aes_key, sizeof(aes_key)); | |
32 | CryptoKey key(CEPH_CRYPTO_AES, ceph_clock_now(), keybuf); | |
33 | ||
34 | const char *msg="hello! this is a message\n"; | |
35 | char pad[16]; | |
36 | memset(pad, 0, 16); | |
37 | bufferptr ptr(msg, strlen(msg)); | |
38 | bufferlist enc_in; | |
39 | enc_in.append(ptr); | |
40 | enc_in.append(msg, strlen(msg)); | |
41 | ||
42 | bufferlist enc_out; | |
43 | if (key.encrypt(enc_in, enc_out) < 0) { | |
44 | derr(0) << "couldn't encode!" << dendl; | |
45 | exit(1); | |
46 | } | |
47 | ||
48 | const char *enc_buf = enc_out.c_str(); | |
49 | for (unsigned i=0; i<enc_out.length(); i++) { | |
50 | std::cout << hex << (int)(unsigned char)enc_buf[i] << dec << " "; | |
51 | if (i && !(i%16)) | |
52 | std::cout << std::endl; | |
53 | } | |
54 | ||
55 | bufferlist dec_in, dec_out; | |
56 | ||
57 | dec_in = enc_out; | |
58 | ||
59 | if (key.decrypt(dec_in, dec_out) < 0) { | |
60 | derr(0) << "couldn't decode!" << dendl; | |
61 | } | |
62 | ||
63 | dout(0) << "decoded len: " << dec_out.length() << dendl; | |
64 | dout(0) << "decoded msg: " << dec_out.c_str() << dendl; | |
65 | ||
66 | return 0; | |
67 | #endif | |
68 | } | |
69 |