Skip to content

Commit 723a856

Browse files
committed
Disable keep-alive and remove the shutdown workaround.
Some RFC 3161 TSA servers (e.g. time.certum.pl) advertise "Connection: close" but delay closing the connection, when keep-alive was requested. The client waited for EOF and attempted to work around this by explicitly shutting down the socket.
1 parent 988f722 commit 723a856

File tree

1 file changed

+8
-36
lines changed

1 file changed

+8
-36
lines changed

osslsigncode.c

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -798,63 +798,37 @@ static int verify_callback(int ok, X509_STORE_CTX *ctx)
798798
/*
799799
* Read data from socket BIO
800800
* [in] s_bio: socket BIO
801-
* [in] rctx: open connection context
802-
* [in] use_ssl: HTTPS request switch
803801
* [returns] memory BIO
804802
*/
805-
static BIO *socket_bio_read(BIO *s_bio, OSSL_HTTP_REQ_CTX *rctx, int use_ssl)
803+
static BIO *socket_bio_read(BIO *s_bio)
806804
{
807-
int retry = 1, ok = 0, written = 0, resp_len = 0;
805+
int retry = 1, ok = 0;
808806
char *buf = OPENSSL_malloc(OSSL_HTTP_DEFAULT_MAX_RESP_LEN);
809807
BIO *resp = BIO_new(BIO_s_mem());
810808

811-
if (rctx) {
812-
resp_len = (int)OSSL_HTTP_REQ_CTX_get_resp_len(rctx);
813-
}
814-
if (resp_len == 0) {
815-
if (use_ssl)
816-
BIO_ssl_shutdown(s_bio);
817-
else {
818-
int fd = (int)BIO_get_fd(s_bio, NULL);
819-
820-
if (fd >= 0) {
821-
#ifdef WIN32
822-
(void)shutdown(fd, SD_SEND);
823-
#else /* WIN32 */
824-
(void)shutdown(fd, SHUT_WR);
825-
#endif /* WIN32 */
826-
}
827-
}
828-
}
829-
ERR_clear_error();
830809
while (retry) {
831810
int n;
832811

833812
errno = 0;
834813
n = BIO_read(s_bio, buf, OSSL_HTTP_DEFAULT_MAX_RESP_LEN);
835814
if (n > 0) {
836-
written += BIO_write(resp, buf, n);
815+
(void)BIO_write(resp, buf, n);
837816
} else if (BIO_eof(s_bio) == 1) {
838817
ok = 1;
839-
retry = 0; /* EOF */
818+
retry = 0; /* HTTP EOF */
840819
} else if (BIO_should_retry(s_bio)) {
841820
} else {
842821
unsigned long err = ERR_get_error();
843822

844823
if (err == 0) {
845824
ok = 1;
846-
retry = 0; /* use_ssl EOF */
825+
retry = 0; /* HTTPS EOF */
847826
} else {
848827
fprintf(stderr, "\nHTTP failure: error %ld: %s\n", err, ERR_reason_error_string(err));
849828
retry = 0; /* FAILED */
850829
}
851830
}
852-
if (resp_len > 0 && resp_len == written) {
853-
ok = 1;
854-
retry = 0; /* all response has been read */
855-
}
856831
}
857-
OSSL_HTTP_close(rctx, ok);
858832
OPENSSL_free(buf);
859833
if (!ok) {
860834
BIO_free_all(resp);
@@ -916,12 +890,10 @@ static void check_authenticode_timestamp(BIO **resp)
916890
static BIO *bio_get_http(char *url, BIO *req, char *proxy, int rfc3161, char *cafile, char *crlfile)
917891
{
918892
BIO *tmp_bio = NULL, *s_bio = NULL, *resp = NULL;
919-
OSSL_HTTP_REQ_CTX *rctx = NULL;
920893
HTTP_TLS_Info info;
921894
SSL_CTX *ssl_ctx = NULL;
922895
char *server = NULL, *port = NULL, *path = NULL;
923896
int timeout = -1; /* blocking mode, exactly one try, see BIO_do_connect_retry() */
924-
int keep_alive = 1; /* prefer */
925897
int use_ssl = 0;
926898

927899
if (!url) {
@@ -975,9 +947,9 @@ static BIO *bio_get_http(char *url, BIO *req, char *proxy, int rfc3161, char *ca
975947
content_type = "application/octet-stream"; /* Authenticode Timestamp */
976948
expected_content_type = "application/octet-stream";
977949
}
978-
s_bio = OSSL_HTTP_transfer(&rctx, server, port, path, use_ssl, proxy, NULL,
950+
s_bio = OSSL_HTTP_transfer(NULL, server, port, path, use_ssl, proxy, NULL,
979951
NULL, NULL, http_tls_cb, &info, 0, NULL, content_type, req,
980-
expected_content_type, 0, 0, timeout, keep_alive);
952+
expected_content_type, 0, 0, timeout, 0);
981953
BIO_free(tmp_bio);
982954
}
983955
OPENSSL_free(server);
@@ -986,7 +958,7 @@ static BIO *bio_get_http(char *url, BIO *req, char *proxy, int rfc3161, char *ca
986958
SSL_CTX_free(ssl_ctx);
987959

988960
if (s_bio) {
989-
resp = socket_bio_read(s_bio, rctx, use_ssl);
961+
resp = socket_bio_read(s_bio);
990962
BIO_free_all(s_bio);
991963
if (resp && req && !rfc3161)
992964
check_authenticode_timestamp(&resp);

0 commit comments

Comments
 (0)