Skip to content

Commit

Permalink
[FAB-7880] add error code to empty cert
Browse files Browse the repository at this point in the history
	clients can now verify the empty cert error code from the sdk.
	This is used when calling TLSCACerts.TLSCert() on the orderer
	or the peer's config.

	to check if an empty cert is returned cast it to a status object
	and verify its code. Example:
	ocert, err := ordererConfig.TLSCACerts.TLSCert()
	s, ok := status.FromError(err)
	if ok && s.code == status.EmptyCert.ToInt32() {
	// then we have an empty cert error
	}

Change-Id: Ibe4e68c478bd95d2930a8001b68ef81352dc3b45
Signed-off-by: Baha Shaaban <baha.shaaban@securekey.com>
  • Loading branch information
Baha Shaaban committed Jan 24, 2018
1 parent 3a0dae2 commit ef80627
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion api/apiconfig/network.go
Expand Up @@ -12,6 +12,7 @@ import (
"io/ioutil"

"github.com/hyperledger/fabric-sdk-go/pkg/errors"
"github.com/hyperledger/fabric-sdk-go/pkg/status"
)

// NetworkConfig provides a static definition of a Hyperledger Fabric network
Expand Down Expand Up @@ -184,7 +185,8 @@ func loadCert(rawData []byte) (*x509.Certificate, error) {
return pub, nil
}

return nil, errors.New("pem data missing")
// return an error with an error code for clients to test against status.EmptyCert code
return nil, status.New(status.ClientStatus, status.EmptyCert.ToInt32(), "pem data missing", nil)
}

// MutualTLSConfig Mutual TLS configurations
Expand Down
4 changes: 4 additions & 0 deletions pkg/status/codes.go
Expand Up @@ -29,6 +29,9 @@ const (

// EndorsementMismatch is returned when there is a mismatch in endorsements received by the SDK
EndorsementMismatch Code = 3

// EmptyCert is return when an empty cert is returned
EmptyCert Code = 4
)

// CodeName maps the codes in this packages to human-readable strings
Expand All @@ -37,6 +40,7 @@ var CodeName = map[int32]string{
1: "UNKNOWN",
2: "CONNECTION_FAILED",
3: "ENDORSEMENT_MISMATCH",
4: "EMPTY_CERT",
}

// ToInt32 cast to int32
Expand Down
5 changes: 4 additions & 1 deletion pkg/status/status.go
Expand Up @@ -69,6 +69,8 @@ const (
EndorserClientStatus
// OrdererClientStatus status returned from the orderer client
OrdererClientStatus
// ClientStatus is a generic client status
ClientStatus
)

// GroupName maps the groups in this packages to human-readable strings
Expand All @@ -82,6 +84,7 @@ var GroupName = map[int32]string{
6: "Fabric CA Server Status",
7: "Endorser Client Status",
8: "Orderer Client Status",
9: "Client Status",
}

func (g Group) String() string {
Expand Down Expand Up @@ -120,7 +123,7 @@ func (s *Status) codeString() string {
return ToFabricCommonStatusCode(s.Code).String()
case EventServerStatus:
return ToTransactionValidationCode(s.Code).String()
case EndorserClientStatus, OrdererClientStatus:
case EndorserClientStatus, OrdererClientStatus, ClientStatus:
return ToSDKStatusCode(s.Code).String()
default:
return Unknown.String()
Expand Down

0 comments on commit ef80627

Please sign in to comment.