|
|
|
@ -16,6 +16,7 @@ import (
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/ProtonMail/gopenpgp/v2/crypto" // MIT License
|
|
|
|
|
"github.com/beevik/etree" // BSD-2-clause
|
|
|
|
|
"github.com/mattn/go-xmpp" // BSD-3-Clause
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -112,9 +113,6 @@ func oxStorePrivKey(jid string, privKey string) error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func oxGenPrivKey(jid string, client *xmpp.Client) error {
|
|
|
|
|
var iqOxPublishKey IQoxPublishKeyType
|
|
|
|
|
var iqOxPublishKeyList IQoxPublishKeyListType
|
|
|
|
|
// var iqPubsubCreate IQpubsubCreateType
|
|
|
|
|
xmppUri := "xmpp:" + jid
|
|
|
|
|
key, err := crypto.GenerateKey(xmppUri, xmppUri, "x25519", 0)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -132,32 +130,43 @@ func oxGenPrivKey(jid string, client *xmpp.Client) error {
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
keyCreated := time.Now().UTC().Format("2006-01-02T15:04:05Z")
|
|
|
|
|
fingerprint := strings.ToUpper(key.GetFingerprint())
|
|
|
|
|
// TODO: Get existing key list and append the new one.
|
|
|
|
|
iqOxPublishKey.Xmlns = nsPubsub
|
|
|
|
|
iqOxPublishKey.Publish.Node = nsOxPubKeys + ":" + fingerprint
|
|
|
|
|
iqOxPublishKey.Publish.Item.ID = time.Now().UTC().Format("2006-01-02T15:04:05Z")
|
|
|
|
|
iqOxPublishKey.Publish.Item.Pubkey.Xmlns = nsOx
|
|
|
|
|
iqOxPublishKey.Publish.Item.Pubkey.Data = pubKeyBase64
|
|
|
|
|
iqOxPublishKey.PublishOptions.X.Xmlns = nsJabberData
|
|
|
|
|
iqOxPublishKey.PublishOptions.X.Type = "submit"
|
|
|
|
|
iqOxPublishKey.PublishOptions.X.Field[0].Var = "FORM_TYPE"
|
|
|
|
|
iqOxPublishKey.PublishOptions.X.Field[0].Type = "hidden"
|
|
|
|
|
iqOxPublishKey.PublishOptions.X.Field[0].Value = pubsubPubOptions
|
|
|
|
|
iqOxPublishKey.PublishOptions.X.Field[1].Var = "pubsub#access_model"
|
|
|
|
|
iqOxPublishKey.PublishOptions.X.Field[1].Value = "open"
|
|
|
|
|
|
|
|
|
|
opk, err := xml.Marshal(iqOxPublishKey)
|
|
|
|
|
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()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
println(string(opk))
|
|
|
|
|
iqReply, err := sendIQ(client, jid, "set", string(opk))
|
|
|
|
|
println(xmlstring)
|
|
|
|
|
iqReply, err := sendIQ(client, jid, "set", xmlstring)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if iqReply.Type != "result" {
|
|
|
|
|
return errors.New("Error whil publishing public key.")
|
|
|
|
|
return errors.New("Error while publishing public key.")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Split GetPublicKey in GetPublicKeyList and GetPublicKey
|
|
|
|
@ -176,26 +185,34 @@ func oxGenPrivKey(jid string, client *xmpp.Client) error {
|
|
|
|
|
return errors.New("Couldn't successfully verify public key upload.")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iqOxPublishKeyList.Xmlns = nsPubsub
|
|
|
|
|
iqOxPublishKeyList.Publish.Node = nsOxPubKeys
|
|
|
|
|
iqOxPublishKeyList.Publish.Item.PublicKeysList.Xmlns = nsOx
|
|
|
|
|
iqOxPublishKeyList.Publish.Item.PublicKeysList.PubkeyMetadata[0].V4Fingerprint = fingerprint
|
|
|
|
|
iqOxPublishKeyList.Publish.Item.PublicKeysList.PubkeyMetadata[0].Date =
|
|
|
|
|
time.Now().UTC().Format("2006-01-02T15:04:05Z")
|
|
|
|
|
iqOxPublishKeyList.PublishOptions.X.Xmlns = nsJabberData
|
|
|
|
|
iqOxPublishKeyList.PublishOptions.X.Type = "submit"
|
|
|
|
|
iqOxPublishKeyList.PublishOptions.X.Field[0].Var = "FORM_TYPE"
|
|
|
|
|
iqOxPublishKeyList.PublishOptions.X.Field[0].Type = "hidden"
|
|
|
|
|
iqOxPublishKeyList.PublishOptions.X.Field[0].Value = pubsubPubOptions
|
|
|
|
|
iqOxPublishKeyList.PublishOptions.X.Field[1].Var = "pubsub#access_model"
|
|
|
|
|
iqOxPublishKeyList.PublishOptions.X.Field[1].Value = "open"
|
|
|
|
|
|
|
|
|
|
opkl, err := xml.Marshal(iqOxPublishKeyList)
|
|
|
|
|
root = etree.NewDocument()
|
|
|
|
|
pubsub = root.CreateElement("pubsub")
|
|
|
|
|
pubsub.CreateAttr("xmlns", nsPubsub)
|
|
|
|
|
publish = pubsub.CreateElement("publish")
|
|
|
|
|
publish.CreateAttr("node", nsOxPubKeys)
|
|
|
|
|
item = publish.CreateElement("item")
|
|
|
|
|
pubkeymeta := item.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()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
println(string(opkl))
|
|
|
|
|
iqReply, err = sendIQ(client, jid, "set", string(opkl))
|
|
|
|
|
println(xmlstring)
|
|
|
|
|
iqReply, err = sendIQ(client, jid, "set", xmlstring)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|