8000 Keysize not extracted from Certificate.PublicKey.Key.Keysize · Issue #17643 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content
Keysize not extracted from Certificate.PublicKey.Key.Keysize #17643
@b-olesen

Description

@b-olesen

Prerequisites

Steps to reproduce

I am expecting Keysize to be present, but only on Mac 7.1.4 it works, on Linux I haven't been able to. Tested with a couple of versions (7.1.3, 7.1.6, 7.2.5)

Code executed :

$url = "https://www.vmware.com"

$today = Get-Date
if ($PSEdition -eq 'Core'){

$Code = @'
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

namespace CertificateCapture
{
public class Utility
{
public static Func<HttpRequestMessage,X509Certificate2,X509Chain,SslPolicyErrors,Boolean> ValidationCallback =
(message, cert, chain, errors) => {
var newCert = new X509Certificate2(cert);
var newChain = new X509Chain();
newChain.Build(newCert);
CapturedCertificates.Add(new CapturedCertificate(){
Certificate = newCert,
CertificateChain = newChain,
PolicyErrors = errors,
URI = message.RequestUri
});
return true;
};
public static List CapturedCertificates = new List();
}

public class CapturedCertificate 
{
    public X509Certificate2 Certificate { get; set; }
    public X509Chain CertificateChain { get; set; }
    public SslPolicyErrors PolicyErrors { get; set; }
    public Uri URI { get; set; }
}

}
'@

            if (-not ("CertificateCapture.Utility" -as [Type])) { Add-Type $Code }

            $Certs = [CertificateCapture.Utility]::CapturedCertificates

            $Handler = [System.Net.Http.HttpClientHandler]::new()
            $Handler.ServerCertificateCustomValidationCallback = [CertificateCapture.Utility]::ValidationCallback
            $Client = [System.Net.Http.HttpClient]::new($Handler)
            $Result = $Client.GetAsync($Url).Result

            $sha256 = [Security.Cryptography.SHA256]::Create()
            $certBytes = $Certs[-1].Certificate.GetRawCertData()
            $hash = $sha256.ComputeHash($certBytes)
            $thumbprint = [BitConverter]::ToString($hash).Replace('-',':')

}

----------------------------------------------------------------------------------------

#. Results on Mac:

----------------------------------------------------------------------------------------

$psversiontable

Name Value


PSVersion 7.1.4
PSEdition Core
GitCommitId 7.1.4
OS Darwin 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

$Certs[-1].Certificate.PublicKey.Key

shows

LegalKeySizes KeySize KeyExchangeAlgorithm SignatureAlgorithm


{System.Security.Cryptography.KeySizes} 2048 RSA RSA

Keysize is available and can be read

----------------------------------------------------------------------------------------

Results on Linux:

----------------------------------------------------------------------------------------

$psversiontable

Name Value


PSVersion 7.1.6
PSEdition Core
GitCommitId 7.1.6
OS Linux 3.10.0-1160.62.1.el7.x86_64 #1 SMP Wed Mar 23 09:04:02 UTC 2022
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

$Certs[-1].Certificate.PublicKey.Key

KeySize LegalKeySizes KeyExchangeAlgorithm SignatureAlgorithm


    {System.Security.Cryptography.KeySizes} RSA                  RSA

Keysize is available and cannot be read

Expected behavior

# ----------------------------------------------------------------------------------------
#. Results on Mac:
# ----------------------------------------------------------------------------------------

$psversiontable

Name                           Value
----                           -----
PSVersion                      7.1.4
PSEdition                      Core
GitCommitId                    7.1.4
OS                             Darwin 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0


$Certs[-1].Certificate.PublicKey.Key

shows

LegalKeySizes                           KeySize KeyExchangeAlgorithm SignatureAlgorithm
-------------                           ------- -------------------- ------------------
{System.Security.Cryptography.KeySizes}    2048 RSA                  RSA


Keysize is available and can be read

Actual behavior

# ----------------------------------------------------------------------------------------
#  Results on Linux:
# ----------------------------------------------------------------------------------------

$psversiontable

Name                           Value
----                           -----
PSVersion                      7.1.6
PSEdition                      Core
GitCommitId                    7.1.6
OS                             Linux 3.10.0-1160.62.1.el7.x86_64 #1 SMP Wed Mar 23 09:04:02 UTC 2022
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

$Certs[-1].Certificate.PublicKey.Key

KeySize LegalKeySizes                           KeyExchangeAlgorithm SignatureAlgorithm
------- -------------                           -------------------- ------------------
        {System.Security.Cryptography.KeySizes} RSA                  RSA

Keysize is available and cannot be read

Error details

Keysize {Get} method forgotten in Linux version ???

When doing the get-method

Mac shows {Get;Set}
Linux shows {;Set}

Environment data

$psversiontable

Name                           Value
----                           -----
PSVersion                      7.1.6
PSEdition                      Core
GitCommitId                    7.1.6
OS                             Linux 3.10.0-1160.62.1.el7.x86_64 #1 SMP Wed Mar 23 09:04:02 UTC 2022
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productNeeds-TriageThe issue is new and needs to be triaged by a work group.Resolution-No ActivityIssue has had no activity for 6 months or moreWG-DevEx-Portabilityauthoring cross-platform or cross-architecture modules, cmdlets, and scripts

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0