void MainWindow::msgCryptSetup(const MumbleProto::CryptSetup &msg) { ConnectionPtr c= g.sh->cConnection; if (! c) return; if (msg.has_key() && msg.has_client_nonce() && msg.has_server_nonce()) { const std::string &key = msg.key(); const std::string &client_nonce = msg.client_nonce(); const std::string &server_nonce = msg.server_nonce(); if (key.size() == AES_BLOCK_SIZE && client_nonce.size() == AES_BLOCK_SIZE && server_nonce.size() == AES_BLOCK_SIZE) c->csCrypt.setKey(reinterpret_cast<const unsigned char *>(key.data()), reinterpret_cast<const unsigned char *>(client_nonce.data()), reinterpret_cast<const unsigned char *>(server_nonce.data())); } else if (msg.has_server_nonce()) { const std::string &server_nonce = msg.server_nonce(); if (server_nonce.size() == AES_BLOCK_SIZE) { c->csCrypt.uiResync++; memcpy(c->csCrypt.decrypt_iv, server_nonce.data(), AES_BLOCK_SIZE); } } else { MumbleProto::CryptSetup mpcs; mpcs.set_client_nonce(std::string(reinterpret_cast<const char *>(c->csCrypt.encrypt_iv), AES_BLOCK_SIZE)); g.sh->sendMessage(mpcs); } }