Index: /trunk/include/iprt/http.h
===================================================================
--- /trunk/include/iprt/http.h	(revision 45338)
+++ /trunk/include/iprt/http.h	(revision 45339)
@@ -109,4 +109,26 @@
 /** @} */
 
+
+/**
+ * Determine the digest (fingerprint) of a certificate. Allocate memory for
+ * storing the SHA1 fingerprint as well as the SHA512 fingerprint. This
+ * memory has to be freed by RTMemFree().
+ *
+ * @todo Move this function to somewhere else.
+ *
+ * @returns iprt status code.
+ *
+ * @param    hHttp         HTTP interface handle (ignored).
+ * @param    pcszCert      The certificate in PEM format.
+ * @param    cbCert        Size of the certificate.
+ * @param    pabSha1       Where to store the pointer to the SHA1 fingerprint.
+ * @param    pcbSha1       Where to store the size of the SHA1 fingerprint.
+ * @param    pabSha512     Where to store the pointer to the SHA512 fingerprint.
+ * @param    pcbSha512     Where to store the size of the SHA512 fingerprint.
+ */
+RTR3DECL(int) RTHttpCertDigest(RTHTTP hHttp, char *pcszCert, size_t cbCert,
+                               uint8_t **pabSha1, size_t *pcbSha1,
+                               uint8_t **pabSha512, size_t *pcbSha512);
+
 RT_C_DECLS_END
 
Index: /trunk/src/VBox/Runtime/common/misc/http.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/misc/http.cpp	(revision 45338)
+++ /trunk/src/VBox/Runtime/common/misc/http.cpp	(revision 45339)
@@ -37,4 +37,5 @@
 
 #include <curl/curl.h>
+#include <openssl/ssl.h>
 #include "internal/magics.h"
 
@@ -195,4 +196,48 @@
     if (CURL_FAILED(rcCurl))
         return VERR_INVALID_PARAMETER;
