q-koa 13.8.34 → 13.8.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -95,10 +95,8 @@ const validateUnionNotifySign = ({ notifyData, signType, publicKey, md5Key }) =>
|
|
|
95
95
|
if (!notifyData || !notifyData.sign) return false
|
|
96
96
|
const params = { ...notifyData }
|
|
97
97
|
const sign = String(params.sign)
|
|
98
|
+
// 通联签名规则:仅剔除 sign 字段本身,signtype/signType 仍保留在原串里
|
|
98
99
|
delete params.sign
|
|
99
|
-
// 通联回调报文字段是全小写 signtype;同时删除大小写两种做防御
|
|
100
|
-
delete params.signType
|
|
101
|
-
delete params.signtype
|
|
102
100
|
|
|
103
101
|
// 通联 buildSignStr:按 ASCII 字典序拼接,跳过空/undefined/null
|
|
104
102
|
const sortedKeys = Object.keys(params).sort()
|
|
@@ -123,7 +121,10 @@ const validateUnionNotifySign = ({ notifyData, signType, publicKey, md5Key }) =>
|
|
|
123
121
|
// 默认 RSA-SHA1(与 allinpay.js verifySign 保持一致)
|
|
124
122
|
if (!publicKey) return false
|
|
125
123
|
try {
|
|
126
|
-
|
|
124
|
+
// 兼容两种配置格式:已经带 PEM 头尾的直接用;纯 base64 body 再包裹头尾
|
|
125
|
+
const pem = String(publicKey).includes('-----BEGIN')
|
|
126
|
+
? String(publicKey)
|
|
127
|
+
: `-----BEGIN PUBLIC KEY-----\n${publicKey}\n-----END PUBLIC KEY-----`
|
|
127
128
|
const verify = crypto.createVerify('RSA-SHA1')
|
|
128
129
|
verify.update(signStr, 'utf8')
|
|
129
130
|
return verify.verify(pem, sign, 'base64')
|
|
@@ -67,10 +67,16 @@ class AllinPay {
|
|
|
67
67
|
const signStr = this.buildSignStr(params)
|
|
68
68
|
|
|
69
69
|
if (this.signType === 'RSA') {
|
|
70
|
-
|
|
70
|
+
// 兼容三种配置格式:已经带 PEM 头尾直接使用;否则默认包 PKCS#1 (BEGIN RSA PRIVATE KEY) 头尾
|
|
71
|
+
let pem
|
|
72
|
+
if (String(this.privateKey).includes('-----BEGIN')) {
|
|
73
|
+
pem = String(this.privateKey)
|
|
74
|
+
} else {
|
|
75
|
+
pem = `-----BEGIN RSA PRIVATE KEY-----\n${this.privateKey}\n-----END RSA PRIVATE KEY-----`
|
|
76
|
+
}
|
|
71
77
|
const sign = crypto.createSign('RSA-SHA1')
|
|
72
78
|
sign.update(signStr, 'utf8')
|
|
73
|
-
const signature = sign.sign(
|
|
79
|
+
const signature = sign.sign(pem, 'base64')
|
|
74
80
|
|
|
75
81
|
// crypto.createHash('md5').update(originStr).digest('hex')
|
|
76
82
|
return signature
|
|
@@ -93,10 +99,13 @@ class AllinPay {
|
|
|
93
99
|
|
|
94
100
|
const signStr = this.buildSignStr(paramsCopy)
|
|
95
101
|
|
|
96
|
-
|
|
102
|
+
// 兼容两种配置格式:已经带 PEM 头尾的直接用;纯 base64 body 再包裹头尾
|
|
103
|
+
const pem = String(this.publicKey).includes('-----BEGIN')
|
|
104
|
+
? String(this.publicKey)
|
|
105
|
+
: `-----BEGIN PUBLIC KEY-----\n${this.publicKey}\n-----END PUBLIC KEY-----`
|
|
97
106
|
const verify = crypto.createVerify('RSA-SHA1')
|
|
98
107
|
verify.update(signStr, 'utf8')
|
|
99
|
-
const result = verify.verify(
|
|
108
|
+
const result = verify.verify(pem, sign, 'base64')
|
|
100
109
|
|
|
101
110
|
return result
|
|
102
111
|
}
|