SSL mit Curt
-
Hi
Ich möchte eine SSL Verbindung auf swisscom-mobile.ch herstellen und dort eine POST-Anfrage ausführen. Das Resultat möchte ich dann Ausgeben.
Mein Problem ist nun, dass es irgendwie nicht wirklich funktioniert!
Sobald die Anfrage gesendet wurde gibt mir CURL den Fehler zurück, dass es ein Problem mit dem lokalen SSL-Zertifikat hat! Kann mir jemand helfen, was ich ändern muss oder noch hinzufügen muss???Hier mein Code:
const char *pEngine; const char *pCertFile = "testcert.pem"; const char *pCACertFile="cacert.pem"; const char *pKeyName; const char *pKeyType; const char *pPassphrase = NULL; #if USE_ENGINE pKeyName = "rsa_test"; pKeyType = "ENG"; pEngine = "chil"; /* for nChiper HSM... */ #else pKeyName = "testkey.pem"; pKeyType = "PEM"; pEngine = NULL; #endif CURL *curl_post; CURLcode res; curl_slist *cookieptr; CString cookieid; CString buffer; buffer=""; curl_post = curl_easy_init(); if(curl_post) { curl_easy_setopt(curl_post, CURLOPT_URL, "https://www.swisscom-mobile.ch/youth/youth_zone_home-de.aspx?login"); curl_easy_setopt(curl_post, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6"); curl_easy_setopt(curl_post, CURLOPT_POSTFIELDS, "isiwebuserid=UID&isiwebpasswd=PW"); curl_easy_setopt(curl_post, CURLOPT_COOKIEFILE, ""); curl_easy_setopt(curl_post, CURLOPT_HEADER, 1); curl_easy_setopt(curl_post, CURLOPT_WRITEFUNCTION, writer); curl_easy_setopt(curl_post, CURLOPT_WRITEDATA, &buffer); if (pEngine) /* use crypto engine */ { if (curl_easy_setopt(curl_post, CURLOPT_SSLENGINE,pEngine) != CURLE_OK) { /* load the crypto engine */ fprintf(stderr,"can't set crypto engine\n"); } if (curl_easy_setopt(curl_post, CURLOPT_SSLENGINE_DEFAULT,1) != CURLE_OK) { /* set the crypto engine as default */ /* only needed for the first time you load a engine in a curl object... */ fprintf(stderr,"can't set crypto engine as default\n"); } } /* cert is stored PEM coded in file... */ /* since PEM is default, we needn't set it for PEM */ curl_easy_setopt(curl_post,CURLOPT_SSLCERTTYPE,"PEM"); /* set the cert for client authentication */ curl_easy_setopt(curl_post,CURLOPT_SSLCERT,pCertFile); /* sorry, for engine we must set the passphrase (if the key has one...) */ if (pPassphrase) curl_easy_setopt(curl_post,CURLOPT_SSLKEYPASSWD,pPassphrase); /* if we use a key stored in a crypto engine, we must set the key type to "ENG" */ curl_easy_setopt(curl_post,CURLOPT_SSLKEYTYPE,pKeyType); /* set the private key (file or ID in engine) */ curl_easy_setopt(curl_post,CURLOPT_SSLKEY,pKeyName); /* set the file with the certs vaildating the server */ curl_easy_setopt(curl_post,CURLOPT_CAINFO,pCACertFile); /* disconnect if we can't validate server's cert */ curl_easy_setopt(curl_post,CURLOPT_SSL_VERIFYPEER,1); res = curl_easy_perform(curl_post); if(res != CURLE_OK) { curl_easy_cleanup(curl_post); AfxMessageBox(curl_easy_strerror(res)); } AfxMessageBox(buffer); /* always cleanup */ curl_easy_cleanup(curl_post); }Vielen Dank für eure Hilfe!