client

package module
v0.0.0-...-5b0ec2e Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package client implements a client library for OTS supporting the OTSMeta content format for file upload support

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAttachmentsDisabled signalizes the instance has attachments
	// disabled but the checked secret contains attachments
	ErrAttachmentsDisabled = errors.New("attachments are disabled on this instance")
	// ErrAttachmentsTooLarge signalizes the size of the attached files
	// exceeds the configured maximum size of the given instance
	ErrAttachmentsTooLarge = errors.New("attachment size exceeds allowed size")
	// ErrAttachmentTypeNotAllowed signalizes any file does not match
	// the allowed extensions / mime types
	ErrAttachmentTypeNotAllowed = errors.New("attachment type is not allowed")
)
View Source
var KeyDerivationFunc = openssl.NewPBKDF2Generator(sha512.New, 300000) //nolint:gomnd // that's the definition

KeyDerivationFunc defines the key derivation algorithm used in OTS to derive the key / iv from the password for encryption. You only should change this if you are running an OTS instance with modified parameters.

The corresponding settings are found in `/src/crypto.js` in the OTS source code.

View Source
var Logger *logrus.Entry

Logger can be set to enable logging from the library. By default all log-messages will be discarded.

View Source
var PasswordLength = 20

PasswordLength defines the length of the generated encryption password

View Source
var RequestTimeout = 5 * time.Second

RequestTimeout defines how long the request to the OTS instance for create and fetch may take

View Source
var UserAgent = "ots-client/1.x +https://github.com/Luzifer/ots"

UserAgent defines the user-agent to send when interacting with an OTS instance. When using this library please set this to something the operator of the instance can determine your client from and provide an URL to useful information about your tool.

Functions

func Create

func Create(instanceURL string, secret Secret, expireIn time.Duration) (string, time.Time, error)

Create serializes the secret and creates a new secret on the instance given by its URL.

The given URL should point to the frontend of the instance. Do not include the API paths, they are added automatically. For the expireIn parameter zero value can be used to use server-default.

So for OTS.fyi you'd use `New("https://ots.fyi/")`

func SanityCheck

func SanityCheck(instanceURL string, secret Secret) error

SanityCheck fetches the instance settings and validates the secret against those settings (matching file size, disabled attachments, allowed file types, ...)

Types

type HTTPClientIntf

type HTTPClientIntf interface {
	Do(*http.Request) (*http.Response, error)
}

HTTPClientIntf describes a minimal interface to be fulfilled by the given HTTP client. This can be used for mocking and to pass in authenticated clients

var HTTPClient HTTPClientIntf = http.DefaultClient

HTTPClient defines the client to use for create and fetch requests and can be overwritten to provide authentication

type Secret

type Secret struct {
	Secret      string             `json:"secret"`
	Attachments []SecretAttachment `json:"attachments,omitempty"`
}

Secret represents a secret parsed from / prepared for serialization to the OTS API

func Fetch

func Fetch(secretURL string) (s Secret, err error)

Fetch retrieves a secret by its given URL. The URL given must include the fragment (part after the `#`) with the secret ID and the encryption passphrase.

The object returned will always be an OTSMeta object even in case the secret is a plain secret without attachments.

type SecretAttachment

type SecretAttachment struct {
	Name    string `json:"name"`
	Type    string `json:"type"`
	Data    string `json:"data"`
	Content []byte `json:"-"`
}

SecretAttachment represents a file attached to a Secret. The Data property must be the plain content (binary / text / ...) of the file to attach. The base64 en-/decoding is done transparently. The Name is the name of the file shown to the user (so ideally should be the file-name on the source system). The Type should contain the mime time of the file or an empty string.

Jump to

Keyboard shortcuts

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