dia_salmon.go 1.38 KB
Newer Older
Lukas Matt's avatar
Lukas Matt committed
1 2
package federation
//
Ghost User's avatar
Ghost User committed
3 4
// GangGo Federation Library
// Copyright (C) 2017-2018 Lukas Matt <lukas@zauberstuhl.de>
Lukas Matt's avatar
Lukas Matt committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

import (
Lukas Matt's avatar
Lukas Matt committed
21
  "crypto/rsa"
Ghost User's avatar
Ghost User committed
22
  "encoding/json"
Lukas Matt's avatar
Lukas Matt committed
23
  "github.com/Zauberstuhl/go-xml"
Lukas Matt's avatar
Lukas Matt committed
24 25
)

Ghost User's avatar
Ghost User committed
26 27
func DiasporaParse(raw []byte) (message DiasporaMessage, err error) {
  err = xml.Unmarshal(raw, &message)
Lukas Matt's avatar
Lukas Matt committed
28
  if err != nil {
Ghost User's avatar
Ghost User committed
29
    Log.Error(err)
Lukas Matt's avatar
Lukas Matt committed
30 31
    return
  }
Ghost User's avatar
Ghost User committed
32
  err = message.Parse()
33
  return
Lukas Matt's avatar
Lukas Matt committed
34 35
}

Ghost User's avatar
Ghost User committed
36 37 38 39 40 41 42 43
func DiasporaParseEncrypted(raw []byte, privKey *rsa.PrivateKey) (message DiasporaMessage, err error) {
  wrapper := &DiasporaAesWrapper{}
  err = json.Unmarshal(raw, wrapper)
  if err != nil {
    Log.Error("Cannot parse request", "err", err)
    return
  }

Lukas Matt's avatar
Lukas Matt committed
44
  entityXML, err := wrapper.Decrypt(privKey)
Lukas Matt's avatar
Lukas Matt committed
45
  if err != nil {
Ghost User's avatar
Ghost User committed
46
    Log.Error(err)
Lukas Matt's avatar
Lukas Matt committed
47 48
    return
  }
49

Ghost User's avatar
Ghost User committed
50
  return DiasporaParse(entityXML)
Lukas Matt's avatar
Lukas Matt committed
51
}