...
authorVolker Birk <vb@pep-project.org>
Wed, 22 Jun 2016 09:01:21 +0200
changeset 116967ed8d930c1
parent 115 51ec60d88bd3
child 117 a0bb0649aae8
...
GateKeeper.cpp
GateKeeper.h
pEpCOMServerAdapter.vcxproj
     1.1 --- a/GateKeeper.cpp	Wed Jun 22 00:11:21 2016 +0200
     1.2 +++ b/GateKeeper.cpp	Wed Jun 22 09:01:21 2016 +0200
     1.3 @@ -15,7 +15,7 @@
     1.4      const DWORD GateKeeper::waiting = 10000; // 10000 ms is 10 sec
     1.5  
     1.6      GateKeeper::GateKeeper(CpEpCOMServerAdapterModule * const self)
     1.7 -        : _self(self), now(time(NULL)), next(now + time_diff()), hkUpdater(NULL), internet(NULL)
     1.8 +        : _self(self), now(time(NULL)), next(now + time_diff()), hkUpdater(NULL), internet(NULL), hAES(NULL), hRSA(NULL)
     1.9      {
    1.10          LONG lResult = RegOpenCurrentUser(KEY_READ, &cu);
    1.11          assert(lResult == ERROR_SUCCESS);
    1.12 @@ -82,7 +82,7 @@
    1.13          while (!_self->m_bComInitialized)
    1.14              Sleep(1);
    1.15  
    1.16 -        // MessageBox(NULL, _T("test"), _T("keep_plugin"), MB_ICONINFORMATION | MB_TOPMOST);
    1.17 +        MessageBox(NULL, _T("test"), _T("keep_plugin"), MB_ICONINFORMATION | MB_TOPMOST);
    1.18  
    1.19          DWORD value;
    1.20          DWORD size;
    1.21 @@ -119,7 +119,7 @@
    1.22          return key;
    1.23      }
    1.24  
    1.25 -    GateKeeper::aeskey_t GateKeeper::delivery_key()
    1.26 +    BCRYPT_KEY_HANDLE GateKeeper::delivery_key()
    1.27      {
    1.28          aeskey_t key;
    1.29  
    1.30 @@ -131,14 +131,20 @@
    1.31          key.qw_key[0] = dist(gen);
    1.32          key.qw_key[1] = dist(gen);
    1.33  
    1.34 -        return key;
    1.35 +        BCRYPT_KEY_HANDLE hKey;
    1.36 +        NTSTATUS status = BCryptGenerateSymmetricKey(hAES, &hKey, NULL, 0, (PUCHAR) &key, (ULONG) sizeof(aeskey_t), 0);
    1.37 +        assert(status == 0);
    1.38 +        if (status)
    1.39 +            throw runtime_error("BCryptGenerateSymmetricKey");
    1.40 +
    1.41 +        return hKey;
    1.42      }
    1.43  
    1.44 -    string GateKeeper::wrapped_delivery_key(aeskey_t key)
    1.45 +    string GateKeeper::wrapped_delivery_key(BCRYPT_KEY_HANDLE hKey)
    1.46      {
    1.47          string result;
    1.48  
    1.49 -        // ...
    1.50 +        BCRYPT_KEY_HANDLE hUpdateKey;
    1.51  
    1.52          return result;
    1.53      }
    1.54 @@ -185,7 +191,19 @@
    1.55      {
    1.56          return; // disabled for now
    1.57  
    1.58 +        NTSTATUS status = BCryptOpenAlgorithmProvider(&hAES, BCRYPT_AES_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0);
    1.59 +        assert(status == 0);
    1.60 +        if (status)
    1.61 +            goto closing;
    1.62 +
    1.63 +        status = BCryptOpenAlgorithmProvider(&hRSA, BCRYPT_RSA_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0);
    1.64 +        assert(status == 0);
    1.65 +        if (status)
    1.66 +            goto closing;
    1.67 +
    1.68          internet = InternetOpen(_T("pEp"), INTERNET_OPEN_TYPE_PROXY, NULL, NULL, 0);
    1.69 +        if (!internet)
    1.70 +            goto closing;
    1.71  
    1.72          product_list& products = registered_products();
    1.73          DWORD context = 0;
    1.74 @@ -193,8 +211,16 @@
    1.75              update_product(*i, context++);
    1.76          }
    1.77  
    1.78 -        InternetCloseHandle(internet);
    1.79 +    closing:
    1.80 +        if (internet)
    1.81 +            InternetCloseHandle(internet);
    1.82 +        if (hAES)
    1.83 +            BCryptCloseAlgorithmProvider(hAES, 0);
    1.84 +        if (hRSA)
    1.85 +            BCryptCloseAlgorithmProvider(hRSA, 0);
    1.86          internet = NULL;
    1.87 +        hAES = NULL;
    1.88 +        hRSA = NULL;
    1.89      }
    1.90  
    1.91  } // namespace pEp
     2.1 --- a/GateKeeper.h	Wed Jun 22 00:11:21 2016 +0200
     2.2 +++ b/GateKeeper.h	Wed Jun 22 09:01:21 2016 +0200
     2.3 @@ -44,8 +44,8 @@
     2.4          void keep_plugin();
     2.5  
     2.6          string update_key();
     2.7 -        aeskey_t delivery_key();
     2.8 -        string wrapped_delivery_key(aeskey_t key);
     2.9 +        BCRYPT_KEY_HANDLE delivery_key();
    2.10 +        string wrapped_delivery_key(BCRYPT_KEY_HANDLE key);
    2.11  
    2.12          void update_product(product p, DWORD context);
    2.13          product_list& registered_products();
    2.14 @@ -58,6 +58,8 @@
    2.15          HKEY cu;
    2.16          HKEY hkUpdater;
    2.17          HINTERNET internet;
    2.18 +        BCRYPT_ALG_HANDLE hAES;
    2.19 +        BCRYPT_ALG_HANDLE hRSA;
    2.20  
    2.21          CpEpCOMServerAdapterModule * _self;
    2.22      };
     3.1 --- a/pEpCOMServerAdapter.vcxproj	Wed Jun 22 00:11:21 2016 +0200
     3.2 +++ b/pEpCOMServerAdapter.vcxproj	Wed Jun 22 09:01:21 2016 +0200
     3.3 @@ -85,7 +85,7 @@
     3.4        <SubSystem>Windows</SubSystem>
     3.5        <GenerateDebugInformation>true</GenerateDebugInformation>
     3.6        <RegisterOutput>false</RegisterOutput>
     3.7 -      <AdditionalDependencies>comsuppwd.lib;%(AdditionalDependencies);Wininet.lib</AdditionalDependencies>
     3.8 +      <AdditionalDependencies>comsuppwd.lib;%(AdditionalDependencies);Wininet.lib;bcrypt.lib</AdditionalDependencies>
     3.9        <PerUserRedirection>true</PerUserRedirection>
    3.10      </Link>
    3.11    </ItemDefinitionGroup>
    3.12 @@ -120,7 +120,7 @@
    3.13        <EnableCOMDATFolding>true</EnableCOMDATFolding>
    3.14        <OptimizeReferences>true</OptimizeReferences>
    3.15        <RegisterOutput>true</RegisterOutput>
    3.16 -      <AdditionalDependencies>comsuppw.lib;%(AdditionalDependencies);Wininet.lib</AdditionalDependencies>
    3.17 +      <AdditionalDependencies>comsuppw.lib;%(AdditionalDependencies);Wininet.lib;bcrypt.lib</AdditionalDependencies>
    3.18      </Link>
    3.19    </ItemDefinitionGroup>
    3.20    <ItemGroup>