/*
- * Copyright (c) 2014 Samsung Electronics Co.
+ * Copyright (c) 2014 - 2019 Samsung Electronics Co.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <openssl/ssl.h>
#include <fts.h>
#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
#include <dpl/log/log.h>
#include <certificate-impl.h>
#include <openssl_utils.h>
namespace CKM {
namespace {
+const char *const HTTP_PREFIX = "http://";
+const size_t HTTP_PREFIX_LEN = sizeof(HTTP_PREFIX) / sizeof(HTTP_PREFIX[0]);
+const char *const HTTPS_PREFIX = "https://";
+const size_t HTTPS_PREFIX_LEN = sizeof(HTTPS_PREFIX) / sizeof(HTTPS_PREFIX[0]);
+
typedef std::unique_ptr<BIO, std::function<void(BIO *)>> BioUniquePtr;
void BIO_write_and_free(BIO *bio)
LogDebug("Using proxy: " << proxy.get());
+ if (strncmp(HTTP_PREFIX, proxy.get(), HTTP_PREFIX_LEN) != 0 &&
+ strncmp(HTTPS_PREFIX, proxy.get(), HTTPS_PREFIX_LEN) != 0) {
+ LogDebug("No http/https prefix. Assuming http.");
+ char *tmp = NULL;
+ if (asprintf(&tmp, "%s%s", HTTP_PREFIX, proxy.get()) == -1) {
+ LogError("Http prefix application failed.");
+ return CKM_API_OCSP_STATUS_INTERNAL_ERROR;
+ }
+ proxy.reset(tmp);
+ }
+
if (!OCSP_parse_url(proxy.get(), &phost, &pport, &ppath, &use_ssl)) {
return CKM_API_OCSP_STATUS_INVALID_URL;
}