Juan Lang : crypt32: Implement CryptFormatObject for szOID_NETSCAPE_CERT_TYPE.

Alexandre Julliard julliard at winehq.org
Thu Nov 20 08:20:33 CST 2008


Module: wine
Branch: master
Commit: 76d25370940245600de4d4acdb239392249410c8
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=76d25370940245600de4d4acdb239392249410c8

Author: Juan Lang <juan.lang at gmail.com>
Date:   Wed Nov 19 12:06:08 2008 -0800

crypt32: Implement CryptFormatObject for szOID_NETSCAPE_CERT_TYPE.

---

 dlls/crypt32/crypt32_En.rc |    7 +++
 dlls/crypt32/cryptres.h    |    7 +++
 dlls/crypt32/object.c      |  110 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 124 insertions(+), 0 deletions(-)

diff --git a/dlls/crypt32/crypt32_En.rc b/dlls/crypt32/crypt32_En.rc
index 301816e..ace77d2 100644
--- a/dlls/crypt32/crypt32_En.rc
+++ b/dlls/crypt32/crypt32_En.rc
@@ -227,4 +227,11 @@ STRINGTABLE DISCARDABLE
     IDS_CRL_SIGN "CRL Signing"
     IDS_ENCIPHER_ONLY "Encipher Only"
     IDS_DECIPHER_ONLY "Decipher Only"
+    IDS_NETSCAPE_SSL_CLIENT "SSL Client Authentication"
+    IDS_NETSCAPE_SSL_SERVER "SSL Server Authentication"
+    IDS_NETSCAPE_SMIME "S/MIME"
+    IDS_NETSCAPE_SIGN "Signature"
+    IDS_NETSCAPE_SSL_CA "SSL CA"
+    IDS_NETSCAPE_SMIME_CA "S/MIME CA"
+    IDS_NETSCAPE_SIGN_CA "Signature CA"
 }
diff --git a/dlls/crypt32/cryptres.h b/dlls/crypt32/cryptres.h
index 58daa07..6d0ac46 100644
--- a/dlls/crypt32/cryptres.h
+++ b/dlls/crypt32/cryptres.h
@@ -217,5 +217,12 @@
 #define IDS_CRL_SIGN 1250
 #define IDS_ENCIPHER_ONLY 1251
 #define IDS_DECIPHER_ONLY 1252
+#define IDS_NETSCAPE_SSL_CLIENT 1253
+#define IDS_NETSCAPE_SSL_SERVER 1254
+#define IDS_NETSCAPE_SMIME 1255
+#define IDS_NETSCAPE_SIGN 1256
+#define IDS_NETSCAPE_SSL_CA 1257
+#define IDS_NETSCAPE_SMIME_CA 1258
+#define IDS_NETSCAPE_SIGN_CA 1259
 
 #endif /* ndef __WINE_CRYPTRES_H__ */
diff --git a/dlls/crypt32/object.c b/dlls/crypt32/object.c
index 2a556cb..bd3ad11 100644
--- a/dlls/crypt32/object.c
+++ b/dlls/crypt32/object.c
@@ -2057,6 +2057,114 @@ static BOOL WINAPI CRYPT_FormatEnhancedKeyUsage(DWORD dwCertEncodingType,
     return ret;
 }
 
