Skip to content

Commit 1f477c3

Browse files
authored
Merge pull request #3 from dorssel/signed_installer
signed installer
2 parents 3324af3 + d778f03 commit 1f477c3

13 files changed

+110
-48
lines changed

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ indent_style = space
99
[*.{cs,csx,vb,vbx}]
1010
indent_size = 4
1111
insert_final_newline = true
12+
trim_trailing_whitespace = true
1213
charset = utf-8-bom
1314
[*.{wxs,xslt}]
1415
indent_size = 4
1516
insert_final_newline = true
17+
trim_trailing_whitespace = true
1618
charset = utf-8-bom
1719
###############################
1820
# .NET Coding Conventions #

Installer/Installer.wixproj

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@
4040
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
4141
<DefineConstants>Debug;PublishDir=$(PublishDir);DriversDir=$(ProjectDir)..\Drivers;ProductId=$(ProductId)</DefineConstants>
4242
<Cultures>en-US</Cultures>
43+
<SuppressAllWarnings>False</SuppressAllWarnings>
44+
<Pedantic>True</Pedantic>
4345
</PropertyGroup>
4446
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
4547
<OutputPath>bin\$(Configuration)\</OutputPath>
4648
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
4749
<DefineConstants>PublishDir=$(PublishDir);DriversDir=$(ProjectDir)..\Drivers;ProductId=$(ProductId)</DefineConstants>
4850
<Cultures>en-US</Cultures>
51+
<SuppressAllWarnings>False</SuppressAllWarnings>
52+
<Pedantic>True</Pedantic>
4953
</PropertyGroup>
5054
<ItemGroup>
5155
<Compile Include="Drivers.wxs" />
@@ -83,20 +87,17 @@
8387
</WixExtension>
8488
</ItemGroup>
8589
<ItemGroup>
86-
<!--
87-
Solution Explorer gives a (benign) warning for PackageReference in wixproj files.
88-
-->
89-
<PackageReference Include="GitVersionTask" Version="5.3.7" Visible="false">
90+
<PackageReference Include="GitVersionTask" Version="5.5.0" Visible="false">
9091
<PrivateAssets>all</PrivateAssets>
9192
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
9293
</PackageReference>
93-
<PackageReference Include="WiX" Version="3.*" Visible="false" />
94+
<PackageReference Include="WiX" Version="3.11.2" Visible="false" />
9495
</ItemGroup>
9596
<Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" />
9697
<Import Project="$(WixTargetsPath)" Condition=" '$(WixTargetsPath)' != '' " />
9798
<ImportGroup Condition=" '$(BuildingInsideVisualStudio)' == 'true' ">
98-
<Import Project="$(NuGetPackageRoot)gitversiontask\5.3.7\build\GitVersionTask.props" />
99-
<Import Project="$(NuGetPackageRoot)gitversiontask\5.3.7\build\GitVersionTask.targets" />
99+
<Import Project="$(NuGetPackageRoot)gitversiontask\5.5.0\build\GitVersionTask.props" />
100+
<Import Project="$(NuGetPackageRoot)gitversiontask\5.5.0\build\GitVersionTask.targets" />
100101
</ImportGroup>
101102
<Target Name="EnsureWixToolsetInstalled" AfterTargets="BeforeBuild" />
102103
<Target Name="SetTarget" AfterTargets="GetVersion">

Installer/Product.wxs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
<Package InstallerVersion="500" Compressed="yes" InstallScope="perMachine" />
2929

3030
<?ifdef Debug ?>
31-
<MediaTemplate EmbedCab="yes" CompressionLevel="none" />
31+
<MediaTemplate EmbedCab="yes" CompressionLevel="none" />
3232
<?else?>
33-
<MediaTemplate EmbedCab="yes" CompressionLevel="high" />
33+
<MediaTemplate EmbedCab="yes" CompressionLevel="high" />
3434
<?endif?>
3535

3636
<!--
@@ -48,7 +48,7 @@
4848
<Property Id="ARPURLINFOABOUT">https://github.com/dorssel/usbipd-win</Property>
4949
<Property Id="ARPURLUPDATEINFO">https://github.com/dorssel/usbipd-win/releases</Property>
5050
<Property Id="ARPHELPLINK">https://github.com/dorssel/usbipd-win/issues</Property>
51-
51+
5252
<Feature
5353
Id="Server"
5454
Level="1"

