|
@@ -10,7 +10,6 @@ import (
|
|
|
"encoding/json"
|
|
|
"encoding/pem"
|
|
|
"eta/eta_bridge/global"
|
|
|
- "eta/eta_bridge/rpc/sso"
|
|
|
"fmt"
|
|
|
"google.golang.org/grpc"
|
|
|
"google.golang.org/grpc/codes"
|
|
@@ -21,9 +20,9 @@ import (
|
|
|
)
|
|
|
|
|
|
type encryptedRequest struct {
|
|
|
- Message []byte `json:"ciphertext"`
|
|
|
- Nonce string `json:"nonce"` // 添加随机字符串
|
|
|
- Timestamp int64 `json:"timestamp"` // 添加时间戳
|
|
|
+ Message interface{} `json:"ciphertext"`
|
|
|
+ Nonce string `json:"nonce"` // 添加随机字符串
|
|
|
+ Timestamp int64 `json:"timestamp"` // 添加时间戳
|
|
|
}
|
|
|
|
|
|
// 自定义拦截器
|
|
@@ -53,10 +52,8 @@ func SignatureInterceptor(ctx context.Context, req interface{}, _ *grpc.UnarySer
|
|
|
if !ok || len(signature) == 0 {
|
|
|
return nil, status.Errorf(codes.InvalidArgument, "签名信息不能为空")
|
|
|
}
|
|
|
- message := req.(*sso.LoginRequest)
|
|
|
- str, err := json.Marshal(message)
|
|
|
decrytData := encryptedRequest{
|
|
|
- Message: str,
|
|
|
+ Message: req,
|
|
|
Nonce: nonceStr[0], // 添加随机字符串
|
|
|
Timestamp: timestamp, // 添加时间戳
|
|
|
}
|
|
@@ -93,7 +90,11 @@ func parsePublicKeyFromPEM(pemBytes []byte) (pubKey *rsa.PublicKey, err error) {
|
|
|
if block == nil {
|
|
|
global.LOG.Error("公钥解析失败")
|
|
|
}
|
|
|
- pubKey, err = x509.ParsePKCS1PublicKey(block.Bytes)
|
|
|
+ pubInterface, err := x509.ParsePKIXPublicKey(block.Bytes)
|
|
|
+ pubKey, ok := pubInterface.(*rsa.PublicKey)
|
|
|
+ if !ok {
|
|
|
+ global.LOG.Error("公钥解析失败")
|
|
|
+ }
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|