summaryrefslogtreecommitdiff
path: root/totpgen.h
blob: e9283d8fd6da489eb0efcb9dc5a11ecdb76168c0 (plain)
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 <iostream>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cctype>
#include <unordered_set>

#include <unistd.h>

#include <wx/wx.h>
#include <wx/stdpaths.h>
#include <wx/dir.h>
#include <wx/clipbrd.h>
#include <wx/regex.h>
#include <wx/font.h>

#include <nlohmann/json.hpp>
using json = nlohmann::json;

static const std::string base32 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";

class TOTPGenGUI : public wxApp {
	public:
		virtual bool OnInit();
};

class TOTPGen : public wxFrame {
	public:
		TOTPGen();

	private:
		wxPanel *MainWindow;
		wxBoxSizer *MainSizer;

		wxBoxSizer *SelectSizer;
		wxBoxSizer *TextSizer;

		wxBoxSizer *ButtonSizer_Upper;
		wxBoxSizer *ButtonSizer_Middle;
		wxBoxSizer *ButtonSizer_Lower;

		wxComboBox *SecretChooser;
		void ReloadSelections(void);
		void SelectSecret(wxCommandEvent& event);

		wxStaticText *TOTPField;
		void ResizeTextToFit(wxStaticText *text_field);

		wxTimer *CountdownTimer;
		wxGauge *CountdownGauge;
		void UpdateStatus(wxTimerEvent& event);

		wxButton *AddButton;
		void AddSecret(wxCommandEvent& event);
		bool IsBase32(std::string& str);

		wxButton *DeleteButton;
		void DeleteSecret(wxCommandEvent& event);

		wxButton *CopyButton;
		void CopyText(wxCommandEvent& event);

		wxButton *QuitButton;
		void OnExit(wxCommandEvent& event);

		std::string Passphrase;
		wxButton *SecurityButton;
		void InitDB(wxCommandEvent& event);
		void SetPassword(wxCommandEvent& event);
		void Unlock(wxCommandEvent& event);

		json KeyDB;
		wxString SecretDB_File;
		void InitAES(const char *passphrase,
		             unsigned char *salt,
		             unsigned char *key,
		             unsigned char *iv);
		bool DecryptDB(void);
		bool EncryptDB(const std::string& secret_str);

		std::string Secret;
		std::string TOTP;
		bool GenTOTP(const std::string& secret_str);
};