1    	#ifndef CEPH_CLS_OTP_TYPES_H
2    	#define CEPH_CLS_OTP_TYPES_H
3    	
4    	#include "include/encoding.h"
5    	#include "include/types.h"
6    	
7    	
8    	#define CLS_OTP_MAX_REPO_SIZE 100
9    	
10   	class JSONObj;
11   	
12   	namespace rados {
13   	  namespace cls {
14   	    namespace otp {
15   	
16   	      enum OTPType {
17   	        OTP_UNKNOWN = 0,
18   	        OTP_HOTP = 1,  /* unsupported */
19   	        OTP_TOTP = 2,
20   	      };
21   	
22   	      enum SeedType {
23   	        OTP_SEED_UNKNOWN = 0,
24   	        OTP_SEED_HEX = 1,
25   	        OTP_SEED_BASE32 = 2,
26   	      };
27   	
28   	      struct otp_info_t {
29   	        OTPType type{OTP_TOTP};
30   	        string id;
31   	        string seed;
32   	        SeedType seed_type{OTP_SEED_UNKNOWN};
33   	        bufferlist seed_bin; /* parsed seed, built automatically by otp_set_op,
34   	                              * not being json encoded/decoded on purpose
35   	                              */
36   	        int32_t time_ofs{0};
37   	        uint32_t step_size{30}; /* num of seconds foreach otp to test */
38   	        uint32_t window{2}; /* num of otp after/before start otp to test */
39   	
40   	        otp_info_t() {}
41   	
42   	        void encode(bufferlist &bl) const {
43   	          ENCODE_START(1, 1, bl);
44   	          encode((uint8_t)type, bl);
45   	          /* if we ever implement anything other than TOTP
46   	           * then we'll need to branch here */
47   	          encode(id, bl);
48   	          encode(seed, bl);
49   	          encode((uint8_t)seed_type, bl);
50   	          encode(seed_bin, bl);
51   	          encode(time_ofs, bl);
52   	          encode(step_size, bl);
53   	          encode(window, bl);
54   	          ENCODE_FINISH(bl);
55   	        }
56   	        void decode(bufferlist::const_iterator &bl) {
57   	          DECODE_START(1, bl);
58   	          uint8_t t;
59   	          decode(t, bl);
60   	          type = (OTPType)t;
61   	          decode(id, bl);
62   	          decode(seed, bl);
63   	          uint8_t st;
64   	          decode(st, bl);
65   	          seed_type = (SeedType)st;
66   	          decode(seed_bin, bl);
67   	          decode(time_ofs, bl);
68   	          decode(step_size, bl);
69   	          decode(window, bl);
70   	          DECODE_FINISH(bl);
71   	        }
72   	        void dump(Formatter *f) const;
73   	        void decode_json(JSONObj *obj);
74   	      };
75   	      WRITE_CLASS_ENCODER(rados::cls::otp::otp_info_t)
76   	
77   	      enum OTPCheckResult {
78   	        OTP_CHECK_UNKNOWN = 0,
79   	        OTP_CHECK_SUCCESS = 1,
80   	        OTP_CHECK_FAIL = 2,
81   	      };
82   	
83   	      struct otp_check_t {
84   	        string token;
85   	        ceph::real_time timestamp;
86   	        OTPCheckResult result{OTP_CHECK_UNKNOWN};
87   	
88   	        void encode(bufferlist &bl) const {
89   	          ENCODE_START(1, 1, bl);
90   	          encode(token, bl);
91   	          encode(timestamp, bl);
(1) Event overrun-buffer-val: Overrunning buffer pointed to by "char const((char)this->result)" of 1 bytes by passing it to a function which accesses it at byte offset 7. [details]
92   	          encode((char)result, bl);
93   	          ENCODE_FINISH(bl);
94   	        }
95   	        void decode(bufferlist::const_iterator &bl) {
96   	          DECODE_START(1, bl);
97   	          decode(token, bl);
98   	          decode(timestamp, bl);
99   	          uint8_t t;
100  	          decode(t, bl);
101  	          result = (OTPCheckResult)t;
102  	          DECODE_FINISH(bl);
103  	        }
104  	      };
105  	      WRITE_CLASS_ENCODER(rados::cls::otp::otp_check_t)
106  	
107  	      struct otp_repo_t {
108  	        map<string, otp_info_t> entries;
109  	
110  	        otp_repo_t() {}
111  	
112  	        void encode(bufferlist &bl) const {
113  	          ENCODE_START(1, 1, bl);
114  	          encode(entries, bl);
115  	          ENCODE_FINISH(bl);
116  	        }
117  	        void decode(bufferlist::const_iterator &bl) {
118  	          DECODE_START(1, bl);
119  	          decode(entries, bl);
120  	          DECODE_FINISH(bl);
121  	        }
122  	      };
123  	      WRITE_CLASS_ENCODER(rados::cls::otp::otp_repo_t)
124  	    }
125  	  }
126  	}
127  	
128  	WRITE_CLASS_ENCODER(rados::cls::otp::otp_info_t)
129  	WRITE_CLASS_ENCODER(rados::cls::otp::otp_check_t)
130  	WRITE_CLASS_ENCODER(rados::cls::otp::otp_repo_t)
131  	
132  	#endif
133