Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added minimal CI + Signing section #503

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Build CI

on:
push:
branches: ["*"]
pull_request:
branches: ["*"]
workflow_dispatch:

env:
BUILD_CONFIG: RelWithDebInfo

jobs:
build:
strategy:
matrix:
include:
- shell_arch: x64
win_arch: x64
- shell_arch: x86
win_arch: x86
- shell_arch: amd64_arm64
win_arch: arm64
- shell_arch: amd64_arm
win_arch: arm

name: Build for ${{ matrix.win_arch }}
runs-on: windows-latest

steps:
- name: Get Sources
uses: actions/checkout@v3

- name: Setup shell
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.shell_arch }}

- name: Prepare build
run: cmake -B build -G "Ninja"

- name: Build
run: cmake --build build --config ${{env.BUILD_CONFIG}} -j 3

- name: Prepare files for upload
run: |
mkdir upload
mkdir upload/${{ matrix.win_arch }}

copy src/btrfs.inf upload
copy build/ubtrfs.dll upload/${{ matrix.win_arch }}
copy build/shellbtrfs.dll upload/${{ matrix.win_arch }}
copy build/mkbtrfs.exe upload/${{ matrix.win_arch }}
copy build/btrfs.sys upload/${{ matrix.win_arch }}

mkdir upload-pdb
mkdir upload-pdb/${{ matrix.win_arch }}

copy build/ubtrfs.pdb upload-pdb/${{ matrix.win_arch }}
copy build/shellbtrfs.pdb upload-pdb/${{ matrix.win_arch }}
copy build/mkbtrfs.pdb upload-pdb/${{ matrix.win_arch }}
copy build/btrfs.pdb upload-pdb/${{ matrix.win_arch }}
Comment on lines +47 to +62
Copy link

@brian6932 brian6932 Nov 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mkdir upload
mkdir upload/${{ matrix.win_arch }}
copy src/btrfs.inf upload
copy build/ubtrfs.dll upload/${{ matrix.win_arch }}
copy build/shellbtrfs.dll upload/${{ matrix.win_arch }}
copy build/mkbtrfs.exe upload/${{ matrix.win_arch }}
copy build/btrfs.sys upload/${{ matrix.win_arch }}
mkdir upload-pdb
mkdir upload-pdb/${{ matrix.win_arch }}
copy build/ubtrfs.pdb upload-pdb/${{ matrix.win_arch }}
copy build/shellbtrfs.pdb upload-pdb/${{ matrix.win_arch }}
copy build/mkbtrfs.pdb upload-pdb/${{ matrix.win_arch }}
copy build/btrfs.pdb upload-pdb/${{ matrix.win_arch }}
'', '/${{ matrix.win_arch }}', '-pdb', '-pdb/${{ matrix.win_arch }}' | ForEach-Object { New-Item -ItemType Directory "upload$_" }
'', '-vol' | ForEach-Object { Copy-Item "src/btrfs$_.inf" upload }
'ubtrfs.dll', 'shellbtrfs.dll', 'mkbtrfs.exe', 'btrfs.sys' | ForEach-Object {
Copy-Item "build/$_" upload/${{ matrix.win_arch }}
Copy-Item "build/$($_.Substring(0, $_.Length - 3))pdb" upload-pdb/${{ matrix.win_arch }}
}

Should be PowerShell (mkdir is not PowerShell), and should copy btrfs-vol.inf as well

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If your interest in this is because you are planning to run your own fork with different filename limits, do NOT do this. You will corrupt your filesystem when you use it on Linux, as even with the changes on that Russian site the kernel driver will overwrite other data with the long filename.

Copy link

@brian6932 brian6932 Nov 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah that's not my sole reason, I did try that. It didn't corrupt anything, but I did get a warning on Linux when running btrfs commands, renaming such paths removes any warnings, and just works.
My goal wasn't really to run a fork (branch is deleted now), but just to see if the CI worked, it didn't work well enough for me, so I learned how to do the signing manually.


