8
8
#include < curl/curl.h>
9
9
#include < string>
10
10
#include " typtopconfig.h"
11
- #include " plog/Log .h"
11
+ #include " typtop .h"
12
12
13
13
using namespace std ;
14
14
15
15
16
16
// const string url = "https://ec2-54-209-30-18.compute-1.amazonaws.com/submit";
17
17
const string url = UPLOAD_URL;
18
- const string key = " a40648638b48abf2159f9331cbab9cb3ae81d8cd247c145942c3cce9c708ae89" ;
18
+ // sha256 of the the private key of the server -- a shared secret
19
+ // Doesn't provide much security, except some attacker who are just want to spoof the server.
20
+ // The dedicated attacker can just read the source code and fill my data with garbage.
21
+ const string key = " 82e4ae0301ea4ef8db76945666f08d1b5ffef2ae0f27737889d2d21e32ee7e54" ;
22
+
19
23
/* *
20
24
* Sends the data to the amazon server. It assumes all the fields are url encoded,
21
25
* and will not try to encode.
@@ -25,7 +29,7 @@ const string key = "a40648638b48abf2159f9331cbab9cb3ae81d8cd247c145942c3cce9c70
25
29
* @return : success code
26
30
*/
27
31
28
- int send_log_to_server (const string uid, const string log, int test= 1 ) {
32
+ int send_log_to_server (const string uid, const string log, int test) {
29
33
CURL *curl;
30
34
CURLcode res = CURLE_SEND_ERROR;
31
35
// struct curl_slist *headers = NULL; /* http headers to send with request */
@@ -47,22 +51,19 @@ int send_log_to_server(const string uid, const string log, int test=1) {
47
51
curl = curl_easy_init ();
48
52
FILE *devnull = fopen (" /dev/null" , " w" );
49
53
if (curl) {
54
+ curl_easy_setopt (curl, CURLOPT_WRITEDATA, devnull);
50
55
curl_easy_setopt (curl, CURLOPT_URL, url.c_str ());
56
+
51
57
/* Now specify the POST data */
52
58
curl_easy_setopt (curl, CURLOPT_POSTFIELDSIZE, payload.size ());
53
59
curl_easy_setopt (curl, CURLOPT_POSTFIELDS, payload.c_str ());
54
- /* Add the certificate */
55
- // curl_easy_setopt(curl, CURLOPT_CAINFO, CAFILE);
56
-
57
- // Till I can fix this weird bug
58
- curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0L );
59
- curl_easy_setopt (curl, CURLOPT_WRITEDATA, devnull);
60
60
61
+ curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 1L );
61
62
62
63
/* set content type */
63
- // headers = curl_slist_append(headers, "Accept: application/json");
64
- // headers = curl_slist_append(headers, "Content-Type: application/json");
65
- // curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
64
+ /* headers = curl_slist_append(headers, "Accept: application/json"); */
65
+ /* headers = curl_slist_append(headers, "Content-Type: application/json"); */
66
+ /* curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); */
66
67
67
68
/* set timeout */
68
69
curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 1L );
@@ -72,16 +73,12 @@ int send_log_to_server(const string uid, const string log, int test=1) {
72
73
res = curl_easy_perform (curl);
73
74
/* Check for errors */
74
75
if (res != CURLE_OK){
75
- LOG_ERROR << " curl_easy_perform() failed: " << curl_easy_strerror (res);
76
- // // try old cert once
77
- // curl_easy_setopt(curl, CURLOPT_CAINFO, OLD_CAFILE);
78
- // res = curl_easy_perform(curl);
79
- // if(res != CURLE_OK){
80
- // LOG_ERROR << "curl_easy_perform() failed: "<< curl_easy_strerror(res)
81
- // << "\nCAFILE: " << OLD_CAFILE << endl;
82
- // }
83
- } else
76
+ LOG_DEBUG << " curl_easy_perform() failed: " << curl_easy_strerror (res);
77
+ } else {
84
78
curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &response_code);
79
+ LOG_DEBUG << " CURL response code: " << response_code;
80
+ }
81
+
85
82
86
83
/* always cleanup */
87
84
curl_easy_cleanup (curl);
0 commit comments