/[openpgpmdrv]/trunk/OpenPGPminidriverTest/main.cpp
ViewVC logotype

Annotation of /trunk/OpenPGPminidriverTest/main.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5 - (hide annotations)
Tue Mar 2 18:54:34 2010 UTC (15 years, 2 months ago) by vletoux
File size: 6072 byte(s)
authentication working
1 vletoux 1 /* OpenPGP Smart Card Mini Driver
2     Copyright (C) 2009 Vincent Le Toux
3    
4     This library is Free software; you can redistribute it and/or
5     modify it under the terms of the GNU Lesser General Public
6     License version 2.1 as published by the Free Software Foundation.
7    
8     This library is distributed in the hope that it will be useful,
9     but WITHOUT ANY WARRANTY; without even the implied warranty of
10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11     Lesser General Public License for more details.
12    
13     You should have received a copy of the GNU Lesser General Public
14     License along with this library; if not, write to the Free Software
15     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16     */
17    
18     #include <windows.h>
19     #include <tchar.h>
20     #include <cardmod.h>
21     #include <commctrl.h>
22     #include "dialog.h"
23     #include "global.h"
24    
25     #ifdef UNICODE
26     #if defined _M_IX86
27     #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
28     #elif defined _M_IA64
29     #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
30     #elif defined _M_X64
31     #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
32     #else
33     #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
34     #endif
35     #endif
36    
37     // Variables globales :
38     HINSTANCE hInst; // instance actuelle
39     HWND hMainWnd;
40    
41     INT_PTR CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
42    
43     int APIENTRY _tWinMain(HINSTANCE hInstance,
44     HINSTANCE hPrevInstance,
45     LPTSTR lpCmdLine,
46     int nCmdShow)
47     {
48     UNREFERENCED_PARAMETER(hPrevInstance);
49     UNREFERENCED_PARAMETER(lpCmdLine);
50     hInst = hInstance;
51    
52     DialogBox (hInst, MAKEINTRESOURCE (IDD_DLG), 0, WndProc);
53     return 0;
54    
55     }
56    
57     void MessageBoxWin32(DWORD status) {
58     LPVOID Error;
59     FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
60     NULL,status,0,(LPTSTR)&Error,0,NULL);
61     MessageBox(NULL,(LPCTSTR)Error,NULL,MB_ICONASTERISK);
62     LocalFree(Error);
63     }
64    
65     BOOL GetContainerName(PWSTR szContainer, PDWORD pdwKeySpec)
66     {
67     DWORD iItem = SendMessage(GetDlgItem(hMainWnd, IDC_LSTCONTAINER),LB_GETCURSEL,0,0);
68     if (iItem == LB_ERR) return FALSE;
69     SendMessage( GetDlgItem(hMainWnd,IDC_LSTCONTAINER), LB_GETTEXT,iItem,(LPARAM)szContainer);
70     *pdwKeySpec = _tstoi(szContainer + _tcslen(szContainer) - 1);
71     szContainer[ _tcslen(szContainer) - 2] = 0;
72     return TRUE;
73     }
74    
75     INT_PTR CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
76     {
77     int wmId, wmEvent;
78     DWORD dwReturn;
79     TCHAR szPin[256];
80     TCHAR szContainer[256];
81     DWORD dwKeySpec;
82     switch (message)
83     {
84     case WM_INITDIALOG:
85     hMainWnd = hWnd;
86     CheckDlgButton(hWnd,IDC_CurrentDll,BST_CHECKED);
87     CheckDlgButton(hWnd,IDC_PINUSER,BST_CHECKED);
88     SendDlgItemMessage(hMainWnd,IDC_CONTAINERINDEX,CB_ADDSTRING,0,(LPARAM)TEXT("Signature"));
89     SendDlgItemMessage(hMainWnd,IDC_CONTAINERINDEX,CB_ADDSTRING,0,(LPARAM)TEXT("Authentication"));
90     SendDlgItemMessage(hMainWnd,IDC_CONTAINERINDEX,CB_ADDSTRING,0,(LPARAM)TEXT("Confidentiality"));
91     SendDlgItemMessage(hMainWnd,IDC_CONTAINERINDEX, CB_SETCURSEL, 0, 0);
92     break;
93    
94     case WM_CLOSE:
95     EndDialog(hWnd, IDOK);
96     return TRUE;
97     case WM_COMMAND:
98     wmId = LOWORD(wParam);
99     wmEvent = HIWORD(wParam);
100    
101     switch (wmId)
102     {
103     case IDC_CONNECT:
104     if (IsDlgButtonChecked(hWnd,IDC_SystemDll))
105     {
106     dwReturn = Connect(TRUE);
107     }
108     else
109     {
110     dwReturn = Connect(FALSE);
111     }
112     if (dwReturn)
113     {
114     MessageBoxWin32(dwReturn);
115     }
116     break;
117     case IDC_DISCONNECT:
118     dwReturn = Disconnect();
119     if (dwReturn)
120     {
121     MessageBoxWin32(dwReturn);
122     }
123     break;
124     case IDC_PIN:
125     GetDlgItemText(hWnd,IDC_TXTPIN,szPin,ARRAYSIZE(szPin));
126     DWORD dwRemaining;
127     if (IsDlgButtonChecked(hWnd,IDC_PINADMIN))
128     {
129     dwReturn = Authenticate(szPin, wszCARD_USER_ADMIN, &dwRemaining);
130     }
131     else
132     {
133     dwReturn = Authenticate(szPin, wszCARD_USER_USER, &dwRemaining);
134     }
135     MessageBoxWin32(dwReturn);
136     break;
137     case IDC_LISTFILES:
138     dwReturn = ListFiles();
139     if (dwReturn)
140     {
141     MessageBoxWin32(dwReturn);
142     }
143     break;
144     case IDC_NEWKEY:
145     dwReturn = GenerateNewKey(SendDlgItemMessage(hMainWnd,IDC_CONTAINERINDEX, CB_GETCURSEL, 0, 0));
146     MessageBoxWin32(dwReturn);
147     break;
148     case IDC_IMPORTKEY:
149     dwReturn = ImportKey(SendDlgItemMessage(hMainWnd,IDC_CONTAINERINDEX, CB_GETCURSEL, 0, 0));
150     MessageBoxWin32(dwReturn);
151     break;
152 vletoux 5 case IDC_SAMEKEY:
153     dwReturn = SetTheSameKeyForAllContainers();
154     MessageBoxWin32(dwReturn);
155     break;
156 vletoux 1 ////////// base CSP
157     case IDC_CONTAINER:
158     dwReturn = ListContainer();
159     if (dwReturn)
160     {
161     MessageBoxWin32(dwReturn);
162     }
163     break;
164     case IDC_SIGN:
165     if (GetContainerName(szContainer, &dwKeySpec))
166     {
167     dwReturn = Sign(szContainer, dwKeySpec);
168     MessageBoxWin32(dwReturn);
169     }
170     break;
171     case IDC_DECRYPT:
172     if (GetContainerName(szContainer, &dwKeySpec))
173     {
174     dwReturn = Decrypt(szContainer, dwKeySpec);
175     MessageBoxWin32(dwReturn);
176     }
177     break;
178     case IDC_LSTCONTAINER:
179     switch(wmEvent)
180     {
181     case LBN_DBLCLK:
182     if (GetContainerName(szContainer, &dwKeySpec))
183     {
184     dwReturn = ViewCertificate(szContainer, dwKeySpec);
185     if (dwReturn)
186     {
187     MessageBoxWin32(dwReturn);
188     }
189     }
190     break;
191     }
192     break;
193     }
194     break;
195     }
196     return FALSE;
197     }
198    

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26