+static struct BitToString netscapeCertTypeMap[] = {
+ { NETSCAPE_SSL_CLIENT_AUTH_CERT_TYPE, IDS_NETSCAPE_SSL_CLIENT, { 0 } },
+ { NETSCAPE_SSL_SERVER_AUTH_CERT_TYPE, IDS_NETSCAPE_SSL_SERVER, { 0 } },
+ { NETSCAPE_SMIME_CERT_TYPE, IDS_NETSCAPE_SMIME, { 0 } },
+ { NETSCAPE_SIGN_CERT_TYPE, IDS_NETSCAPE_SIGN, { 0 } },
+ { NETSCAPE_SSL_CA_CERT_TYPE, IDS_NETSCAPE_SSL_CA, { 0 } },
+ { NETSCAPE_SMIME_CA_CERT_TYPE, IDS_NETSCAPE_SMIME_CA, { 0 } },
+ { NETSCAPE_SIGN_CA_CERT_TYPE, IDS_NETSCAPE_SIGN_CA, { 0 } },
+};
+
+static BOOL WINAPI CRYPT_FormatNetscapeCertType(DWORD dwCertEncodingType,
+ DWORD dwFormatType, DWORD dwFormatStrType, void *pFormatStruct,
+ LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat,
+ DWORD *pcbFormat)
+{
+    DWORD size;
+    CRYPT_BIT_BLOB *bits;
+    BOOL ret;
+
+    if (!cbEncoded)
+    {
+        SetLastError(E_INVALIDARG);
+        return FALSE;
+    }
+    if ((ret = CryptDecodeObjectEx(dwCertEncodingType, X509_BITS,
+     pbEncoded, cbEncoded, CRYPT_DECODE_ALLOC_FLAG, NULL, &bits, &size)))
+    {
+        WCHAR infoNotAvailable[MAX_STRING_RESOURCE_LEN];
+        DWORD bytesNeeded = sizeof(WCHAR);
+
+        LoadStringW(hInstance, IDS_INFO_NOT_AVAILABLE, infoNotAvailable,
+         sizeof(infoNotAvailable) / sizeof(infoNotAvailable[0]));
+        if (!bits->cbData || bits->cbData > 1)
+        {
+            bytesNeeded += strlenW(infoNotAvailable) * sizeof(WCHAR);
+            if (!pbFormat)
+                *pcbFormat = bytesNeeded;
+            else if (*pcbFormat < bytesNeeded)
+            {
+                *pcbFormat = bytesNeeded;
+                SetLastError(ERROR_MORE_DATA);
+                ret = FALSE;
+            }
+            else
+            {
+                LPWSTR str = pbFormat;
+
+                *pcbFormat = bytesNeeded;
+                strcpyW(str, infoNotAvailable);
+            }
+        }
+        else
+        {
+            static BOOL stringsLoaded = FALSE;
+            int i;
+            DWORD bitStringLen;
+            BOOL first = TRUE;
+
+            if (!stringsLoaded)
+            {
+                for (i = 0; i < sizeof(netscapeCertTypeMap) /
+                 sizeof(netscapeCertTypeMap[0]); i++)
+                    LoadStringW(hInstance, netscapeCertTypeMap[i].id,
+                     netscapeCertTypeMap[i].str, MAX_STRING_RESOURCE_LEN);
+                stringsLoaded = TRUE;
+            }
+            CRYPT_FormatBits(dwFormatStrType, bits->pbData[0],
+             netscapeCertTypeMap,
+             sizeof(netscapeCertTypeMap) / sizeof(netscapeCertTypeMap[0]),
+             NULL, &bitStringLen, &first);
+            bytesNeeded += bitStringLen;
+            bytesNeeded += 3 * sizeof(WCHAR); /* " (" + ")" */
+            CRYPT_FormatHexString(0, 0, 0, NULL, NULL, bits->pbData,
+             bits->cbData, NULL, &size);
+            bytesNeeded += size;
+            if (!pbFormat)
+                *pcbFormat = bytesNeeded;
+            else if (*pcbFormat < bytesNeeded)
+            {
+                *pcbFormat = bytesNeeded;
+                SetLastError(ERROR_MORE_DATA);
+                ret = FALSE;
+            }
+            else
+            {
+                LPWSTR str = pbFormat;
+
+                bitStringLen = bytesNeeded;
+                first = TRUE;
+                CRYPT_FormatBits(dwFormatStrType, bits->pbData[0],
+                 netscapeCertTypeMap,
+                 sizeof(netscapeCertTypeMap) / sizeof(netscapeCertTypeMap[0]),
+                 str, &bitStringLen, &first);
+                str += bitStringLen / sizeof(WCHAR) - 1;
+                *str++ = ' ';
+                *str++ = '(';
+                CRYPT_FormatHexString(0, 0, 0, NULL, NULL, bits->pbData,
+                 bits->cbData, str, &size);
+                str += size / sizeof(WCHAR) - 1;
+                *str++ = ')';
+                *str = 0;
+            }
+        }
+        LocalFree(bits);
+    }
+    return ret;
+}
+
 static WCHAR financialCriteria[MAX_STRING_RESOURCE_LEN];
 static WCHAR available[MAX_STRING_RESOURCE_LEN];
 static WCHAR notAvailable[MAX_STRING_RESOURCE_LEN];
@@ -2225,6 +2333,8 @@ static CryptFormatObjectFunc CRYPT_GetBuiltinFormatFunction(DWORD encodingType,
         format = CRYPT_FormatCRLDistPoints;
     else if (!strcmp(lpszStructType, szOID_ENHANCED_KEY_USAGE))
         format = CRYPT_FormatEnhancedKeyUsage;
+    else if (!strcmp(lpszStructType, szOID_NETSCAPE_CERT_TYPE))
+        format = CRYPT_FormatNetscapeCertType;
     else if (!strcmp(lpszStructType, SPC_FINANCIAL_CRITERIA_OBJID))
         format = CRYPT_FormatSpcFinancialCriteria;
     if (!format && !(formatStrType & CRYPT_FORMAT_STR_NO_HEX))




More information about the wine-cvs mailing list