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

Contents of /trunk/OpenPGPminidriverTest/PublicDataOperations.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (show annotations)
Thu Mar 18 16:03:39 2010 UTC (15 years, 1 month ago) by vletoux
File size: 4152 byte(s)
first working & stable version
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 <stdio.h>
21 #include <cardmod.h>
22 #include "global.h"
23 #include "dialog.h"
24
25
26 DWORD ListFiles(HWND hWnd, PSTR szDirectory)
27 {
28 DWORD dwReturn = 0, dwSize;
29 LPSTR pszFiles = NULL;
30
31 dwSize = 0;
32 dwReturn = pCardData->pfnCardEnumFiles(pCardData, szDirectory, &pszFiles, &dwSize, 0);
33 if (!dwReturn)
34 {
35 LPSTR szCurrentFile = pszFiles;
36 while (szCurrentFile[0] != 0)
37 {
38 CHAR szText[256];
39 if (szDirectory)
40 {
41 sprintf_s(szText, ARRAYSIZE(szText),"%s\\%s",szDirectory, szCurrentFile);
42 }
43 else
44 {
45 sprintf_s(szText, ARRAYSIZE(szText),"%s",szCurrentFile);
46 }
47 SendDlgItemMessageA(hWnd,IDC_FILES,LB_ADDSTRING,0,(LPARAM)szText);
48 if (_stricmp(szCurrentFile,"cardapps") == 0)
49 {
50 PBYTE pbData = NULL;
51 dwSize = 0;
52 dwReturn = pCardData->pfnCardReadFile(pCardData, szDirectory, szCurrentFile, 0, &pbData, &dwSize);
53 if (dwReturn == 0)
54 {
55 CHAR szDirectory[9];
56 for (DWORD dwI = 0; dwI < dwSize; dwI+=8)
57 {
58 memcpy(szDirectory, pbData + dwI, 8);
59 szDirectory[8] = 0;
60 ListFiles(hWnd, szDirectory);
61 }
62
63 pCardData->pfnCspFree(pbData);
64 }
65 }
66
67 szCurrentFile = szCurrentFile + strlen(szCurrentFile)+1;
68 }
69 pCardData->pfnCspFree(pszFiles);
70 }
71 return dwReturn;
72 }
73
74 DWORD ListFiles(HWND hWnd)
75 {
76 if (!pCardData)
77 {
78 return SCARD_E_COMM_DATA_LOST;
79 }
80 SendMessage(GetDlgItem(hWnd, IDC_FILES),LB_RESETCONTENT,0,0);
81 return ListFiles(hWnd, NULL);
82 }
83
84 DWORD ViewFile(HWND hWnd)
85 {
86 CHAR szFileName[256];
87 PSTR szFile, szDirectory;
88 DWORD dwReturn;
89 PBYTE pbData = NULL;
90 DWORD dwSize;
91 TCHAR szData[10];
92 __try
93 {
94 // clear text
95 SendMessage( GetDlgItem(hWnd, IDC_CONTENT), WM_SETTEXT,0,(LPARAM) "");
96
97 DWORD iItem = (DWORD)SendMessage(GetDlgItem(hWnd, IDC_FILES),LB_GETCURSEL,0,0);
98 if (iItem == LB_ERR)
99 {
100 dwReturn = SCARD_E_COMM_DATA_LOST;
101 __leave;
102 }
103 if (!pCardData)
104 {
105 dwReturn = SCARD_E_COMM_DATA_LOST;
106 __leave;
107 }
108 SendMessageA( GetDlgItem(hWnd,IDC_FILES), LB_GETTEXT,iItem,(LPARAM)szFileName);
109
110 szFile = strchr(szFileName,'\\');
111 if (szFile)
112 {
113 *szFile = 0;
114 szFile++;
115 szDirectory = szFileName;
116 }
117 else
118 {
119 szDirectory = NULL;
120 szFile = szFileName;
121 }
122 dwReturn = pCardData->pfnCardReadFile(pCardData,szDirectory,szFile, 0, &pbData, &dwSize);
123 if (dwReturn)
124 {
125 __leave;
126 }
127 if (strcmp(szDirectory, "openpgp") == 0 && strcmp(szFile, "certific") == 0 )
128 {
129 PCCERT_CONTEXT pCertContext = CertCreateCertificateContext( X509_ASN_ENCODING , pbData, dwSize);
130 if (!pCertContext)
131 {
132 dwReturn = GetLastError();
133 __leave;
134 }
135 ViewCertificate(hWnd, pCertContext);
136 CertFreeCertificateContext(pCertContext);
137 }
138 else
139 {
140 for(DWORD dwI = 0; dwI < dwSize; dwI++)
141 {
142 _stprintf_s(szData,ARRAYSIZE(szData),TEXT("%02X "),pbData[dwI]);
143 SendMessage( // returns LRESULT in lResult
144 GetDlgItem(hWnd, IDC_CONTENT), // (HWND) handle to destination control
145 EM_REPLACESEL, // (UINT) message ID
146 FALSE, // = () wParam;
147 (LPARAM)szData // = (LPARAM)(LPCTSTR) lParam;
148 );
149
150 }
151 }
152 }
153 __finally
154 {
155 if (pbData)
156 pCardData->pfnCspFree(pbData);
157 }
158 return dwReturn;
159 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26