|
@@ -10,7 +10,6 @@ import (
|
|
|
"encoding/json"
|
|
|
"encoding/pem"
|
|
|
"eta/eta_bridge/global"
|
|
|
- "fmt"
|
|
|
"google.golang.org/grpc"
|
|
|
"google.golang.org/grpc/codes"
|
|
|
"google.golang.org/grpc/metadata"
|
|
@@ -61,21 +60,20 @@ func SignatureInterceptor(ctx context.Context, req interface{}, _ *grpc.UnarySer
|
|
|
if err != nil {
|
|
|
return nil, status.Errorf(codes.InvalidArgument, "json序列化失败")
|
|
|
}
|
|
|
- publicKey, err := parsePublicKeyFromPEM([]byte(""))
|
|
|
+ publicKey, err := parsePublicKeyFromPEM()
|
|
|
if err != nil {
|
|
|
return nil, status.Errorf(codes.InvalidArgument, "公钥解析失败")
|
|
|
}
|
|
|
- fmt.Println(string(dds))
|
|
|
// 验证签名
|
|
|
- if !verifySignature(string(dds), signature[0], publicKey) {
|
|
|
+ if !verifySignature(dds, signature[0], publicKey) {
|
|
|
return nil, status.Errorf(codes.PermissionDenied, "invalid signature")
|
|
|
}
|
|
|
return handler(ctx, req)
|
|
|
}
|
|
|
|
|
|
// 验证签名
|
|
|
-func verifySignature(message, signature string, publicKey *rsa.PublicKey) bool {
|
|
|
- hash := sha256.Sum256([]byte(message))
|
|
|
+func verifySignature(message []byte, signature string, publicKey *rsa.PublicKey) bool {
|
|
|
+ hash := sha256.Sum256(message)
|
|
|
signatureBytes, err := base64.StdEncoding.DecodeString(signature)
|
|
|
if err != nil {
|
|
|
return false
|
|
@@ -84,7 +82,7 @@ func verifySignature(message, signature string, publicKey *rsa.PublicKey) bool {
|
|
|
return err == nil
|
|
|
}
|
|
|
|
|
|
-func parsePublicKeyFromPEM(pemBytes []byte) (pubKey *rsa.PublicKey, err error) {
|
|
|
+func parsePublicKeyFromPEM() (pubKey *rsa.PublicKey, err error) {
|
|
|
pemBlock, err := ioutil.ReadFile("./config/rsa_public_key.pem")
|
|
|
block, _ := pem.Decode(pemBlock)
|
|
|
if block == nil {
|