summaryrefslogtreecommitdiff
path: root/totpgen.h
blob: 8feee9acb79b5e6c492dca903953e83cb9641172 (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
#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>

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 *ButtonSizer_Upper;
		wxBoxSizer *ButtonSizer_Lower;

		wxButton *UpdateSecretButton;
		void UpdateSecret(wxCommandEvent& event);

		bool Locked;
		wxButton *UnlockButton;
		void Unlock(wxCommandEvent& event);

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

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

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

		wxString SecretFile;

		void InitAES(const char *passphrase,
		             unsigned char *salt,
		             unsigned char *key,
		             unsigned char *iv);

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

		std::string Secret;
		std::string Passphrase;

		bool IsBase32(std::string& str);

		bool DecryptSecret(void);
		bool EncryptSecret(std::string& secret_str);

		std::string TOTP;

		bool GenTOTP(std::string& secret_str);
};