ncanode

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: MIT Imports: 8 Imported by: 0

README

ncanode-go

Клиент NCANode для Go

Установка

go get -u github.com/danikarik/ncanode-go

Использование

import "github.com/danikarik/ncanode-go"

client, err := ncanode.NewClient("http://127.0.0.1:14579")
if err != nil {
    log.Fatal(err)
}

resp, err := client.NodeInfo()
if err != nil {
    log.Fatal(err)
}

log.Println(resp.Result)

Авторы

Лицензия

Проект лицензирован под MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidRequestBody is returned if input parameters of client method has
	// not enough or empty values.
	ErrInvalidRequestBody = errors.New("ncanode: invalid request body")

	// ErrFailedConnection is returned if host is not available.
	ErrFailedConnection = errors.New("ncanode: connection failed")
)

Functions

This section is empty.

Types

type Cert

type Cert struct {
	Valid        bool           `json:"valid"`
	NotAfter     Time           `json:"notAfter"`
	NotBefore    Time           `json:"notBefore"`
	Chain        []X509Response `json:"chain"`
	KeyUsage     KeyUsage       `json:"keyUsage"`
	SerialNumber string         `json:"serialNumber"`
	Subject      Subject        `json:"subject"`
	SignAlg      string         `json:"signAlg"`
	Sign         string         `json:"sign"`
	PublicKey    string         `json:"publicKey"`
	Issuer       Subject        `json:"issuer"`
	KeyUser      []KeyUser      `json:"keyUser"`
	OCSP         *Revocation    `json:"ocsp"`
	CRL          *Revocation    `json:"crl"`
}

Cert holds data of certificate.

type Client

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

Client is API client.

func NewClient

func NewClient(addr string, opts ...Option) (*Client, error)

NewClient returns a new Client.

Takes NCANode host address and options.

func (*Client) NodeInfo

func (c *Client) NodeInfo() (*NodeInfoResponse, error)

NodeInfo returns NCANode server stats.

See https://ncanode.kz/docs.php?go=d8324d275a38b9c386071731e33afcaee4db7b50

func (*Client) PKCS12Info

func (c *Client) PKCS12Info(p12, password string, verifyOCSP, verifyCRL bool) (*X509Response, error)

PKCS12Info returns P12 container info.

See https://ncanode.kz/docs.php?go=9797704344e3175efb3260fbc5e58dac6c2fed3d

func (*Client) RawSign

func (c *Client) RawSign(p12, password, raw string, config *TSPConfig) (*RawSignResponse, error)

RawSign signs any input string and saves into cms.

See https://ncanode.kz/docs.php?go=b52dfc5eddafafb5d7c8cccb06c5f0e011a27f3d

func (*Client) RawVerify

func (c *Client) RawVerify(cms string, verifyOCSP, verifyCRL bool) (*RawVerifyResponse, error)

RawVerify validates cms signature.

See https://ncanode.kz/docs.php?go=3f85fac8fa2729687ed307e791ce0fb17d704e26

func (*Client) TSPSign

func (c *Client) TSPSign(raw string, policy Policy, alg HashAlgorithm) (*TSPSignResponse, error)

TSPSign signs any input string using TSP.

See https://ncanode.kz/docs.php?go=366ea24993a9887051c5f647f8dba8fa5e236d58

func (*Client) TSPVerify

func (c *Client) TSPVerify(cms string) (*TSPVerifyResponse, error)

TSPVerify validates tsp signature.

See https://ncanode.kz/docs.php?go=c2e4ebcfdb0ce789aa3f985ad96d1d223c835284

func (*Client) X509Info

func (c *Client) X509Info(cert string, verifyOCSP, verifyCRL bool) (*X509Response, error)

X509Info returns certifacate info.

See https://ncanode.kz/docs.php?go=68c0077b854fcdb23c567751b1329be3a34447c0

func (*Client) XMLSign

func (c *Client) XMLSign(p12, password, xml string, config *TSPConfig) (*XMLSignResponse, error)

