Friday, October 30, 2009

How to push certificate to "Trusted root certificate authorities" using Installer

In order to run your Full Trust enabled WPF XBAP application, you have to use “Self signed certificate authority file” for running and deploying XBAP application. The certificate should pushed it into “Trusted Publisher” and “Authority Root” certificate storages. You can use X509Certificate2 and X509Store classes in your installer assembly for pushing the certificate to certificate storage. Please use the following code snippet.


string certPath = string.Format(@"{0}\Aaa.cer", Environment.GetFolderPath(Environment.SpecialFolder.System));
X509Certificate2 certificate = new X509Certificate2(certPath);
X509Store trustedPublisherStore = new X509Store(StoreName.TrustedPublisher, StoreLocation.LocalMachine);
X509Store trustedAuthorityRootStore = new X509Store(StoreName.AuthRoot, StoreLocation.LocalMachine);

try
{
     trustedPublisherStore.Open(OpenFlags.ReadWrite);
     trustedPublisherStore.Add(certificate);
     trustedAuthorityRootStore.Open(OpenFlags.ReadWrite);
     trustedAuthorityRootStore.Add(certificate);
}
catch (Exception ex)
{
     MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace);
}
finally
{
     trustedPublisherStore.Close();
     trustedAuthorityRootStore.Close();
}


Please refer the following link to know more about “WPF - XBAP as Full Trust Application

Post a Comment