1 // testi2.cpp : Defines the entry point for the application.
\r
4 #define FD_SETSIZE 5000
\r
6 #include "resource.h"
\r
7 #include <winsock2.h>
\r
11 #define FD_SETSIZE 5000
\r
12 #include "silcincludes.h"
\r
13 #include "clientlibincludes.h"
\r
16 #define MAX_LOADSTRING 100
\r
18 // Global Variables:
\r
19 HINSTANCE hInst; // current instance
\r
20 TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
\r
21 TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
\r
23 // Foward declarations of functions included in this code module:
\r
24 ATOM MyRegisterClass(HINSTANCE hInstance);
\r
25 BOOL InitInstance(HINSTANCE, int);
\r
26 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
\r
27 LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
\r
29 void silc_op_say(SilcClient client, SilcClientConnection conn,
\r
30 SilcClientMessageType type, char *msg, ...)
\r
35 memset(message, 0, sizeof(message));
\r
36 strncat(message, "\n*** ", 5);
\r
39 vsprintf(message + 5, msg, vp);
\r
42 MessageBox( NULL, (char *)message, "say", MB_OK | MB_ICONINFORMATION );
\r
45 void silc_notify(SilcClient client, SilcClientConnection conn,
\r
46 SilcNotifyType type, ...)
\r
51 void silc_connect(SilcClient client, SilcClientConnection conn, int success)
\r
56 int silc_auth_meth(SilcClient client, SilcClientConnection conn,
\r
57 char *hostname, uint16 port,
\r
58 SilcProtocolAuthMeth *auth_meth,
\r
59 unsigned char **auth_data,
\r
60 uint32 *auth_data_len)
\r
62 *auth_meth = SILC_AUTH_NONE;
\r
65 void silc_verify_public_key(SilcClient client, SilcClientConnection conn,
\r
66 SilcSocketType conn_type, unsigned char *pk,
\r
67 uint32 pk_len, SilcSKEPKType pk_type,
\r
68 SilcVerifyPublicKey completion, void *context)
\r
70 completion(TRUE, context);
\r
73 void silc_command_reply(SilcClient client, SilcClientConnection conn,
\r
74 SilcCommandPayload cmd_payload, int success,
\r
75 SilcCommand command, SilcCommandStatus status, ...)
\r
80 /* SILC client operations */
\r
81 SilcClientOperations ops = {
\r
91 silc_verify_public_key,
\r
94 SILC_TASK_CALLBACK(connect_client)
\r
96 SilcClient client = (SilcClient)context;
\r
97 silc_client_connect_to_server(client, 1334, "leevi.kuo.fi.ssh.com", NULL);
\r
100 void silc_log(char *message)
\r
104 void silc_debugl(char *file, char *function,
\r
105 int line, char *message)
\r
108 memcpy(m, message, strlen(message));
\r
109 m[strlen(message)] = '\n';
\r
110 m[strlen(message) + 1] = 0;
\r
111 OutputDebugString(m);
\r
114 void silc_hexdumpl(char *file, char *function,
\r
115 int line, unsigned char *data_in,
\r
116 uint32 data_len, char *message)
\r
119 int off, pos, count;
\r
120 unsigned char *data = (unsigned char *)data_in;
\r
121 char m[10000], *cp;
\r
122 int len = data_len;
\r
124 // memset(m, 0, sizeof(m));
\r
127 snprintf(cp, 10000, "%s:%d: %s\n", function, line, message);
\r
137 if ((len - pos) < 16 && (len - pos <= len - off))
\r
147 snprintf(cp, sizeof(m), "%08X ", k++ * 16);
\r
151 for (i = 0; i < count; i++) {
\r
152 snprintf(cp, sizeof(m), "%02X ", data[pos + i]);
\r
155 if ((i + 1) % 4 == 0) {
\r
156 snprintf(cp, sizeof(m), " ");
\r
161 if (count && count < 16) {
\r
164 for (j = 0; j < 16 - count; j++) {
\r
165 snprintf(cp, sizeof(m), " ");
\r
168 if ((j + count + 1) % 4 == 0) {
\r
169 snprintf(cp, sizeof(m), " ");
\r
175 for (i = 0; i < count; i++) {
\r
178 if (data[pos] < 32 || data[pos] >= 127)
\r
183 snprintf(cp, sizeof(m), "%c", ch);
\r
189 snprintf(cp, sizeof(m), "\n");
\r
197 OutputDebugString(m);
\r
198 MessageBox( NULL, (char *)m, "hexdump", MB_OK | MB_ICONINFORMATION );
\r
202 silc_create_key_pair(char *pkcs_name, int bits, char *path,
\r
204 SilcPublicKey *ret_pub_key,
\r
205 SilcPrivateKey *ret_prv_key)
\r
208 SilcPublicKey pub_key;
\r
209 SilcPrivateKey prv_key;
\r
211 unsigned char *key;
\r
213 char pkfile[256], prvfile[256];
\r
215 if (!pkcs_name || !path)
\r
221 rng = silc_rng_alloc();
\r
222 silc_rng_init(rng);
\r
223 silc_rng_global_init(rng);
\r
225 /* Generate keys */
\r
226 silc_pkcs_alloc((const unsigned char *)pkcs_name, &pkcs);
\r
227 pkcs->pkcs->init(pkcs->context, bits, rng);
\r
229 /* Save public key into file */
\r
230 key = silc_pkcs_get_public_key(pkcs, &key_len);
\r
231 pub_key = silc_pkcs_public_key_alloc(pkcs->pkcs->name, identifier,
\r
233 *ret_pub_key = pub_key;
\r
235 memset(key, 0, sizeof(key_len));
\r
238 /* Save private key into file */
\r
239 key = silc_pkcs_get_private_key(pkcs, &key_len);
\r
240 prv_key = silc_pkcs_private_key_alloc(pkcs->pkcs->name, key, key_len);
\r
241 *ret_prv_key = prv_key;
\r
243 memset(key, 0, sizeof(key_len));
\r
246 silc_rng_free(rng);
\r
247 silc_pkcs_free(pkcs);
\r
253 int APIENTRY WinMain(HINSTANCE hInstance,
\r
254 HINSTANCE hPrevInstance,
\r
258 // TODO: Place code here.
\r
260 HACCEL hAccelTable;
\r
262 HANDLE handles[100];
\r
265 WSAEVENT e, e2, e3;
\r
270 // Initialize global strings
\r
271 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
\r
272 LoadString(hInstance, IDC_TESTI2, szWindowClass, MAX_LOADSTRING);
\r
273 MyRegisterClass(hInstance);
\r
275 // Perform application initialization:
\r
276 if (!InitInstance (hInstance, nCmdShow))
\r
281 hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TESTI2);
\r
284 SilcSchedule sched;
\r
287 silc_net_win32_init();
\r
288 client = silc_client_alloc(&ops, NULL, NULL, "SILC-1.0-0.5.1");
\r
289 client->realname = "pekka riikonen";
\r
290 client->username = "priikone";
\r
291 client->hostname = "leevi.kuo.fi.ssh.com";
\r
293 silc_cipher_register_default();
\r
294 silc_pkcs_register_default();
\r
295 silc_hash_register_default();
\r
296 silc_hmac_register_default();
\r
299 silc_log_set_debug_callbacks(silc_debugl, silc_hexdumpl);
\r
301 silc_create_key_pair("rsa", 1024, "kk", "UN=priikone, HN=pelle.kuo.fi.ssh.com",
\r
302 &client->public_key, &client->private_key);
\r
304 silc_client_init(client);
\r
306 silc_schedule_task_add(client->schedule, 0, connect_client,
\r
307 client, 0, 1, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
\r
309 silc_client_run(client);
\r
316 // FUNCTION: MyRegisterClass()
\r
318 // PURPOSE: Registers the window class.
\r
322 // This function and its usage is only necessary if you want this code
\r
323 // to be compatible with Win32 systems prior to the 'RegisterClassEx'
\r
324 // function that was added to Windows 95. It is important to call this function
\r
325 // so that the application will get 'well formed' small icons associated
\r
328 ATOM MyRegisterClass(HINSTANCE hInstance)
\r
332 wcex.cbSize = sizeof(WNDCLASSEX);
\r
334 wcex.style = CS_HREDRAW | CS_VREDRAW;
\r
335 wcex.lpfnWndProc = (WNDPROC)WndProc;
\r
336 wcex.cbClsExtra = 0;
\r
337 wcex.cbWndExtra = 0;
\r
338 wcex.hInstance = hInstance;
\r
339 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_TESTI2);
\r
340 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
\r
341 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
\r
342 wcex.lpszMenuName = (LPCSTR)IDC_TESTI2;
\r
343 wcex.lpszClassName = szWindowClass;
\r
344 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
\r
346 return RegisterClassEx(&wcex);
\r
350 // FUNCTION: InitInstance(HANDLE, int)
\r
352 // PURPOSE: Saves instance handle and creates main window
\r
356 // In this function, we save the instance handle in a global variable and
\r
357 // create and display the main program window.
\r
359 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
\r
363 hInst = hInstance; // Store instance handle in our global variable
\r
365 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
\r
366 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
\r
372 FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
373 FORMAT_MESSAGE_FROM_SYSTEM |
\r
374 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
377 0, // Default language
\r
378 (LPTSTR) &lpMsgBuf,
\r
382 // Process any inserts in lpMsgBuf.
\r
384 // Display the string.
\r
385 MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
\r
386 // Free the buffer.
\r
387 LocalFree( lpMsgBuf );
\r
392 ShowWindow(hWnd, nCmdShow);
\r
393 UpdateWindow(hWnd);
\r
399 // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
\r
401 // PURPOSE: Processes messages for the main window.
\r
403 // WM_COMMAND - process the application menu
\r
404 // WM_PAINT - Paint the main window
\r
405 // WM_DESTROY - post a quit message and return
\r
408 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
\r
413 TCHAR szHello[MAX_LOADSTRING];
\r
414 LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
\r
419 wmId = LOWORD(wParam);
\r
420 wmEvent = HIWORD(wParam);
\r
421 // Parse the menu selections:
\r
425 DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
\r
428 DestroyWindow(hWnd);
\r
431 return DefWindowProc(hWnd, message, wParam, lParam);
\r
435 hdc = BeginPaint(hWnd, &ps);
\r
436 // TODO: Add any drawing code here...
\r
438 GetClientRect(hWnd, &rt);
\r
439 DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
\r
440 EndPaint(hWnd, &ps);
\r
443 PostQuitMessage(0);
\r
446 return DefWindowProc(hWnd, message, wParam, lParam);
\r
451 // Mesage handler for about box.
\r
452 LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
\r
456 case WM_INITDIALOG:
\r
460 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
\r
462 EndDialog(hDlg, LOWORD(wParam));
\r