Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit f4ddd6f

Browse files
committed
[FAB-6258] Bump fabric third_party revision
Change-Id: I2de1ebf52442a957928b4245020f3011e9cd32e0 Signed-off-by: Troy Ronda <troy.ronda@securekey.com>
1 parent 171e0c6 commit f4ddd6f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1344
-670
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ FABRIC_TOOLS_IMAGE ?= hyperledger/fabric-tools
4646
FABRIC_TOOLS_TAG ?= $(ARCH)-$(FABRIC_TOOLS_VERSION)
4747

4848
# Upstream fabric patching (overridable)
49-
THIRDPARTY_FABRIC_CA_BRANCH ?= release
50-
THIRDPARTY_FABRIC_CA_COMMIT ?= v1.0.2
49+
THIRDPARTY_FABRIC_CA_BRANCH ?= master
50+
THIRDPARTY_FABRIC_CA_COMMIT ?= 2f9617379ec6c253e610ac02b60b3f963f95ad1d
5151
THIRDPARTY_FABRIC_BRANCH ?= master
52-
THIRDPARTY_FABRIC_COMMIT ?= a657db28a0ff53ed512bd6f4ac4786a0f4ca709c
52+
THIRDPARTY_FABRIC_COMMIT ?= 505eb68f64493db86859b649b91e7b7068139e6f
5353

5454
# Local variables used by makefile
5555
PACKAGE_NAME := github.com/hyperledger/fabric-sdk-go

