internal

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

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 (
	BytesPerLine = 22 // As is done in paperkey (https://www.jabberwocky.com/software/paperkey/)
	PdfTextFont  = "Times"
	PdfMonoFont  = "Courier"
)
View Source
const (
	HeaderFieldVersion              = "PaperCrypt Version"
	HeaderFieldSerial               = "Content Serial"
	HeaderFieldPurpose              = "Purpose"
	HeaderFieldComment              = "Comment"
	HeaderFieldDate                 = "Date"
	HeaderFieldLength               = "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 = "" /* 511-byte string literal not displayed */
	PDFSectionRecoveryHeading       = "Recovering the data"
	PDFSectionRecoveryContent       = "" /* 251-byte string literal not displayed */
	PDFSectionRecoveryContentNoQR   = "" /* 230-byte string literal not displayed */
)

Variables

This section is empty.

Functions

func BytesFromBase64

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

func Crc24Checksum

func Crc24Checksum(data []byte) uint32

func DecodeSerial

func DecodeSerial(serial string) ([]byte, error)

DecodeSerial decodes a serial number

func DeserializeBinary

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

func Fatal added in v1.0.1

func Fatal(cmd *cobra.Command, err 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(cmd *cobra.Command, path string, override bool) *os.File

GetFileHandleCarefully returns a file handle for the given path. will warn if the file already exists, and crash if override is false. if path is empty, returns os.Stdout. will exit with code 1 if the file cannot be opened. must be closed by the caller.

func ParseHexUint32

func ParseHexUint32(hex string) (uint32, error)

func PrintInputAndGetReader added in v1.0.1

func PrintInputAndGetReader(cmd *cobra.Command, inFileName string) *os.File

PrintInputAndGetReader prints the input source and returns the reader. if path is empty, returns os.Stdin. will exit with code 1 if the file cannot be opened. must be closed by the caller.

func PrintInputAndRead added in v1.0.1

func PrintInputAndRead(cmd *cobra.Command, inFileName string) []byte

PrintInputAndRead prints the input source and returns the contents of the file. if path is empty, returns os.Stdin. will exit with code 1 if the file cannot be opened or read.

func PrintInputSource added in v1.0.1

func PrintInputSource(cmd *cobra.Command, inFileName string)

func PrintWrittenSize added in v1.0.1

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

func ReadTtyLine

func ReadTtyLine() (string, error)

func SerializeBinary

func SerializeBinary(data *[]byte) 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 SliceHasString

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

func SprintBinarySize

func SprintBinarySize(size int) string

func SprintBinarySize64

func SprintBinarySize64(size int64) string

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

	// Data is the encrypted data as a PGP message
	Data *crypto.PGPMessage

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

	// Purpose is the purpose of document
	Purpose string

	// Comment is the comment on document
	Comment string

	// CreatedAt is the creation timestamp
	CreatedAt time.Time

	// DataCRC24 is the CRC-24 checksum of the encrypted data
	DataCRC24 uint32

	// DataCRC32 is the CRC-32 checksum of the encrypted data
	DataCRC32 uint32

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

func NewPaperCrypt

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

NewPaperCrypt creates a new paper crypt

func (*PaperCrypt) GetBinary

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

func (*PaperCrypt) GetBinarySerialized

func (p *PaperCrypt) GetBinarySerialized() string

func (*PaperCrypt) GetLength

func (p *PaperCrypt) GetLength() int

func (*PaperCrypt) GetPDF

func (p *PaperCrypt) GetPDF(noQR 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 QR-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 QR 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

type VersionDetails

type VersionDetails struct {
	Version    string
	BuildDate  string
	GitCommit  string
	GitBranch  string
	GitTag     string
	GitRef     string
	GitRepo    string
	GitIsDirty bool
	GitSummary string
	GoVersion  string
	OsArch     string
	OsType     string
	BuiltBy    string
}
var VersionInfo VersionDetails

Jump to

Keyboard shortcuts

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