attachments

package
v0.0.0-...-a8b6a46 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2020 License: BSD-3-Clause, BSD-3-Clause Imports: 46 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAbortOnPartMismatch = errors.New("local part mismatch, aborting upload")

ErrAbortOnPartMismatch is returned when there is a mismatch between a current part and a previous attempt part. If ErrAbortOnPartMismatch is returned, the caller should abort the upload attempt and start from scratch.

View Source
var ErrPartNotFound = errors.New("part does not exist in stash")

Functions

func AssetFromMessage

func AssetFromMessage(ctx context.Context, g *globals.Context, uid gregor1.UID, convID chat1.ConversationID,
	msgID chat1.MessageID, preview bool) (res chat1.Asset, err error)

func DetectMIMEType

func DetectMIMEType(ctx context.Context, src *os.File) (res string, err error)

Types

type AttachmentInfo

type AttachmentInfo struct {
	ObjectKey string                   // s3 destination
	EncKey    signencrypt.SecretboxKey // encryption key
	SignKey   signencrypt.SignKey      // signing key
	VerifyKey signencrypt.VerifyKey    // verification key
	Parts     map[int]string           // map of parts uploaded to S3, key == part number, value == hash of ciphertext
	StartedAt time.Time                // when the upload started
}

type AttachmentStash

type AttachmentStash interface {
	Start(key StashKey, info AttachmentInfo) error
	Lookup(key StashKey) (AttachmentInfo, bool, error)
	RecordPart(key StashKey, partNumber int, hash string) error
	Finish(key StashKey) error
}

type Decrypter

type Decrypter interface {
	// Decrypt takes a ciphertext reader, encryption and verify keys.
	// It returns a plaintext reader.  It uses the constant nonce.
	Decrypt(ciphertext io.Reader, encKey, verifyKey []byte) (plaintext io.Reader)

	// DecryptWithNonce takes a ciphertext reader, nonce, encryption and verify keys.
	// It returns a plaintext reader.
	DecryptWithNonce(ciphertext io.Reader, nonce signencrypt.Nonce, encKey, verifyKey []byte) (plaintext io.Reader)
}

type Dimension

type Dimension struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

func (*Dimension) Empty

func (d *Dimension) Empty() bool

func (*Dimension) Encode

func (d *Dimension) Encode() string

type Encrypter

type Encrypter interface {
	// EncryptedLen returns the number of bytes that the ciphertext of
	// size plaintext bytes will be.
	EncryptedLen(size int) int

	// Encrypt takes a plaintext reader and returns a ciphertext reader.
	// It generates new keys every time it is called and uses a
	// constant nonce.
	Encrypt(plaintext io.Reader) (ciphertext io.Reader, err error)

	// EncryptWithNonce takes a plaintext reader and returns a ciphertext reader.
	// It generates new keys every time it is called and uses
	// the provided nonce.
	EncryptWithNonce(plaintext io.Reader, nonce signencrypt.Nonce) (ciphertext io.Reader, err error)

	// EncryptResume takes a plaintext reader and a set of keys.  It
	// returns a ciphertext reader.  It *does not* generate new keys
	// but uses the parameter keys.  These keys should *only* be used
	// to encrypt the same plaintext as a previous attempt.
	EncryptResume(r io.Reader, nonce signencrypt.Nonce, encKey signencrypt.SecretboxKey, signKey signencrypt.SignKey, verifyKey signencrypt.VerifyKey) (io.Reader, error)

	// EncryptKey returns the ephemeral key that was used during the
	// last invocation of Encrypt.
	EncryptKey() []byte

	// VerifyKey returns the public portion of the signing key used during
	// the last invocation of Encrypt.  It can be used for signature
	// verification.
	VerifyKey() []byte
}

type ErrorWrapper

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

func NewErrorWrapper

func NewErrorWrapper(prefix string, err error) *ErrorWrapper

func (*ErrorWrapper) Details

