Casdk

package module
v0.0.0-...-728054b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2018 License: MIT Imports: 27 Imported by: 0

README

Casdk

Go Report Card

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAlgorithmFamily = errors.New("invalid algorithm family")
	ErrInvalidAlgorithm       = errors.New("invalid algorithm for ECDSA")
	ErrInvalidHash            = errors.New("invalid hash algorithm")
	ErrInvalidKeyType         = errors.New("invalid key type is provided")
	ErrEnrollmentIdMissing    = errors.New("enrollment id is empty")
	ErrAffiliationMissing     = errors.New("affiliation is missing")
	ErrTypeMissing            = errors.New("type is missing")
	ErrCertificateEmpty       = errors.New("certificate cannot be nil")
	ErrIdentityNameMissing    = errors.New("identity must have  name")
)

Functions

func InitCASDK

func InitCASDK(configPth string, configFile string) error

func IsPathExists

func IsPathExists(filepath string) (bool, error)

func Register

func Register(ca *FabricCAClient, identity *Identity, req *CARegistrationRequest) error

func Revoke

func Revoke(ca *FabricCAClient, identity *Identity, req *CARevocationRequest) error

func SaveCrl

func SaveCrl(ca *FabricCAClient, request *CARevocationRequest, result *CARevokeResult) error

Save crl

Types

type BasicKeyRequest

type BasicKeyRequest struct {
	Algo string `json:"algo" yaml:"algo"`
	Size int    `json:"size" yaml:"size"`
}

BasicKeyRequest encapsulates size and algorithm for the key to be generated

type CAConfig

type CAConfig struct {
	CryptoConfig      `yaml:"crypto"`
	Url               string `yaml:"url"`
	SkipTLSValidation bool   `yaml:"skipTLSValidation"`
	MspId             string `yaml:"mspId"`
	FilePath          string `yaml:"filepath"`
}

func NewCAConfig

func NewCAConfig(path string) (*CAConfig, error)

type CAGetCertResponse

type CAGetCertResponse struct {
	// RootCertificates is list of pem encoded certificates
	RootCertificates []*x509.Certificate
	// IntermediateCertificates is list of pem encoded intermediate certificates
	IntermediateCertificates []*pem.Block
	// CAName is the name of the CA server that returns this certificates
	CAName string
	// Version is the version of server that returns this certificates
	Version string
}

CAGetCertsResponse holds response from `GetCaCertificateChain`

type CAGetIdentityResponse

type CAGetIdentityResponse struct {
	CaIdentityResponse
	CAName string `json:"caname"`
}

func GetIndentity

func GetIndentity(ca *FabricCAClient, identity *Identity, id string, caName string) (CAGetIdentityResponse, error)

type CAListAllIdentitesResponse

type CAListAllIdentitesResponse struct {
	CAName     string               `json:"caname"`
	Identities []CaIdentityResponse `json:"identities,omitempty"`
}

func GetIndentities

func GetIndentities(ca *FabricCAClient, identity *Identity) (CAListAllIdentitesResponse, error)

type CARegistrationRequest

type CARegistrationRequest struct {
	// EnrolmentId is unique name that identifies identity
	EnrolmentId string `json:"id"`
	// Type defines type of this identity (user,client, auditor etc...)
	Type string `json:"type"`
	// Secret is password that will be used for enrollment. If not provided random password will be generated
	Secert string `json:"secert,omitempty" mask:"password" help:"The enrollment secret for the identity being registered"`
	// MaxEnrollments define maximum number of times that identity can enroll. If not provided or is 0 there is no limit
	MaxEnrollments int `json:"max_enrollments,omitempty"`
	// Affiliation associates identity with particular organisation.
	// for example org1.department1 makes this identity part of organisation `org1` and department `department1`
	// Hierarchical structure can be created using .(dot). For example org1.dep1 will create dep1 as part of org1
	Affiliation string `json:"affiliation" help:"The identity's affiliation"`
	// Attrs are attributes associated with this identity
	Attrs []CaRegisterAttribute `json:"attrs,omitempty"`
	// CAName is the name of the CA that should be used. FabricCa support more than one CA server on same endpoint and
	// this names are used to distinguish between them. If empty default CA instance will be used.
	CAName string `json:"caname,omitempty" skip:"true"`
}

RegistrationRequest holds all data needed for new registration of new user in Certificate Authority

type CARevocationRequest

type CARevocationRequest struct {
	// EnrollmentId of the identity whose certificates should be revoked
	// If this field is omitted, then Serial and AKI must be specified.
	EnrollmentId string `json:"id,omitempty"`
	// Serial number of the certificate to be revoked
	// If this is omitted, then EnrollmentId must be specified
	Serial string `json:"serial,omitempty"`
	// AKI (Authority Key Identifier) of the certificate to be revoked
	AKI string `json:"aki,omitempty"`
	// Reason is the reason for revocation.  See https://godoc.org/golang.org/x/crypto/ocsp for
	// valid values.  The default value is 0 (ocsp.Unspecified).
	Reason string `json:"reason,omitempty"`
	// CAName is the name of the CA that should be used. FabricCa support more than one CA server on same endpoint and
	// this names are used to distinguish between them. If empty default CA instance will be used.
	CAName string `json:"caname,omitempty"`
	// GenCRL specifies whether to generate a CRL. CRL will be returned only when AKI and Serial are provided.
	GenCRL bool `json:"gencrl,omitempty"`
}

