Added path_to_plain_ascii for use by driver-ssl
This commit is contained in:
@@ -32,6 +32,16 @@ const int INVALID_SOCKET = -1;
|
|||||||
|
|
||||||
struct termios orig_termios;
|
struct termios orig_termios;
|
||||||
|
|
||||||
|
// OpenSSL requires plain ascii pathnames. Returns empty string
|
||||||
|
// if the path cannot be converted to plain ascii.
|
||||||
|
std::string path_to_plain_ascii(const std::filesystem::path &path) {
|
||||||
|
std::string s = path.native();
|
||||||
|
for (char c : s) {
|
||||||
|
if ((c < 1) || (c > 127)) return "";
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
std::string strerror_str(int err) {
|
std::string strerror_str(int err) {
|
||||||
char errbuf[256];
|
char errbuf[256];
|
||||||
return strerror_r(err, errbuf, 256);
|
return strerror_r(err, errbuf, 256);
|
||||||
|
|||||||
@@ -8,13 +8,13 @@
|
|||||||
#include "driver-util.hpp"
|
#include "driver-util.hpp"
|
||||||
#include "driver-ssl.hpp"
|
#include "driver-ssl.hpp"
|
||||||
#include "drivenengine.hpp"
|
#include "drivenengine.hpp"
|
||||||
#include "util.hpp"
|
|
||||||
#include "source.hpp"
|
#include "source.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
@@ -29,6 +29,20 @@
|
|||||||
#include <openssl/bio.h>
|
#include <openssl/bio.h>
|
||||||
#include <openssl/pem.h>
|
#include <openssl/pem.h>
|
||||||
|
|
||||||
|
// OpenSSL requires plain ascii pathnames. Returns empty string
|
||||||
|
// if the path cannot be converted to plain ascii.
|
||||||
|
std::string path_to_plain_ascii(const std::filesystem::path &path) {
|
||||||
|
std::wstring s = path.native();
|
||||||
|
for (wchar_t c : s) {
|
||||||
|
if ((c < 1) || (c > 127)) return "";
|
||||||
|
}
|
||||||
|
std::ostringstream oss;
|
||||||
|
for (wchar_t c : s) {
|
||||||
|
oss << ((char)c);
|
||||||
|
}
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
static void set_nonblocking(SOCKET sock) {
|
static void set_nonblocking(SOCKET sock) {
|
||||||
u_long mode = 1; // 1 to enable non-blocking socket
|
u_long mode = 1; // 1 to enable non-blocking socket
|
||||||
int status = ioctlsocket(sock, FIONBIO, &mode);
|
int status = ioctlsocket(sock, FIONBIO, &mode);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
extern std::string strerror_str(int err);
|
extern std::string strerror_str(int err);
|
||||||
|
extern std::string path_to_plain_ascii(const std::filesystem::path &path);
|
||||||
|
|
||||||
namespace drvssl {
|
namespace drvssl {
|
||||||
|
|
||||||
@@ -163,7 +164,10 @@ void ctx_load_cert_from_directory(SSL_CTX *ctx, const std::string &dir) {
|
|||||||
std::vector<std::string> cert_paths;
|
std::vector<std::string> cert_paths;
|
||||||
|
|
||||||
for (const auto & entry : std::filesystem::directory_iterator(dir)) {
|
for (const auto & entry : std::filesystem::directory_iterator(dir)) {
|
||||||
std::string fn = entry.path();
|
std::string fn = path_to_plain_ascii(entry.path());
|
||||||
|
if (fn.empty()) {
|
||||||
|
std::cerr << "Ignoring file with non-ascii filename: " << entry.path() << std::endl;
|
||||||
|
} else {
|
||||||
if (count_certificates(fn.c_str()) >= 1) {
|
if (count_certificates(fn.c_str()) >= 1) {
|
||||||
cert_paths.push_back(fn);
|
cert_paths.push_back(fn);
|
||||||
}
|
}
|
||||||
@@ -171,6 +175,7 @@ void ctx_load_cert_from_directory(SSL_CTX *ctx, const std::string &dir) {
|
|||||||
key_paths.push_back(fn);
|
key_paths.push_back(fn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (cert_paths.size() > 1) {
|
if (cert_paths.size() > 1) {
|
||||||
std::cerr << "Directory contains multiple certs: " << dir << std::endl;
|
std::cerr << "Directory contains multiple certs: " << dir << std::endl;
|
||||||
|
|||||||
Reference in New Issue
Block a user