Allow verification without specifying a server name

This commit is contained in:
Brendan Abolivier 2017-09-04 15:03:36 +01:00
parent 9344201031
commit fd27afbf82
No known key found for this signature in database
GPG key ID: 8EF1500759F70623

View file

@ -30,18 +30,37 @@ import (
// Returns nil if all the verifications succeeded. // Returns nil if all the verifications succeeded.
// Returns an error if something failed in the process. // Returns an error if something failed in the process.
func CheckIDServerSignatures(idServer string, signatures map[string]map[string]string, marshalledBody []byte) error { func CheckIDServerSignatures(idServer string, signatures map[string]map[string]string, marshalledBody []byte) error {
// TODO: Check if the domain is part of a list of trusted ID servers if len(idServer) > 0 {
idServerSignatures, ok := signatures[idServer] // TODO: Check if the domain is part of a list of trusted ID servers
if !ok { idServerSignatures, ok := signatures[idServer]
return errors.New("No signature for domain " + idServer) if !ok {
return errors.New("No signature for domain " + idServer)
}
return retrieveAndVerify(idServer, idServerSignatures, marshalledBody)
} }
for keyID := range idServerSignatures { for domain, sigs := range signatures {
pubKey, err := queryIDServerPubKey(idServer, keyID) if err := retrieveAndVerify(domain, sigs, marshalledBody); err != nil {
return err
}
}
return nil
}
// retrieveAndVerify iterates over a given set of signatures and, for each of them,
// requests the corresponding public key to the identity server and verify the
// signature.
// Returns an error if the verification failed or if something went wrong in the
// process.
func retrieveAndVerify(domain string, signatures map[string]string, marshalledBody []byte) error {
for keyID := range signatures {
pubKey, err := queryIDServerPubKey(domain, keyID)
if err != nil { if err != nil {
return err return err
} }
if err = gomatrixserverlib.VerifyJSON(idServer, gomatrixserverlib.KeyID(keyID), pubKey, marshalledBody); err != nil { if err = gomatrixserverlib.VerifyJSON(domain, gomatrixserverlib.KeyID(keyID), pubKey, marshalledBody); err != nil {
return err return err
} }
} }