func (e *ErrorWrapper) Details() string

func (*ErrorWrapper) Error

func (e *ErrorWrapper) Error() string

type FileStash

type FileStash struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewFileStash

func NewFileStash(dir string) *FileStash

func (*FileStash) Finish

func (f *FileStash) Finish(key StashKey) error

func (*FileStash) Lookup

func (f *FileStash) Lookup(key StashKey) (AttachmentInfo, bool, error)

func (*FileStash) RecordPart

func (f *FileStash) RecordPart(key StashKey, partNumber int, hash string) error

func (*FileStash) Start

func (f *FileStash) Start(key StashKey, info AttachmentInfo) error

type PendingPreviews

type PendingPreviews struct {
	globals.Contextified
	utils.DebugLabeler
}

func NewPendingPreviews

func NewPendingPreviews(g *globals.Context) *PendingPreviews

func (*PendingPreviews) Get

func (p *PendingPreviews) Get(ctx context.Context, outboxID chat1.OutboxID) (res Preprocess, err error)

func (*PendingPreviews) Put

func (p *PendingPreviews) Put(ctx context.Context, outboxID chat1.OutboxID, pre Preprocess) (err error)

func (*PendingPreviews) Remove

func (p *PendingPreviews) Remove(ctx context.Context, outboxID chat1.OutboxID)

type Preprocess

type Preprocess struct {
	ContentType        string
	Preview            []byte
	PreviewContentType string
	BaseDim            *Dimension
	BaseDurationMs     int
	PreviewDim         *Dimension
	PreviewDurationMs  int
}

func PreprocessAsset

func PreprocessAsset(ctx context.Context, g *globals.Context, log utils.DebugLabeler, filename string,
	callerPreview *chat1.MakePreviewRes) (p Preprocess, err error)

func (*Preprocess) BaseMetadata

func (p *Preprocess) BaseMetadata() chat1.AssetMetadata

func (*Preprocess) Export

func (p *Preprocess) Export(getLocation func() *chat1.PreviewLocation) (res chat1.MakePreviewRes, err error)

func (*Preprocess) PreviewMetadata

func (p *Preprocess) PreviewMetadata() chat1.AssetMetadata

type PreviewRes

type PreviewRes struct {
	Source            []byte
	ContentType       string
	BaseWidth         int
	BaseHeight        int
	BaseDurationMs    int
	PreviewWidth      int
	PreviewHeight     int
	PreviewDurationMs int
}

func Preview

func Preview(ctx context.Context, g *globals.Context, log utils.DebugLabeler, src io.Reader, contentType,
	basename string) (*PreviewRes, error)

Preview creates preview assets from src. It returns an in-memory BufferSource and the content type of the preview asset.

type PutS3Result

type PutS3Result struct {
	Region   string
	Endpoint string
	Bucket   string
	Path     string
	Size     int64
}

PutS3Result is the success result of calling PutS3.

type ReadResetter

type ReadResetter interface {
	io.Reader
	Reset() error
}

type S3Signer

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

func NewS3Signer

func NewS3Signer(ri func() chat1.RemoteInterface) *S3Signer

func (*S3Signer) Sign

func (s *S3Signer) Sign(payload []byte) ([]byte, error)

Sign implements github.com/keybase/go/chat/s3.Signer interface.

type S3Store

type S3Store struct {
	utils.DebugLabeler
	// contains filtered or unexported fields
}

func NewS3Store

func NewS3Store(logger logger.Logger, env *libkb.Env, runtimeDir string) *S3Store

NewS3Store creates a standard Store that uses a real S3 connection.

func NewStoreTesting

func NewStoreTesting(log logger.Logger, kt func(enc, sig []byte)) *S3Store

NewStoreTesting creates an Store suitable for testing purposes. It is not exposed outside this package. It uses an in-memory s3 interface, reports enc/sig keys, and allows limiting the number of blocks uploaded.

func (*S3Store) DecryptAsset

