|
|
@ -20,7 +20,8 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func oxDeleteNodes(jid string, client *xmpp.Client,
|
|
|
|
func oxDeleteNodes(jid string, client *xmpp.Client,
|
|
|
|
iqc chan xmpp.IQ) error {
|
|
|
|
iqc chan xmpp.IQ,
|
|
|
|
|
|
|
|
) error {
|
|
|
|
nodeListRequest := etree.NewDocument()
|
|
|
|
nodeListRequest := etree.NewDocument()
|
|
|
|
nodeListRequest.WriteSettings.AttrSingleQuote = true
|
|
|
|
nodeListRequest.WriteSettings.AttrSingleQuote = true
|
|
|
|
query := nodeListRequest.CreateElement("query")
|
|
|
|
query := nodeListRequest.CreateElement("query")
|
|
|
@ -73,14 +74,14 @@ func oxDeleteNodes(jid string, client *xmpp.Client,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func oxDecrypt(m xmpp.Chat, client *xmpp.Client, iqc chan xmpp.IQ,
|
|
|
|
func oxDecrypt(m xmpp.Chat, client *xmpp.Client, iqc chan xmpp.IQ,
|
|
|
|
user string, oxPrivKey *crypto.Key) (string, time.Time, error) {
|
|
|
|
user string, oxPrivKey *crypto.Key,
|
|
|
|
|
|
|
|
) (string, time.Time, error) {
|
|
|
|
var cryptMsgByte []byte
|
|
|
|
var cryptMsgByte []byte
|
|
|
|
var err error
|
|
|
|
var err error
|
|
|
|
sender := strings.Split(m.Remote, "/")[0]
|
|
|
|
sender := strings.Split(m.Remote, "/")[0]
|
|
|
|
for _, r := range m.OtherElem {
|
|
|
|
for _, r := range m.OtherElem {
|
|
|
|
if r.XMLName.Space == nsOx {
|
|
|
|
if r.XMLName.Space == nsOx {
|
|
|
|
cryptMsgByte, err =
|
|
|
|
cryptMsgByte, err = base64.StdEncoding.DecodeString(r.InnerXML)
|
|
|
|
base64.StdEncoding.DecodeString(r.InnerXML)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return strError, time.Now(), err
|
|
|
|
return strError, time.Now(), err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -155,7 +156,8 @@ func isOxMsg(m xmpp.Chat) bool {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func oxImportPrivKey(jid string, privKeyLocation string, client *xmpp.Client,
|
|
|
|
func oxImportPrivKey(jid string, privKeyLocation string, client *xmpp.Client,
|
|
|
|
iqc chan xmpp.IQ) error {
|
|
|
|
iqc chan xmpp.IQ,
|
|
|
|
|
|
|
|
) error {
|
|
|
|
xmppURI := "xmpp:" + jid
|
|
|
|
xmppURI := "xmpp:" + jid
|
|
|
|
buffer, err := readFile(privKeyLocation)
|
|
|
|
buffer, err := readFile(privKeyLocation)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -225,7 +227,8 @@ func oxImportPrivKey(jid string, privKeyLocation string, client *xmpp.Client,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func oxPublishPubKey(jid string, client *xmpp.Client, iqc chan xmpp.IQ,
|
|
|
|
func oxPublishPubKey(jid string, client *xmpp.Client, iqc chan xmpp.IQ,
|
|
|
|
pubKey *crypto.Key) error {
|
|
|
|
pubKey *crypto.Key,
|
|
|
|
|
|
|
|
) error {
|
|
|
|
keyCreated := time.Now().UTC().Format("2006-01-02T15:04:05Z")
|
|
|
|
keyCreated := time.Now().UTC().Format("2006-01-02T15:04:05Z")
|
|
|
|
fingerprint := strings.ToUpper(pubKey.GetFingerprint())
|
|
|
|
fingerprint := strings.ToUpper(pubKey.GetFingerprint())
|
|
|
|
keySerialized, err := pubKey.Serialize()
|
|
|
|
keySerialized, err := pubKey.Serialize()
|
|
|
@ -344,7 +347,7 @@ func oxGetPrivKeyLoc(jid string) (string, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dataDir += "/go-sendxmpp/oxprivkeys/"
|
|
|
|
dataDir += "/go-sendxmpp/oxprivkeys/"
|
|
|
|
if _, err = os.Stat(dataDir); os.IsNotExist(err) {
|
|
|
|
if _, err = os.Stat(dataDir); os.IsNotExist(err) {
|
|
|
|
err = os.MkdirAll(dataDir, 0700)
|
|
|
|
err = os.MkdirAll(dataDir, 0o700)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return strError, err
|
|
|
|
return strError, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -377,7 +380,7 @@ func oxGetPubKeyLoc(fingerprint string) (string, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dataDir += "/go-sendxmpp/oxpubkeys/"
|
|
|
|
dataDir += "/go-sendxmpp/oxpubkeys/"
|
|
|
|
if _, err = os.Stat(dataDir); os.IsNotExist(err) {
|
|
|
|
if _, err = os.Stat(dataDir); os.IsNotExist(err) {
|
|
|
|
err = os.MkdirAll(dataDir, 0700)
|
|
|
|
err = os.MkdirAll(dataDir, 0o700)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return strError, err
|
|
|
|
return strError, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -430,9 +433,9 @@ func oxStoreKey(location string, key string) error {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if runtime.GOOS != "windows" {
|
|
|
|
if runtime.GOOS != "windows" {
|
|
|
|
_ = file.Chmod(os.FileMode(0600))
|
|
|
|
_ = file.Chmod(os.FileMode(0o600))
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
_ = file.Chmod(os.FileMode(0200))
|
|
|
|
_ = file.Chmod(os.FileMode(0o200))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_, err = file.Write([]byte(key))
|
|
|
|
_, err = file.Write([]byte(key))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -446,7 +449,8 @@ func oxStoreKey(location string, key string) error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func oxGenPrivKey(jid string, client *xmpp.Client, iqc chan xmpp.IQ,
|
|
|
|
func oxGenPrivKey(jid string, client *xmpp.Client, iqc chan xmpp.IQ,
|
|
|
|
passphrase string, keyType string) error {
|
|
|
|
passphrase string, keyType string,
|
|
|
|
|
|
|
|
) error {
|
|
|
|
xmppURI := "xmpp:" + jid
|
|
|
|
xmppURI := "xmpp:" + jid
|
|
|
|
key, err := crypto.GenerateKey(xmppURI, "", keyType, 4096)
|
|
|
|
key, err := crypto.GenerateKey(xmppURI, "", keyType, 4096)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -487,7 +491,8 @@ func oxGenPrivKey(jid string, client *xmpp.Client, iqc chan xmpp.IQ,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func oxRecvPublicKeys(client *xmpp.Client, iqc chan xmpp.IQ, recipient string,
|
|
|
|
func oxRecvPublicKeys(client *xmpp.Client, iqc chan xmpp.IQ, recipient string,
|
|
|
|
fingerprint string) (*crypto.KeyRing, error) {
|
|
|
|
fingerprint string,
|
|
|
|
|
|
|
|
) (*crypto.KeyRing, error) {
|
|
|
|
opkr := etree.NewDocument()
|
|
|
|
opkr := etree.NewDocument()
|
|
|
|
opkr.WriteSettings.AttrSingleQuote = true
|
|
|
|
opkr.WriteSettings.AttrSingleQuote = true
|
|
|
|
opkrPs := opkr.CreateElement("pubsub")
|
|
|
|
opkrPs := opkr.CreateElement("pubsub")
|
|
|
@ -557,7 +562,8 @@ func oxRecvPublicKeys(client *xmpp.Client, iqc chan xmpp.IQ, recipient string,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func oxGetPublicKeyRing(client *xmpp.Client, iqc chan xmpp.IQ,
|
|
|
|
func oxGetPublicKeyRing(client *xmpp.Client, iqc chan xmpp.IQ,
|
|
|
|
recipient string) (*crypto.KeyRing, error) {
|
|
|
|
recipient string,
|
|
|
|
|
|
|
|
) (*crypto.KeyRing, error) {
|
|
|
|
publicKeyRing, err := crypto.NewKeyRing(nil)
|
|
|
|
publicKeyRing, err := crypto.NewKeyRing(nil)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
@ -610,8 +616,7 @@ func oxGetPublicKeyRing(client *xmpp.Client, iqc chan xmpp.IQ,
|
|
|
|
if oxPubKeyListXMLPubsubItemsItemPkl == nil {
|
|
|
|
if oxPubKeyListXMLPubsubItemsItemPkl == nil {
|
|
|
|
return nil, errors.New("ox: no keblic-keys-list element")
|
|
|
|
return nil, errors.New("ox: no keblic-keys-list element")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
oxPubKeyListXMLPubsubItemsItemPklPm :=
|
|
|
|
oxPubKeyListXMLPubsubItemsItemPklPm := oxPubKeyListXMLPubsubItemsItemPkl.SelectElements("pubkey-metadata")
|
|
|
|
oxPubKeyListXMLPubsubItemsItemPkl.SelectElements("pubkey-metadata")
|
|
|
|
|
|
|
|
for _, r := range oxPubKeyListXMLPubsubItemsItemPklPm {
|
|
|
|
for _, r := range oxPubKeyListXMLPubsubItemsItemPklPm {
|
|
|
|
date := r.SelectAttr("date")
|
|
|
|
date := r.SelectAttr("date")
|
|
|
|
if date == nil {
|
|
|
|
if date == nil {
|
|
|
@ -701,7 +706,8 @@ func oxGetPublicKeyRing(client *xmpp.Client, iqc chan xmpp.IQ,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func oxEncrypt(client *xmpp.Client, iqc chan xmpp.IQ, oxPrivKey *crypto.Key,
|
|
|
|
func oxEncrypt(client *xmpp.Client, iqc chan xmpp.IQ, oxPrivKey *crypto.Key,
|
|
|
|
recipient string, keyRing *crypto.KeyRing, message string) (string, error) {
|
|
|
|
recipient string, keyRing *crypto.KeyRing, message string,
|
|
|
|
|
|
|
|
) (string, error) {
|
|
|
|
if message == "" {
|
|
|
|
if message == "" {
|
|
|
|
return "", nil
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|