sdk

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSR

type CSR struct {
	CSR []byte `json:"csr,omitempty"`
}

type CSRMetadata

type CSRMetadata struct {
	CommonName         string   `json:"common_name"`
	Organization       []string `json:"organization"`
	OrganizationalUnit []string `json:"organizational_unit"`
	Country            []string `json:"country"`
	Province           []string `json:"province"`
	Locality           []string `json:"locality"`
	StreetAddress      []string `json:"street_address"`
	PostalCode         []string `json:"postal_code"`
	DNSNames           []string `json:"dns_names"`
	IPAddresses        []string `json:"ip_addresses"`
	EmailAddresses     []string `json:"email_addresses"`
}

type CertStatus

type CertStatus int
const (
	Valid CertStatus = iota
	Revoked
	Unknown
)

func (CertStatus) MarshalJSON

func (c CertStatus) MarshalJSON() ([]byte, error)

func (CertStatus) String

func (c CertStatus) String() string

type Certificate

type Certificate struct {
	SerialNumber string    `json:"serial_number,omitempty"`
	Certificate  string    `json:"certificate,omitempty"`
	Key          string    `json:"key,omitempty"`
	Revoked      bool      `json:"revoked,omitempty"`
	ExpiryTime   time.Time `json:"expiry_time,omitempty"`
	EntityID     string    `json:"entity_id,omitempty"`
	DownloadUrl  string    `json:"-"`
}

type CertificateBundle

type CertificateBundle struct {
	CA          []byte `json:"ca"`
	Certificate []byte `json:"certificate"`
	PrivateKey  []byte `json:"private_key"`
}

type CertificatePage

type CertificatePage struct {
	Total        uint64        `json:"total"`
	Offset       uint64        `json:"offset"`
	Limit        uint64        `json:"limit"`
	Certificates []Certificate `json:"certificates,omitempty"`
}

type Config

type Config struct {
	CertsURL string
	HostURL  string

	MsgContentType  ContentType
	TLSVerification bool
	CurlFlag        bool
}

type ContentType

type ContentType string

ContentType represents all possible content types.

const (
	// CTJSON represents JSON content type.
	CTJSON ContentType = "application/json"

	// CTJSONSenML represents JSON SenML content type.
	CTJSONSenML ContentType = "application/senml+json"

	// CTBinary represents binary content type.
	CTBinary ContentType = "application/octet-stream"
)

type OCSPResponse

type OCSPResponse struct {
	Status       CertStatus `json:"status"`
	SerialNumber *big.Int   `json:"serial_number"`
	RevokedAt    *time.Time `json:"revoked_at,omitempty"`
	ProducedAt   *time.Time `json:"produced_at,omitempty"`
	Certificate  []byte     `json:"certificate,omitempty"`
	IssuerHash   string     `json:"issuer_hash,omitempty"`
}

type Options

type Options struct {
	CommonName         string
	Organization       []string `json:"organization"`
	OrganizationalUnit []string `json:"organizational_unit"`
	Country            []string `json:"country"`
	Province           []string `json:"province"`
	Locality           []string `json:"locality"`
	StreetAddress      []string `json:"street_address"`
	PostalCode         []string `json:"postal_code"`
	DnsNames           []string `json:"dns_names"`
}

type PageMetadata

type PageMetadata struct {
	Total              uint64   `json:"total"`
	Offset             uint64   `json:"offset,omitempty"`
	Limit              uint64   `json:"limit"`
	EntityID           string   `json:"entity_id,omitempty"`
	Token              string   `json:"token,omitempty"`
	CommonName         string   `json:"common_name,omitempty"`
	Organization       []string `json:"organization,omitempty"`
	OrganizationalUnit []string `json:"organizational_unit,omitempty"`
	Country            []string `json:"country,omitempty"`
	Province           []string `json:"province,omitempty"`
	Locality           []string `json:"locality,omitempty"`
	StreetAddress      []string `json:"street_address,omitempty"`
	PostalCode         []string `json:"postal_code,omitempty"`
	DNSNames           []string `json:"dns_names,omitempty"`
	IPAddresses        []string `json:"ip_addresses,omitempty"`
	EmailAddresses     []string `json:"email_addresses,omitempty"`
	Status             string   `json:"status,omitempty"`
	TTL                string   `json:"ttl,omitempty"`
}

