internal

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: AGPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BytesPerLine        = 24
	PdfTextFont         = "Text"
	PdfMonoFont         = "Mono"
	PdfDataLineFontSize = 11
)
View Source
const (
	HeaderFieldVersion              = "PaperCrypt Version"
	HeaderFieldSerial               = "Content Serial"
	HeaderFieldPurpose              = "Purpose"
	HeaderFieldComment              = "Comment"
	HeaderFieldDate                 = "Date"
	HeaderFieldDataFormat           = "Data Format"
	HeaderFieldContentLength        = "Content Length"
	HeaderFieldCRC24                = "Content CRC-24"
	HeaderFieldCRC32                = "Content CRC-32"
	HeaderFieldSHA256               = "Content SHA-256"
	HeaderFieldHeaderCRC32          = "Header CRC-32"
	PDFHeaderSheetID                = "Sheet ID"
	PDFHeading                      = "PaperCrypt Recovery Sheet"
	PDFSectionDescriptionHeading    = "What is this?"
	PDFSectionDescriptionContent    = "" /* 235-byte string literal not displayed */
	PDFSectionRepresentationHeading = "Binary Data Representation"
	PDFSectionRepresentationContent = "" /* 556-byte string literal not displayed */
	PDFSectionRecoveryHeading       = "Recovering the data"
	PDFSectionRecoveryContent       = "" /* 251-byte string literal not displayed */
	PDFSectionRecoveryContentNo2D   = "" /* 230-byte string literal not displayed */
)
View Source
const (
	CRC24Polynomial = uint32(0x864CFB) // CRC-24 polynomial
	CRC24Initial    = uint32(0xB704CE) // Initial value
	CRC24TableSize  = uint32(256)      // Table size for faster computation
)
View Source
const (
	TimeStampFormatLong      = "Mon, 02 Jan 2006 15:04:05.000000000 -0700"
	TimeStampFormatLongTZ    = "Mon, 02 Jan 2006 15:04:05.000000000 MST"
	TimeStampFormatShort     = "2006-01-02 15:04:05"
	TimeStampFormatDate      = "2006-01-02"
	TimeStampFormatPDFHeader = "2006-01-02 15:04 -0700"
)
View Source
const (
	BytesPerLineV1 = 22 // As is done in paperkey (https://www.jabberwocky.com/software/paperkey/)
)

Variables

View Source
var (
	PdfTextFontRegularBytes []byte
	PdfTextFontBoldBytes    []byte
	PdfTextFontItalicBytes  []byte
)
View Source
var (
	PdfMonoFontRegularBytes []byte
	PdfMonoFontBoldBytes    []byte
	PdfMonoFontItalicBytes  []byte
)
View Source
var (
	// URL is used to style URLs.
	URL = lipgloss.NewStyle().Foreground(lipgloss.Color("3")).Render

	// Warning is used to style warnings for the user.
	Warning = lipgloss.NewStyle().Foreground(lipgloss.Color("11")).Bold(true).Render

	Bold = lipgloss.NewStyle().Bold(true).Render
)
View Source
var VersionInfo goversion.Info

Functions

func BytesFromBase64

func BytesFromBase64(data string) ([]byte, error)

func CloseFileIfNotStd added in v1.1.1

func CloseFileIfNotStd(file *os.File) error

func Crc24Checksum

func Crc24Checksum(data []byte) uint32

func DeserializeBinary

func DeserializeBinary(data *[]byte) ([]byte, error)

func GenerateFromSeed added in v1.4.0

func GenerateFromSeed(seed int64, amount int, wordList *[]string) ([]string, error)

func GeneratePassphraseSheetPDF

func GeneratePassphraseSheetPDF(seed int64, words []string) ([]byte, error)

func GenerateSerial

func GenerateSerial(length uint8) (string, error)

GenerateSerial generates a random serial number of length `length`.

func GetFileHandleCarefully

func GetFileHandleCarefully(path string, override bool) (*os.File, error)

GetFileHandleCarefully returns a file handle for the given path. will warn if the file already exists, and error if override is false. if path is empty, returns os.Stdout.

func NormalizeLineEndings added in v1.4.0

func NormalizeLineEndings(data []byte) []byte

func ParseHexUint32

func ParseHexUint32(hex string) (uint32, error)

func PrintInputAndGetReader added in v1.0.1

func PrintInputAndGetReader(inFileName string) (*os.File, error)

PrintInputAndGetReader prints the input source and returns the reader. if path is empty, returns os.Stdin. must be closed by the caller.

func PrintInputAndRead added in v1.0.1

