salmon.go 1.28 KB
Newer Older
zauberstuhl's avatar
zauberstuhl committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
package federation
//
// GangGo Diaspora Federation Library
// Copyright (C) 2017 Lukas Matt <lukas@zauberstuhl.de>
//
// 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 (
zauberstuhl's avatar
zauberstuhl committed
21 22
  "crypto/rsa"
  "github.com/Zauberstuhl/go-xml"
zauberstuhl's avatar
zauberstuhl committed
23 24
)

25
func ParseDecryptedRequest(entityXML []byte) (message Message, entity Entity, err error) {
26
  err = xml.Unmarshal(entityXML, &message)
zauberstuhl's avatar
zauberstuhl committed
27
  if err != nil {
28
    logger.Error(err)
zauberstuhl's avatar
zauberstuhl committed
29 30
    return
  }
31
  entity, err = message.Parse()
32
  return
zauberstuhl's avatar
zauberstuhl committed
33 34
}

35
func ParseEncryptedRequest(wrapper AesWrapper, privKey *rsa.PrivateKey) (message Message, entity Entity, err error) {
zauberstuhl's avatar
zauberstuhl committed
36
  entityXML, err := wrapper.Decrypt(privKey)
zauberstuhl's avatar
zauberstuhl committed
37
  if err != nil {
38
    logger.Error(err)
zauberstuhl's avatar
zauberstuhl committed
39 40
    return
  }
41 42

  return ParseDecryptedRequest(entityXML)
zauberstuhl's avatar
zauberstuhl committed
43
}