Installer/UserInterface.wxs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
<Fragment>
2121
<WixVariable Id="WixUILicenseRtf" Value="COPYING.rtf" />
2222
<UI Id="UserInterface">
23-
<UIRef Id="UI_Minimal" />
23+
<UIRef Id="UI_Minimal" />
2424
</UI>
2525
</Fragment>
2626

2727
<Fragment>
2828
<UI Id="UI_Minimal">
29-
<UIRef Id="WixUI_Minimal" />
29+
<UIRef Id="WixUI_Minimal" />
3030
</UI>
3131
</Fragment>
3232

@@ -51,10 +51,10 @@
5151
<!--
5252
BUG: Cost calculation is wrong for x64 installs (also for WixUI_FeatureTree). There is no known workaround.
5353
-->
54-
54+
5555
<UI Id="UI_Advanced">
5656
<UIRef Id="WixUI_Advanced" />
5757
<UIRef Id="WixUI_ErrorProgressText" />
5858
</UI>
59-
</Fragment>
59+
</Fragment>
6060
</Wix>

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,32 @@
22

33
Windows software for hosting locally connected USB devices to other machines, including Hyper-V guests.
44

5-
## How to use (ignoring caveats)
5+
## How to use
6+
7+
This software requires Microsoft Windows 8 / Microsoft Windows Server 2012 or newer;
8+
it does not depend on any other software.
69

710
1) Run the installer (.msi) on the Windows machine where your USB device is connected.
811
2) From another (possibly virtual) machine running Linux, use `usbip` to claim the USB device.
912

10-
If you find that your device does not work, first read *caveats* below. Please file an issue if you think your device should work with the current release.
13+
If you find that your device does not work, first read *limitations* below.
14+
Please file an issue if you think your device should work with the current release.
1115

1216
## How to remove
1317

14-
Uninstall via Add/Remove Programs or via Settings/Apps. There should be no left-overs, but if you do find any: please file an issue.
18+
Uninstall via Add/Remove Programs or via Settings/Apps.
19+
There should be no left-overs, but if you do find any: please file an issue.
1520

16-
## The caveats...
21+
## Limitations
1722

1823
- For now, only USB devices with so called *bulk* endpoints work (USB flash drives, FTDI USB-to-serial, etc.).
19-
- **No security** restrictions on who claims which device. Unlike Linux `usbipd`, this software (for now) exposes all available USB devices to all other computers on you local subnet.
20-
- The software is not digitally signed (yet), so you will get some nasty warnings about untrusted software. For the paranoid: review the code and build it yourself (this is open source after all...). Consider to become a sponsor so I can afford a software signing certificate.
2124

22-
## Some details on how it works
25+
## How it works
26+
27+
The software glues together the UsbIp network protocol (as implemented by the Linux kernel) and the USB drivers.
28+
The installer includes the USB drivers from VirtualBox, which are also licensed under GPL and are properly signed by Oracle.
29+
This *should* play nice with a coexisting full installation of VirtualBox, but that has not been tested extensively.
30+
31+
The software itself consists of an auto-start background service.
2332

24-
The software glues together the UsbIp network protocol as implemented by the Linux kernel and the VirtualBox USB drivers. The installer includes the VirtualBox drivers (which fortunately are also licensed under GPL), so you may get popups about Oracle software. This *should* play nice with a coexisting full installation of VirtualBox, but that has not been tested extensively. The software itself consists of an auto-start background service, but for debugging purposes it can be run in a console window instead. The service logs to the EventLog. The installer also adds a firewall rule to allow all local subnets to connect to the application.
33+
The installer also adds a firewall rule to allow all local subnets to connect to the service; this firewall rule can be tweaked to fine tune access control.

