Working on login / world connection mostly there, fixed a few crashes with encryption on 0 length packets

This commit is contained in:
KimLS
2016-10-29 23:23:04 -07:00
parent 0b8b41d91f
commit f3e2af7e42
19 changed files with 441 additions and 412 deletions
+41 -41
View File
@@ -17,8 +17,8 @@ namespace EQ
template <class Archive>
void serialize(Archive & archive)
{
archive(CEREAL_NVP(zero),
CEREAL_NVP(opcode));
archive(zero,
opcode);
}
};
@@ -34,11 +34,11 @@ namespace EQ
template <class Archive>
void serialize(Archive & archive)
{
archive(CEREAL_NVP(zero),
CEREAL_NVP(opcode),
CEREAL_NVP(protocol_version),
CEREAL_NVP(connect_code),
CEREAL_NVP(max_packet_size));
archive(zero,
opcode,
protocol_version,
connect_code,
max_packet_size);
}
};
@@ -57,14 +57,14 @@ namespace EQ
template <class Archive>
void serialize(Archive & archive)
{
archive(CEREAL_NVP(zero),
CEREAL_NVP(opcode),
CEREAL_NVP(connect_code),
CEREAL_NVP(encode_key),
CEREAL_NVP(crc_bytes),
CEREAL_NVP(encode_pass1),
CEREAL_NVP(encode_pass2),
CEREAL_NVP(max_packet_size));
archive(zero,
opcode,
connect_code,
encode_key,
crc_bytes,
encode_pass1,
encode_pass2,
max_packet_size);
}
};
@@ -78,9 +78,9 @@ namespace EQ
template <class Archive>
void serialize(Archive & archive)
{
archive(CEREAL_NVP(zero),
CEREAL_NVP(opcode),
CEREAL_NVP(connect_code));
archive(zero,
opcode,
connect_code);
}
};
@@ -94,9 +94,9 @@ namespace EQ
template <class Archive>
void serialize(Archive & archive)
{
archive(CEREAL_NVP(zero),
CEREAL_NVP(opcode),
CEREAL_NVP(sequence));
archive(zero,
opcode,
sequence);
}
};
@@ -109,8 +109,8 @@ namespace EQ
template <class Archive>
void serialize(Archive & archive)
{
archive(CEREAL_NVP(reliable),
CEREAL_NVP(total_size));
archive(reliable,
total_size);
}
};
@@ -131,16 +131,16 @@ namespace EQ
template <class Archive>
void serialize(Archive & archive)
{
archive(CEREAL_NVP(zero),
CEREAL_NVP(opcode),
CEREAL_NVP(timestamp),
CEREAL_NVP(stat_ping),
CEREAL_NVP(avg_ping),
CEREAL_NVP(min_ping),
CEREAL_NVP(max_ping),
CEREAL_NVP(last_ping),
CEREAL_NVP(packets_sent),
CEREAL_NVP(packets_recv));
archive(zero,
opcode,
timestamp,
stat_ping,
avg_ping,
min_ping,
max_ping,
last_ping,
packets_sent,
packets_recv);
}
};
@@ -159,14 +159,14 @@ namespace EQ
template <class Archive>
void serialize(Archive & archive)
{
archive(CEREAL_NVP(zero),
CEREAL_NVP(opcode),
CEREAL_NVP(timestamp),
CEREAL_NVP(our_timestamp),
CEREAL_NVP(client_sent),
CEREAL_NVP(client_recv),
CEREAL_NVP(server_sent),
CEREAL_NVP(server_recv));
archive(zero,
opcode,
timestamp,
our_timestamp,
client_sent,
client_recv,
server_sent,
server_recv);
}
};
}
+1 -5
View File
@@ -26,11 +26,7 @@ namespace EQ {
template<typename T>
T GetSerialize(size_t offset) const
{
if (T::size() > (Length() - offset)) {
throw std::out_of_range("Packet::GetSerialize(), packet not large enough to cast to type.");
}
{
T ret;
Util::MemoryStreamReader reader(((char*)Data() + offset), Length());
cereal::BinaryInputArchive input(reader);
+9 -6
View File
@@ -19,20 +19,23 @@ EQ::Net::ServertalkClient::~ServertalkClient()
{
}
void EQ::Net::ServertalkClient::Send(uint16_t opcode, EQ::Net::Packet & p)
void EQ::Net::ServertalkClient::Send(uint16_t opcode, EQ::Net::Packet &p)
{
EQ::Net::WritablePacket out;
#ifdef ENABLE_SECURITY
if (m_encrypted) {
if (p.Length() == 0) {
p.PutUInt8(0, 0);
}
out.PutUInt32(0, p.Length() + crypto_secretbox_MACBYTES);
out.PutUInt16(4, opcode);
unsigned char *cipher = new unsigned char[p.Length() + crypto_secretbox_MACBYTES];
crypto_box_easy_afternm(cipher, (unsigned char*)p.Data(), p.Length(), m_nonce_ours, m_shared_key);
std::unique_ptr<unsigned char[]> cipher(new unsigned char[p.Length() + crypto_secretbox_MACBYTES]);
crypto_box_easy_afternm(&cipher[0], (unsigned char*)p.Data(), p.Length(), m_nonce_ours, m_shared_key);
(*(uint64_t*)&m_nonce_ours[0])++;
out.PutData(6, cipher, p.Length() + crypto_secretbox_MACBYTES);
delete[] cipher;
out.PutData(6, &cipher[0], p.Length() + crypto_secretbox_MACBYTES);
}
else {
out.PutUInt32(0, p.Length());
@@ -22,8 +22,13 @@ void EQ::Net::ServertalkServerConnection::Send(uint16_t opcode, EQ::Net::Packet
EQ::Net::WritablePacket out;
#ifdef ENABLE_SECURITY
if (m_encrypted) {
if (p.Length() == 0) {
p.PutUInt8(0, 0);
}
out.PutUInt32(0, p.Length() + crypto_secretbox_MACBYTES);
out.PutUInt16(4, opcode);
std::unique_ptr<unsigned char[]> cipher(new unsigned char[p.Length() + crypto_secretbox_MACBYTES]);
crypto_box_easy_afternm(&cipher[0], (unsigned char*)p.Data(), p.Length(), m_nonce_ours, m_shared_key);