entities.go 6.4 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 21
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 "encoding/xml"

22 23 24 25 26 27 28 29 30 31 32 33 34
/* Header

  <?xml version="1.0" encoding="UTF-8"?>
  <diaspora xmlns="https://joindiaspora.com/protocol" xmlns:me="http://salmon-protocol.org/ns/magic-env">
    <header>
      <author_id>dia@192.168.0.173:3000</author_id>
    </header>
*/
type Header struct {
  XMLName xml.Name `xml:"header"`
  AuthorId string `xml:"author_id"`
}

zauberstuhl's avatar
zauberstuhl committed
35 36 37 38 39 40 41 42 43
/* Encrypted Header

  <?xml version="1.0" encoding="UTF-8"?>
  <decrypted_header>
    <iv>...</iv>
    <aes_key>...</aes_key>
    <author_id>one@two.tld</author_id>
  </decrypted_header>
*/
44
// XXX legacy?
zauberstuhl's avatar
zauberstuhl committed
45 46 47 48 49 50 51 52 53 54 55 56 57
type XmlDecryptedHeader struct {
  XMLName xml.Name `xml:"decrypted_header"`
  Iv string `xml:"iv"`
  AesKey string `xml:"aes_key"`
  AuthorId string `xml:"author_id"`
}

type JsonEnvHeader struct {
  AesKey string `json:"aes_key"`
  Ciphertext string `json:"ciphertext"`
}


58 59 60 61 62 63 64 65 66 67 68 69 70 71
// Private Request
//
//  <?xml version="1.0" encoding="UTF-8"?>
//  <diaspora xmlns="https://joindiaspora.com/protocol" xmlns:me="http://salmon-protocol.org/ns/magic-env">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me:sig>
//    </me:env>
//  </diaspora>

type PrivateEnvMarshal struct {
zauberstuhl's avatar
zauberstuhl committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
  XMLName xml.Name `xml:"me:env"`
  Me string `xml:"xmlns:me,attr"`
  Data struct {
    XMLName xml.Name `xml:"me:data"`
    Type string `xml:"type,attr"`
    Data string `xml:",chardata"`
  }
  Encoding string `xml:"me:encoding"`
  Alg string `xml:"me:alg"`
  Sig struct {
    XMLName xml.Name `xml:"me:sig"`
    Sig string `xml:",chardata"`
    KeyId string `xml:"key_id,attr,omitempty"`
  }
}

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
type PrivateMarshal struct {
  XMLName xml.Name `xml:"diaspora"`
  Xmlns string `xml:"xmlns,attr"`
  XmlnsMe string `xml:"me,attr"`
  EncryptedHeader string `xml:"encrypted_header,omitempty"`
  Env PrivateEnvMarshal
}

type PublicMarshal struct {
  XMLName xml.Name `xml:"diaspora"`
  Xmlns string `xml:"xmlns,attr"`
  XmlnsMe string `xml:"me,attr"`
  Header Header
  Env PrivateEnvMarshal
}

zauberstuhl's avatar
zauberstuhl committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
// NOTE I had huge problems with marshal
// and unmarshal with the same structs
// apperently namespaces in tags are a problem
// for the go xml implementation

type DiasporaUnmarshal struct {
  XMLName xml.Name `xml:"diaspora"`
  Xmlns string `xml:"xmlns,attr"`
  XmlnsMe string `xml:"me,attr"`
  Header struct {
    XMLName xml.Name `xml:"header"`
    AuthorId string `xml:"author_id"`
  }
  EncryptedHeader string `xml:"encrypted_header,omitempty"`
  DecryptedHeader *XmlDecryptedHeader `xml:",omitempty"`
  Env struct {
    XMLName xml.Name `xml:"env"`
    Me string `xml:"me,attr"`
    Data struct {
      XMLName xml.Name `xml:"data"`
      Type string `xml:"type,attr"`
      Data string `xml:",chardata"`
    }
    Encoding string `xml:"encoding"`
    Alg string `xml:"alg"`
    Sig struct {
      XMLName xml.Name `xml:"sig"`
      Sig string `xml:",chardata"`
      KeyId string `xml:"key_id,attr,omitempty"`
    }
  }
}

type Entity struct {
  XMLName xml.Name `xml:"XML"`
  Post EntityPost `xml:"post"`
140
  RequestBody []byte `xml:"-"` // original body payload
zauberstuhl's avatar
zauberstuhl committed
141 142 143 144 145 146 147
}

type EntityPost struct {
  XMLName xml.Name `xml:"post,omitempty"`
  Request *EntityRequest `xml:"request,omitempty"`
  Retraction *EntityRetraction `xml:"retraction,omitempty"`
  Profile *EntityProfile `xml:"profile,omitempty"`
zauberstuhl's avatar
zauberstuhl committed
148
  Reshare *EntityStatusMessage `xml:"reshare,omitempty"`
zauberstuhl's avatar
zauberstuhl committed
149 150 151 152 153 154
  StatusMessage *EntityStatusMessage `xml:"status_message,omitempty"`
  Comment *EntityComment `xml:"comment,omitempty"`
  Like *EntityLike `xml:"like,omitempty"`
  SignedRetraction *EntityRelayableSignedRetraction `xml:"signed_retraction,omitempty"`
  RelayableRetraction *EntityRelayableSignedRetraction `xml:"relayable_retraction,omitempty"`
}