jaraco / jaraco/keyring

Proposal: add WSL backend via windows executable

Open
#622 6 comments 0 reactions 0 assignees View on GitHub
enhancement help wanted Linux Windows
Dominant language
Python
Stars
1.5k
Forks
196
PR merge metrics
No merged PRs in 30d

Description

Don't worry, this is not the 4th request to access windows APIs from Linux ;-)
I want to pinch the following idea, and I'm also willing to give it a try myself if it's worthwhile.

In case python is running on WSL, we usually have quite some trouble installing/running any other reasonable backend. We also don't have (simple) access to windows APIs.
However what we have is access to windows executables!

Now all we need is an executable which can access the credential store for us.
Microsoft provides one (`cmdkey`), but for whatever reason it does not read passwords :(

For the sake of argument let's say we have python with pywin32 installed.

store test_pass:
```
/mnt/c/Users/lla2hi$ /mnt/c/Program\ Files\ \(x86\)/Python39-32/python.exe -c "import pywintypes; import win32cred; win32cred.CredWrite({'Type':win32cred.CRED_TYPE_GENERIC, 'TargetName':'test_service', 'UserName':'test_user', 'CredentialBlob':'test_pass', 'Comment':'Stored using python-keyring', 'Persist':win32cred.CRED_PERSIST_ENTERPRISE}, 0);"
```

retrieve test_pass:
```
/mnt/c/Program\ Files\ \(x86\)/Python39-32/python.exe -c "import win32cred; print(win32cred.CredRead(Type=win32cred.CRED_TYPE_GENERIC, TargetName='test_service')['Credential
Blob'].decode('utf-16'));"
test_pass
```

We can easily do that from our WSL python by starting a subprocess!

Maybe there is a better windows executable than python.exe with pywin32 installed...
When I try the same with powershell it asks for a password.
I do not understand yet why it's fine from python, but from powershell I need to authenticate.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing the WSL scenario and the Python subprocess examples using python.exe, pywin32, and PowerShell. Determine the supported Windows executable approach for reading and writing credentials from WSL; done means the proposed backend can access the Windows credential store without requiring the unavailable Linux backend or manual authentication.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell, python
Domain
security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.