-
Notifications
You must be signed in to change notification settings - Fork 709
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-5389] gencsr command for fabric-ca-client
Adding a gencsr command to fabric-ca-client for [FAB-5389] to generate certificate signing requests and to write them to a file without any interaction with the fabric-ca-server. This allows the user to send ceritificate signing requests to an external CA for private keys generated by the BCCSP for the msp directory. Change-Id: Id17b56c122d82875a3cfb0d2332e8cacd26b0eea Signed-off-by: Jonathan Patchell <Jonathan.Patchell@gemalto.com>
- Loading branch information
Jonathan Patchell
authored and
Jonathan Patchell
committed
Aug 15, 2017
1 parent
8335b0c
commit 77f76df
Showing
7 changed files
with
272 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
Copyright IBM Corp. 2017 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/cloudflare/cfssl/log" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// initCmd represents the init command | ||
var gencsrCmd = &cobra.Command{ | ||
Use: "gencsr", | ||
Short: "Generate a CSR", | ||
Long: "Generate a Certificate Signing Request for an identity", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) > 0 { | ||
return fmt.Errorf(extraArgsError, args, cmd.UsageString()) | ||
} | ||
|
||
err := runGenCSR(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
// csrCommonName is the certificate signing request common name specified via the flag | ||
var csrCommonName string | ||
|
||
func init() { | ||
gencsrCmd.Flags().StringVar(&csrCommonName, "csr.cn", "", "The common name for the certificate signing request") | ||
rootCmd.AddCommand(gencsrCmd) | ||
} | ||
|
||
// The client enroll main logic | ||
func runGenCSR(cmd *cobra.Command) error { | ||
log.Debug("Entered runGenCSR") | ||
|
||
err := configInit(cmd.Name()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if csrCommonName != "" { | ||
clientCfg.CSR.CN = csrCommonName | ||
} | ||
|
||
err = clientCfg.GenCSR(filepath.Dir(cfgFileName)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters