diff --git a/src/SKIT.FlurlHttpClient.Wechat.TenpayV3/Exceptions/WechatTenpayResponseVerificationException.cs b/src/SKIT.FlurlHttpClient.Wechat.TenpayV3/Exceptions/WechatTenpayResponseVerificationException.cs deleted file mode 100644 index 0be0e102..00000000 --- a/src/SKIT.FlurlHttpClient.Wechat.TenpayV3/Exceptions/WechatTenpayResponseVerificationException.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; - -namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Exceptions -{ - public class WechatTenpayResponseVerificationException : WechatTenpayException - { - /// - internal WechatTenpayResponseVerificationException() - { - } - - /// - internal WechatTenpayResponseVerificationException(string message) - : base(message) - { - } - - /// - internal WechatTenpayResponseVerificationException(string message, Exception innerException) - : base(message, innerException) - { - } - } -} diff --git a/src/SKIT.FlurlHttpClient.Wechat.TenpayV3/Extensions/WechatTenpayClientEventVerificationExtensions.cs b/src/SKIT.FlurlHttpClient.Wechat.TenpayV3/Extensions/WechatTenpayClientEventVerificationExtensions.cs index 520ad71a..e782b3d5 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.TenpayV3/Extensions/WechatTenpayClientEventVerificationExtensions.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.TenpayV3/Extensions/WechatTenpayClientEventVerificationExtensions.cs @@ -35,39 +35,23 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3 if (callbackSignature == null) throw new ArgumentNullException(nameof(callbackSignature)); if (callbackSerialNumber == null) throw new ArgumentNullException(nameof(callbackSerialNumber)); - if (client.CertificateManager == null) + if (client.CertificateManager != null) { - throw new Exceptions.WechatTenpayResponseVerificationException($"You must set an instance of `{nameof(Settings.CertificateManager)}` at first."); - } - else - { - string? certificate = client.CertificateManager.GetCertificate(callbackSerialNumber); - if (certificate == null) - throw new Exceptions.WechatTenpayResponseVerificationException("Cannot get certificate by the serial number, may not be stored."); - - string? publicKey = null; try { - publicKey = Utilities.RSAUtility.ExportPublicKey(certificate); - } - catch (Exception ex) - { - throw new Exceptions.WechatTenpayResponseVerificationException("Cannot get public key of the certificate, may not be a valid certificate data.", ex); - } + string certificate = client.CertificateManager.GetCertificate(callbackSerialNumber)!; + string publicKey = Utilities.RSAUtility.ExportPublicKey(certificate); - try - { return Utilities.RSAUtility.VerifyWithSHA256( publicKey: publicKey, plainText: GetPlainTextForSignature(timestamp: callbackTimestamp, nonce: callbackNonce, body: callbackBody), signature: callbackSignature ); } - catch (Exception ex) - { - throw new Exceptions.WechatTenpayResponseVerificationException("Verify event signature failed. Please see the `InnerException` for more details.", ex); - } + catch { } } + + return false; } private static string GetPlainTextForSignature(string timestamp, string nonce, string body) diff --git a/src/SKIT.FlurlHttpClient.Wechat.TenpayV3/Extensions/WechatTenpayClientResponseVerificationExtensions.cs b/src/SKIT.FlurlHttpClient.Wechat.TenpayV3/Extensions/WechatTenpayClientResponseVerificationExtensions.cs index 3df729bb..616b9ce9 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.TenpayV3/Extensions/WechatTenpayClientResponseVerificationExtensions.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.TenpayV3/Extensions/WechatTenpayClientResponseVerificationExtensions.cs @@ -23,42 +23,23 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3 if (client == null) throw new ArgumentNullException(nameof(client)); if (response == null) throw new ArgumentNullException(nameof(response)); - if (client.CertificateManager == null) + if (client.CertificateManager != null) { - throw new Exceptions.WechatTenpayResponseVerificationException($"You must set an instance of `{nameof(Settings.CertificateManager)}` at first."); - } - else - { - if (response.WechatpayCertSerialNumber == null) - throw new Exceptions.WechatTenpayResponseVerificationException("Cannot read the serial number in headers of this response."); - - string? certificate = client.CertificateManager.GetCertificate(response.WechatpayCertSerialNumber); - if (certificate == null) - throw new Exceptions.WechatTenpayResponseVerificationException("Cannot get certificate by the serial number, may not be stored."); - - string? publicKey = null; try { - publicKey = Utilities.RSAUtility.ExportPublicKey(certificate); - } - catch (Exception ex) - { - throw new Exceptions.WechatTenpayResponseVerificationException("Cannot get public key of the certificate, may not be a valid certificate data.", ex); - } + string certificate = client.CertificateManager.GetCertificate(response.WechatpayCertSerialNumber)!; + string publicKey = Utilities.RSAUtility.ExportPublicKey(certificate); - try - { return Utilities.RSAUtility.VerifyWithSHA256( publicKey: publicKey, plainText: GetPlainTextForSignature(response), signature: response.WechatpaySignature ); } - catch (Exception ex) - { - throw new Exceptions.WechatTenpayResponseVerificationException("Verify response signature failed.", ex); - } + catch { } } + + return false; } private static string GetPlainTextForSignature(WechatTenpayResponse response)