func (a *S3Store) DecryptAsset(ctx context.Context, w io.Writer, body io.Reader, asset chat1.Asset,
	progress types.ProgressReporter) error

func (*S3Store) DeleteAsset

func (a *S3Store) DeleteAsset(ctx context.Context, params chat1.S3Params, signer s3.Signer, asset chat1.Asset) error

func (*S3Store) DeleteAssets

func (a *S3Store) DeleteAssets(ctx context.Context, params chat1.S3Params, signer s3.Signer, assets []chat1.Asset) error

func (*S3Store) DownloadAsset

func (a *S3Store) DownloadAsset(ctx context.Context, params chat1.S3Params, asset chat1.Asset,
	w io.Writer, signer s3.Signer, progress types.ProgressReporter) error

DownloadAsset gets an object from S3 as described in asset.

func (*S3Store) GetAssetReader

func (a *S3Store) GetAssetReader(ctx context.Context, params chat1.S3Params, asset chat1.Asset,
	signer s3.Signer) (io.ReadCloser, error)

func (*S3Store) PutS3

func (a *S3Store) PutS3(ctx context.Context, r io.Reader, size int64, task *UploadTask, previous *AttachmentInfo) (res *PutS3Result, err error)

PutS3 uploads the data in Reader r to S3. It chooses whether to use putSingle or putMultiPipeline based on the size of the object.

func (*S3Store) StreamAsset

func (a *S3Store) StreamAsset(ctx context.Context, params chat1.S3Params, asset chat1.Asset,
	signer s3.Signer) (io.ReadSeeker, error)

func (*S3Store) UploadAsset

func (a *S3Store) UploadAsset(ctx context.Context, task *UploadTask, encryptedOut io.Writer) (res chat1.Asset, err error)

type Sender

type Sender struct {
	globals.Contextified
	utils.DebugLabeler
}

func NewSender

func NewSender(gc *globals.Context) *Sender

func (*Sender) MakePreview

func (s *Sender) MakePreview(ctx context.Context, filename string, outboxID chat1.OutboxID) (res chat1.MakePreviewRes, err error)

func (*Sender) PostFileAttachment

func (s *Sender) PostFileAttachment(ctx context.Context, sender types.Sender, uid gregor1.UID,
	convID chat1.ConversationID, tlfName string, vis keybase1.TLFVisibility, inOutboxID *chat1.OutboxID,
	filename, title string, md []byte, clientPrev chat1.MessageID, ephemeralLifetime *gregor1.DurationSec,
	callerPreview *chat1.MakePreviewRes) (outboxID chat1.OutboxID, msgID *chat1.MessageID, err error)

func (*Sender) PostFileAttachmentMessage

func (s *Sender) PostFileAttachmentMessage(ctx context.Context, sender types.Sender,
	convID chat1.ConversationID, tlfName string, vis keybase1.TLFVisibility, filename, title string,
	md []byte, clientPrev chat1.MessageID, ephemeralLifetime *gregor1.DurationSec) (outboxID chat1.OutboxID, msgID *chat1.MessageID, err error)

type SignDecrypter

type SignDecrypter struct{}

func NewSignDecrypter

func NewSignDecrypter() *SignDecrypter

func (*SignDecrypter) Decrypt

func (s *SignDecrypter) Decrypt(r io.Reader, encKey, verifyKey []byte) io.Reader

func (*SignDecrypter) DecryptWithNonce

func (s *SignDecrypter) DecryptWithNonce(r io.Reader, nonce signencrypt.Nonce, encKey, verifyKey []byte) (plaintext io.Reader)

type SignEncrypter

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

func NewSignEncrypter

func NewSignEncrypter() *SignEncrypter

func (*SignEncrypter) Encrypt

func (s *SignEncrypter) Encrypt(r io.Reader) (io.Reader, error)

func (*SignEncrypter) EncryptKey

func (s *SignEncrypter) EncryptKey() []byte

func (*SignEncrypter) EncryptResume

