⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialogs.c

📁 IP网络语音通讯软件源代码. 不可多得的语音源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/*

				Dialogue procedures

*/

#include "netfone.h"

typedef struct _NEW_HOST_PARAMS {
    LPSTR pszHostName;
    LPIN_ADDR paddr;
    unsigned short *port_no;
    HANDLE hAsync;
    ULONG laddr;
    BYTE bBuffer[MAXGETHOSTSTRUCT];
} NEW_HOST_PARAMS, FAR *LPNEW_HOST_PARAMS;

NEW_HOST_PARAMS NewHostParams;          // Parameters for NewHost dialog

//	SESSIONKEYGENERATE  --  Generate a random session key

void sessionKeyGenerate(LPSTR key, BOOL binary)
{
	int j, k;
	char s[256];
    struct MD5Context md5c;
    char md5key[16], md5key1[16];
    POINT p;
	MEMORYSTATUS ms;
	
	/*	The following gets all kind of information likely
		to vary from moment to moment and uses it as the initial
		seed for the random number generator.  If any of these
		causes porting problems in the future, just delete them.  */
	
    wsprintf(s, Format(28), GetTickCount());
    wsprintf(s + strlen(s), Format(28), time(NULL));
    gethostname(s + strlen(s), 256);
    wsprintf(s + strlen(s), Format(29), GetActiveWindow());
    wsprintf(s + strlen(s), Format(28), GetFreeSpace(0));
	ms.dwLength = sizeof(MEMORYSTATUS);
	GlobalMemoryStatus(&ms);
	wsprintf(s + strlen(s), Format(28), ms.dwMemoryLoad); 
	wsprintf(s + strlen(s), Format(28), ms.dwAvailPhys); 
	wsprintf(s + strlen(s), Format(28), ms.dwAvailPageFile); 
    GetCursorPos(&p);
    wsprintf(s + strlen(s), Format(30), p.x, p.y); 
    MD5Init(&md5c);
    MD5Update(&md5c, s, strlen(s));
    MD5Final(md5key, &md5c);
    wsprintf(s + strlen(s), Format(28), (time(NULL) + 65121) ^ 0x375F);
    MD5Init(&md5c);
    MD5Update(&md5c, s, strlen(s));
    MD5Final(md5key1, &md5c);
#ifdef CRYPTO    
    init_idearand(md5key, md5key1, time(NULL));
#endif    
    for (j = k = 0; j < 16; j++) {
#ifdef CRYPTO    
        unsigned char rb = idearand();
#else
		unsigned char rb = (unsigned char) (md5key[j] ^ md5key1[j]);        
#endif        
        
        if (binary) {
        	key[j] = (char) rb;
        } else {
#define Rad16(x) ((x) + 'A')
	        key[k++] = Rad16((rb >> 4) & 0xF);
	        key[k++] = Rad16(rb & 0xF);
	        if (j & 1) {
	            key[k++] = '-';
	        }
        }
    }
    if (!binary) {
    	key[--k] = 0;
    }
#ifdef CRYPTO    
    close_idearand();
#endif    
}

/*  MAKEINTERNALENCRYPTIONKEYS  --  Create actual encryption keys from user
									specified keys.  */

