Add configurable client key algorithm

This commit is contained in:
√(noham)²
2026-08-27 16:21:40 +02:00
parent 3f1b4fd728
commit 36d4b1258f
4 changed files with 21 additions and 1 deletions

View File

@@ -116,6 +116,7 @@ The config file (`~/Library/Preferences/rmfakecloud.config`) supports the follow
| `port` | Number | `443` | Your rmfakecloud server port | | `port` | Number | `443` | Your rmfakecloud server port |
| `client_cert` | String | (none) | Path to client certificate file (PEM) for mTLS | | `client_cert` | String | (none) | Path to client certificate file (PEM) for mTLS |
| `client_key` | String | (none) | Path to client private key file (PEM) for mTLS | | `client_key` | String | (none) | Path to client private key file (PEM) for mTLS |
| `key_algorithm` | String | `rsa` | Key algorithm: `rsa`, `ec`, `dsa`, `dh`, or `opaque` |
| `ca_cert` | String | (none) | Path to custom CA certificate file (PEM) | | `ca_cert` | String | (none) | Path to custom CA certificate file (PEM) |
| `disable_ssl_verification` | Boolean | `false` | Disable SSL peer verification (not recommended) | | `disable_ssl_verification` | Boolean | `false` | Disable SSL peer verification (not recommended) |

View File

@@ -1,5 +1,6 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include <QtCore/QString> #include <QtCore/QString>
#include <QtNetwork/QSsl>
extern NSString *gConfiguredHostObjC; extern NSString *gConfiguredHostObjC;
extern NSNumber *gConfiguredPortObjC; extern NSNumber *gConfiguredPortObjC;
@@ -8,6 +9,7 @@ extern NSNumber *gConfiguredPort;
extern QString gConfiguredClientCertPath; extern QString gConfiguredClientCertPath;
extern QString gConfiguredClientKeyPath; extern QString gConfiguredClientKeyPath;
extern QString gConfiguredCACertPath; extern QString gConfiguredCACertPath;
extern QSsl::KeyAlgorithm gConfiguredKeyAlgorithm;
extern bool gDisableSSLVerification; extern bool gDisableSSLVerification;
void ConfigLoadOrCreate(void); void ConfigLoadOrCreate(void);

View File

@@ -8,6 +8,7 @@ static NSString *const kConfigPortKey = @"port";
static NSString *const kConfigClientCertKey = @"client_cert"; static NSString *const kConfigClientCertKey = @"client_cert";
static NSString *const kConfigClientKeyKey = @"client_key"; static NSString *const kConfigClientKeyKey = @"client_key";
static NSString *const kConfigCACertKey = @"ca_cert"; static NSString *const kConfigCACertKey = @"ca_cert";
static NSString *const kConfigKeyAlgorithmKey = @"key_algorithm";
static NSString *const kConfigDisableSSLVerifyKey = @"disable_ssl_verification"; static NSString *const kConfigDisableSSLVerifyKey = @"disable_ssl_verification";
static NSString *const kDefaultHost = @"example.com"; static NSString *const kDefaultHost = @"example.com";
static NSNumber *const kDefaultPort = @(443); static NSNumber *const kDefaultPort = @(443);
@@ -19,6 +20,7 @@ NSNumber *gConfiguredPort = @(443);
QString gConfiguredClientCertPath; QString gConfiguredClientCertPath;
QString gConfiguredClientKeyPath; QString gConfiguredClientKeyPath;
QString gConfiguredCACertPath; QString gConfiguredCACertPath;
QSsl::KeyAlgorithm gConfiguredKeyAlgorithm = QSsl::Rsa;
bool gDisableSSLVerification = false; bool gDisableSSLVerification = false;
static NSString *PreferencesDirectory(void) { static NSString *PreferencesDirectory(void) {
@@ -111,6 +113,21 @@ void ConfigLoadOrCreate(void) {
if ([caPathValue isKindOfClass:[NSString class]] && [caPathValue length]) { if ([caPathValue isKindOfClass:[NSString class]] && [caPathValue length]) {
gConfiguredCACertPath = QStringFromNSStringSafe(caPathValue); gConfiguredCACertPath = QStringFromNSStringSafe(caPathValue);
} }
NSString *keyAlgoValue = configDict[kConfigKeyAlgorithmKey];
if ([keyAlgoValue isKindOfClass:[NSString class]] && [keyAlgoValue length]) {
NSString *lower = [keyAlgoValue lowercaseString];
if ([lower isEqualToString:@"ec"]) {
gConfiguredKeyAlgorithm = QSsl::Ec;
} else if ([lower isEqualToString:@"dsa"]) {
gConfiguredKeyAlgorithm = QSsl::Dsa;
} else if ([lower isEqualToString:@"dh"]) {
gConfiguredKeyAlgorithm = QSsl::Dh;
} else if ([lower isEqualToString:@"opaque"]) {
gConfiguredKeyAlgorithm = QSsl::Opaque;
} else {
gConfiguredKeyAlgorithm = QSsl::Rsa;
}
}
if ([disableSSLValue respondsToSelector:@selector(boolValue)]) { if ([disableSSLValue respondsToSelector:@selector(boolValue)]) {
gDisableSSLVerification = [disableSSLValue boolValue]; gDisableSSLVerification = [disableSSLValue boolValue];
} }

View File

@@ -35,7 +35,7 @@ void SSLConfigLoad(void) {
QFile keyFile(QString::fromUtf8(keyPath.toUtf8())); QFile keyFile(QString::fromUtf8(keyPath.toUtf8()));
if (keyFile.open(QIODevice::ReadOnly)) { if (keyFile.open(QIODevice::ReadOnly)) {
gClientKey = QSslKey(keyFile.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey); gClientKey = QSslKey(keyFile.readAll(), gConfiguredKeyAlgorithm, QSsl::Pem, QSsl::PrivateKey);
keyFile.close(); keyFile.close();
if (gClientKey.isNull()) { if (gClientKey.isNull()) {
NSLogger(@"[RMHook] Failed to parse client key from %s", keyPath.toUtf8().constData()); NSLogger(@"[RMHook] Failed to parse client key from %s", keyPath.toUtf8().constData());