Skip to content

Commit d87ad12

Browse files
feat: Rewrite Windows components in Rust (#26)
BREAKING CHANGE: The file location and interface of the Windows component are updated, though it was not intended to be used by end users. Co-authored-by: Takaya Saeki <abc.tkys+pub@gmail.com>
1 parent 0fd2c6d commit d87ad12

File tree

29 files changed

+446
-883
lines changed

29 files changed

+446
-883
lines changed

.github/workflows/cicd.yaml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,41 +58,37 @@ jobs:
5858
path: build/pam_wsl_hello.so
5959
if-no-files-found: error
6060

61-
build-windows-binaries:
62-
name: "Build Windows binaries"
61+
build-windows-binary:
62+
name: "Build Windows binary"
6363

6464
runs-on: windows-latest
6565

6666
steps:
6767
- uses: actions/checkout@v2
6868

69-
- name: Add msbuild to PATH
70-
uses: microsoft/setup-msbuild@v1.0.2
71-
7269
- name: Build
73-
run: make clean all
74-
working-directory: win_components
70+
run: make clean build/WindowsHelloBridge.exe
7571

7672
- uses: actions/upload-artifact@v2
7773
name: Upload artifacts
7874
with:
79-
name: "Windows Binaries"
80-
path: win_components/build/
75+
name: "Windows Binary"
76+
path: build/WindowsHelloBridge.exe
8177
if-no-files-found: error
8278

8379
release:
8480
name: "Release"
8581

8682
runs-on: ubuntu-latest
8783

88-
needs: [build-pam-module, build-windows-binaries]
84+
needs: [build-pam-module, build-windows-binary]
8985

9086
steps:
9187
- uses: actions/checkout@v2
9288

9389
- uses: actions/download-artifact@v2
9490
with:
95-
name: "Windows Binaries"
91+
name: "Windows Binary"
9692
path: build
9793

9894
- uses: actions/download-artifact@v2
@@ -106,7 +102,7 @@ jobs:
106102
uses: TriPSs/conventional-changelog-action@v3
107103
with:
108104
github-token: ${{ secrets.github_token }}
109-
version-file: Cargo.toml
105+
version-file: ./wsl_hello_pam/Cargo.toml,./win_hello_bridge/Cargo.toml
110106
version-path: package.version
111107
skip-on-empty: false
112108
git-user-name: "github-actions[bot]"

Cargo.lock

Lines changed: 72 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
[package]
2-
name = "wsl_hello_pam"
3-
version = "1.4.0"
4-
authors = ["Takaya Saeki <abc.tkys+pub@gmail.com>"]
5-
6-
[lib]
7-
name = "pam_wsl_hello"
8-
crate-type = ["dylib"]
9-
10-
[dependencies]
11-
libc = "0.2.0"
12-
openssl = "0.10.29"
13-
toml = "0.4"
14-
uuid = { version = "0.5", features = ["v4"] }
15-
16-
[profile.release]
17-
lto = true
1+
[workspace]
2+
3+
members = [
4+
"win_hello_bridge",
5+
"wsl_hello_pam",
6+
]
7+
8+
[profile.release]
9+
lto = true

Makefile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
RELEASE := release
22

3+
WIN_CARGO="cargo.exe"
4+
35
.PHONY: all clean cleanall cleanrelease install release lint
46

5-
all: build/pam_wsl_hello.so\
6-
build/WindowsHelloAuthenticator/WindowsHelloAuthenticator.exe\
7-
build/WindowsHelloKeyCredentialCreator/WindowsHelloKeyCredentialCreator.exe
7+
all: build/pam_wsl_hello.so build/WindowsHelloBridge.exe
88

99
build/pam_wsl_hello.so: | build
10-
cargo build --release
10+
# Build the PAM lib from Linux
11+
cargo build --release -p wsl_hello_pam
1112
strip target/release/libpam_wsl_hello.so
1213
cp ./target/release/libpam_wsl_hello.so build/pam_wsl_hello.so
1314

14-
build/WindowsHelloAuthenticator/WindowsHelloAuthenticator.exe build/WindowsHelloKeyCredentialCreator/WindowsHelloKeyCredentialCreator.exe: | build
15-
$(MAKE) -C win_components all
16-
cp -R win_components/build/* build/
15+
build/WindowsHelloBridge.exe: | build
16+
# Build the authenticator from Windows
17+
$(WIN_CARGO) build -p win_hello_bridge --release
18+
strip target/release/WindowsHelloBridge.exe
19+
cp ./target/release/WindowsHelloBridge.exe ./build
1720

1821
build:
1922
mkdir -p build
@@ -22,7 +25,6 @@ clean:
2225
cargo clean
2326

2427
cleanall: clean
25-
$(MAKE) -C win_components clean
2628

2729
cleanrelease: cleanall
2830
rm -rf build

README.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ biometric login of [Windows Hello](https://www.microsoft.com/en-us/windows/windo
55
This PAM module allows you to authenticate `sudo` via face recognition, fingerprint authentication, and of couse machine-local PIN.
66
It runs in both WSL and WSL 2.
77

8-
The Linux PAM module is written in Rust, and Windows CLI apps are written in C#.
8+
Both the Linux PAM module and Windows CLI app are written in Rust.
99
Please use it at your own risk. There is no warranty.
1010

1111
![demo](https://github.com/nullpo-head/WSL-Hello-sudo/blob/master/demo.gif)
@@ -31,7 +31,7 @@ $ ./install.sh
3131
Although you don't have to care about the detailed installation process,
3232
`install.sh` does following things.
3333

34-
1. Copy small Windows CLI apps that launch Windows Hello to `C:\Users\your_account\pam_wsl_hello` (default location)
34+
1. Copy a small Windows CLI app that launches Windows Hello to `C:\Users\your_account\pam_wsl_hello` (default location)
3535
2. Install a PAM module to your WSL system.
3636
3. Create config files in `/etc/pam_wsl_hello/`
3737
4. Create a pam-configs entry in `/usr/share/pam-configs/` for automatic PAM configuration
@@ -90,23 +90,16 @@ auth sufficient pam_wsl_hello.so
9090

9191
## Build
9292

93-
The Linux PAM module of "WSL Hello sudo" is written in Rust, and the Windows CLI apps are written in C#.
94-
So, `cargo` and Visual Studio are required to build it.
93+
Both the Linux PAM module and the Windows CLI apps of "WSL Hello sudo" are written in Rust.
94+
So, only `cargo` is required to build it.
9595

96-
Before building "WSL Hello sudo", add the path to `MSBuild.exe` to `PATH` environment variable of __`bash` on WSL__, not Windows.
97-
If you build Windows CLI apps with your Visual Studio GUI, you can ignore that.
98-
In my environment, MSBuild lives in `/mnt/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/`
99-
100-
To build "WSL Hello sudo", just run `make`.
96+
To build "WSL Hello sudo", make sure you're in WSL and then just run `make`.
10197

10298
```ShellSession
10399
$ git clone https://github.com/nullpo-head/WSL-Hello-sudo.git
104100
$ cd WSL-Hello-sudo
105101
$ make
106102
```
107-
It invokes `cargo` and `MSBuild.exe` properly.
108-
109-
> Whether you're using `bash` or Windows, the repository must be in the Windows filesystem, otherwise `MSBuild.exe` won't work.
110103

111104
## Internals
112105

@@ -121,4 +114,3 @@ So, the PAM module authenticates the given Linux user by the following process.
121114
3. Windows Hello makes a signature of the given input by the private key of the current Windows user
122115
4. The companion Windows app returns the signature
123116
5. The PAM module verifies the signature by the public key of the Windows user who corresponds to the given Linux user.
124-

install.sh

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ if [ "$(whoami)" = "root" ]; then
3737
exit 1
3838
fi
3939
if [ ! -e build/pam_wsl_hello.so ] || \
40-
[ ! -e build/WindowsHelloAuthenticator/WindowsHelloAuthenticator.exe ] || \
41-
[ ! -e build/WindowsHelloKeyCredentialCreator/WindowsHelloKeyCredentialCreator.exe ]; then
40+
[ ! -e build/WindowsHelloBridge.exe ]; then
4241
echo "No built binary was found. Build first before installing."
4342
exit 1
4443
fi
@@ -60,26 +59,40 @@ if [[ ! -e "${MNT}" ]]; then
6059
echo -n ": "
6160
read -r MNT
6261
fi
62+
6363
WINUSER=$("${MNT}/Windows/System32/cmd.exe" /C "echo | set /p dummy=%username%") # Hacky. Get Windows's user name without new line
64-
DEF_PAM_WSL_HELLO_WINPATH="${MNT}/Users/$WINUSER/pam_wsl_hello"
65-
echo "Input the install location for Windows Hello authentication components."
66-
echo "They are Windows .exe files and required to be in a valid Windows directory"
64+
DEF_PAM_WSL_HELLO_WINPATH="${MNT}/Users/$WINUSER/AppData/Local/Programs/wsl-hello-sudo"
65+
OLD_DEF_PAM_WSL_HELLO_WINPATH="${MNT}/Users/$WINUSER/pam_wsl_hello"
66+
67+
echo "Input the install location for Windows Hello authentication component."
68+
echo "It is a Windows .exe file and required to be in a valid Windows directory"
6769
echo -n "Default [${DEF_PAM_WSL_HELLO_WINPATH}] :"
6870
read -r PAM_WSL_HELLO_WINPATH
71+
6972
if [ -z "$PAM_WSL_HELLO_WINPATH" ]; then
7073
PAM_WSL_HELLO_WINPATH=$DEF_PAM_WSL_HELLO_WINPATH
7174
fi
75+
7276
if [ ! -e "$PAM_WSL_HELLO_WINPATH" ]; then
7377
if prompt_yn "'$PAM_WSL_HELLO_WINPATH' does not exist. Create it? [Y/n]" "y"; then
7478
set -x
7579
mkdir -p "$PAM_WSL_HELLO_WINPATH"
7680
fi
7781
fi
82+
83+
MAYBE_OLD_KEY_PATH="$OLD_DEF_PAM_WSL_HELLO_WINPATH/pam_wsl_hello_$USER.pem"
84+
KEY_PATH="$PAM_WSL_HELLO_WINPATH/pam_wsl_hello_$USER.pem"
85+
if [ -f "$MAYBE_OLD_KEY_PATH" ]; then
86+
echo "Migrating existing key identity"
87+
mv "$MAYBE_OLD_KEY_PATH" "$KEY_PATH"
88+
rm -r "$OLD_DEF_PAM_WSL_HELLO_WINPATH"
89+
fi
90+
7891
set +x
79-
echo_stage "Installing Windows components of WSL-Hello-sudo..."
92+
echo_stage "Installing Windows component of WSL-Hello-sudo..."
8093
set -x
81-
cp -r build/{WindowsHelloAuthenticator,WindowsHelloKeyCredentialCreator} "$PAM_WSL_HELLO_WINPATH/"
82-
find "$PAM_WSL_HELLO_WINPATH/" -name "*.exe" -print0 | xargs -0 chmod +x
94+
cp build/WindowsHelloBridge.exe "$PAM_WSL_HELLO_WINPATH/"
95+
chmod +x "$PAM_WSL_HELLO_WINPATH/WindowsHelloBridge.exe"
8396

8497
set +x
8598
echo_stage "Installing PAM module to the Linux system..."
@@ -134,24 +147,30 @@ fi
134147
echo_stage "Creating the config files of WSL-Hello-sudo..."
135148
set -x
136149
sudo mkdir -p /etc/pam_wsl_hello/
150+
PAM_CONFIG_FILENAME="/etc/pam_wsl_hello/config"
151+
AUTHENTICATOR_PATH="authenticator_path = \"$PAM_WSL_HELLO_WINPATH/WindowsHelloBridge.exe\""
152+
137153
set +x
138-
if [ ! -e "/etc/pam_wsl_hello/config" ] || prompt_yn "'/etc/pam_wsl_hello/config' already exists. Overwrite it? [y/N]" "n" ; then
154+
if [ ! -e "$PAM_CONFIG_FILENAME" ] || prompt_yn "'$PAM_CONFIG_FILENAME' already exists. Overwrite it? [y/N]" "n" ; then
139155
set -x
140156
sudo touch /etc/pam_wsl_hello/config
141-
sudo echo "authenticator_path = \"$PAM_WSL_HELLO_WINPATH/WindowsHelloAuthenticator/WindowsHelloAuthenticator.exe\"" | sudo tee /etc/pam_wsl_hello/config
157+
sudo echo "$AUTHENTICATOR_PATH" | sudo tee "$PAM_CONFIG_FILENAME"
142158
sudo echo "win_mnt = \"$MNT\"" | sudo tee -a /etc/pam_wsl_hello/config
159+
elif grep -q "WindowsHelloAuthenticator" "$PAM_CONFIG_FILENAME" ; then
160+
echo "Migrating PAM config to v2.0"
161+
sudo sed -i "1s;authenticator_path.*;$AUTHENTICATOR_PATH;" "$PAM_CONFIG_FILENAME"
143162
else
144163
echo "Skipping creation of '/etc/pam_wsl_hello/config'..."
145164
fi
146165
set +x
147166
echo "Please authenticate yourself now to create a credential for '$USER' and '$WINUSER' pair."
148-
KEY_ALREADY_EXIST_ERR=170
167+
KEY_ALREADY_EXIST_ERR=171
149168
set -x
150169
pushd "$PAM_WSL_HELLO_WINPATH"
151-
WindowsHelloKeyCredentialCreator/WindowsHelloKeyCredentialCreator.exe "pam_wsl_hello_$USER" || test $? = $KEY_ALREADY_EXIST_ERR
170+
./WindowsHelloBridge.exe creator "pam_wsl_hello_$USER" || test $? = $KEY_ALREADY_EXIST_ERR
152171
sudo mkdir -p /etc/pam_wsl_hello/public_keys
153172
popd
154-
sudo cp "$PAM_WSL_HELLO_WINPATH/pam_wsl_hello_$USER.pem" /etc/pam_wsl_hello/public_keys/
173+
sudo cp "$KEY_PATH" /etc/pam_wsl_hello/public_keys/
155174

156175
set +x
157176
echo_stage "Creating uninstall.sh..."

0 commit comments

Comments
 (0)