GithubHelp home page GithubHelp logo

Comments (8)

Crypt32 avatar Crypt32 commented on August 27, 2024

I'll take a look. I thought, relative paths should work by default.

from pspki.

Crypt32 avatar Crypt32 commented on August 27, 2024

Thread was not updated for a long time.

from pspki.

PatrickOnGit avatar PatrickOnGit commented on August 27, 2024

issue not solved.

from pspki.

Crypt32 avatar Crypt32 commented on August 27, 2024

I can't repro this. Here is what I get in my lab:

PS C:\Users\administrator.CONTOSO> dir *.req


    Directory: C:\Users\administrator.CONTOSO


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---       2015.10.15.     8:44        1612 req.req


PS C:\Users\administrator.CONTOSO> Get-CertificateRequest -path .\req.req


RequestType        : PKCS10
SubjectDn          : System.Security.Cryptography.X509Certificates.X500DistinguishedName
ExternalData       :
Version            : 1
SubjectName        : System.Security.Cryptography.X509Certificates.X500DistinguishedName
Subject            : CN=hostname, OU=IT, O=Company, L=City, S=California, C=US
PublicKey          : System.Security.Cryptography.X509Certificates.PublicKey
Extensions         : {2.5.29.15 (Key Usage), 2.5.29.37 (Enhanced Key Usage), 1.2.840.113549.1.9.15 (SMIME Capabilities)
                     , 2.5.29.14 (Subject Key Identifier)}
Attributes         : {0, 0, 0}
SignatureAlgorithm : 1.2.840.113549.1.1.5 (sha1RSA)
SignatureIsValid   : True
RawData            : {48, 130, 4, 85...}

from pspki.

PatrickOnGit avatar PatrickOnGit commented on August 27, 2024

from pspki.

PatrickOnGit avatar PatrickOnGit commented on August 27, 2024

Hello Vadims

I can reproduce the issue (See Windows and PowerShell Version information below).

PS C:\Users\Administrator> Get-Module pspki

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     3.4.1.0    PSPKI                               {Add-AdCertificate, Add-AdCertificateRevocationList, Add-AuthorityInformationA...


PS C:\Users\Administrator> ls *.req


    Directory: C:\Users\Administrator


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        07-Jun-19     23:39           7274 BSNB150-VMDC3-signed.req
-a----        11-Dec-18     17:46           1370 BSNB150-VMDC3.req
-a----        07-Jun-19     17:23           7274 BSNB150-VMDC3_signed.req


PS C:\Users\Administrator> Get-CertificateRequest .\BSNB150-VMDC3.req
New-Object : Exception calling ".ctor" with "1" argument(s): "The system cannot find the file specified"
At C:\Program Files\WindowsPowerShell\Modules\PSPKI\3.4.1.0\Client\Get-CertificateRequest.ps1:20 char:4
+             New-Object Security.Cryptography.X509CertificateRequests. ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

PS C:\Users\Administrator> Get-CertificateRequest C:\Users\Administrator\BSNB150-VMDC3.req


RequestType        : PKCS10
SubjectDn          : System.Security.Cryptography.X509Certificates.X500DistinguishedName
ExternalData       :
Version            : 1
SubjectName        : System.Security.Cryptography.X509Certificates.X500DistinguishedName
Subject            : CN=test.server.com
PublicKey          : System.Security.Cryptography.X509Certificates.PublicKey
Extensions         : {System.Security.Cryptography.Oid, System.Security.Cryptography.Oid, System.Security.Cryptography.Oid}
Attributes         : {0, 0, 0}
SignatureAlgorithm : System.Security.Cryptography.Oid
SignatureIsValid   : True
RawData            : {48, 130, 3, 164...}

The issue is in line 20:

New-Object Security.Cryptography.X509CertificateRequests.X509CertificateRequest -ArgumentList .\BSNB150-VMDC3.req

New-Object : Exception calling ".ctor" with "1" argument(s): "The system cannot find the file specified"
At line:1 char:1
+ New-Object Security.Cryptography.X509CertificateRequests.X509Certific ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

Changing it slightly using Resolve-Path (which works using relative and full paths, but may return more then one file using wildcards):

PS C:\Users\Administrator> New-Object Security.Cryptography.X509CertificateRequests.X509CertificateRequest -ArgumentList ( Resolve-Path .\BS
NB150-VMDC3.req )


RequestType        : PKCS10
SubjectDn          : System.Security.Cryptography.X509Certificates.X500DistinguishedName
ExternalData       :
Version            : 1
SubjectName        : System.Security.Cryptography.X509Certificates.X500DistinguishedName
Subject            : CN=test.server.com
PublicKey          : System.Security.Cryptography.X509Certificates.PublicKey
Extensions         : {System.Security.Cryptography.Oid, System.Security.Cryptography.Oid, System.Security.Cryptography.Oid}
Attributes         : {0, 0, 0}
SignatureAlgorithm : System.Security.Cryptography.Oid
SignatureIsValid   : True
RawData            : {48, 130, 3, 164...}

I tried on the following Windows / PowerShell Versions

PS C:\Users\Administrator> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14393.2969
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.2969
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

PS C:\Users\Administrator> Get-CimInstance CIM_OperatingSystem | Select Caption, Version, CodeSet,OSLanguage

Caption                                  Version    CodeSet OSLanguage
-------                                  -------    ------- ----------
Microsoft Windows Server 2016 Datacenter 10.0.14393 1252          1033

from pspki.

Crypt32 avatar Crypt32 commented on August 27, 2024

Ok, reopened the issue. It seems that PS no longer updates working directory for .NET classes. As the result if you switch current directory in PS console, then relative paths will stop working.

Can you confirm current working directory for .net: [Environment]::CurrentDirectory?
if you change PS location to this directory, do relative paths work for you?

from pspki.

PatrickOnGit avatar PatrickOnGit commented on August 27, 2024

Hello Vadims

You are right. the current .Net location is different than the current location I cd'd to.

PS C:\Users\Administrator> [Environment]::CurrentDirectory
C:\Windows\system32

When executing the command in C:\Windows\system32 and use a path relative to this, the command works.

PS C:\Windows\system32> Get-CertificateRequest  '..\..\Users\Administrator\BSNB150-VMDC3.req'


RequestType        : PKCS10
SubjectDn          : System.Security.Cryptography.X509Certificates.X500DistinguishedName
ExternalData       :
Version            : 1
SubjectName        : System.Security.Cryptography.X509Certificates.X500DistinguishedName
Subject            : CN=test.server.com
PublicKey          : System.Security.Cryptography.X509Certificates.PublicKey
Extensions         : {System.Security.Cryptography.Oid, System.Security.Cryptography.Oid, System.Security.Cryptography.Oid}
Attributes         : {0, 0, 0}
SignatureAlgorithm : System.Security.Cryptography.Oid
SignatureIsValid   : True
RawData            : {48, 130, 3, 164...}

What also works is adding $PWD in front of the relative path, but of course only if the path

PS C:\Users\Administrator> Get-CertificateRequest "$pwd\.\Users\Administrator\BSNB150-VMDC3.req"

But probably most reliant is always converting each path to full path using Resolve-Path

from pspki.

Related Issues (20)

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.