This commit is contained in:
Martin Dosch 2023-01-19 19:38:34 +01:00
parent 841c47dec3
commit 81c8a09dcb
No known key found for this signature in database
GPG Key ID: 52A57CFCE13D657D
2 changed files with 85 additions and 60 deletions

66
ox.go
View File

@ -177,35 +177,11 @@ func oxPublishPubKey(jid string, client *xmpp.Client, iqc chan xmpp.IQ,
return err
}
pubKeyBase64 := base64.StdEncoding.EncodeToString(keySerialized)
root := etree.NewDocument()
pubsub := root.CreateElement("pubsub")
pubsub.CreateAttr("xmlns", nsPubsub)
publish := pubsub.CreateElement("publish")
publish.CreateAttr("node", nsOxPubKeys+":"+fingerprint)
item := publish.CreateElement("item")
item.CreateAttr("id", keyCreated)
pubkey := item.CreateElement("pubkey")
pubkey.CreateAttr("xmlns", nsOx)
data := pubkey.CreateElement("data")
data.CreateText(pubKeyBase64)
publishoptions := pubsub.CreateElement("publish-options")
x := publishoptions.CreateElement("x")
x.CreateAttr("xmlns", nsJabberData)
x.CreateAttr("type", "submit")
field := x.CreateElement("field")
field.CreateAttr("var", "FORM_TYPE")
field.CreateAttr("type", "hidden")
value := field.CreateElement("value")
value.CreateText(pubsubPubOptions)
field = x.CreateElement("field")
field.CreateAttr("var", "pubsub#access_model")
value = field.CreateElement("value")
value.CreateText("open")
xmlstring, err := root.WriteToString()
ppk, err := oxPublishPubKeyRequest(pubKeyBase64, fingerprint, keyCreated)
if err != nil {
return err
}
iqReply, err := sendIQ(client, iqc, jid, "set", xmlstring)
iqReply, err := sendIQ(client, iqc, jid, "set", ppk)
if err != nil {
return err
}
@ -224,35 +200,11 @@ func oxPublishPubKey(jid string, client *xmpp.Client, iqc chan xmpp.IQ,
if pubKeyBase64 != base64.StdEncoding.EncodeToString(ownPubKeyFromPubsubSerialized) {
return errors.New("couldn't successfully verify public key upload")
}
root = etree.NewDocument()
pubsub = root.CreateElement("pubsub")
pubsub.CreateAttr("xmlns", nsPubsub)
publish = pubsub.CreateElement("publish")
publish.CreateAttr("node", nsOxPubKeys)
item = publish.CreateElement("item")
pubkeyslist := item.CreateElement("public-keys-list")
pubkeyslist.CreateAttr("xmlns", nsOx)
pubkeymeta := pubkeyslist.CreateElement("pubkey-metadata")
pubkeymeta.CreateAttr("v4-fingerprint", fingerprint)
pubkeymeta.CreateAttr("date", keyCreated)
publishoptions = pubsub.CreateElement("publish-options")
x = publishoptions.CreateElement("x")
x.CreateAttr("xmlns", nsJabberData)
x.CreateAttr("type", "submit")
field = x.CreateElement("field")
field.CreateAttr("var", "FORM_TYPE")
field.CreateAttr("type", "hidden")
value = field.CreateElement("value")
value.CreateText(pubsubPubOptions)
field = x.CreateElement("field")
field.CreateAttr("var", "pubsub#access_model")
value = field.CreateElement("value")
value.CreateText("open")
xmlstring, err = root.WriteToString()
ppkl, err := oxPublishPubKeyListRequest(fingerprint, keyCreated)
if err != nil {
return err
}
iqReply, err = sendIQ(client, iqc, jid, "set", xmlstring)
iqReply, err = sendIQ(client, iqc, jid, "set", ppkl)
if err != nil {
return err
}
@ -427,17 +379,11 @@ func oxGenPrivKey(jid string, client *xmpp.Client, iqc chan xmpp.IQ,
func oxRecvPublicKeys(client *xmpp.Client, iqc chan xmpp.IQ, recipient string,
fingerprint string) (*crypto.KeyRing, error) {
opkr := etree.NewDocument()
opkrPs := opkr.CreateElement("pubsub")
opkrPs.CreateAttr("xmlns", nsPubsub)
opkrPsItems := opkrPs.CreateElement("items")
opkrPsItems.CreateAttr("node", nsOxPubKeys+":"+fingerprint)
opkrPsItems.CreateAttr("max_items", "1")
opkrString, err := opkr.WriteToString()
opkr, err := oxRecvPubKeysRequest(fingerprint)
if err != nil {
return nil, err
}
oxPublicKey, err := sendIQ(client, iqc, recipient, "get", opkrString)
oxPublicKey, err := sendIQ(client, iqc, recipient, "get", opkr)
if err != nil {
return nil, err
}

View File

@ -99,3 +99,82 @@ func oxParseSignCrypt(message string) (oxSigncrypt, error) {
output.body = body.Text()
return output, nil
}
func oxPublishPubKeyRequest(pubKeyBase64 string, fingerprint string,
keyCreated string) (string, error) {
root := etree.NewDocument()
pubsub := root.CreateElement("pubsub")
pubsub.CreateAttr("xmlns", nsPubsub)
publish := pubsub.CreateElement("publish")
publish.CreateAttr("node", nsOxPubKeys+":"+fingerprint)
item := publish.CreateElement("item")
item.CreateAttr("id", keyCreated)
pubkey := item.CreateElement("pubkey")
pubkey.CreateAttr("xmlns", nsOx)
data := pubkey.CreateElement("data")
data.CreateText(pubKeyBase64)
publishoptions := pubsub.CreateElement("publish-options")
x := publishoptions.CreateElement("x")
x.CreateAttr("xmlns", nsJabberData)
x.CreateAttr("type", "submit")
field := x.CreateElement("field")
field.CreateAttr("var", "FORM_TYPE")
field.CreateAttr("type", "hidden")
value := field.CreateElement("value")
value.CreateText(pubsubPubOptions)
field = x.CreateElement("field")
field.CreateAttr("var", "pubsub#access_model")
value = field.CreateElement("value")
value.CreateText("open")
output, err := root.WriteToString()
if err != nil {
return output, err
}
return output, nil
}
func oxPublishPubKeyListRequest(fingerprint string, keyCreated string) (string, error) {
root := etree.NewDocument()
pubsub := root.CreateElement("pubsub")
pubsub.CreateAttr("xmlns", nsPubsub)
publish := pubsub.CreateElement("publish")
publish.CreateAttr("node", nsOxPubKeys)
item := publish.CreateElement("item")
pubkeyslist := item.CreateElement("public-keys-list")
pubkeyslist.CreateAttr("xmlns", nsOx)
pubkeymeta := pubkeyslist.CreateElement("pubkey-metadata")
pubkeymeta.CreateAttr("v4-fingerprint", fingerprint)
pubkeymeta.CreateAttr("date", keyCreated)
publishoptions := pubsub.CreateElement("publish-options")
x := publishoptions.CreateElement("x")
x.CreateAttr("xmlns", nsJabberData)
x.CreateAttr("type", "submit")
field := x.CreateElement("field")
field.CreateAttr("var", "FORM_TYPE")
field.CreateAttr("type", "hidden")
value := field.CreateElement("value")
value.CreateText(pubsubPubOptions)
field = x.CreateElement("field")
field.CreateAttr("var", "pubsub#access_model")
value = field.CreateElement("value")
value.CreateText("open")
output, err := root.WriteToString()
if err != nil {
return output, err
}
return output, nil
}
func oxRecvPubKeysRequest(fingerprint string) (string, error) {
opkr := etree.NewDocument()
opkrPs := opkr.CreateElement("pubsub")
opkrPs.CreateAttr("xmlns", nsPubsub)
opkrPsItems := opkrPs.CreateElement("items")
opkrPsItems.CreateAttr("node", nsOxPubKeys+":"+fingerprint)
opkrPsItems.CreateAttr("max_items", "1")
output, err := opkr.WriteToString()
if err != nil {
return output, err
}
return output, nil
}