# README
go-sign
Self verification after sign of golang lib.
Install cmd
go install github.com/xuender/go-sign/cmd/sign@latest
Examples
base
Check the integrity of the execution file to prevent tampering or virus intrusion.
package main
import (
"fmt"
"github.com/xuender/go-sign"
)
func main() {
if err := sign.Check("secret_key"); err != nil {
panic(err)
}
fmt.Println("Hello Word.")
fmt.Println("This file integrity.")
}
go build -o helloword main.go
sign -s=secret_key helloword
licence
Check license string.
package main
import (
"fmt"
"os"
"github.com/xuender/go-sign"
)
func main() {
if len(os.Args) < 2 {
panic("Miss licence.")
}
if err := sign.Check(os.Args[1]); err != nil {
panic("Licence FAILED.")
}
fmt.Println("Hello Word.")
fmt.Println("Licence OK.")
}
go build -o helloword main.go
sign -s=licence_str helloword
# run
./helloword licence_str
env
Check environment variables.
package main
import (
"fmt"
"github.com/xuender/go-sign"
)
func main() {
if err := sign.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 sign -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/go-sign"
)
func main() {
if err := sign.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
sign -m helloword
complex
Only run on the sign machine and has env.
package main
import (
"fmt"
"os"
"github.com/xuender/go-sign"
)
func main() {
mid := sign.GetMachineSecret(os.Getenv("SECRET_KEY"))
if err := sign.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 sign -m -e=SECRET_KEY helloword
# set env and run
SECRET_KEY=secret_key ./helloword
Safe
To enhance the security level, set the safe parameter at build time.
go build -o helloword \
-ldflags "-X 'github.com/xuender/go-sign.Safe=strong'" \
main.go
PS
Use sign and Check/CheckEnv/CheckMachine must be signed, otherwise it cannot run after build.
License
© xuender, 2022~time.Now