Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
"errors"
"fmt"

"github.com/hyperledger/fabric-contract-api-go/contractapi"
log "github.com/sirupsen/logrus"
"github.com/hyperledger-cacti/cacti/weaver/common/protos-go/v2/common"
wutils "github.com/hyperledger-cacti/cacti/weaver/core/network/fabric-interop-cc/libs/utils/v2"
"github.com/hyperledger/fabric-contract-api-go/contractapi"
log "github.com/sirupsen/logrus"
)

const accessControlObjectType = "accessControl"
Expand Down Expand Up @@ -159,12 +159,12 @@ func verifyAccessToCC(s *SmartContract, ctx contractapi.TransactionContextInterf
// TODO: Check if these will be the same format (Or convert to matching formats at some point)
// TODO: Need to use principalType and perform different validation for type "certificate" and "ca".
// Code below assumes that requestor's membership has already been authenticated earlier if the type is "ca"
if (rule.PrincipalType == "certificate" && query.Certificate == rule.Principal) {
if rule.PrincipalType == "certificate" && query.Certificate == rule.Principal {
// Break loop as cert is valid.
log.Infof("Access Control Policy PERMITS the request '%s' from '%s:%s'", viewAddressString, query.RequestingNetwork, query.Certificate)
return nil
}
if (rule.PrincipalType == "ca" && query.RequestingOrg == rule.Principal) {
if rule.PrincipalType == "ca" && query.RequestingOrg == rule.Principal {
// Break loop as cert is valid.
log.Infof("Access Control Policy PERMITS the request '%s' from '%s:%s'", viewAddressString, query.RequestingNetwork, query.RequestingOrg)
return nil
Expand All @@ -173,10 +173,10 @@ func verifyAccessToCC(s *SmartContract, ctx contractapi.TransactionContextInterf

}
var errorMessage string
if (query.Certificate != "") {
errorMessage = fmt.Sprintf("Access Control Policy DOES NOT PERMIT the request '%s' from '%s:%s'", viewAddressString, query.RequestingNetwork, query.Certificate)
} else if (query.RequestingOrg != "") {
errorMessage = fmt.Sprintf("Access Control Policy DOES NOT PERMIT the request '%s' from '%s:%s'", viewAddressString, query.RequestingNetwork, query.RequestingOrg)
if query.Certificate != "" {
errorMessage = fmt.Sprintf("Access Control Policy DOES NOT PERMIT the request '%s' from '%s:%s'", viewAddressString, query.RequestingNetwork, query.Certificate)
} else if query.RequestingOrg != "" {
errorMessage = fmt.Sprintf("Access Control Policy DOES NOT PERMIT the request '%s' from '%s:%s'", viewAddressString, query.RequestingNetwork, query.RequestingOrg)
} else {
errorMessage = fmt.Sprintf("Access Control Policy DOES NOT PERMIT the request '%s' from a foreign entity", viewAddressString)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"fmt"
"testing"

"github.com/hyperledger-cacti/cacti/weaver/core/network/fabric-interop-cc/libs/testutils/mocks"
"github.com/stretchr/testify/require"
"github.com/hyperledger-cacti/cacti/weaver/common/protos-go/v2/common"
wtest "github.com/hyperledger-cacti/cacti/weaver/core/network/fabric-interop-cc/libs/testutils"
"github.com/hyperledger-cacti/cacti/weaver/core/network/fabric-interop-cc/libs/testutils/mocks"
"github.com/stretchr/testify/require"
)

var accessControlAsset = common.AccessControlPolicy{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"math/big"
"time"

"golang.org/x/crypto/ed25519"
"github.com/ethereum/go-ethereum/crypto/ecies"
"github.com/golang/protobuf/proto"
"github.com/hyperledger-cacti/cacti/weaver/common/protos-go/v2/common"
"golang.org/x/crypto/ed25519"
)

const (
Expand Down Expand Up @@ -89,9 +89,11 @@ func verifyCaCertificate(cert *x509.Certificate, memberCertificate string) error
return nil
}

/* This function will receive arguments for exactly one node with the following cert chain assumed: <root cert> -> <int cert 0> -> <int cert 1> -> ......
In a Fabric network, we assume that there are multiple MSPs, each having one or more Root CAs and zero or more Intermediate CAs.
In a Corda network, we assume that there is a single Root CA and Doorman CA, and one or more Node CAs corresponding to nodes.
/*
This function will receive arguments for exactly one node with the following cert chain assumed: <root cert> -> <int cert 0> -> <int cert 1> -> ......

In a Fabric network, we assume that there are multiple MSPs, each having one or more Root CAs and zero or more Intermediate CAs.
In a Corda network, we assume that there is a single Root CA and Doorman CA, and one or more Node CAs corresponding to nodes.
*/
func verifyCertificateChain(cert *x509.Certificate, certPEMs []string) error {
var parentCert *x509.Certificate
Expand Down Expand Up @@ -272,7 +274,7 @@ func encryptWithCert(message []byte, cert *x509.Certificate) ([]byte, error) {
pubKey := getECDSAPublicKeyFromCertificate(cert)
if pubKey != nil {
return encryptWithECDSAPublicKey(message, pubKey)
} else if (cert.RawSubjectPublicKeyInfo != nil && len(cert.RawSubjectPublicKeyInfo) == 44) { // ed25519 public key
} else if cert.RawSubjectPublicKeyInfo != nil && len(cert.RawSubjectPublicKeyInfo) == 44 { // ed25519 public key
// We expect the key to be 44 bytes, but only the last 32 bytes (multiple of 8) comprise the public key
return encryptWithEd25519PublicKey(message, cert.RawSubjectPublicKeyInfo[12:])
} else {
Expand Down Expand Up @@ -323,7 +325,7 @@ func generateConfidentialInteropPayloadAndHash(message []byte, cert string) ([]b

confidentialPayloadContents := common.ConfidentialPayloadContents{
Payload: message,
Random: hashKey,
Random: hashKey,
}
confidentialPayloadContentsBytes, err := proto.Marshal(&confidentialPayloadContents)
if err != nil {
Expand All @@ -347,8 +349,8 @@ func generateConfidentialInteropPayloadAndHash(message []byte, cert string) ([]b

confidentialPayload := common.ConfidentialPayload{
EncryptedPayload: encryptedPayload,
HashType: common.ConfidentialPayload_HMAC,
Hash: payloadHMAC,
HashType: common.ConfidentialPayload_HMAC,
Hash: payloadHMAC,
}
confidentialPayloadBytes, err := proto.Marshal(&confidentialPayload)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"
"github.com/ethereum/go-ethereum/crypto/ecies"
"github.com/golang/protobuf/proto"
"github.com/hyperledger-cacti/cacti/weaver/common/protos-go/v2/common"
"github.com/stretchr/testify/require"
)

func TestVerifyCertificateChain(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ package main
import (
"encoding/base64"
"encoding/json"
"strings"
"fmt"
"strings"

"github.com/hyperledger-cacti/cacti/weaver/common/protos-go/v2/common"
"github.com/hyperledger-cacti/cacti/weaver/common/protos-go/v2/identity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"fmt"
"os"

wutils "github.com/hyperledger-cacti/cacti/weaver/core/network/fabric-interop-cc/libs/utils/v2"
"github.com/hyperledger/fabric-chaincode-go/shim"
"github.com/hyperledger/fabric-contract-api-go/contractapi"
log "github.com/sirupsen/logrus"
wutils "github.com/hyperledger-cacti/cacti/weaver/core/network/fabric-interop-cc/libs/utils/v2"
)

const e2eConfidentialityKey = "e2eConfidentialityFlag"
Expand Down Expand Up @@ -89,12 +89,12 @@ func main() {
_, ok := os.LookupEnv("EXTERNAL_SERVICE")
if ok {
server := &shim.ChaincodeServer{
CCID: os.Getenv("CHAINCODE_CCID"),
Address: os.Getenv("CHAINCODE_ADDRESS"),
CC: chaincode,
TLSProps: shim.TLSProperties{
Disabled: true,
},
CCID: os.Getenv("CHAINCODE_CCID"),
Address: os.Getenv("CHAINCODE_ADDRESS"),
CC: chaincode,
TLSProps: shim.TLSProperties{
Disabled: true,
},
}
// Start the chaincode external server
err = server.Start()
Expand All @@ -105,6 +105,4 @@ func main() {
fmt.Printf("Error starting Interop chaincode: %s", err)
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
package main

import (
"fmt"
"errors"
"fmt"

"github.com/hyperledger-cacti/cacti/weaver/core/network/fabric-interop-cc/libs/assetexchange/v2"
wutils "github.com/hyperledger-cacti/cacti/weaver/core/network/fabric-interop-cc/libs/utils/v2"
"github.com/hyperledger/fabric-contract-api-go/contractapi"
log "github.com/sirupsen/logrus"
wutils "github.com/hyperledger-cacti/cacti/weaver/core/network/fabric-interop-cc/libs/utils/v2"
)

const (
callerCCIdPrefix = "CallerCCId_" // prefix for the caller CC ID map, contractId --> caller-cc-id
callerCCIdPrefix = "CallerCCId_" // prefix for the caller CC ID map, contractId --> caller-cc-id
)

// helper functions to log and return errors
Expand Down Expand Up @@ -50,7 +50,7 @@ func (s *SmartContract) LockAsset(ctx contractapi.TransactionContextInterface, a
}

// Start the locking process now
contractId, err := assetexchange.LockAsset(ctx, callerChaincodeID, assetAgreementBytesBase64, lockInfoBytesBase64)
contractId, err := assetexchange.LockAsset(ctx, callerChaincodeID, assetAgreementBytesBase64, lockInfoBytesBase64)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -327,5 +327,3 @@ func (s *SmartContract) GetHTLCHashPreImage(ctx contractapi.TransactionContextIn
func (s *SmartContract) GetHTLCHashPreImageByContractId(ctx contractapi.TransactionContextInterface, contractId string) (string, error) {
return assetexchange.GetHTLCHashPreImageByContractId(ctx, contractId)
}


Loading
Loading