Commit a3f9db50 authored by pengjun's avatar pengjun Committed by vipwzw

cert执行器linter告警整改

parent 0c401767
......@@ -25,17 +25,17 @@ var (
alog = log.New("module", "authority")
cpuNum = runtime.NumCPU()
// 默认证书组织名
// OrgName 默认证书组织名
OrgName = "Chain33"
// 全局证书校验器
// Author 全局证书校验器
Author = &Authority{}
// 是否开启全局校验开关
// IsAuthEnable 是否开启全局校验开关
IsAuthEnable = false
)
// 证书校验器主要结构
// Authority 证书校验器主要结构
type Authority struct {
// 证书文件路径
cryptoPath string
......@@ -51,14 +51,14 @@ type Authority struct {
HistoryCertCache *HistoryCertData
}
// 历史变更记录
// HistoryCertData 历史变更记录
type HistoryCertData struct {
CryptoCfg *core.AuthConfig
CurHeight int64
NxtHeight int64
}
// 初始化auth
// Init 初始化auth
func (auth *Authority) Init(conf *ty.Authority) error {
if conf == nil || !conf.Enable {
return nil
......@@ -98,7 +98,7 @@ func (auth *Authority) Init(conf *ty.Authority) error {
return nil
}
// store数据转成authConfig数据
// newAuthConfig store数据转成authConfig数据
func newAuthConfig(store *types.HistoryCertStore) *core.AuthConfig {
ret := &core.AuthConfig{}
ret.RootCerts = make([][]byte, len(store.Rootcerts))
......@@ -119,7 +119,7 @@ func newAuthConfig(store *types.HistoryCertStore) *core.AuthConfig {
return ret
}
// 从数据库中的记录数据恢复证书,用于证书回滚
// ReloadCert 从数据库中的记录数据恢复证书,用于证书回滚
func (auth *Authority) ReloadCert(store *types.HistoryCertStore) error {
if !IsAuthEnable {
return nil
......@@ -148,7 +148,7 @@ func (auth *Authority) ReloadCert(store *types.HistoryCertStore) error {
return nil
}
// 从新的authdir下的文件更新证书,用于证书更新
// ReloadCertByHeght 从新的authdir下的文件更新证书,用于证书更新
func (auth *Authority) ReloadCertByHeght(currentHeight int64) error {
if !IsAuthEnable {
return nil
......@@ -177,7 +177,7 @@ func (auth *Authority) ReloadCertByHeght(currentHeight int64) error {
return nil
}
// 并发校验证书
// ValidateCerts 并发校验证书
func (auth *Authority) ValidateCerts(task []*types.Signature) bool {
//FIXME 有并发校验的场景需要考虑竞争,暂时没有并发校验的场景
done := make(chan struct{})
......@@ -239,7 +239,7 @@ func (auth *Authority) task(done <-chan struct{}, taskes <-chan *types.Signature
}
}
// 检验证书
// Validate 检验证书
func (auth *Authority) Validate(signature *types.Signature) error {
// 从proto中解码signature
cert, err := auth.validator.GetCertFromSignature(signature.Signature)
......@@ -265,7 +265,7 @@ func (auth *Authority) Validate(signature *types.Signature) error {
return nil
}
// 历史数据转成store可存储的历史数据
// ToHistoryCertStore 历史数据转成store可存储的历史数据
func (certdata *HistoryCertData) ToHistoryCertStore(store *types.HistoryCertStore) {
if store == nil {
alog.Error("Convert cert data to cert store failed")
......@@ -291,21 +291,21 @@ func (certdata *HistoryCertData) ToHistoryCertStore(store *types.HistoryCertStor
store.NxtHeight = certdata.NxtHeight
}
// 用户关联的证书私钥信息
// User 用户关联的证书私钥信息
type User struct {
ID string
Cert []byte
Key crypto.PrivKey
}
// userloader, SKD加载user使用
// UserLoader SKD加载user使用
type UserLoader struct {
configPath string
userMap map[string]*User
signType int
}
// userloader初始化
// Init userloader初始化
func (loader *UserLoader) Init(configPath string, signType string) error {
loader.configPath = configPath
loader.userMap = make(map[string]*User)
......@@ -376,7 +376,7 @@ func (loader *UserLoader) genCryptoPriv(keyBytes []byte) (crypto.PrivKey, error)
return priv, nil
}
// 根据用户名获取user结构
// Get 根据用户名获取user结构
func (loader *UserLoader) Get(userName string) (*User, error) {
keyvalue := fmt.Sprintf("%s@%s-cert.pem", userName, OrgName)
user, ok := loader.userMap[keyvalue]
......
......@@ -109,7 +109,7 @@ func certFromX509Cert(cert *x509.Certificate) (certificate, error) {
return newCert, nil
}
// 将ECDSA的公钥转成SM2公钥
// ParseECDSAPubKey2SM2PubKey 将ECDSA的公钥转成SM2公钥
func ParseECDSAPubKey2SM2PubKey(key *ecdsa.PublicKey) *sm2.PublicKey {
sm2Key := &sm2.PublicKey{
key.Curve,
......
......@@ -54,7 +54,7 @@ const (
crlsfolder = "crls"
)
// 获取证书文件配置
// GetAuthConfig 获取证书文件配置
func GetAuthConfig(dir string) (*AuthConfig, error) {
cacertDir := filepath.Join(dir, cacerts)
intermediatecertsDir := filepath.Join(dir, intermediatecerts)
......
......@@ -38,7 +38,7 @@ type ecdsaValidator struct {
CRL []*pkix.CertificateList
}
// 创建ecdsa校验器
// NewEcdsaValidator 创建ecdsa校验器
func NewEcdsaValidator() Validator {
return &ecdsaValidator{}
}
......
......@@ -10,7 +10,7 @@ import (
ty "github.com/33cn/plugin/plugin/dapp/cert/types"
)
// 根据类型获取校验器
// GetLocalValidator 根据类型获取校验器
func GetLocalValidator(authConfig *AuthConfig, signType int) (Validator, error) {
var lclValidator Validator
var err error
......
......@@ -33,7 +33,7 @@ type gmValidator struct {
CRL []*pkix.CertificateList
}
// 创建国密证书校验器
// NewGmValidator 创建国密证书校验器
func NewGmValidator() Validator {
return &gmValidator{}
}
......
......@@ -7,7 +7,7 @@ package core
type noneValidator struct {
}
// 创建none校验器
// NewNoneValidator 创建none校验器
func NewNoneValidator() (Validator, error) {
return &noneValidator{}, nil
}
......
......@@ -4,7 +4,7 @@
package core
// 证书校验器
// Validator 证书校验器
type Validator interface {
Setup(config *AuthConfig) error
......@@ -13,7 +13,7 @@ type Validator interface {
GetCertFromSignature(signature []byte) ([]byte, error)
}
// 校验器配置
// AuthConfig 校验器配置
type AuthConfig struct {
RootCerts [][]byte
IntermediateCerts [][]byte
......
......@@ -17,14 +17,14 @@ import (
)
const (
// 默认CA名称
// CANAME 默认CA名称
CANAME = "ca"
CONFIGFILENAME = "chain33.cryptogen.toml"
OUTPUTDIR = "./authdir/crypto"
ORGNAME = "Chain33"
)
// 证书生成工具配置
// Config 证书生成工具配置
type Config struct {
Name []string
SignType string
......
......@@ -7,12 +7,12 @@ package csp
import "crypto"
const (
// ECDSA类型
// ECDSAP256KeyGen ECDSA类型
ECDSAP256KeyGen = 1
SM2P256KygGen = 2
)
// 通用key接口
// Key 通用key接口
type Key interface {
Bytes() ([]byte, error)
SKI() []byte
......@@ -21,30 +21,30 @@ type Key interface {
PublicKey() (Key, error)
}
// 签名器参数接口
// SignerOpts 签名器参数接口
type SignerOpts interface {
crypto.SignerOpts
}
// 证书生成器接口
// CSP 证书生成器接口
type CSP interface {
KeyGen(opts int) (k Key, err error)
Sign(k Key, digest []byte, opts SignerOpts) (signature []byte, err error)
}
// key存储接口
// KeyStore key存储接口
type KeyStore interface {
ReadOnly() bool
StoreKey(k Key) (err error)
}
// 签名器接口
// Signer 签名器接口
type Signer interface {
Sign(k Key, digest []byte, opts SignerOpts) (signature []byte, err error)
}
// key生成器接口
// KeyGenerator key生成器接口
type KeyGenerator interface {
KeyGen(opts int) (k Key, err error)
}
......@@ -11,7 +11,7 @@ import (
"github.com/pkg/errors"
)
// 创建新的证书生成结构
// New 创建新的证书生成结构
func New(keyStore KeyStore) (CSP, error) {
signers := make(map[reflect.Type]Signer)
signers[reflect.TypeOf(&ecdsaPrivateKey{})] = &ecdsaSigner{}
......
......@@ -32,12 +32,12 @@ func signECDSA(k *ecdsa.PrivateKey, digest []byte, opts SignerOpts) (signature [
return MarshalECDSASignature(r, s)
}
// ECDSA签名结构
// ECDSASignature ECDSA签名结构
type ECDSASignature struct {
R, S *big.Int
}
// 编码ECDSA类型签名
// MarshalECDSASignature 编码ECDSA类型签名
func MarshalECDSASignature(r, s *big.Int) ([]byte, error) {
return asn1.Marshal(ECDSASignature{r, s})
}
......
......@@ -22,7 +22,7 @@ import (
var logger = log.New("tools", "cryptogen")
// 创建key存储器
// NewFileBasedKeyStore 创建key存储器
func NewFileBasedKeyStore(pwd []byte, path string, readOnly bool) (KeyStore, error) {
ks := &fileBasedKeyStore{}
return ks, ks.Init(pwd, path, readOnly)
......
......@@ -27,12 +27,12 @@ func signSM2(k *sm2.PrivateKey, digest []byte, opts SignerOpts) (signature []byt
return MarshalSM2Signature(r, s)
}
// SM2签名结构
// SM2Signature SM2签名结构
type SM2Signature struct {
R, S *big.Int
}
// 编码SM2起签名
// MarshalSM2Signature 编码SM2起签名
func MarshalSM2Signature(r, s *big.Int) ([]byte, error) {
return asn1.Marshal(SM2Signature{r, s})
}
......
......@@ -20,7 +20,7 @@ type cspCryptoSigner struct {
pk interface{}
}
// 创建签名器
// New 创建签名器
func New(csp lccsp.CSP, key lccsp.Key) (crypto.Signer, error) {
if csp == nil {
return nil, errors.New("bccsp instance must be different from nil")
......
......@@ -211,7 +211,7 @@ func publicKeyToEncryptedPEM(publicKey interface{}, pwd []byte) ([]byte, error)
}
}
// DER字符转成公钥
// DERToPublicKey DER字符转成公钥
func DERToPublicKey(raw []byte) (pub interface{}, err error) {
if len(raw) == 0 {
return nil, errors.New("Invalid DER. It must be different from nil")
......
......@@ -95,7 +95,7 @@ func newEcdsaCA(baseDir, name string) (*EcdsaCA, error) {
return ca, nil
}
// 证书签名
// SignCertificate 证书签名
func (ca *EcdsaCA) SignCertificate(baseDir, name string, sans []string, pub interface{}) (*x509.Certificate, error) {
template := x509Template()
template.KeyUsage = x509.KeyUsageDigitalSignature
......@@ -116,7 +116,7 @@ func (ca *EcdsaCA) SignCertificate(baseDir, name string, sans []string, pub inte
return cert, nil
}
// 生成本地用户
// GenerateLocalUser 生成本地用户
func (ca *EcdsaCA) GenerateLocalUser(baseDir, name string) error {
err := createFolderStructure(baseDir, true)
if err != nil {
......@@ -234,7 +234,7 @@ func newSM2CA(baseDir, name string) (*SM2CA, error) {
return ca, nil
}
// 证书签名
// SignCertificate 证书签名
func (ca *SM2CA) SignCertificate(baseDir, name string, sans []string, pub interface{}) (*x509.Certificate, error) {
template := x509Template()
template.KeyUsage = x509.KeyUsageDigitalSignature
......@@ -256,7 +256,7 @@ func (ca *SM2CA) SignCertificate(baseDir, name string, sans []string, pub interf
return utils.ParseSm2CertificateToX509(cert), nil
}
// 生成本地用户
// GenerateLocalUser 生成本地用户
func (ca *SM2CA) GenerateLocalUser(baseDir, name string) error {
err := createFolderStructure(baseDir, true)
if err != nil {
......
......@@ -64,7 +64,7 @@ func GetPublicKeySKIFromCert(cert []byte, signType int) (string, error) {
return hex.EncodeToString(ski), nil
}
// 证书编码进签名
// EncodeCertToSignature 证书编码进签名
func EncodeCertToSignature(signByte []byte, cert []byte) ([]byte, error) {
certSign := crypto.CertSignature{}
certSign.Signature = append(certSign.Signature, signByte...)
......@@ -72,7 +72,7 @@ func EncodeCertToSignature(signByte []byte, cert []byte) ([]byte, error) {
return asn1.Marshal(certSign)
}
// 从签名中解码证书
// DecodeCertFromSignature 从签名中解码证书
func DecodeCertFromSignature(signByte []byte) ([]byte, []byte, error) {
var certSignature crypto.CertSignature
_, err := asn1.Unmarshal(signByte, &certSignature)
......@@ -83,7 +83,7 @@ func DecodeCertFromSignature(signByte []byte) ([]byte, []byte, error) {
return certSignature.Cert, certSignature.Signature, nil
}
// pem结构转成byte类型私钥
// PrivKeyByteFromRaw pem结构转成byte类型私钥
func PrivKeyByteFromRaw(raw []byte, signType int) ([]byte, error) {
block, _ := pem.Decode(raw)
if block == nil {
......
......@@ -20,7 +20,7 @@ func init() {
ety.InitFuncList(types.ListMethod(&Cert{}))
}
// 初始化
// Init 初始化
func Init(name string, sub []byte) {
driverName = name
var cfg ct.Authority
......@@ -31,12 +31,12 @@ func Init(name string, sub []byte) {
drivers.Register(driverName, newCert, types.GetDappFork(driverName, "Enable"))
}
// 获取cert执行器名
// GetName 获取cert执行器名
func GetName() string {
return newCert().GetName()
}
// cert执行器
// Cert cert执行器
type Cert struct {
drivers.DriverBase
}
......@@ -48,12 +48,12 @@ func newCert() drivers.Driver {
return c
}
// 获取cert执行器名
// GetDriverName 获取cert执行器名
func (c *Cert) GetDriverName() string {
return driverName
}
// cert执行器tx证书校验
// CheckTx cert执行器tx证书校验
func (c *Cert) CheckTx(tx *types.Transaction, index int) error {
// 基类检查
err := c.DriverBase.CheckTx(tx, index)
......
......@@ -16,7 +16,7 @@ func calcCertHeightKey(height int64) []byte {
return []byte(fmt.Sprintf("LODB-cert-%d", height))
}
// 启用证书交易执行
// ExecLocal_New 启用证书交易执行
func (c *Cert) ExecLocal_New(payload *ct.CertNew, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if !authority.IsAuthEnable {
clog.Error("Authority is not available. Please check the authority config or authority initialize error logs.")
......@@ -39,7 +39,7 @@ func (c *Cert) ExecLocal_New(payload *ct.CertNew, tx *types.Transaction, receipt
return &set, nil
}
// 更新证书交易执行
// ExecLocal_Update 更新证书交易执行
func (c *Cert) ExecLocal_Update(payload *ct.CertUpdate, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if !authority.IsAuthEnable {
clog.Error("Authority is not available. Please check the authority config or authority initialize error logs.")
......@@ -63,7 +63,7 @@ func (c *Cert) ExecLocal_Update(payload *ct.CertUpdate, tx *types.Transaction, r
return &set, nil
}
// 非证书变更交易执行
// ExecLocal_Normal 非证书变更交易执行
func (c *Cert) ExecLocal_Normal(payload *ct.CertNormal, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if !authority.IsAuthEnable {
clog.Error("Authority is not available. Please check the authority config or authority initialize error logs.")
......
......@@ -5,7 +5,7 @@
package types
var (
// cert执行器名
// CertX cert执行器名
CertX = "cert"
ExecerCert = []byte(CertX)
actionName = map[string]int32{
......
......@@ -7,7 +7,7 @@ package types
import "errors"
var (
// cert校验失败
// ErrValidateCertFailed cert校验失败
ErrValidateCertFailed = errors.New("ErrValidateCertFailed")
ErrGetHistoryCertData = errors.New("ErrGetHistoryCertData")
ErrUnknowAuthSignType = errors.New("ErrUnknowAuthSignType")
......
......@@ -23,7 +23,7 @@ func init() {
types.RegisterDappFork(CertX, "Enable", 0)
}
// cert执行器类型结构
// CertType cert执行器类型结构
type CertType struct {
types.ExecTypeBase
}
......
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