user1811107
user1811107

Reputation: 759

Xamarin/Visual Studio on Mac - iPhone - Not able to list X509Store certificates

Environment Device: . iPhone6s

Development Environment: .net Standard 1.5, Visual Studio on Mac Community Version 7.2.2 (build 7), Xamarin

I have the following code to get/list Certificates that are installed on my iPhone. I have not been successful so far – I get an empty collection when I use the code below.

I am running the code on the iPhone using a development provisioning profile.

I have 2 projects a portable Project and an iOS project. The Code listed below is in the Portable Class library.

using System;
using System.Collections.Generic;
using Xamarin.Forms;

using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

    X509Store paramStore 

    paramStore  = new X509Store(StoreName.My, StoreLocation.CurrentUser) 

    paramStore.Open(OpenFlags.ReadOnly); 
    foreach (X509Certificate2 mCert in paramStore.Certificates)
    {
     numberOfCertificates = numberOfCertificates + 1;

    }

I have also tried accessing StoreName.Root, StoreName.CertificateAuthority along with variations of OpenFlags e.g. .ReadWrite - same result no data.

Looking for input/thoughts.

Upvotes: 0

Views: 508

Answers (1)

Kevin Li
Kevin Li

Reputation: 2258

Unfortunately, it is not supported on iOS, here's the explanation from Apple side:

First, some clarifications:

  • Given that you’re talking about “client authentication” earlier, I presume you’re talking about digital identities rather than certificates. Note A digital identity is the combination of a private key and a certificate that contains the public key that matches that private key, and is what you need to present on the client side if you want the server to authenticate the client.

  • It seems that you care about digital identities installed via MDM. Credentials installed that way are placed in an Apple keychain access group and, as such, are only accessible to Apple apps. QA1745 Making Certificates and Keys Available To Your App discusses this in more detail.

Is there any way to check [whether a digital identity] is installed on [the device]?

Not in general.

More details, please refer to the related case in Apple Developer Forum: How to get Certificates list from iOS device?

Upvotes: 1

Related Questions