summaryrefslogtreecommitdiff
path: root/plugins/SecureIM/src/crypt_check.cpp
blob: b1bb9512ce1de4342fc03f3e99e88be7e3299b59 (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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#include "commonheaders.h"


int getContactStatus(HANDLE hContact) {

	pSupPro ptr = getSupPro(hContact);
	if (ptr)
		return DBGetContactSettingWord(hContact, ptr->name, "Status", ID_STATUS_OFFLINE);

	return -1;
}


BOOL isSecureProtocol(HANDLE hContact) {

	pSupPro ptr = getSupPro(hContact);
	if (!ptr) return false;

	return ptr->inspecting;
}


BYTE isContactSecured(HANDLE hContact) {
	// íóæíà ïðîâåðêà íà Offline è â ýòîì ñëó÷àå äðóãèå ñòàòóñû
	if (!clist_cnt) return 0;

	BYTE r=0;
	if ( isProtoMetaContacts(hContact))
		hContact = getMostOnline(hContact); // âîçüìåì òîò, ÷åðåç êîòîðûé ïîéäåò ñîîáùåíèå

	for(int j=0;j<clist_cnt;j++) {
		if ( clist[j].hContact == hContact ) {
			if ( !clist[j].proto->inspecting ) break;
       			DBVARIANT dbv;
			r=clist[j].mode;
			switch(r) {
			case MODE_NATIVE:
				if (cpp_keyx(clist[j].cntx)!=0) r|=SECURED;
				break;
			case MODE_PGP:
				DBGetContactSetting(hContact,szModuleName,"pgp",&dbv);
				if ( dbv.type!=0 ) r|=SECURED;
				DBFreeVariant(&dbv);
				break;
			case MODE_GPG:
				DBGetContactSetting(hContact,szModuleName,"gpg",&dbv);
				if ( dbv.type!=0 ) r|=SECURED;
				DBFreeVariant(&dbv);
				break;
			case MODE_RSAAES:
				if (exp->rsa_get_state(clist[j].cntx)==7) r|=SECURED;
				break;
			case MODE_RSA:
				if (clist[j].cntx) r|=SECURED;
				break;
			}
			break;
		}
	}
	return r; // (mode&SECURED) - ïðîâåðêà íà EST/DIS
}


BOOL isClientMiranda(pUinKey ptr, BOOL emptyMirverAsMiranda) {

	if ( !bMCD ) return true;
	if ( !ptr->proto->inspecting ) return false;

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


BOOL isClientMiranda(HANDLE hContact, BOOL emptyMirverAsMiranda) {

	if ( !bMCD ) return true;
	if ( !clist_cnt ) return false;

	for(int j=0;j<clist_cnt;j++) {
		if ( clist[j].hContact == hContact ) {
			return isClientMiranda(&clist[j],emptyMirverAsMiranda);
		}
	}
	return false;
}


BOOL isProtoSmallPackets(HANDLE hContact) {

	if (!clist_cnt) return false;
	for(int j=0;j<clist_cnt;j++) {
		if ( clist[j].hContact == hContact ) {
			if ( !clist[j].proto->inspecting ) break;
				return  strstr(clist[j].proto->name,"IRC")!=NULL ||
					strstr(clist[j].proto->name,"WinPopup")!=NULL ||
					strstr(clist[j].proto->name,"VyChat")!=NULL;
		}
	}
	return false;
}


BOOL isContactInvisible(HANDLE hContact) {

	if ( !db_get_b(hContact,"CList","Hidden",0)) {
		if ( !clist_cnt ) return false;
		for(int j=0;j<clist_cnt;j++) {
			if ( clist[j].hContact == hContact ) {
				if ( !clist[j].proto->inspecting ) return false;
				if ( clist[j].waitForExchange ) return false;
				switch( (int)DBGetContactSettingWord(hContact,clist[j].proto->name,"ApparentMode",0)) {
				case 0:
					return (CallProtoService(clist[j].proto->name,PS_GETSTATUS,0,0)==ID_STATUS_INVISIBLE);
				case ID_STATUS_ONLINE:
					return false;
				case ID_STATUS_OFFLINE:
					return true;
				} //switch
				break;
			}
		}// for
	}
	return true;
}


BOOL isNotOnList(HANDLE hContact) {
	return db_get_b(hContact, "CList", "NotOnList", 0);
}


BOOL isContactNewPG(HANDLE hContact) {

	if (!clist_cnt) return false;
	for(int j=0;j<clist_cnt;j++) {
		if (clist[j].hContact == hContact) {
			if ( !clist[j].proto->inspecting ) break;
			if ( !clist[j].cntx ) break;
			return (clist[j].features & CPP_FEATURES_NEWPG) != 0;
		}
	}
	return false;
}


BOOL isContactPGP(HANDLE hContact) {

	if (!bPGPloaded || (!bPGPkeyrings && !bPGPprivkey)) return false;
	if (!clist_cnt) return false;
	for(int j=0;j<clist_cnt;j++) {
	    if (clist[j].hContact == hContact) {
		if ( !clist[j].proto->inspecting ) break;
	    	if ( clist[j].mode!=MODE_PGP ) break;
        	DBVARIANT dbv;
        	DBGetContactSetting(hContact,szModuleName,"pgp",&dbv);
        	BOOL r=(dbv.type!=0);
        	DBFreeVariant(&dbv);
        	return r;
	    }
	}
	return false;
}


BOOL isContactGPG(HANDLE hContact) {

	if (!bGPGloaded || !bGPGkeyrings) return false;
	if (!clist_cnt) return false;
	for(int j=0;j<clist_cnt;j++) {
	    if (clist[j].hContact == hContact) {
		if ( !clist[j].proto->inspecting ) break;
	    	if ( clist[j].mode!=MODE_GPG ) break;
        	DBVARIANT dbv;
        	DBGetContactSetting(hContact,szModuleName,"gpg",&dbv);
        	BOOL r=(dbv.type!=0);
        	DBFreeVariant(&dbv);
        	return r;
	    }
	}
	return false;
}


BOOL isContactRSAAES(HANDLE hContact) {

	if (!clist_cnt) return false;
        for(int j=0;j<clist_cnt;j++) {
		if (clist[j].hContact == hContact) {
			if ( !clist[j].proto->inspecting ) break;
			if ( clist[j].mode!=MODE_RSAAES ) break;
        		return true;
		}
	}
	return false;
}


BOOL isContactRSA(HANDLE hContact) {

	if (!clist_cnt) return false;
        for(int j=0;j<clist_cnt;j++) {
		if (clist[j].hContact == hContact) {
			if ( !clist[j].proto->inspecting ) break;
			if ( clist[j].mode!=MODE_RSA ) break;
        	return true;
		}
	}
	return false;
}


BOOL isChatRoom(HANDLE hContact) {

	if (!clist_cnt) return false;
	for(int j=0;j<clist_cnt;j++) {
		if ( clist[j].hContact == hContact ) {
			if ( !clist[j].proto->inspecting ) break;
			return (db_get_b(hContact,clist[j].proto->name,"ChatRoom",0)!=0);
		}
	}
	return false;
}


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;

	BOOL isSecureIM = false;
	if ( bNOL && db_get_b(ptr->hContact,"CList","NotOnList",0)) {
		return false;
	}
	LPSTR mirver = myDBGetString(ptr->hContact,ptr->proto->name,"MirVer");
	if ( mirver ) {
		isSecureIM = (emptyMirverAsSecureIM && !*mirver) || (strstr(mirver,"SecureIM")!=NULL) || (strstr(mirver,"secureim")!=NULL);
		mir_free(mirver);
	}
	return isSecureIM;
}


BOOL isSecureIM(HANDLE hContact, BOOL emptyMirverAsSecureIM) {

	if ( !bAIP ) return false;
	if ( !clist_cnt ) return false;

	for(int j=0;j<clist_cnt;j++) {
		if (clist[j].hContact == hContact) {
			return isSecureIM(&clist[j],emptyMirverAsSecureIM);
		}
	}
	return false;
}


// EOF