int makeInternalEncryptionKeys(HWND hwnd, LPCLIENT_DATA d)
{
#ifdef IP_MAX_MEMBERSHIPS
	if (IN_MULTICAST(d->inetSock.sin_addr.s_addr)) {
	
		/* Windows 95 WINSOCK bombs with an "out of range address"
		   when a char is passed as the multicast TTL optval, as
		   one does on Unix and which works fine with Trumpet
		   Winsock.  Work-around by allowing the user to send either
		   a char or an int.  Trumpet happens to work OK if you pass
		   an int, but there's probably some other WINSOCK that won't
		   accept a length of 2 for this argument. */
	
		if (waNetMultiTTLisChar) {
			unsigned char scope = d->multicast_scope;
		
			if (setsockopt(d->sReply, IPPROTO_IP, IP_MULTICAST_TTL,
							(char *) &scope, sizeof scope) == -1 ||
				setsockopt(d->sControl, IPPROTO_IP, IP_MULTICAST_TTL,
							(char *) &scope, sizeof scope) == -1) {
	            int serr = WSAGetLastError();
	            
		        MsgBox(hwnd, MB_ICONSTOP | MB_OK, Format(38),
		                d->szHost, serr, SockerrToString(serr));
			}
		} else {
			int scope = d->multicast_scope;
		
			if (setsockopt(d->sReply, IPPROTO_IP, IP_MULTICAST_TTL,
							(char *) &scope, sizeof scope) == -1 ||
				setsockopt(d->sControl, IPPROTO_IP, IP_MULTICAST_TTL,
							(char *) &scope, sizeof scope) == -1) {
	            int serr = WSAGetLastError();
	            
		        MsgBox(hwnd, MB_ICONSTOP | MB_OK, Format(38),
		                d->szHost, serr, SockerrToString(serr));
			}
		}
	}
#endif	

#ifdef CRYPTO
	if ((d->deskey[0] = d->rtpdeskey[0] =
		 d->vatdeskey[0] = (_fstrlen(d->desKeyString) > 0)) == TRUE) {
		int j;
	    struct MD5Context md5c;
	    char md5key[16], algorithm[16];
						
	    MD5Init(&md5c);
	    MD5Update(&md5c, d->desKeyString, _fstrlen(d->desKeyString));
	    MD5Final(md5key, &md5c);
	    for (j = 0; j < 8; j++) {
	        d->deskey[j + 1] = (char)
	                      ((md5key[j] ^ md5key[j + 8]) & 0x7F);
	    }
	    des_string_to_key(d->desKeyString, (des_cblock FAR *) (d->vatdeskey + 1));
		string_DES_key(d->desKeyString, (LPBYTE) d->rtpdeskey + 1, algorithm);
        if (_fstrcmp(algorithm, rstring(IDS_T_DES_CBC)) != 0) {
	        MsgBox(hwnd, MB_ICONSTOP | MB_OK, Format(68), (LPSTR) algorithm,
	        	   (LPSTR) rstring(IDS_T_DES_CBC));
		}
	}
	
	if ((d->ideakey[0] = (_fstrlen(d->ideaKeyString) > 0)) == TRUE) {
	    struct MD5Context md5c;
						
	    MD5Init(&md5c);
	    MD5Update(&md5c, d->ideaKeyString, _fstrlen(d->ideaKeyString));
		MD5Final(d->ideakey + 1, &md5c);
	}
	
	if ((d->blowfish_spec = (_fstrlen(d->blowfishKeyString) > 0)) == TRUE) {
	    struct MD5Context md5c;
		unsigned char bfvec[16];
						
	    MD5Init(&md5c);
	    MD5Update(&md5c, d->blowfishKeyString, _fstrlen(d->blowfishKeyString));
		MD5Final(bfvec, &md5c);
		BF_set_key(&(d->blowfishkey), 16, bfvec);
	}
	
	if (d->opgpUserList[0]) {
		char cmd[256];
		HFILE kfile;
		char tp[MAX_PATH];

		GetTempPath(sizeof tp, tp); 
	    sessionKeyGenerate(d->opgpkey + 1, TRUE);
	    d->opgpkey[0] = FALSE;
		GetTempFileName(tp, "PK", 0, d->opgpFileName);
	
        kfile = _lcreat(d->opgpFileName, 0);
		if (kfile == HFILE_ERROR) {
            MessageBox(hwnd, rstring(IDS_T_PGP_OPEN_SESSION_ERR),
            	rstring(IDS_T_PGP_ENCODING_TITLE), MB_ICONEXCLAMATION | MB_OK);
		} else {
			UINT execStat = 0;
		
			_lwrite(kfile, "K", 1);
			_lwrite(kfile, d->opgpkey + 1, 16);
			_lclose(kfile);
			
			/*	First try to run PGP via the PIF in our own directory.  This
				guarantees it's run with the modes we've chosen, such as
				in a window rather than full-screen.  */
			
			if (GetModuleFileName(hInst, cmd, sizeof cmd) > 0) {
				char *cp = cmd + strlen(cmd);
				
				while (cp >= cmd && *cp != '\\' && *cp != ':') {
					cp--;
				}
				cp[1] = 0;
				wsprintf(cmd + strlen(cmd), Format(53),
						 d->opgpFileName, d->opgpUserList + 1);
				execStat = WinExec(cmd, SW_SHOW); 
			}

			/*	If that didn't work, attempt to run PGP by straight path
				search using the default modes.  */
				
			if (execStat < 32) {                       
            	wsprintf(cmd, Format(31), d->opgpFileName, d->opgpUserList + 1);
            	execStat = WinExec(cmd, SW_SHOW);
            }
	            
            //	Set timer to poll for completion of encoding
	            
            if (execStat >= 32) {
	            d->opgpFileName[_fstrlen(d->opgpFileName) - 3] = 0;
	            _fstrcat(d->opgpFileName, "PGP");
	            SetTimer(hwnd, 4, 1000, NULL);
	        } else {
	        	wsprintf(cmd + strlen(cmd), Format(51), execStat);
	        	MessageBox(hwnd, cmd, rstring(IDS_T_CANT_INVOKE_PGP_ENCODE),
			   		MB_OK | MB_ICONEXCLAMATION);
	        }
		}
	}
	
	if (d->otpFileName[0]) {
		HFILE fp = _lopen(d->otpFileName, OF_READ);
		if (fp == HFILE_ERROR) {
			MessageBox(hwnd, rstring(IDS_T_PGP_KEY_OPEN_ERR),
				NULL, MB_ICONEXCLAMATION | MB_OK);
			return FALSE;
		} else {
            UINT j, k, l = _lread(fp, d->otp, BUFL);
            if (l == 0) {
                /* Idiot supplied void key file.  Give 'im
                   what he asked for: no encryption. */
                d->otp[0] = 0;
                l = 1;
            }
            /* If the file is shorter than the maximum buffer
               we may need to encrypt, replicate the key until
               the buffer is filled. */
            j = l;
            k = 0;
            while (j < BUFL) {
                d->otp[j++] = d->otp[k++];
                if (k >= l) {
                    k = 0;
                }
            }
			_lclose(fp);
		}
	}
#endif

	/* When the keys change, we want to immediately send an
	   RTP/VAT SDES/ID message in the new encryption so the
	   other end can sense the protocol and encryption. */
	   
	d->sendSDEStimer = 0;	
	return TRUE; 
}

