Commit 5886042f authored by vipwzw's avatar vipwzw

auto ci

parent 09366cfa
...@@ -6,11 +6,12 @@ package main ...@@ -6,11 +6,12 @@ package main
import ( import (
"fmt" "fmt"
log "github.com/33cn/chain33/common/log/log15"
"gopkg.in/yaml.v2"
"os" "os"
"path/filepath" "path/filepath"
log "github.com/33cn/chain33/common/log/log15"
"gopkg.in/yaml.v2"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
_ "github.com/33cn/plugin/plugin/crypto/init" _ "github.com/33cn/plugin/plugin/crypto/init"
"github.com/33cn/plugin/plugin/dapp/cert/authority/tools/cryptogen/generator" "github.com/33cn/plugin/plugin/dapp/cert/authority/tools/cryptogen/generator"
...@@ -30,8 +31,8 @@ var ( ...@@ -30,8 +31,8 @@ var (
Short: "chain33 crypto tool for generating key and certificate", Short: "chain33 crypto tool for generating key and certificate",
Run: generate, Run: generate,
} }
cfg *generator.GenConfig cfg *generator.GenConfig
logger = log.New("module", "main") logger = log.New("module", "main")
) )
func initCfg(path string) (*generator.GenConfig, error) { func initCfg(path string) (*generator.GenConfig, error) {
......
...@@ -123,7 +123,7 @@ func (ks *fileBasedKeyStore) StoreKey(k Key) (err error) { ...@@ -123,7 +123,7 @@ func (ks *fileBasedKeyStore) StoreKey(k Key) (err error) {
func (ks *fileBasedKeyStore) storePrivateKeyByte(alias string, privateKey interface{}) error { func (ks *fileBasedKeyStore) storePrivateKeyByte(alias string, privateKey interface{}) error {
rawKey, err := utils.PrivateKeyToByte(privateKey) rawKey, err := utils.PrivateKeyToByte(privateKey)
if err != nil { if err != nil {
logger.Error("Failed converting private key to PEM","name", alias, "error", err) logger.Error("Failed converting private key to PEM", "name", alias, "error", err)
return err return err
} }
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"encoding/asn1" "encoding/asn1"
"encoding/pem" "encoding/pem"
"fmt" "fmt"
pkecdsa "github.com/33cn/plugin/plugin/crypto/ecdsa" pkecdsa "github.com/33cn/plugin/plugin/crypto/ecdsa"
pkesm2 "github.com/33cn/plugin/plugin/crypto/sm2" pkesm2 "github.com/33cn/plugin/plugin/crypto/sm2"
"github.com/33cn/plugin/plugin/dapp/evm/executor/vm/common" "github.com/33cn/plugin/plugin/dapp/evm/executor/vm/common"
......
package generator package generator
type UserConfig struct { type UserConfig struct {
Name string `yaml:"Name"` Name string `yaml:"Name"`
} }
type CAConfig struct { type CAConfig struct {
CommonName string `yaml:"CommonName"` CommonName string `yaml:"CommonName"`
Country string `yaml:"Country"` Country string `yaml:"Country"`
Province string `yaml:"Province"` Province string `yaml:"Province"`
Locality string `yaml:"Locality"` Locality string `yaml:"Locality"`
Expire int `yaml:"Expire"` Expire int `yaml:"Expire"`
} }
type CertConfig struct { type CertConfig struct {
Name string `yaml:"Name"` Name string `yaml:"Name"`
CA CAConfig `yaml:"CA"` CA CAConfig `yaml:"CA"`
User []UserConfig `yaml:"User"` User []UserConfig `yaml:"User"`
} }
type GenConfig struct { type GenConfig struct {
SignType string `yaml:"SignType"` SignType string `yaml:"SignType"`
Root CertConfig `yaml:"Root"` Root CertConfig `yaml:"Root"`
Organizations []CertConfig `yaml:"Organizations"` Organizations []CertConfig `yaml:"Organizations"`
} }
func (cfg *GenConfig) GetOrgCertConfig(orgName string) *CertConfig { func (cfg *GenConfig) GetOrgCertConfig(orgName string) *CertConfig {
......
...@@ -28,19 +28,19 @@ import ( ...@@ -28,19 +28,19 @@ import (
// EcdsaCA ecdsa CA结构 // EcdsaCA ecdsa CA结构
type EcdsaCA struct { type EcdsaCA struct {
Name string Name string
Signer crypto.Signer Signer crypto.Signer
SignCert *x509.Certificate SignCert *x509.Certificate
CertConfig *CertConfig CertConfig *CertConfig
} }
// SM2CA SM2 CA结构 // SM2CA SM2 CA结构
type SM2CA struct { type SM2CA struct {
Name string Name string
Signer crypto.Signer Signer crypto.Signer
SignCert *sm2.Certificate SignCert *sm2.Certificate
Sm2Key csp.Key Sm2Key csp.Key
CertConfig *CertConfig CertConfig *CertConfig
} }
// NewCA 根据类型生成CA生成器 // NewCA 根据类型生成CA生成器
...@@ -79,7 +79,7 @@ func newEcdsaCA(baseDir string, certConfig *CertConfig) (*EcdsaCA, error) { ...@@ -79,7 +79,7 @@ func newEcdsaCA(baseDir string, certConfig *CertConfig) (*EcdsaCA, error) {
template.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageAny} template.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageAny}
subject := pkix.Name{ subject := pkix.Name{
Country: []string{certConfig.CA.Country}, Country: []string{certConfig.CA.Country},
Locality: []string{certConfig.CA.Locality}, Locality: []string{certConfig.CA.Locality},
Province: []string{certConfig.CA.Province}, Province: []string{certConfig.CA.Province},
} }
...@@ -94,10 +94,10 @@ func newEcdsaCA(baseDir string, certConfig *CertConfig) (*EcdsaCA, error) { ...@@ -94,10 +94,10 @@ func newEcdsaCA(baseDir string, certConfig *CertConfig) (*EcdsaCA, error) {
return nil, err return nil, err
} }
ca = &EcdsaCA{ ca = &EcdsaCA{
Name: certConfig.Name, Name: certConfig.Name,
Signer: signer, Signer: signer,
SignCert: x509Cert, SignCert: x509Cert,
CertConfig: certConfig, CertConfig: certConfig,
} }
return ca, nil return ca, nil
...@@ -119,7 +119,7 @@ func (ca *EcdsaCA) SignCertificate(baseDir, fileName string, sans []string, pub ...@@ -119,7 +119,7 @@ func (ca *EcdsaCA) SignCertificate(baseDir, fileName string, sans []string, pub
} }
subject := pkix.Name{ subject := pkix.Name{
Country: []string{ca.CertConfig.CA.Country}, Country: []string{ca.CertConfig.CA.Country},
Locality: []string{ca.CertConfig.CA.Locality}, Locality: []string{ca.CertConfig.CA.Locality},
Province: []string{ca.CertConfig.CA.Province}, Province: []string{ca.CertConfig.CA.Province},
} }
...@@ -171,10 +171,10 @@ func (ca *EcdsaCA) GenerateLocalOrg(baseDir, fileName string, orgCfg *CertConfig ...@@ -171,10 +171,10 @@ func (ca *EcdsaCA) GenerateLocalOrg(baseDir, fileName string, orgCfg *CertConfig
} }
orgCA := &EcdsaCA{ orgCA := &EcdsaCA{
Name: ca.Name, Name: ca.Name,
Signer: signer, Signer: signer,
SignCert: cert, SignCert: cert,
CertConfig: orgCfg, CertConfig: orgCfg,
} }
return orgCA, nil return orgCA, nil
} }
...@@ -267,7 +267,7 @@ func newSM2CA(baseDir string, certConfig *CertConfig) (*SM2CA, error) { ...@@ -267,7 +267,7 @@ func newSM2CA(baseDir string, certConfig *CertConfig) (*SM2CA, error) {
template.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageAny} template.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageAny}
subject := pkix.Name{ subject := pkix.Name{
Country: []string{certConfig.CA.Country}, Country: []string{certConfig.CA.Country},
Locality: []string{certConfig.CA.Locality}, Locality: []string{certConfig.CA.Locality},
Province: []string{certConfig.CA.Province}, Province: []string{certConfig.CA.Province},
} }
...@@ -309,7 +309,7 @@ func (ca *SM2CA) SignCertificate(baseDir, fileName string, sans []string, pub in ...@@ -309,7 +309,7 @@ func (ca *SM2CA) SignCertificate(baseDir, fileName string, sans []string, pub in
} }
subject := pkix.Name{ subject := pkix.Name{
Country: []string{ca.CertConfig.CA.Country}, Country: []string{ca.CertConfig.CA.Country},
Locality: []string{ca.CertConfig.CA.Locality}, Locality: []string{ca.CertConfig.CA.Locality},
Province: []string{ca.CertConfig.CA.Province}, Province: []string{ca.CertConfig.CA.Province},
} }
...@@ -362,10 +362,10 @@ func (ca *SM2CA) GenerateLocalOrg(baseDir, fileName string, orgCfg *CertConfig) ...@@ -362,10 +362,10 @@ func (ca *SM2CA) GenerateLocalOrg(baseDir, fileName string, orgCfg *CertConfig)
} }
orgCA := &SM2CA{ orgCA := &SM2CA{
Name: orgCfg.Name, Name: orgCfg.Name,
Signer: signer, Signer: signer,
SignCert: utils.ParseX509CertificateToSm2(cert), SignCert: utils.ParseX509CertificateToSm2(cert),
CertConfig: orgCfg, CertConfig: orgCfg,
} }
return orgCA, nil return orgCA, nil
} }
...@@ -424,7 +424,7 @@ func createFolderStructure(rootDir string, isOrg bool) error { ...@@ -424,7 +424,7 @@ func createFolderStructure(rootDir string, isOrg bool) error {
filepath.Join(rootDir, "signcerts"), filepath.Join(rootDir, "signcerts"),
} }
if isOrg { if isOrg {
folders = append(folders, filepath.Join(rootDir, "intermediatecerts"),) folders = append(folders, filepath.Join(rootDir, "intermediatecerts"))
} }
for _, folder := range folders { for _, folder := range folders {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment