~ubuntu-branches/ubuntu/vivid/unrar-nonfree/vivid

« back to all changes in this revision

Viewing changes to secpassword.cpp

  • Committer: Package Import Robot
  • Author(s): Martin Meredith
  • Date: 2015-02-03 12:58:01 UTC
  • mfrom: (1.1.18) (5.1.18 sid)
  • Revision ID: package-import@ubuntu.com-20150203125801-od6ev8cqy1er51vz
Tags: 1:5.2.5-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
#ifndef CRYPTPROTECTMEMORY_BLOCK_SIZE
8
8
#define CRYPTPROTECTMEMORY_BLOCK_SIZE           16
9
9
#define CRYPTPROTECTMEMORY_SAME_PROCESS         0x00
 
10
#define CRYPTPROTECTMEMORY_CROSS_PROCESS        0x01
10
11
#endif
11
12
 
12
13
class CryptLoader
48
49
    CRYPTUNPROTECTMEMORY pCryptUnprotectMemory;
49
50
};
50
51
 
51
 
// We want to call FreeLibrary when RAR is exiting.
 
52
// We need to call FreeLibrary when RAR is exiting.
52
53
CryptLoader GlobalCryptLoader;
53
54
#endif
54
55
 
55
56
SecPassword::SecPassword()
56
57
{
 
58
  CrossProcess=false;
57
59
  Set(L"");
58
60
}
59
61
 
99
101
  // Source string can be shorter than destination as in case when we process
100
102
  // -p<pwd> parameter, so we need to take into account both sizes.
101
103
  memcpy(Dst,Src,Min(SrcSize,DstSize)*sizeof(*Dst));
102
 
  SecHideData(Dst,DstSize*sizeof(*Dst),Encode);
 
104
  SecHideData(Dst,DstSize*sizeof(*Dst),Encode,CrossProcess);
103
105
}
104
106
 
105
107
 
156
158
}
157
159
 
158
160
 
159
 
void SecHideData(void *Data,size_t DataSize,bool Encode)
 
161
void SecHideData(void *Data,size_t DataSize,bool Encode,bool CrossProcess)
160
162
{
161
163
#ifdef _WIN_ALL
162
164
  // Try to utilize the secure Crypt[Un]ProtectMemory if possible.
163
165
  if (GlobalCryptLoader.pCryptProtectMemory==NULL)
164
166
    GlobalCryptLoader.Load();
165
167
  size_t Aligned=DataSize-DataSize%CRYPTPROTECTMEMORY_BLOCK_SIZE;
 
168
  DWORD Flags=CrossProcess ? CRYPTPROTECTMEMORY_CROSS_PROCESS : CRYPTPROTECTMEMORY_SAME_PROCESS;
166
169
  if (Encode)
167
170
  {
168
171
    if (GlobalCryptLoader.pCryptProtectMemory!=NULL)
169
172
    {
170
 
      if (!GlobalCryptLoader.pCryptProtectMemory(Data,DWORD(Aligned),CRYPTPROTECTMEMORY_SAME_PROCESS))
 
173
      if (!GlobalCryptLoader.pCryptProtectMemory(Data,DWORD(Aligned),Flags))
171
174
      {
172
175
        ErrHandler.GeneralErrMsg(L"CryptProtectMemory failed");
173
176
        ErrHandler.SysErrMsg();
180
183
  {
181
184
    if (GlobalCryptLoader.pCryptUnprotectMemory!=NULL)
182
185
    {
183
 
      if (!GlobalCryptLoader.pCryptUnprotectMemory(Data,DWORD(Aligned),CRYPTPROTECTMEMORY_SAME_PROCESS))
 
186
      if (!GlobalCryptLoader.pCryptUnprotectMemory(Data,DWORD(Aligned),Flags))
184
187
      {
185
188
        ErrHandler.GeneralErrMsg(L"CryptUnprotectMemory failed");
186
189
        ErrHandler.SysErrMsg();