github.com/Consensys/quorum@v21.1.0+incompatible/plugin/local_verifier.go (about) 1 package plugin 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "os" 7 "path" 8 ) 9 10 const DefaultPublicKeyFile = "Central.pgp.pk" 11 12 // Local Implementation of plugin.Verifier 13 type LocalVerifier struct { 14 PublicKeyPath string // where to obtain PGP public key 15 SignatureBaseDir string // where to obtain plugin signature file 16 } 17 18 // Build a new LocalVerifier 19 func NewLocalVerifier(publicKeyPath string, pluginSignatureBaseDir string) (*LocalVerifier, error) { 20 if _, err := os.Stat(publicKeyPath); os.IsNotExist(err) { 21 return nil, err 22 } 23 stat, err := os.Stat(pluginSignatureBaseDir) 24 if os.IsNotExist(err) { 25 return nil, err 26 } 27 if !stat.Mode().IsDir() { 28 return nil, fmt.Errorf("pluginSignatureBaseDir is not a directory") 29 } 30 verifier := &LocalVerifier{ 31 PublicKeyPath: publicKeyPath, 32 SignatureBaseDir: pluginSignatureBaseDir, 33 } 34 return verifier, nil 35 } 36 37 // Verify a plugin giving its name from Central 38 func (v *LocalVerifier) VerifySignature(definition *PluginDefinition, checksum string) error { 39 pluginSigPath := path.Join(v.SignatureBaseDir, definition.SignatureFileName()) 40 if _, err := os.Stat(pluginSigPath); os.IsNotExist(err) { 41 return err 42 } 43 pubkey, err := ioutil.ReadFile(v.PublicKeyPath) 44 if err != nil { 45 return err 46 } 47 sig, err := ioutil.ReadFile(pluginSigPath) 48 if err != nil { 49 return err 50 } 51 return verify(sig, pubkey, checksum) 52 }