summaryrefslogtreecommitdiff
path: root/plugins/SecureIM/src/crypt_check.cpp
blob: 183f93f62f70bc8096cac946222ba588765f4d06 (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 (!db_get_s(hContact, MODULENAME, "pgp", &dbv)) {
			res |= SECURED;
			db_free(&dbv);
		}
		break;

	case MODE_GPG:
		if (!db_get_s(hContact, MODULENAME, "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 CallProtoService(p->proto->name, PS_GETSTATUS, 0, 0) == 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 (db_get_s(hContact, MODULENAME, "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 (db_get_s(hContact, MODULENAME, "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;
}