gosum

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: MIT Imports: 10 Imported by: 0

README

Gosum

Self verification of golang lib.

Install cmd

go install github.com/xuender/gosum/cmd/gosum@latest

Examples

base

Check the integrity of the execution file to prevent tampering or virus intrusion.

package main

import (
	"fmt"

	"github.com/xuender/gosum"
)

func main() {
	if err := gosum.Check("secret_key"); err != nil {
		panic(err)
	}

	fmt.Println("Hello Word.")
	fmt.Println("This file integrity.")
}
go build -o helloword main.go
gosum -s=secret_key helloword
env

Check environment variables.

package main

import (
	"fmt"

	"github.com/xuender/gosum"
)

func main() {
	if err := gosum.CheckEnv("SECRET_KEY"); err != nil {
		panic(err)
	}

	fmt.Println("Hello Word.")
	fmt.Println("Run on safe environment.")
}
go build -o helloword main.go
SECRET_KEY=secret_key gosum -e=SECRET_KEY helloword
# set env and run
SECRET_KEY=secret_key ./helloword
machine

Only run on the sign machine.

package main

import (
	"fmt"

	"github.com/xuender/gosum"
)

func main() {
	if err := gosum.CheckMachine(); err != nil {
		panic(err)
	}

	fmt.Println("Hello Word.")
	fmt.Println("Run on sign machine.")
}
go build -o helloword main.go
# sign on the final running machine
gosum -m helloword

ps: CheckMachine must be signed, otherwise it cannot run after build.

Documentation

Index

Constants

View Source
const (
	FileMode = 0o666
	DirMode  = 0o700
)

Variables

View Source
var (
	ErrSignFailed = errors.New("sign failed")
	ErrFileName   = errors.New("error file name")
	ErrSigned     = errors.New("file has been signed")
)
View Source
var (
	ModVersion = "(devel)"
	ModSum     = "00000000"
	ModPath    = ""
)

nolint

Functions

func Check

func Check(secret string) error

func CheckEnv added in v1.1.1

func CheckEnv(env string) error

func CheckFile

func CheckFile(file, secret string) error

func CheckMachine added in v1.1.1

func CheckMachine() error

func GetMachineSecret added in v1.1.1

func GetMachineSecret() (string, error)

Types

type ContainsReader added in v1.1.0

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

func NewContainsReader added in v1.1.0

func NewContainsReader(reader io.Reader, subslice []byte) *ContainsReader

func (*ContainsReader) Contains added in v1.1.0

func (p *ContainsReader) Contains() bool

func (*ContainsReader) Read added in v1.1.0

func (p *ContainsReader) Read(data []byte) (n int, err error)

type Sum added in v1.0.2

type Sum struct {
	Error    error
	HasGosum bool
	// contains filtered or unexported fields
}

func NewSum added in v1.0.2

func NewSum(file string, secret []byte) *Sum

func (*Sum) Check added in v1.0.2

func (p *Sum) Check() error

func (*Sum) Hash added in v1.1.0

func (p *Sum) Hash() ([]byte, error)

func (*Sum) Sign added in v1.1.0

func (p *Sum) Sign() error

Directories

Path Synopsis
cmd
examples
env

Jump to

Keyboard shortcuts

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