ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

main.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2008 Maarten Lankhorst
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00017  */
00018 
00019 #define NONAMELESSUNION
00020 
00021 #include "config.h"
00022 
00023 #include <stdarg.h>
00024 
00025 #include "windef.h"
00026 #include "winbase.h"
00027 #include "winnls.h"
00028 #include "winreg.h"
00029 #include "wincrypt.h"
00030 #include "wintrust.h"
00031 #include "winuser.h"
00032 #include "objbase.h"
00033 #include "cryptdlg.h"
00034 #include "cryptuiapi.h"
00035 #include "cryptres.h"
00036 #include "wine/unicode.h"
00037 #include "wine/debug.h"
00038 
00039 WINE_DEFAULT_DEBUG_CHANNEL(cryptdlg);
00040 
00041 static HINSTANCE hInstance;
00042 
00043 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
00044 {
00045     TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
00046 
00047     switch (fdwReason)
00048     {
00049         case DLL_WINE_PREATTACH:
00050             return FALSE;    /* prefer native version */
00051         case DLL_PROCESS_ATTACH:
00052             DisableThreadLibraryCalls(hinstDLL);
00053             hInstance = hinstDLL;
00054             break;
00055         case DLL_PROCESS_DETACH:
00056             break;
00057         default:
00058             break;
00059     }
00060     return TRUE;
00061 }
00062 
00063 /***********************************************************************
00064  *      GetFriendlyNameOfCertA (CRYPTDLG.@)
00065  */
00066 DWORD WINAPI GetFriendlyNameOfCertA(PCCERT_CONTEXT pccert, LPSTR pchBuffer,
00067                              DWORD cchBuffer)
00068 {
00069     return CertGetNameStringA(pccert, CERT_NAME_FRIENDLY_DISPLAY_TYPE, 0, NULL,
00070      pchBuffer, cchBuffer);
00071 }
00072 
00073 /***********************************************************************
00074  *      GetFriendlyNameOfCertW (CRYPTDLG.@)
00075  */
00076 DWORD WINAPI GetFriendlyNameOfCertW(PCCERT_CONTEXT pccert, LPWSTR pchBuffer,
00077                              DWORD cchBuffer)
00078 {
00079     return CertGetNameStringW(pccert, CERT_NAME_FRIENDLY_DISPLAY_TYPE, 0, NULL,
00080      pchBuffer, cchBuffer);
00081 }
00082 
00083 /***********************************************************************
00084  *      CertTrustInit (CRYPTDLG.@)
00085  */
00086 HRESULT WINAPI CertTrustInit(CRYPT_PROVIDER_DATA *pProvData)
00087 {
00088     HRESULT ret = S_FALSE;
00089 
00090     TRACE("(%p)\n", pProvData);
00091 
00092     if (pProvData->padwTrustStepErrors &&
00093      !pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_WVTINIT])
00094         ret = S_OK;
00095     TRACE("returning %08x\n", ret);
00096     return ret;
00097 }
00098 
00099 /***********************************************************************
00100  *      CertTrustCertPolicy (CRYPTDLG.@)
00101  */
00102 BOOL WINAPI CertTrustCertPolicy(CRYPT_PROVIDER_DATA *pProvData, DWORD idxSigner, BOOL fCounterSignerChain, DWORD idxCounterSigner)
00103 {
00104     FIXME("(%p, %d, %s, %d)\n", pProvData, idxSigner, fCounterSignerChain ? "TRUE" : "FALSE", idxCounterSigner);
00105     return FALSE;
00106 }
00107 
00108 /***********************************************************************
00109  *      CertTrustCleanup (CRYPTDLG.@)
00110  */
00111 HRESULT WINAPI CertTrustCleanup(CRYPT_PROVIDER_DATA *pProvData)
00112 {
00113     FIXME("(%p)\n", pProvData);
00114     return E_NOTIMPL;
00115 }
00116 
00117 static BOOL CRYPTDLG_CheckOnlineCRL(void)
00118 {
00119     static const WCHAR policyFlagsKey[] = { 'S','o','f','t','w','a','r','e',
00120      '\\','M','i','c','r','o','s','o','f','t','\\','C','r','y','p','t','o','g',
00121      'r','a','p','h','y','\\','{','7','8','0','1','e','b','d','0','-','c','f',
00122      '4','b','-','1','1','d','0','-','8','5','1','f','-','0','0','6','0','9',
00123      '7','9','3','8','7','e','a','}',0 };
00124     static const WCHAR policyFlags[] = { 'P','o','l','i','c','y','F','l','a',
00125      'g','s',0 };
00126     HKEY key;
00127     BOOL ret = FALSE;
00128 
00129     if (!RegOpenKeyExW(HKEY_LOCAL_MACHINE, policyFlagsKey, 0, KEY_READ, &key))
00130     {
00131         DWORD type, flags, size = sizeof(flags);
00132 
00133         if (!RegQueryValueExW(key, policyFlags, NULL, &type, (BYTE *)&flags,
00134          &size) && type == REG_DWORD)
00135         {
00136             /* The flag values aren't defined in any header I'm aware of, but
00137              * this value is well documented on the net.
00138              */
00139             if (flags & 0x00010000)
00140                 ret = TRUE;
00141         }
00142         RegCloseKey(key);
00143     }
00144     return ret;
00145 }
00146 
00147 /* Returns TRUE if pCert is not in the Disallowed system store, or FALSE if it
00148  * is.
00149  */
00150 static BOOL CRYPTDLG_IsCertAllowed(PCCERT_CONTEXT pCert)
00151 {
00152     BOOL ret;
00153     BYTE hash[20];
00154     DWORD size = sizeof(hash);
00155 
00156     if ((ret = CertGetCertificateContextProperty(pCert,
00157      CERT_SIGNATURE_HASH_PROP_ID, hash, &size)))
00158     {
00159         static const WCHAR disallowedW[] =
00160          { 'D','i','s','a','l','l','o','w','e','d',0 };
00161         HCERTSTORE disallowed = CertOpenStore(CERT_STORE_PROV_SYSTEM_W,
00162          X509_ASN_ENCODING, 0, CERT_SYSTEM_STORE_CURRENT_USER, disallowedW);
00163 
00164         if (disallowed)
00165         {
00166             PCCERT_CONTEXT found = CertFindCertificateInStore(disallowed,
00167              X509_ASN_ENCODING, 0, CERT_FIND_SIGNATURE_HASH, hash, NULL);
00168 
00169             if (found)
00170             {
00171                 ret = FALSE;
00172                 CertFreeCertificateContext(found);
00173             }
00174             CertCloseStore(disallowed, 0);
00175         }
00176     }
00177     return ret;
00178 }
00179 
00180 static DWORD CRYPTDLG_TrustStatusToConfidence(DWORD errorStatus)
00181 {
00182     DWORD confidence = 0;
00183 
00184     confidence = 0;
00185     if (!(errorStatus & CERT_TRUST_IS_NOT_SIGNATURE_VALID))
00186         confidence |= CERT_CONFIDENCE_SIG;
00187     if (!(errorStatus & CERT_TRUST_IS_NOT_TIME_VALID))
00188         confidence |= CERT_CONFIDENCE_TIME;
00189     if (!(errorStatus & CERT_TRUST_IS_NOT_TIME_NESTED))
00190         confidence |= CERT_CONFIDENCE_TIMENEST;
00191     return confidence;
00192 }
00193 
00194 static BOOL CRYPTDLG_CopyChain(CRYPT_PROVIDER_DATA *data,
00195  PCCERT_CHAIN_CONTEXT chain)
00196 {
00197     BOOL ret;
00198     CRYPT_PROVIDER_SGNR signer;
00199     PCERT_SIMPLE_CHAIN simpleChain = chain->rgpChain[0];
00200     DWORD i;
00201 
00202     memset(&signer, 0, sizeof(signer));
00203     signer.cbStruct = sizeof(signer);
00204     ret = data->psPfns->pfnAddSgnr2Chain(data, FALSE, 0, &signer);
00205     if (ret)
00206     {
00207         CRYPT_PROVIDER_SGNR *sgnr = WTHelperGetProvSignerFromChain(data, 0,
00208          FALSE, 0);
00209 
00210         if (sgnr)
00211         {
00212             sgnr->dwError = simpleChain->TrustStatus.dwErrorStatus;
00213             sgnr->pChainContext = CertDuplicateCertificateChain(chain);
00214         }
00215         else
00216             ret = FALSE;
00217         for (i = 0; ret && i < simpleChain->cElement; i++)
00218         {
00219             ret = data->psPfns->pfnAddCert2Chain(data, 0, FALSE, 0,
00220              simpleChain->rgpElement[i]->pCertContext);
00221             if (ret)
00222             {
00223                 CRYPT_PROVIDER_CERT *cert;
00224 
00225                 if ((cert = WTHelperGetProvCertFromChain(sgnr, i)))
00226                 {
00227                     CERT_CHAIN_ELEMENT *element = simpleChain->rgpElement[i];
00228 
00229                     cert->dwConfidence = CRYPTDLG_TrustStatusToConfidence(
00230                      element->TrustStatus.dwErrorStatus);
00231                     cert->dwError = element->TrustStatus.dwErrorStatus;
00232                     cert->pChainElement = element;
00233                 }
00234                 else
00235                     ret = FALSE;
00236             }
00237         }
00238     }
00239     return ret;
00240 }
00241 
00242 static CERT_VERIFY_CERTIFICATE_TRUST *CRYPTDLG_GetVerifyData(
00243  CRYPT_PROVIDER_DATA *data)
00244 {
00245     CERT_VERIFY_CERTIFICATE_TRUST *pCert = NULL;
00246 
00247     /* This should always be true, but just in case the calling function is
00248      * called directly:
00249      */
00250     if (data->pWintrustData->dwUnionChoice == WTD_CHOICE_BLOB &&
00251      data->pWintrustData->u.pBlob && data->pWintrustData->u.pBlob->cbMemObject ==
00252      sizeof(CERT_VERIFY_CERTIFICATE_TRUST) &&
00253      data->pWintrustData->u.pBlob->pbMemObject)
00254          pCert = (CERT_VERIFY_CERTIFICATE_TRUST *)
00255           data->pWintrustData->u.pBlob->pbMemObject;
00256     return pCert;
00257 }
00258 
00259 static HCERTCHAINENGINE CRYPTDLG_MakeEngine(CERT_VERIFY_CERTIFICATE_TRUST *cert)
00260 {
00261     HCERTCHAINENGINE engine = NULL;
00262     HCERTSTORE root = NULL, trust = NULL;
00263     DWORD i;
00264 
00265     if (cert->cRootStores)
00266     {
00267         root = CertOpenStore(CERT_STORE_PROV_COLLECTION, 0, 0,
00268          CERT_STORE_CREATE_NEW_FLAG, NULL);
00269         if (root)
00270         {
00271             for (i = 0; i < cert->cRootStores; i++)
00272                 CertAddStoreToCollection(root, cert->rghstoreRoots[i], 0, 0);
00273         }
00274     }
00275     if (cert->cTrustStores)
00276     {
00277         trust = CertOpenStore(CERT_STORE_PROV_COLLECTION, 0, 0,
00278          CERT_STORE_CREATE_NEW_FLAG, NULL);
00279         if (root)
00280         {
00281             for (i = 0; i < cert->cTrustStores; i++)
00282                 CertAddStoreToCollection(trust, cert->rghstoreTrust[i], 0, 0);
00283         }
00284     }
00285     if (cert->cRootStores || cert->cStores || cert->cTrustStores)
00286     {
00287         CERT_CHAIN_ENGINE_CONFIG config;
00288 
00289         memset(&config, 0, sizeof(config));
00290         config.cbSize = sizeof(config);
00291         config.hRestrictedRoot = root;
00292         config.hRestrictedTrust = trust;
00293         config.cAdditionalStore = cert->cStores;
00294         config.rghAdditionalStore = cert->rghstoreCAs;
00295         config.hRestrictedRoot = root;
00296         CertCreateCertificateChainEngine(&config, &engine);
00297         CertCloseStore(root, 0);
00298         CertCloseStore(trust, 0);
00299     }
00300     return engine;
00301 }
00302 
00303 /***********************************************************************
00304  *      CertTrustFinalPolicy (CRYPTDLG.@)
00305  */
00306 HRESULT WINAPI CertTrustFinalPolicy(CRYPT_PROVIDER_DATA *data)
00307 {
00308     BOOL ret;
00309     DWORD err = S_OK;
00310     CERT_VERIFY_CERTIFICATE_TRUST *pCert = CRYPTDLG_GetVerifyData(data);
00311 
00312     TRACE("(%p)\n", data);
00313 
00314     if (data->pWintrustData->dwUIChoice != WTD_UI_NONE)
00315         FIXME("unimplemented for UI choice %d\n",
00316          data->pWintrustData->dwUIChoice);
00317     if (pCert)
00318     {
00319         DWORD flags = 0;
00320         CERT_CHAIN_PARA chainPara;
00321         HCERTCHAINENGINE engine;
00322 
00323         memset(&chainPara, 0, sizeof(chainPara));
00324         chainPara.cbSize = sizeof(chainPara);
00325         if (CRYPTDLG_CheckOnlineCRL())
00326             flags |= CERT_CHAIN_REVOCATION_CHECK_END_CERT;
00327         engine = CRYPTDLG_MakeEngine(pCert);
00328         GetSystemTimeAsFileTime(&data->sftSystemTime);
00329         ret = CRYPTDLG_IsCertAllowed(pCert->pccert);
00330         if (ret)
00331         {
00332             PCCERT_CHAIN_CONTEXT chain;
00333 
00334             ret = CertGetCertificateChain(engine, pCert->pccert,
00335              &data->sftSystemTime, NULL, &chainPara, flags, NULL, &chain);
00336             if (ret)
00337             {
00338                 if (chain->cChain != 1)
00339                 {
00340                     FIXME("unimplemented for more than 1 simple chain\n");
00341                     err = TRUST_E_SUBJECT_FORM_UNKNOWN;
00342                     ret = FALSE;
00343                 }
00344                 else if ((ret = CRYPTDLG_CopyChain(data, chain)))
00345                 {
00346                     if (CertVerifyTimeValidity(&data->sftSystemTime,
00347                      pCert->pccert->pCertInfo))
00348                     {
00349                         ret = FALSE;
00350                         err = CERT_E_EXPIRED;
00351                     }
00352                 }
00353                 else
00354                     err = TRUST_E_SYSTEM_ERROR;
00355                 CertFreeCertificateChain(chain);
00356             }
00357             else
00358                 err = TRUST_E_SUBJECT_NOT_TRUSTED;
00359         }
00360         CertFreeCertificateChainEngine(engine);
00361     }
00362     else
00363     {
00364         ret = FALSE;
00365         err = TRUST_E_NOSIGNATURE;
00366     }
00367     /* Oddly, native doesn't set the error in the trust step error location,
00368      * probably because this action is more advisory than anything else.
00369      * Instead it stores it as the final error, but the function "succeeds" in
00370      * any case.
00371      */
00372     if (!ret)
00373         data->dwFinalError = err;
00374     TRACE("returning %d (%08x)\n", S_OK, data->dwFinalError);
00375     return S_OK;
00376 }
00377 
00378 /***********************************************************************
00379  *      CertViewPropertiesA (CRYPTDLG.@)
00380  */
00381 BOOL WINAPI CertViewPropertiesA(CERT_VIEWPROPERTIES_STRUCT_A *info)
00382 {
00383     CERT_VIEWPROPERTIES_STRUCT_W infoW;
00384     LPWSTR title = NULL;
00385     BOOL ret;
00386 
00387     TRACE("(%p)\n", info);
00388 
00389     memcpy(&infoW, info, sizeof(infoW));
00390     if (info->szTitle)
00391     {
00392         int len = MultiByteToWideChar(CP_ACP, 0, info->szTitle, -1, NULL, 0);
00393 
00394         title = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
00395         if (title)
00396         {
00397             MultiByteToWideChar(CP_ACP, 0, info->szTitle, -1, title, len);
00398             infoW.szTitle = title;
00399         }
00400         else
00401         {
00402             ret = FALSE;
00403             goto error;
00404         }
00405     }
00406     ret = CertViewPropertiesW(&infoW);
00407     HeapFree(GetProcessHeap(), 0, title);
00408 error:
00409     return ret;
00410 }
00411 
00412 /***********************************************************************
00413  *      CertViewPropertiesW (CRYPTDLG.@)
00414  */
00415 BOOL WINAPI CertViewPropertiesW(CERT_VIEWPROPERTIES_STRUCT_W *info)
00416 {
00417     static GUID cert_action_verify = CERT_CERTIFICATE_ACTION_VERIFY;
00418     CERT_VERIFY_CERTIFICATE_TRUST trust;
00419     WINTRUST_BLOB_INFO blob;
00420     WINTRUST_DATA wtd;
00421     LONG err;
00422     BOOL ret;
00423 
00424     TRACE("(%p)\n", info);
00425 
00426     memset(&trust, 0, sizeof(trust));
00427     trust.cbSize = sizeof(trust);
00428     trust.pccert = info->pCertContext;
00429     trust.cRootStores = info->cRootStores;
00430     trust.rghstoreRoots = info->rghstoreRoots;
00431     trust.cStores = info->cStores;
00432     trust.rghstoreCAs = info->rghstoreCAs;
00433     trust.cTrustStores = info->cTrustStores;
00434     trust.rghstoreTrust = info->rghstoreTrust;
00435     memset(&blob, 0, sizeof(blob));
00436     blob.cbStruct = sizeof(blob);
00437     blob.cbMemObject = sizeof(trust);
00438     blob.pbMemObject = (BYTE *)&trust;
00439     memset(&wtd, 0, sizeof(wtd));
00440     wtd.cbStruct = sizeof(wtd);
00441     wtd.dwUIChoice = WTD_UI_NONE;
00442     wtd.dwUnionChoice = WTD_CHOICE_BLOB;
00443     wtd.u.pBlob = &blob;
00444     wtd.dwStateAction = WTD_STATEACTION_VERIFY;
00445     err = WinVerifyTrust(NULL, &cert_action_verify, &wtd);
00446     if (err == ERROR_SUCCESS)
00447     {
00448         CRYPTUI_VIEWCERTIFICATE_STRUCTW uiInfo;
00449         BOOL propsChanged = FALSE;
00450 
00451         memset(&uiInfo, 0, sizeof(uiInfo));
00452         uiInfo.dwSize = sizeof(uiInfo);
00453         uiInfo.hwndParent = info->hwndParent;
00454         uiInfo.dwFlags =
00455          CRYPTUI_DISABLE_ADDTOSTORE | CRYPTUI_ENABLE_EDITPROPERTIES;
00456         uiInfo.szTitle = info->szTitle;
00457         uiInfo.pCertContext = info->pCertContext;
00458         uiInfo.cPurposes = info->cArrayPurposes;
00459         uiInfo.rgszPurposes = (LPCSTR *)info->arrayPurposes;
00460         uiInfo.u.hWVTStateData = wtd.hWVTStateData;
00461         uiInfo.fpCryptProviderDataTrustedUsage = TRUE;
00462         uiInfo.cPropSheetPages = info->cArrayPropSheetPages;
00463         uiInfo.rgPropSheetPages = info->arrayPropSheetPages;
00464         uiInfo.nStartPage = info->nStartPage;
00465         ret = CryptUIDlgViewCertificateW(&uiInfo, &propsChanged);
00466         wtd.dwStateAction = WTD_STATEACTION_CLOSE;
00467         WinVerifyTrust(NULL, &cert_action_verify, &wtd);
00468     }
00469     else
00470         ret = FALSE;
00471     return ret;
00472 }
00473 
00474 static BOOL CRYPT_FormatHexString(const BYTE *pbEncoded, DWORD cbEncoded,
00475  WCHAR *str, DWORD *pcchStr)
00476 {
00477     BOOL ret;
00478     DWORD charsNeeded;
00479 
00480     if (cbEncoded)
00481         charsNeeded = (cbEncoded * 3);
00482     else
00483         charsNeeded = 1;
00484     if (!str)
00485     {
00486         *pcchStr = charsNeeded;
00487         ret = TRUE;
00488     }
00489     else if (*pcchStr < charsNeeded)
00490     {
00491         *pcchStr = charsNeeded;
00492         SetLastError(ERROR_MORE_DATA);
00493         ret = FALSE;
00494     }
00495     else
00496     {
00497         static const WCHAR fmt[] = { '%','0','2','x',' ',0 };
00498         static const WCHAR endFmt[] = { '%','0','2','x',0 };
00499         DWORD i;
00500         LPWSTR ptr = str;
00501 
00502         *pcchStr = charsNeeded;
00503         if (cbEncoded)
00504         {
00505             for (i = 0; i < cbEncoded; i++)
00506             {
00507                 if (i < cbEncoded - 1)
00508                     ptr += sprintfW(ptr, fmt, pbEncoded[i]);
00509                 else
00510                     ptr += sprintfW(ptr, endFmt, pbEncoded[i]);
00511             }
00512         }
00513         else
00514             *ptr = 0;
00515         ret = TRUE;
00516     }
00517     return ret;
00518 }
00519 
00520 static const WCHAR indent[] = { ' ',' ',' ',' ',' ',0 };
00521 static const WCHAR colonCrlf[] = { ':','\r','\n',0 };
00522 static const WCHAR colonSpace[] = { ':',' ',0 };
00523 static const WCHAR crlf[] = { '\r','\n',0 };
00524 static const WCHAR commaSep[] = { ',',' ',0 };
00525 
00526 static BOOL CRYPT_FormatCPS(DWORD dwCertEncodingType,
00527  DWORD dwFormatStrType, const BYTE *pbEncoded, DWORD cbEncoded,
00528  WCHAR *str, DWORD *pcchStr)
00529 {
00530     BOOL ret;
00531     DWORD size, charsNeeded = 1;
00532     CERT_NAME_VALUE *cpsValue;
00533 
00534     if ((ret = CryptDecodeObjectEx(dwCertEncodingType, X509_UNICODE_ANY_STRING,
00535      pbEncoded, cbEncoded, CRYPT_DECODE_ALLOC_FLAG, NULL, &cpsValue, &size)))
00536     {
00537         LPCWSTR sep;
00538         DWORD sepLen;
00539 
00540         if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
00541             sep = crlf;
00542         else
00543             sep = commaSep;
00544 
00545         sepLen = strlenW(sep);
00546 
00547         if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
00548         {
00549             charsNeeded += 3 * strlenW(indent);
00550             if (str && *pcchStr >= charsNeeded)
00551             {
00552                 strcpyW(str, indent);
00553                 str += strlenW(indent);
00554                 strcpyW(str, indent);
00555                 str += strlenW(indent);
00556                 strcpyW(str, indent);
00557                 str += strlenW(indent);
00558             }
00559         }
00560         charsNeeded += cpsValue->Value.cbData / sizeof(WCHAR);
00561         if (str && *pcchStr >= charsNeeded)
00562         {
00563             strcpyW(str, (LPWSTR)cpsValue->Value.pbData);
00564             str += cpsValue->Value.cbData / sizeof(WCHAR);
00565         }
00566         charsNeeded += sepLen;
00567         if (str && *pcchStr >= charsNeeded)
00568         {
00569             strcpyW(str, sep);
00570             str += sepLen;
00571         }
00572         LocalFree(cpsValue);
00573         if (!str)
00574             *pcchStr = charsNeeded;
00575         else if (*pcchStr < charsNeeded)
00576         {
00577             *pcchStr = charsNeeded;
00578             SetLastError(ERROR_MORE_DATA);
00579             ret = FALSE;
00580         }
00581         else
00582             *pcchStr = charsNeeded;
00583     }
00584     return ret;
00585 }
00586 
00587 static BOOL CRYPT_FormatUserNotice(DWORD dwCertEncodingType,
00588  DWORD dwFormatStrType, const BYTE *pbEncoded, DWORD cbEncoded,
00589  WCHAR *str, DWORD *pcchStr)
00590 {
00591     BOOL ret;
00592     DWORD size, charsNeeded = 1;
00593     CERT_POLICY_QUALIFIER_USER_NOTICE *notice;
00594 
00595     if ((ret = CryptDecodeObjectEx(dwCertEncodingType,
00596      X509_PKIX_POLICY_QUALIFIER_USERNOTICE, pbEncoded, cbEncoded,
00597      CRYPT_DECODE_ALLOC_FLAG, NULL, &notice, &size)))
00598     {
00599         static const WCHAR numFmt[] = { '%','d',0 };
00600         CERT_POLICY_QUALIFIER_NOTICE_REFERENCE *pNoticeRef =
00601          notice->pNoticeReference;
00602         LPCWSTR headingSep, sep;
00603         DWORD headingSepLen, sepLen;
00604         LPWSTR noticeRef, organization, noticeNum, noticeText;
00605         DWORD noticeRefLen, organizationLen, noticeNumLen, noticeTextLen;
00606         WCHAR noticeNumStr[11];
00607 
00608         noticeRefLen = LoadStringW(hInstance, IDS_NOTICE_REF,
00609          (LPWSTR)&noticeRef, 0);
00610         organizationLen = LoadStringW(hInstance, IDS_ORGANIZATION,
00611          (LPWSTR)&organization, 0);
00612         noticeNumLen = LoadStringW(hInstance, IDS_NOTICE_NUM,
00613          (LPWSTR)&noticeNum, 0);
00614         noticeTextLen = LoadStringW(hInstance, IDS_NOTICE_TEXT,
00615          (LPWSTR)&noticeText, 0);
00616         if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
00617         {
00618             headingSep = colonCrlf;
00619             sep = crlf;
00620         }
00621         else
00622         {
00623             headingSep = colonSpace;
00624             sep = commaSep;
00625         }
00626         sepLen = strlenW(sep);
00627         headingSepLen = strlenW(headingSep);
00628 
00629         if (pNoticeRef)
00630         {
00631             DWORD k;
00632             LPCSTR src;
00633 
00634             if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
00635             {
00636                 charsNeeded += 3 * strlenW(indent);
00637                 if (str && *pcchStr >= charsNeeded)
00638                 {
00639                     strcpyW(str, indent);
00640                     str += strlenW(indent);
00641                     strcpyW(str, indent);
00642                     str += strlenW(indent);
00643                     strcpyW(str, indent);
00644                     str += strlenW(indent);
00645                 }
00646             }
00647             charsNeeded += noticeRefLen;
00648             if (str && *pcchStr >= charsNeeded)
00649             {
00650                 memcpy(str, noticeRef, noticeRefLen * sizeof(WCHAR));
00651                 str += noticeRefLen;
00652             }
00653             charsNeeded += headingSepLen;
00654             if (str && *pcchStr >= charsNeeded)
00655             {
00656                 strcpyW(str, headingSep);
00657                 str += headingSepLen;
00658             }
00659             if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
00660             {
00661                 charsNeeded += 4 * strlenW(indent);
00662                 if (str && *pcchStr >= charsNeeded)
00663                 {
00664                     strcpyW(str, indent);
00665                     str += strlenW(indent);
00666                     strcpyW(str, indent);
00667                     str += strlenW(indent);
00668                     strcpyW(str, indent);
00669                     str += strlenW(indent);
00670                     strcpyW(str, indent);
00671                     str += strlenW(indent);
00672                 }
00673             }
00674             charsNeeded += organizationLen;
00675             if (str && *pcchStr >= charsNeeded)
00676             {
00677                 memcpy(str, organization, organizationLen * sizeof(WCHAR));
00678                 str += organizationLen;
00679             }
00680             charsNeeded += strlen(pNoticeRef->pszOrganization);
00681             if (str && *pcchStr >= charsNeeded)
00682                 for (src = pNoticeRef->pszOrganization; src && *src;
00683                  src++, str++)
00684                     *str = *src;
00685             charsNeeded += sepLen;
00686             if (str && *pcchStr >= charsNeeded)
00687             {
00688                 strcpyW(str, sep);
00689                 str += sepLen;
00690             }
00691             for (k = 0; k < pNoticeRef->cNoticeNumbers; k++)
00692             {
00693                 if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
00694                 {
00695                     charsNeeded += 4 * strlenW(indent);
00696                     if (str && *pcchStr >= charsNeeded)
00697                     {
00698                         strcpyW(str, indent);
00699                         str += strlenW(indent);
00700                         strcpyW(str, indent);
00701                         str += strlenW(indent);
00702                         strcpyW(str, indent);
00703                         str += strlenW(indent);
00704                         strcpyW(str, indent);
00705                         str += strlenW(indent);
00706                     }
00707                 }
00708                 charsNeeded += noticeNumLen;
00709                 if (str && *pcchStr >= charsNeeded)
00710                 {
00711                     memcpy(str, noticeNum, noticeNumLen * sizeof(WCHAR));
00712                     str += noticeNumLen;
00713                 }
00714                 sprintfW(noticeNumStr, numFmt, k + 1);
00715                 charsNeeded += strlenW(noticeNumStr);
00716                 if (str && *pcchStr >= charsNeeded)
00717                 {
00718                     strcpyW(str, noticeNumStr);
00719                     str += strlenW(noticeNumStr);
00720                 }
00721                 charsNeeded += sepLen;
00722                 if (str && *pcchStr >= charsNeeded)
00723                 {
00724                     strcpyW(str, sep);
00725                     str += sepLen;
00726                 }
00727             }
00728         }
00729         if (notice->pszDisplayText)
00730         {
00731             if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
00732             {
00733                 charsNeeded += 3 * strlenW(indent);
00734                 if (str && *pcchStr >= charsNeeded)
00735                 {
00736                     strcpyW(str, indent);
00737                     str += strlenW(indent);
00738                     strcpyW(str, indent);
00739                     str += strlenW(indent);
00740                     strcpyW(str, indent);
00741                     str += strlenW(indent);
00742                 }
00743             }
00744             charsNeeded += noticeTextLen;
00745             if (str && *pcchStr >= charsNeeded)
00746             {
00747                 memcpy(str, noticeText, noticeTextLen * sizeof(WCHAR));
00748                 str += noticeTextLen;
00749             }
00750             charsNeeded += strlenW(notice->pszDisplayText);
00751             if (str && *pcchStr >= charsNeeded)
00752             {
00753                 strcpyW(str, notice->pszDisplayText);
00754                 str += strlenW(notice->pszDisplayText);
00755             }
00756             charsNeeded += sepLen;
00757             if (str && *pcchStr >= charsNeeded)
00758             {
00759                 strcpyW(str, sep);
00760                 str += sepLen;
00761             }
00762         }
00763         LocalFree(notice);
00764         if (!str)
00765             *pcchStr = charsNeeded;
00766         else if (*pcchStr < charsNeeded)
00767         {
00768             *pcchStr = charsNeeded;
00769             SetLastError(ERROR_MORE_DATA);
00770             ret = FALSE;
00771         }
00772         else
00773             *pcchStr = charsNeeded;
00774     }
00775     return ret;
00776 }
00777 
00778 /***********************************************************************
00779  *      FormatVerisignExtension (CRYPTDLG.@)
00780  */
00781 BOOL WINAPI FormatVerisignExtension(DWORD dwCertEncodingType,
00782  DWORD dwFormatType, DWORD dwFormatStrType, void *pFormatStruct,
00783  LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat,
00784  DWORD *pcbFormat)
00785 {
00786     CERT_POLICIES_INFO *policies;
00787     DWORD size;
00788     BOOL ret = FALSE;
00789 
00790     if (!cbEncoded)
00791     {
00792         SetLastError(E_INVALIDARG);
00793         return FALSE;
00794     }
00795     if ((ret = CryptDecodeObjectEx(dwCertEncodingType, X509_CERT_POLICIES,
00796      pbEncoded, cbEncoded, CRYPT_DECODE_ALLOC_FLAG, NULL, &policies, &size)))
00797     {
00798         static const WCHAR numFmt[] = { '%','d',0 };
00799         DWORD charsNeeded = 1; /* space for NULL terminator */
00800         LPCWSTR headingSep, sep;
00801         DWORD headingSepLen, sepLen;
00802         WCHAR policyNum[11], policyQualifierNum[11];
00803         LPWSTR certPolicy, policyId, policyQualifierInfo, policyQualifierId;
00804         LPWSTR cps, userNotice, qualifier;
00805         DWORD certPolicyLen, policyIdLen, policyQualifierInfoLen;
00806         DWORD policyQualifierIdLen, cpsLen, userNoticeLen, qualifierLen;
00807         DWORD i;
00808         LPWSTR str = pbFormat;
00809 
00810         certPolicyLen = LoadStringW(hInstance, IDS_CERT_POLICY,
00811          (LPWSTR)&certPolicy, 0);
00812         policyIdLen = LoadStringW(hInstance, IDS_POLICY_ID, (LPWSTR)&policyId,
00813          0);
00814         policyQualifierInfoLen = LoadStringW(hInstance,
00815          IDS_POLICY_QUALIFIER_INFO, (LPWSTR)&policyQualifierInfo, 0);
00816         policyQualifierIdLen = LoadStringW(hInstance, IDS_POLICY_QUALIFIER_ID,
00817          (LPWSTR)&policyQualifierId, 0);
00818         cpsLen = LoadStringW(hInstance, IDS_CPS, (LPWSTR)&cps, 0);
00819         userNoticeLen = LoadStringW(hInstance, IDS_USER_NOTICE,
00820          (LPWSTR)&userNotice, 0);
00821         qualifierLen = LoadStringW(hInstance, IDS_QUALIFIER,
00822          (LPWSTR)&qualifier, 0);
00823         if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
00824         {
00825             headingSep = colonCrlf;
00826             sep = crlf;
00827         }
00828         else
00829         {
00830             headingSep = colonSpace;
00831             sep = commaSep;
00832         }
00833         sepLen = strlenW(sep);
00834         headingSepLen = strlenW(headingSep);
00835 
00836         for (i = 0; ret && i < policies->cPolicyInfo; i++)
00837         {
00838             CERT_POLICY_INFO *policy = &policies->rgPolicyInfo[i];
00839             DWORD j;
00840             LPCSTR src;
00841 
00842             charsNeeded += 1; /* '['*/
00843             if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00844                 *str++ = '[';
00845             sprintfW(policyNum, numFmt, i + 1);
00846             charsNeeded += strlenW(policyNum);
00847             if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00848             {
00849                 strcpyW(str, policyNum);
00850                 str += strlenW(policyNum);
00851             }
00852             charsNeeded += 1; /* ']'*/
00853             if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00854                 *str++ = ']';
00855             charsNeeded += certPolicyLen;
00856             if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00857             {
00858                 memcpy(str, certPolicy, certPolicyLen * sizeof(WCHAR));
00859                 str += certPolicyLen;
00860             }
00861             charsNeeded += headingSepLen;
00862             if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00863             {
00864                 strcpyW(str, headingSep);
00865                 str += headingSepLen;
00866             }
00867             if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
00868             {
00869                 charsNeeded += strlenW(indent);
00870                 if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00871                 {
00872                     strcpyW(str, indent);
00873                     str += strlenW(indent);
00874                 }
00875             }
00876             charsNeeded += policyIdLen;
00877             if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00878             {
00879                 memcpy(str, policyId, policyIdLen * sizeof(WCHAR));
00880                 str += policyIdLen;
00881             }
00882             charsNeeded += strlen(policy->pszPolicyIdentifier);
00883             if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00884             {
00885                 for (src = policy->pszPolicyIdentifier; src && *src;
00886                  src++, str++)
00887                     *str = *src;
00888             }
00889             charsNeeded += sepLen;
00890             if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00891             {
00892                 strcpyW(str, sep);
00893                 str += sepLen;
00894             }
00895             for (j = 0; j < policy->cPolicyQualifier; j++)
00896             {
00897                 CERT_POLICY_QUALIFIER_INFO *qualifierInfo =
00898                  &policy->rgPolicyQualifier[j];
00899                 DWORD sizeRemaining;
00900 
00901                 if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
00902                 {
00903                     charsNeeded += strlenW(indent);
00904                     if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00905                     {
00906                         strcpyW(str, indent);
00907                         str += strlenW(indent);
00908                     }
00909                 }
00910                 charsNeeded += 1; /* '['*/
00911                 if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00912                     *str++ = '[';
00913                 charsNeeded += strlenW(policyNum);
00914                 if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00915                 {
00916                     strcpyW(str, policyNum);
00917                     str += strlenW(policyNum);
00918                 }
00919                 charsNeeded += 1; /* ','*/
00920                 if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00921                     *str++ = ',';
00922                 sprintfW(policyQualifierNum, numFmt, j + 1);
00923                 charsNeeded += strlenW(policyQualifierNum);
00924                 if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00925                 {
00926                     strcpyW(str, policyQualifierNum);
00927                     str += strlenW(policyQualifierNum);
00928                 }
00929                 charsNeeded += 1; /* ']'*/
00930                 if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00931                     *str++ = ']';
00932                 charsNeeded += policyQualifierInfoLen;
00933                 if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00934                 {
00935                     memcpy(str, policyQualifierInfo,
00936                      policyQualifierInfoLen * sizeof(WCHAR));
00937                     str += policyQualifierInfoLen;
00938                 }
00939                 charsNeeded += headingSepLen;
00940                 if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00941                 {
00942                     strcpyW(str, headingSep);
00943                     str += headingSepLen;
00944                 }
00945                 if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
00946                 {
00947                     charsNeeded += 2 * strlenW(indent);
00948                     if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00949                     {
00950                         strcpyW(str, indent);
00951                         str += strlenW(indent);
00952                         strcpyW(str, indent);
00953                         str += strlenW(indent);
00954                     }
00955                 }
00956                 charsNeeded += policyQualifierIdLen;
00957                 if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00958                 {
00959                     memcpy(str, policyQualifierId,
00960                      policyQualifierIdLen * sizeof(WCHAR));
00961                     str += policyQualifierIdLen;
00962                 }
00963                 if (!strcmp(qualifierInfo->pszPolicyQualifierId,
00964                  szOID_PKIX_POLICY_QUALIFIER_CPS))
00965                 {
00966                     charsNeeded += cpsLen;
00967                     if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00968                     {
00969                         memcpy(str, cps, cpsLen * sizeof(WCHAR));
00970                         str += cpsLen;
00971                     }
00972                 }
00973                 else if (!strcmp(qualifierInfo->pszPolicyQualifierId,
00974                  szOID_PKIX_POLICY_QUALIFIER_USERNOTICE))
00975                 {
00976                     charsNeeded += userNoticeLen;
00977                     if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00978                     {
00979                         memcpy(str, userNotice, userNoticeLen * sizeof(WCHAR));
00980                         str += userNoticeLen;
00981                     }
00982                 }
00983                 else
00984                 {
00985                     charsNeeded += strlen(qualifierInfo->pszPolicyQualifierId);
00986                     if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00987                     {
00988                         for (src = qualifierInfo->pszPolicyQualifierId;
00989                          src && *src; src++, str++)
00990                             *str = *src;
00991                     }
00992                 }
00993                 charsNeeded += sepLen;
00994                 if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
00995                 {
00996                     strcpyW(str, sep);
00997                     str += sepLen;
00998                 }
00999                 if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
01000                 {
01001                     charsNeeded += 2 * strlenW(indent);
01002                     if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
01003                     {
01004                         strcpyW(str, indent);
01005                         str += strlenW(indent);
01006                         strcpyW(str, indent);
01007                         str += strlenW(indent);
01008                     }
01009                 }
01010                 charsNeeded += qualifierLen;
01011                 if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
01012                 {
01013                     memcpy(str, qualifier, qualifierLen * sizeof(WCHAR));
01014                     str += qualifierLen;
01015                 }
01016                 charsNeeded += headingSepLen;
01017                 if (str && *pcbFormat >= charsNeeded * sizeof(WCHAR))
01018                 {
01019                     strcpyW(str, headingSep);
01020                     str += headingSepLen;
01021                 }
01022                 /* This if block is deliberately redundant with the same if
01023                  * block above, in order to keep the code more readable (the
01024                  * code flow follows the order in which the strings are output.)
01025                  */
01026                 if (!strcmp(qualifierInfo->pszPolicyQualifierId,
01027                  szOID_PKIX_POLICY_QUALIFIER_CPS))
01028                 {
01029                     if (!str || *pcbFormat < charsNeeded * sizeof(WCHAR))
01030                     {
01031                         /* Insufficient space, determine how much is needed. */
01032                         ret = CRYPT_FormatCPS(dwCertEncodingType,
01033                          dwFormatStrType, qualifierInfo->Qualifier.pbData,
01034                          qualifierInfo->Qualifier.cbData, NULL, &size);
01035                         if (ret)
01036                             charsNeeded += size - 1;
01037                     }
01038                     else
01039                     {
01040                         sizeRemaining = *pcbFormat / sizeof(WCHAR);
01041                         sizeRemaining -= str - (LPWSTR)pbFormat;
01042                         ret = CRYPT_FormatCPS(dwCertEncodingType,
01043                          dwFormatStrType, qualifierInfo->Qualifier.pbData,
01044                          qualifierInfo->Qualifier.cbData, str, &sizeRemaining);
01045                         if (ret || GetLastError() == ERROR_MORE_DATA)
01046                         {
01047                             charsNeeded += sizeRemaining - 1;
01048                             str += sizeRemaining - 1;
01049                         }
01050                     }
01051                 }
01052                 else if (!strcmp(qualifierInfo->pszPolicyQualifierId,
01053                  szOID_PKIX_POLICY_QUALIFIER_USERNOTICE))
01054                 {
01055                     if (!str || *pcbFormat < charsNeeded * sizeof(WCHAR))
01056                     {
01057                         /* Insufficient space, determine how much is needed. */
01058                         ret = CRYPT_FormatUserNotice(dwCertEncodingType,
01059                          dwFormatStrType, qualifierInfo->Qualifier.pbData,
01060                          qualifierInfo->Qualifier.cbData, NULL, &size);
01061                         if (ret)
01062                             charsNeeded += size - 1;
01063                     }
01064                     else
01065                     {
01066                         sizeRemaining = *pcbFormat / sizeof(WCHAR);
01067                         sizeRemaining -= str - (LPWSTR)pbFormat;
01068                         ret = CRYPT_FormatUserNotice(dwCertEncodingType,
01069                          dwFormatStrType, qualifierInfo->Qualifier.pbData,
01070                          qualifierInfo->Qualifier.cbData, str, &sizeRemaining);
01071                         if (ret || GetLastError() == ERROR_MORE_DATA)
01072                         {
01073                             charsNeeded += sizeRemaining - 1;
01074                             str += sizeRemaining - 1;
01075                         }
01076                     }
01077                 }
01078                 else
01079                 {
01080                     if (!str || *pcbFormat < charsNeeded * sizeof(WCHAR))
01081                     {
01082                         /* Insufficient space, determine how much is needed. */
01083                         ret = CRYPT_FormatHexString(
01084                          qualifierInfo->Qualifier.pbData,
01085                          qualifierInfo->Qualifier.cbData, NULL, &size);
01086                         if (ret)
01087                             charsNeeded += size - 1;
01088                     }
01089                     else
01090                     {
01091                         sizeRemaining = *pcbFormat / sizeof(WCHAR);
01092                         sizeRemaining -= str - (LPWSTR)pbFormat;
01093                         ret = CRYPT_FormatHexString(
01094                          qualifierInfo->Qualifier.pbData,
01095                          qualifierInfo->Qualifier.cbData, str, &sizeRemaining);
01096                         if (ret || GetLastError() == ERROR_MORE_DATA)
01097                         {
01098                             charsNeeded += sizeRemaining - 1;
01099                             str += sizeRemaining - 1;
01100                         }
01101                     }
01102                 }
01103             }
01104         }
01105         LocalFree(policies);
01106         if (ret)
01107         {
01108             if (!pbFormat)
01109                 *pcbFormat = charsNeeded * sizeof(WCHAR);
01110             else if (*pcbFormat < charsNeeded * sizeof(WCHAR))
01111             {
01112                 *pcbFormat = charsNeeded * sizeof(WCHAR);
01113                 SetLastError(ERROR_MORE_DATA);
01114                 ret = FALSE;
01115             }
01116             else
01117                 *pcbFormat = charsNeeded * sizeof(WCHAR);
01118         }
01119     }
01120     return ret;
01121 }
01122 
01123 #define szOID_MICROSOFT_Encryption_Key_Preference "1.3.6.1.4.1.311.16.4"
01124 
01125 /***********************************************************************
01126  *      DllRegisterServer (CRYPTDLG.@)
01127  */
01128 HRESULT WINAPI DllRegisterServer(void)
01129 {
01130     static WCHAR cryptdlg[] = { 'c','r','y','p','t','d','l','g','.',
01131      'd','l','l',0 };
01132     static WCHAR wintrust[] = { 'w','i','n','t','r','u','s','t','.',
01133      'd','l','l',0 };
01134     static WCHAR certTrustInit[] = { 'C','e','r','t','T','r','u','s','t',
01135      'I','n','i','t',0 };
01136     static WCHAR wintrustCertificateTrust[] = { 'W','i','n','t','r','u','s','t',
01137      'C','e','r','t','i','f','i','c','a','t','e','T','r','u','s','t',0 };
01138     static WCHAR certTrustCertPolicy[] = { 'C','e','r','t','T','r','u','s','t',
01139      'C','e','r','t','P','o','l','i','c','y',0 };
01140     static WCHAR certTrustFinalPolicy[] = { 'C','e','r','t','T','r','u','s','t',
01141      'F','i','n','a','l','P','o','l','i','c','y',0 };
01142     static WCHAR certTrustCleanup[] = { 'C','e','r','t','T','r','u','s','t',
01143      'C','l','e','a','n','u','p',0 };
01144     static const WCHAR cryptDlg[] = { 'c','r','y','p','t','d','l','g','.',
01145        'd','l','l',0 };
01146     CRYPT_REGISTER_ACTIONID reg;
01147     GUID guid = CERT_CERTIFICATE_ACTION_VERIFY;
01148     HRESULT hr = S_OK;
01149 
01150     memset(&reg, 0, sizeof(reg));
01151     reg.cbStruct = sizeof(reg);
01152     reg.sInitProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
01153     reg.sInitProvider.pwszDLLName = cryptdlg;
01154     reg.sInitProvider.pwszFunctionName = certTrustInit;
01155     reg.sCertificateProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
01156     reg.sCertificateProvider.pwszDLLName = wintrust;
01157     reg.sCertificateProvider.pwszFunctionName = wintrustCertificateTrust;
01158     reg.sCertificatePolicyProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
01159     reg.sCertificatePolicyProvider.pwszDLLName = cryptdlg;
01160     reg.sCertificatePolicyProvider.pwszFunctionName = certTrustCertPolicy;
01161     reg.sFinalPolicyProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
01162     reg.sFinalPolicyProvider.pwszDLLName = cryptdlg;
01163     reg.sFinalPolicyProvider.pwszFunctionName = certTrustFinalPolicy;
01164     reg.sCleanupProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
01165     reg.sCleanupProvider.pwszDLLName = cryptdlg;
01166     reg.sCleanupProvider.pwszFunctionName = certTrustCleanup;
01167     if (!WintrustAddActionID(&guid, WT_ADD_ACTION_ID_RET_RESULT_FLAG, &reg))
01168         hr = GetLastError();
01169     CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_ENCODE_OBJECT_FUNC,
01170      "1.3.6.1.4.1.311.16.1.1", cryptDlg, "EncodeAttrSequence");
01171     CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_ENCODE_OBJECT_FUNC,
01172      szOID_MICROSOFT_Encryption_Key_Preference, cryptDlg, "EncodeRecipientID");
01173     CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_DECODE_OBJECT_FUNC,
01174      "1.3.6.1.4.1.311.16.1.1", cryptDlg, "DecodeAttrSequence");
01175     CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_DECODE_OBJECT_FUNC,
01176      szOID_MICROSOFT_Encryption_Key_Preference, cryptDlg, "DecodeRecipientID");
01177     CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_FORMAT_OBJECT_FUNC,
01178      szOID_PKIX_KP_EMAIL_PROTECTION, cryptDlg, "FormatPKIXEmailProtection");
01179     CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_FORMAT_OBJECT_FUNC,
01180      szOID_CERT_POLICIES, cryptDlg, "FormatVerisignExtension");
01181     return hr;
01182 }
01183 
01184 /***********************************************************************
01185  *      DllUnregisterServer (CRYPTDLG.@)
01186  */
01187 HRESULT WINAPI DllUnregisterServer(void)
01188 {
01189     GUID guid = CERT_CERTIFICATE_ACTION_VERIFY;
01190 
01191     WintrustRemoveActionID(&guid);
01192     CryptUnregisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_ENCODE_OBJECT_FUNC,
01193      "1.3.6.1.4.1.311.16.1.1");
01194     CryptUnregisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_ENCODE_OBJECT_FUNC,
01195      szOID_MICROSOFT_Encryption_Key_Preference);
01196     CryptUnregisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_DECODE_OBJECT_FUNC,
01197      "1.3.6.1.4.1.311.16.1.1");
01198     CryptUnregisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_DECODE_OBJECT_FUNC,
01199      szOID_MICROSOFT_Encryption_Key_Preference);
01200     CryptUnregisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_FORMAT_OBJECT_FUNC,
01201      szOID_PKIX_KP_EMAIL_PROTECTION);
01202     CryptUnregisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_FORMAT_OBJECT_FUNC,
01203      szOID_CERT_POLICIES);
01204     return S_OK;
01205 }

Generated on Sat May 26 2012 04:15:41 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.