https://github.com/xuender/go-sign
Self verification after sign of golang lib.
https://github.com/xuender/go-sign
build cmd go golang golang-library safety sign
Last synced: 2 months ago
JSON representation
Self verification after sign of golang lib.
- Host: GitHub
- URL: https://github.com/xuender/go-sign
- Owner: xuender
- License: mit
- Created: 2022-04-27T03:10:23.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-03T10:38:37.000Z (about 3 years ago)
- Last Synced: 2025-02-09T19:40:51.382Z (4 months ago)
- Topics: build, cmd, go, golang, golang-library, safety, sign
- Language: Go
- Homepage:
- Size: 38.1 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- License: LICENSE
Awesome Lists containing this project
README
# go-sign
[](https://github.com/xuender/go-sign/actions)
[](https://codecov.io/gh/xuender/go-sign)
[](https://goreportcard.com/report/github.com/xuender/go-sign)
[](https://pkg.go.dev/github.com/xuender/go-sign)
[](https://gitter.im/xuender-go-sign/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[](https://github.com/xuender/go-sign/blob/main/LICENSE)
[](https://github.com/xuender/go-sign/issues)
[](https://github.com/xuender/go-sign/stargazers)Self verification after sign of golang lib.
[Changelog](http://github.com/xuender/go-sign/blob/master/History.md) | [中文](http://github.com/xuender/go-sign/blob/master/README_CN.md)
## Install cmd
```shell
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.
```go
package mainimport (
"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.")
}
``````shell
go build -o helloword main.go
sign -s=secret_key helloword
```### licence
Check license string.
```go
package mainimport (
"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.")
}
``````shell
go build -o helloword main.go
sign -s=licence_str helloword
# run
./helloword licence_str
```### env
Check environment variables.
```go
package mainimport (
"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.")
}
``````shell
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.
```go
package mainimport (
"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.")
}
``````shell
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.
```go
package mainimport (
"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.")
}
``````shell
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.
```shell
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
[MIT License](https://github.com/xuender/go-sign/blob/master/License)