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