+
+    return VINF_SUCCESS;
+}
+
+RTR3DECL(int) RTHttpCertDigest(RTHTTP hHttp, char *pcszCert, size_t cbCert,
+                               uint8_t **pabSha1,   size_t *pcbSha1,
+                               uint8_t **pabSha512, size_t *pcbSha512)
+{
+    BIO *cert = BIO_new_mem_buf(pcszCert, cbCert);
+    if (!cert)
+        return VERR_INTERNAL_ERROR;
+
+    X509 *crt = NULL;
+    if (!PEM_read_bio_X509(cert, &crt, NULL, NULL))
+        return VERR_INTERNAL_ERROR;
+
+    unsigned cb;
+    unsigned char md[EVP_MAX_MD_SIZE];
+
+    const EVP_MD *digest = EVP_sha1();
+    int rc = X509_digest(crt, digest, md, &cb);
+    if (rc <= 0)
+        return VERR_INTERNAL_ERROR;
+    *pabSha1 = (uint8_t*)RTMemAlloc(cb);
+    if (!*pabSha1)
+        return VERR_NO_MEMORY;
+    memcpy(*pabSha1, md, cb);
+    *pcbSha1 = cb;
+
+    digest = EVP_sha512();
+    rc = X509_digest(crt, digest, md, &cb);
+    if (rc <= 0)
+    {
+        RTMemFree(*pabSha1);
+        return VERR_INTERNAL_ERROR;
+    }
+    *pabSha512 = (uint8_t*)RTMemAlloc(cb);
+    if (!*pabSha512)
+    {
+        RTMemFree(*pabSha512);
+        return VERR_NO_MEMORY;
+    }
+    memcpy(*pabSha512, md, cb);
+    *pcbSha512 = cb;
 
     return VINF_SUCCESS;
Index: /trunk/src/VBox/Runtime/testcase/tstHttp.cpp
===================================================================
--- /trunk/src/VBox/Runtime/testcase/tstHttp.cpp	(revision 45338)
+++ /trunk/src/VBox/Runtime/testcase/tstHttp.cpp	(revision 45339)
@@ -60,9 +60,61 @@
     if (RT_SUCCESS(rc) && pszBuf)
     {
-	/// @todo check certificate fingerprint against a strong hash,
-	// otherwise there's a simple way for a man-in-the-middle attack
-        rc = RTStrmWrite(CAFile, pszBuf, strlen(pszBuf));
-	if (RT_SUCCESS(rc))
-            rc = RTStrmWrite(CAFile, RTFILE_LINEFEED, strlen(RTFILE_LINEFEED));
+        uint8_t *abSha1;
+        size_t  cbSha1;
+        uint8_t *abSha512;
+        size_t  cbSha512;
+        const uint8_t abSha1PCA3G5[] =
+        {
+            0x4e, 0xb6, 0xd5, 0x78, 0x49, 0x9b, 0x1c, 0xcf, 0x5f, 0x58,
+            0x1e, 0xad, 0x56, 0xbe, 0x3d, 0x9b, 0x67, 0x44, 0xa5, 0xe5
+        };
+        const uint8_t abSha512PCA3G5[] =
+        {
+            0xd4, 0xf8, 0x10, 0x54, 0x72, 0x77, 0x0a, 0x2d,
+            0xe3, 0x17, 0xb3, 0xcf, 0xed, 0x61, 0xae, 0x5c,
+            0x5d, 0x3e, 0xde, 0xa1, 0x41, 0x35, 0xb2, 0xdf,
+            0x60, 0xe2, 0x61, 0xfe, 0x3a, 0xc1, 0x66, 0xa3,
+            0x3c, 0x88, 0x54, 0x04, 0x4f, 0x1d, 0x13, 0x46,
+            0xe3, 0x8c, 0x06, 0x92, 0x9d, 0x70, 0x54, 0xc3,
+            0x44, 0xeb, 0x2c, 0x74, 0x25, 0x9e, 0x5d, 0xfb,
+            0xd2, 0x6b, 0xa8, 0x9a, 0xf0, 0xb3, 0x6a, 0x01
+        };
+        rc = RTHttpCertDigest(hHttp, pszBuf, strlen(pszBuf),
+                              &abSha1, &cbSha1, &abSha512, &cbSha512);
+        if (RT_SUCCESS(rc))
+        {
+            if (cbSha1 != sizeof(abSha1PCA3G5))
+            {
+                RTPrintf("Wrong SHA1 digest size of PCA-3G5\n");
+                rc = VERR_INTERNAL_ERROR;
+            }
+            else if (memcmp(abSha1PCA3G5, abSha1, cbSha1))
+            {
+                RTPrintf("Wrong SHA1 digest for PCA-3G5:\n"
+                        "Got:      %.*Rhxs\n"
+                        "Expected: %.*Rhxs\n",
+                        cbSha1, abSha1, sizeof(abSha1PCA3G5), abSha1PCA3G5);
+                rc = VERR_INTERNAL_ERROR;
+            }
+            if (cbSha512 != sizeof(abSha512PCA3G5))
+            {
+                RTPrintf("Wrong SHA512 digest size of PCA-3G5\n");
+                rc = VERR_INTERNAL_ERROR;
+            }
+            else if (memcmp(abSha512PCA3G5, abSha512, cbSha512))
+            {
+                RTPrintf("Wrong SHA512 digest for PCA-3G5:\n"
+                        "Got:      %.*Rhxs\n"
+                        "Expected: %.*Rhxs\n",
+                        cbSha512, abSha512, sizeof(abSha512PCA3G5), abSha512PCA3G5);
+                rc = VERR_INTERNAL_ERROR;
+            }
+            RTMemFree(abSha1);
+            RTMemFree(abSha512);
+            if (RT_SUCCESS(rc))
+                rc = RTStrmWrite(CAFile, pszBuf, strlen(pszBuf));
+            if (RT_SUCCESS(rc))
+                rc = RTStrmWrite(CAFile, RTFILE_LINEFEED, strlen(RTFILE_LINEFEED));
+        }
     }
     if (pszBuf)
@@ -79,9 +131,61 @@
     if (RT_SUCCESS(rc) && pszBuf)
     {
-	/// @todo check certificate fingerprint against a strong hash,
-	// otherwise there's a simple way for a man-in-the-middle attack
-        rc = RTStrmWrite(CAFile, pszBuf, strlen(pszBuf));
-	if (RT_SUCCESS(rc))
-            rc = RTStrmWrite(CAFile, RTFILE_LINEFEED, strlen(RTFILE_LINEFEED));
+        uint8_t *abSha1;
+        size_t  cbSha1;
+        uint8_t *abSha512;
+        size_t  cbSha512;
+        const uint8_t abSha1PCA3[] =
+        {
+            0xa1, 0xdb, 0x63, 0x93, 0x91, 0x6f, 0x17, 0xe4, 0x18, 0x55,
+            0x09, 0x40, 0x04, 0x15, 0xc7, 0x02, 0x40, 0xb0, 0xae, 0x6b
+        };
+        const uint8_t abSha512PCA3[] =
+        {
+            0xbb, 0xf7, 0x8a, 0x19, 0x9f, 0x37, 0xee, 0xa2,
+            0xce, 0xc8, 0xaf, 0xe3, 0xd6, 0x22, 0x54, 0x20,
+            0x74, 0x67, 0x6e, 0xa5, 0x19, 0xb7, 0x62, 0x1e,
+            0xc1, 0x2f, 0xd5, 0x08, 0xf4, 0x64, 0xc4, 0xc6,
+            0xbb, 0xc2, 0xf2, 0x35, 0xe7, 0xbe, 0x32, 0x0b,
+            0xde, 0xb2, 0xfc, 0x44, 0x92, 0x5b, 0x8b, 0x9b,
+            0x77, 0xa5, 0x40, 0x22, 0x18, 0x12, 0xcb, 0x3d,
+            0x0a, 0x67, 0x83, 0x87, 0xc5, 0x45, 0xc4, 0x99
+        };
+        rc = RTHttpCertDigest(hHttp, pszBuf, strlen(pszBuf),
+                              &abSha1, &cbSha1, &abSha512, &cbSha512);
+        if (RT_SUCCESS(rc))
+        {
+            if (cbSha1 != sizeof(abSha1PCA3))
+            {
+                RTPrintf("Wrong SHA1 digest size of PCA-3\n");
+                rc = VERR_INTERNAL_ERROR;
+            }
+            else if (memcmp(abSha1PCA3, abSha1, cbSha1))
+            {
+                RTPrintf("Wrong SHA1 digest for PCA-3:\n"
+                        "Got:      %.*Rhxs\n"
+                        "Expected: %.*Rhxs\n",
+                        cbSha1, abSha1, sizeof(abSha1PCA3), abSha1PCA3);
+                rc = VERR_INTERNAL_ERROR;
+            }
+            if (cbSha512 != sizeof(abSha512PCA3))
+            {
+                RTPrintf("Wrong SHA512 digest size of PCA-3\n");
+                rc = VERR_INTERNAL_ERROR;
+            }
+            else if (memcmp(abSha512PCA3, abSha512, cbSha512))
+            {
+                RTPrintf("Wrong SHA512 digest for PCA-3:\n"
+                        "Got:      %.*Rhxs\n"
+                        "Expected: %.*Rhxs\n",
+                        cbSha512, abSha512, sizeof(abSha512PCA3), abSha512PCA3);
+                rc = VERR_INTERNAL_ERROR;
+            }
+            RTMemFree(abSha1);
+            RTMemFree(abSha512);
+            if (RT_SUCCESS(rc))
+                rc = RTStrmWrite(CAFile, pszBuf, strlen(pszBuf));
+            if (RT_SUCCESS(rc))
+                rc = RTStrmWrite(CAFile, RTFILE_LINEFEED, strlen(RTFILE_LINEFEED));
+        }
     }
     if (pszBuf)
@@ -100,4 +204,5 @@
     if (RT_SUCCESS(rc))
         rc = RTHttpSetCAFile(hHttp, CAFILE_NAME);
+
     if (RT_SUCCESS(rc))
         rc = RTHttpGet(hHttp,
@@ -109,5 +214,9 @@
         cErrors++;
 
-    RTPrintf("Error code: %Rrc\nGot: %s\n", rc, pszBuf);
+    if (RT_FAILURE(rc))
+        RTPrintf("Error code: %Rrc\n", rc);
+    else
+        RTPrintf("Success!\n");
+    RTPrintf("Got: %s\n", pszBuf);
     RTMemFree(pszBuf);
 
