From 0c4bf7be544aaf963d715ee7a3076e10706969f5 Mon Sep 17 00:00:00 2001 From: drbob Date: Mon, 5 Jul 2010 18:32:53 +0000 Subject: [PATCH] Fix incorrect TLV Signature DataType. This will cause loss of all forums (again). Sorry - I don't lightly change datatypes... but better to do it all at once. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3258 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/serialiser/rstlvkeys.cc | 63 ++++++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/libretroshare/src/serialiser/rstlvkeys.cc b/libretroshare/src/serialiser/rstlvkeys.cc index 6660ea452..9ccc20a53 100644 --- a/libretroshare/src/serialiser/rstlvkeys.cc +++ b/libretroshare/src/serialiser/rstlvkeys.cc @@ -35,6 +35,7 @@ #include #include +//#define TLV_DEBUG 1 /************************************* RsTlvSecurityKey ************************************/ @@ -88,7 +89,13 @@ bool RsTlvSecurityKey::SetTlv(void *data, uint32_t size, uint32_t *offset) /* s uint32_t tlvend = *offset + tlvsize; if (size < tlvend) + { +#ifdef TLV_DEBUG + std::cerr << "RsTlvSecurityKey::SetTlv() Failed not enough space"; + std::cerr << std::endl; +#endif return false; /* not enough space */ + } bool ok = true; @@ -118,10 +125,22 @@ bool RsTlvSecurityKey::GetTlv(void *data, uint32_t size, uint32_t *offset) /* s uint32_t tlvend = *offset + tlvsize; if (size < tlvend) /* check size */ + { +#ifdef TLV_DEBUG + std::cerr << "RsTlvSecurityKey::GetTlv() Fail, not enough space"; + std::cerr << std::endl; +#endif return false; /* not enough space */ + } if (tlvtype != TLV_TYPE_SECURITYKEY) /* check type */ + { +#ifdef TLV_DEBUG + std::cerr << "RsTlvSecurityKey::GetTlv() Fail, wrong type"; + std::cerr << std::endl; +#endif return false; + } bool ok = true; @@ -153,6 +172,14 @@ bool RsTlvSecurityKey::GetTlv(void *data, uint32_t size, uint32_t *offset) /* s *offset = tlvend; } + if (!ok) + { +#ifdef TLV_DEBUG + std::cerr << "RsTlvSecurityKey::GetTlv() Failed somewhere ok == false"; + std::cerr << std::endl; +#endif + } + return ok; } @@ -225,7 +252,13 @@ bool RsTlvSecurityKeySet::SetTlv(void *data, uint32_t size, uint32_t *offset) / uint32_t tlvend = *offset + tlvsize; if (size < tlvend) + { +#ifdef TLV_DEBUG + std::cerr << "RsTlvSecurityKeySet::SetTlv() Failed not enough space"; + std::cerr << std::endl; +#endif return false; /* not enough space */ + } bool ok = true; @@ -382,18 +415,32 @@ bool RsTlvKeySignature::SetTlv(void *data, uint32_t size, uint32_t *offset) /* uint32_t tlvend = *offset + tlvsize; if (size < tlvend) + { +#ifdef TLV_DEBUG + std::cerr << "RsTlvKeySignature::SetTlv() Fail, not enough space"; + std::cerr << std::endl; +#endif return false; /* not enough space */ + } bool ok = true; /* start at data[offset] */ /* add mandatory parts first */ - ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_SECURITYKEY, tlvsize); + ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_KEYSIGNATURE, tlvsize); ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_KEYID, keyId); ok &= signData.SetTlv(data, tlvend, offset); + if (!ok) + { +#ifdef TLV_DEBUG + std::cerr << "RsTlvKeySignature::SetTlv() Failed somewhere"; + std::cerr << std::endl; +#endif + } + return ok; } @@ -409,10 +456,22 @@ bool RsTlvKeySignature::GetTlv(void *data, uint32_t size, uint32_t *offset) /* uint32_t tlvend = *offset + tlvsize; if (size < tlvend) /* check size */ + { +#ifdef TLV_DEBUG + std::cerr << "RsTlvKeySignature::GetTlv() Not Enough Space"; + std::cerr << std::endl; +#endif return false; /* not enough space */ + } - if (tlvtype != TLV_TYPE_SECURITYKEY) /* check type */ + if (tlvtype != TLV_TYPE_KEYSIGNATURE) /* check type */ + { +#ifdef TLV_DEBUG + std::cerr << "RsTlvKeySignature::GetTlv() Type Fail"; + std::cerr << std::endl; +#endif return false; + } bool ok = true;