internal/github.com/hyperledger/fabric-ca/api/client.go

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ type RegistrationRequest struct {
2929
// Name is the unique name of the identity
3030
Name string `json:"id" help:"Unique name of the identity"`
3131
// Type of identity being registered (e.g. "peer, app, user")
32-
Type string `json:"type" help:"Type of identity being registered (e.g. 'peer, app, user')"`
32+
Type string `json:"type" def:"user" help:"Type of identity being registered (e.g. 'peer, app, user')"`
3333
// Secret is an optional password. If not specified,
3434
// a random secret is generated. In both cases, the secret
3535
// is returned in the RegistrationResponse.
36-
Secret string `json:"secret,omitempty" help:"The enrollment secret for the identity being registered"`
36+
Secret string `json:"secret,omitempty" secret:"password" help:"The enrollment secret for the identity being registered"`
3737
// MaxEnrollments is the maximum number of times the secret can
3838
// be reused to enroll.
3939
MaxEnrollments int `json:"max_enrollments,omitempty" def:"-1" help:"The maximum number of times the secret can be reused to enroll."`
@@ -67,6 +67,9 @@ type EnrollmentRequest struct {
6767
CSR *CSRInfo `json:"csr,omitempty" help:"Certificate Signing Request info"`
6868
// CAName is the name of the CA to connect to
6969
CAName string `json:"caname,omitempty" skip:"true"`
70+
// AttrReqs are requests for attributes to add to the certificate.
71+
// Each attribute is added only if the requestor owns the attribute.
72+
AttrReqs []*AttributeRequest `json:"attr_reqs,omitempty"`
7073
}
7174

7275
// ReenrollmentRequest is a request to reenroll an identity.
@@ -80,6 +83,9 @@ type ReenrollmentRequest struct {
8083
CSR *CSRInfo `json:"csr,omitempty"`
8184
// CAName is the name of the CA to connect to
8285
CAName string `json:"caname,omitempty" skip:"true"`
86+
// AttrReqs are requests for attributes to add to the certificate.
87+
// Each attribute is added only if the requestor owns the attribute.
88+
AttrReqs []*AttributeRequest `json:"attr_reqs,omitempty"`
8389
}
8490

8591
// RevocationRequest is a revocation request for a single certificate or all certificates
@@ -109,7 +115,7 @@ type GetCAInfoRequest struct {
109115
CAName string `json:"caname,omitempty" skip:"true"`
110116
}
111117

112-
// CSRInfo is Certificate Signing Request information
118+
// CSRInfo is Certificate Signing Request (CSR) Information
113119
type CSRInfo struct {
114120
CN string `json:"CN"`
115121
Names []csr.Name `json:"names,omitempty"`
@@ -123,4 +129,32 @@ type CSRInfo struct {
123129
type Attribute struct {
124130
Name string `json:"name"`
125131
Value string `json:"value"`
132+
ECert bool `json:"ecert,omitempty"`
133+
}
134+
135+
// GetName returns the name of the attribute
136+
func (a *Attribute) GetName() string {
137+
return a.Name
138+
}
139+
140+
// GetValue returns the value of the attribute
141+
func (a *Attribute) GetValue() string {
142+
return a.Value
143+
}
144+
145+
// AttributeRequest is a request for an attribute.
146+
// This implements the certmgr/AttributeRequest interface.
147+
type AttributeRequest struct {
148+
Name string `json:"name"`
149+
Require bool `json:"require,omitempty"`
150+
}
151+
152+
// GetName returns the name of an attribute being requested
153+
func (ar *AttributeRequest) GetName() string {
154+
return ar.Name
155+
}
156+
157+
// IsRequired returns true if the attribute being requested is required
158+
func (ar *AttributeRequest) IsRequired() bool {
159+
return ar.Require
126160
}

internal/github.com/hyperledger/fabric-ca/api/net.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ type RegistrationResponseNet struct {
4343
// EnrollmentRequestNet is a request to enroll an identity
4444
type EnrollmentRequestNet struct {
4545
signer.SignRequest
46-
CAName string
46+
CAName string
47+
AttrReqs []*AttributeRequest `json:"attr_reqs,omitempty"`
4748
}
4849

4950
// ReenrollmentRequestNet is a request to reenroll an identity.
5051
// This is useful to renew a certificate before it has expired.
5152
type ReenrollmentRequestNet struct {
5253
signer.SignRequest
53-
CAName string
54+
CAName string
55+
AttrReqs []*AttributeRequest `json:"attr_reqs,omitempty"`
5456
}
5557

5658
// RevocationRequestNet is a revocation request which flows over the network

internal/github.com/hyperledger/fabric-ca/lib/client.go

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ package lib
2323
import (
2424
"bytes"
2525
"encoding/json"
26-
"errors"
2726
"fmt"
2827
"io/ioutil"
2928
"net"
@@ -34,6 +33,8 @@ import (
3433
"strconv"
3534
"strings"
3635

36+
"github.com/hyperledger/fabric-sdk-go/pkg/errors"
37+
3738
cfsslapi "github.com/cloudflare/cfssl/api"
3839
"github.com/cloudflare/cfssl/csr"
3940
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/api"
@@ -56,6 +57,8 @@ type Client struct {
5657
keyFile, certFile, caCertsDir string
5758
// The crypto service provider (BCCSP)
5859
csp bccsp.BCCSP
60+
// HTTP client associated with this Fabric CA client
61+
httpClient *http.Client
5962
}
6063

6164
// Init initializes the client
@@ -75,33 +78,59 @@ func (c *Client) Init() error {
7578
keyDir := path.Join(mspDir, "keystore")
7679
err = os.MkdirAll(keyDir, 0700)
7780
if err != nil {
78-
return fmt.Errorf("Failed to create keystore directory: %s", err)
81+
return errors.Wrap(err, "Failed to create keystore directory")
7982
}
8083
c.keyFile = path.Join(keyDir, "key.pem")
8184
// Cert directory and file
8285
certDir := path.Join(mspDir, "signcerts")
8386
err = os.MkdirAll(certDir, 0755)
8487
if err != nil {
85-
return fmt.Errorf("Failed to create signcerts directory: %s", err)
88+
return errors.Wrap(err, "Failed to create signcerts directory")
8689
}
8790
c.certFile = path.Join(certDir, "cert.pem")
8891
// CA certs directory
8992
c.caCertsDir = path.Join(mspDir, "cacerts")
9093
err = os.MkdirAll(c.caCertsDir, 0755)
9194
if err != nil {
92-
return fmt.Errorf("Failed to create cacerts directory: %s", err)
95+
return errors.Wrap(err, "Failed to create cacerts directory")
9396
}
9497
// Initialize BCCSP (the crypto layer)
9598
c.csp, err = util.InitBCCSP(&cfg.CSP, mspDir, c.HomeDir)
9699
if err != nil {
97100
return err
98101
}
102+
// Create http.Client object and associate it with this client
103+
err = c.initHTTPClient()
104+
if err != nil {
105+
return err
106+
}
107+
99108
// Successfully initialized the client
100109
c.initialized = true
101110
}
102111
return nil
103112
}
104113

114+
func (c *Client) initHTTPClient() error {
115+
tr := new(http.Transport)
116+
if c.Config.TLS.Enabled {
117+
log.Info("TLS Enabled")
118+
119+
err := tls.AbsTLSClient(&c.Config.TLS, c.HomeDir)
120+
if err != nil {
121+
return err
122+
}
123+
124+
tlsConfig, err2 := tls.GetClientTLSConfig(&c.Config.TLS, c.csp)
125+
if err2 != nil {
126+
return fmt.Errorf("Failed to get client TLS config: %s", err2)
127+
}
128+
tr.TLSClientConfig = tlsConfig
129+
}
130+
c.httpClient = &http.Client{Transport: tr}
131+
return nil
132+
}
133+
105134
// GetServerInfoResponse is the response from the GetServerInfo call
106135
type GetServerInfoResponse struct {
107136
// CAName is the name of the CA
@@ -168,11 +197,12 @@ func (c *Client) Enroll(req *api.EnrollmentRequest) (*EnrollmentResponse, error)
168197
// Generate the CSR
169198
csrPEM, key, err := c.GenCSR(req.CSR, req.Name)
170199
if err != nil {
171-
return nil, fmt.Errorf("Failure generating CSR: %s", err)
200+
return nil, errors.WithMessage(err, "Failure generating CSR")
172201
}
173202

174203
reqNet := &api.EnrollmentRequestNet{
175-
CAName: req.CAName,
204+
CAName: req.CAName,
205+
AttrReqs: req.AttrReqs,
176206
}
177207

178208
if req.CSR != nil {
@@ -211,7 +241,7 @@ func (c *Client) newEnrollmentResponse(result *enrollmentResponseNet, id string,
211241
log.Debugf("newEnrollmentResponse %s", id)
212242
certByte, err := util.B64Decode(result.Cert)
213243
if err != nil {
214-
return nil, fmt.Errorf("Invalid response format from server: %s", err)
244+
return nil, errors.WithMessage(err, "Invalid response format from server")
215245
}
216246
resp := &EnrollmentResponse{
217247
Identity: newIdentity(c, id, key, certByte),
@@ -298,7 +328,7 @@ func (c *Client) StoreMyIdentity(cert []byte) error {
298328
}
299329
err = util.WriteFile(c.certFile, cert, 0644)
300330
if err != nil {
301-
return fmt.Errorf("Failed to store my certificate: %s", err)
331+
return errors.WithMessage(err, "Failed to store my certificate")
302332
}
303333
log.Infof("Stored client certificate at %s", c.certFile)
304334
return nil
@@ -322,7 +352,7 @@ func (c *Client) LoadIdentity(keyFile, certFile string) (*Identity, error) {
322352
log.Debugf("No key found in BCCSP keystore, attempting fallback")
323353
key, err = util.ImportBCCSPKeyFromPEM(keyFile, c.csp, true)
324354
if err != nil {
325-
return nil, fmt.Errorf("Could not find the private key in BCCSP keystore nor in keyfile %s: %s", keyFile, err)
355+
return nil, errors.WithMessage(err, fmt.Sprintf("Could not find the private key in BCCSP keystore nor in keyfile %s", keyFile))
326356
}
327357
}
328358
return c.NewIdentity(key, cert)
@@ -365,7 +395,7 @@ func (c *Client) newGet(endpoint string) (*http.Request, error) {
365395
}
366396
req, err := http.NewRequest("GET", curl, bytes.NewReader([]byte{}))
367397
if err != nil {
368-
return nil, fmt.Errorf("Failed creating GET request for %s: %s", curl, err)
398+
return nil, errors.Wrapf(err, "Failed creating GET request for %s", curl)
369399
}
370400
return req, nil
371401
}
@@ -378,7 +408,7 @@ func (c *Client) newPost(endpoint string, reqBody []byte) (*http.Request, error)
378408
}
379409
req, err := http.NewRequest("POST", curl, bytes.NewReader(reqBody))
380410
if err != nil {
381-
return nil, fmt.Errorf("Failed posting to %s: %s", curl, err)
411+
return nil, errors.Wrapf(err, "Failed posting to %s", curl)
382412
}
383413
return req, nil
384414
}
@@ -394,35 +424,21 @@ func (c *Client) SendReq(req *http.Request, result interface{}) (err error) {
394424
return err
395425
}
396426

397-
var tr = new(http.Transport)
398-
399-
if c.Config.TLS.Enabled {
400-
log.Info("TLS Enabled")
401-
402-
err = tls.AbsTLSClient(&c.Config.TLS, c.HomeDir)
403-
if err != nil {
404-
return err
405-
}
406-
407-
tlsConfig, err2 := tls.GetClientTLSConfig(&c.Config.TLS, c.csp)
408-
if err2 != nil {
409-
return fmt.Errorf("Failed to get client TLS config: %s", err2)
410-
}
411-
412-
tr.TLSClientConfig = tlsConfig
413-
}
414-
415-
httpClient := &http.Client{Transport: tr}
416-
resp, err := httpClient.Do(req)
427+
resp, err := c.httpClient.Do(req)
417428
if err != nil {
418-
return fmt.Errorf("POST failure [%s]; not sending\n%s", err, reqStr)
429+
return errors.Wrapf(err, "POST failure of request: %s", reqStr)
419430
}
420431
var respBody []byte
421432
if resp.Body != nil {
422433
respBody, err = ioutil.ReadAll(resp.Body)
423-
defer resp.Body.Close()
434+
defer func() {
435+
err := resp.Body.Close()
436+
if err != nil {
437+
log.Debugf("Failed to close the response body: %s", err.Error())
438+
}
439+
}()
424440
if err != nil {
425-
return fmt.Errorf("Failed to read response [%s] of request:\n%s", err, reqStr)
441+
return errors.Wrapf(err, "Failed to read response of request: %s", reqStr)
426442
}
427443
log.Debugf("Received response\n%s", util.HTTPResponseToString(resp))
428444
}
@@ -431,22 +447,22 @@ func (c *Client) SendReq(req *http.Request, result interface{}) (err error) {
431447
body = new(cfsslapi.Response)
432448
err = json.Unmarshal(respBody, body)
433449
if err != nil {
434-
return fmt.Errorf("Failed to parse response: %s\n%s", err, respBody)
450+
return errors.Wrapf(err, "Failed to parse response: %s", respBody)
435451
}
436452
if len(body.Errors) > 0 {
437453
msg := body.Errors[0].Message
438-
return fmt.Errorf("Error response from server was: %s", msg)
454+
return errors.Errorf("Response from server: %s", msg)
439455
}
440456
}
441457
scode := resp.StatusCode
442458
if scode >= 400 {
443-
return fmt.Errorf("Failed with server status code %d for request:\n%s", scode, reqStr)
459+
return errors.Errorf("Failed with server status code %d for request:\n%s", scode, reqStr)
444460
}
445461
if body == nil {
446-
return fmt.Errorf("Empty response body:\n%s", reqStr)
462+
return errors.Errorf("Empty response body:\n%s", reqStr)
447463
}
448464
if !body.Success {
449-
return fmt.Errorf("Server returned failure for request:\n%s", reqStr)
465+
return errors.Errorf("Server returned failure for request:\n%s", reqStr)
450466
}
451467
log.Debugf("Response body result: %+v", body.Result)
452468
if result != nil {

internal/github.com/hyperledger/fabric-ca/lib/clientconfig.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ package lib
2323
import (
2424
"fmt"
2525
"net/url"
26+
"path"
2627

2728
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/api"
29+
log "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib/logbridge"
2830
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib/tls"
31+
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/util"
32+
"github.com/hyperledger/fabric-sdk-go/pkg/errors"
2933
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp/factory"
3034
)
3135

@@ -63,7 +67,7 @@ func (c *ClientConfig) Enroll(rawurl, home string) (*EnrollmentResponse, error)
6367
expecting := fmt.Sprintf(
6468
"%s://<enrollmentID>:<secret>@%s",
6569
purl.Scheme, purl.Host)
66-
return nil, fmt.Errorf(
70+
return nil, errors.Errorf(
6771
"The URL of the fabric CA server is missing the enrollment ID and secret;"+
6872
" found '%s' but expecting '%s'", rawurl, expecting)
6973
}
@@ -74,3 +78,32 @@ func (c *ClientConfig) Enroll(rawurl, home string) (*EnrollmentResponse, error)
7478
client := &Client{HomeDir: home, Config: c}
7579
return client.Enroll(&c.Enrollment)
7680
}
81+
82+
// GenCSR generates a certificate signing request and writes the CSR to a file.
83+
func (c *ClientConfig) GenCSR(home string) error {
84+
85+
client := &Client{HomeDir: home, Config: c}
86+
// Generate the CSR
87+
88+
err := client.Init()
89+
if err != nil {
90+
return err
91+
}
92+
93+
if c.CSR.CN == "" {
94+
return errors.Errorf("CSR common name not specified; use '--csr.cn' flag")
95+
}
96+
97+
csrPEM, _, err := client.GenCSR(&c.CSR, c.CSR.CN)
98+
if err != nil {
99+
return err
100+
}
101+
102+
csrFile := path.Join(client.Config.MSPDir, "signcerts", fmt.Sprintf("%s.csr", c.CSR.CN))
103+
err = util.WriteFile(csrFile, csrPEM, 0644)
104+
if err != nil {
105+
return errors.WithMessage(err, "Failed to store the CSR")
106+
}
107+
log.Infof("Stored CSR at %s", csrFile)
108+
return nil
109+
}

0 commit comments

Comments
 (0)