I have the following code to add a generated self-signed certificate to the certificate store:
try
{
StorePermission sp = new StorePermission(PermissionState.Unrestricted);
sp.Flags = StorePermissionFlags.AllFlags;
sp.Assert();
StoreName storeName = StoreName.TrustedPeople;
StoreLocation storeLocation = StoreLocation.CurrentUser;
X509Store store = new X509Store(storeName, storeLocation);
store.Open(OpenFlags.ReadWrite);
Console.WriteLine($"Cert count: {store.Certificates.Count}");
//store.AddRange(new X509Certificate2Collection(cert));
store.Certificates.Add(cert);
Console.WriteLine($"Cert count: {store.Certificates.Count}");
store.Close();
}
catch (Exception ex)
{
throw;
}
It resided in a .Net Standard libray and works flawlessly with a console application.
I intend to use it with a Xamarin.Android project. The code runs, but it does nothing, the Count
value remains the same after the Add
method.
This is what I see on the output:
I/mono-stdout(18830): Cert count: 1
Cert count: 1
D/Mono (18830): DllImport searching in: 'libmono-btls-shared' ('./libmono-btls-shared.so').
D/Mono (18830): Searching for 'mono_btls_x509_cmp'.
D/Mono (18830): Probing 'mono_btls_x509_cmp'.
D/Mono (18830): Found as 'mono_btls_x509_cmp'.
The thread 0x16d0 has exited with code 0 (0x0).
Cert count: 1
I/mono-stdout(18830): Cert count: 1
What permission/method should I use to add it to the Android cert store?