2022-02-04 23:01:18 +03:00
|
|
|
/*
|
2022-02-18 09:20:06 +03:00
|
|
|
* Copyright (c) 2022, The PurpleI2P Project
|
2022-02-04 23:01:18 +03:00
|
|
|
*
|
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3
|
|
|
|
*
|
|
|
|
* See full license text in LICENSE file at top of project tree
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SSU2_H__
|
|
|
|
#define SSU2_H__
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include "Crypto.h"
|
|
|
|
#include "RouterInfo.h"
|
|
|
|
#include "TransportSession.h"
|
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace transport
|
|
|
|
{
|
|
|
|
const int SSU2_TERMINATION_TIMEOUT = 330; // 5.5 minutes
|
2022-02-12 03:21:04 +03:00
|
|
|
|
|
|
|
enum SSU2MessageType
|
|
|
|
{
|
|
|
|
eSSU2SessionRequest = 0
|
|
|
|
};
|
2022-02-04 23:01:18 +03:00
|
|
|
|
|
|
|
class SSU2Session: public TransportSession, public std::enable_shared_from_this<SSU2Session>
|
|
|
|
{
|
2022-02-12 03:21:04 +03:00
|
|
|
union Header
|
|
|
|
{
|
|
|
|
uint64_t ll[2];
|
|
|
|
uint8_t buf[16];
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint8_t connID[8];
|
|
|
|
uint8_t packetNum[4];
|
|
|
|
uint8_t type;
|
|
|
|
uint8_t flags[3];
|
|
|
|
} h;
|
|
|
|
};
|
|
|
|
|
2022-02-04 23:01:18 +03:00
|
|
|
public:
|
|
|
|
|
|
|
|
SSU2Session (std::shared_ptr<const i2p::data::RouterInfo> in_RemoteRouter = nullptr,
|
|
|
|
std::shared_ptr<const i2p::data::RouterInfo::Address> addr = nullptr, bool peerTest = false);
|
|
|
|
~SSU2Session ();
|
2022-02-05 23:58:39 +03:00
|
|
|
|
2022-02-10 22:03:09 +03:00
|
|
|
private:
|
|
|
|
|
|
|
|
void SendSessionRequest ();
|
2022-02-12 03:21:04 +03:00
|
|
|
void EncryptHeader (Header& h);
|
2022-02-10 22:03:09 +03:00
|
|
|
void CreateHeaderMask (const uint8_t * kh1, const uint8_t * nonce1, const uint8_t * kh2, const uint8_t * nonce2);
|
|
|
|
|
2022-02-05 23:58:39 +03:00
|
|
|
private:
|
|
|
|
|
|
|
|
std::shared_ptr<i2p::crypto::X25519Keys> m_EphemeralKeys;
|
|
|
|
std::unique_ptr<i2p::crypto::NoiseSymmetricState> m_NoiseState;
|
2022-02-10 22:03:09 +03:00
|
|
|
std::shared_ptr<const i2p::data::RouterInfo::Address> m_Address;
|
|
|
|
|
2022-02-12 03:21:04 +03:00
|
|
|
union
|
|
|
|
{
|
|
|
|
uint64_t ll[2];
|
|
|
|
uint8_t buf[16];
|
|
|
|
} m_HeaderMask;
|
2022-02-04 23:01:18 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|