locked
How to get SSL certificate Info?

    Question

  • Hello,

    I am developing application for Windows 8.1 and need to get some properties of SSL certificate for a give url like ValidFrom, ValidTo, IssuerName and HashString but don't know how to get this.

    It will be helpful if you share some code snipped for it.

    Thanks in advance.

    Monday, June 30, 2014 6:17 AM

Answers

  • Hi Matt,

    Thanks for the reply

    I found the solution, There is a method GetHasValue in Certificate Class which gives Thumprint info.

    Here is the code for that

    CryptographicBuffer.EncodeToHexString(CryptographicBuffer.CreateFromByteArray(serverCert.GetHashValue()))

    Thursday, September 11, 2014 5:17 AM

All replies

  • Hello,

    I am developing application for Windows Phone 8.1 and need to get some properties of SSL certificate for a give url like ValidFrom, ValidTo, IssuerName and HashString but don't know how to get this.

    It will be helpful if you share some code snipped for it.

    Thanks in advance.

    Monday, June 30, 2014 6:14 AM
  • Please refer to this API for the information that you require from the certificate:

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.security.cryptography.certificates.certificate.aspx

    Below is a code sample.  I don't see a property for HashString in the APIs.

     <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
       <StackPanel VerticalAlignment="Center" HorizontalAlignment="Left" Margin="40">
       <TextBox Width="300" Height="500" Background="White" x:Name="MyTextBox" AcceptsReturn="True"/>
                <Button Content="Select .cer Certificate" Click="Button_Click" />
      </StackPanel>
    </Grid>
     private async void Button_Click(object sender, RoutedEventArgs e)
            {
                FileOpenPicker MyFOP = new FileOpenPicker();
                MyFOP.FileTypeFilter.Add(".cer");
                StorageFile MyStorageFile = await MyFOP.PickSingleFileAsync();
                IBuffer MyCertificateBlob = await FileIO.ReadBufferAsync(MyStorageFile);
                Certificate MyCertificate = new Certificate(MyCertificateBlob);
                MyTextBox.Text += "ValidFrom: " + MyCertificate.ValidFrom + "\r\n";
                MyTextBox.Text += "ValidTo: " + MyCertificate.ValidTo + "\r\n";
                MyTextBox.Text += "Issuer: " + MyCertificate.Issuer + "\r\n";
            }



    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, June 30, 2014 7:35 PM
    Moderator
  • Hi Matt

    Thanks for the reply,

    The code snippet you shared is for getting properties from local certificate ,what I need it to get SSL certificate of given https URL.

    Tuesday, July 01, 2014 5:21 AM
  • You can follow these steps to make a StreamSocket connection to the website. You can use UpGradeToSSLAsync to make it an SSL connection, then get StreamSocket.Information to get the Certificate information as shown above.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, July 01, 2014 12:15 PM
    Moderator
  • Hi Matt

    Thanks for your reply,

    I tried StreamSocket Sample but didn't find it useful for my purpose.

    It will be helpful if you can share some code here, I am not that much aware with SocketConnections.


    • Edited by zee_patel Tuesday, July 01, 2014 1:57 PM
    Tuesday, July 01, 2014 1:54 PM
  • Hi Matt,

    As you suggested using StreamSocket now I am able to get Server Certificate Info like validto, validfrom etc, but I also need Thumbprint of that certificate, I am not able to find any properties or method in Certificate Class for that.

    Please can you suggest me how to get Thumbprint of that certificate?

    Monday, August 11, 2014 10:04 AM
  • Hi Matt,

    Any updates for getting SSL certificate Thumbprint?

    Wednesday, September 10, 2014 6:01 AM
  • There is no way to get the Thumbprint without using a third-party API.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, September 10, 2014 8:33 PM
    Moderator
  • Hi Matt,

    Thanks for the reply

    I found the solution, There is a method GetHasValue in Certificate Class which gives Thumprint info.

    Here is the code for that

    CryptographicBuffer.EncodeToHexString(CryptographicBuffer.CreateFromByteArray(serverCert.GetHashValue()))

    Thursday, September 11, 2014 5:17 AM
  • That's pretty awesome, I am glad you found it.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, September 11, 2014 5:09 PM
    Moderator