Last active
March 21, 2018 21:26
-
-
Save JonCooperWorks/e74aa6040546420eb2268869cb73e706 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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