UsbIpServer/ConnectedClient.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ async Task HandleRequestImportAsync(CancellationToken cancellationToken)
125125
}
126126
catch
127127
{
128+
#pragma warning disable CA1508 // Avoid dead conditional code (false possitive)
128129
if (status != Status.ST_OK)
130+
#pragma warning restore CA1508 // Avoid dead conditional code
129131
{
130132
await SendOpCodeAsync(OpCode.OP_REP_IMPORT, status);
131133
}
@@ -142,7 +144,7 @@ async Task<OpCode> RecvOpCodeAsync(CancellationToken cancellationToken)
142144
var version = BinaryPrimitives.ReadUInt16BigEndian(buf.AsSpan(0));
143145
if (version != USBIP_VERSION)
144146
{
145-
throw new ProtocolViolationException($"version mismatch: expected 1.11, got {version >> 8}.{version & 0xff}");
147+
throw new ProtocolViolationException($"version mismatch: expected {USBIP_VERSION >> 8}.{USBIP_VERSION & 0xff}, got {version >> 8}.{version & 0xff}");
146148
}
147149

148150
var opCode = (OpCode)BinaryPrimitives.ReadUInt16BigEndian(buf.AsSpan(2));

UsbIpServer/DeviceFile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public DeviceFile(string fileName)
4141
if (!ThreadPool.BindHandle(handle))
4242
{
4343
handle.Dispose();
44-
throw new SystemException("BindHandle failed");
44+
throw new UnexpectedResultException("ThreadPool.BindHandle() failed");
4545
}
4646
}
4747

@@ -69,7 +69,7 @@ void OnCompletion(uint errorCode, uint numBytes, NativeOverlapped* nativeOverlap
6969
}
7070
else
7171
{
72-
taskCompletionSource.SetException(new SystemException($"DeviceIoControl returned error {(Win32Error)errorCode}"));
72+
taskCompletionSource.SetException(new Win32Exception((int)errorCode, $"DeviceIoControl returned error {(Win32Error)errorCode}"));
7373
}
7474
Overlapped.Free(nativeOverlapped);
7575
}

UsbIpServer/Interop/VBoxUsb.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ public struct UsbSupGetDev
140140
/// <summary>VBoxUsb: usb.h: USBDEVICESTATE</summary>
141141
public enum UsbDeviceState : uint
142142
{
143-
UNSUPPORTED = 1,
143+
INVALID = 0,
144+
UNSUPPORTED,
144145
USED_BY_HOST,
145146
USED_BY_HOST_CAPTURABLE,
146147
UNUSED,
@@ -241,7 +242,7 @@ public enum UsbSupDirection : uint
241242
public enum UsbSupXferFlags : uint
242243
{
243244
USBSUP_FLAG_NONE = 0,
244-
USBSUP_FLAG_SHORT_OK = (1 << 0),
245+
USBSUP_FLAG_SHORT_OK = 1 << 0,
245246
}
246247

247248
/// <summary>VBoxUsb: usblib-win.h: USBSUP_ERROR</summary>

UsbIpServer/Interop/WinSDK.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public enum Win32Error : uint
4545
public enum FileFlags : uint
4646
{
4747
/// <summary>WinSDK: WinBase.h</summary>
48-
FILE_FLAG_OVERLAPPED = (1 << 30),
48+
FILE_FLAG_OVERLAPPED = 1 << 30,
4949
}
5050

5151
/// <summary>WinSDK: devpropdev.h: DEVPROPTYPE</summary>
@@ -62,19 +62,19 @@ public enum DevPropType : uint
6262
public enum DiGetClassFlags : uint
6363
{
6464
/// <summary>WinSDK: SetupAPI.h</summary>
65-
DIGCF_DEFAULT = (1 << 0),
65+
DIGCF_DEFAULT = 1 << 0,
6666

6767
/// <summary>WinSDK: SetupAPI.h</summary>
68-
DIGCF_PRESENT = (1 << 1),
68+
DIGCF_PRESENT = 1 << 1,
6969

7070
/// <summary>WinSDK: SetupAPI.h</summary>
71-
DIGCF_ALLCLASSES = (1 << 2),
71+
DIGCF_ALLCLASSES = 1 << 2,
7272

7373
/// <summary>WinSDK: SetupAPI.h</summary>
74-
DIGCF_PROFILE = (1 << 3),
74+
DIGCF_PROFILE = 1 << 3,
7575

7676
/// <summary>WinSDK: SetupAPI.h</summary>
77-
DIGCF_DEVICEINTERFACE = (1 << 4),
77+
DIGCF_DEVICEINTERFACE = 1 << 4,
7878
}
7979

8080
/// <summary>WinSDK: devpropdev.h: DEVPROPKEY</summary>
@@ -136,43 +136,53 @@ public struct SpDevInfoData
136136
public static class NativeMethods
137137
{
138138
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
139+
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
139140
public static extern SafeFileHandle CreateFile(string lpFileName, [MarshalAs(UnmanagedType.U4)] FileAccess dwDesiredAccess,
140141
[MarshalAs(UnmanagedType.U4)] FileShare dwShareMode, IntPtr lpSecurityAttributes, [MarshalAs(UnmanagedType.U4)] FileMode dwCreationDisposition,
141142
[MarshalAs(UnmanagedType.U4)] FileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile);
142143

143144
[DllImport("kernel32.dll", SetLastError = true)]
145+
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
144146
public static extern bool DeviceIoControl(SafeFileHandle hDevice, uint ioControlCode, IntPtr inBuffer, uint nInBufferSize,
145147
IntPtr outBuffer, uint nOutBufferSize, out uint pBytesReturned, IntPtr overlapped);
146148

147149
[DllImport("setupapi.dll", SetLastError = true)]
150+
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
148151
public static extern bool SetupDiDestroyDeviceInfoList(IntPtr DeviceInfoSet);
149152

150153
[DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Unicode)]
154+
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
151155
public static extern SafeDeviceInfoSetHandle SetupDiGetClassDevs(IntPtr ClassGuid, [MarshalAs(UnmanagedType.LPWStr)] string? Enumerator,
152156
IntPtr hwndParent, DiGetClassFlags Flags);
153157

154158
[DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Unicode)]
159+
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
155160
public static extern SafeDeviceInfoSetHandle SetupDiGetClassDevs(in Guid ClassGuid, [MarshalAs(UnmanagedType.LPWStr)] string? Enumerator,
156161
IntPtr hwndParent, DiGetClassFlags Flags);
157162

