예제 #1
0
파일: NLPacket.cpp 프로젝트: CryptArc/hifi
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
파일: NLPacket.cpp 프로젝트: CryptArc/hifi
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
파일: NLPacket.cpp 프로젝트: CryptArc/hifi
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
파일: NLPacket.cpp 프로젝트: CryptArc/hifi
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
파일: NLPacket.cpp 프로젝트: CryptArc/hifi
PacketType NLPacket::typeInHeader(const udt::Packet& packet) {
    auto headerOffset = Packet::totalHeaderSize(packet.isPartOfMessage());
    return *reinterpret_cast<const PacketType*>(packet.getData() + headerOffset);
}