XMLSign signs xml.

See https://ncanode.kz/docs.php?go=7025fdf95d235db4bc6985efd3d1574214107cfd

func (*Client) XMLVerify

func (c *Client) XMLVerify(xml string, verifyOCSP, verifyCRL bool) (*XMLVerifyResponse, error)

XMLVerify validates xml signature.

See https://ncanode.kz/docs.php?go=50acb512216c279acfa7eeb6de6dc2592039bd83

type Gender

type Gender string

Gender is an alias of person gender.

const (
	GenderMale   Gender = "MALE"
	GenderFemale Gender = "FEMALE"
)

List of values Gender can take.

type HashAlgorithm

type HashAlgorithm string

HashAlgorithm is an alias of tsp hash algorithm.

const (
	MD5         HashAlgorithm = "MD5"
	SHA1        HashAlgorithm = "SHA1"
	SHA224      HashAlgorithm = "SHA224"
	SHA256      HashAlgorithm = "SHA256"
	SHA384      HashAlgorithm = "SHA384"
	SHA512      HashAlgorithm = "SHA512"
	RIPEMD128   HashAlgorithm = "RIPEMD128"
	RIPEMD160   HashAlgorithm = "RIPEMD160"
	RIPEMD256   HashAlgorithm = "RIPEMD256"
	GOST34311GT HashAlgorithm = "GOST34311GT"
	GOST34311   HashAlgorithm = "GOST34311"
)

List of values HashAlgorithm can take.

type KeyUsage

type KeyUsage string

KeyUsage is an alias of digital key type.

const (
	KeyUsageAuth    KeyUsage = "AUTH"
	KeyUsageSign    KeyUsage = "SIGN"
	KeyUsageUnknown KeyUsage = "UNKNOWN"
)

List of values KeyUsage can take.

type KeyUser

type KeyUser string

KeyUser is an alias of user type.

const (
	KeyUserIndividual       KeyUser = "INDIVIDUAL"
	KeyUserOrganization     KeyUser = "ORGANIZATION"
	KeyUserCEO              KeyUser = "CEO"
	KeyUserCanSign          KeyUser = "CAN_SIGN"
	KeyUserCanSignFinancial KeyUser = "CAN_SIGN_FINANCIAL"
	KeyUserHR               KeyUser = "HR"
	KeyUserEmployee         KeyUser = "EMPLOYEE"
	KeyUserNCAPrivileges    KeyUser = "NCA_PRIVILEGES"
	KeyUserNCAAdmin         KeyUser = "NCA_ADMIN"
	KeyUserNCAManager       KeyUser = "NCA_MANAGER"
	KeyUserNCAOperator      KeyUser = "NCA_OPERATOR"
)

List of values KeyUser can take.

type NodeInfoResponse

type NodeInfoResponse struct {
	Result struct {
		Datetime Time   `json:"dateTime"`
		Timezone string `json:"timezone"`
		Name     string `json:"name"`
		Version  string `json:"version"`
	} `json:"result"`
	// contains filtered or unexported fields
}

NodeInfoResponse describes json response from NodeInfo.

func (NodeInfoResponse) Error

func (r NodeInfoResponse) Error() string

type Option

type Option func(c *Client) error

Option changes client properties.

func WithHTTPClient

func WithHTTPClient(hc *http.Client) Option

WithHTTPClient sets own http client.

func WithTimeout

func WithTimeout(t time.Duration) Option

WithTimeout sets http client timeout by given duration.

type Policy

type Policy string

Policy is an alias of tsp signing policy.

const (
	TSAGostPolicy   Policy = "TSA_GOST_POLICY"
	TSAGostGtPolicy Policy = "TSA_GOSTGT_POLICY"
)

List of values Policy can take.

type RawSignResponse

type RawSignResponse struct {
	Result struct {
		CMS string `json:"cms"`
		TSP string `json:"tsp,omitempty"`
	} `json:"result"`
	// contains filtered or unexported fields
}

RawSignResponse describes json response from RawSign.

