Skip to content
Snippets Groups Projects
Commit f52d7c5f authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Fix WITHOUT_CRYPTLIB

parent 751b5891
Branches
Tags
No related merge requests found
Pipeline #8076 passed
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#ifndef WITHOUT_CRYPTLIB
#include <cryptlib.h> #include <cryptlib.h>
#endif
#include "bbslist.h" #include "bbslist.h"
#include "conn.h" #include "conn.h"
...@@ -38,7 +40,9 @@ struct http_session { ...@@ -38,7 +40,9 @@ struct http_session {
struct bbslist hacky_list_entry; struct bbslist hacky_list_entry;
struct http_cache_info cache; struct http_cache_info cache;
SOCKET sock; SOCKET sock;
#ifndef WITHOUT_CRYPTLIB
CRYPT_SESSION tls; CRYPT_SESSION tls;
#endif
bool is_tls; bool is_tls;
bool is_chunked; bool is_chunked;
bool not_modified; bool not_modified;
...@@ -100,6 +104,7 @@ recv_nbytes(struct http_session *sess, uint8_t *buf, size_t chunk_size, bool *eo ...@@ -100,6 +104,7 @@ recv_nbytes(struct http_session *sess, uint8_t *buf, size_t chunk_size, bool *eo
while (received < chunk_size) { while (received < chunk_size) {
ssize_t rc; ssize_t rc;
if (sess->is_tls) { if (sess->is_tls) {
#ifndef WITHOUT_CRYPTLIB
int copied = 0; int copied = 0;
int status = cryptPopData(sess->tls, &buf[received], chunk_size - received, &copied); int status = cryptPopData(sess->tls, &buf[received], chunk_size - received, &copied);
if (cryptStatusError(status)) { if (cryptStatusError(status)) {
...@@ -107,6 +112,7 @@ recv_nbytes(struct http_session *sess, uint8_t *buf, size_t chunk_size, bool *eo ...@@ -107,6 +112,7 @@ recv_nbytes(struct http_session *sess, uint8_t *buf, size_t chunk_size, bool *eo
goto error_return; goto error_return;
} }
rc = copied; rc = copied;
#endif
} }
else { else {
if (!socket_readable(sess->sock, 5000)) { if (!socket_readable(sess->sock, 5000)) {
...@@ -152,11 +158,13 @@ close_socket(struct http_session *sess) ...@@ -152,11 +158,13 @@ close_socket(struct http_session *sess)
static void static void
free_session(struct http_session *sess) free_session(struct http_session *sess)
{ {
#ifndef WITHOUT_CRYPTLIB
if (sess->is_tls && sess->tls != -1) { if (sess->is_tls && sess->tls != -1) {
cryptSetAttribute(sess->tls, CRYPT_SESSINFO_ACTIVE, 0); cryptSetAttribute(sess->tls, CRYPT_SESSINFO_ACTIVE, 0);
cryptDestroySession(sess->tls); cryptDestroySession(sess->tls);
sess->tls = -1; sess->tls = -1;
} }
#endif
close_socket(sess); close_socket(sess);
if (sess->cache_info) { if (sess->cache_info) {
fclose(sess->cache_info); fclose(sess->cache_info);
...@@ -228,6 +236,7 @@ send_request(struct http_session *sess) ...@@ -228,6 +236,7 @@ send_request(struct http_session *sess)
sess->cache.request_time = time(NULL); sess->cache.request_time = time(NULL);
ssize_t sent; ssize_t sent;
if (sess->is_tls) { if (sess->is_tls) {
#ifndef WITHOUT_CRYPTLIB
int copied; int copied;
int ret = cryptPushData(sess->tls, reqstr, len, &copied); int ret = cryptPushData(sess->tls, reqstr, len, &copied);
if (cryptStatusError(ret)) { if (cryptStatusError(ret)) {
...@@ -239,6 +248,7 @@ send_request(struct http_session *sess) ...@@ -239,6 +248,7 @@ send_request(struct http_session *sess)
if (cryptStatusError(ret)) { if (cryptStatusError(ret)) {
sent = -1; sent = -1;
} }
#endif
} }
else { else {
sent = send(sess->sock, reqstr, len, 0); sent = send(sess->sock, reqstr, len, 0);
...@@ -955,6 +965,7 @@ error_return: ...@@ -955,6 +965,7 @@ error_return:
static bool static bool
tls_setup(struct http_session *sess) tls_setup(struct http_session *sess)
{ {
#ifndef WITHOUT_CRYPTLIB
int status; int status;
status = cryptCreateSession(&sess->tls, CRYPT_UNUSED, CRYPT_SESSION_SSL); status = cryptCreateSession(&sess->tls, CRYPT_UNUSED, CRYPT_SESSION_SSL);
if (cryptStatusError(status)) { if (cryptStatusError(status)) {
...@@ -983,6 +994,7 @@ tls_setup(struct http_session *sess) ...@@ -983,6 +994,7 @@ tls_setup(struct http_session *sess)
return true; return true;
error_return: error_return:
#endif
return false; return false;
} }
...@@ -1114,7 +1126,9 @@ iniReadHttp(struct webget_request *req) ...@@ -1114,7 +1126,9 @@ iniReadHttp(struct webget_request *req)
struct http_session sess = { struct http_session sess = {
.sock = INVALID_SOCKET, .sock = INVALID_SOCKET,
.req = req, .req = req,
#ifndef WITHOUT_CRYPTLIB
.tls = -1, .tls = -1,
#endif
.hacky_list_entry = { .hacky_list_entry = {
.hidepopups = true, .hidepopups = true,
.address_family = PF_UNSPEC, .address_family = PF_UNSPEC,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment