Skip to content

Commit

Permalink
Merge pull request #150 from s7techlab/add-profile-ca-enrollment
Browse files Browse the repository at this point in the history
add enroll profile
  • Loading branch information
vitiko authored Apr 26, 2024
2 parents 2adae58 + 56ff320 commit 1232e47
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion client/ca/http/enroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (c *Client) Enroll(ctx context.Context, name, secret string, req *x509.Cert
}
}

if options.Profile == "" {
options.Profile = ca.EnrollProfileDefault
}

// Add default signature algorithm if not defined
if req.SignatureAlgorithm == x509.UnknownSignatureAlgorithm {
req.SignatureAlgorithm = c.crypto.GetSignatureAlgorithm()
Expand All @@ -45,7 +49,7 @@ func (c *Client) Enroll(ctx context.Context, name, secret string, req *x509.Cert

pemCsr := pem.EncodeToMemory(&pem.Block{Type: `CERTIFICATE REQUEST`, Bytes: csr})

reqBytes, err := json.Marshal(signer.SignRequest{Request: string(pemCsr)})
reqBytes, err := json.Marshal(signer.SignRequest{Request: string(pemCsr), Profile: string(options.Profile)})
if err != nil {
return nil, options.PrivateKey, errors.Wrap(err, `failed to marshal CSR request to JSON`)
}
Expand Down
19 changes: 19 additions & 0 deletions client/ca/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,38 @@ import (
"net/url"
)

type EnrollProfile string

const (
// EnrollProfileDefault asks Fabric CA for certificate used for signing
EnrollProfileDefault EnrollProfile = ""
// EnrollProfileTls asks Fabric CA for certificate used for TLS communication
EnrollProfileTls EnrollProfile = "tls"
)

type EnrollOpts struct {
PrivateKey interface{}
Profile EnrollProfile
}

type EnrollOpt func(opts *EnrollOpts) error

// WithEnrollPrivateKey allows to use previously created private key
func WithEnrollPrivateKey(privateKey interface{}) EnrollOpt {
return func(opts *EnrollOpts) error {
opts.PrivateKey = privateKey
return nil
}
}

// WithEnrollProfile allows to require profile of enrolled certificate
func WithEnrollProfile(profile EnrollProfile) EnrollOpt {
return func(opts *EnrollOpts) error {
opts.Profile = profile
return nil
}
}

type CertificateListOpt func(values *url.Values) error

func WithEnrollId(enrollId string) CertificateListOpt {
Expand Down

0 comments on commit 1232e47

Please sign in to comment.