| 547 | |
| 548 | |
| 549 | size_t Archive::ReadHeader50() |
| 550 | { |
| 551 | RawRead Raw(this); |
| 552 | |
| 553 | bool Decrypt=Encrypted && CurBlockPos>(int64)SFXSize+SIZEOF_MARKHEAD5; |
| 554 | |
| 555 | if (Decrypt) |
| 556 | { |
| 557 | #if defined(RAR_NOCRYPT) |
| 558 | return 0; |
| 559 | #else |
| 560 | |
| 561 | byte HeadersInitV[SIZE_INITV]; |
| 562 | if (Read(HeadersInitV,SIZE_INITV)!=SIZE_INITV) |
| 563 | { |
| 564 | UnexpEndArcMsg(); |
| 565 | return 0; |
| 566 | } |
| 567 | |
| 568 | // We repeat the password request only for manually entered passwords |
| 569 | // and not for -p<pwd>. Wrong password can be intentionally provided |
| 570 | // in -p<pwd> to not stop batch processing for encrypted archives. |
| 571 | bool GlobalPassword=Cmd->Password.IsSet() || uiIsGlobalPasswordSet(); |
| 572 | |
| 573 | while (true) // Repeat the password prompt for wrong passwords. |
| 574 | { |
| 575 | RequestArcPassword(); |
| 576 | |
| 577 | byte PswCheck[SIZE_PSWCHECK]; |
| 578 | HeadersCrypt.SetCryptKeys(false,CRYPT_RAR50,&Cmd->Password,CryptHead.Salt,HeadersInitV,CryptHead.Lg2Count,NULL,PswCheck); |
| 579 | // Verify password validity. |
| 580 | if (CryptHead.UsePswCheck && memcmp(PswCheck,CryptHead.PswCheck,SIZE_PSWCHECK)!=0) |
| 581 | { |
| 582 | if (GlobalPassword) // For -p<pwd> or Ctrl+P. |
| 583 | { |
| 584 | // This message is used by Android GUI to reset cached passwords. |
| 585 | // Update appropriate code if changed. |
| 586 | uiMsg(UIERROR_BADPSW,FileName,FileName); |
| 587 | FailedHeaderDecryption=true; |
| 588 | ErrHandler.SetErrorCode(RARX_BADPWD); |
| 589 | return 0; |
| 590 | } |
| 591 | else // For passwords entered manually. |
| 592 | { |
| 593 | // This message is used by Android GUI and Windows GUI and SFX to |
| 594 | // reset cached passwords. Update appropriate code if changed. |
| 595 | uiMsg(UIWAIT_BADPSW,FileName,FileName); |
| 596 | Cmd->Password.Clean(); |
| 597 | } |
| 598 | |
| 599 | #ifdef RARDLL |
| 600 | // Avoid new requests for unrar.dll to prevent the infinite loop |
| 601 | // if app always returns the same password. |
| 602 | ErrHandler.SetErrorCode(RARX_BADPWD); |
| 603 | Cmd->DllError=ERAR_BAD_PASSWORD; |
| 604 | ErrHandler.Exit(RARX_BADPWD); |
| 605 | #else |
| 606 | continue; // Request a password again. |
nothing calls this directly
no test coverage detected