--- /dev/null
+// testi2.cpp : Defines the entry point for the application.\r
+//\r
+\r
+#define FD_SETSIZE 5000\r
+#include "stdafx.h"\r
+#include "resource.h"\r
+#include <winsock2.h>\r
+#include <mswsock.h>\r
+extern "C"\r
+{\r
+#define FD_SETSIZE 5000\r
+#include "silcincludes.h"\r
+#include "clientlibincludes.h"\r
+}\r
+\r
+#define MAX_LOADSTRING 100\r
+\r
+// Global Variables:\r
+HINSTANCE hInst; // current instance\r
+TCHAR szTitle[MAX_LOADSTRING]; // The title bar text\r
+TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text\r
+\r
+// Foward declarations of functions included in this code module:\r
+ATOM MyRegisterClass(HINSTANCE hInstance);\r
+BOOL InitInstance(HINSTANCE, int);\r
+LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);\r
+LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);\r
+\r
+void silc_op_say(SilcClient client, SilcClientConnection conn, \r
+ SilcClientMessageType type, char *msg, ...)\r
+{\r
+ va_list vp;\r
+ char message[2048];\r
+\r
+ memset(message, 0, sizeof(message));\r
+ strncat(message, "\n*** ", 5);\r
+\r
+ va_start(vp, msg);\r
+ vsprintf(message + 5, msg, vp);\r
+ va_end(vp);\r
+\r
+ MessageBox( NULL, (char *)message, "say", MB_OK | MB_ICONINFORMATION );\r
+}\r
+\r
+void silc_notify(SilcClient client, SilcClientConnection conn, \r
+ SilcNotifyType type, ...)\r
+{\r
+\r
+}\r
+\r
+void silc_connect(SilcClient client, SilcClientConnection conn, int success)\r
+{\r
+\r
+}\r
+\r
+int silc_auth_meth(SilcClient client, SilcClientConnection conn,\r
+ char *hostname, uint16 port,\r
+ SilcProtocolAuthMeth *auth_meth,\r
+ unsigned char **auth_data,\r
+ uint32 *auth_data_len)\r
+{\r
+ *auth_meth = SILC_AUTH_NONE;\r
+ return TRUE;\r
+}\r
+void silc_verify_public_key(SilcClient client, SilcClientConnection conn,\r
+ SilcSocketType conn_type, unsigned char *pk, \r
+ uint32 pk_len, SilcSKEPKType pk_type,\r
+ SilcVerifyPublicKey completion, void *context)\r
+{\r
+ completion(TRUE, context);\r
+}\r
+\r
+void silc_command_reply(SilcClient client, SilcClientConnection conn,\r
+ SilcCommandPayload cmd_payload, int success,\r
+ SilcCommand command, SilcCommandStatus status, ...)\r
+{\r
+\r
+}\r
+\r
+/* SILC client operations */\r
+SilcClientOperations ops = {\r
+ silc_op_say,\r
+ NULL,\r
+ NULL,\r
+ silc_notify,\r
+ NULL,\r
+ silc_command_reply,\r
+ silc_connect,\r
+ NULL,\r
+ silc_auth_meth,\r
+ silc_verify_public_key,\r
+};\r
+\r
+SILC_TASK_CALLBACK(connect_client)\r
+{\r
+ SilcClient client = (SilcClient)context;\r
+ silc_client_connect_to_server(client, 1334, "leevi.kuo.fi.ssh.com", NULL);\r
+}\r
+\r
+void silc_log(char *message)\r
+{\r
+}\r
+\r
+void silc_debugl(char *file, char *function, \r
+ int line, char *message)\r
+{\r
+ char m[5000];\r
+ memcpy(m, message, strlen(message));\r
+ m[strlen(message)] = '\n';\r
+ m[strlen(message) + 1] = 0;\r
+ OutputDebugString(m);\r
+}\r
+\r
+void silc_hexdumpl(char *file, char *function, \r
+ int line, unsigned char *data_in,\r
+ uint32 data_len, char *message)\r
+{\r
+ int i, k;\r
+ int off, pos, count;\r
+ unsigned char *data = (unsigned char *)data_in;\r
+ char m[10000], *cp;\r
+ int len = data_len;\r
+ \r
+// memset(m, 0, sizeof(m));\r
+\r
+ cp = m;\r
+ snprintf(cp, 10000, "%s:%d: %s\n", function, line, message);\r
+ cp += strlen(cp);\r
+\r
+ k = 0;\r
+ off = len % 16;\r
+ pos = 0;\r
+ count = 16;\r
+ while (1) {\r
+\r
+ if (off) {\r
+ if ((len - pos) < 16 && (len - pos <= len - off))\r
+ count = off;\r
+ } else {\r
+ if (pos == len)\r
+ count = 0;\r
+ }\r
+ if (off == len)\r
+ count = len;\r
+\r
+ if (count) {\r
+ snprintf(cp, sizeof(m), "%08X ", k++ * 16);\r
+ cp += strlen(cp);\r
+ }\r
+\r
+ for (i = 0; i < count; i++) {\r
+ snprintf(cp, sizeof(m), "%02X ", data[pos + i]);\r
+ cp += strlen(cp);\r
+ \r
+ if ((i + 1) % 4 == 0) {\r
+ snprintf(cp, sizeof(m), " ");\r
+ cp += strlen(cp);\r
+ }\r
+ }\r
+\r
+ if (count && count < 16) {\r
+ int j;\r
+ \r
+ for (j = 0; j < 16 - count; j++) {\r
+ snprintf(cp, sizeof(m), " ");\r
+ cp += strlen(cp);\r
+ \r
+ if ((j + count + 1) % 4 == 0) {\r
+ snprintf(cp, sizeof(m), " ");\r
+ cp += strlen(cp);\r
+ }\r
+ }\r
+ }\r
+ \r
+ for (i = 0; i < count; i++) {\r
+ char ch;\r
+ \r
+ if (data[pos] < 32 || data[pos] >= 127)\r
+ ch = '.';\r
+ else\r
+ ch = data[pos];\r
+\r
+ snprintf(cp, sizeof(m), "%c", ch);\r
+ cp += strlen(cp);\r
+ pos++;\r
+ }\r
+\r
+ if (count) {\r
+ snprintf(cp, sizeof(m), "\n");\r
+ cp += strlen(cp);\r
+ }\r
+\r
+ if (count < 16)\r
+ break;\r
+ }\r
+ \r
+ OutputDebugString(m);\r
+ MessageBox( NULL, (char *)m, "hexdump", MB_OK | MB_ICONINFORMATION );\r
+}\r
+\r
+static int \r
+silc_create_key_pair(char *pkcs_name, int bits, char *path,\r
+ char *identifier, \r
+ SilcPublicKey *ret_pub_key,\r
+ SilcPrivateKey *ret_prv_key)\r
+{\r
+ SilcPKCS pkcs;\r
+ SilcPublicKey pub_key;\r
+ SilcPrivateKey prv_key;\r
+ SilcRng rng;\r
+ unsigned char *key;\r
+ uint32 key_len;\r
+ char pkfile[256], prvfile[256];\r
+\r
+ if (!pkcs_name || !path)\r
+ return FALSE;\r
+\r
+ if (!bits)\r
+ bits = 1024;\r
+\r
+ rng = silc_rng_alloc();\r
+ silc_rng_init(rng);\r
+ silc_rng_global_init(rng);\r
+\r
+ /* Generate keys */\r
+ silc_pkcs_alloc((const unsigned char *)pkcs_name, &pkcs);\r
+ pkcs->pkcs->init(pkcs->context, bits, rng);\r
+\r
+ /* Save public key into file */\r
+ key = silc_pkcs_get_public_key(pkcs, &key_len);\r
+ pub_key = silc_pkcs_public_key_alloc(pkcs->pkcs->name, identifier,\r
+ key, key_len);\r
+ *ret_pub_key = pub_key;\r
+\r
+ memset(key, 0, sizeof(key_len));\r
+ silc_free(key);\r
+\r
+ /* Save private key into file */\r
+ key = silc_pkcs_get_private_key(pkcs, &key_len);\r
+ prv_key = silc_pkcs_private_key_alloc(pkcs->pkcs->name, key, key_len);\r
+ *ret_prv_key = prv_key;\r
+\r
+ memset(key, 0, sizeof(key_len));\r
+ silc_free(key);\r
+\r
+ silc_rng_free(rng);\r
+ silc_pkcs_free(pkcs);\r
+\r
+ return TRUE;\r
+}\r
+\r
+\r
+int APIENTRY WinMain(HINSTANCE hInstance,\r
+ HINSTANCE hPrevInstance,\r
+ LPSTR lpCmdLine,\r
+ int nCmdShow)\r
+{\r
+ // TODO: Place code here.\r
+ MSG msg;\r
+ HACCEL hAccelTable;\r
+ HANDLE h;\r
+ HANDLE handles[100];\r
+ SOCKET s;\r
+ unsigned int k;\r
+ WSAEVENT e, e2, e3;\r
+ int ret;\r
+ DWORD ready;\r
+ HMODULE mod;\r
+\r
+ // Initialize global strings\r
+ LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);\r
+ LoadString(hInstance, IDC_TESTI2, szWindowClass, MAX_LOADSTRING);\r
+ MyRegisterClass(hInstance);\r
+\r
+ // Perform application initialization:\r
+ if (!InitInstance (hInstance, nCmdShow)) \r
+ {\r
+ return FALSE;\r
+ }\r
+\r
+ hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TESTI2);\r
+\r
+ {\r
+ SilcSchedule sched; \r
+ SilcClient client;\r
+\r
+ silc_net_win32_init();\r
+ client = silc_client_alloc(&ops, NULL, NULL, "SILC-1.0-0.5.1");\r
+ client->realname = "pekka riikonen";\r
+ client->username = "priikone";\r
+ client->hostname = "leevi.kuo.fi.ssh.com";\r
+\r
+ silc_cipher_register_default();\r
+ silc_pkcs_register_default();\r
+ silc_hash_register_default();\r
+ silc_hmac_register_default();\r
+\r
+ silc_debug = TRUE;\r
+ silc_log_set_debug_callbacks(silc_debugl, silc_hexdumpl);\r
+\r
+ silc_create_key_pair("rsa", 1024, "kk", "UN=priikone, HN=pelle.kuo.fi.ssh.com", \r
+ &client->public_key, &client->private_key);\r
+\r
+ silc_client_init(client);\r
+\r
+ silc_schedule_task_add(client->schedule, 0, connect_client, \r
+ client, 0, 1, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL); \r
+\r
+ silc_client_run(client); \r
+ }\r
+ \r
+ return msg.wParam;\r
+}\r
+\r
+//\r
+// FUNCTION: MyRegisterClass()\r
+//\r
+// PURPOSE: Registers the window class.\r
+//\r
+// COMMENTS:\r
+//\r
+// This function and its usage is only necessary if you want this code\r
+// to be compatible with Win32 systems prior to the 'RegisterClassEx'\r
+// function that was added to Windows 95. It is important to call this function\r
+// so that the application will get 'well formed' small icons associated\r
+// with it.\r
+//\r
+ATOM MyRegisterClass(HINSTANCE hInstance)\r
+{\r
+ WNDCLASSEX wcex;\r
+\r
+ wcex.cbSize = sizeof(WNDCLASSEX); \r
+\r
+ wcex.style = CS_HREDRAW | CS_VREDRAW;\r
+ wcex.lpfnWndProc = (WNDPROC)WndProc;\r
+ wcex.cbClsExtra = 0;\r
+ wcex.cbWndExtra = 0;\r
+ wcex.hInstance = hInstance;\r
+ wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_TESTI2);\r
+ wcex.hCursor = LoadCursor(NULL, IDC_ARROW);\r
+ wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);\r
+ wcex.lpszMenuName = (LPCSTR)IDC_TESTI2;\r
+ wcex.lpszClassName = szWindowClass;\r
+ wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);\r
+\r
+ return RegisterClassEx(&wcex);\r
+}\r
+\r
+//\r
+// FUNCTION: InitInstance(HANDLE, int)\r
+//\r
+// PURPOSE: Saves instance handle and creates main window\r
+//\r
+// COMMENTS:\r
+//\r
+// In this function, we save the instance handle in a global variable and\r
+// create and display the main program window.\r
+//\r
+BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)\r
+{\r
+ HWND hWnd;\r
+\r
+ hInst = hInstance; // Store instance handle in our global variable\r
+\r
+ hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,\r
+ CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);\r
+\r
+ if (!hWnd)\r
+ {\r
+ LPVOID lpMsgBuf;\r
+ FormatMessage( \r
+ FORMAT_MESSAGE_ALLOCATE_BUFFER | \r
+ FORMAT_MESSAGE_FROM_SYSTEM | \r
+ FORMAT_MESSAGE_IGNORE_INSERTS,\r
+ NULL,\r
+ GetLastError(),\r
+ 0, // Default language\r
+ (LPTSTR) &lpMsgBuf,\r
+ 0,\r
+ NULL \r
+ );\r
+ // Process any inserts in lpMsgBuf.\r
+ // ...\r
+ // Display the string.\r
+ MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );\r
+ // Free the buffer.\r
+ LocalFree( lpMsgBuf );\r
+\r
+ return FALSE;\r
+ }\r
+\r
+ ShowWindow(hWnd, nCmdShow);\r
+ UpdateWindow(hWnd);\r
+\r
+ return TRUE;\r
+}\r
+\r
+//\r
+// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)\r
+//\r
+// PURPOSE: Processes messages for the main window.\r
+//\r
+// WM_COMMAND - process the application menu\r
+// WM_PAINT - Paint the main window\r
+// WM_DESTROY - post a quit message and return\r
+//\r
+//\r
+LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)\r
+{\r
+ int wmId, wmEvent;\r
+ PAINTSTRUCT ps;\r
+ HDC hdc;\r
+ TCHAR szHello[MAX_LOADSTRING];\r
+ LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);\r
+\r
+ switch (message) \r
+ {\r
+ case WM_COMMAND:\r
+ wmId = LOWORD(wParam); \r
+ wmEvent = HIWORD(wParam); \r
+ // Parse the menu selections:\r
+ switch (wmId)\r
+ {\r
+ case IDM_ABOUT:\r
+ DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);\r
+ break;\r
+ case IDM_EXIT:\r
+ DestroyWindow(hWnd);\r
+ break;\r
+ default:\r
+ return DefWindowProc(hWnd, message, wParam, lParam);\r
+ }\r
+ break;\r
+ case WM_PAINT:\r
+ hdc = BeginPaint(hWnd, &ps);\r
+ // TODO: Add any drawing code here...\r
+ RECT rt;\r
+ GetClientRect(hWnd, &rt);\r
+ DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);\r
+ EndPaint(hWnd, &ps);\r
+ break;\r
+ case WM_DESTROY:\r
+ PostQuitMessage(0);\r
+ break;\r
+ default:\r
+ return DefWindowProc(hWnd, message, wParam, lParam);\r
+ }\r
+ return 0;\r
+}\r
+\r
+// Mesage handler for about box.\r
+LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
+{\r
+ switch (message)\r
+ {\r
+ case WM_INITDIALOG:\r
+ return TRUE;\r
+\r
+ case WM_COMMAND:\r
+ if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) \r
+ {\r
+ EndDialog(hDlg, LOWORD(wParam));\r
+ return TRUE;\r
+ }\r
+ break;\r
+ }\r
+ return FALSE;\r
+}\r