-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathunlocktask.cpp
More file actions
88 lines (79 loc) · 2.02 KB
/
unlocktask.cpp
File metadata and controls
88 lines (79 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "unlocktask.h"
extern "C" {
#include "signetdev/host/signetdev.h"
}
#include "signetcliapplication.h"
#include <iostream>
void unlockTask::help()
{
std::cout << "Unlock the device by entering your master password." << std::endl
<< std::endl
<< "Usage: signet-cli unlock" << std::endl << std::endl;
}
unlockTask::unlockTask()
{
}
bool unlockTask::canStart()
{
return true;
}
bool unlockTask::start()
{
int token;
::signetdev_get_device_state(NULL, &token);
return true;
}
void unlockTask::doLogin()
{
std::string str;
std::cout << "Enter password:";
std::cout.flush();
std::cin >> str;
}
void unlockTask::cmdResponse(void *cb_user_param, int cmd_token, int cmd, int end_device_state, int messages_remaining, int resp_code, void *resp_data)
{
Q_UNUSED(cb_user_param);
Q_UNUSED(cmd_token);
Q_UNUSED(messages_remaining);
int token;
switch(cmd) {
case SIGNETDEV_CMD_GET_DEVICE_STATE: {
switch (end_device_state) {
case LOGGED_IN:
std::cout << "Device already unlocked" << std::endl;
QCoreApplication::quit();
break;
default:
::signetdev_startup(NULL, &token);
break;
}
} break;
case SIGNETDEV_CMD_STARTUP: {
SignetCLIApplication *app = SignetCLIApplication::get();
signetdev_startup_resp_data *resp = (signetdev_startup_resp_data *) resp_data;
std::cout << "Enter password:";
std::cout.flush();
std::string str;
std::getline(std::cin, str);
u8 key[LOGIN_KEY_SZ];
std::cout << "Please wait while the authenticatio key is being generated..." << std::endl;
app->generateKey(QString(str.c_str()), key, resp->hashfn, resp->salt);
std::cout << "Press device button to login..." << std::endl;
::signetdev_login(NULL, &token, key, LOGIN_KEY_SZ, 0);
} break;
case SIGNETDEV_CMD_LOGIN:
switch (resp_code) {
case BAD_PASSWORD:
std::cout << "Password invalid" << std::endl;
break;
case OKAY:
std::cout << "Device unlocked" << std::endl;
break;
default:
std::cout << "Unexpected error " << resp_code << std::endl;
break;
}
QCoreApplication::quit();
break;
}
}