|
|
|
@ -417,17 +417,17 @@ func oxGetPublicKeyRing(client *xmpp.Client, recipient string) (*crypto.KeyRing,
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
doc := etree.NewDocument()
|
|
|
|
|
err = doc.ReadFromFile(pubKeyRingLocation)
|
|
|
|
|
pubKeyReadXML := etree.NewDocument()
|
|
|
|
|
err = pubKeyReadXML.ReadFromFile(pubKeyRingLocation)
|
|
|
|
|
if err == nil {
|
|
|
|
|
date := doc.SelectElement("date")
|
|
|
|
|
date := pubKeyReadXML.SelectElement("date")
|
|
|
|
|
if date != nil {
|
|
|
|
|
savedKeysDate, err := time.Parse(time.RFC3339, date.Text())
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if !savedKeysDate.Before(newestKey) {
|
|
|
|
|
pubKeys := doc.SelectElements("pubkey")
|
|
|
|
|
pubKeys := pubKeyReadXML.SelectElements("pubkey")
|
|
|
|
|
if pubKeys == nil {
|
|
|
|
|
return nil, errors.New("Couldn't read public keys from cache.")
|
|
|
|
|
}
|
|
|
|
@ -457,8 +457,8 @@ func oxGetPublicKeyRing(client *xmpp.Client, recipient string) (*crypto.KeyRing,
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
doc2 := etree.NewDocument()
|
|
|
|
|
date := doc2.CreateElement("date")
|
|
|
|
|
pubKeySaveXML := etree.NewDocument()
|
|
|
|
|
date := pubKeySaveXML.CreateElement("date")
|
|
|
|
|
date.SetText(newestKey.Format(time.RFC3339))
|
|
|
|
|
for _, key := range pubKeyRing.GetKeys() {
|
|
|
|
|
keySerialized, err := key.Serialize()
|
|
|
|
@ -468,10 +468,10 @@ func oxGetPublicKeyRing(client *xmpp.Client, recipient string) (*crypto.KeyRing,
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
saveKey := doc2.CreateElement("pubkey")
|
|
|
|
|
saveKey := pubKeySaveXML.CreateElement("pubkey")
|
|
|
|
|
saveKey.SetText(base64.StdEncoding.EncodeToString(keySerialized))
|
|
|
|
|
}
|
|
|
|
|
err = doc2.WriteToFile(pubKeyRingLocation)
|
|
|
|
|
err = pubKeySaveXML.WriteToFile(pubKeyRingLocation)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|