func PrintInputAndRead(inFileName string) ([]byte, error)

PrintInputAndRead prints the input source and returns the contents of the file. if path is empty, returns os.Stdin.

func PrintWrittenSize added in v1.0.1

func PrintWrittenSize(size int, file *os.File)

func ReadTtyLine

func ReadTtyLine() ([]byte, error)

func SensitivePrompt added in v1.1.1

func SensitivePrompt() ([]byte, error)

SensitivePrompt reads a password from the tty (if available) or stdin (if not).

func SerializeBinary

func SerializeBinary(data *[]byte, bytesPerLine int) string

SerializeBinary returns the encrypted binary data, formatted for restoration lines will hold 22 bytes of data, prefaces by the line number, followed by the CRC-24 of the line, bytes are printed as two base16 (hex) digits, separated by a space. Example:

1: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 <CRC-24 of this line>
2: ... <CRC-24 of this line>

10: ... <CRC-24 of this line> ... n-1: ... <CRC-24 of this line> n: <CRC-24 of the block>

See [example.pdf](example.pdf) for an example.

func SerializeBinaryV1 added in v1.4.0

func SerializeBinaryV1(data *[]byte) string

SerializeBinaryV1 serializes binary data using SerializeBinary.

func SerializeBinaryV2 added in v1.4.0

func SerializeBinaryV2(data *[]byte) string

SerializeBinaryV2 serializes binary data using SerializeBinary.

func SliceHasString

func SliceHasString(slice []string, str string) bool

func SplitTextHeaderAndBody added in v1.4.0

func SplitTextHeaderAndBody(data []byte) ([]byte, []byte, error)

func SprintBinarySize

func SprintBinarySize(size int) string

func SprintBinarySize64

func SprintBinarySize64(size int64) string

func TextToHeaderMap added in v1.4.0

func TextToHeaderMap(text []byte) (map[string]string, error)

func ValidateCRC24

func ValidateCRC24(data []byte, checksum uint32) bool

func ValidateCRC32

func ValidateCRC32(data []byte, checksum uint32) bool

Types

type LineData

type LineData struct {
	LineNumber uint32
	Data       []byte
	CRC24      uint32
}

type PaperCrypt

type PaperCrypt struct {
	// Version is the version of papercrypt used to generate the document.
	Version string `json:"v"`

	// DataFormat determines whether the data is raw (although still gzipped), or follows the PGP message format (gzipped).
	DataFormat PaperCryptDataFormat `json:"f"`

	// SerialNumber is the serial number of document, used to identify it. It is generated randomly if not provided.
	SerialNumber string `json:"sn"`

	// Purpose is the purpose of document
	Purpose string `json:"p"`

	// Comment is the comment on document
	Comment string `json:"cm"`

	// CreatedAt is the creation timestamp
	CreatedAt time.Time `json:"ct"`

	// DataCRC24 is the CRC-24 checksum of the encrypted data
	DataCRC24 uint32 `json:"d_c24"`

	// DataCRC32 is the CRC-32 checksum of the encrypted data
	DataCRC32 uint32 `json:"d_c32"`

	// DataSHA256 is the SHA-256 checksum of the encrypted data
	DataSHA256 [32]byte `json:"d_s256"`

	// Data is the contents of the document
	// it can be either of two formats:
	//   a) ASCII armored OpenPGP data, if DataFormat is PGP
	//      the contained message is gzipped before encryption
	//   b) Raw data of any kind, if DataFormat is Raw
	// either way, data is always gzipped after processing
	Data []byte `json:"d"`
}

func DeserializeV1Text added in v1.4.0

func DeserializeV1Text(data []byte, ignoreVersionMismatch bool, ignoreChecksumMismatch bool) (*PaperCrypt, error)

func DeserializeV2Text added in v1.4.0

func DeserializeV2Text(data []byte, ignoreVersionMismatch bool, ignoreChecksumMismatch bool) (*PaperCrypt, error)

func NewPaperCrypt

func NewPaperCrypt(version string, data []byte, serialNumber string, purpose string, comment string, createdAt time.Time, format PaperCryptDataFormat) *PaperCrypt

NewPaperCrypt creates a new paper crypt.

func (*PaperCrypt) Decode added in v1.4.0

func (p *PaperCrypt) Decode(passphrase []byte) ([]byte, error)

func (*PaperCrypt) GetBinarySerialized

func (p *PaperCrypt) GetBinarySerialized() (string, error)

func (*PaperCrypt) GetDataLength added in v1.4.0

