示例#1
0
QByteArray NLPacket::hashForPacketAndSecret(const udt::Packet& packet, const QUuid& connectionSecret) {
    QCryptographicHash hash(QCryptographicHash::Md5);
    
    int offset = Packet::totalHeaderSize(packet.isPartOfMessage()) + sizeof(PacketType) + sizeof(PacketVersion)
        + NUM_BYTES_RFC4122_UUID + NUM_BYTES_MD5_HASH;
    
    // add the packet payload and the connection UUID
    hash.addData(packet.getData() + offset, packet.getDataSize() - offset);
    hash.addData(connectionSecret.toRfc4122());
    
    // return the hash
    return hash.result();
}
示例#2
0
bool IceServer::packetVersionMatch(const udt::Packet& packet) {
    PacketType headerType = NLPacket::typeInHeader(packet);
    PacketVersion headerVersion = NLPacket::versionInHeader(packet);
    
    if (headerVersion == versionForPacketType(headerType)) {
        return true;
    } else {
        qDebug() << "Packet version mismatch for packet" << headerType << " from" << packet.getSenderSockAddr();
        
        return false;
    }
}
示例#3
0
bool LimitedNodeList::packetVersionMatch(const udt::Packet& packet) {
    PacketType headerType = NLPacket::typeInHeader(packet);
    PacketVersion headerVersion = NLPacket::versionInHeader(packet);
    
    if (headerVersion != versionForPacketType(headerType)) {
        
        static QMultiHash<QUuid, PacketType> sourcedVersionDebugSuppressMap;
        static QMultiHash<HifiSockAddr, PacketType> versionDebugSuppressMap;
        
        bool hasBeenOutput = false;
        QString senderString;
        
        if (NON_SOURCED_PACKETS.contains(headerType)) {
            const HifiSockAddr& senderSockAddr = packet.getSenderSockAddr();
            hasBeenOutput = versionDebugSuppressMap.contains(senderSockAddr, headerType);
            
            if (!hasBeenOutput) {
                versionDebugSuppressMap.insert(senderSockAddr, headerType);
                senderString = QString("%1:%2").arg(senderSockAddr.getAddress().toString()).arg(senderSockAddr.getPort());
            }
        } else {
            QUuid sourceID = NLPacket::sourceIDInHeader(packet);
            
            hasBeenOutput = sourcedVersionDebugSuppressMap.contains(sourceID, headerType);
            
            if (!hasBeenOutput) {
                sourcedVersionDebugSuppressMap.insert(sourceID, headerType);
                senderString = uuidStringWithoutCurlyBraces(sourceID.toString());
            }
        }
        
        if (!hasBeenOutput) {
            qCDebug(networking) << "Packet version mismatch on" << headerType << "- Sender"
                << senderString << "sent" << qPrintable(QString::number(headerVersion)) << "but"
                << qPrintable(QString::number(versionForPacketType(headerType))) << "expected.";
            
            emit packetVersionMismatch(headerType);
        }
        
        return false;
    } else {
        return true;
    }
}
示例#4
0
QByteArray NLPacket::verificationHashInHeader(const udt::Packet& packet) {
    int offset = Packet::totalHeaderSize(packet.isPartOfMessage()) + sizeof(PacketType) + sizeof(PacketVersion) + NUM_BYTES_RFC4122_UUID;
    return QByteArray(packet.getData() + offset, NUM_BYTES_MD5_HASH);
}
示例#5
0
QUuid NLPacket::sourceIDInHeader(const udt::Packet& packet) {
    int offset = Packet::totalHeaderSize(packet.isPartOfMessage()) + sizeof(PacketType) + sizeof(PacketVersion);
    return QUuid::fromRfc4122(QByteArray::fromRawData(packet.getData() + offset, NUM_BYTES_RFC4122_UUID));
}
示例#6
0
PacketVersion NLPacket::versionInHeader(const udt::Packet& packet) {
    auto headerOffset = Packet::totalHeaderSize(packet.isPartOfMessage());
    return *reinterpret_cast<const PacketVersion*>(packet.getData() + headerOffset + sizeof(PacketType));
}
示例#7
0
PacketType NLPacket::typeInHeader(const udt::Packet& packet) {
    auto headerOffset = Packet::totalHeaderSize(packet.isPartOfMessage());
    return *reinterpret_cast<const PacketType*>(packet.getData() + headerOffset);
}