| 194 | } |
| 195 | |
| 196 | void DatagramDestination::HandleDatagram2 (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len, |
| 197 | i2p::garlic::ECIESX25519AEADRatchetSession * from) |
| 198 | { |
| 199 | if (len < 433) |
| 200 | { |
| 201 | LogPrint (eLogWarning, "Datagram: datagram2 is too short ", len); |
| 202 | return; |
| 203 | } |
| 204 | i2p::data::IdentityEx identity; |
| 205 | size_t identityLen = identity.FromBuffer (buf, len); |
| 206 | if (!identityLen) return; |
| 207 | size_t signatureLen = identity.GetSignatureLen (); |
| 208 | if (signatureLen + identityLen > len) return; |
| 209 | |
| 210 | std::shared_ptr<i2p::data::LeaseSet> ls; |
| 211 | bool verified = false; |
| 212 | if (from) |
| 213 | { |
| 214 | ls = m_Owner->FindLeaseSet (identity.GetIdentHash ()); |
| 215 | if (ls) |
| 216 | { |
| 217 | uint8_t staticKey[32]; |
| 218 | ls->Encrypt (nullptr, staticKey); |
| 219 | if (!memcmp (from->GetRemoteStaticKey (), staticKey, 32)) |
| 220 | verified = true; |
| 221 | else |
| 222 | { |
| 223 | LogPrint (eLogError, "Datagram: Remote LeaseSet static key mismatch for datagram2 from ", |
| 224 | identity.GetIdentHash ().ToBase32 ()); |
| 225 | return; |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | const uint8_t * flags = buf + identityLen; |
| 230 | size_t offset = identityLen + 2; |
| 231 | bool isOptions = false; |
| 232 | if (flags[1] & DATAGRAM2_FLAG_OPTIONS) |
| 233 | { |
| 234 | isOptions = true; |
| 235 | m_Options.CleanUp (); |
| 236 | auto optionsLen = m_Options.FromBuffer (buf + offset, len - offset); |
| 237 | if (optionsLen) |
| 238 | offset += optionsLen; |
| 239 | else |
| 240 | { |
| 241 | LogPrint (eLogWarning, "Datagram: datagram2 can't read options"); |
| 242 | return; |
| 243 | } |
| 244 | } |
| 245 | if (offset > len) |
| 246 | { |
| 247 | LogPrint (eLogWarning, "Datagram: datagram2 is too short ", len, " expected ", offset); |
| 248 | return; |
| 249 | } |
| 250 | if (!verified) |
| 251 | { |
| 252 | std::shared_ptr<i2p::crypto::Verifier> transientVerifier; |
| 253 | if (flags[1] & DATAGRAM2_FLAG_OFFLINE_SIGNATURE) |
nothing calls this directly
no test coverage detected