- Timestamp:
- Apr 4, 2013 9:37:00 AM (12 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/http.cpp
r43713 r45331 1 2 1 /* $Id$ */ 3 2 /** @file … … 6 5 7 6 /* 8 * Copyright (C) 2012 Oracle Corporation7 * Copyright (C) 2012-2013 Oracle Corporation 9 8 * 10 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 35 34 #include <iprt/mem.h> 36 35 #include <iprt/string.h> 36 #include <iprt/file.h> 37 37 38 38 #include <curl/curl.h> … … 49 49 long lLastResp; 50 50 struct curl_slist *pHeaders; 51 const char *pcszCAFile; 51 52 } RTHTTPINTERNAL; 52 53 typedef RTHTTPINTERNAL *PRTHTTPINTERNAL; … … 198 199 } 199 200 201 RTR3DECL(int) RTHttpSetCAFile(RTHTTP hHttp, const char *pcszCAFile) 202 { 203 PRTHTTPINTERNAL pHttpInt = hHttp; 204 RTHTTP_VALID_RETURN(pHttpInt); 205 206 pHttpInt->pcszCAFile = pcszCAFile; 207 208 return VINF_SUCCESS; 209 } 210 200 211 RTR3DECL(int) RTHttpGet(RTHTTP hHttp, const char *pcszUrl, char **ppszResponse) 201 212 { … … 213 224 #endif 214 225 215 /* XXX */ 216 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_CAINFO, "/etc/ssl/certs/ca-certificates.crt"); 217 if (CURL_FAILED(rcCurl)) 218 return VERR_INTERNAL_ERROR; 226 const char *pcszCAFile = "/etc/ssl/certs/ca-certificates.crt"; 227 if (pHttpInt->pcszCAFile) 228 pcszCAFile = pHttpInt->pcszCAFile; 229 if (RTFileExists(pcszCAFile)) 230 { 231 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_CAINFO, pcszCAFile); 232 if (CURL_FAILED(rcCurl)) 233 return VERR_INTERNAL_ERROR; 234 } 219 235 220 236 RTHTTPMEMCHUNK chunk = { NULL, 0 }; -
trunk/src/VBox/Runtime/testcase/tstHttp.cpp
r43645 r45331 5 5 6 6 /* 7 * Copyright (C) 2012 Oracle Corporation7 * Copyright (C) 2012-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 31 31 #include <iprt/http.h> 32 32 #include <iprt/mem.h> 33 #include <iprt/file.h> 33 34 #include <iprt/stream.h> 35 #include <iprt/string.h> 34 36 #include <iprt/initterm.h> 35 #include <iprt/thread.h> 37 38 #define CAFILE_NAME "tstHttp-tempcafile.crt" 36 39 37 40 int main() … … 44 47 int rc = RTHttpCreate(&hHttp); 45 48 char *pszBuf = NULL; 49 PRTSTREAM CAFile = NULL; 50 51 // create certificate file 52 rc = RTStrmOpen(CAFILE_NAME, "w+b", &CAFile); 53 54 // fetch root CA certificate (new one, often avoided in cert chains by 55 // using an intermediate cert which is signed by old root) 56 if (RT_SUCCESS(rc)) 57 rc = RTHttpGet(hHttp, 58 "http://www.verisign.com/repository/roots/root-certificates/PCA-3G5.pem", 59 &pszBuf); 60 if (RT_SUCCESS(rc) && pszBuf) 61 { 62 /// @todo check certificate fingerprint against a strong hash, 63 // otherwise there's a simple way for a man-in-the-middle attack 64 rc = RTStrmWrite(CAFile, pszBuf, strlen(pszBuf)); 65 if (RT_SUCCESS(rc)) 66 rc = RTStrmWrite(CAFile, RTFILE_LINEFEED, strlen(RTFILE_LINEFEED)); 67 } 68 if (pszBuf) 69 { 70 RTMemFree(pszBuf); 71 pszBuf = NULL; 72 } 73 74 // fetch root CA certificate (old one, but still very widely used) 75 if (RT_SUCCESS(rc)) 76 rc = RTHttpGet(hHttp, 77 "http://www.verisign.com/repository/roots/root-certificates/PCA-3.pem", 78 &pszBuf); 79 if (RT_SUCCESS(rc) && pszBuf) 80 { 81 /// @todo check certificate fingerprint against a strong hash, 82 // otherwise there's a simple way for a man-in-the-middle attack 83 rc = RTStrmWrite(CAFile, pszBuf, strlen(pszBuf)); 84 if (RT_SUCCESS(rc)) 85 rc = RTStrmWrite(CAFile, RTFILE_LINEFEED, strlen(RTFILE_LINEFEED)); 86 } 87 if (pszBuf) 88 { 89 RTMemFree(pszBuf); 90 pszBuf = NULL; 91 } 92 93 // close certificate file 94 if (CAFile) 95 { 96 RTStrmClose(CAFile); 97 CAFile = NULL; 98 } 99 100 if (RT_SUCCESS(rc)) 101 rc = RTHttpSetCAFile(hHttp, CAFILE_NAME); 46 102 if (RT_SUCCESS(rc)) 47 103 rc = RTHttpGet(hHttp, … … 50 106 RTHttpDestroy(hHttp); 51 107 108 if (RT_FAILURE(rc)) 109 cErrors++; 110 52 111 RTPrintf("Error code: %Rrc\nGot: %s\n", rc, pszBuf); 53 112 RTMemFree(pszBuf); 54 113 114 // RTFileDelete(CAFILE_NAME); 115 55 116 return !!cErrors; 56 117 }
Note:
See TracChangeset
for help on using the changeset viewer.