Windows and Mac Keystore - Installing x.509 PKI PKCS#12 Certificates

Let’s say I want to secure my Unity application using x.509 PKCS#12 Certificates. I want to do this for a number of reasons, but the main reason to verify the authenticity of the user beyond a normal email address and password.

So my signup process for a new user would be:

  1. download my unity app
  2. enter email address
  3. verify given email address
  4. automate the CA certificate installation process to where the user is not involved at all
  5. login

#s 123 and 5 are no brainers. #4 is what I need help with. Does Unity have access to the each platforms Keystore?

OK So I figured how to add a cert to the store. But, when I look in certmgr on windows, the cert is not listed.

public class test : MonoBehaviour {

// Use this for initialization
void Start() {
// insert the CA into the Root Store (trusted root certificate authorities (CAs))
X509Store store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadWrite);
var newCert = new X509Certificate2(@“C:\path\to\cert.crt”);
Debug.Log("new certificate: " + newCert.Subject);
store.Add(newCert);
store.Close();
}
}

I don’t get any errors.

I was a little confused about the store. It is only within Unity and not shared in Windows.

Final code:

X509Store store = new X509Store(); // you don’t need to specify the store name or location
store.Open(OpenFlags.ReadWrite);
X509Certificate2 newCert = new X509Certificate2(@“C:\path\to\cert.cer”);
Debug.Log(“# of certificates in store before remove: " + store.Certificates.Count);
store.Remove(newCert);
Debug.Log(”# of certificates in store after remove: " + store.Certificates.Count);
Debug.Log(“new certificate: " + newCert.Subject);
store.Add(newCert);
Debug.Log(”# of certificates in store after add: " + store.Certificates.Count);
store.Close();

Please see attached debugging output.

2857587--209009--Capture.PNG