func (p *PaperCrypt) GetDataLength() int

func (*PaperCrypt) GetPDF

func (p *PaperCrypt) GetPDF(no2D bool, lowerCaseEncoding bool) ([]byte, error)

GetPDF returns the binary representation of the paper crypt The PDF will be generated to include some basic information about papercrypt, some metadata, optionally a 2D-Code, and the encrypted data.

The data will be formatted as

a) ASCII armored OpenPGP data, if --armor is specified
b) Base16 (hex) encoded binary data, if --armor is not specified

The PDF Document will have a header row, containing the following information:

  • Serial Number
  • Creation Date
  • Purpose

and, next to the markdown information, a 2D code containing the encrypted data.

func (*PaperCrypt) GetText

func (p *PaperCrypt) GetText(lowerCaseEncoding bool) ([]byte, error)

GetText returns the text representation of the paper crypt.

func (*PaperCrypt) MarshalJSON added in v1.4.0

func (p *PaperCrypt) MarshalJSON() ([]byte, error)

func (*PaperCrypt) UnmarshalJSON added in v1.4.0

func (p *PaperCrypt) UnmarshalJSON(data []byte) error

type PaperCryptContainerVersion added in v1.4.0

type PaperCryptContainerVersion uint32
const (
	PaperCryptContainerVersionUnknown PaperCryptContainerVersion = 0
	PaperCryptContainerVersionMajor1  PaperCryptContainerVersion = 1
	PaperCryptContainerVersionMajor2  PaperCryptContainerVersion = 2
	PaperCryptContainerVersionDevel   PaperCryptContainerVersion = PaperCryptContainerVersion(0xFFFFFFFF)
)

func PaperCryptContainerVersionFromString added in v1.4.0

func PaperCryptContainerVersionFromString(s string) PaperCryptContainerVersion

func (PaperCryptContainerVersion) String added in v1.4.0

type PaperCryptDataFormat added in v1.4.0

type PaperCryptDataFormat uint8
const (
	PaperCryptDataFormatPGP PaperCryptDataFormat = 0
	PaperCryptDataFormatRaw PaperCryptDataFormat = 1
)

func PaperCryptDataFormatFromString added in v1.4.0

func PaperCryptDataFormatFromString(s string) PaperCryptDataFormat

func (PaperCryptDataFormat) String added in v1.4.0

func (f PaperCryptDataFormat) String() string

type PaperCryptV1 added in v1.4.0

type PaperCryptV1 struct {
	// Version is the version of papercrypt used to generate the document.
	Version string `json:"Version"`

	// Data is the encrypted data as a PGP message
	Data *crypto.PGPMessage `json:"Data"`

	// SerialNumber is the serial number of document, used to identify it. It is generated randomly if not provided.
	SerialNumber string `json:"SerialNumber"`

	// Purpose is the purpose of document
	Purpose string `json:"Purpose"`

	// Comment is the comment on document
	Comment string `json:"Comment"`

	// CreatedAt is the creation timestamp
	CreatedAt time.Time `json:"CreatedAt"`

	// DataCRC24 is the CRC-24 checksum of the encrypted data
	DataCRC24 uint32 `json:"DataCRC24"`

	// DataCRC32 is the CRC-32 checksum of the encrypted data
	DataCRC32 uint32 `json:"DataCRC32"`

	// DataSHA256 is the SHA-256 checksum of the encrypted data
	DataSHA256 [32]byte `json:"DataSHA256"`
}

func NewPaperCryptV1 added in v1.4.0

func NewPaperCryptV1(version string, data *crypto.PGPMessage, serialNumber string, purpose string, comment string, createdAt time.Time) *PaperCryptV1

NewPaperCryptV1 creates a new paper crypt

func (*PaperCryptV1) GetBinary added in v1.4.0

func (p *PaperCryptV1) GetBinary() []byte

func (*PaperCryptV1) GetBinarySerialized added in v1.4.0

func (p *PaperCryptV1) GetBinarySerialized() string

func (*PaperCryptV1) GetLength added in v1.4.0

func (p *PaperCryptV1) GetLength() int

func (*PaperCryptV1) GetText added in v1.4.0

func (p *PaperCryptV1) GetText(lowerCaseEncoding bool) ([]byte, error)

func (*PaperCryptV1) ToNextVersion added in v1.4.0

func (p *PaperCryptV1) ToNextVersion() (*PaperCrypt, error)

ToNextVersion converts the PaperCryptV1 to the next version, PaperCrypt, by encoding format information and compressing the data.

Jump to

Keyboard shortcuts

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