This repository was archived by the owner on Mar 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
88 lines (73 loc) · 2.48 KB
/
main.cc
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
/*
Copyright (C) 2024 Selwin van Dijk
This file is part of get_signal_desktop_key_mac.
get_signal_desktop_key_mac is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
get_signal_desktop_key_mac is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with get_signal_desktop_key_mac. If not, see <https://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <cstdlib>
#include "main.h"
bool g_verbose;
int main(int argc, char *argv[])
{
auto getKey = [](std::set<std::string> const &secrets, std::string const &encryptedkey, std::string &decrypted)
{
if (g_verbose) [[unlikely]]
for (auto const &s : secrets)
std::cout << "(Got secrets: " << s << ")" << std::endl;
for (auto const &s : secrets)
{
decrypted = decryptKey_linux_mac(s, encryptedkey);
if (!decrypted.empty())
return true;
}
return false;
};
// arg handling
g_verbose = false;
std::string signal_config_file(std::getenv("HOME"));
signal_config_file += "/Library/Application Support/Signal/config.json";
for (int i = 1; i < argc; ++i)
{
if (argv[i] == "-v"s)
g_verbose = true;
else
signal_config_file = argv[i];
}
// get encrypted key from Signal Desktop config
std::string encryptedkey = getEncryptedKey(signal_config_file);
if (encryptedkey.empty())
{
std::cout << "Failed to get encrypted key" << std::endl;
return 1;
}
if (g_verbose) [[unlikely]] std::cout << "(Encrypted key: " << encryptedkey << ")" << std::endl;
std::set<std::string> secrets;
std::string decrypted;
// get secret from libsecret (should work on Gnome and KDE 6)
getSecret_Mac(&secrets);
if (getKey(secrets, encryptedkey, decrypted)) // try what we got now (maybe we dont need to check kwallet)...
{
std::cout << " *** Decrypted key : " << decrypted << " ***" << std::endl;
return 0;
}
if (secrets.empty())
{
std::cout << "Failed to get any secrets" << std::endl;
return 1;
}
if (decrypted.empty())
{
std::cout << "Failed to decrypt valid key. :(" << std::endl;
return 1;
}
return 1;
}