@@ -1126,6 +1126,8 @@ SelectDriver(
11261126 WCHAR CatPath [MAX_PATH ] = { 0 };
11271127 WCHAR SysPath [MAX_PATH ] = { 0 };
11281128 WCHAR InfPath [MAX_PATH ] = { 0 };
1129+ WCHAR DownlevelShimPath [MAX_PATH ] = { 0 };
1130+
11291131 if (!PathCombineW (CatPath , RandomTempSubDirectory , L"wintun.cat" ) ||
11301132 !PathCombineW (SysPath , RandomTempSubDirectory , L"wintun.sys" ) ||
11311133 !PathCombineW (InfPath , RandomTempSubDirectory , L"wintun.inf" ))
@@ -1141,6 +1143,53 @@ SelectDriver(
11411143 LastError = LOG_LAST_ERROR (L"Failed to extract driver" );
11421144 goto cleanupDelete ;
11431145 }
1146+
1147+ WCHAR * WintrustKeyOriginalValue = NULL ;
1148+ HKEY WintrustKey = NULL ;
1149+ if (!IsWindows10 )
1150+ {
1151+ LOG (WINTUN_LOG_INFO , L"Shimming downlevel driver loader" );
1152+ if (!PathCombineW (DownlevelShimPath , RandomTempSubDirectory , L"downlevelshim.dll" ))
1153+ {
1154+ DownlevelShimPath [0 ] = L'\0' ;
1155+ LastError = ERROR_BUFFER_OVERFLOW ;
1156+ goto cleanupDelete ;
1157+ }
1158+ if (!ResourceCopyToFile (DownlevelShimPath , L"downlevelshim.dll" ))
1159+ {
1160+ LastError = LOG_LAST_ERROR (L"Failed to extract downlevel shim" );
1161+ goto cleanupDelete ;
1162+ }
1163+ LastError = RegOpenKeyExW (
1164+ HKEY_LOCAL_MACHINE ,
1165+ L"SOFTWARE\\Microsoft\\Cryptography\\Providers\\Trust\\FinalPolicy\\{F750E6C3-38EE-11D1-85E5-00C04FC295EE}" ,
1166+ 0 ,
1167+ KEY_QUERY_VALUE | KEY_SET_VALUE ,
1168+ & WintrustKey );
1169+ if (LastError != ERROR_SUCCESS )
1170+ {
1171+ LOG_ERROR (LastError , L"Failed to open Wintrust FinalPolicy key" );
1172+ goto cleanupDelete ;
1173+ }
1174+ WintrustKeyOriginalValue = RegistryQueryString (WintrustKey , L"$DLL" , TRUE);
1175+ if (!WintrustKeyOriginalValue )
1176+ {
1177+ LastError = LOG_LAST_ERROR (L"Failed to read current Wintrust FinalPolicy key" );
1178+ goto cleanupWintrustKey ;
1179+ }
1180+ LastError = RegSetValueExW (
1181+ WintrustKey ,
1182+ L"$DLL" ,
1183+ 0 ,
1184+ REG_SZ ,
1185+ (BYTE * )DownlevelShimPath ,
1186+ (DWORD )((wcslen (DownlevelShimPath ) + 1 ) * sizeof (DownlevelShimPath [0 ])));
1187+ if (LastError != ERROR_SUCCESS )
1188+ {
1189+ LOG_ERROR (LastError , L"Failed to set Wintrust FinalPolicy key" );
1190+ goto cleanupWintrustChangedKey ;
1191+ }
1192+ }
11441193 LOG (WINTUN_LOG_INFO , L"Installing driver" );
11451194 WCHAR InfStorePath [MAX_PATH ];
11461195 if (!SetupCopyOEMInfW (InfPath , NULL , SPOST_NONE , 0 , InfStorePath , MAX_PATH , NULL , NULL ))
@@ -1185,10 +1234,26 @@ SelectDriver(
11851234 LastError = ERROR_SUCCESS ;
11861235 DestroyDriverInfoListOnCleanup = FALSE;
11871236
1237+ cleanupWintrustChangedKey :
1238+ if (WintrustKeyOriginalValue )
1239+ RegSetValueExW (
1240+ WintrustKey ,
1241+ L"$DLL" ,
1242+ 0 ,
1243+ REG_SZ ,
1244+ (BYTE * )WintrustKeyOriginalValue ,
1245+ (DWORD )((wcslen (WintrustKeyOriginalValue + 1 ) * sizeof (WintrustKeyOriginalValue [0 ]))));
1246+ cleanupWintrustKey :
1247+ if (WintrustKey )
1248+ RegCloseKey (WintrustKey );
1249+ if (WintrustKeyOriginalValue )
1250+ Free (WintrustKeyOriginalValue );
11881251cleanupDelete :
11891252 DeleteFileW (CatPath );
11901253 DeleteFileW (SysPath );
11911254 DeleteFileW (InfPath );
1255+ if (DownlevelShimPath [0 ])
1256+ DeleteFileW (DownlevelShimPath );
11921257cleanupDirectory :
11931258 RemoveDirectoryW (RandomTempSubDirectory );
11941259cleanupExistingAdapters :
0 commit comments