gosign

package module
v0.0.7 Latest Latest
Warning

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

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

README

gosign

GoCI codecov Go Report Card GoDoc Gitter GitHub license GitHub issues GitHub stars

Self verification after sign of golang lib.

Changelog | 中文

Install cmd

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

Examples

base

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

package main

import (
	"fmt"

	"github.com/xuender/gosign"
)

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

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

Check license string.

package main

import (
	"fmt"
	"os"

	"github.com/xuender/gosign"
)

func main() {
	if len(os.Args) < 2 {
		panic("Miss licence.")
	}

	if err := gosign.Check(os.Args[1]); err != nil {
		panic("Licence FAILED.")
	}

	fmt.Println("Hello Word.")
	fmt.Println("Licence OK.")
}
go build -o helloword main.go
gosign -s=licence_str helloword
# run
./helloword licence_str
env

Check environment variables.

package main

import (
	"fmt"

	"github.com/xuender/gosign"
)

func main() {
	if err := gosign.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 gosign -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/gosign"
)

func main() {
	if err := gosign.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
gosign -m helloword
complex

Only run on the sign machine and has env.

package main

import (
	"fmt"
	"os"

	"github.com/xuender/gosign"
)

func main() {
	mid := gosign.GetMachineSecret(os.Getenv("SECRET_KEY"))
	if err := gosign.Check(mid); err != nil {
		panic(err)
	}

	fmt.Println("Hello Word.")
	fmt.Println("Run on sign machine and has env.")
}
go build -o helloword main.go
# sign on the final running machine
SECRET_KEY=secret_key gosign -m -e=SECRET_KEY helloword
# set env and run
SECRET_KEY=secret_key ./helloword

PS

Use gosign and Check/CheckEnv/CheckMachine must be signed, otherwise it cannot run after build.

License

© xuender, 2022~time.Now

MIT License

Documentation

Index

Examples

Constants

This section is empty.

Variables

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

nolint

Functions

func Check

func Check(secret string) error
Example
package main

import (
	"fmt"

	"github.com/xuender/gosign"
)

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

	fmt.Println("Hello Word.")
	fmt.Println("This file integrity.")

}
Output:

Hello Word.
This file integrity.

func CheckEnv

func CheckEnv(env string) error
Example
package main

import (
	"fmt"

	"github.com/xuender/gosign"
)

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

	fmt.Println("Hello Word.")
	fmt.Println("Run on safe environment.")

}
Output:

Hello Word.
Run on safe environment.

func CheckFile

func CheckFile(file, secret string) error

func CheckMachine

func CheckMachine() error
Example
package main

import (
	"fmt"

	"github.com/xuender/gosign"
)

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

	fmt.Println("Hello Word.")
	fmt.Println("Run on sign machine.")

}
Output:

Hello Word.
Run on sign machine.

func Error added in v0.0.6

func Error(file string, err error) error

func GetMachineSecret

func GetMachineSecret(secret string) string

func GetMod added in v0.0.6

func GetMod(info *debug.BuildInfo, ok bool) *debug.Module

func IsBuild added in v0.0.7

func IsBuild(file string) bool

Types

type ContainsReader

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

func NewContainsReader

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

func (*ContainsReader) Contains

func (p *ContainsReader) Contains() bool

func (*ContainsReader) Read

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

type Sign

type Sign struct {
	Error     error
	Hasgosign bool
	// contains filtered or unexported fields
}

func NewSign

func NewSign(file string, secret []byte) *Sign

func (*Sign) Check

func (p *Sign) Check() error

func (*Sign) Hash

func (p *Sign) Hash(reader io.Reader) ([]byte, error)

func (*Sign) Sign

func (p *Sign) Sign() error

Directories

Path Synopsis
cmd
gosign command
examples
base command
complex command
env command
licence command
machine command

Jump to

Keyboard shortcuts

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