2016-05-18 02:52:22 +08:00
|
|
|
/*
|
2023-09-07 16:59:15 +08:00
|
|
|
* Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 18:52:47 +08:00
|
|
|
*
|
2018-12-06 21:00:36 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:52:22 +08:00
|
|
|
* 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
|
1998-12-21 18:52:47 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2024-06-07 02:38:43 +08:00
|
|
|
#include "internal/e_os.h"
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
2024-06-07 02:38:43 +08:00
|
|
|
#include "internal/thread_once.h"
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/crypto.h>
|
|
|
|
#include <openssl/x509.h>
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2024-06-07 02:38:43 +08:00
|
|
|
#if defined(_WIN32)
|
|
|
|
|
|
|
|
static char x509_private_dir[MAX_PATH + 1];
|
2024-06-25 22:57:52 +08:00
|
|
|
static char *x509_private_dirptr = NULL;
|
|
|
|
|
2024-06-07 02:38:43 +08:00
|
|
|
static char x509_cert_area[MAX_PATH + 1];
|
2024-06-25 22:57:52 +08:00
|
|
|
static char *x509_cert_areaptr = NULL;
|
|
|
|
|
2024-06-07 02:38:43 +08:00
|
|
|
static char x509_cert_dir[MAX_PATH + 1];
|
2024-06-25 22:57:52 +08:00
|
|
|
static char *x509_cert_dirptr = NULL;
|
|
|
|
|
2024-06-07 02:38:43 +08:00
|
|
|
static char x509_cert_file[MAX_PATH + 1];
|
2024-06-25 22:57:52 +08:00
|
|
|
static char *x509_cert_fileptr = NULL;
|
2024-06-07 02:38:43 +08:00
|
|
|
|
|
|
|
static void get_windows_default_path(char *pathname, const char *suffix)
|
|
|
|
{
|
|
|
|
char *ossldir;
|
|
|
|
|
|
|
|
ossldir = ossl_get_openssldir();
|
|
|
|
|
2024-06-25 22:57:52 +08:00
|
|
|
if (ossldir == NULL)
|
|
|
|
return;
|
|
|
|
|
2024-06-07 02:38:43 +08:00
|
|
|
OPENSSL_strlcpy(pathname, ossldir, MAX_PATH - 1);
|
|
|
|
if (MAX_PATH - strlen(pathname) > strlen(suffix))
|
|
|
|
strcat(pathname, suffix);
|
|
|
|
}
|
|
|
|
|
|
|
|
static CRYPTO_ONCE openssldir_setup_init = CRYPTO_ONCE_STATIC_INIT;
|
|
|
|
DEFINE_RUN_ONCE_STATIC(do_openssldir_setup)
|
|
|
|
{
|
|
|
|
get_windows_default_path(x509_private_dir, "\\private");
|
2024-06-25 22:57:52 +08:00
|
|
|
if (strlen(x509_private_dir) > 0)
|
|
|
|
x509_private_dirptr = x509_private_dir;
|
|
|
|
|
2024-06-07 02:38:43 +08:00
|
|
|
get_windows_default_path(x509_cert_area, "\\");
|
2024-06-25 22:57:52 +08:00
|
|
|
if (strlen(x509_cert_area) > 0)
|
|
|
|
x509_cert_areaptr = x509_cert_area;
|
|
|
|
|
2024-06-07 02:38:43 +08:00
|
|
|
get_windows_default_path(x509_cert_dir, "\\certs");
|
2024-06-25 22:57:52 +08:00
|
|
|
if (strlen(x509_cert_dir) > 0)
|
|
|
|
x509_cert_dirptr = x509_cert_dir;
|
|
|
|
|
2024-06-07 02:38:43 +08:00
|
|
|
get_windows_default_path(x509_cert_file, "\\cert.pem");
|
2024-06-25 22:57:52 +08:00
|
|
|
if (strlen(x509_cert_file) > 0)
|
|
|
|
x509_cert_fileptr = x509_cert_file;
|
|
|
|
|
2024-06-07 02:38:43 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
const char *X509_get_default_private_dir(void)
|
1998-12-21 18:52:47 +08:00
|
|
|
{
|
2024-06-07 02:38:43 +08:00
|
|
|
#if defined (_WIN32)
|
|
|
|
RUN_ONCE(&openssldir_setup_init, do_openssldir_setup);
|
2024-06-25 22:57:52 +08:00
|
|
|
return x509_private_dirptr;
|
2024-06-07 02:38:43 +08:00
|
|
|
#else
|
2017-10-17 22:04:09 +08:00
|
|
|
return X509_PRIVATE_DIR;
|
2024-06-07 02:38:43 +08:00
|
|
|
#endif
|
1998-12-21 18:52:47 +08:00
|
|
|
}
|
2015-01-22 11:40:55 +08:00
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
const char *X509_get_default_cert_area(void)
|
1998-12-21 18:52:47 +08:00
|
|
|
{
|
2024-06-07 02:38:43 +08:00
|
|
|
#if defined (_WIN32)
|
|
|
|
RUN_ONCE(&openssldir_setup_init, do_openssldir_setup);
|
2024-06-25 22:57:52 +08:00
|
|
|
return x509_cert_areaptr;
|
2024-06-07 02:38:43 +08:00
|
|
|
#else
|
2017-10-17 22:04:09 +08:00
|
|
|
return X509_CERT_AREA;
|
2024-06-07 02:38:43 +08:00
|
|
|
#endif
|
1998-12-21 18:52:47 +08:00
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
const char *X509_get_default_cert_dir(void)
|
1998-12-21 18:52:47 +08:00
|
|
|
{
|
2024-06-07 02:38:43 +08:00
|
|
|
#if defined (_WIN32)
|
|
|
|
RUN_ONCE(&openssldir_setup_init, do_openssldir_setup);
|
2024-06-25 22:57:52 +08:00
|
|
|
return x509_cert_dirptr;
|
2024-06-07 02:38:43 +08:00
|
|
|
#else
|
2017-10-17 22:04:09 +08:00
|
|
|
return X509_CERT_DIR;
|
2024-06-07 02:38:43 +08:00
|
|
|
#endif
|
1998-12-21 18:52:47 +08:00
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
const char *X509_get_default_cert_file(void)
|
1998-12-21 18:52:47 +08:00
|
|
|
{
|
2024-06-07 02:38:43 +08:00
|
|
|
#if defined (_WIN32)
|
|
|
|
RUN_ONCE(&openssldir_setup_init, do_openssldir_setup);
|
2024-06-25 22:57:52 +08:00
|
|
|
return x509_cert_fileptr;
|
2024-06-07 02:38:43 +08:00
|
|
|
#else
|
2017-10-17 22:04:09 +08:00
|
|
|
return X509_CERT_FILE;
|
2024-06-07 02:38:43 +08:00
|
|
|
#endif
|
1998-12-21 18:52:47 +08:00
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
const char *X509_get_default_cert_dir_env(void)
|
1998-12-21 18:52:47 +08:00
|
|
|
{
|
2017-10-17 22:04:09 +08:00
|
|
|
return X509_CERT_DIR_EVP;
|
1998-12-21 18:52:47 +08:00
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
const char *X509_get_default_cert_file_env(void)
|
1998-12-21 18:52:47 +08:00
|
|
|
{
|
2017-10-17 22:04:09 +08:00
|
|
|
return X509_CERT_FILE_EVP;
|
1998-12-21 18:52:47 +08:00
|
|
|
}
|