mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-02-16 16:04:27 -06:00
Allow verification without specifying a server name
This commit is contained in:
parent
9344201031
commit
fd27afbf82
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue