1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/trust/service.go
Alexander Morozov 9e50bf6270 Remove engine from trust
Signed-off-by: Alexander Morozov <lk4d4@docker.com>
2015-04-20 12:48:33 -07:00

53 lines
1.1 KiB
Go

package trust
import (
"fmt"
"time"
"github.com/Sirupsen/logrus"
"github.com/docker/libtrust"
)
type NotVerifiedError string
func (e NotVerifiedError) Error() string {
return string(e)
}
func (t *TrustStore) CheckKey(ns string, key []byte, perm uint16) (bool, error) {
if len(key) == 0 {
return false, fmt.Errorf("Missing PublicKey")
}
pk, err := libtrust.UnmarshalPublicKeyJWK(key)
if err != nil {
return false, fmt.Errorf("Error unmarshalling public key: %v", err)
}
if perm == 0 {
perm = 0x03
}
t.RLock()
defer t.RUnlock()
if t.graph == nil {
return false, NotVerifiedError("no graph")
}
// Check if any expired grants
verified, err := t.graph.Verify(pk, ns, perm)
if err != nil {
return false, fmt.Errorf("Error verifying key to namespace: %s", ns)
}
if !verified {
logrus.Debugf("Verification failed for %s using key %s", ns, pk.KeyID())
return false, NotVerifiedError("not verified")
}
if t.expiration.Before(time.Now()) {
return false, NotVerifiedError("expired")
}
return true, nil
}
func (t *TrustStore) UpdateBase() {
t.fetch()
}