2 using System
.Runtime
.CompilerServices
;
3 using System
.Runtime
.InteropServices
;
6 using System
.Windows
.Interop
;
7 using System
.Windows
.Media
;
8 using Org
.BouncyCastle
.Asn1
;
12 public partial class App
: Application
14 private static class Const
16 internal static readonly string MAX_KEY_SIZE
= (1U << 16).ToString();
21 AppDomain
.CurrentDomain
.UnhandledException
+= new UnhandledExceptionEventHandler(ExceptionHandler
);
24 protected override void OnStartup(StartupEventArgs e
)
26 const string BOUNCY
= "Org.BouncyCastle.";
29 Environment
.SetEnvironmentVariable(BOUNCY
+ "EC.Fp_MaxSize", Const
.MAX_KEY_SIZE
);
30 Environment
.SetEnvironmentVariable(BOUNCY
+ "Rsa.MaxSize", Const
.MAX_KEY_SIZE
);
31 Environment
.SetEnvironmentVariable(BOUNCY
+ "Asn1.AllowUnsafeInteger", string.Empty
);
32 Environment
.SetEnvironmentVariable(BOUNCY
+ "EC.Fp_Certainty", string.Empty
);
33 Environment
.SetEnvironmentVariable(BOUNCY
+ "Fpe.Disable", string.Empty
);
34 Environment
.SetEnvironmentVariable(BOUNCY
+ "Fpe.Disable_Ff1", string.Empty
);
35 Environment
.SetEnvironmentVariable(BOUNCY
+ "Pkcs1.Strict", string.Empty
);
36 Environment
.SetEnvironmentVariable(BOUNCY
+ "Pkcs12.IgnoreUselessPassword", string.Empty
);
37 Environment
.SetEnvironmentVariable(BOUNCY
+ "X509.Allow_Non-DER_TBSCert", string.Empty
);
42 if (Array
.Exists(e
.Args
, str
=> StrCaseCmp(str
, "--render-mode=software")) || StrCaseCmp(Environment
.GetEnvironmentVariable("CertViewer.RenderMode"), "software"))
44 RenderOptions
.ProcessRenderMode
= RenderMode
.SoftwareOnly
;
48 Require(typeof(Asn1Encodable
));
51 private static void ExceptionHandler(object sender
, UnhandledExceptionEventArgs args
)
55 if (args
.ExceptionObject
is Exception exception
)
57 FatalAppExit(0, $"{exception.GetType().Name}: {exception.Message}");
64 private static bool StrCaseCmp(string s1
, string s2
)
66 if ((!ReferenceEquals(s1
, null)) && (!ReferenceEquals(s2
, null)))
68 return string.Equals(s1
.Trim(), s2
.Trim(), StringComparison
.OrdinalIgnoreCase
);
73 [MethodImpl(MethodImplOptions
.NoInlining
)]
74 private static void Require(Type _
) { }
76 [DllImport("kernel32.dll", ExactSpelling
=true, CharSet
=CharSet
.Unicode
, EntryPoint
="FatalAppExitW")]
77 [SuppressUnmanagedCodeSecurity
]
78 private static extern void FatalAppExit(uint reserved
, string message
);