func (RawSignResponse) Error

func (r RawSignResponse) Error() string

type RawVerifyResponse

type RawVerifyResponse struct {
	Result struct {
		Valid bool `json:"valid"`
		Cert  Cert `json:"cert"`
	} `json:"result"`
	// contains filtered or unexported fields
}

RawVerifyResponse describes json response from RawVerify.

func (RawVerifyResponse) Error

func (r RawVerifyResponse) Error() string

type Revocation

type Revocation struct {
	Reason    interface{} `json:"revokationReason"`
	Time      Time        `json:"revokationTime"`
	RevokedBy string      `json:"revokedBy,omitempty"`
	Status    Status      `json:"status"`
}

Revocation holds data of revoked certificate.

type Status

type Status string

Status is an alias of revocation status.

const (
	StatusUnknown Status = "UNKNOWN"
	StatusActive  Status = "ACTIVE"
	StatusRevoked Status = "REVOKED"
)

List of values Status can take.

type Subject

type Subject struct {
	LastName     string `json:"lastName,omitempty"`
	Country      string `json:"country,omitempty"`
	CommonName   string `json:"commonName,omitempty"`
	Gender       Gender `json:"gender,omitempty"`
	Surname      string `json:"surname,omitempty"`
	Locality     string `json:"locality,omitempty"`
	DN           string `json:"dn,omitempty"`
	State        string `json:"state,omitempty"`
	BirthDate    string `json:"birthDate,omitempty"`
	IIN          string `json:"iin,omitempty"`
	BIN          string `json:"bin,omitempty"`
	Organization string `json:"organization,omitempty"`
	Email        string `json:"email,omitempty"`
}

Subject holds person or organization data.

type TSPConfig

type TSPConfig struct {
	Enabled       bool
	Policy        Policy
	HashAlgorithm HashAlgorithm
	InCMS         bool
}

TSPConfig specifies TSP signing options. Used if Enabled is set to true.

type TSPSignResponse

type TSPSignResponse struct {
	Result struct {
		TSP string `json:"tsp"`
	} `json:"result"`
	// contains filtered or unexported fields
}

TSPSignResponse describes json response from TSPSign.

func (TSPSignResponse) Error

func (r TSPSignResponse) Error() string

type TSPVerifyResponse

type TSPVerifyResponse struct {
	Result struct {
		TSPHashAlgorithm HashAlgorithm `json:"tspHashAlgorithm"`
		SerialNumber     string        `json:"serialNumber"`
		GenTime          Time          `json:"genTime"`
		Hash             string        `json:"hash"`
		Policy           string        `json:"policy"`
	} `json:"result"`
	// contains filtered or unexported fields
}

TSPVerifyResponse describes json response from TSPVerify.

func (TSPVerifyResponse) Error

func (r TSPVerifyResponse) Error() string

type Time

type Time struct{ time.Time }

Time is a small wrapper of std time. Difference is time layout used by json decoding.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON implements custom marshaling of json encoder.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom unmarshaling of json decoder.

type X509Response

type X509Response struct {
	Result Cert `json:"result"`
	// contains filtered or unexported fields
}

X509Response describes json response from X509Info.

func (X509Response) Error

func (r X509Response) Error() string

type XMLSignResponse

type XMLSignResponse struct {
	Result struct {
		XML string `json:"xml"`
		TSP string `json:"tsp"`
	} `json:"result"`
	// contains filtered or unexported fields
}

XMLSignResponse describes json response from XMLSign.

func (XMLSignResponse) Error

func (r XMLSignResponse) Error() string

type XMLVerifyResponse

type XMLVerifyResponse struct {
	Result struct {
		Valid bool `json:"valid"`
		Cert  Cert `json:"cert"`
	} `json:"result"`
	// contains filtered or unexported fields
}

XMLVerifyResponse describes json response from XMLVerify.

func (XMLVerifyResponse) Error

func (r XMLVerifyResponse) Error() string

Jump to

Keyboard shortcuts

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