Skip to content

Commit

Permalink
Merge pull request #110 from s7techlab/identity_ou_loader
Browse files Browse the repository at this point in the history
Identity ou loader
  • Loading branch information
vitiko authored Mar 31, 2022
2 parents 30b6aca + 8cb68df commit fcc03d7
Show file tree
Hide file tree
Showing 23 changed files with 605 additions and 125 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ require (
github.com/hyperledger/fabric-protos-go v0.0.0-20201028172056-a3136dde2354
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mitchellh/mapstructure v1.2.2
github.com/onsi/ginkgo v1.8.0
github.com/onsi/gomega v1.9.0
github.com/pelletier/go-toml v1.4.0 // indirect
github.com/pkg/errors v0.8.1
github.com/spf13/afero v1.2.2 // indirect
Expand All @@ -34,7 +36,7 @@ require (
golang.org/x/text v0.3.5 // indirect
google.golang.org/genproto v0.0.0-20210122163508-8081c04a3579 // indirect
google.golang.org/grpc v1.29.1
google.golang.org/protobuf v1.25.0 // indirect
google.golang.org/protobuf v1.25.0
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.2.8
)
6 changes: 3 additions & 3 deletions identity/deprecated.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func NewMSPIdentityRaw(mspId string, cert *x509.Certificate, privateKey interfac
return New(mspId, cert, privateKey), nil
}

// Deprecated: use NewMSP to create MSP
func NewMSPIdentitiesFromPath(mspID string, mspPath string) (*MSPContent, error) {
return NewMSP(mspID, WithMSPPath(mspPath))
// Deprecated: use MSPFromPath to create MSP
func NewMSPIdentitiesFromPath(mspID string, mspPath string) (*MSPConfig, error) {
return MSPFromPath(mspID, mspPath)
}

// Deprecated: use New
Expand Down
36 changes: 14 additions & 22 deletions identity/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,28 @@ var (
// - (optional) a folder tlsintermediatecerts to include PEM files each corresponding to an intermediate TLS CA’s certificate

const (
MSPAdmincertsPath = "admincerts"
MSPCacertsPath = "cacerts"
MSPIntermediatecertsPath = "intermediatecerts"
MSPKeystorePath = "keystore"
MSPSigncertsPath = "signcerts"
MSPUserscertsPath = "user"
MSPAdminCertsPath = `admincerts`
MSPCaCertsPath = `cacerts`
MSPIntermediateCertsPath = `intermediatecerts`
MSPTLSCaCertsPath = `tlscacerts`
MSPTLSIntermediateCertsPath = `tlsintermediatecerts`
MSPKeystorePath = "keystore"
MSPSignCertsPath = "signcerts"
MSPUsersCertsPath = "user"
MSPOuCertsPath = "ou"
MspConfigFile = "config.yaml"
)

func AdmincertsPath(mspPath string) string {
return filepath.Join(mspPath, MSPAdmincertsPath)
func AdminCertsPath(mspPath string) string {
return filepath.Join(mspPath, MSPAdminCertsPath)
}

func KeystorePath(mspPath string) string {
return filepath.Join(mspPath, MSPKeystorePath)
}

func SigncertsPath(mspPath string) string {
return filepath.Join(mspPath, MSPSigncertsPath)
}

func UsercertsPath(mspPath string) string {
return filepath.Join(mspPath, MSPUserscertsPath)
}

func CacertsPath(mspPath string) string {
return filepath.Join(mspPath, MSPCacertsPath)
}

func IntermediatecertsPath(mspPath string) string {
return filepath.Join(mspPath, MSPIntermediatecertsPath)
func SignCertsPath(mspPath string) string {
return filepath.Join(mspPath, MSPSignCertsPath)
}

func readFirstFile(dir string) ([]byte, error) {
Expand Down
15 changes: 12 additions & 3 deletions identity/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,24 @@ func New(mspId string, cert *x509.Certificate, privateKey interface{}) *identity
}
}

func FromBytesWithoutSigning(mspId string, certRaw []byte) (*identity, error) {
cert, err := Certificate(certRaw)
if err != nil {
return nil, fmt.Errorf(`certificate: %w`, err)
}

return New(mspId, cert, nil), nil
}

func FromBytes(mspId string, certRaw []byte, keyRaw []byte) (*identity, error) {
cert, err := Certificate(certRaw)
if err != nil {
return nil, err
return nil, fmt.Errorf(`certificate: %w`, err)
}

key, err := Key(keyRaw)
if err != nil {
return nil, err
return nil, fmt.Errorf(`key: %w`, err)
}

return New(mspId, cert, key), nil
Expand All @@ -67,7 +76,7 @@ func FromCertKeyPath(mspId string, certPath string, keyPath string) (api.Identit
}

func SignerFromMSPPath(mspId string, mspPath string) (*identity, error) {
return FirstFromPath(mspId, SigncertsPath(mspPath), KeystorePath(mspPath))
return FirstFromPath(mspId, SignCertsPath(mspPath), KeystorePath(mspPath))
}

func (i *identity) GetSigningIdentity(cs api.CryptoSuite) msp.SigningIdentity {
Expand Down
2 changes: 1 addition & 1 deletion identity/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,5 @@ func KeyForCert(certRaw []byte, keyDir string) (interface{}, error) {
return Key(keyRaw)
}

return nil, ErrKeyNotFound
return nil, fmt.Errorf(`key dir = %s, files: %d: %w`, keyDir, len(files), ErrKeyNotFound)
}
Loading

0 comments on commit fcc03d7

Please sign in to comment.