63 Star 181 Fork 3

Gitee 极速下载 / hyperledger-fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/hyperledger/fabric
克隆/下载
ca.go 2.38 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package tlsgen
import (
"crypto"
"crypto/x509"
)
// CertKeyPair denotes a TLS certificate and corresponding key,
// both PEM encoded
type CertKeyPair struct {
// Cert is the certificate, PEM encoded
Cert []byte
// Key is the key corresponding to the certificate, PEM encoded
Key []byte
crypto.Signer
TLSCert *x509.Certificate
}
// CA defines a certificate authority that can generate
// certificates signed by it
type CA interface {
// CertBytes returns the certificate of the CA in PEM encoding
CertBytes() []byte
NewIntermediateCA() (CA, error)
// newCertKeyPair returns a certificate and private key pair and nil,
// or nil, error in case of failure
// The certificate is signed by the CA and is used for TLS client authentication
NewClientCertKeyPair() (*CertKeyPair, error)
// NewServerCertKeyPair returns a CertKeyPair and nil,
// with a given custom SAN.
// The certificate is signed by the CA.
// Returns nil, error in case of failure
NewServerCertKeyPair(host string) (*CertKeyPair, error)
}
type ca struct {
caCert *CertKeyPair
}
func NewCA() (CA, error) {
c := &ca{}
var err error
c.caCert, err = newCertKeyPair(true, false, "", nil, nil)
if err != nil {
return nil, err
}
return c, nil
}
func (c *ca) NewIntermediateCA() (CA, error) {
intermediateCA := &ca{}
var err error
intermediateCA.caCert, err = newCertKeyPair(true, false, "", c.caCert.Signer, c.caCert.TLSCert)
if err != nil {
return nil, err
}
return intermediateCA, nil
}
// CertBytes returns the certificate of the CA in PEM encoding
func (c *ca) CertBytes() []byte {
return c.caCert.Cert
}
// newClientCertKeyPair returns a certificate and private key pair and nil,
// or nil, error in case of failure
// The certificate is signed by the CA and is used as a client TLS certificate
func (c *ca) NewClientCertKeyPair() (*CertKeyPair, error) {
return newCertKeyPair(false, false, "", c.caCert.Signer, c.caCert.TLSCert)
}
// newServerCertKeyPair returns a certificate and private key pair and nil,
// or nil, error in case of failure
// The certificate is signed by the CA and is used as a server TLS certificate
func (c *ca) NewServerCertKeyPair(host string) (*CertKeyPair, error) {
keypair, err := newCertKeyPair(false, true, host, c.caCert.Signer, c.caCert.TLSCert)
if err != nil {
return nil, err
}
return keypair, nil
}
Go
1
https://gitee.com/mirrors/hyperledger-fabric.git
git@gitee.com:mirrors/hyperledger-fabric.git
mirrors
hyperledger-fabric
hyperledger-fabric
v2.1.1

搜索帮助

53164aa7 5694891 3bd8fe86 5694891