Skip to content

Instantly share code, notes, and snippets.

@JonCooperWorks
Last active March 21, 2018 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonCooperWorks/e74aa6040546420eb2268869cb73e706 to your computer and use it in GitHub Desktop.
Save JonCooperWorks/e74aa6040546420eb2268869cb73e706 to your computer and use it in GitHub Desktop.
package main
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"io/ioutil"
"log"
"github.com/joncooperworks/signedplugin"
)
const (
pluginPath = "exampleplugin.so"
)
func main() {
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
log.Fatalln(err.Error())
}
p, err := ioutil.ReadFile(pluginPath)
if err != nil {
log.Fatalln(err.Error())
}
signature, err := signedplugin.Sign(key, p)
if err != nil {
log.Fatalln(err.Error())
}
publicKey := key.Public().(*ecdsa.PublicKey)
log.Println("Attempting to verify with correct signature.")
plugin, err := signedplugin.Open(publicKey, signature, pluginPath)
if err != nil {
log.Fatalln(err.Error())
}
sym, err := plugin.Lookup("Hello")
if err != nil {
log.Fatalln(err.Error())
}
Hello := sym.(func())
Hello()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment