|
|
|
@ -19,7 +19,7 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func oxImportPrivKey(jid string, privKeyLocation string, client *xmpp.Client) error {
|
|
|
|
|
xmppUri := "xmpp:" + jid
|
|
|
|
|
xmppURI := "xmpp:" + jid
|
|
|
|
|
buffer, err := readFile(privKeyLocation)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
@ -32,8 +32,8 @@ func oxImportPrivKey(jid string, privKeyLocation string, client *xmpp.Client) er
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
entity := key.GetEntity()
|
|
|
|
|
if entity.Identities[xmppUri] == nil {
|
|
|
|
|
return errors.New("Key identity is not " + xmppUri)
|
|
|
|
|
if entity.Identities[xmppURI] == nil {
|
|
|
|
|
return errors.New("Key identity is not " + xmppURI)
|
|
|
|
|
}
|
|
|
|
|
pk, err := key.GetPublicKey()
|
|
|
|
|
if err != nil {
|
|
|
|
@ -195,8 +195,8 @@ func oxStoreKey(location string, key string) error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func oxGenPrivKey(jid string, client *xmpp.Client, passphrase string) error {
|
|
|
|
|
xmppUri := "xmpp:" + jid
|
|
|
|
|
key, err := crypto.GenerateKey(xmppUri, xmppUri, "x25519", 0)
|
|
|
|
|
xmppURI := "xmpp:" + jid
|
|
|
|
|
key, err := crypto.GenerateKey(xmppURI, xmppURI, "x25519", 0)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
@ -263,20 +263,20 @@ func oxGenPrivKey(jid string, client *xmpp.Client, passphrase string) error {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if iqReply.Type != "result" {
|
|
|
|
|
return errors.New("Error while publishing public key.")
|
|
|
|
|
return errors.New("Error while publishing public key")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ownPubKeyRingFromPubsub, err := oxRecvPublicKeys(client, jid, fingerprint)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.New("Couldn't successfully verify public key upload.")
|
|
|
|
|
return errors.New("Couldn't successfully verify public key upload")
|
|
|
|
|
}
|
|
|
|
|
ownPubKeyFromPubsub := ownPubKeyRingFromPubsub.GetKeys()[0]
|
|
|
|
|
ownPubKeyFromPubsubSerialized, err := ownPubKeyFromPubsub.Serialize()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.New("Couldn't successfully verify public key upload.")
|
|
|
|
|
return errors.New("Couldn't successfully verify public key upload")
|
|
|
|
|
}
|
|
|
|
|
if pubKeyBase64 != base64.StdEncoding.EncodeToString(ownPubKeyFromPubsubSerialized) {
|
|
|
|
|
return errors.New("Couldn't successfully verify public key upload.")
|
|
|
|
|
return errors.New("Couldn't successfully verify public key upload")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
root = etree.NewDocument()
|
|
|
|
@ -312,7 +312,7 @@ func oxGenPrivKey(jid string, client *xmpp.Client, passphrase string) error {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if iqReply.Type != "result" {
|
|
|
|
|
return errors.New("Couldn't publish public key list.")
|
|
|
|
|
return errors.New("Couldn't publish public key list")
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
@ -401,7 +401,7 @@ func oxGetPublicKeyRing(client *xmpp.Client, recipient string) (*crypto.KeyRing,
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pubKeyRingId := "none"
|
|
|
|
|
pubKeyRingID := "none"
|
|
|
|
|
newestKey, err := time.Parse(time.RFC3339, "1900-01-01T00:00:00Z")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
@ -422,14 +422,14 @@ func oxGetPublicKeyRing(client *xmpp.Client, recipient string) (*crypto.KeyRing,
|
|
|
|
|
}
|
|
|
|
|
if keyDate.After(newestKey) {
|
|
|
|
|
newestKey = keyDate
|
|
|
|
|
pubKeyRingId = fingerprint.Value
|
|
|
|
|
pubKeyRingID = fingerprint.Value
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if pubKeyRingId == "none" {
|
|
|
|
|
if pubKeyRingID == "none" {
|
|
|
|
|
return nil, errors.New("server didn't provide public key fingerprints for " + recipient)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pubKeyRingLocation, err := oxGetPubKeyLoc(pubKeyRingId)
|
|
|
|
|
pubKeyRingLocation, err := oxGetPubKeyLoc(pubKeyRingID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -446,7 +446,7 @@ func oxGetPublicKeyRing(client *xmpp.Client, recipient string) (*crypto.KeyRing,
|
|
|
|
|
if !savedKeysDate.Before(newestKey) {
|
|
|
|
|
pubKeys := pubKeyReadXML.SelectElements("pubkey")
|
|
|
|
|
if pubKeys == nil {
|
|
|
|
|
return nil, errors.New("Couldn't read public keys from cache.")
|
|
|
|
|
return nil, errors.New("Couldn't read public keys from cache")
|
|
|
|
|
}
|
|
|
|
|
for _, r := range pubKeys {
|
|
|
|
|
keyByte, err := base64.StdEncoding.DecodeString(r.Text())
|
|
|
|
@ -470,7 +470,7 @@ func oxGetPublicKeyRing(client *xmpp.Client, recipient string) (*crypto.KeyRing,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pubKeyRing, err := oxRecvPublicKeys(client, recipient, pubKeyRingId)
|
|
|
|
|
pubKeyRing, err := oxRecvPublicKeys(client, recipient, pubKeyRingID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|