api

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HttpPort    = "80"
	HttpsPort   = "443"
	DefaultHost = "cas.codenotary.com"
)

Variables

View Source
var ErrNotFound = fmt.Errorf("artifact is not found")

ErrNotVerified is returned when an artifact is not found on CNLC

View Source
var ErrNotVerified = fmt.Errorf("artifact is not verified")

ErrNotVerified is returned when an artifact is not verified on CNLC

Functions

func AppendPrefix

func AppendPrefix(prefix string, key []byte) []byte

func AppendSignerId

func AppendSignerId(signerId string, k []byte) []byte

func GetSignerIDByApiKey

func GetSignerIDByApiKey(lcApiKey string) string

func NewLcClient

func NewLcClient(lcApiKey, lcLedger, host, port, lcCertPath string, skipTlsVerify, noTls bool, signingPubKey *ecdsa.PublicKey) (*sdk.LcClient, error)

func NewLcClientByContext

func NewLcClientByContext(context store.CurrentContext, lcApiKey string, lcLedger string, signingPubKey *ecdsa.PublicKey) (*sdk.LcClient, error)

Types

type Artifact

type Artifact struct {
	Kind        string
	Name        string
	Hash        string
	Size        uint64
	ContentType string
	IncludedIn  []PackageDetails
	Deps        []PackageDetails
	Metadata
}

Artifact represents the set of all relevant information gathered from a digital asset.

func (Artifact) Copy

func (a Artifact) Copy() Artifact

Copy returns a deep copy of the artifact.

func (Artifact) ToLcArtifact

func (a Artifact) ToLcArtifact() *LcArtifact

type ArtifactResponse

type ArtifactResponse struct {
	// root fields
	Kind        string `json:"kind" yaml:"kind" cas:"Kind"`
	Name        string `json:"name" yaml:"name" cas:"Name"`
	Hash        string `json:"hash" yaml:"hash" cas:"Hash"`
	Size        uint64 `json:"size" yaml:"size" cas:"Size"`
	ContentType string `json:"contentType" yaml:"contentType" cas:"ContentType"`
	URL         string `json:"url" yaml:"url" cas:"URL"`

	// custom metadata
	Metadata Metadata `json:"metadata" yaml:"metadata" cas:"Metadata"`

	// ArtifactResponse specific
	Status string `json:"status,omitempty" yaml:"status,omitempty"`
}

ArtifactResponse holds artifact values returned by the platform.

func (ArtifactResponse) Artifact

func (a ArtifactResponse) Artifact() *Artifact

Artifact returns an new *Artifact from a

func (ArtifactResponse) String

func (a ArtifactResponse) String() string

type Error

type Error struct {
	Description string   `json:"description"`
	Status      int      `json:"status"`
	Message     string   `json:"message"`
	Path        string   `json:"path"`
	Timestamp   string   `json:"timestamp"`
	Error       string   `json:"error"`
	FieldErrors []string `json:"fieldErrors"`
}

Error represents a CodeNotary platform's API returned error.

type LcArtifact

type LcArtifact struct {
	// root fields
	Uid         string    `json:"uid" yaml:"uid" cas:"UID"`
	Kind        string    `json:"kind" yaml:"kind" cas:"Kind"`
	Name        string    `json:"name" yaml:"name" cas:"Name"`
	Hash        string    `json:"hash" yaml:"hash" cas:"Hash"`
	Size        uint64    `json:"size" yaml:"size" cas:"Size"`
	Timestamp   time.Time `json:"timestamp,omitempty" yaml:"timestamp" cas:"Timestamp"`
	ContentType string    `json:"contentType" yaml:"contentType" cas:"ContentType"`

	// custom metadata
	Metadata Metadata `json:"metadata" yaml:"metadata" cas:"Metadata"`

	Signer  string      `json:"signer" yaml:"signer" cas:"SignerID"`
	Revoked *time.Time  `json:"revoked,omitempty" yaml:"revoked" cas:"Apikey revoked"`
	Status  meta.Status `json:"status" yaml:"status" cas:"Status"`
	Ledger  string      `json:"ledger,omitempty" yaml:"ledger"`

	IncludedIn []PackageDetails `json:"included_in,omitempty" yaml:"included_in,omitempty" cas:"Included in"`
	Deps       []PackageDetails `json:"bom,omitempty" yaml:"bom,omitempty" cas:"Dependencies"`
	PublicKey  string
}

func ItemToLcArtifact

func ItemToLcArtifact(item *schema.ItemExt) (*LcArtifact, error)

func LcVerifyEnv

func LcVerifyEnv(hash, lcLedger, signerID string) (a *LcArtifact, err error)

PublicCNLCVerify allow connection and verification on CNLC ledger with a single call using environment variables. LcLedger parameter is used when a cross-ledger key is provided in order to specify the ledger on which future operations will be directed. Empty string is accepted. signerID parameter is used to filter result on a specific signer ID. If empty value is provided is used the current logged signerID value.

func PublicCNLCVerify

func PublicCNLCVerify(hash, lcLedger, signerID, lcHost, lcPort, lcCert string, lcSkipTlsVerify, lcNoTls bool) (a *LcArtifact, err error)

PublicCNLCVerify allow connection and verification on CNLC ledger with a single call. LcLedger parameter is used when a cross-ledger key is provided in order to specify the ledger on which future operations will be directed. Empty string is accepted signerID parameter is used to filter result on a specific signer ID. If empty value is provided is used the current logged signerID value.

