Beispiel #1
0
        public bool LoadAICHHashsetFromFile(Mpd.Generic.IO.FileDataIO pFile, bool bVerify)
        {
            m_aAICHPartHashSet.Clear();
            AICHHash masterHash =
                MuleApplication.Instance.AICHObjectManager.CreateAICHHash(pFile);

            if (HasAICHHash && masterHash != AICHHash)
            {
                return(false);
            }
            ushort nCount = pFile.ReadUInt16();

            for (int i = 0; i < nCount; i++)
            {
                m_aAICHPartHashSet.Add(MuleApplication.Instance.AICHObjectManager.CreateAICHHash(pFile));
            }
            if (bVerify)
            {
                return(VerifyAICHHashSet());
            }
            else
            {
                return(true);
            }
        }
Beispiel #2
0
        public AICHHash CreateAICHHash(Mpd.Generic.IO.FileDataIO fileInput)
        {
            AICHHash hash = CreateAICHHash();

            hash.Read(fileInput);

            return(hash);
        }
Beispiel #3
0
 public AICHHashImpl(AICHHash k)
     : this()
 {
     if (k != null)
     {
         Array.Copy(k.RawHash, byBuffer_, MuleConstants.HASHSIZE);
     }
 }
Beispiel #4
0
        public void WriteAICHHashsetToFile(Mpd.Generic.IO.FileDataIO pFile)
        {
            AICHHash.Write(pFile);
            int uParts = m_aAICHPartHashSet.Count;

            pFile.WriteUInt16((ushort)uParts);
            for (int i = 0; i < uParts; i++)
            {
                m_aAICHPartHashSet[i].Write(pFile);
            }
        }
Beispiel #5
0
        public bool ReadHashSetsFromPacket(Mpd.Generic.IO.FileDataIO pFile, ref bool rbMD4, ref bool rbAICH)
        {
            byte byOptions    = pFile.ReadUInt8();
            bool bMD4Present  = (byOptions & 0x01) > 0;
            bool bAICHPresent = (byOptions & 0x02) > 0;

            // We don't abort on unkown option, because even if there is another unknown hashset, there is no data afterwards we
            // try to read on the only occasion this function is used. So we might be able to add optional flags in the future
            // without having to adjust the protocol any further (new additional data/hashs should not be appended without adjustement however)

            if (bMD4Present && !rbMD4)
            {
                // Even if we don't want it, we still have to read the file to skip it
                byte[] tmpHash = new byte[16];
                pFile.ReadHash16(tmpHash);
                uint parts = pFile.ReadUInt16();
                for (uint i = 0; i < parts; i++)
                {
                    pFile.ReadHash16(tmpHash);
                }
            }
            else if (!bMD4Present)
            {
                rbMD4 = false;
            }
            else if (bMD4Present && rbMD4)
            {
                if (!LoadMD4HashsetFromFile(pFile, true))
                {       // corrupt
                    rbMD4  = false;
                    rbAICH = false;
                    return(false);
                }
            }

            if (bAICHPresent && !rbAICH)
            {
                // Even if we don't want it, we still have to read the file to skip it
                AICHHash tmpHash =
                    MuleApplication.Instance.AICHObjectManager.CreateAICHHash(pFile);
                ushort nCount = pFile.ReadUInt16();
                for (int i = 0; i < nCount; i++)
                {
                    tmpHash.Read(pFile);
                }
            }
            else if (!bAICHPresent || !HasAICHHash)
            {
                rbAICH = false;
            }
            else if (bAICHPresent && rbAICH)
            {
                if (!LoadAICHHashsetFromFile(pFile, true))
                {       // corrupt
                    if (rbMD4)
                    {
                        DeleteMD4Hashset();
                        rbMD4 = false;
                    }
                    rbAICH = false;
                    return(false);
                }
            }
            return(true);
        }
Beispiel #6
0
 public void SetMasterHash(AICHHash hash, AICHStatusEnum newStatus)
 {
 }
Beispiel #7
0
 public void UntrustedHashReceived(AICHHash Hash, uint dwFromIP)
 {
     return;
 }
Beispiel #8
0
 public void GetHash(AICHHash Hash)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Beispiel #9
