2015-11-17 18:11:00 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/serialiser: rschatitems.h
|
|
|
|
*
|
|
|
|
* RetroShare Serialiser.
|
|
|
|
*
|
|
|
|
* Copyright 2007-2008 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
#include <openssl/ssl.h>
|
|
|
|
|
2017-04-26 05:40:46 -04:00
|
|
|
#include "rsitems/rsserviceids.h"
|
|
|
|
#include "rsitems/itempriorities.h"
|
|
|
|
#include "rsitems/rsitem.h"
|
|
|
|
|
2015-11-17 18:11:00 -05:00
|
|
|
#include "retroshare/rstypes.h"
|
|
|
|
#include "serialiser/rstlvkeys.h"
|
|
|
|
#include "serialiser/rsserial.h"
|
|
|
|
|
|
|
|
#include "serialiser/rstlvidset.h"
|
|
|
|
#include "serialiser/rstlvfileitem.h"
|
|
|
|
|
|
|
|
/* chat Flags */
|
2015-11-18 23:56:35 -05:00
|
|
|
const uint32_t RS_GXS_TUNNEL_FLAG_CLOSING_DISTANT_CONNECTION = 0x0400;
|
|
|
|
const uint32_t RS_GXS_TUNNEL_FLAG_ACK_DISTANT_CONNECTION = 0x0800;
|
|
|
|
const uint32_t RS_GXS_TUNNEL_FLAG_KEEP_ALIVE = 0x1000;
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-18 23:56:35 -05:00
|
|
|
const uint8_t RS_PKT_SUBTYPE_GXS_TUNNEL_DATA = 0x01 ;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_GXS_TUNNEL_DH_PUBLIC_KEY = 0x02 ;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_GXS_TUNNEL_STATUS = 0x03 ;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_GXS_TUNNEL_DATA_ACK = 0x04 ;
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-18 23:56:35 -05:00
|
|
|
typedef uint64_t GxsTunnelDHSessionId ;
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-18 23:56:35 -05:00
|
|
|
class RsGxsTunnelItem: public RsItem
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
|
|
|
public:
|
2017-07-21 11:30:26 -04:00
|
|
|
explicit RsGxsTunnelItem(uint8_t item_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_GXS_TUNNEL,item_subtype)
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
|
|
|
setPriorityLevel(QOS_PRIORITY_RS_CHAT_ITEM) ;
|
|
|
|
}
|
|
|
|
|
2015-11-18 23:56:35 -05:00
|
|
|
virtual ~RsGxsTunnelItem() {}
|
2015-11-17 18:11:00 -05:00
|
|
|
virtual void clear() {}
|
|
|
|
};
|
|
|
|
|
2015-11-24 21:57:59 -05:00
|
|
|
/*!
|
|
|
|
* For sending distant communication data. The item is not encrypted after being serialised, but the data it.
|
|
|
|
* The MAC is computed over encrypted data using the PFS key. All other items (except DH keys) are serialised, encrypted, and
|
|
|
|
* sent as data in a RsGxsTunnelDataItem.
|
|
|
|
*
|
|
|
|
* @see p3GxsTunnelService
|
|
|
|
*/
|
|
|
|
class RsGxsTunnelDataItem: public RsGxsTunnelItem
|
|
|
|
{
|
|
|
|
public:
|
2017-07-21 11:30:26 -04:00
|
|
|
RsGxsTunnelDataItem() :RsGxsTunnelItem(RS_PKT_SUBTYPE_GXS_TUNNEL_DATA), unique_item_counter(0), flags(0), service_id(0), data_size(0), data(NULL) {}
|
|
|
|
explicit RsGxsTunnelDataItem(uint8_t subtype) :RsGxsTunnelItem(subtype) , unique_item_counter(0), flags(0), service_id(0), data_size(0), data(NULL) {}
|
2015-11-24 21:57:59 -05:00
|
|
|
|
|
|
|
virtual ~RsGxsTunnelDataItem() {}
|
|
|
|
virtual void clear() {}
|
|
|
|
|
2017-04-29 17:02:44 -04:00
|
|
|
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
2015-11-24 21:57:59 -05:00
|
|
|
|
|
|
|
uint64_t unique_item_counter; // this allows to make the item unique
|
|
|
|
uint32_t flags; // mainly NEEDS_HACK?
|
|
|
|
uint32_t service_id ;
|
|
|
|
uint32_t data_size ; // encrypted data size
|
|
|
|
unsigned char *data ; // encrypted data
|
|
|
|
};
|
2015-11-18 23:56:35 -05:00
|
|
|
|
|
|
|
// Used to send status of connection. This can be closing orders, flushing orders, etc.
|
|
|
|
// These items are always sent encrypted.
|
|
|
|
|
|
|
|
class RsGxsTunnelStatusItem: public RsGxsTunnelItem
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
|
|
|
public:
|
2016-01-01 22:36:07 -05:00
|
|
|
RsGxsTunnelStatusItem() :RsGxsTunnelItem(RS_PKT_SUBTYPE_GXS_TUNNEL_STATUS) , status(0) {}
|
2015-11-18 23:56:35 -05:00
|
|
|
RsGxsTunnelStatusItem(void *data,uint32_t size) ; // deserialization
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-18 23:56:35 -05:00
|
|
|
virtual ~RsGxsTunnelStatusItem() {}
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2017-04-29 17:02:44 -04:00
|
|
|
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-30 00:02:44 -05:00
|
|
|
uint32_t status ;
|
2015-11-17 18:11:00 -05:00
|
|
|
};
|
|
|
|
|
2015-11-18 23:56:35 -05:00
|
|
|
// Used to confirm reception of an encrypted item.
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-18 23:56:35 -05:00
|
|
|
class RsGxsTunnelDataAckItem: public RsGxsTunnelItem
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
|
|
|
public:
|
2017-07-21 11:30:26 -04:00
|
|
|
RsGxsTunnelDataAckItem() :RsGxsTunnelItem(RS_PKT_SUBTYPE_GXS_TUNNEL_DATA_ACK), unique_item_counter(0) {}
|
2015-11-18 23:56:35 -05:00
|
|
|
RsGxsTunnelDataAckItem(void *data,uint32_t size) ; // deserialization
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-18 23:56:35 -05:00
|
|
|
virtual ~RsGxsTunnelDataAckItem() {}
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2017-04-29 17:02:44 -04:00
|
|
|
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2017-04-29 17:02:44 -04:00
|
|
|
uint64_t unique_item_counter ; // unique identifier for that item
|
2015-11-17 18:11:00 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// This class contains the public Diffie-Hellman parameters to be sent
|
|
|
|
// when performing a DH agreement over a distant chat tunnel.
|
|
|
|
//
|
2015-11-18 23:56:35 -05:00
|
|
|
class RsGxsTunnelDHPublicKeyItem: public RsGxsTunnelItem
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
|
|
|
public:
|
2017-07-21 11:30:26 -04:00
|
|
|
RsGxsTunnelDHPublicKeyItem() :RsGxsTunnelItem(RS_PKT_SUBTYPE_GXS_TUNNEL_DH_PUBLIC_KEY), public_key(NULL) {}
|
2015-11-18 23:56:35 -05:00
|
|
|
RsGxsTunnelDHPublicKeyItem(void *data,uint32_t size) ; // deserialization
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-26 20:40:06 -05:00
|
|
|
virtual ~RsGxsTunnelDHPublicKeyItem() ;
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2017-04-29 17:02:44 -04:00
|
|
|
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
2015-11-17 18:11:00 -05:00
|
|
|
|
|
|
|
// Private data to DH public key item
|
|
|
|
//
|
|
|
|
BIGNUM *public_key ;
|
|
|
|
|
|
|
|
RsTlvKeySignature signature ; // signs the public key in a row.
|
2016-06-02 23:47:57 -04:00
|
|
|
RsTlvPublicRSAKey gxs_key ; // public key of the signer
|
2015-11-17 18:11:00 -05:00
|
|
|
|
|
|
|
private:
|
2015-11-18 23:56:35 -05:00
|
|
|
// make the object non copy-able
|
2017-07-21 11:30:26 -04:00
|
|
|
RsGxsTunnelDHPublicKeyItem(const RsGxsTunnelDHPublicKeyItem&) : RsGxsTunnelItem(RS_PKT_SUBTYPE_GXS_TUNNEL_DH_PUBLIC_KEY), public_key(NULL) {}
|
|
|
|
const RsGxsTunnelDHPublicKeyItem& operator=(const RsGxsTunnelDHPublicKeyItem&) { public_key = NULL; return *this ;}
|
2015-11-17 18:11:00 -05:00
|
|
|
};
|
|
|
|
|
2017-04-29 17:02:44 -04:00
|
|
|
class RsGxsTunnelSerialiser: public RsServiceSerializer
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
2015-11-27 23:37:39 -05:00
|
|
|
public:
|
2017-04-29 17:02:44 -04:00
|
|
|
RsGxsTunnelSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_GXS_TUNNEL) {}
|
|
|
|
|
|
|
|
virtual RsItem *create_item(uint16_t service,uint8_t item_subtype) const ;
|
2015-11-17 18:11:00 -05:00
|
|
|
};
|
|
|
|
|