func VerifiableItemExtToLcArtifact

func VerifiableItemExtToLcArtifact(item *schema.VerifiableItemExt) (*LcArtifact, error)

func ZItemToLcArtifact

func ZItemToLcArtifact(ie *schema.ZItemExt) (*LcArtifact, error)

func (*LcArtifact) Date

func (lca *LcArtifact) Date() string

Date returns a RFC3339 formatted string of verification time (v.Timestamp), if any, otherwise an empty string.

type LcSignOption

type LcSignOption func(*lcSignOpts) error

SignOption is a functional option for signing operations

func LcSignWithBom

func LcSignWithBom(bom []*schema.VCNDependency) LcSignOption

func LcSignWithStatus

func LcSignWithStatus(status meta.Status) LcSignOption

SignWithStatus returns the functional option for the given status.

type LcUser

type LcUser struct {
	Client     *sdk.LcClient
	PrivateKey *ed25519.PrivateKey
}

User represent a CodeNotary platform user.

func GetOrCreateLcUser

func GetOrCreateLcUser(lcApiKey, lcLedger, host, port, lcCert string, skipTlsVerifySet, skipTlsVerify, noTlsSet, noTls bool, signingPubKey *ecdsa.PublicKey, publicAuth bool) (*LcUser, error)

GetOrCreateLcUser returns a new User instance configured with provided parameters or an error. Before creating a new user it looks for a context one LcLedger parameter is used when a cross-ledger key is provided in order to specify the ledger on which future operations will be directed. Empty string is accepted

func NewLcUserVolatile

func NewLcUserVolatile(lcApiKey, lcLedger string, host string, port string) *LcUser

NewLcUserVolatile returns a new User instance without a backing cfg file.

func (*LcUser) CheckConnectionPublicKey

func (u *LcUser) CheckConnectionPublicKey(enforceSignatureVerify bool) error

CheckConnectionPublicKey the aim of this method is to guarantee that the connection between cas and a CAS server are verified by the first login auto trusted signature. This method fetches an immudb state, checks if the public key provided to the immudb client match server signature and saves locally such key. In addition it checks if a previously trusted (local) key is the same to the current one used by client. This guarantee that the connection is established on a previously trusted server. If enforceSignatureVerify is TRUE it requires an explicit fingerprint confirmation. NOTE: if CAS_SIGNING_PUB_KEY_FILE or CAS_SIGNING_PUB_KEY environment flag or arguments are provided this method is not called.

func (*LcUser) LoadArtifact

func (u *LcUser) LoadArtifact(
	hash, signerID string,
	uid string,
	tx uint64,
	gRPCMetadata map[string][]string,
) (lc *LcArtifact, verified bool, err error)

LoadArtifact fetches and returns an *lcArtifact for the given hash and current u, if any.

func (*LcUser) LoadArtifacts

func (u *LcUser) LoadArtifacts(
	signerID string,
	hashes []string,
	gRPCMetadata map[string][]string,
) (artifacts []*LcArtifact, verified []bool, errs []error, err error)

LoadArtifacts fetches and returns multiple *lcArtifact for the given hashes and current u, if any.

func (LcUser) RequireFeatOrErr

func (u LcUser) RequireFeatOrErr(feat string) error

func (LcUser) Sign

func (u LcUser) Sign(artifact Artifact, options ...LcSignOption) (uint64, error)

Sign is invoked by the User to notarize an artifact using the given functional options, By default, the artifact is notarized using status = meta.StatusTrusted, visibility meta.VisibilityPrivate.

func (LcUser) SignMulti

func (u LcUser) SignMulti(artifacts []*Artifact, options [][]LcSignOption) (uint64, error)

SignMulti ...

type Metadata

type Metadata map[string]interface{}

Metadata holds custom artifact attributes

func (Metadata) Get

func (m Metadata) Get(key string, defaultValue interface{}) interface{}

Get returns the value for the given key, if any, otherwise returns defaultValue

func (*Metadata) Set

func (m *Metadata) Set(key string, value interface{})

Set sets the value for given key

func (*Metadata) SetValues

func (m *Metadata) SetValues(values map[string]interface{})

SetValues sets given values into this Metadata instance

type PackageDetails

type PackageDetails struct {
	Name    string      `json:"name" yaml:"name" cas:"name"`
	Version string      `json:"version,omitempty" yaml:"version,omitempty" cas:"version"`
	Hash    string      `json:"hash" yaml:"hash" cas:"hash"`
	Status  meta.Status `json:"status" yaml:"status" cas:"status"`
	License string      `json:"license,omitempty" yaml:"license"`
}

type SignOption

type SignOption func(*signOpts) error

SignOption is a functional option for signing operations

func SignWithStatus

func SignWithStatus(status meta.Status) SignOption

SignWithStatus returns the functional option for the given status.

type User

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

User represent a CodeNotary platform user.

func (*User) ClearAuth

func (u *User) ClearAuth()

ClearAuth deletes the stored authentication token.

func (User) Config

func (u User) Config() *store.User

Config returns the User configuration object (see store.User), if any. It returns nil if the User is not properly initialized.

func (User) User

func (u User) User() *store.User

Config returns the User configuration object (see store.User), if any. It returns nil if the User is not properly initialized.

func (*User) UserByCfg

func (u *User) UserByCfg(cfg *store.User)

UserByCfg configures current user with a custom values

Jump to

Keyboard shortcuts

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