]>
Commit | Line | Data |
---|---|---|
afe554c2 | 1 | /* |
33388b44 | 2 | * Copyright 2007-2020 The OpenSSL Project Authors. All Rights Reserved. |
afe554c2 DDO |
3 | * Copyright Nokia 2007-2019 |
4 | * Copyright Siemens AG 2015-2019 | |
5 | * | |
6 | * Licensed under the Apache License 2.0 (the "License"). You may not use | |
7 | * this file except in compliance with the License. You can obtain a copy | |
8 | * in the file LICENSE in the source distribution or at | |
9 | * https://www.openssl.org/source/license.html | |
10 | */ | |
11 | ||
12 | #include <string.h> | |
13 | #include <stdio.h> | |
14 | ||
15 | #include <openssl/asn1t.h> | |
16 | #include <openssl/http.h> | |
17 | #include "internal/sockets.h" | |
18 | ||
19 | #include "openssl/cmp.h" | |
20 | #include "cmp_local.h" | |
21 | ||
22 | /* explicit #includes not strictly needed since implied by the above: */ | |
23 | #include <ctype.h> | |
24 | #include <fcntl.h> | |
25 | #include <stdlib.h> | |
26 | #include <openssl/bio.h> | |
27 | #include <openssl/buffer.h> | |
28 | #include <openssl/cmp.h> | |
29 | #include <openssl/err.h> | |
30 | ||
31 | /* | |
32 | * Send the PKIMessage req and on success return the response, else NULL. | |
33 | * Any previous error queue entries will likely be removed by ERR_clear_error(). | |
34 | */ | |
35 | OSSL_CMP_MSG *OSSL_CMP_MSG_http_perform(OSSL_CMP_CTX *ctx, | |
36 | const OSSL_CMP_MSG *req) | |
37 | { | |
4b1fe471 | 38 | char server_port[32] = { '\0' }; |
afe554c2 | 39 | STACK_OF(CONF_VALUE) *headers = NULL; |
afe554c2 | 40 | const char *const content_type_pkix = "application/pkixcmp"; |
1a5ae1da | 41 | int tls_used; |
4b1fe471 | 42 | OSSL_CMP_MSG *res; |
afe554c2 | 43 | |
4b1fe471 | 44 | if (ctx == NULL || req == NULL) { |
afe554c2 | 45 | CMPerr(0, CMP_R_NULL_ARGUMENT); |
4b1fe471 | 46 | return NULL; |
afe554c2 DDO |
47 | } |
48 | ||
49 | if (!X509V3_add_value("Pragma", "no-cache", &headers)) | |
50 | return NULL; | |
51 | ||
4b1fe471 DDO |
52 | if (ctx->serverPort != 0) |
53 | BIO_snprintf(server_port, sizeof(server_port), "%d", ctx->serverPort); | |
afe554c2 | 54 | |
1a5ae1da DDO |
55 | tls_used = OSSL_CMP_CTX_get_http_cb_arg(ctx) != NULL; |
56 | ossl_cmp_log2(DEBUG, ctx, "connecting to CMP server %s%s", | |
57 | ctx->server, tls_used ? " using TLS" : ""); | |
afe554c2 | 58 | res = (OSSL_CMP_MSG *) |
4b1fe471 | 59 | OSSL_HTTP_post_asn1(ctx->server, server_port, ctx->serverPath, |
1a5ae1da | 60 | tls_used, ctx->proxy, ctx->no_proxy, NULL, NULL, |
afe554c2 | 61 | ctx->http_cb, OSSL_CMP_CTX_get_http_cb_arg(ctx), |
9253f834 DDO |
62 | headers, content_type_pkix, (const ASN1_VALUE *)req, |
63 | ASN1_ITEM_rptr(OSSL_CMP_MSG), | |
afe554c2 DDO |
64 | 0, 0, ctx->msg_timeout, content_type_pkix, |
65 | ASN1_ITEM_rptr(OSSL_CMP_MSG)); | |
1a5ae1da | 66 | ossl_cmp_debug(ctx, "disconnected from CMP server"); |
afe554c2 DDO |
67 | sk_CONF_VALUE_pop_free(headers, X509V3_conf_free); |
68 | return res; | |
69 | } |