A local copy of OpenSSL from GitHub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.4 KiB

  1. /*
  2. * Copyright 2007-2020 The OpenSSL Project Authors. All Rights Reserved.
  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. #include <string.h>
  12. #include <stdio.h>
  13. #include <openssl/asn1t.h>
  14. #include <openssl/http.h>
  15. #include "internal/sockets.h"
  16. #include "openssl/cmp.h"
  17. #include "cmp_local.h"
  18. /* explicit #includes not strictly needed since implied by the above: */
  19. #include <ctype.h>
  20. #include <fcntl.h>
  21. #include <stdlib.h>
  22. #include <openssl/bio.h>
  23. #include <openssl/buffer.h>
  24. #include <openssl/cmp.h>
  25. #include <openssl/err.h>
  26. /*
  27. * Send the PKIMessage req and on success return the response, else NULL.
  28. * Any previous error queue entries will likely be removed by ERR_clear_error().
  29. */
  30. OSSL_CMP_MSG *OSSL_CMP_MSG_http_perform(OSSL_CMP_CTX *ctx,
  31. const OSSL_CMP_MSG *req)
  32. {
  33. char server_port[32] = { '\0' };
  34. STACK_OF(CONF_VALUE) *headers = NULL;
  35. const char *const content_type_pkix = "application/pkixcmp";
  36. int tls_used;
  37. OSSL_CMP_MSG *res;
  38. if (ctx == NULL || req == NULL) {
  39. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  40. return NULL;
  41. }
  42. if (!X509V3_add_value("Pragma", "no-cache", &headers))
  43. return NULL;
  44. if (ctx->serverPort != 0)
  45. BIO_snprintf(server_port, sizeof(server_port), "%d", ctx->serverPort);
  46. tls_used = OSSL_CMP_CTX_get_http_cb_arg(ctx) != NULL;
  47. ossl_cmp_log2(DEBUG, ctx, "connecting to CMP server %s%s",
  48. ctx->server, tls_used ? " using TLS" : "");
  49. res = (OSSL_CMP_MSG *)
  50. OSSL_HTTP_post_asn1(ctx->server, server_port, ctx->serverPath,
  51. tls_used, ctx->proxy, ctx->no_proxy, NULL, NULL,
  52. ctx->http_cb, OSSL_CMP_CTX_get_http_cb_arg(ctx),
  53. headers, content_type_pkix, (const ASN1_VALUE *)req,
  54. ASN1_ITEM_rptr(OSSL_CMP_MSG),
  55. 0, 0, ctx->msg_timeout, content_type_pkix,
  56. ASN1_ITEM_rptr(OSSL_CMP_MSG));
  57. ossl_cmp_debug(ctx, "disconnected from CMP server");
  58. sk_CONF_VALUE_pop_free(headers, X509V3_conf_free);
  59. return res;
  60. }