GithubHelp home page GithubHelp logo

honzajscz / sninstallpfx Goto Github PK

View Code? Open in Web Editor NEW
30.0 30.0 9.0 58 KB

This utility is an alternative for command sn.exe -i <infile> <container> and installs key pair from <pfx_infile> into a key container compatible for MSBuild. It computes the container name automatically and accepts password as a command line argument.

License: MIT License

C# 100.00%

sninstallpfx's People

Contributors

honzajscz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sninstallpfx's Issues

CryptographicException thrown during RSACryptoServiceProvider ctor when container already created by another user

Running SnInstallPfx for a particular certificate in Jenkins yielded an exception with the following stack trace:

Unhandled Exception: System.Security.Cryptography.CryptographicException: Object already exists.

    at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
    at System.Security.Cryptography.Utils._CreateCSP(CspParameters param, Boolean randomKeyContainer, SafeProvHandle& hProv)
    at System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)
    at System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)
    at System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()
    at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters, Boolean useDefaultKeySize)
    at SnInstallPfx.SnInstallPfx.Main(String[] args)

After some digging, I realized that before finding & trying SnInstallPfx.exe, I'd logged into the server and created that container myself (which of course didn't help Jenkins, running under a different account). Logging back into the server and deleting my copy of the container solved the issue for me.

FYI, I'll ship you a PR regarding this very soon that simply catches the CryptographicException and provides a useful error message. There's likely something more elegant & useful to be done inside ResolveKeySourceTask.IsContainerInstalled. I'm not comfortable enough with keys & containers to attempt that myself, but I thought a minimal PR would be a better "thank you" for providing this tool than no PR at all.

Add to action marketplace

Hi thanks for making this tool!

Currently I use this in a GitHub action and manually download the .exe using Invoke-WebRequest https://github.com/honzajscz/SnInstallPfx/releases/download/0.1.2-beta/SnInstallPfx.exe -OutFile SnInstallPfx.exe in powershell. It would be convenient if this tool got added to the Action Marketplace, such that it can be easily added to a workflow.

dont work for me !

i used this to install my pfx certificat and still Cannot import the following key file: igakey.pfx. part of my dockerfile :

SHELL ["cmd", "/S", "/C"]
RUN powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; Invoke-WebRequest https://github.com/honzajscz/SnInstallPfx/releases/download/0.1.2-beta/SnInstallPfx.exe -OutFile SnInstallPfx.exe
RUN SnInstallPfx.exe ./DTOPrestation/igakey.pfx ***********
RUN SnInstallPfx.exe ./CommonDataV2/igaKey.pfx *********
RUN SnInstallPfx.exe ./SAGILEA_WEB/Resources/SagileaWeb.pfx *******
RUN SnInstallPfx.exe ./SEPAVirement/igaKey.pfx **********
RUN SnInstallPfx.exe ./Normes/DSN_Parametrage/DSN_ParamDAL/igaKey.pfx ********
SHELL ["powershell", "-Command"]

WORKDIR /inetpub/wwwroot/SAGILEA_WEB/WebApplication/
RUN msbuild ./WebApplication.csproj /property:Configuration=Release

Error :
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(3222,5): error MSB3325: Cannot import the following key file: igakey.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_1E532C4C0BA55C05 [C:\inetpub\wwwroot\DTOPrestation\DTOPrestation.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(3222,5): error MSB3321: Importing key file "igakey.pfx" was canceled. [C:\inetpub\wwwroot\DTOPrestation\DTOPrestation.csproj].................

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.