MCPcopy Create free account
hub / github.com/e2wugui/zeze / ProcessSHandshake

Method ProcessSHandshake

cxx/Net.cpp:246–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

244 }
245
246 int Service::ProcessSHandshake(Protocol* _p)
247 {
248 SHandshake* p = (SHandshake*)_p;
249
250 const int8_t* inputKey = nullptr;
251 int inputKeyLen = 0;
252 const int8_t* outputKey = nullptr;
253 int outputKeyLen = 0;
254 std::auto_ptr<limax::HmacMD5> outputHmacMD5;
255 std::auto_ptr<limax::HmacMD5> inputHmacMD5;
256
257 switch (p->Argument->encryptType)
258 {
259 case Constant::eEncryptTypeAes:
260 {
261 auto material = p->Sender->dhContext->computeDHKey(
262 (unsigned char*)p->Argument->encryptParam.data(), (int)p->Argument->encryptParam.size());
263
264 size_t key_len = p->Sender->LastAddressBytes.size();
265 int8_t* key = (int8_t*)p->Sender->LastAddressBytes.data();
266
267 int32_t half = (int32_t)material.size() / 2;
268 {
269 outputHmacMD5.reset(new limax::HmacMD5(key, 0, (int)key_len));
270 outputHmacMD5->update((int8_t*)&material[0], 0, half);
271 outputKey = outputHmacMD5->digest();
272 outputKeyLen = 16;
273 }
274 {
275 inputHmacMD5.reset(new limax::HmacMD5(key, 0, (int)key_len));
276 inputHmacMD5->update((int8_t*)&material[0], half, (int32_t)material.size() - half);
277 inputKey = inputHmacMD5->digest();
278 inputKeyLen = 16;
279 }
280 }
281 break;
282
283 case Constant::eEncryptTypeAesNoSecureIp:
284 {
285 // material 是const std::vector<unsigned char>&,不用释放。
286 auto material = p->Sender->dhContext->computeDHKey(
287 (unsigned char*)p->Argument->encryptParam.data(), (int)p->Argument->encryptParam.size());
288
289 int32_t half = (int32_t)material.size() / 2;
290 outputKey = (const int8_t*)&material[0];
291 outputKeyLen = half;
292 inputKey = (const int8_t*)&material[half];
293 inputKeyLen = (int)(material.size() - half);
294 }
295 break;
296 }
297 p->Sender->SetOutputSecurity(p->Argument->encryptType, outputKey, outputKeyLen, p->Argument->compressC2s);
298 p->Sender->SetInputSecurity(p->Argument->encryptType, inputKey, inputKeyLen, p->Argument->compressS2c);
299 CHandshakeDone done;
300 done.Send(p->Sender.get());
301 p->Sender->dhContext.reset();
302 OnHandshakeDone(p->Sender);
303 return 0;

Callers

nothing calls this directly

Calls 10

computeDHKeyMethod · 0.80
digestMethod · 0.80
SetOutputSecurityMethod · 0.80
SetInputSecurityMethod · 0.80
sizeMethod · 0.65
updateMethod · 0.65
getMethod · 0.65
OnHandshakeDoneFunction · 0.50
resetMethod · 0.45
SendMethod · 0.45

Tested by

no test coverage detected