type CARevokeResult

type CARevokeResult struct {
	// RevokedCertificates is list of revoked certificates
	RevokedCertificates []CaRevokeResultCertificate `json:"RevokedCerts"`
	// CRL is the certificate revocation list from the operation.
	CRL string `json:"CRL"`
}

type CSRInfo

type CSRInfo struct {
	CN           string           `json:"CN"`
	Names        []csr.Name       `json:"names,omitempty"`
	Hosts        []string         `json:"hosts,omitempty"`
	KeyRequest   *BasicKeyRequest `json:"key,omitempty"`
	CA           *csr.CAConfig    `json:"ca,omitempty"`
	SerialNumber string           `json:"serial_number,omitempty"`
}

type CaEnrollAttribute

type CaEnrollAttribute struct {
	// Name is the name of the attribute
	Name string `json:"name"`
	// Optional define behaviour when required attribute is not available to user. If `true` then request will continue,
	// but attribute will not be included in ECert. If `false` and attribute is missing, request will fail.
	// If false and attribute is available, request will continue and attribute will be added in ECert
	Optional bool `json:"optional,omitempty"`
}

type CaEnrollmentRequest

type CaEnrollmentRequest struct {
	// EnrollmentId is the unique entity identifies
	EnrollmentId string `json:"name" skip:"true"`
	// Secret is the password for this identity
	Secret string `json:"secret,omitempty" skip:"true" mask:"password"`
	// Profile define which CA profile to be used for signing. When this profile is empty default profile is used.
	// This is the common situation when issuing and ECert.
	// If request is fo generating TLS certificates then profile must be `tls`
	// If operation is related to parent CA server then profile must be `ca`
	// In FabricCA custom profiles can be created. In this situation use custom profile name.
	Profile string `json:"profile,omitempty"`
	//Label is used for hardware secure modules.
	Label string `json:"label,omitempty"`
	// CAName is the name of the CA that should be used. FabricCa support more than one CA server on same endpoint and
	// this names are used to distinguish between them. If empty default CA instance will be used.
	CAName string `json:"caname,omitempty" skip:"true"`
	// Host is the list of valid host names for this certificate. If empty default hosts will be used
	Hosts []string `json:"hosts"`
	// Attrs are the attributes that must be included in ECert. This is subset of the attributes used in registration.
	Attrs []CaEnrollAttribute `json:"attr_reqs,omitempty"`
	// CSR is Certificate Signing Request info
	CSR *CSRInfo `json:"csr,omitempty" help:"Certificate Signing Request info"`
}

CaEnrollmentRequest holds data needed for getting ECert (enrollment) from CA server

type CaIdentityResponse

type CaIdentityResponse struct {
	ID             string                `json:"id"`
	Type           string                `json:"type"`
	Affiliation    string                `json:"affiliation"`
	Attributes     []CaRegisterAttribute `json:"attrs" mapstructure:"attrs"`
	MaxEnrollments int                   `json:"max_enrollments" mapstructure:"max_enrollments"`
}

type CaRegisterAttribute

type CaRegisterAttribute struct {
	// Name is the name of the attribute.
	Name string `json:"name"`
	// Value is the value of the attribute. Can be empty string
	Value string `json:"value"`
	// ECert define how this attribute will be included in ECert. If this value is true this attribute will be
	// added to ECert automatically on Enrollment if no attributes are requested on Enrollment request.
	ECert bool `json:"ecert,omitempty"`
}

CaRegisterAttribute holds user attribute used for registration for example user may have attr `accountType` with value `premium` this attributes can be accessed in chainCode and build business logic on top of them

type CaRevokeResultCertificate

type CaRevokeResultCertificate struct {
	// Serial is revoked certificate serial number
	Serial string `json:"Serial"`
	// AKI is revoked certificate AKI
	AKI string `json:"AKI"`
}

CaRevokeResultCertificate identify revoked certificate

type CryptoConfig

type CryptoConfig struct {
	Family    string `yaml:"family"`
	Algorithm string `yaml:"algorithm"`
	Hash      string `yaml:"hash"`
}

type CryptoSuite

type CryptoSuite interface {
	// GenerateKey returns PrivateKey.
	GenerateKey() (interface{}, error)
	// CreateCertificateRequest will create CSR request. It takes enrolmentId and Private key
	CreateCertificateRequest(enrollmentId string, key interface{}, hosts []string) ([]byte, error)
	// Sign signs message. It takes message to sign and Private key
	Sign(msg []byte, k interface{}) ([]byte, error)
	// Hash computes Hash value of provided data. Hash function will be different in different crypto implementations.
	Hash(data []byte) []byte
}

