Ejemplo n.º 1
0
        public void Execute()
        {
            bool paddingOracleInput = PaddingOracleInput;

            Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate
            {
                pres.padInput(paddingOracleInput);
            }, paddingOracleInput);


            switch (curState)
            {
            case STATES.INITP1:
                //Change Description
                changePres(pres.descTask, Resources.descP1Init);

                //change btn description
                changePres(pres.btnNextLbl, Resources.btnLblP1Init);

                //Set Phase Header
                Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate
                {
                    pres.setPhase(1);
                }, null);

                //no real padding input = no picture!
                Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate
                {
                    pres.inPadValid.Visibility   = Visibility.Hidden;
                    pres.inPadInvalid.Visibility = Visibility.Hidden;
                }, null);

                //init padding length
                curPadLen = 0;

                //init cipher block input
                initCipherInput();

                //init presentation output
                string prelBlockValue   = arrToString(prelBlock);
                string cipherBlockValue = arrToString(cipherBlock);

                changePres(pres.inPrelBlock, prelBlockValue);
                changePres(pres.inCipherBlock, cipherBlockValue);

                changePres(pres.attDecBlock, getMultipleValue("??"));
                changePres(pres.attCorruptedBlock, prelBlockValue);
                changePres(pres.attOverlayBlock, getMultipleValue("00"));
                changePres(pres.attPlainBlock, getMultipleValue("??"));

                break;

            case STATES.PHASE1:         //find valid padding
                if (paddingOracleInput) //valid padding found
                {
                    //Change Description
                    changePres(pres.descTask, Resources.descP1Done);

                    //Change State
                    curState = STATES.INITP2;
                    retState = RETSTATES.PHASE1END;

                    //Switch to single clicks
                    runToNextPhase = false;


                    Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate
                    {
                        //deactivate run button
                        pres.btnRun.IsEnabled = false;

                        //change bordercolor of description
                        pres.changeBorderColor(true);
                    }, null);

                    //change btn description
                    changePres(pres.btnNextLbl, Resources.btnLblP1End);
                }
                else     //padding still invalid
                {
                    //change btn description
                    changePres(pres.descTask, Resources.descP1Task);

                    //change btn description
                    changePres(pres.btnNextLbl, Resources.btnLblP1);
                }

                break;

            case STATES.PHASE2:     //find padding length
                bool isFinished = false;

                if (bytePointer == blockSize - 2 && paddingOracleInput)   //if padding length is '01'
                {
                    isFinished = true;

                    //Set Padding Length
                    curPadLen     = 1;
                    curPadLenSave = curPadLen;

                    //update viewbytes
                    if (blockSize > 8)
                    {
                        firstViewBytePos = blockSize - 7;
                        updateScrollValue();
                    }

                    //Change Description
                    changePres(pres.descTask, Resources.descP2DoneSpecial);
                }
                else if (!paddingOracleInput)     //padding byte changed
                {
                    isFinished = true;

                    //Set Padding Length
                    curPadLen     = Convert.ToByte(blockSize - bytePointer);
                    curPadLenSave = curPadLen;

                    //Change Description
                    changePres(pres.descTask, Resources.descP2Done + curPadLen);
                }


                if (isFinished)     //(first) padding byte found
                {
                    //Change State
                    curState = STATES.INITP3;
                    retState = RETSTATES.PHASE2END;

                    //Switch to single clicks
                    runToNextPhase = false;


                    Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate
                    {
                        //deactivate run button
                        pres.btnRun.IsEnabled = false;

                        //change bordercolor of description
                        pres.changeBorderColor(true);
                    }, null);

                    //change btn description
                    changePres(pres.btnNextLbl, Resources.btnLblP2End);
                }
                else     //padding still invalid
                {
                    //activate run button
                    Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate
                    {
                        pres.btnRun.IsEnabled = true;
                    }, null);

                    //Change Description
                    changePres(pres.descTask, Resources.descP2Task);

                    //change btn description
                    changePres(pres.btnNextLbl, Resources.btnLblP2);

                    //ret state
                    retState = RETSTATES.PHASE2;
                }
                break;

            case STATES.PHASE3FIND:     //decrypt
                if (paddingOracleInput) //valid padding found
                {
                    //Change State
                    curState = STATES.PHASE3DEC;
                    retState = RETSTATES.PHASE3FINDEND;

                    if (!finishAll)
                    {
                        //Change Description
                        changePres(pres.descTask, Resources.descP3FindDone);

                        //deactivate run button
                        Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate
                        {
                            pres.btnRun.IsEnabled    = false;
                            pres.btnReturn.IsEnabled = false;
                        }, null);

                        //change btn description
                        changePres(pres.btnNextLbl, Resources.btnLblP3Decrypt);
                    }
                }
                else     //still looking for valid padding
                {
                    Boolean activateReturnBtn = true;
                    if (retState == RETSTATES.NR)
                    {
                        retState = RETSTATES.PHASE3INCPADDING;
                    }
                    else
                    {
                        retState          = RETSTATES.PHASE3FIND;
                        activateReturnBtn = false;
                    }

                    if (!finishAll)
                    {
                        //Change Description
                        changePres(pres.descTask, Resources.descP3FindTask);

                        //change btn description
                        changePres(pres.btnNextLbl, Resources.btnLblP3Find);

                        //activate run button
                        Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate
                        {
                            pres.btnRun.IsEnabled = true;
                            if (activateReturnBtn)
                            {
                                pres.btnReturn.IsEnabled = true;
                            }
                        }, null);
                    }
                }

                break;

            case STATES.ERROR:
                GuiLogMessage("An Error Occurred!", NotificationLevel.Error);
                break;
            }


            idle = false;
            if (runToNextPhase || finishAll)
            {
                ExecuteRound();
            }
            else
            {
                isClickActive = true;
            }
        }
