summaryrefslogtreecommitdiff
path: root/plugins/SecureIM/src/crypt_check.cpp
blob: 0b9242d9e2926ed6f34b8c78ed13942f56c1a384 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include "commonheaders.h"

int getContactStatus(MCONTACT hContact)
{
	pSupPro ptr = getSupPro(hContact);
	if (ptr)
		return db_get_w(hContact, ptr->name, "Status", ID_STATUS_OFFLINE);

	return -1;
}

bool isSecureProtocol(MCONTACT hContact)
{
	pSupPro ptr = getSupPro(hContact);
	if (!ptr)
		return false;

	return ptr->inspecting != 0;
}

BYTE isContactSecured(MCONTACT hContact)
{
	// нужна проверка на Offline и в этом случае другие статусы
	if (!arClist.getCount()) return 0;

	if (db_mc_isMeta(hContact))
		hContact = db_mc_getMostOnline(hContact); // возьмем тот, через который пойдет сообщение

	pUinKey p = findUinKey(hContact);
	if (!p || !p->proto || !p->proto->inspecting)
		return false;

	BYTE res = p->mode;
	DBVARIANT dbv;
	switch (p->mode) {
	case MODE_NATIVE:
		if (cpp_keyx(p->cntx) != 0) res |= SECURED;
		break;

	case MODE_PGP:
		if (!g_plugin.getString(hContact, "pgp", &dbv)) {
			res |= SECURED;
			db_free(&dbv);
		}
		break;

	case MODE_GPG:
		if (!g_plugin.getString(hContact, "gpg", &dbv)) {
			res |= SECURED;
			db_free(&dbv);
		}
		break;

	case MODE_RSAAES:
		if (mir_exp->rsa_get_state(p->cntx) == 7) res |= SECURED;
		break;

	case MODE_RSA:
		if (p->cntx != nullptr) res |= SECURED;
		break;
	}
	return res;
}

bool isClientMiranda(pUinKey ptr, BOOL emptyMirverAsMiranda)
{
	if (!bMCD) return true;
	if (!ptr->proto->inspecting) return false;

	bool isMiranda = true;
	LPSTR mirver = db_get_sa(ptr->hContact, ptr->proto->name, "MirVer");
	if (mirver) {
		isMiranda = (emptyMirverAsMiranda && !*mirver) || (strstr(mirver, "Miranda") != nullptr);
		mir_free(mirver);
	}
	return isMiranda;
}

bool isClientMiranda(MCONTACT hContact, BOOL emptyMirverAsMiranda)
{
	if (!bMCD) return true;
	if (!arClist.getCount()) return false;

	pUinKey p = findUinKey(hContact);
	return (p) ? isClientMiranda(p, emptyMirverAsMiranda) : false;
}

bool isProtoSmallPackets(MCONTACT hContact)
{
	pUinKey p = findUinKey(hContact);
	if (!p || !p->proto || !p->proto->inspecting)
		return false;

	return strstr(p->proto->name, "IRC") != nullptr || strstr(p->proto->name, "WinPopup") != nullptr || strstr(p->proto->name, "VyChat") != nullptr;
}

bool isContactInvisible(MCONTACT hContact)
{
	if (!db_mc_isSub(hContact) && db_get_b(hContact, "CList", "Hidden", 0))
		return true;

	pUinKey p = findUinKey(hContact);
	if (!p || p->waitForExchange || !p->proto || !p->proto->inspecting)
		return false;

	switch (db_get_w(hContact, p->proto->name, "ApparentMode", 0)) {
	case 0:
		return Proto_GetStatus(p->proto->name) == ID_STATUS_INVISIBLE;
	case ID_STATUS_ONLINE:
		return false;
	case ID_STATUS_OFFLINE:
		return true;
	}
	return false;
}

bool isNotOnList(MCONTACT hContact)
{
	return db_get_b(hContact, "CList", "NotOnList", 0) != 0;
}

bool isContactNewPG(MCONTACT hContact)
{
	pUinKey p = findUinKey(hContact);
	if (!p || !p->proto || !p->proto->inspecting || !p->cntx)
		return false;

	return (p->features & CPP_FEATURES_NEWPG) != 0;
}

bool isContactPGP(MCONTACT hContact)
{
	if (!bPGPloaded || (!bPGPkeyrings && !bPGPprivkey)) return false;

	pUinKey p = findUinKey(hContact);
	if (!p || !p->proto || !p->proto->inspecting || p->mode != MODE_PGP)
		return false;

	DBVARIANT dbv;
	if (g_plugin.getString(hContact, "pgp", &dbv)) return false;
	db_free(&dbv);
	return true;
}

bool isContactGPG(MCONTACT hContact)
{
	if (!bGPGloaded || !bGPGkeyrings) return false;

	pUinKey p = findUinKey(hContact);
	if (!p || !p->proto || !p->proto->inspecting || p->mode != MODE_GPG)
		return false;

	DBVARIANT dbv;
	if (g_plugin.getString(hContact, "gpg", &dbv)) return false;
	db_free(&dbv);
	return true;
}

bool isContactRSAAES(MCONTACT hContact)
{
	pUinKey p = findUinKey(hContact);
	if (!p || !p->proto || !p->proto->inspecting)
		return false;

	return p->mode == MODE_RSAAES;
}

bool isContactRSA(MCONTACT hContact)
{
	pUinKey p = findUinKey(hContact);
	if (!p || !p->proto || !p->proto->inspecting)
		return false;

	return p->mode == MODE_RSA;
}

bool isChatRoom(MCONTACT hContact)
{
	pUinKey p = findUinKey(hContact);
	if (!p || !p->proto || !p->proto->inspecting)
		return false;

	return db_get_b(hContact, p->proto->name, "ChatRoom", 0) != 0;
}

bool isFileExist(LPCSTR filename)
{
	return (GetFileAttributes(filename) != (UINT)-1);
}

bool isSecureIM(pUinKey ptr, BOOL emptyMirverAsSecureIM)
{
	if (!bAIP) return false;
	if (!ptr->proto->inspecting) return false;

	if (bNOL && db_get_b(ptr->hContact, "CList", "NotOnList", 0))
		return false;

	bool isSecureIM = false;
	LPSTR mirver = db_get_sa(ptr->hContact, ptr->proto->name, "MirVer");
	if (mirver) {
		isSecureIM = (emptyMirverAsSecureIM && !*mirver) || (strstr(mirver, "SecureIM") != nullptr) || (strstr(mirver, "secureim") != nullptr);
		mir_free(mirver);
	}
	return isSecureIM;
}

bool isSecureIM(MCONTACT hContact, BOOL emptyMirverAsSecureIM)
{
	if (!bAIP) return false;

	pUinKey p = findUinKey(hContact);
	return (p) ? isSecureIM(p, emptyMirverAsSecureIM) : false;
}