Protect git repository auth token with certificate from hardware token
- installed git
- certificate with private key on hardware token
- .NET Framework 4.7.1 or higher
- Visual Studio 2013 to build binary from sources
- Copy git-credential-cert.exe to C:\Program Files\Git\mingw64\libexec\git-core folder
- Specify git-credential-cert as git credential helper:
git config --global credential.helper cert
- Don't forget to delete your credentials from Windows Credential Manager and all other places where it is not in safe
For Visual Studio it is required to specify this helper in %USERPROFILE%\.gitconfig file
You can add it like this:
[credential]
helper=C:\\\\Program\\ Files\\\\Git\\\\mingw64\\\\libexec\\\\git-core\\\\git-credential-cert.exe
Generate certificate with private key for token encryption and signing credentials data in store:
makecert.exe -pe -r -a sha1 -len 2048 -n "CN=<specify here your own cert name>" -eku "1.3.6.1.5.5.7.3.4" -sky exchange -sv cert.pvk cert.cer
pvk2pfx.exe -pvk cert.pvk -spc cert.cer -pfx cert.pfx
Import certificate to hardware token using SafeNet Authentication Client or any other third-party software.
During import, choose pfx file and enter empty password for importing. Do not forget to delete private key from your disk.
git push
Git helper checks your database (%USERPROFILE%\git-credential-cert file), and if there are no existing credentials for current URL, it will ask for the username and password to store it.
git-credential-cert.exe list
git-credential-cert.exe delete <URL>
- delete helper:
del "C:\Program Files\Git\mingw64\libexec\git-core\git-credential-cert.exe"
- clear git-credential-cert.exe helper from %USERPROFILE%\.gitconfig
- specify your own or previous credential helper (f.e.)
git config --global credential.helper manager
- delete git-credential-cert encrypted database (if required):
del "%USERPROFILE%\\.git-credential-cert"
1.1. ✔ Incorrect method
1.2. ✔ Input has no key=value format
1.3. ✔ Input has unknown key
1.4. ✔ Store file corrupted - exception with stacktrace
1.5. ✔ Writing store file exception
2.1. ✔ Create new store, file does not exist
2.2. ✔ No certs with private key
2.3. ✔ Fail to encrypt (ejected token) - exception
2.4. ✔ Trying to add already existing url
3.1. ✔ There are no required parameters
3.2. ✔ Store has no credential for required url
3.3. ✔ Cert for signature and decryption not found
3.4. ✔ Cert for signature check exist, but have no private key for decryption
3.5. ✔ Incorrect signature
4.1. ✔ List credentials (URL + UserName + Cert.Subject + Cert.Thumbprint + Created DateTime)
5.1. ✔ Trying to remove not existing credentials
6.1. ✔ Trying to remove not existing credentials
6.2. ✔ No url specified
7.1. ✔ Working from Visual Studio Code
7.2. ✔ Working from Visual Studio
7.3. ✔ git token revocation (error + erase)