158163
[DllImport("setupapi.dll", SetLastError = true)]
164+
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
159165
public static extern bool SetupDiEnumDeviceInfo(SafeDeviceInfoSetHandle DeviceInfoSet, uint MemberIndex, ref SpDevInfoData DeviceInfoData);
160166

161167
[DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Unicode)]
168+
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
162169
public static extern bool SetupDiGetDeviceProperty(SafeDeviceInfoSetHandle DeviceInfoSet, in SpDevInfoData DeviceInfoData,
163170
in DevPropKey PropertyKey, [MarshalAs(UnmanagedType.U4)] out DevPropType PropertyType,
164171
byte[]? PropertyBuffer, uint PropertyBufferSize, out uint RequiredSize, uint Flags);
165172

166173
[DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Unicode)]
174+
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
167175
public static extern bool SetupDiGetDeviceProperty(SafeDeviceInfoSetHandle DeviceInfoSet, in SpDevInfoData DeviceInfoData,
168176
in DevPropKey PropertyKey, [MarshalAs(UnmanagedType.U4)] out DevPropType PropertyType,
169177
byte[]? PropertyBuffer, uint PropertyBufferSize, IntPtr RequiredSize, uint Flags);
170178

171179
[DllImport("setupapi.dll", SetLastError = true)]
180+
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
172181
public static extern bool SetupDiEnumDeviceInterfaces(SafeDeviceInfoSetHandle hDevInfo, IntPtr devInfo,
173182
in Guid interfaceClassGuid, uint memberIndex, ref SpDeviceInterfaceData deviceInterfaceData);
174183

175184
[DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
185+
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
176186
public static extern bool SetupDiGetDeviceInterfaceDetail(
177187
SafeDeviceInfoSetHandle hDevInfo, in SpDeviceInterfaceData DeviceInterfaceData, byte[]? DeviceInterfaceDetailData, uint DeviceInterfaceDetailDataSize,
178188
out uint RequiredSize, IntPtr DeviceInfoData);

0 commit comments

Comments
 (0)