NB! This project is outdated and unmaintained, please refer to the OpenSC WindowsInstaller instead!
| r39 | r99 | |
|---|---|---|
| 21 | 21 | - copy cspsign.exe to system32 |
| 22 | 22 | - run cspsign s csp11.dll csp11.sig |
| 23 | - run csp11ins |
|
| 23 | - run csp11ins csp11.sig | |
| 24 | 24 | |
| 25 | 25 | Win 95/98/ME/NT4 was not tested. Note from the original README: |
| r39 | r99 | |
|---|---|---|
| 34 | 34 | */ |
| 35 | 35 | |
| 36 | #undef UNICODE // ## Not Yet | |
| 36 | #ifdef HAVE_CONFIG_H | |
| 37 | #include <config.h> | |
| 38 | #endif | |
| 37 | 39 | #include <stdlib.h> |
| 38 | 40 | #include <stdio.h> |
| … | … | |
| 66 | 68 | /** \brief Register the CSP11 DLL. |
| 67 | 69 | */ |
| 68 | int |
|
| 70 | int main(int argc, char *argv[]) | |
| 69 | 71 | { |
| 72 | char *szSigFile = NULL; | |
| 73 | ||
| 74 | if (argc != 2) { | |
| 75 | fprintf (stderr, "Usage: %s sig-file\n", argv[0]); | |
| 76 | exit (1); | |
| 77 | } | |
| 78 | ||
| 79 | szSigFile = argv[1]; | |
| 80 | ||
| 70 | 81 | /** 1. Open the signature file.*/ |
| 71 | if ((hSigFile = CreateFile |
|
| 82 | if ((hSigFile = CreateFileA(szSigFile, | |
| 72 | 83 | GENERIC_READ, 0, NULL, |
| 73 | 84 | OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, |
| … | … | |
| 117 | 128 | |
| 118 | 129 | /** 6.Create or open a key in local machine for CSP #11:*/ |
| 119 | if ((ret = RegCreateKeyEx |
|
| 130 | if ((ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, | |
| 120 | 131 | (const char *) szProvider, |
| 121 | 132 | 0L, "", REG_OPTION_NON_VOLATILE, |
| … | … | |
| 127 | 138 | |
| 128 | 139 | /** 7. Register the "Image Path" for CSP 11 DLL.*/ |
| 129 | if ((ret = RegSetValueEx |
|
| 130 | |
|
| 140 | if ((ret = RegSetValueExA(hKey, "Image Path", 0L, REG_SZ, (PBYTE)szImagePath, | |
| 141 | (DWORD)strlen(szImagePath)+1)) != ERROR_SUCCESS) | |
| 131 | 142 | { |
| 132 | 143 | printf("Error setting registry Image Path.\n"); |
| … | … | |
| 136 | 147 | /** 8. Set CSP type to PROV_RSA_FULL (==1). */ |
| 137 | 148 | dwValue = CSP11_PROV_TYPE; |
| 138 | if ((ret = RegSetValueEx |
|
| 139 | ( |
|
| 149 | if ((ret = RegSetValueExA(hKey, "Type", 0L, REG_DWORD, | |
| 150 | (PBYTE)&dwValue, | |
| 140 | 151 | sizeof(DWORD))) != ERROR_SUCCESS) |
| 141 | 152 | { |
| … | … | |
| 145 | 156 | |
| 146 | 157 | /** 9. Store signature. */ |
| 147 | if ((ret = RegSetValueEx |
|
| 148 | |
|
| 158 | if ((ret = RegSetValueExA(hKey, "Signature", 0L, REG_BINARY, | |
| 159 | lpvAddress, | |
| 149 | 160 | fileSize)) != ERROR_SUCCESS) |
| 150 | 161 | { |
| … | … | |
| 157 | 168 | |
| 158 | 169 | /** 10.Create or open a key in local machine for CSP of type 001*/ |
| 159 | if ((ret = RegCreateKeyEx |
|
| 170 | if ((ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, | |
| 160 | 171 | (const char *) szType, |
| 161 | 172 | 0L, "", REG_OPTION_NON_VOLATILE, |
| r39 | r99 | |
|---|---|---|
| 3 | 3 | LIBS = User32.lib |
| 4 | 4 | |
| 5 | COPTS = /Zi /MD /nologo /D_WIN32_WINNT=0x0400 / |
|
| 5 | COPTS = /Zi /MD /nologo /D_WIN32_WINNT=0x0400 /DWIN32_LEAN_AND_MEAN /DUNICODE /I$(CSPDK_INC) /I$(OPENSC_INC) /I../include | |
| 6 | 6 | LINKFLAGS = /DEBUG /NOLOGO /INCREMENTAL:NO /MACHINE:IX86 |
| 7 | 7 | |
| … | … | |
| 16 | 16 | cl $(COPTS) /c $< |
| 17 | 17 | |
| 18 | $(TARGET): $(OBJECTS) | |
| 19 | rc csp11.rc | |
| 18 | csp11.def: csp11.exports | |
| 19 | echo LIBRARY CSP11 > csp11.def | |
| 20 | echo DESCRIPTION 'Cryptographic Service Provider #11' >> csp11.def | |
| 21 | type csp11.exports >> csp11.def | |
| 22 | ||
| 23 | $(TARGET): $(OBJECTS) csp11.def | |
| 24 | rc resource.rc | |
| 20 | 25 | link $(LINKFLAGS) /dll /def:csp11.def /implib:csp11.lib /out:csp11.dll \ |
| 21 | |
|
| 26 | resource.res $(OBJECTS) $(LIBS) |
| r39 | r99 | |
|---|---|---|
| 28 | 28 | */ |
| 29 | 29 | |
| 30 | #ifdef HAVE_CONFIG_H | |
| 31 | #include <config.h> | |
| 32 | #endif | |
| 30 | 33 | #include <stdlib.h> |
| 31 | 34 | #include <stdio.h> |
| r39 | r99 | |
|---|---|---|
| 30 | 30 | |
| 31 | 31 | #ifndef _CSP_DEBUG_H_ |
| 32 | ||
| 33 | 32 | #define _CSP_DEBUG_H_ /**< csp11.h inclusion tag. */ |
| 34 | 33 | #ifdef __cplusplus |
| … | … | |
| 69 | 68 | } |
| 70 | 69 | #endif |
| 71 | #endif / |
|
| 70 | #endif /* _CSP_DEBUG_H_ */ | |
| 72 | 71 |
| r39 | r99 | |
|---|---|---|
| 43 | 43 | */ |
| 44 | 44 | |
| 45 | #if |
|
| 46 | # |
|
| 45 | #ifdef HAVE_CONFIG_H | |
| 46 | #include <config.h> | |
| 47 | 47 | #endif |
| 48 | ||
| 49 | ||
| 50 | 48 | #include <stdio.h> |
| 51 | 49 | #include <stdlib.h> |
| … | … | |
| 54 | 52 | #ifdef _MSC_VER |
| 55 | 53 | #include <cspdk.h> |
| 56 | #include |
|
| 54 | #include <missdef.h> | |
| 57 | 55 | #else |
| 58 | #include |
|
| 56 | #include <misscrypt.h> | |
| 59 | 57 | #endif |
| 60 | #include <rsaref/win32.h> | |
| 61 | #include <rsaref/pkcs11.h> | |
| 58 | #include <pkcs11.h> | |
| 62 | 59 | #include "csp11.h" |
| 63 | 60 | #include "pkcs11-services.h" |
| 64 | 61 | #include "ui-pin.h" |
| 65 | 62 | #include "csp-debug.h" |
| 63 | ||
| 64 | /** \brief Return the wanted handler index in the given granted handlers list. | |
| 65 | * | |
| 66 | * \param grantedHandles Pointer to the beginning of the granted handlers | |
| 67 | * tab. | |
| 68 | * \param max_len The maximum lenth of the granted handlers list. | |
| 69 | * \param wantedHandle The wanted handler. | |
| 70 | * | |
| 71 | * \return An integer from 0 to max_len-1 if a granted context is found. | |
| 72 | * Negative value if not. | |
| 73 | * \ingroup SPInternal | |
| 74 | */ | |
| 75 | static int findGrantedHandle(HANDLE *grantedHandles, int max_len, HANDLE wantedHandle); | |
| 76 | ||
| 77 | /** \brief Grants a cryptographic handle. | |
| 78 | * | |
| 79 | * Used to remember granted handlers. | |
| 80 | * | |
| 81 | * \param grantedHandles Pointer to the granted handler list pointer. | |
| 82 | * \param lenth Pointer to the lenth of the list. | |
| 83 | * \param lenth Maximum authorized lenth of the list. 0 means unlimited. | |
| 84 | * \param handle The handle to grant. | |
| 85 | * | |
| 86 | * \return TRUE if everything went OK. | |
| 87 | * \ingroup SPInternal | |
| 88 | */ | |
| 89 | static BOOL grantHandle(HANDLE **grantedHandles, int *lenth, | |
| 90 | HANDLE handle); | |
| 91 | ||
| 92 | /** \brief Revokes a granted cryptographic handle. | |
| 93 | * | |
| 94 | * Used to forget a granted handle. | |
| 95 | * | |
| 96 | * \param handle Handler to the provided context to forget. | |
| 97 | * \param lenth Lenth of the granted handles list. | |
| 98 | * \param grantedHandles Pointer to the granted handles list. | |
| 99 | * | |
| 100 | * \return TRUE if everything went OK. | |
| 101 | * \ingroup SPInternal | |
| 102 | */ | |
| 103 | static BOOL revokeHandle(HANDLE **grantedHandles, int *lenth, HANDLE handle); | |
| 104 | ||
| 105 | /** \brief Check if a crypto handler was provided. | |
| 106 | * | |
| 107 | * Check if the given handler is really a valid cryptographic context handler. | |
| 108 | * | |
| 109 | * \param lenth Number of granted handles. | |
| 110 | * \param grantedHandles Pointer to the granted handles list. | |
| 111 | * \param handle Handle to check. | |
| 112 | * | |
| 113 | * \return TRUE if the handler was granted by CSP-eleven, FALSE if not. | |
| 114 | * \ingroup SPInternal | |
| 115 | */ | |
| 116 | static BOOL grantedHandle(HANDLE *grantedHandles, int lenth, HANDLE handle); | |
| 117 | ||
| 118 | /** \brief Return the algId csp11 ALGORITHM. | |
| 119 | * | |
| 120 | * Browse the algorithms table and get the wanted definition. | |
| 121 | * | |
| 122 | * \param algId The wanted CAPI algorithm ID. | |
| 123 | * \param algorithm The corresponding ALGORITHM structure. | |
| 124 | * | |
| 125 | * \return TRUE if algorithm found, FALSE if not. | |
| 126 | * | |
| 127 | * \ingroup SPInternal | |
| 128 | */ | |
| 129 | static BOOL getAlgorithm(ALG_ID algId, ALGORITHM *algorithm); | |
| 130 | ||
| 131 | /** \brief Return size of produced hash value in bytes. | |
| 132 | * | |
| 133 | * \warning The size is returned in BYTES. | |
| 134 | * | |
| 135 | * \param Algid Id of wanted algorithm size. | |
| 136 | * | |
| 137 | * \return >0 integer if the id is supported, -1 if not. | |
| 138 | * | |
| 139 | * \ingroup SPInternal | |
| 140 | */ | |
| 141 | static DWORD getHashSize(ALG_ID Algid); | |
| 142 | ||
| 143 | /** \brief Initialise a key handler. | |
| 144 | * | |
| 145 | * \param pProvCtx Pointer to the used crypto context. | |
| 146 | * \param pKey Pointer to the handler to fill. | |
| 147 | * \param algId Key algorithm CAPI ID. | |
| 148 | * \return TRUE; | |
| 149 | * | |
| 150 | * \ingroup SPInternal | |
| 151 | */ | |
| 152 | static BOOL initKey(PROV_CTX *pProvCtx, KEY_INFO *pKey, ALG_ID algId); | |
| 153 | ||
| 154 | /** \brief Reverse a byte string. | |
| 155 | * | |
| 156 | * \param pBytes Pointer to the bytes string. | |
| 157 | * \param stringLen Length of the bytes string. | |
| 158 | * | |
| 159 | * \return TRUE if the bytes string was successfully reversed. | |
| 160 | * \ingroup SPInternal | |
| 161 | * \note Hey school boys, students or better, take a look ! | |
| 162 | * Gambin gave us a teach: a very good algo to reverse bytes string. | |
| 163 | */ | |
| 164 | static BOOL reverseBytesString(BYTE *pBytes, DWORD stringLen); | |
| 165 | ||
| 166 | /** \brief Set hash algi and alg oid. | |
| 167 | * | |
| 168 | * Set the hash algid and try to get the corresponding oid. | |
| 169 | * If no oid found, bad alg id. | |
| 170 | * \param algId The alg Id to set. | |
| 171 | * \param pHash Pointer to the key information structure. | |
| 172 | * \ingroup SPInternal | |
| 173 | * | |
| 174 | * \return TRUE if algid and oid are set. | |
| 175 | */ | |
| 176 | static BOOL setHashAlgId(ALG_ID algId, HASH_INFO *pHash); | |
| 177 | ||
| 178 | /** \brief Set key algi and alg oid. | |
| 179 | * | |
| 180 | * Set the key algid and try to get the corresponding oid. | |
| 181 | * If no oid found, bad alg id. | |
| 182 | * \param algId The alg Id to set. | |
| 183 | * \param pKey Pointer to the key information structure. | |
| 184 | * | |
| 185 | * \ingroup SPInternal | |
| 186 | * \return TRUE if algid and oid are set. | |
| 187 | */ | |
| 188 | static BOOL setKeyAlgId(ALG_ID algId, KEY_INFO *pKey); | |
| 66 | 189 | |
| 67 | 190 | |
| … | … | |
| 83 | 206 | static int grantedKeysNb = 0; /**< Number of actual granted keys.*/ |
| 84 | 207 | |
| 85 | //static HANDLE GetProcessHeap() = NULL; /**< Handle to the csp11 heap object. */ | |
| 208 | #if 0 | |
| 209 | static HANDLE GetProcessHeap() = NULL; /**< Handle to the csp11 heap object. */ | |
| 210 | #endif | |
| 86 | 211 | |
| 87 | 212 | ALGORITHM Algs[] = { |
| … | … | |
| 120 | 245 | BOOL WINAPI |
| 121 | 246 | DllMain( |
| 122 | HINSTANCE hinstDLL, / |
|
| 123 | DWORD fdwReason, / |
|
| 124 | LPVOID lpvReserved) / |
|
| 247 | HINSTANCE hinstDLL, /* handle to the DLL module */ | |
| 248 | DWORD fdwReason, /* reason for calling function */ | |
| 249 | LPVOID lpvReserved) /* reserved */ | |
| 125 | 250 | { |
| 126 | 251 | switch( fdwReason ) |
| … | … | |
| 151 | 276 | */ |
| 152 | 277 | BOOL WINAPI |
| 153 | CPAcquireContext |
|
| 278 | CPAcquireContextW( | |
| 154 | 279 | OUT HCRYPTPROV *phProv, |
| 155 | 280 | IN LPCSTR szContainer, |
| 156 | 281 | IN DWORD dwFlags, |
| 157 | IN PVTableProvStruc |
|
| 282 | IN PVTableProvStrucW pVTable) | |
| 158 | 283 | { |
| 159 | LP |
|
| 284 | LPCSTR cName = NULL; /* Local copy of szContainer C string pointer */ | |
| 160 | 285 | size_t nameSize = 0; /* Size of the provided container name.*/ |
| 161 | 286 | PROV_CTX *pProvCtx = NULL; /* Provider context */ |
| … | … | |
| 165 | 290 | applicable.*/ |
| 166 | 291 | char debug[255]; |
| 167 | |
|
| 292 | HWND FuncReturnedhWnd = 0; | |
| 168 | 293 | |
| 169 | 294 | DEBUG(3,"_-_-_-_-_-_-_-_-_Acquiring Context-_-_-_-_-_-_-_-_-\n"); |
| … | … | |
| 1911 | 2036 | hashValLen = getHashSize(pHash->Algid); |
| 1912 | 2037 | /** - If hash size < 0, bad hash.*/ |
| 1913 | if(hashValLen |
|
| 2038 | if(hashValLen == 0) | |
| 1914 | 2039 | { |
| 1915 | 2040 | SetLastError(NTE_BAD_HASH); |
| … | … | |
| 2006 | 2131 | hashLen = getHashSize(pHash->Algid); |
| 2007 | 2132 | /** - If hash size < 0, bad hash.*/ |
| 2008 | if(hashLen |
|
| 2133 | if(hashLen == 0) | |
| 2009 | 2134 | { |
| 2010 | 2135 | SetLastError(NTE_BAD_HASH); |
| … | … | |
| 2047 | 2172 | hashLen = getHashSize(pHash->Algid); |
| 2048 | 2173 | /** - If hash size < 0, bad hash.*/ |
| 2049 | if(hashLen |
|
| 2174 | if(hashLen == 0) | |
| 2050 | 2175 | { |
| 2051 | 2176 | SetLastError(NTE_BAD_HASH); |
| … | … | |
| 2079 | 2204 | hashLen = getHashSize(pHash->Algid); |
| 2080 | 2205 | /** - If hash size < 0, bad hash.*/ |
| 2081 | if(hashLen |
|
| 2206 | if(hashLen == 0) | |
| 2082 | 2207 | { |
| 2083 | 2208 | SetLastError(NTE_BAD_HASH); |
| … | … | |
| 2277 | 2402 | OUT HCRYPTKEY *phKey) |
| 2278 | 2403 | { |
| 2279 | *phKey = (HCRYPTKEY)NULL; / |
|
| 2404 | *phKey = (HCRYPTKEY)NULL; /* Replace NULL with your own structure. */ | |
| 2280 | 2405 | DEBUG(3,"_-_-_-_-_-_-_-_-_Importing key-_-_-_-_-_-_-_-_-\n"); |
| 2281 | 2406 | DEBUG(1, "ERROR: A not implemented function was called !!!\n"); |
| … | … | |
| 3249 | 3374 | hashValLen = getHashSize(pHash->Algid); |
| 3250 | 3375 | /** - If hash size < 0, bad hash.*/ |
| 3251 | if(hashValLen |
|
| 3376 | if(hashValLen == 0) | |
| 3252 | 3377 | { |
| 3253 | 3378 | SetLastError(NTE_BAD_HASH); |
| … | … | |
| 3287 | 3412 | OUT HCRYPTKEY *phKey) |
| 3288 | 3413 | { |
| 3289 | *phKey = (HCRYPTKEY)NULL; / |
|
| 3414 | *phKey = (HCRYPTKEY)NULL; /* Replace NULL with your own structure. */ | |
| 3290 | 3415 | /** \todo code it.*/ |
| 3291 | 3416 | DEBUG(3,"_-_-_-_-_-_-_-_-_Duplicate key-_-_-_-_-_-_-_-_-\n"); |
| … | … | |
| 3298 | 3423 | |
| 3299 | 3424 | /** \brief Return the wanted handler index in the granted handlers list.*/ |
| 3300 | ||
| 3425 | static int findGrantedHandle(HANDLE *grantedHandles, int max_len, HANDLE wantedHandle) | |
| 3301 | 3426 | { |
| 3302 | 3427 | HANDLE *current; /* Current handler index in the handlers list.*/ |
| … | … | |
| 3353 | 3478 | |
| 3354 | 3479 | /** \brief Grants a handler.*/ |
| 3355 | ||
| 3480 | static BOOL grantHandle(HANDLE **grantedHandles, int *length, HANDLE handle) | |
| 3356 | 3481 | { |
| 3357 | 3482 | int index, i; /* Position indexes in the handlers list.*/ |
| … | … | |
| 3422 | 3547 | |
| 3423 | 3548 | /** - If the context index is valid.*/ |
| 3424 | if (index>=0 && index< |
|
| 3549 | if (index>=0 && index<=(*length)) | |
| 3425 | 3550 | { |
| 3426 | 3551 | /** - Fill the new list with the provided context.*/ |
| … | … | |
| 3453 | 3578 | |
| 3454 | 3579 | /** \brief Revokes a granted cryptographic handler.*/ |
| 3455 | ||
| 3580 | static BOOL revokeHandle(HANDLE **grantedHandles, int *length, HANDLE handle) | |
| 3456 | 3581 | { |
| 3457 | 3582 | int index, i; /* Position indexes in the handlers list.*/ |
| … | … | |
| 3544 | 3669 | } |
| 3545 | 3670 | |
| 3546 | ||
| 3671 | static BOOL grantedHandle(HANDLE *grantedHandles, int length, HANDLE handle) | |
| 3547 | 3672 | { |
| 3548 | 3673 | /** - If the wanted handle has a position index >=0, it has been granted.*/ |
| … | … | |
| 3557 | 3682 | } |
| 3558 | 3683 | |
| 3559 | ||
| 3684 | static DWORD getHashSize(ALG_ID Algid) | |
| 3560 | 3685 | { |
| 3561 | 3686 | switch(Algid) |
| … | … | |
| 3586 | 3711 | return 20+16; |
| 3587 | 3712 | default: |
| 3588 | /** - Everything else: |
|
| 3589 | return |
|
| 3713 | /** - Everything else: 0.*/ | |
| 3714 | return 0; | |
| 3590 | 3715 | } |
| 3591 | 3716 | } |
| r39 | r99 | |
|---|---|---|
| 62 | 62 | |
| 63 | 63 | #ifndef _CSP11_H_ |
| 64 | ||
| 65 | 64 | #define _CSP11_H_ /**< csp11.h inclusion tag. */ |
| 66 | 65 | #ifdef __cplusplus |
| … | … | |
| 319 | 318 | */ |
| 320 | 319 | BOOL WINAPI |
| 321 | CPAcquireContext |
|
| 320 | CPAcquireContextW( | |
| 322 | 321 | OUT HCRYPTPROV *phProv, |
| 323 | 322 | IN LPCSTR szContainer, |
| 324 | 323 | IN DWORD dwFlags, |
| 325 | IN PVTableProvStruc |
|
| 324 | IN PVTableProvStrucW pVTable); | |
| 326 | 325 | |
| 327 | 326 | |
| … | … | |
| 1488 | 1487 | OUT HCRYPTKEY *phKey); |
| 1489 | 1488 | |
| 1490 | ||
| 1491 | ||
| 1492 | ||
| 1493 | ||
| 1494 | ||
| 1495 | ||
| 1496 | ||
| 1497 | ||
| 1498 | ||
| 1499 | ||
| 1500 | ||
| 1501 | ||
| 1502 | ||
| 1503 | ||
| 1504 | ||
| 1505 | ||
| 1506 | ||
| 1507 | ||
| 1508 | ||
| 1509 | ||
| 1510 | ||
| 1511 | ||
| 1512 | ||
| 1513 | ||
| 1514 | ||
| 1515 | ||
| 1516 | ||
| 1517 | ||
| 1518 | ||
| 1519 | ||
| 1520 | ||
| 1521 | ||
| 1522 | ||
| 1523 | ||
| 1524 | ||
| 1525 | ||
| 1526 | ||
| 1527 | ||
| 1528 | ||
| 1529 | ||
| 1530 | ||
| 1531 | ||
| 1532 | ||
| 1533 | ||
| 1534 | ||
| 1535 | ||
| 1536 | ||
| 1537 | ||
| 1538 | ||
| 1539 | ||
| 1540 | ||
| 1541 | ||
| 1542 | ||
| 1543 | ||
| 1544 | ||
| 1545 | ||
| 1546 | ||
| 1547 | ||
| 1548 | ||
| 1549 | ||
| 1550 | ||
| 1551 | ||
| 1552 | ||
| 1553 | ||
| 1554 | ||
| 1555 | ||
| 1556 | ||
| 1557 | ||
| 1558 | ||
| 1559 | ||
| 1560 | ||
| 1561 | ||
| 1562 | ||
| 1563 | ||
| 1564 | ||
| 1565 | ||
| 1566 | ||
| 1567 | ||
| 1568 | ||
| 1569 | ||
| 1570 | ||
| 1571 | ||
| 1572 | ||
| 1573 | ||
| 1574 | ||
| 1575 | ||
| 1576 | ||
| 1577 | ||
| 1578 | ||
| 1579 | ||
| 1580 | ||
| 1581 | ||
| 1582 | ||
| 1583 | ||
| 1584 | ||
| 1585 | ||
| 1586 | ||
| 1587 | ||
| 1588 | ||
| 1589 | ||
| 1590 | ||
| 1591 | ||
| 1592 | ||
| 1593 | ||
| 1594 | ||
| 1595 | ||
| 1596 | ||
| 1597 | ||
| 1598 | ||
| 1599 | ||
| 1600 | ||
| 1601 | ||
| 1602 | ||
| 1603 | ||
| 1604 | ||
| 1605 | ||
| 1606 | ||
| 1607 | ||
| 1608 | ||
| 1609 | ||
| 1610 | ||
| 1611 | ||
| 1612 | ||
| 1613 | ||
| 1614 | ||
| 1615 | ||
| 1616 | ||
| 1617 | ||
| 1618 | 1489 | #ifdef __cplusplus |
| 1619 | 1490 | } |
| 1620 | 1491 | #endif |
| 1621 | #endif / |
|
| 1622 | ||
| 1492 | #endif /* _CSP11_H_ */ | |
| 1493 |
| r39 | r99 | |
|---|---|---|
| 36 | 36 | */ |
| 37 | 37 | |
| 38 | #if |
|
| 39 | # |
|
| 38 | #ifdef HAVE_CONFIG_H | |
| 39 | #include <config.h> | |
| 40 | 40 | #endif |
| 41 | ||
| 42 | ||
| 43 | 41 | #include <stdio.h> |
| 44 | 42 | #include <windows.h> |
| … | … | |
| 46 | 44 | #ifdef _MSC_VER |
| 47 | 45 | #include <cspdk.h> |
| 48 | #include |
|
| 46 | #include <missdef.h> | |
| 49 | 47 | #else |
| 50 | #include |
|
| 48 | #include <misscrypt.h> | |
| 51 | 49 | #endif |
| 52 | #include <rsaref/win32.h> | |
| 53 | #include <rsaref/pkcs11.h> | |
| 50 | #include <pkcs11.h> | |
| 54 | 51 | #include "pkcs11-helpers.h" |
| 55 | 52 | |
| … | … | |
| 112 | 109 | } |
| 113 | 110 | } |
| 114 | return |
|
| 111 | return 0; | |
| 115 | 112 | } |
| 116 | 113 |
| r39 | r99 | |
|---|---|---|
| 39 | 39 | |
| 40 | 40 | #ifndef _PKCS11_HELPERS_H_ |
| 41 | ||
| 42 | 41 | #define _PKCS11_HELPERS_H_ /**< pkcs11_helpers.h inclusion tag. */ |
| 43 | 42 |
| r60 | r99 | |
|---|---|---|
| 41 | 41 | */ |
| 42 | 42 | |
| 43 | #if |
|
| 44 | # |
|
| 43 | #ifdef HAVE_CONFIG_H | |
| 44 | #include <config.h> | |
| 45 | 45 | #endif |
| 46 | ||
| 47 | ||
| 48 | 46 | #include <stdio.h> |
| 49 | 47 | #include <windows.h> |
| … | … | |
| 52 | 50 | #ifdef _MSC_VER |
| 53 | 51 | #include <cspdk.h> |
| 54 | #include |
|
| 52 | #include <missdef.h> | |
| 55 | 53 | #else |
| 56 | #include |
|
| 54 | #include <misscrypt.h> | |
| 57 | 55 | #endif |
| 58 | #include <rsaref/win32.h> | |
| 59 | #include <rsaref/pkcs11.h> | |
| 56 | #include <pkcs11.h> | |
| 60 | 57 | #include "csp11.h" |
| 61 | 58 | #include "pkcs11-services.h" |
| … | … | |
| 75 | 72 | * \return True if the object can decrypt. |
| 76 | 73 | */ |
| 77 | PATTRIBUTE_FUNCTION_MACRO(DECRYPT, CK_BBOOL) |
|
| 74 | PATTRIBUTE_FUNCTION_MACRO(DECRYPT, CK_BBOOL) | |
| 78 | 75 | |
| 79 | 76 | /** \fn CK_BBOOL * getENCRYPT(CK_FUNCTION_LIST_PTR p11, PROV_CTX *pProvCtx, CK_OBJECT_HANDLE obj, CK_ULONG_PTR pulCount) |
| … | … | |
| 85 | 82 | * \return True if the object can decrypt. |
| 86 | 83 | */ |
| 87 | PATTRIBUTE_FUNCTION_MACRO(ENCRYPT, CK_BBOOL) |
|
| 84 | PATTRIBUTE_FUNCTION_MACRO(ENCRYPT, CK_BBOOL) | |
| 88 | 85 | |
| 89 | 86 | /** \fn CK_BBOOL * getEXTRACTABLE(CK_FUNCTION_LIST_PTR p11, PROV_CTX *pProvCtx, CK_OBJECT_HANDLE obj, CK_ULONG_PTR pulCount) |
| … | … | |
| 95 | 92 | * \return True if the object is extractable. |
| 96 | 93 | */ |
| 97 | PATTRIBUTE_FUNCTION_MACRO(EXTRACTABLE, CK_BBOOL) |
|
| 94 | PATTRIBUTE_FUNCTION_MACRO(EXTRACTABLE, CK_BBOOL) | |
| 98 | 95 | |
| 99 | 96 | /** \fn unsigned char * getID(CK_FUNCTION_LIST_PTR p11, PROV_CTX *pProvCtx, CK_OBJECT_HANDLE obj, CK_ULONG_PTR pulCount) |
| … | … | |
| 105 | 102 | * \return The Object ID. |
| 106 | 103 | */ |
| 107 | PATTRIBUTE_FUNCTION_MACRO(ID, unsigned char) |
|
| 104 | PATTRIBUTE_FUNCTION_MACRO(ID, unsigned char) | |
| 108 | 105 | |
| 109 | 106 | /** \fn CK_KEY_TYPE * getKEY_TYPE(CK_FUNCTION_LIST_PTR p11, PROV_CTX *pProvCtx,CK_OBJECT_HANDLE obj, CK_ULONG_PTR pulCount) |
| … | … | |
| 115 | 112 | * \return The Object ID. |
| 116 | 113 | */ |
| 117 | PATTRIBUTE_FUNCTION_MACRO(KEY_TYPE, CK_KEY_TYPE) |
|
| 114 | PATTRIBUTE_FUNCTION_MACRO(KEY_TYPE, CK_KEY_TYPE) | |
| 118 | 115 | |
| 119 | 116 | /** \fn CK_UTF8CHAR * getLABEL(CK_FUNCTION_LIST_PTR p11, PROV_CTX *pProvCtx, CK_OBJECT_HANDLE obj, CK_ULONG_PTR pulCount) |
| … | … | |
| 126 | 123 | * \return the object label. |
| 127 | 124 | */ |
| 128 | PATTRIBUTE_FUNCTION_MACRO(LABEL, CK_UTF8CHAR) |
|
| 125 | PATTRIBUTE_FUNCTION_MACRO(LABEL, CK_UTF8CHAR) | |
| 129 | 126 | |
| 130 | 127 | /** \fn unsigned char * getMODULUS(CK_FUNCTION_LIST_PTR p11, PROV_CTX *pProvCtx, CK_OBJECT_HANDLE obj, CK_ULONG_PTR pulCount) |
| … | … | |
| 136 | 133 | * \return The Object modulus. |
| 137 | 134 | */ |
| 138 | PATTRIBUTE_FUNCTION_MACRO(MODULUS, unsigned char) |
|
| 135 | PATTRIBUTE_FUNCTION_MACRO(MODULUS, unsigned char) | |
| 139 | 136 | |
| 140 | 137 | /** \fn CK_ULONG * getMODULUS_BITS(CK_FUNCTION_LIST_PTR p11, PROV_CTX *pProvCtx, CK_OBJECT_HANDLE obj, CK_ULONG_PTR pulCount) |
| … | … | |
| 146 | 143 | * \return The Object modulus length. |
| 147 | 144 | */ |
| 148 | PATTRIBUTE_FUNCTION_MACRO(MODULUS_BITS, CK_ULONG) |
|
| 145 | PATTRIBUTE_FUNCTION_MACRO(MODULUS_BITS, CK_ULONG) | |
| 149 | 146 | |
| 150 | 147 | /** \fn CK_BYTE * getPUBLIC_EXPONENT(CK_FUNCTION_LIST_PTR p11, PROV_CTX *pProvCtx, CK_OBJECT_HANDLE obj, CK_ULONG_PTR pulCount) |
| … | … | |
| 157 | 154 | * \return the object public exponent. |
| 158 | 155 | */ |
| 159 | PATTRIBUTE_FUNCTION_MACRO(PUBLIC_EXPONENT, CK_BYTE) |
|
| 156 | PATTRIBUTE_FUNCTION_MACRO(PUBLIC_EXPONENT, CK_BYTE) | |
| 160 | 157 | |
| 161 | 158 | /** \fn CK_BBOOL * getSIGN(CK_FUNCTION_LIST_PTR p11, PROV_CTX *pProvCtx, CK_OBJECT_HANDLE obj, CK_ULONG_PTR pulCount) |
| … | … | |
| 168 | 165 | * \return the object label. |
| 169 | 166 | */ |
| 170 | PATTRIBUTE_FUNCTION_MACRO(SIGN, CK_BBOOL) |
|
| 167 | PATTRIBUTE_FUNCTION_MACRO(SIGN, CK_BBOOL) | |
| 171 | 168 | |
| 172 | 169 | /** \fn CK_BYTE *getVALUE(CK_FUNCTION_LIST_PTR p11, PROV_CTX *pProvCtx, CK_OBJECT_HANDLE obj, CK_ULONG_PTR pulCount) |
| … | … | |
| 178 | 175 | * \return The Object value. |
| 179 | 176 | */ |
| 180 | PATTRIBUTE_FUNCTION_MACRO(VALUE, unsigned char) |
|
| 177 | PATTRIBUTE_FUNCTION_MACRO(VALUE, unsigned char) | |
| 181 | 178 | |
| 182 | 179 | BOOL keyObjectCanEncrypt(PROV_CTX *pProvCtx, CK_OBJECT_HANDLE hKey) |
| … | … | |
| 422 | 419 | /*hashLen = |
| 423 | 420 | * getHashLenFromcIdentifier(containerInfo.sigKeyHashAlg);*/ |
| 424 | if(hashLen |
|
| 421 | if(hashLen == 0) | |
| 425 | 422 | { |
| 426 | 423 | return FALSE; |
| … | … | |
| 562 | 559 | mechanism.mechanism = getMechFromcIdentifier(containerInfo.kxKeyHashAlg); |
| 563 | 560 | /*hashLen = getHashLenFromcIdentifier(containerInfo.kxKeyHashAlg);*/ |
| 564 | if(hashLen |
|
| 561 | if(hashLen == 0) | |
| 565 | 562 | { |
| 566 | 563 | return FALSE; |
| … | … | |
| 707 | 704 | |
| 708 | 705 | /** - Wrap Crosof Algid with PKCS #11 mechanism id.*/ |
| 709 | if(mechanism.mechanism |
|
| 706 | if(mechanism.mechanism == (CK_MECHANISM_TYPE)-1) | |
| 710 | 707 | { |
| 711 | 708 | return FALSE; |
| … | … | |
| 810 | 807 | hServiceInfo = pProvCtx->container.hServiceInformation; |
| 811 | 808 | /** - Fill structure info.*/ |
| 812 | / |
|
| 809 | /*pSigKey->signPrivateKey = privateKey;*/ | |
| 813 | 810 | pKeyInfo->hKey = publicKey; |
| 814 | 811 | |
| … | … | |
| 846 | 843 | memset(pPubExp,0, sizeof(DWORD)); |
| 847 | 844 | memcpy(pPubExp, pPublicExponent, 3); |
| 848 | / |
|
| 845 | /* *pPubExp = (*pPubExp)>>8; */ | |
| 849 | 846 | HeapFree(pProvCtx->heap, 0, pPublicExponent); |
| 850 | 847 | return TRUE; |
| … | … | |
| 975 | 972 | } |
| 976 | 973 | |
| 977 | / |
|
| 974 | /*rv = p11->C_WrapKey(hServiceInfo->hSession, );*/ | |
| 978 | 975 | |
| 979 | 976 | return FALSE; |
| … | … | |
| 991 | 988 | HANDLE *phKeyInformation, ALG_ID algId) |
| 992 | 989 | { |
| 993 | CK_OBJECT_HANDLE |
|
| 994 | CK_OBJECT_HANDLE |
|
| 990 | CK_OBJECT_HANDLE hPublicKey; /* Pointer to PKCS #11 Handle to the public key object.*/ | |
| 991 | CK_OBJECT_HANDLE hPrivateKey; /* Pointer to PKCS #11 Handle to the private key object. | |
| 995 | 992 | */ |
| 996 | 993 | PKCS11_KEY_INFO *pKeyInformation=NULL; /* PKCS11 key information.*/ |
| … | … | |
| 1009 | 1006 | } |
| 1010 | 1007 | /** - Call service specific key pair generation function.*/ |
| 1011 | if(PKCS11_genKeyPair(pProvCtx, modulusBits, |
|
| 1008 | if(PKCS11_genKeyPair(pProvCtx, modulusBits, &hPrivateKey, &hPublicKey)) | |
| 1012 | 1009 | { |
| 1013 | 1010 | /** - Allocate memory for pkcs11 key information structure.*/ |
| … | … | |
| 1020 | 1017 | } |
| 1021 | 1018 | /** - Fill key structure.*/ |
| 1022 | if(!fillP11Key(pProvCtx, |
|
| 1019 | if(!fillP11Key(pProvCtx, hPublicKey, pKeyInformation)) | |
| 1023 | 1020 | { |
| 1024 | 1021 | SetLastError(NTE_FAIL); |
| … | … | |
| 1066 | 1063 | PKCS11_SERVICE_INFO *hServiceInfo = NULL; /* Pointer to the key container structure. */ |
| 1067 | 1064 | CK_MECHANISM mechanism = { |
| 1068 | //CKM_RSA_X9_31, NULL, 0 }; /* Mechanism used in order to simple sign.*/ | |
| 1069 | //CKM_RSA_PKCS_PSS, NULL, 0 }; /* Mechanism used in order to simple sign.*/ | |
| 1070 | //CKM_RSA_9796, NULL, 0 }; /* Mechanism used in order to simple sign.*/ | |
| 1065 | #if 0 | |
| 1066 | CKM_RSA_X9_31, NULL, 0 }; /* Mechanism used in order to simple sign.*/ | |
| 1067 | CKM_RSA_PKCS_PSS, NULL, 0 }; /* Mechanism used in order to simple sign.*/ | |
| 1068 | CKM_RSA_9796, NULL, 0 }; /* Mechanism used in order to simple sign.*/ | |
| 1069 | #endif | |
| 1071 | 1070 | CKM_RSA_PKCS, NULL, 0 }; /* Mechanism used in order to simple sign.*/ |
| 1072 | //CKM_RSA_X_509, NULL, 0 }; /* Mechanism used in order to simple sign.*/ | |
| 1071 | #if 0 | |
| 1072 | CKM_RSA_X_509, NULL, 0 }; /* Mechanism used in order to simple sign.*/ | |
| 1073 | #endif | |
| 1073 | 1074 | char debug[100]; |
| 1074 | 1075 | |
| … | … | |
| 1703 | 1704 | return FALSE; |
| 1704 | 1705 | } |
| 1705 | ||
| 1706 | if(valueLenth<0) | |
| 1706 | ||
| 1707 | #if 0 | |
| 1708 | if(valueLenth < 0) | |
| 1707 | 1709 | { |
| 1708 | 1710 | return FALSE; |
| 1709 | 1711 | } |
| 1710 | ||
| 1712 | #endif | |
| 1711 | 1713 | } |
| 1712 | 1714 | /** - If objectValue is not NULL, this is the final call.*/ |
| … | … | |
| 2068 | 2070 | { |
| 2069 | 2071 | hashLen = getHashLenFromcIdentifier(containerInfo->sigKeyHashAlg); |
| 2070 | if(hashLen |
|
| 2072 | if(hashLen == 0) | |
| 2071 | 2073 | { |
| 2072 | 2074 | return FALSE; |
| … | … | |
| 2138 | 2140 | { |
| 2139 | 2141 | hashLen = getHashLenFromcIdentifier(containerInfo->kxKeyHashAlg); |
| 2140 | if(hashLen |
|
| 2142 | if(hashLen == 0) | |
| 2141 | 2143 | { |
| 2142 | 2144 | return FALSE; |
| … | … | |
| 2418 | 2420 | modulus = getMODULUS(p11, pProvCtx, hPublicKey, &idsNumber); |
| 2419 | 2421 | mechanism.mechanism = getMechFromcIdentifier(cIdentifier); |
| 2420 | if(mechanism.mechanism |
|
| 2422 | if(mechanism.mechanism == (CK_MECHANISM_TYPE)-1) | |
| 2421 | 2423 | { |
| 2422 | 2424 | return FALSE; |
| … | … | |
| 2593 | 2595 | char debug[100]; |
| 2594 | 2596 | |
| 2595 | |
|
| 2597 | WCHAR * dllName = L"opensc-pkcs11.dll"; | |
| 2596 | 2598 | |
| 2597 | 2599 | /** - Set cryptoki initialization arguments.*/ |
| … | … | |
| 2783 | 2785 | /* attribute*/ |
| 2784 | 2786 | /** - Set up ID attribute template.*/ |
| 2785 | //template[0].type = CKA_CLASS; | |
| 2786 | //objectClass = CKO_PRIVATE_KEY; | |
| 2787 | //template[0].pValue = &objectClass; | |
| 2788 | //template[0].ulValueLen = 0; | |
| 2789 | //template[0].ulValueLen = sizeof(objectClass); /*We want a public key | |
| 2790 | /* class object.*/ | |
| 2787 | #if 0 | |
| 2788 | template[0].type = CKA_CLASS; | |
| 2789 | objectClass = CKO_PRIVATE_KEY; | |
| 2790 | template[0].pValue = &objectClass; | |
| 2791 | template[0].ulValueLen = 0; | |
| 2792 | template[0].ulValueLen = sizeof(objectClass); /*We want a public key | |
| 2793 | class object.*/ | |
| 2794 | #endif | |
| 2791 | 2795 | /** \todo Filter key to sign. */ |
| 2792 | 2796 | template[1].type = CKA_SIGN; |
| … | … | |
| 2795 | 2799 | /** - Initiate signature key research.*/ |
| 2796 | 2800 | rv = p11->C_FindObjectsInit(hServiceInfo->hSession, template, 2); |
| 2797 | / |
|
| 2801 | /*rv = p11->C_FindObjectsInit(hServiceInfo->hSession, template, 1); */ | |
| 2798 | 2802 | if (rv != CKR_OK) |
| 2799 | 2803 | { |
| … | … | |
| 2842 | 2846 | CK_SLOT_ID slotId = NO_SLOT; /* The selected slot Id. */ |
| 2843 | 2847 | PKCS11_SERVICE_INFO *hServiceInfo = NULL; /* Pointer to the key container structure. */ |
| 2844 | // char *pin = NULL; /* Local pointer on the pin string. */ | |
| 2845 | //char *pin = "1234"; /* Local pointer on the pin string | |
| 2846 | //For testing purpose: 1234. */ | |
| 2848 | #if 0 | |
| 2849 | char *pin = NULL; /* Local pointer on the pin string. */ | |
| 2850 | char *pin = "1234"; /* Local pointer on the pin string | |
| 2851 | For testing purpose: 1234. */ | |
| 2852 | #endif | |
| 2847 | 2853 | |
| 2848 | 2854 | hServiceInfo = pProvCtx->container.hServiceInformation; |
| … | … | |
| 2892 | 2898 | CK_OBJECT_HANDLE signatureKey; /* Pointer to the key used to sign.*/ |
| 2893 | 2899 | CK_MECHANISM mechanism = { |
| 2894 | //CKM_RSA_X9_31, NULL, 0 }; /* Mechanism used in order to simple sign.*/ | |
| 2895 | //CKM_RSA_PKCS_PSS, NULL, 0 }; /* Mechanism used in order to simple sign.*/ | |
| 2896 | //CKM_RSA_9796, NULL, 0 }; /* Mechanism used in order to simple sign.*/ | |
| 2900 | #if 0 | |
| 2901 | CKM_RSA_X9_31, NULL, 0 }; /* Mechanism used in order to simple sign.*/ | |
| 2902 | CKM_RSA_PKCS_PSS, NULL, 0 }; /* Mechanism used in order to simple sign.*/ | |
| 2903 | CKM_RSA_9796, NULL, 0 }; /* Mechanism used in order to simple sign.*/ | |
| 2904 | #endif | |
| 2897 | 2905 | CKM_RSA_PKCS, NULL, 0 }; /* Mechanism used in order to simple sign.*/ |
| 2898 | //CKM_RSA_X_509, NULL, 0 }; /* Mechanism used in order to simple sign.*/ | |
| 2906 | #if 0 | |
| 2907 | CKM_RSA_X_509, NULL, 0 }; /* Mechanism used in order to simple sign.*/ | |
| 2908 | #endif | |
| 2899 | 2909 | char debug[100]; |
| 2900 | 2910 |
| r39 | r99 | |
|---|---|---|
| 51 | 51 | |
| 52 | 52 | #ifndef _PKCS11_SERVICES_H_ |
| 53 | ||
| 54 | 53 | #define _PKCS11_SERVICES_H_ /**< pkcs11_services.h inclusion tag. */ |
| 55 | 54 | |
| … | … | |
| 799 | 798 | BOOL validateKeySigPin(PROV_CTX provCtx, char *pin); |
| 800 | 799 | |
| 801 | #endif / |
|
| 802 | ||
| 800 | #endif /* _PKCS11_SERVICES_H_ */ | |
| 801 |
| r39 | r99 | |
|---|---|---|
| 1 | /* | |
| 1 | 2 | //{{NO_DEPENDENCIES}} |
| 2 | 3 | // Microsoft Developer Studio generated include file. |
| 3 | 4 | // Used by csp11.rc |
| 4 | 5 | // |
| 6 | */ | |
| 5 | 7 | #define IDS_CHV 1 |
| 6 | 8 | #define IDS_CHV_PROMPT 2 |
| … | … | |
| 43 | 45 | #define IDC_STATIC -1 |
| 44 | 46 | |
| 47 | /* | |
| 45 | 48 | // Next default values for new objects |
| 46 | // | |
| 49 | // | |
| 50 | */ | |
| 47 | 51 | #ifdef APSTUDIO_INVOKED |
| 48 | 52 | #ifndef APSTUDIO_READONLY_SYMBOLS |
| r39 | r99 | |
|---|---|---|
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | #ifdef HAVE_CONFIG_H | |
| 30 | #include <config.h> | |
| 31 | #endif | |
| 29 | 32 | #include <stdio.h> |
| 30 | 33 | #include <stdlib.h> |
| … | … | |
| 65 | 68 | wc.lpfnWndProc = DefWindowProc; |
| 66 | 69 | wc.hInstance = csp11hInstance; |
| 67 | wc.lpszClassName = |
|
| 68 | wc.lpszMenuName = |
|
| 70 | wc.lpszClassName = L"csp11GUI"; | |
| 71 | wc.lpszMenuName = L"MMenu"; | |
| 69 | 72 | wc.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 ); |
| 70 | 73 | wc.hIcon = NULL; /*LoadIcon( hInstance, MAKEINTRESOURCE( 100 ) );*/ |
| … | … | |
| 83 | 86 | /** - Create the main window.*/ |
| 84 | 87 | cspHWnd = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_TOPMOST, |
| 85 | |
|
| 86 | |
|
| 88 | L"csp11GUI", | |
| 89 | L"CSP #11 Graphical User Interface", | |
| 87 | 90 | WS_MINIMIZEBOX | |
| 88 | 91 | WS_SIZEBOX | |
| … | … | |
| 117 | 120 | /** - Dialog box initialization:*/ |
| 118 | 121 | case WM_INITDIALOG: |
| 119 | { / |
|
| 122 | { /* Save string pointer passed here */ | |
| 120 | 123 | SETPOINTER( hDlg, lParam ); |
| 121 | 124 | |
| 122 | if( lstrlen( (LP |
|
| 123 | SetWindowText( GetDlgItem( hDlg, 100 ), / |
|
| 124 | (LP |
|
| 125 | if( lstrlen( (LPWSTR)lParam ) ) /* If something is in the string */ | |
| 126 | SetWindowText( GetDlgItem( hDlg, 100 ), /* put it into the */ | |
| 127 | (LPWSTR)lParam ); /* edit control now */ | |
| 125 | 128 | SetFocus(hDlg); |
| 126 | 129 | LoadString(csp11hInstance, IDS_CHV_PROMPT, message, |
| … | … | |
| 138 | 141 | |
| 139 | 142 | case WM_COMMAND: |
| 140 | if( wParam == IDCANCEL ) / |
|
| 143 | if( wParam == IDCANCEL ) /* If Cancel is pressed, quit */ | |
| 141 | 144 | { |
| 142 | 145 | KILLPOINTER( hDlg ); |
| 143 | 146 | |
| 144 | EndDialog( hDlg, FALSE ); / |
|
| 147 | EndDialog( hDlg, FALSE ); /* Cause DialogBoxParam to return FALSE */ | |
| 145 | 148 | return( TRUE ); |
| 146 | 149 | } |
| 147 | 150 | if( wParam == IDOK ) |
| 148 | 151 | { |
| 149 | |
|
| 150 | if( ! GetDlgItemText( hDlg, 100, |
|
| 151 | break; / |
|
| 152 | / |
|
| 153 | lstrcpy( ( |
|
| 152 | WCHAR wszStr[ 128 ]; | |
| 153 | if( ! GetDlgItemText( hDlg, 100, wszStr, 128 ) ) /* If nothing in */ | |
| 154 | break; /* the edit control, quit */ | |
| 155 | /* Copy from here to pointer passed to WM_INITDIALOG */ | |
| 156 | lstrcpy( (WCHAR *)GETPOINTER( hDlg ), wszStr ); | |
| 154 | 157 | KILLPOINTER( hDlg ); |
| 155 | 158 | |
| 156 | EndDialog( hDlg, TRUE ); / |
|
| 159 | EndDialog( hDlg, TRUE ); /* Cause DialogBoxParam to return TRUE */ | |
| 157 | 160 | return( TRUE ); |
| 158 | 161 | } |
| … | … | |
| 172 | 175 | /** - Dialog box initialization:*/ |
| 173 | 176 | case WM_INITDIALOG: |
| 174 | { / |
|
| 177 | { /* Save string pointer passed here */ | |
| 175 | 178 | SetFocus(hDlg); |
| 176 | 179 | LoadString(csp11hInstance, IDS_BAD_PIN_MSG, message, |
| … | … | |
| 184 | 187 | |
| 185 | 188 | case WM_COMMAND: |
| 186 | if( wParam == IDOK ) / |
|
| 189 | if( wParam == IDOK ) /* If Cancel is pressed, quit */ | |
| 187 | 190 | { |
| 188 | 191 | KILLPOINTER( hDlg ); |
| 189 | 192 | |
| 190 | EndDialog( hDlg, TRUE ); / |
|
| 193 | EndDialog( hDlg, TRUE ); /* Cause DialogBoxParam to return FALSE */ | |
| 191 | 194 | return( TRUE ); |
| 192 | 195 | } |
| … | … | |
| 205 | 208 | /** - Dialog box initialization:*/ |
| 206 | 209 | case WM_INITDIALOG: |
| 207 | { / |
|
| 210 | { /* Save string pointer passed here */ | |
| 208 | 211 | SetFocus(hDlg); |
| 209 | 212 | LoadString(csp11hInstance, IDS_INVALID_PIN_MSG, message, |
| … | … | |
| 217 | 220 | |
| 218 | 221 | case WM_COMMAND: |
| 219 | if( wParam == IDOK ) / |
|
| 222 | if( wParam == IDOK ) /* If Cancel is pressed, quit */ | |
| 220 | 223 | { |
| 221 | 224 | KILLPOINTER( hDlg ); |
| 222 | 225 | |
| 223 | EndDialog( hDlg, TRUE ); / |
|
| 226 | EndDialog( hDlg, TRUE ); /* Cause DialogBoxParam to return FALSE */ | |
| 224 | 227 | return( TRUE ); |
| 225 | 228 | } |
| … | … | |
| 237 | 240 | /** - Dialog box initialization:*/ |
| 238 | 241 | case WM_INITDIALOG: |
| 239 | { / |
|
| 242 | { /* Save string pointer passed here */ | |
| 240 | 243 | SetFocus(hDlg); |
| 241 | 244 | LoadString(csp11hInstance, IDS_PIN_LOCKED_MSG, message, |
| … | … | |
| 249 | 252 | |
| 250 | 253 | case WM_COMMAND: |
| 251 | if( wParam == IDCANCEL ) / |
|
| 254 | if( wParam == IDCANCEL ) /* If Cancel is pressed, quit */ | |
| 252 | 255 | { |
| 253 | 256 | KILLPOINTER( hDlg ); |
| 254 | 257 | |
| 255 | EndDialog( hDlg, FALSE ); / |
|
| 258 | EndDialog( hDlg, FALSE ); /* Cause DialogBoxParam to return FALSE */ | |
| 256 | 259 | return( TRUE ); |
| 257 | 260 | } |
| 258 | 261 | if( wParam == ID_MB_UNLOCK ) |
| 259 | 262 | { |
| 260 | EndDialog( hDlg, TRUE ); / |
|
| 263 | EndDialog( hDlg, TRUE ); /* Cause DialogBoxParam to return TRUE */ | |
| 261 | 264 | return( TRUE ); |
| 262 | 265 | } |
| … | … | |
| 277 | 280 | /** - Dialog box initialization:*/ |
| 278 | 281 | case WM_INITDIALOG: |
| 279 | { / |
|
| 282 | { /* Save string pointer passed here */ | |
| 280 | 283 | SetFocus(hDlg); |
| 281 | 284 | LoadString(csp11hInstance, IDS_WRONG_CARD_MSG, message, |
| … | … | |
| 292 | 295 | |
| 293 | 296 | case WM_COMMAND: |
| 294 | if( wParam == IDCANCEL ) / |
|
| 297 | if( wParam == IDCANCEL ) /* If Cancel is pressed, quit */ | |
| 295 | 298 | { |
| 296 | 299 | KILLPOINTER( hDlg ); |
| 297 | 300 | |
| 298 | EndDialog( hDlg, FALSE ); / |
|
| 301 | EndDialog( hDlg, FALSE ); /* Cause DialogBoxParam to return FALSE */ | |
| 299 | 302 | return( TRUE ); |
| 300 | 303 | } |
| 301 | 304 | if( wParam == IDRETRY ) |
| 302 | 305 | { |
| 303 | EndDialog( hDlg, TRUE ); / |
|
| 306 | EndDialog( hDlg, TRUE ); /* Cause DialogBoxParam to return TRUE */ | |
| 304 | 307 | return( TRUE ); |
| 305 | 308 | } |
| … | … | |
| 312 | 315 | { |
| 313 | 316 | int validPIN = 0; /* If a validpin is found.*/ |
| 314 | |
|
| 317 | WCHAR wszText[9]; | |
| 315 | 318 | int i; /* iterator*/ |
| 316 | 319 | BOOL badPin; |
| 317 | 320 | |
| 318 | lstrcpy( |
|
| 321 | lstrcpy(wszText, L""); | |
| 319 | 322 | |
| 320 | 323 | if(csp11hInstance == NULL) |
| … | … | |
| 346 | 349 | badPin = FALSE; |
| 347 | 350 | if(DialogBoxParam(csp11hInstance, MAKEINTRESOURCE( 10000 ), *pHWnd, |
| 348 | InputDlgProc, (LPARAM) |
|
| 351 | InputDlgProc, (LPARAM)wszText ) ) | |
| 349 | 352 | { |
| 350 | 353 | |
| 351 | if((lstrlen( |
|
| 354 | if((lstrlen(wszText)>8) || !lstrlen(wszText) || (lstrlen(wszText)<4)) | |
| 352 | 355 | { |
| 353 | 356 | badPin = TRUE; |
| 354 | 357 | } |
| 355 | for(i=0; i<lstrlen( |
|
| 356 | { |
|
| 357 | if(( |
|
| 358 | for(i=0; i<lstrlen(wszText);i++) | |
| 359 | { | |
| 360 | if((wszText[i]>L'9') || (wszText[i]<L'0')) | |
| 358 | 361 | { |
| 359 | 362 | badPin = TRUE; |
| … | … | |
| 366 | 369 | else |
| 367 | 370 | { |
| 368 | strncpy(pin, szText, 8); | |
| 371 | int i; | |
| 372 | for (i=0;i<8;i++) { | |
| 373 | pin[i] = '0' + (wszText[i] - L'0'); | |
| 374 | } | |
| 369 | 375 | return TRUE; |
| 370 | 376 | } |
| r39 | r99 | |
|---|---|---|
| 1 | 1 | CSPDK_INC = ..\..\CSPDK\SDKINC |
| 2 | COPTS = /Zi /MD /nologo /D_WIN32_WINNT=0x0400 /I$(CSPDK_INC) |
|
| 2 | COPTS = /Zi /MD /nologo /D_WIN32_WINNT=0x0400 /I$(CSPDK_INC) /I../include | |
| 3 | 3 | LINKFLAGS = /DEBUG /NOLOGO /INCREMENTAL:NO /MACHINE:IX86 |
| 4 | 4 | LIBS= user32.lib gdi32.lib advapi32.lib |
| r39 | r99 | |
|---|---|---|
| 39 | 39 | #ifdef _MSC_VER |
| 40 | 40 | #include <cspdk.h> |
| 41 | #else | |
| 42 | #include <misscrypt.h> | |
| 41 | 43 | #endif |
| 42 | 44 |
| r39 | r99 | |
|---|---|---|
| 1 | 1 | CSPDK_INC = ..\..\CSPDK\SDKINC |
| 2 | COPTS = /Zi /MD /nologo /D_WIN32_WINNT=0x0400 /I$(CSPDK_INC) |
|
| 2 | COPTS = /Zi /MD /nologo /D_WIN32_WINNT=0x0400 /I$(CSPDK_INC) /I../include | |
| 3 | 3 | LINKFLAGS = /DEBUG /NOLOGO /INCREMENTAL:NO /MACHINE:IX86 |
| 4 | 4 | LIBS= crypt32.lib |
| r39 | r99 | |
|---|---|---|
| 40 | 40 | #include <windows.h> |
| 41 | 41 | #include <wincrypt.h> |
| 42 | #ifndef _MSC_VER | |
| 43 | #include <misscrypt.h> | |
| 44 | #endif | |
| 42 | 45 | |
| 43 | 46 | #define ENTRYPOINT APIENTRY /**< define the WinMain type.*/ |