This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathproxy.gateway.go
104 lines (77 loc) · 2.89 KB
/
proxy.gateway.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
Copyright 2020 Telefónica Digital España. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package main
import (
log "TrustID/fabric-chaincode/log"
"encoding/json"
"errors"
"github.com/hyperledger/fabric-chaincode-go/shim"
)
func (cc *Chaincode) checkArgs(stub shim.ChaincodeStubInterface, args []string) (string, error) {
log.Infof("[%s][%s][checkArgs] Get Identity", CHANNEL_ENV, IDGATEWAY)
var result string
idReq := Request{}
err := json.Unmarshal([]byte(args[0]), &idReq)
var identity *Identity
var publicKey string
if idReq.PublicKey != "" {
publicKey = parseKey(idReq.PublicKey)
params, err := checkSignature(idReq.Payload, publicKey)
if params["function"].(string) == "createSelfIdentity" {
result, err = cc.createSelfIdentity(stub, params["params"])
}
return result, err
}
identity, err = cc.getIDRegistry(stub, idReq.Did)
if err != nil {
log.Errorf("[%s][%s][checkArgs] Error verifying signature: %v", CHANNEL_ENV, IDGATEWAY, err.Error())
return "", err
}
publicKey = parseKey(identity.PublicKey)
params, err := checkSignature(idReq.Payload, publicKey)
if params["function"].(string) == "getIdentity" {
result, err = cc.getIdentity(stub, idReq.Did, identity, params["params"])
}
if params["function"].(string) == "verifyIdentity" {
result, err = cc.verifyIdentity(stub, idReq.Did, identity, params["params"])
}
if params["function"].(string) == "revokeIdentity" {
result, err = cc.revokeIdentity(stub, idReq.Did, identity, params["params"])
}
if params["function"].(string) == "createServiceIdentity" {
result, err = cc.createServiceIdentity(stub, idReq.Did, params["params"])
}
if params["function"].(string) == "createIdentity" {
result, err = cc.createIdentity(stub, idReq.Did, params["params"])
}
if params["function"].(string) == "getServiceIdentity" {
result, err = cc.getServiceIdentity(stub, params["params"])
}
if params["function"].(string) == "updateServiceAccess" {
result, err = cc.updateServiceAccess(stub, idReq.Did, params["params"])
}
if params["function"].(string) == "updateService" {
result, err = cc.updateService(stub, idReq.Did, params["params"])
}
if params["function"].(string) == "invoke" {
result, err = cc.invoke(stub, idReq.Did, params["params"])
}
return result, err
}
func checkSignature(payload string, key string) (map[string]interface{}, error) {
log.Errorf("[%s][%s][checkSignature] Verifying signature", CHANNEL_ENV, IDGATEWAY)
message, err := verifySignature(payload, key)
if err != nil {
log.Errorf("[%s][%s][checkSignature] Error verifying signature: %v", CHANNEL_ENV, IDGATEWAY, err.Error())
return nil, errors.New(ERRORVerSign)
}
params := make(map[string]interface{})
err = json.Unmarshal(message, ¶ms)
if err != nil {
log.Errorf("[%s][%s][checkSignature] Error parsing: %v", CHANNEL_ENV, IDGATEWAY, err.Error())
return nil, errors.New(ERRORParsingData)
}
return params, nil
}