func (s *SignEncrypter) EncryptResume(r io.Reader, nonce signencrypt.Nonce, encKey signencrypt.SecretboxKey, signKey signencrypt.SignKey, verifyKey signencrypt.VerifyKey) (io.Reader, error)

EncryptResume is used to create a SignEncrypter to resume an interrupted attachment upload. It is *very* important that the keys passed in are not used to encrypt different plaintext than their original usage.

func (*SignEncrypter) EncryptWithNonce

func (s *SignEncrypter) EncryptWithNonce(r io.Reader, nonce signencrypt.Nonce) (io.Reader, error)

func (*SignEncrypter) EncryptedLen

func (s *SignEncrypter) EncryptedLen(size int64) int64

func (*SignEncrypter) SignKey

func (s *SignEncrypter) SignKey() []byte

func (*SignEncrypter) VerifyKey

func (s *SignEncrypter) VerifyKey() []byte

type StashKey

type StashKey struct {
	OutboxID chat1.OutboxID
	Preview  bool
}

func NewStashKey

func NewStashKey(outboxID chat1.OutboxID, preview bool) StashKey

func (StashKey) String

func (s StashKey) String() string

type Store

type Store interface {
	UploadAsset(ctx context.Context, task *UploadTask, encryptedOut io.Writer) (chat1.Asset, error)
	DownloadAsset(ctx context.Context, params chat1.S3Params, asset chat1.Asset, w io.Writer,
		signer s3.Signer, progress types.ProgressReporter) error
	GetAssetReader(ctx context.Context, params chat1.S3Params, asset chat1.Asset,
		signer s3.Signer) (io.ReadCloser, error)
	StreamAsset(ctx context.Context, params chat1.S3Params, asset chat1.Asset, signer s3.Signer) (io.ReadSeeker, error)
	DecryptAsset(ctx context.Context, w io.Writer, body io.Reader, asset chat1.Asset,
		progress types.ProgressReporter) error
	DeleteAsset(ctx context.Context, params chat1.S3Params, signer s3.Signer, asset chat1.Asset) error
	DeleteAssets(ctx context.Context, params chat1.S3Params, signer s3.Signer, assets []chat1.Asset) error
}

type UploadTask

type UploadTask struct {
	S3Params  chat1.S3Params
	Filename  string
	FileSize  int64
	Plaintext ReadResetter

	S3Signer       s3.Signer
	ConversationID chat1.ConversationID
	UserID         gregor1.UID
	OutboxID       chat1.OutboxID
	Preview        bool
	Progress       types.ProgressReporter
	// contains filtered or unexported fields
}

func (*UploadTask) Nonce

func (u *UploadTask) Nonce() signencrypt.Nonce

type Uploader

type Uploader struct {
	globals.Contextified
	utils.DebugLabeler
	sync.Mutex
	// contains filtered or unexported fields
}

func NewUploader

func NewUploader(g *globals.Context, store Store, s3signer s3.Signer, ri func() chat1.RemoteInterface) *Uploader

func (*Uploader) Cancel

func (u *Uploader) Cancel(ctx context.Context, outboxID chat1.OutboxID) (err error)

func (*Uploader) Complete

func (u *Uploader) Complete(ctx context.Context, outboxID chat1.OutboxID)

func (*Uploader) Register

func (u *Uploader) Register(ctx context.Context, uid gregor1.UID, convID chat1.ConversationID,
	outboxID chat1.OutboxID, title, filename string, metadata []byte, callerPreview *chat1.MakePreviewRes) (res types.AttachmentUploaderResultCb, err error)

func (*Uploader) Retry

func (u *Uploader) Retry(ctx context.Context, outboxID chat1.OutboxID) (res types.AttachmentUploaderResultCb, err error)

func (*Uploader) SetPreviewTempDir

func (u *Uploader) SetPreviewTempDir(dir string)

func (*Uploader) Status

Jump to

Keyboard shortcuts

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