- name: Upload driver files
uses: actions/upload-artifact@v3
with:
name: btrfs
path: upload/*

- name: Upload PDB files
uses: actions/upload-artifact@v3
with:
name: btrfs-pdb
path: upload-pdb/*

sign:
needs: build
runs-on: windows-latest
name: Sign

env:
INF2CAT_PROGRAM: 'C:/Program Files (x86)/Windows Kits/10/bin/x86/Inf2Cat.exe'

steps:
- name: Get Sources
uses: actions/checkout@v3

- name: Setup shell
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x86

- uses: actions/download-artifact@v3
with:
name: btrfs
path: upload

- name: Import key
run: |
# Create the PFX file from the base64-encoded secret
"${{ secrets.PFX_FILE_B64 }}" | Out-File -FilePath pfx.b64
CertUtil -decode pfx.b64 cert.pfx
# Import it
$plaintextpwd = "password"
$pwd = ConvertTo-SecureString -String $plaintextpwd -Force -AsPlainText
Import-PfxCertificate -FilePath ./cert.pfx -CertStoreLocation Cert:\CurrentUser\My -Password $pwd

- name: Create catalog file
run: |
cd upload
& "${{env.INF2CAT_PROGRAM}}" /os:10_NI_X64 /driver:.

- name: Sign catalog file
run: |
cd upload
SignTool sign /fd SHA256 /v /s My /n "Btrfs driver" /t http://timestamp.digicert.com btrfs.cat

- name: Upload driver
uses: actions/upload-artifact@v3
with:
name: btrfs
path: upload/*
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
out
.vs
build
build-*
88 changes: 88 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Build CI](https://github.com/maharmstone/btrfs/actions/workflows/build.yml/badge.svg)](https://github.com/maharmstone/btrfs/actions/workflows/build.yml)

WinBtrfs v1.8
-------------

Expand Down Expand Up @@ -137,12 +139,98 @@ Compilation

To compile with Visual C++ 2019, open the directory and let CMake do its thing.
If you have the Windows DDK installed correctly, it should just work.
Note: you need to use the Ninja generator for CMake, else the driver might not work once installed

To compile with GCC on Linux, you will need a cross-compiler set up, for either
`i686-w64-mingw32` or `x86_64-w64-mingw32`. Create a build directory, then use
either `mingw-x86.cmake` or `mingw-amd64.cmake` as CMake toolchain files to
generate your Makefile.

Signing
-----------

To install a built-from-source or a nightly (from github actions) driver, you need to sign it.
In this section, I will show how to disable driver signature enforcement, or how to sign the driver using test-signing.
Warning: both of these solutions aren't perfect, if you are looking for a everyday-use it is recommanded to use the release builds, which are signed with a Microsoft-trusted key.


## Disabling signature enforcement

Note: this isn't persistent accross reboots

Relevant link : https://docs.microsoft.com/en-us/windows-hardware/drivers/install/installing-an-unsigned-driver-during-development-and-test

### 1 - Reboot your computer without driver signature enforcement

(This can be done by pressing the 'Shift' key while rebooting the computer, this will take you to a special screen from which you can select "Troubleshoot" -> "Startup settings" -> "Disable driver signature enforcement")

### 2 - Install the driver

Open the previously downloaded artifact from Github Actions (or mimic the directory structure and fill it with the binaries you just compiled), right-click the btrfs.inf file -> install

A window saying "Microsoft can't verify the publisher of this driver" should pop-up. Click "Install anyway"

If the window didn't show up, the driver probably wasn't installed, make sure you booted your computer with driver signature enforcement disabled.

The computer should next tell you to reboot your computer

### 3 - Reboot the computer again without driver signature enforcement

Follow the same instructions as step 1

### 4 - Done !

The driver should now be installed ! Note it will only load when the computer is started without driver signature enforcement



## Test-signing the driver

Note: This method is harder to put in place, and has the only benefit of persisting after reboots.

Example commands are given for each steps but it is recommand to check the microsoft documentation link about test-signing, so you know what you are doing

Relevant link: https://docs.microsoft.com/en-us/windows-hardware/drivers/install/test-signing

### 1 - Put your computer in test mode

test-signing doesn't seem to work with Windows by default. You will need to put your computer in a special mode to allow test-signing.

`bcdedit /set testsigning on`

Note: you might need to disable Secure Boot for this to work

### 2 - Generate a MakeCert certificate

This certificate will be used to sign the catalog file of the driver

`makecert -r -pe -ss PrivateCertStore -n CN=Contoso.com(Test) ContosoTest.cer`

### 3 - Install the certificate to your system

For your certificate to be effective, it needs to be installed in the "Trusted Root Certification Authorities" certificate store of the computer you want to install the driver on.
You can add it by launching "CertMgr" **as administrator**, selecting the "Trusted Root Certification Authorities" certificate store, and importing the .cer file generated earlier
(The command given on the documentation doesn't seem to work and just launches the CertMgr GUI)

### 4 - Generate a catalog file for your driver

You will need the "Inf2Cat" tool, installed as part of the WDK.
Run the command in the same directory as your btrfs.inf file (or modify the /driver flag)

The command will differ in your case (because of the path) but here is the one I used :

`"C:\Program Files (x86)\Windows Kits\10\bin\x86\Inf2Cat.exe" /os:10_NI_X64 /driver:.`

Note: this was tested in Windows 11, you might need to change the values of the /os flag according to your Windows version

### 5 - Sign the catalog file

Simply sign the catalog file of the driver with the certificate you generated

`SignTool sign /fd SHA256 /v /s PrivateCertStore /n contoso.com(test) /t http://timestamp.digicert.com btrfs.cat`

Only steps 4-5 needs to be done again to sign a new build of the driver

Mappings
--------

Expand Down
2 changes: 1 addition & 1 deletion src/btrfs.inf
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ mkbtrfs.exe = 1,,
1 = %DiskId1%,,,\arm

[SourceDisksNames.arm64]
1 = %DiskId1%,,,\aarch64
1 = %DiskId1%,,,\arm64

;;
;; String Section
Expand Down