Browse code
Integrate OTP code into dual_control; various
- Add core files to .gitignore
- Add crypto++ to .travis.yml and Makefile
Showing 8 changed files
- .gitignore
- .travis.yml
- Makefile.in
- dual_control_tool.cc
- generator.cc
- generator.h
- installer.cc
- installer.h
... | ... |
@@ -1,6 +1,7 @@ |
1 | 1 |
CXXFLAGS += -fPIC -fno-stack-protector -std=c++14 -g |
2 | 2 |
CFLAGS += -fPIC -fno-stack-protector -g |
3 |
-LDFLAGS = -lcryptopp -lpam |
|
3 |
+LDFLAGS = -Wl,-Bstatic -lcrypto++ -Wl,-Bdynamic -lpam -Wl,--as-needed |
|
4 |
+#LDFLAGS = -lcrypto++ -lpam -Wl,--as-needed |
|
4 | 5 |
|
5 | 6 |
INTEGRATION_OBJS = sys_syslog.o sys_fstream.o sys_unistd.o sys_pwd.o sys_pam.o \ |
6 | 7 |
sys_stdlib.o sys_time.o |
... | ... |
@@ -40,14 +40,10 @@ installer init_installer() |
40 | 40 |
unistd unistd (unistd::create()); |
41 | 41 |
directory directory (directory::create (unistd, pwd)); |
42 | 42 |
stdlib stdlib (stdlib::get()); |
43 |
- sys_time timer (sys_time::get()); |
|
43 |
+ sys_time time (sys_time::get()); |
|
44 | 44 |
int code_digits = 6; |
45 |
- auto the_generator = |
|
46 |
- std::make_shared<totp_generator> (timer, "\x00", code_digits); |
|
47 |
- generator generator = std::bind (&totp_generator::generate_token, |
|
48 |
- the_generator); |
|
49 |
- installer installer (installer::create (tokens, unistd, directory, |
|
50 |
- generator)); |
|
45 |
+ auto the_generator = std::make_shared<totp_generator> (time, "\x00", code_digits); |
|
46 |
+ installer installer (installer::create (tokens, unistd, directory, the_generator)); |
|
51 | 47 |
|
52 | 48 |
return installer; |
53 | 49 |
} |
... | ... |
@@ -12,6 +12,7 @@ |
12 | 12 |
#include "generator.h" |
13 | 13 |
#include <iostream> |
14 | 14 |
|
15 |
+namespace { |
|
15 | 16 |
int ipow (int base, int exp) |
16 | 17 |
{ |
17 | 18 |
int result = 1; |
... | ... |
@@ -47,7 +48,7 @@ time_t time_step (const time_t time, const int step) |
47 | 48 |
return time / step; |
48 | 49 |
} |
49 | 50 |
|
50 |
-class impl : public token_generator_ifc |
|
51 |
+class token_generator_impl : public token_generator_ifc |
|
51 | 52 |
{ |
52 | 53 |
private: |
53 | 54 |
unsigned long truncate (const std::string &mac) const |
... | ... |
@@ -91,24 +92,23 @@ private: |
91 | 92 |
return key; |
92 | 93 |
} |
93 | 94 |
|
94 |
- const sys_time &sys_time; |
|
95 |
+ const sys_time &clock; |
|
95 | 96 |
unsigned int code_digits; |
96 | 97 |
const std::shared_ptr<CryptoPP::SecByteBlock> key; |
97 | 98 |
public: |
98 |
- impl (const class sys_time &sys_time, |
|
99 |
+ token_generator_impl (const sys_time &clock, |
|
99 | 100 |
const std::string &key_c, |
100 | 101 |
const int code_digits) : |
101 |
- sys_time (sys_time), code_digits (code_digits), |
|
102 |
+ clock (clock), code_digits (code_digits), |
|
102 | 103 |
key (std::make_shared<CryptoPP::SecByteBlock> (CryptoPP::SecByteBlock ( |
103 | 104 |
reinterpret_cast<const unsigned char *> (key_c.c_str()), key_c.size()))) |
104 | 105 |
{} |
105 | 106 |
|
106 | 107 |
std::string generate_token () const override |
107 | 108 |
{ |
109 |
+ clock.time(nullptr); |
|
108 | 110 |
time_t foo = 111; |
109 |
- const CryptoPP::Integer &time = sys_time.time (&foo); |
|
110 |
- std::cout << "At the tone, the time is: " << foo << " or " << time << "\a" |
|
111 |
- << std::endl; |
|
111 |
+ const CryptoPP::Integer &time = clock.time (&foo); |
|
112 | 112 |
int time_step_size = 30; |
113 | 113 |
CryptoPP::Integer current_step = time_step (time.ConvertToLong(), |
114 | 114 |
time_step_size); |
... | ... |
@@ -118,16 +118,13 @@ public: |
118 | 118 |
return is.str(); |
119 | 119 |
} |
120 | 120 |
}; |
121 |
+} |
|
121 | 122 |
|
122 | 123 |
// Generator goes here.... |
123 | 124 |
|
124 | 125 |
totp_generator::totp_generator ( |
125 |
- const class sys_time |
|
126 |
- &sys_time, |
|
126 |
+ const sys_time &clock, |
|
127 | 127 |
const std::string &key_c, |
128 | 128 |
const int code_digits) : |
129 |
- delegate_ (std::make_shared<impl> (sys_time, |
|
130 |
- key_c, |
|
131 |
- code_digits)) |
|
129 |
+ delegate_ (std::make_shared<token_generator_impl> (clock, key_c, code_digits)) |
|
132 | 130 |
{} |
133 |
- |
... | ... |
@@ -27,10 +27,11 @@ private: |
27 | 27 |
tokens tokens_; |
28 | 28 |
unistd unistd_; |
29 | 29 |
directory directory_; |
30 |
- generator generator_; |
|
30 |
+ std::shared_ptr<totp_generator> generator_; |
|
31 | 31 |
public: |
32 | 32 |
impl (const tokens &tokens, const unistd &unistd, |
33 |
- const directory &directory, const generator &generator) : |
|
33 |
+ const directory &directory, |
|
34 |
+ const std::shared_ptr<totp_generator> generator) : |
|
34 | 35 |
tokens_ (tokens), unistd_ (unistd), directory_ (directory), |
35 | 36 |
generator_ (generator) {} |
36 | 37 |
std::string install_token() const override |
... | ... |
@@ -50,7 +51,7 @@ public: |
50 | 51 |
} |
51 | 52 |
|
52 | 53 |
user user (found_user[0]); |
53 |
- std::string token (generator_()); |
|
54 |
+ std::string token (generator_->generate_token()); |
|
54 | 55 |
tokens_.save (user, token); |
55 | 56 |
return token; |
56 | 57 |
} |
... | ... |
@@ -59,7 +60,7 @@ public: |
59 | 60 |
} |
60 | 61 |
|
61 | 62 |
installer installer::create (const tokens &tokens, const unistd &unistd, |
62 |
- const directory &directory, const generator &generator) |
|
63 |
+ const directory &directory, const std::shared_ptr<totp_generator> generator) |
|
63 | 64 |
{ |
64 | 65 |
return installer (std::make_shared<impl> (tokens, unistd, directory, |
65 | 66 |
generator)); |
... | ... |
@@ -44,7 +44,7 @@ public: |
44 | 44 |
return delegate_->install_token(); |
45 | 45 |
} |
46 | 46 |
static installer create (const tokens &tokens, const unistd &unistd, |
47 |
- const directory &directory, const generator &generator); |
|
47 |
+ const directory &directory, const std::shared_ptr<totp_generator> generator); |
|
48 | 48 |
}; |
49 | 49 |
|
50 | 50 |
#endif |