Ejemplo n.º 2
0
        private void ExecuteRound() //invoked by click or Execute()
        {
            bool reRun = false;     //required for finish all

            do
            {
                reRun = false;
                switch (curState)
                {
                case STATES.INITP1:
                    //Set Byte Pointer
                    setBytePointer(blockSize - 1, true);

                    //Change Output
                    changePres(pres.outCorruptedBlock, arrToString(prelBlock));
                    changePres(pres.outCipherBlock, arrToString(cipherBlock));

                    //Change State
                    curState = STATES.PHASE1;
                    pres.btnReturn.IsEnabled = false;

                    //activate run button
                    pres.btnRun.IsEnabled = true;

                    //change decription border
                    pres.changeBorderColor(false);

                    //update viewbyte
                    firstViewBytePos = blockSize - 7;
                    updateScrollValue();

                    //Send Request
                    sendOracleRequest();

                    break;

                case STATES.PHASE1:     //find valid padding
                    setOverlayOld();
                    changeCurByte();
                    sendOracleRequest();
                    break;

                case STATES.INITP2:
                    //Change Description
                    changePres(pres.descTask, Resources.descP2Init);

                    //Set Phase Header
                    pres.setPhase(2);

                    //change decription border
                    pres.changeBorderColor(false);

                    //Set Byte Pointer
                    setBytePointer(-1, false);

                    //Change State
                    curState = STATES.PHASE2;
                    retState = RETSTATES.NR;
                    pres.btnReturn.IsEnabled = false;

                    //change btn description
                    changePres(pres.btnNextLbl, Resources.btnLblP2Init);

                    //update viewbyte
                    firstViewBytePos = 1;
                    updateScrollValue();

                    //no new padding input = no picture!
                    pres.inPadValid.Visibility = Visibility.Hidden;

                    requestsSentSave = requestsSent;

                    isClickActive = true;

                    break;

                case STATES.PHASE2:     //find padding length
                    //restore value of changed byte
                    if (bytePointer >= 0)
                    {
                        corruptedBlock[bytePointer] = prelBlock[bytePointer];
                        setOverlayOld();
                        overlayBlock[bytePointer] = 0;
                        changePres(pres.attOverlayBlock, arrToString(overlayBlock));
                    }
                    //Set Byte Pointer
                    setBytePointer(bytePointer + 1, true);

                    //update viewbyte
                    if (firstViewBytePos < bytePointer - 6)
                    {
                        firstViewBytePos = bytePointer - 6;
                        updateScrollValue();
                    }

                    //Send Request
                    setOverlayOld();
                    changeCurByte();
                    sendOracleRequest();

                    break;

                case STATES.INITP3:
                    //Change Description
                    changePres(pres.descTask, Resources.descP3Init);

                    //Set Phase Header
                    pres.setPhase(3);

                    //change decription border
                    pres.changeBorderColor(false);

                    //set padding in plaintext block
                    for (int padCounter = 0; padCounter < blockSize - 1; padCounter++)
                    {
                        if (padCounter < curPadLen)
                        {
                            plaintextBlock[blockSize - 1 - padCounter] = curPadLen;
                        }
                        else
                        {
                            plaintextBlock[blockSize - 1 - padCounter] = 0;
                        }
                    }
                    changePres(pres.attPlainBlock, arrToIncompleteString(plaintextBlock));

                    //restore value of prel byte where first pad byte was found
                    setOverlayOld();
                    overlayBlock[bytePointer]--;
                    overlayBlock[bytePointer]--;
                    changeCurByte();

                    //Set Byte Pointer; set to 7, because the last (padding) byte is decrypted first
                    setBytePointer(blockSize - 1, true);

                    //Change State
                    curState = STATES.PHASE3DEC;
                    pres.btnReturn.IsEnabled      = false;
                    pres.btnReturnPhase.IsEnabled = false;

                    //change btn description
                    changePres(pres.btnNextLbl, Resources.btnLblP3Decrypt);

                    //no new padding input = no picture!
                    pres.inPadInvalid.Visibility = Visibility.Hidden;
                    requestsSentSave             = requestsSent;

                    isClickActive = true;

                    break;

                case STATES.PHASE3DEC:
                    Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate
                    {
                        pres.btnReturn.IsEnabled = false;
                    }, null);

                    //Decrypt
                    decryptByte();

                    if (!finishAll)
                    {
                        //Change Description
                        changePres(pres.descTask, Resources.descP3Dec);

                        //Switch to single steps
                        runToNextPhase = false;
                    }

                    //Set Byte Pointer
                    setBytePointer(bytePointer - 1, true);

                    //update viewbyte
                    if (bytePointer < firstViewBytePos - 1)
                    {
                        if (bytePointer >= 1)
                        {
                            firstViewBytePos = bytePointer + 1;
                        }
                        updateScrollValue();
                    }

                    //Decide what to do next (end or go to next byte?)
                    if (bytePointer < 0)     //everything decrypted
                    {
                        changePres(pres.descTask, Resources.descP3Done);

                        setBytePointer(0, false);

                        //change btn description
                        changePres(pres.btnNextLbl, Resources.btnLblP3End);

                        Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate
                        {
                            pres.btnNext.IsEnabled   = true;
                            pres.btnRun.IsEnabled    = false;
                            pres.btnFinish.IsEnabled = false;
                        }, null);

                        curState = STATES.PHASE3PLAIN;
                    }
                    else if (bytesDecrypted >= curPadLen) //if all padding bytes have been decrypted
                    {
                        if (!paddingDecrypted)            //is run once, when padding is completely decrypted
                        {
                            changePres(pres.descTask, Resources.descP3DecPadDone);
                            paddingDecrypted = true;
                        }

                        if (finishAll)
                        {
                            reRun = true;
                        }
                        else
                        {
                            //change task description
                            changePres(pres.descTask, Resources.descP3DecDone);

                            //change btn description
                            changePres(pres.btnNextLbl, Resources.btnLblP3IncPad);
                        }


                        curState = STATES.PHASE3NEXT;
                    }

                    //no new padding input = no picture!
                    Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate
                    {
                        pres.inPadValid.Visibility = Visibility.Hidden;
                        isClickActive = true;
                    }, null);

                    break;

                case STATES.PHASE3NEXT:     //when padding is valid (new byte found)
                    //return state
                    retState = RETSTATES.NR;
                    Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate
                    {
                        pres.btnReturn.IsEnabled = true;
                    }, null);

                    increasePadding();
                    if (!finishAll)
                    {
                        Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate
                        {
                            pres.btnFinish.IsEnabled = true;
                        }, null);
                    }
                    curState = STATES.PHASE3FIND;
                    sendOracleRequest();

                    break;

                case STATES.PHASE3FIND:     //find valid padding
                    setOverlayOld();
                    changeCurByte();
                    sendOracleRequest();
                    break;

                case STATES.PHASE3PLAIN:
                    //changePres(pres.attCorruptedBlock, arrToString(prelBlock));
                    changePres(pres.attOverlayBlock, getMultipleValue("00"));

                    for (int byteCounter = 0; byteCounter < blockSize; byteCounter++)
                    {
                        plaintextBlock[byteCounter] = Convert.ToByte(prelBlock[byteCounter] ^ decryptedBlock[byteCounter]);
                        overlayBlock[byteCounter]   = 0;
                    }

                    changePres(pres.attPlainBlock, arrToString(plaintextBlock));

                    changePres(pres.descTask, Resources.descDone);
                    pres.btnNext.IsEnabled        = false;
                    pres.btnReturn.IsEnabled      = false;
                    pres.btnReturnPhase.IsEnabled = false;
                    pres.btnNextLbl.Content       = "";
                    pres.imgComplete.Visibility   = Visibility.Visible;

                    curState = STATES.END;

                    break;

                case STATES.ERROR:
                    pres.descTask.Text = "An error occurred. Any processing has been aborted.";
                    break;
                }
            } while (reRun);
        }