type SDK

type SDK interface {
	// IssueCert issues a certificate for a thing required for mTLS.
	//
	// example:
	// cert , _ := sdk.IssueCert("entityID", "10h", []string{"ipAddr1", "ipAddr2"}, sdk.Options{CommonName: "commonName"})
	//  fmt.Println(cert)
	IssueCert(entityID, ttl string, ipAddrs []string, opts Options) (Certificate, errors.SDKError)

	// DownloadCert returns a certificate given certificate ID
	//
	// example:
	//  certBundle, _ := sdk.DownloadCert("serialNumber", "download-token")
	//  fmt.Println(certBundle)
	DownloadCert(token, serialNumber string) (CertificateBundle, errors.SDKError)

	// RevokeCert revokes certificate for thing with thingID
	//
	// example:
	//  err := sdk.RevokeCert("serialNumber")
	//  fmt.Println(err) // nil if successful
	RevokeCert(serialNumber string) errors.SDKError

	// RenewCert renews certificate for thing with thingID
	//
	// example:
	//  err := sdk.RenewCert("serialNumber")
	//  fmt.Println(err) // nil if successful
	RenewCert(serialNumber string) errors.SDKError

	// ListCerts lists all certificates for a client
	//
	// example:
	//  page, _ := sdk.ListCerts(PageMetadata{Limit: 10, Offset: 0})
	//  fmt.Println(page)
	ListCerts(pm PageMetadata) (CertificatePage, errors.SDKError)

	// DeleteCert deletes certificates for a given entityID.
	//
	// example:
	//  err := sdk.DeleteCert("entityID")
	//  fmt.Println(err)
	DeleteCert(entityID string) errors.SDKError

	// ViewCert retrieves a certificate record from the database.
	//
	// example:
	//  cert, _ := sdk.ViewCert("serialNumber")
	//  fmt.Println(cert)
	ViewCert(serialNumber string) (Certificate, errors.SDKError)

	// RetrieveCertDownloadToken retrieves a download token for a certificate
	//
	// example:
	//  token, _ := sdk.RetrieveCertDownloadToken("serialNumber")
	//  fmt.Println(token)
	RetrieveCertDownloadToken(serialNumber string) (Token, errors.SDKError)

	// OCSP checks the revocation status of a certificate
	//
	// example:
	//  response, _ := sdk.OCSP("serialNumber", "")
	//  fmt.Println(response)
	OCSP(serialNumber, cert string) (OCSPResponse, errors.SDKError)

	// ViewCA views the signing certificate
	//
	// example:
	//  response, _ := sdk.ViewCA(token)
	//  fmt.Println(response)
	ViewCA(token string) (Certificate, errors.SDKError)

	// DownloadCA downloads the signing certificate
	//
	// example:
	//  response, _ := sdk.DownloadCA(token)
	//  fmt.Println(response)
	DownloadCA(token string) (CertificateBundle, errors.SDKError)

	// GetCAToken get token for viewing and downloading CA
	//
	// example:
	//  response, _ := sdk.GetCAToken()
	//  fmt.Println(response)
	GetCAToken() (Token, errors.SDKError)

	// IssueFromCSR issues certificate from provided CSR
	//
	// example:
	//	certs, err := sdk.IssueFromCSR( "entityID", "ttl", "csrFile")
	//	fmt.Println(err)
	IssueFromCSR(entityID, ttl string, csr string) (Certificate, errors.SDKError)
}

func NewSDK

func NewSDK(conf Config) SDK

type Token

type Token struct {
	Token string `json:"token"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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