0
        public bool VerifyHashTree(AICHHashAlgorithm hashalg, bool bDeleteBadTrees)
        {
            if (!HashValid)
            {
                if (bDeleteBadTrees)
                {
                    leftTree_  = null;
                    rightTree_ = null;
                }
                //TODO: Log
                //theApp.QueueDebugLogLine(/*DLP_HIGH,*/ false, _T("VerifyHashTree - No masterhash available"));
                return(false);
            }

            // calculated missing hashs without overwriting anything
            if (leftTree_ != null && !leftTree_.HashValid)
            {
                leftTree_.ReCalculateHash(hashalg, true);
            }
            if (rightTree_ != null && !rightTree_.HashValid)
            {
                rightTree_.ReCalculateHash(hashalg, true);
            }

            if ((rightTree_ != null && rightTree_.HashValid) ^ (leftTree_ != null && leftTree_.HashValid))
            {
                // one branch can never be verified
                if (bDeleteBadTrees)
                {
                    leftTree_  = null;
                    rightTree_ = null;
                }
                //TODO: Log
                //theApp.QueueDebugLogLine(/*DLP_HIGH,*/ false, _T("VerifyHashSet failed - Hashtree incomplete"));
                return(false);
            }
            if ((rightTree_ != null && rightTree_.HashValid) && (leftTree_ != null && leftTree_.HashValid))
            {
                // check verify the hashs of both child nodes against my hash

                AICHHash CmpHash = MuleApplication.Instance.AICHObjectManager.CreateAICHHash();
                hashalg.Reset();
                hashalg.Add(leftTree_.Hash.RawHash);
                hashalg.Add(rightTree_.Hash.RawHash);
                hashalg.Finish(CmpHash);

                if (!Hash.Equals(CmpHash))
                {
                    if (bDeleteBadTrees)
                    {
                        leftTree_  = null;
                        rightTree_ = null;
                    }

                    return(false);
                }
                return(leftTree_.VerifyHashTree(hashalg, bDeleteBadTrees) && rightTree_.VerifyHashTree(hashalg, bDeleteBadTrees));
            }
            else
            {
                // last hash in branch - nothing below to verify
                return(true);
            }
        }
Beispiel #10
0
        public bool SetHash(FileDataIO fileInput, uint wHashIdent, sbyte nLevel, bool bAllowOverwrite)
        {
            if (nLevel == -1)
            {
                // first call, check how many level we need to go
                byte i;
                for (i = 0; i != 32 && (wHashIdent & 0x80000000) == 0; i++)
                {
                    wHashIdent <<= 1;
                }

                if (i > 31)
                {
                    //TODO:Log
                    //theApp.QueueDebugLogLine(/*DLP_HIGH,*/ false, _T("CAICHHashTree::SetHash - found invalid HashIdent (0)"));
                    return(false);
                }
                else
                {
                    nLevel = (sbyte)(31 - i);
                }
            }
            if (nLevel == 0)
            {
                // this is the searched hash
                if (HashValid && !bAllowOverwrite)
                {
                    // not allowed to overwrite this hash, however move the filepointer by reading a hash
                    AICHHash hash = MuleApplication.Instance.AICHObjectManager.CreateAICHHash(fileInput);

                    return(true);
                }

                Hash.Read(fileInput);
                HashValid = true;
                return(true);
            }
            else if (DataSize <= BaseSize)
            { // sanity
              // this is already the last level, cant go deeper

                return(false);
            }
            else
            {
                // adjust ident to point the path to the next node
                wHashIdent <<= 1;
                nLevel--;
                ulong nBlocks = DataSize / BaseSize + ((DataSize % BaseSize != 0) ? (ulong)1 : (ulong)0);
                ulong nLeft   = (((IsLeftBranch) ? nBlocks + 1 : nBlocks) / 2) * BaseSize;
                ulong nRight  = DataSize - nLeft;
                if ((wHashIdent & 0x80000000) > 0)
                {
                    if (LeftTree == null)
                    {
                        LeftTree = MuleApplication.Instance.AICHObjectManager.CreateAICHHashTree(nLeft, true, (nLeft <= MuleConstants.PARTSIZE) ? MuleConstants.EMBLOCKSIZE : MuleConstants.PARTSIZE);
                    }
                    return(LeftTree.SetHash(fileInput, wHashIdent, nLevel));
                }
                else
                {
                    if (RightTree == null)
                    {
                        RightTree = MuleApplication.Instance.AICHObjectManager.CreateAICHHashTree(nRight, false, (nRight <= MuleConstants.PARTSIZE) ? MuleConstants.EMBLOCKSIZE : MuleConstants.PARTSIZE);
                    }
                    return(RightTree.SetHash(fileInput, wHashIdent, nLevel));
                }
            }
        }