Ejemplo n.º 3
0
        public void PreExecution()
        {
            //init variables
            blockSize      = settings.BlockSize;
            curPadLen      = 0;
            bytesDecrypted = 0;
            setBytePointer(blockSize - 1, false);
            PaddingOracleInput = false;
            paddingDecrypted   = false;
            requestsSent       = 0;
            requestsSentSave   = 0;
            idle          = false;
            isClickActive = true;
            //firstViewBytePos = settings.ViewByte;
            firstViewBytePos = 1;

            //init blocks
            cipherBlock     = new byte[blockSize];
            prelBlock       = new byte[blockSize];
            corruptedBlock  = new byte[blockSize];
            overlayBlock    = new byte[blockSize];
            overlayBlockOld = new byte[blockSize];
            decryptedBlock  = new byte[blockSize];
            plaintextBlock  = new byte[blockSize];

            for (int i = 0; i < blockSize; i++)
            {
                decryptedBlock[i]  = 0;
                plaintextBlock[i]  = 0;
                overlayBlock[i]    = 0;
                overlayBlockOld[i] = 0;
            }

            changePres(pres.outCipherBlock, "");
            changePres(pres.outCorruptedBlock, "");
            changePres(pres.attDecBlock, "");
            changePres(pres.attCorruptedBlock, "");
            changePres(pres.attOverlayBlock, "");
            changePres(pres.attPlainBlock, "");

            //set workflow to single step
            runToNextPhase = false;
            finishAll      = false;

            //min value for viewbyte
            double minVal = Math.Min(18 - blockSize, 10);

            minVal /= 10;

            //change presentation
            Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate
            {
                pres.btnNext.IsEnabled        = true;
                pres.btnRun.IsEnabled         = false;
                pres.btnFinish.IsEnabled      = false;
                pres.btnReturn.IsEnabled      = false;
                pres.btnReturnPhase.IsEnabled = false;
                pres.imgComplete.Visibility   = Visibility.Hidden;

                pres.outCounter.Content = "0";

                pres.viewByteScroller.Minimum = minVal;
                pres.viewByteScroller.Value   = 1.0;
                pres.descShownBytes.Content   = "1...8";

                if (minVal == 1)
                {
                    pres.viewByteScroller.Visibility = Visibility.Hidden;
                    pres.viewBytePanel.Visibility    = Visibility.Hidden;
                }
            }, null);



            //init start state
            isInitialized = true;

            curState = STATES.INITP1;

            retState = RETSTATES.NR;
        }