summaryrefslogtreecommitdiff
path: root/src/gmrequest.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-08-03 18:27:45 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-08-03 18:27:45 +0300
commitc5f7132d637f0186433cccb4da7b9283a4dd5d9a (patch)
treec5e912733437e307fb894366cc8bf648776a53ce /src/gmrequest.c
parent8f62f251ee5e49447c0950719ba6629bc1a23257 (diff)
GmCerts: Thread safety; fixed notifications
Must update the status before notifying.
Diffstat (limited to 'src/gmrequest.c')
-rw-r--r--src/gmrequest.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/gmrequest.c b/src/gmrequest.c
index dc08d23b..c0697f49 100644
--- a/src/gmrequest.c
+++ b/src/gmrequest.c
@@ -98,6 +98,25 @@ static void restartTimeout_GmRequest_(iGmRequest *d) {
98 d->timeoutId = SDL_AddTimer(BODY_TIMEOUT, timedOutWhileReceivingBody_GmRequest_, d); 98 d->timeoutId = SDL_AddTimer(BODY_TIMEOUT, timedOutWhileReceivingBody_GmRequest_, d);
99} 99}
100 100
101static void checkServerCertificate_GmRequest_(iGmRequest *d) {
102 const iTlsCertificate *cert = serverCertificate_TlsRequest(d->req);
103 d->certFlags = 0;
104 if (cert) {
105 iGmCerts * certDb = certs_App();
106 const iRangecc domain = urlHost_String(&d->url);
107 d->certFlags |= available_GmRequestCertFlag;
108 if (!isExpired_TlsCertificate(cert)) {
109 d->certFlags |= timeVerified_GmRequestCertFlag;
110 }
111 if (verifyDomain_TlsCertificate(cert, domain)) {
112 d->certFlags |= domainVerified_GmRequestCertFlag;
113 }
114 if (checkTrust_GmCerts(certDb, domain, cert)) {
115 d->certFlags |= trusted_GmRequestCertFlag;
116 }
117 }
118}
119
101static void readIncoming_GmRequest_(iAnyObject *obj) { 120static void readIncoming_GmRequest_(iAnyObject *obj) {
102 iGmRequest *d = (iGmRequest *) obj; 121 iGmRequest *d = (iGmRequest *) obj;
103 iBool notifyUpdate = iFalse; 122 iBool notifyUpdate = iFalse;
@@ -136,6 +155,7 @@ static void readIncoming_GmRequest_(iAnyObject *obj) {
136 } 155 }
137 d->code = code; 156 d->code = code;
138 d->state = receivingBody_GmRequestState; 157 d->state = receivingBody_GmRequestState;
158 checkServerCertificate_GmRequest_(d);
139 notifyUpdate = iTrue; 159 notifyUpdate = iTrue;
140 /* Start a timeout for the remainder of the response, in case the connection 160 /* Start a timeout for the remainder of the response, in case the connection
141 remains open. */ 161 remains open. */
@@ -168,23 +188,7 @@ static void requestFinished_GmRequest_(iAnyObject *obj) {
168 SDL_RemoveTimer(d->timeoutId); 188 SDL_RemoveTimer(d->timeoutId);
169 d->timeoutId = 0; 189 d->timeoutId = 0;
170 d->state = finished_GmRequestState; 190 d->state = finished_GmRequestState;
171 d->certFlags = 0; 191 checkServerCertificate_GmRequest_(d);
172 /* Check the server certificate. */ {
173 const iTlsCertificate *cert = serverCertificate_TlsRequest(d->req);
174 if (cert) {
175 iGmCerts * certDb = certs_App();
176 const iRangecc domain = urlHost_String(&d->url);
177 d->certFlags |= available_GmRequestCertFlag;
178 if (!isExpired_TlsCertificate(cert)) {
179 d->certFlags |= timeVerified_GmRequestCertFlag;
180 }
181 if (verifyDomain_TlsCertificate(cert, domain)) {
182 d->certFlags |= domainVerified_GmRequestCertFlag;
183 }
184 if (checkTrust_GmCerts(certDb, domain, cert)) {
185 d->certFlags |= trusted_GmRequestCertFlag;
186 }
187 }
188#if 0 192#if 0
189 printf("Server certificate:\n%s\n", cstrLocal_String(pem_TlsCertificate(cert))); 193 printf("Server certificate:\n%s\n", cstrLocal_String(pem_TlsCertificate(cert)));
190 iBlock *sha = fingerprint_TlsCertificate(cert); 194 iBlock *sha = fingerprint_TlsCertificate(cert);
@@ -205,7 +209,6 @@ static void requestFinished_GmRequest_(iAnyObject *obj) {
205 } 209 }
206 fflush(stdout); 210 fflush(stdout);
207#endif 211#endif
208 }
209 unlock_Mutex(&d->mutex); 212 unlock_Mutex(&d->mutex);
210 iNotifyAudience(d, finished, GmRequestFinished); 213 iNotifyAudience(d, finished, GmRequestFinished);
211} 214}
@@ -218,6 +221,7 @@ void submit_GmRequest(iGmRequest *d) {
218 d->code = none_GmStatusCode; 221 d->code = none_GmStatusCode;
219 clear_String(&d->header); 222 clear_String(&d->header);
220 clear_Block(&d->body); 223 clear_Block(&d->body);
224 d->certFlags = 0;
221 iUrl url; 225 iUrl url;
222 init_Url(&url, &d->url); 226 init_Url(&url, &d->url);
223 if (equalCase_Rangecc(&url.protocol, "file")) { 227 if (equalCase_Rangecc(&url.protocol, "file")) {