summaryrefslogtreecommitdiff
path: root/plugins/SecureIM/src/crypt.h
blob: 9da46e8be92fd1e6150f9a957695dd3351456033 (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
#ifndef __CRYPT_H__
#define __CRYPT_H__

#define KEYSIZE 256
#define NAMSIZE 512
#define DEFMSGS 4096

#define KEY_A_SIG	0x000000
#define KEY_B_SIG	0x010000

// struct to store all supported protocols
struct SupPro {
	LPSTR name;
	BOOL inspecting;
	int split_on, tsplit_on;
	int split_off, tsplit_off;
};
typedef SupPro *pSupPro;

// struct to store wainting messages
struct waitingMessage {
	LPSTR Message;
	WPARAM wParam;
	waitingMessage *nextMessage;
};
typedef waitingMessage* pWM;

struct partitionMessage {
	int id;
	LPSTR *message; // array of message parts
	partitionMessage *nextMessage;
};
typedef partitionMessage* pPM;

#define HEADER 0xABCD1234
#define FOOTER 0x9876FEDC
#define EMPTYH 0xF1E2D3C4

// memory struct for keys
struct UinKey
{
	HCONTACT hContact;	// handle of contact
	u_int header;		// HEADER
	pSupPro proto;		// proto struct
	BYTE mode,tmode;	// mode: Native,PGP,GPG,RSA/AES,RSA [0..4]
	BYTE status,tstatus;	// status: Disabled,Enabled,AlwaysTry [0..2] for Native mode
	LPSTR msgSplitted;	// message to combine
	pPM msgPart;		// parts of message
	pWM msgQueue;		// last messages not sended or to resend;
	BOOL sendQueue;		// èäåò îòñûëêà î÷åðåäè - íå îáðàáàòûâàþòñÿ ñîîáùåíèÿ
	BOOL offlineKey;
	char waitForExchange;	// 0 - ñáðîñèòü î÷åðåäü
				// 1 - îæèäàåì
				// 2 - äîñëàòü ñ øèôðîâàíèåì
				// 3 - äîñëàòü áåç øèôðîâàíèÿ ñ âîïðîñîì
	BOOL decoded;		// false on decode error
	short features;
	HANDLE cntx;		// crypto context
	BYTE keyLoaded;		// ( 1-PGP, 2-GPG ) | 1-RSA
	BYTE gpgMode,tgpgMode;	// 0-UTF8, 1-ANSI
	char *lastFileRecv;
	char *lastFileSend;
	char **fileSend;
	BOOL finFileRecv;
	BOOL finFileSend;
	LPSTR tmp;		// tmp text string
	u_int footer;		// FOOTER
};
typedef UinKey* pUinKey;

struct TFakeAckParams
{
	__forceinline TFakeAckParams(HCONTACT p1, LONG p2, LPCSTR p3) :
		hContact(p1),
		id(p2),
		msg(p3)
		{}

	HCONTACT hContact;
	LONG   id;
	LPCSTR msg;
};

extern char szUIN[NAMSIZE];
extern char szName[NAMSIZE];

extern LIST<SupPro> arProto;
extern LIST<UinKey> arClist;

// crypt_lists.cpp
void loadContactList();
void freeContactList();
pUinKey addContact(HCONTACT hContact);
void    delContact(HCONTACT hContact);
pSupPro getSupPro(HCONTACT);
pUinKey findUinKey(HCONTACT hContact);
pUinKey getUinKey(HCONTACT hContact);
pUinKey getUinCtx(HANDLE);
void addMsg2Queue(pUinKey,WPARAM,LPSTR);

void getContactName(HCONTACT hContact, LPSTR szName);
void getContactNameA(HCONTACT hContact, LPSTR szName);
void getContactUin(HCONTACT hContact, LPSTR szUIN);
void getContactUinA(HCONTACT hContact, LPSTR szUIN);

// crypt_check.cpp
int getContactStatus(HCONTACT);

bool isSecureProtocol(HCONTACT hContact);
BYTE isContactSecured(HCONTACT hContact);
bool isClientMiranda(pUinKey ptr, BOOL emptyMirverAsMiranda=FALSE);
bool isClientMiranda(HCONTACT hContact, BOOL emptyMirverAsMiranda=FALSE);
bool isProtoSmallPackets(HCONTACT);
bool isContactInvisible(HCONTACT);
bool isNotOnList(HCONTACT);
bool isContactNewPG(HCONTACT);
bool isContactPGP(HCONTACT);
bool isContactGPG(HCONTACT);
bool isContactRSAAES(HCONTACT);
bool isContactRSA(HCONTACT);
bool isChatRoom(HCONTACT);
bool isFileExist(LPCSTR);
bool isSecureIM(pUinKey ptr, BOOL emptyMirverAsSecureIM=FALSE);
bool isSecureIM(HCONTACT hContact, BOOL emptyMirverAsSecureIM=FALSE);

// crypt_icons.cpp
HICON mode2icon(int,int);
HANDLE mode2clicon(int mode, int type);
void RefreshContactListIcons(void);
void ShowStatusIcon(HCONTACT, UINT);
void ShowStatusIcon(HCONTACT);
void ShowStatusIconNotify(HCONTACT);

// crypt_popups.cpp
//static int CALLBACK PopupDlgProc(HWND,UINT,WPARAM,LPARAM);
void showPopup(LPCSTR, HCONTACT, HICON, UINT);
void showPopupEC(HCONTACT);
void showPopupDCmsg(HCONTACT, LPCSTR);
void showPopupDC(HCONTACT);
void showPopupKS(HCONTACT);
void showPopupKRmsg(HCONTACT, LPCSTR);
void showPopupKR(HCONTACT);
void showPopupSM(HCONTACT);
void showPopupRM(HCONTACT);

// crypt_meta.cpp
BOOL isProtoMetaContacts(HCONTACT);
BOOL isDefaultSubContact(HCONTACT);
HCONTACT getMetaContact(HCONTACT);
HCONTACT getMostOnline(HCONTACT);
void DeinitMetaContact(HCONTACT);

// crypt_dll.cpp
LPSTR InitKeyA(pUinKey, int);
int InitKeyB(pUinKey, LPCSTR);
void InitKeyX(pUinKey, BYTE*);
BOOL CalculateKeyX(pUinKey, HCONTACT);
LPSTR encodeMsg(pUinKey, LPARAM);
LPSTR decodeMsg(pUinKey, LPARAM, LPSTR);
BOOL LoadKeyPGP(pUinKey);
BOOL LoadKeyGPG(pUinKey);

// crypt_misc.cpp
void waitForExchange(pUinKey ptr, int flag = 1);

#endif