Skip to content

Commit

Permalink
fix: WECHATPAY2-SHA256-RSA2048 (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
xy-peng authored Oct 18, 2022
1 parent de81100 commit 335e823
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions core/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (
"github.com/wechatpay-apiv3/wechatpay-go/core/auth/validators"
)

const rsaSignatureType = "WECHATPAY2-SHA256-RSA2048"
const defaultSignatureType = rsaSignatureType
const aeadAesGcmAlgorithm = "AEAD_AES_256_GCM"

// Handler 通知处理器,使用前先设置验签和解密的算法套件
type Handler struct {
cipherSuites map[string]CipherSuite
Expand Down Expand Up @@ -49,9 +53,9 @@ func (h *Handler) AddCipherSuite(cipherSuite CipherSuite) *Handler {
// AddRSAWithAESGCM 添加一个 RSA + AES-GCM 的算法套件
func (h *Handler) AddRSAWithAESGCM(verifier auth.Verifier, aesgcm cipher.AEAD) *Handler {
v := CipherSuite{
signatureType: "WECHATPAY2-RSA2048-SHA256",
signatureType: rsaSignatureType,
validator: *validators.NewWechatPayNotifyValidator(verifier),
aeadAlgorithm: "AEAD_AES_256_GCM",
aeadAlgorithm: aeadAesGcmAlgorithm,
aead: aesgcm,
}
return h.AddCipherSuite(v)
Expand All @@ -65,7 +69,7 @@ func (h *Handler) ParseNotifyRequest(
) (*Request, error) {
signType := request.Header.Get("Wechatpay-Signature-Type")
if signType == "" {
signType = "WECHATPAY2-RSA2048-SHA256"
signType = defaultSignatureType
}

suite, ok := h.cipherSuites[signType]
Expand Down
4 changes: 2 additions & 2 deletions core/notify/notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ func TestHandler_ParseNotifyRequest_UnmarshalContentError(t *testing.T) {

func TestHandler_processBody_InvalidAlgorithm(t *testing.T) {
v := CipherSuite{
signatureType: "WECHATPAY2-RSA2048-SHA256",
signatureType: rsaSignatureType,
validator: validators.WechatPayNotifyValidator{},
aeadAlgorithm: "AEAD_AES_256_GCM",
aeadAlgorithm: aeadAesGcmAlgorithm,
aead: nil,
}

Expand Down

0 comments on commit 335e823

Please sign in to comment.