mirror of
https://salsa.debian.org/mdosch/go-sendxmpp
synced 2024-11-15 00:15:10 +00:00
Merge branch 'master' into code-cleanup
This commit is contained in:
commit
5d19a6ce12
@ -4,6 +4,9 @@
|
|||||||
### Added
|
### Added
|
||||||
- Experimental support for Ox (OpenPGP for XMPP) encryption.
|
- Experimental support for Ox (OpenPGP for XMPP) encryption.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Use shorter random ID for resource.
|
||||||
|
|
||||||
## [v0.3.0] 2022-03-21
|
## [v0.3.0] 2022-03-21
|
||||||
### Added
|
### Added
|
||||||
- Added support for joining password protected MUCs.
|
- Added support for joining password protected MUCs.
|
||||||
|
10
helpers.go
10
helpers.go
@ -49,3 +49,13 @@ func getID() string {
|
|||||||
id := fmt.Sprintf("%x-%x-%x", b[0:4], b[4:8], b[8:])
|
id := fmt.Sprintf("%x-%x-%x", b[0:4], b[4:8], b[8:])
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getShortID() string {
|
||||||
|
b := make([]byte, 4)
|
||||||
|
_, err := rand.Read(b)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
id := fmt.Sprintf("%x", b[0:4])
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
34
iqstructs.go
34
iqstructs.go
@ -30,28 +30,6 @@ type OxMessageElement struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Created with https://github.com/miku/zek
|
// Created with https://github.com/miku/zek
|
||||||
type OxCryptElement struct {
|
|
||||||
XMLName xml.Name `xml:"signcrypt"`
|
|
||||||
Text string `xml:",chardata"`
|
|
||||||
Xmlns string `xml:"xmlns,attr"`
|
|
||||||
To struct {
|
|
||||||
Text string `xml:",chardata"`
|
|
||||||
Jid string `xml:"jid,attr"`
|
|
||||||
} `xml:"to"`
|
|
||||||
Time struct {
|
|
||||||
Text string `xml:",chardata"`
|
|
||||||
Stamp string `xml:"stamp,attr"`
|
|
||||||
} `xml:"time"`
|
|
||||||
Rpad string `xml:"rpad"`
|
|
||||||
Payload struct {
|
|
||||||
Text string `xml:",chardata"`
|
|
||||||
Body struct {
|
|
||||||
Text string `xml:",chardata"`
|
|
||||||
Xmlns string `xml:"xmlns,attr"`
|
|
||||||
} `xml:"body"`
|
|
||||||
} `xml:"payload"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Created with https://github.com/miku/zek
|
// Created with https://github.com/miku/zek
|
||||||
type OxPublicKeysList struct {
|
type OxPublicKeysList struct {
|
||||||
XMLName xml.Name `xml:"pubsub"`
|
XMLName xml.Name `xml:"pubsub"`
|
||||||
@ -76,18 +54,6 @@ type OxPublicKeysList struct {
|
|||||||
} `xml:"items"`
|
} `xml:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Created with https://github.com/miku/zek
|
|
||||||
type IQPubsubRequest struct {
|
|
||||||
XMLName xml.Name `xml:"pubsub"`
|
|
||||||
Text string `xml:",chardata"`
|
|
||||||
Xmlns string `xml:"xmlns,attr"`
|
|
||||||
Items struct {
|
|
||||||
Text string `xml:",chardata"`
|
|
||||||
Node string `xml:"node,attr"`
|
|
||||||
MaxItems string `xml:"max_items,attr"`
|
|
||||||
} `xml:"items"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Created with https://github.com/miku/zek
|
// Created with https://github.com/miku/zek
|
||||||
type IQDiscoItemsType struct {
|
type IQDiscoItemsType struct {
|
||||||
XMLName xml.Name `xml:"query"`
|
XMLName xml.Name `xml:"query"`
|
||||||
|
2
main.go
2
main.go
@ -183,7 +183,7 @@ func main() {
|
|||||||
resource = *flagResource
|
resource = *flagResource
|
||||||
} else if resource == "" {
|
} else if resource == "" {
|
||||||
// Use "go-sendxmpp" plus a random string if no other resource is specified
|
// Use "go-sendxmpp" plus a random string if no other resource is specified
|
||||||
resource = "go-sendxmpp." + getID()
|
resource = "go-sendxmpp." + getShortID()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*flagHttpUpload != "") && (*flagInteractive || (*flagMessageFile != "")) {
|
if (*flagHttpUpload != "") && (*flagInteractive || (*flagMessageFile != "")) {
|
||||||
|
36
ox.go
36
ox.go
@ -373,21 +373,23 @@ func oxRecvPublicKeys(client *xmpp.Client, recipient string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func oxGetPublicKeyRing(client *xmpp.Client, recipient string) (*crypto.KeyRing, error) {
|
func oxGetPublicKeyRing(client *xmpp.Client, recipient string) (*crypto.KeyRing, error) {
|
||||||
var oxPublicKeyListRequest IQPubsubRequest
|
|
||||||
var oxPublicKeyListXML OxPublicKeysList
|
var oxPublicKeyListXML OxPublicKeysList
|
||||||
publicKeyRing, err := crypto.NewKeyRing(nil)
|
publicKeyRing, err := crypto.NewKeyRing(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
oxPublicKeyListRequest.Xmlns = nsPubsub
|
oxPubKeyListReq := etree.NewDocument()
|
||||||
oxPublicKeyListRequest.Items.Node = nsOxPubKeys
|
oxPubKeyListReqPs := oxPubKeyListReq.CreateElement("pubsub")
|
||||||
oxPublicKeyListRequest.Items.MaxItems = "1"
|
oxPubKeyListReqPs.CreateAttr("xmlns", nsPubsub)
|
||||||
opkl, err := xml.Marshal(oxPublicKeyListRequest)
|
oxPubKeyListReqPsItems := oxPubKeyListReqPs.CreateElement("items")
|
||||||
|
oxPubKeyListReqPsItems.CreateAttr("node", nsOxPubKeys)
|
||||||
|
oxPubKeyListReqPsItems.CreateAttr("max_items", "1")
|
||||||
|
opkl, err := oxPubKeyListReq.WriteToString()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
oxPublicKeyList, err := sendIQ(client, recipient, "get", string(opkl))
|
oxPublicKeyList, err := sendIQ(client, recipient, "get", opkl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -487,7 +489,6 @@ func oxGetPublicKeyRing(client *xmpp.Client, recipient string) (*crypto.KeyRing,
|
|||||||
|
|
||||||
func oxEncrypt(client *xmpp.Client, oxPrivKey *crypto.Key, recipient string,
|
func oxEncrypt(client *xmpp.Client, oxPrivKey *crypto.Key, recipient string,
|
||||||
keyRing *crypto.KeyRing, message string) (string, error) {
|
keyRing *crypto.KeyRing, message string) (string, error) {
|
||||||
var oxCryptMessage OxCryptElement
|
|
||||||
var oxMessage OxMessageElement
|
var oxMessage OxMessageElement
|
||||||
privKeyRing, err := crypto.NewKeyRing(oxPrivKey)
|
privKeyRing, err := crypto.NewKeyRing(oxPrivKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -501,13 +502,20 @@ func oxEncrypt(client *xmpp.Client, oxPrivKey *crypto.Key, recipient string,
|
|||||||
_ = keyRing.AddKey(ownKey)
|
_ = keyRing.AddKey(ownKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oxCryptMessage.Xmlns = nsOx
|
oxCryptMessage := etree.NewDocument()
|
||||||
oxCryptMessage.To.Jid = recipient
|
oxCryptMessageSc := oxCryptMessage.CreateElement("signcrypt")
|
||||||
oxCryptMessage.Time.Stamp = time.Now().UTC().Format("2006-01-02T15:04:05Z")
|
oxCryptMessageSc.CreateAttr("xmlns", nsOx)
|
||||||
oxCryptMessage.Rpad = getRpad()
|
oxCryptMessageScTo := oxCryptMessageSc.CreateElement("to")
|
||||||
oxCryptMessage.Payload.Body.Xmlns = nsJabberClient
|
oxCryptMessageScTo.CreateAttr("jid", recipient)
|
||||||
oxCryptMessage.Payload.Body.Text = message
|
oxCryptMessageScTime := oxCryptMessageSc.CreateElement("time")
|
||||||
ocm, err := xml.Marshal(oxCryptMessage)
|
oxCryptMessageScTime.CreateAttr("stamp", time.Now().UTC().Format("2006-01-02T15:04:05Z"))
|
||||||
|
oxCryptMessageScRpad := oxCryptMessageSc.CreateElement("rpad")
|
||||||
|
oxCryptMessageScRpad.CreateText(getRpad())
|
||||||
|
oxCryptMessageScPayload := oxCryptMessageSc.CreateElement("payload")
|
||||||
|
oxCryptMessageScPayloadBody := oxCryptMessageScPayload.CreateElement("body")
|
||||||
|
oxCryptMessageScPayloadBody.CreateAttr("xmlns", nsJabberClient)
|
||||||
|
oxCryptMessageScPayloadBody.CreateText(message)
|
||||||
|
ocm, err := oxCryptMessage.WriteToString()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "error", err
|
return "error", err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user