diff --git a/README.md b/README.md index 7a23815..07b5b82 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,7 @@ The config file (`~/Library/Preferences/rmfakecloud.config`) supports the follow | `port` | Number | `443` | Your rmfakecloud server port | | `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 | +| `key_algorithm` | String | `rsa` | Key algorithm: `rsa`, `ec`, `dsa`, `dh`, or `opaque` | | `ca_cert` | String | (none) | Path to custom CA certificate file (PEM) | | `disable_ssl_verification` | Boolean | `false` | Disable SSL peer verification (not recommended) | diff --git a/src/RMHook/Config.h b/src/RMHook/Config.h index 4e603f6..5252cfb 100644 --- a/src/RMHook/Config.h +++ b/src/RMHook/Config.h @@ -1,5 +1,6 @@ #import #include +#include extern NSString *gConfiguredHostObjC; extern NSNumber *gConfiguredPortObjC; @@ -8,6 +9,7 @@ extern NSNumber *gConfiguredPort; extern QString gConfiguredClientCertPath; extern QString gConfiguredClientKeyPath; extern QString gConfiguredCACertPath; +extern QSsl::KeyAlgorithm gConfiguredKeyAlgorithm; extern bool gDisableSSLVerification; void ConfigLoadOrCreate(void); diff --git a/src/RMHook/Config.m b/src/RMHook/Config.m index 80fe28b..0c1296d 100644 --- a/src/RMHook/Config.m +++ b/src/RMHook/Config.m @@ -8,6 +8,7 @@ static NSString *const kConfigPortKey = @"port"; static NSString *const kConfigClientCertKey = @"client_cert"; static NSString *const kConfigClientKeyKey = @"client_key"; static NSString *const kConfigCACertKey = @"ca_cert"; +static NSString *const kConfigKeyAlgorithmKey = @"key_algorithm"; static NSString *const kConfigDisableSSLVerifyKey = @"disable_ssl_verification"; static NSString *const kDefaultHost = @"example.com"; static NSNumber *const kDefaultPort = @(443); @@ -19,6 +20,7 @@ NSNumber *gConfiguredPort = @(443); QString gConfiguredClientCertPath; QString gConfiguredClientKeyPath; QString gConfiguredCACertPath; +QSsl::KeyAlgorithm gConfiguredKeyAlgorithm = QSsl::Rsa; bool gDisableSSLVerification = false; static NSString *PreferencesDirectory(void) { @@ -111,6 +113,21 @@ void ConfigLoadOrCreate(void) { if ([caPathValue isKindOfClass:[NSString class]] && [caPathValue length]) { 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)]) { gDisableSSLVerification = [disableSSLValue boolValue]; } diff --git a/src/RMHook/SSLConfig.m b/src/RMHook/SSLConfig.m index 59f74f7..66bacaf 100644 --- a/src/RMHook/SSLConfig.m +++ b/src/RMHook/SSLConfig.m @@ -35,7 +35,7 @@ void SSLConfigLoad(void) { QFile keyFile(QString::fromUtf8(keyPath.toUtf8())); 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(); if (gClientKey.isNull()) { NSLogger(@"[RMHook] Failed to parse client key from %s", keyPath.toUtf8().constData());