2020-02-20 01:00:26 +08:00
|
|
|
/*
|
2020-04-23 20:55:52 +08:00
|
|
|
* Copyright 2007-2020 The OpenSSL Project Authors. All Rights Reserved.
|
2020-02-20 01:00:26 +08:00
|
|
|
* Copyright Nokia 2007-2019
|
|
|
|
* Copyright Siemens AG 2015-2019
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <openssl/asn1t.h>
|
|
|
|
#include <openssl/http.h>
|
|
|
|
#include "internal/sockets.h"
|
|
|
|
|
|
|
|
#include "openssl/cmp.h"
|
|
|
|
#include "cmp_local.h"
|
|
|
|
|
|
|
|
/* explicit #includes not strictly needed since implied by the above: */
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <openssl/bio.h>
|
|
|
|
#include <openssl/buffer.h>
|
|
|
|
#include <openssl/cmp.h>
|
|
|
|
#include <openssl/err.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send the PKIMessage req and on success return the response, else NULL.
|
|
|
|
* Any previous error queue entries will likely be removed by ERR_clear_error().
|
|
|
|
*/
|
|
|
|
OSSL_CMP_MSG *OSSL_CMP_MSG_http_perform(OSSL_CMP_CTX *ctx,
|
|
|
|
const OSSL_CMP_MSG *req)
|
|
|
|
{
|
2020-03-25 20:46:02 +08:00
|
|
|
char server_port[32] = { '\0' };
|
2020-02-20 01:00:26 +08:00
|
|
|
STACK_OF(CONF_VALUE) *headers = NULL;
|
|
|
|
const char *const content_type_pkix = "application/pkixcmp";
|
2020-08-26 16:11:14 +08:00
|
|
|
int tls_used;
|
2020-03-25 20:46:02 +08:00
|
|
|
OSSL_CMP_MSG *res;
|
2020-02-20 01:00:26 +08:00
|
|
|
|
2020-03-25 20:46:02 +08:00
|
|
|
if (ctx == NULL || req == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
|
2020-03-25 20:46:02 +08:00
|
|
|
return NULL;
|
2020-02-20 01:00:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!X509V3_add_value("Pragma", "no-cache", &headers))
|
|
|
|
return NULL;
|
|
|
|
|
2020-03-25 20:46:02 +08:00
|
|
|
if (ctx->serverPort != 0)
|
|
|
|
BIO_snprintf(server_port, sizeof(server_port), "%d", ctx->serverPort);
|
2020-02-20 01:00:26 +08:00
|
|
|
|
2020-08-26 16:11:14 +08:00
|
|
|
tls_used = OSSL_CMP_CTX_get_http_cb_arg(ctx) != NULL;
|
|
|
|
ossl_cmp_log2(DEBUG, ctx, "connecting to CMP server %s%s",
|
|
|
|
ctx->server, tls_used ? " using TLS" : "");
|
2020-02-20 01:00:26 +08:00
|
|
|
res = (OSSL_CMP_MSG *)
|
2020-03-25 20:46:02 +08:00
|
|
|
OSSL_HTTP_post_asn1(ctx->server, server_port, ctx->serverPath,
|
2020-08-26 16:11:14 +08:00
|
|
|
tls_used, ctx->proxy, ctx->no_proxy, NULL, NULL,
|
2020-02-20 01:00:26 +08:00
|
|
|
ctx->http_cb, OSSL_CMP_CTX_get_http_cb_arg(ctx),
|
2020-05-05 01:54:43 +08:00
|
|
|
headers, content_type_pkix, (const ASN1_VALUE *)req,
|
|
|
|
ASN1_ITEM_rptr(OSSL_CMP_MSG),
|
2020-02-20 01:00:26 +08:00
|
|
|
0, 0, ctx->msg_timeout, content_type_pkix,
|
|
|
|
ASN1_ITEM_rptr(OSSL_CMP_MSG));
|
2020-08-26 16:11:14 +08:00
|
|
|
ossl_cmp_debug(ctx, "disconnected from CMP server");
|
2020-02-20 01:00:26 +08:00
|
|
|
sk_CONF_VALUE_pop_free(headers, X509V3_conf_free);
|
|
|
|
return res;
|
|
|
|
}
|