//	CP_PROC  --  Connection properties dialogue procedure

static LPCLIENT_DATA clientData;

BOOL CALLBACK CP_proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	LPCLIENT_DATA d = clientData;

    switch (message) {
        case WM_INITDIALOG:
        	{
        		char tbuf[132];
        		
        		//	Display host name in dialogue title

#ifdef MODEM        		
        		if (d->inetSock.sin_addr.s_addr == 0) {
        			strcpy(tbuf, rstring(IDS_T_MODEM_SP));
        			GetWindowText(hDlg, tbuf + strlen(tbuf), (sizeof tbuf) - strlen(tbuf));
        		} else
#endif        		 
        		{
	        		GetWindowText(hDlg, tbuf, sizeof tbuf);
	        		_fstrcat(tbuf, " - ");
	        		_fstrcat(tbuf, d->szHost);
	        	}
        		SetWindowText(hDlg, tbuf);
				CheckDlgButton(hDlg, IDC_DEBUG, d->debugging);
				CheckDlgButton(hDlg, IDC_LOOPBACK, d->loopback);
				SetDlgItemText(hDlg, IDC_CP_DESKEY, d->desKeyString);
				SetDlgItemText(hDlg, IDC_CP_IDEAKEY, d->ideaKeyString);
				SetDlgItemText(hDlg, IDC_CP_BLOWFISHKEY, d->blowfishKeyString);
				SetDlgItemText(hDlg, IDC_CP_OTPFILE, d->otpFileName);
				SetDlgItemText(hDlg, IDC_CP_PGPUSERS, d->opgpUserList);
				CheckDlgButton(hDlg, IDC_SAVE_KEYS, d->saveKeys);
#define Crypple(x)	ShowWindow(GetDlgItem(hDlg, x), SW_HIDE)
#ifdef CRYPTO
				Crypple(IDC_CP_NOCRYPTO1);
				Crypple(IDC_CP_NOCRYPTO2);
				Crypple(IDC_CP_NOCRYPTO3);
#define SFonly(x) EnableWindow(GetDlgItem(hDlg, x), protocolSent == PROTOCOL_SPEAKFREE)
				SFonly(IDC_CP_IDEA);
				SFonly(IDC_CP_IDEAKEY);
				SFonly(IDC_CP_BLOWFISH);
				SFonly(IDC_CP_BLOWFISHKEY);
				SFonly(IDC_CP_KEYFILE);
				SFonly(IDC_CP_OTPFILE);
				SFonly(IDC_CP_PGP);
				SFonly(IDC_CP_PGPUSERS);
				SFonly(IDC_CP_PATENT);
				SFonly(IDC_OTP_BROWSE);
#undef SFonly				
#else
				Crypple(IDC_CP_DES);
				Crypple(IDC_CP_DESKEY);
				Crypple(IDC_CP_IDEA);
				Crypple(IDC_CP_IDEAKEY);
				Crypple(IDC_CP_BLOWFISH);
				Crypple(IDC_CP_BLOWFISHKEY);
				Crypple(IDC_CP_KEYFILE);
				Crypple(IDC_CP_OTPFILE);
				Crypple(IDC_CP_PGP);
				Crypple(IDC_CP_PGPUSERS);
				Crypple(IDC_CP_PATENT);
				Crypple(IDC_SAVE_KEYS);
				Crypple(IDC_OTP_BROWSE);
#endif
#undef Crypple
#ifdef IP_MAX_MEMBERSHIPS
				EnableWindow(GetDlgItem(hDlg, IDC_CP_MULTI_SCOPE),
					IN_MULTICAST(d->inetSock.sin_addr.s_addr));
				EnableWindow(GetDlgItem(hDlg, IDC_CP_MULTI_LABEL),
					IN_MULTICAST(d->inetSock.sin_addr.s_addr));
				if (IN_MULTICAST(d->inetSock.sin_addr.s_addr)) {
					SetDlgItemInt(hDlg, IDC_CP_MULTI_SCOPE, d->multicast_scope, FALSE);
				}
#else
				EnableWindow(GetDlgItem(hDlg, IDC_CP_MULTI_SCOPE), FALSE);
				EnableWindow(GetDlgItem(hDlg, IDC_CP_MULTI_LABEL), FALSE);
#endif					
			}
            break;

        case WM_COMMAND:
            switch ((short) WM_COMMAND_ID(wParam)) {
                case IDOK:
#ifdef IP_MAX_MEMBERSHIPS                
                	if (GetDlgItemInt(hDlg, IDC_CP_MULTI_SCOPE, NULL, FALSE) > 255) {
                		MessageBox(hDlg, rstring(IDS_T_MULTICAST_SCOPE_ERR),
                			NULL, MB_ICONEXCLAMATION | MB_OK);
                		return TRUE;
                	}
#endif                	
                	d->debugging = IsDlgButtonChecked(hDlg, IDC_DEBUG);
                	d->loopback = IsDlgButtonChecked(hDlg, IDC_LOOPBACK);
					GetDlgItemText(hDlg, IDC_CP_DESKEY, d->desKeyString, sizeof d->desKeyString);
					GetDlgItemText(hDlg, IDC_CP_IDEAKEY, d->ideaKeyString, sizeof d->ideaKeyString);
					GetDlgItemText(hDlg, IDC_CP_BLOWFISHKEY, d->blowfishKeyString, sizeof d->blowfishKeyString);
					GetDlgItemText(hDlg, IDC_CP_OTPFILE, d->otpFileName, sizeof d->otpFileName);
					GetDlgItemText(hDlg, IDC_CP_PGPUSERS, d->opgpUserList, sizeof d->opgpUserList);
					d->multicast_scope = GetDlgItemInt(hDlg, IDC_CP_MULTI_SCOPE, NULL, FALSE);
                	d->saveKeys = IsDlgButtonChecked(hDlg, IDC_SAVE_KEYS);
                	if (!makeInternalEncryptionKeys(GetParent(hDlg), d)) {
                		break;
                	}
	                EndDialog(hDlg, TRUE);
                    break;

                case IDCANCEL:
                    EndDialog(hDlg, FALSE);
                    break;

#ifdef CRYPTO                    
                case IDC_OTP_BROWSE:
			     	{
			     		OPENFILENAME ofn;
			     		char szString[MAX_PATH];
			

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -