using System; using System.Linq; using HarmonyLib; using TLS = Org.BouncyCastle.Crypto.Tls.LegacyTlsAuthentication; using TimeValid = Org.BouncyCastle.Crypto.Tls.TimeValidVerifyer; [HarmonyPatch] internal static class EmbeddedTlsPatches { internal static void Apply(Harmony harmony) { try { harmony.Patch(AccessTools.Method(typeof(TLS), "NotifyServerCertificate"), prefix: new HarmonyMethod(typeof(EmbeddedTlsPatches), nameof(NotifyServerCertificatePrefix))); RadicadeEacBypassPlugin.LogSource.LogInfo("[TLS] Patched LegacyTlsAuthentication.NotifyServerCertificate (host-scoped accept)"); } catch (Exception ex) { RadicadeEacBypassPlugin.LogSource.LogWarning($"[TLS] NotifyServerCertificate patch failed: {ex.GetType().Name}: {ex.Message}"); } try { harmony.Patch(AccessTools.Method(typeof(TimeValid), "IsValid"), prefix: new HarmonyMethod(typeof(EmbeddedTlsPatches), nameof(IsValidPrefix))); RadicadeEacBypassPlugin.LogSource.LogInfo("[TLS] Patched TimeValidVerifyer.IsValid (host-scoped accept)"); } catch (Exception ex) { RadicadeEacBypassPlugin.LogSource.LogWarning($"[TLS] TimeValidVerifyer patch failed: {ex.GetType().Name}: {ex.Message}"); } } static bool NotifyServerCertificatePrefix(TLS __instance) { try { var uri = __instance.TargetUri; var host = uri?.Host; var verifyerType = __instance.verifyer != null ? __instance.verifyer.GetType().FullName : ""; Diag.Trace( $"[TLS] NotifyServerCertificate: host={host ?? ""}, verifyer={verifyerType}"); if (host != null && IsHostAllowed(host)) { Diag.Trace( $"[TLS] Accepting server certificate for allowed Radicade host '{host}' (embedded-stack bypass)"); return false; } } catch (Exception ex) { RadicadeEacBypassPlugin.LogSource.LogWarning($"[TLS] NotifyServerCertificate prefix error: {ex.GetType().Name}: {ex.Message}"); } return true; } static bool IsValidPrefix(Il2CppSystem.Uri targetUri, ref bool __result) { try { var host = targetUri?.Host; if (host != null && IsHostAllowed(host)) { Diag.Trace( $"[TLS] TimeValidVerifyer.IsValid forced TRUE for allowed Radicade host '{host}'"); __result = true; return false; } } catch (Exception ex) { RadicadeEacBypassPlugin.LogSource.LogWarning($"[TLS] IsValid prefix error: {ex.GetType().Name}: {ex.Message}"); } return true; } public static bool IsHostAllowed(string host) { if (string.IsNullOrWhiteSpace(host)) return false; var raw = RadicadeEacBypassPlugin.TlsAllowedHosts?.Value; if (string.IsNullOrWhiteSpace(raw)) return false; return raw.Split(',') .Select(h => h.Trim().TrimEnd('.')) .Where(h => h.Length > 0) .Any(h => host.TrimEnd('.').Equals(h, StringComparison.OrdinalIgnoreCase)); } }