1 | /* |
---|
2 | * Estonian ID card plugin for web browsers |
---|
3 | * |
---|
4 | * Copyright (C) 2010-2011 Codeborne <info@codeborne.com> |
---|
5 | * |
---|
6 | * This is free software; you can redistribute it and/or |
---|
7 | * modify it under the terms of the GNU Lesser General Public |
---|
8 | * License as published by the Free Software Foundation; either |
---|
9 | * version 2.1 of the License, or (at your option) any later version. |
---|
10 | * |
---|
11 | * This software is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | * Lesser General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU Lesser General Public |
---|
17 | * License along with this library; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
---|
19 | * |
---|
20 | */ |
---|
21 | |
---|
22 | #include "cert_dialog_win.h" |
---|
23 | |
---|
24 | BOOL isCardInReader(PCCERT_CONTEXT certContext) { |
---|
25 | #ifndef WIN_XP |
---|
26 | DWORD flags = CRYPT_ACQUIRE_ONLY_NCRYPT_KEY_FLAG|CRYPT_ACQUIRE_COMPARE_KEY_FLAG|CRYPT_ACQUIRE_SILENT_FLAG; |
---|
27 | NCRYPT_KEY_HANDLE key = 0; |
---|
28 | DWORD spec = 0; |
---|
29 | BOOL ncrypt = FALSE; |
---|
30 | CryptAcquireCertificatePrivateKey(certContext, flags, 0, &key, &spec, &ncrypt); |
---|
31 | if(!key) { |
---|
32 | return FALSE; |
---|
33 | } |
---|
34 | if(ncrypt) { |
---|
35 | NCryptFreeObject(key); |
---|
36 | } |
---|
37 | #endif |
---|
38 | return TRUE; |
---|
39 | } |
---|
40 | |
---|
41 | BOOL WINAPI filter_proc(PCCERT_CONTEXT certContext, BOOL *pfInitialSelectedCert, void *pvCallbackData) { |
---|
42 | BYTE keyUsage; |
---|
43 | CertGetIntendedKeyUsage(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, certContext->pCertInfo, &keyUsage, 1); |
---|
44 | if (!(keyUsage & CERT_NON_REPUDIATION_KEY_USAGE)) { |
---|
45 | return FALSE; |
---|
46 | } |
---|
47 | if(CertVerifyTimeValidity(NULL, certContext->pCertInfo) != 0) { |
---|
48 | return FALSE; |
---|
49 | } |
---|
50 | |
---|
51 | return isCardInReader(certContext); |
---|
52 | } |
---|