func NewECCryptoSuiteFromConfig

func NewECCryptoSuiteFromConfig(config CryptoConfig) (CryptoSuite, error)

type ECCryptSuite

type ECCryptSuite struct {
	// contains filtered or unexported fields
}

func (*ECCryptSuite) CreateCertificateRequest

func (c *ECCryptSuite) CreateCertificateRequest(enrollmentId string, key interface{}, hosts []string) ([]byte, error)

func (*ECCryptSuite) GenerateKey

func (c *ECCryptSuite) GenerateKey() (interface{}, error)

func (*ECCryptSuite) Hash

func (c *ECCryptSuite) Hash(data []byte) []byte

func (*ECCryptSuite) Sign

func (c *ECCryptSuite) Sign(msg []byte, k interface{}) ([]byte, error)

type FabricCAClient

type FabricCAClient struct {
	// Uri is access point for fabric-ca server. Port number and scheme must be provided.
	// for example http://127.0.0.1:7054
	Url string
	// SkipTLSVerification define how connection must handle invalid TLC certificates.
	// if true, all verifications are skipped. This value is overwritten by Transport property, if provided
	SkipTLSVerification bool
	// Crypto is CryptSuite implementation used to sign request for fabric-ca server
	Crypto CryptoSuite
	// Transport define transport rules for communication with fabric-ca server. If nil, default Go setting will be used
	// It is responsibility of the user to provide proper TLS/certificate setting in TLS communication.
	Transport *http.Transport
	// MspId value will be added to Identity in Enrollment and ReEnrollment invocations.
	// This value is not used anywhere in CA implementation, but is need in every call to Fabric and is added here
	// for convenience, because (in general case) FabricCA is serving one MSP
	// User can overwrite this value at any time.
	MspId string
	//
	FilePath string
	//
	ServerInfo ServerInfo
}
var CA *FabricCAClient

func NewCAClient

func NewCAClient(path string, transport *http.Transport) (*FabricCAClient, error)

func NewCaClientFromConfig

func NewCaClientFromConfig(config CAConfig, transport *http.Transport) (*FabricCAClient, error)

func (*FabricCAClient) Enroll

func (f *FabricCAClient) Enroll(request CaEnrollmentRequest) (*Identity, []byte, error)

Enroll execute enrollment request for registered user in FabricCA server. On success new Identity with ECert and generated csr are returned.

func (*FabricCAClient) GetCaCertificateChain

func (f *FabricCAClient) GetCaCertificateChain(caName string) (*CAGetCertResponse, error)

GetCaCertificateChain gets root and intermediate certificates used by FabricCA server. This certificates must be presented to Fabric entities (peers, orderers) as MSP so they can verify that request are from valid entities. caName is the name of the CA that should be used. FabricCa support more than one CA server on same endpoint and this names are used to distinguish between them. If empty default CA instance will be used.

func (*FabricCAClient) GetIdentities

func (f *FabricCAClient) GetIdentities(identity *Identity, caName string) (*CAListAllIdentitesResponse, error)

ListAllIdentities get list of all identities from FabricCa server

func (*FabricCAClient) GetIndentity

func (f *FabricCAClient) GetIndentity(identity *Identity, id string, caName string) (*CAGetIdentityResponse, error)

func (*FabricCAClient) Register

func (f *FabricCAClient) Register(identity *Identity, req *CARegistrationRequest) (string, error)

Register registers new user in fabric-ca server. In registration request attributes, affiliation and max enrolments must be set. It is responsibility of the SDK user to ensure passwords are with big entropy. Identity parameter is certificate for user that makes registration and this user MUST have the role for registering new users.

func (*FabricCAClient) Revoke

func (f *FabricCAClient) Revoke(identity *Identity, request *CARevocationRequest) (*CARevokeResult, error)

Revoke revokes ECert in fabric-ca server. Note that this request will revoke certificate ONLY in FabricCa server. Peers (for now) do not know about this certificate revocation. It is responsibility of the SDK user to update peers and set this certificate in every peer revocation list.

type Identity

type Identity struct {
	Certificate *x509.Certificate
	PrivateKey  interface{}
	MspId       string
}
var ID *Identity

func Enroll

func Enroll(ca *FabricCAClient, req CaEnrollmentRequest) (*Identity, []byte, error)

func (*Identity) SaveCert

func (i *Identity) SaveCert(ca *FabricCAClient, enreq *CaEnrollmentRequest, cainfo *CAGetCertResponse) error

func (*Identity) SaveTLScert

func (i *Identity) SaveTLScert(ca *FabricCAClient, cainfo *CAGetCertResponse) error

type ServerInfo

type ServerInfo struct {
	CAName string
	CACert *x509.Certificate
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL