|
|
@ -72,25 +72,24 @@ func oxStorePrivKey(jid string, privKey string) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func oxGenPrivKey(jid string, client *xmpp.Client) (*crypto.Key, error) {
|
|
|
|
func oxGenPrivKey(jid string, client *xmpp.Client) error {
|
|
|
|
var iqOxPublishKey IQoxPublishKeyType
|
|
|
|
var iqOxPublishKey IQoxPublishKeyType
|
|
|
|
var iqOxPublishKeyList IQoxPublishKeyListType
|
|
|
|
var iqOxPublishKeyList IQoxPublishKeyListType
|
|
|
|
xmppUri := "xmpp:" + jid
|
|
|
|
xmppUri := "xmpp:" + jid
|
|
|
|
key, err := crypto.GenerateKey(xmppUri, xmppUri, "x25519", 0)
|
|
|
|
key, err := crypto.GenerateKey(xmppUri, xmppUri, "x25519", 0)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
keySerialized, _ := key.Serialize()
|
|
|
|
keySerialized, _ := key.Serialize()
|
|
|
|
|
|
|
|
|
|
|
|
pubKey, err := key.GetPublicKey()
|
|
|
|
pubKey, err := key.GetPublicKey()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pubKeyBase64 := base64.StdEncoding.EncodeToString(pubKey)
|
|
|
|
pubKeyBase64 := base64.StdEncoding.EncodeToString(pubKey)
|
|
|
|
err = oxStorePrivKey(jid,
|
|
|
|
err = oxStorePrivKey(jid,
|
|
|
|
base64.StdEncoding.EncodeToString(keySerialized))
|
|
|
|
base64.StdEncoding.EncodeToString(keySerialized))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
// return nil, errors.New("Couldn't store private key:")
|
|
|
|
|
|
|
|
log.Fatal(err)
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fingerprint := key.GetFingerprint()
|
|
|
|
fingerprint := key.GetFingerprint()
|
|
|
@ -109,14 +108,14 @@ func oxGenPrivKey(jid string, client *xmpp.Client) (*crypto.Key, error) {
|
|
|
|
|
|
|
|
|
|
|
|
opk, err := xml.Marshal(iqOxPublishKey)
|
|
|
|
opk, err := xml.Marshal(iqOxPublishKey)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
iqReply, err := sendIQ(client, jid, "set", string(opk))
|
|
|
|
iqReply, err := sendIQ(client, jid, "set", string(opk))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if iqReply.Type != "result" {
|
|
|
|
if iqReply.Type != "result" {
|
|
|
|
return nil, errors.New("Error whil publishing public key.")
|
|
|
|
return errors.New("Error whil publishing public key.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Split GetPublicKey in GetPublicKeyList and GetPublicKey
|
|
|
|
// TODO: Split GetPublicKey in GetPublicKeyList and GetPublicKey
|
|
|
@ -125,14 +124,14 @@ func oxGenPrivKey(jid string, client *xmpp.Client) (*crypto.Key, error) {
|
|
|
|
// upload.
|
|
|
|
// upload.
|
|
|
|
ownPubKeyFromPubsub, err := oxRecvPublicKey(client, jid, fingerprint)
|
|
|
|
ownPubKeyFromPubsub, err := oxRecvPublicKey(client, jid, fingerprint)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.New("Couldn't successfully verify public key upload.")
|
|
|
|
return errors.New("Couldn't successfully verify public key upload.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ownPubKeyFromPubsubSerialized, err := ownPubKeyFromPubsub.Serialize()
|
|
|
|
ownPubKeyFromPubsubSerialized, err := ownPubKeyFromPubsub.Serialize()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, 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) {
|
|
|
|
if pubKeyBase64 != base64.StdEncoding.EncodeToString(ownPubKeyFromPubsubSerialized) {
|
|
|
|
return nil, errors.New("Couldn't successfully verify public key upload.")
|
|
|
|
return errors.New("Couldn't successfully verify public key upload.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
iqOxPublishKeyList.Xmlns = nsPubsub
|
|
|
|
iqOxPublishKeyList.Xmlns = nsPubsub
|
|
|
@ -150,17 +149,17 @@ func oxGenPrivKey(jid string, client *xmpp.Client) (*crypto.Key, error) {
|
|
|
|
|
|
|
|
|
|
|
|
opkl, err := xml.Marshal(iqOxPublishKeyList)
|
|
|
|
opkl, err := xml.Marshal(iqOxPublishKeyList)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
iqReply, err = sendIQ(client, jid, "set", string(opkl))
|
|
|
|
iqReply, err = sendIQ(client, jid, "set", string(opkl))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if iqReply.Type != "result" {
|
|
|
|
if iqReply.Type != "result" {
|
|
|
|
return nil, errors.New("Error while publishing public key list.")
|
|
|
|
return errors.New("Error while publishing public key list.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return key, nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func oxRecvPublicKey(client *xmpp.Client, recipient string, fingerprint string) (*crypto.Key, error) {
|
|
|
|
func oxRecvPublicKey(client *xmpp.Client, recipient string, fingerprint string) (*crypto.Key, error) {
|
|
|
|