private X509SecurityToken getToken(string which) { X509SecurityToken token = null; X509CertificateStore store = null; string serverKeyIdentifier = "bBwPfItvKp3b6TNDq+14qs58VJQ="; //"po3h4Y4J8ITs/pW3acuRjpT8V1o="; string clientKeyIdentifier = "gBfo0147lM6cKnTbbMSuMVvmFY4="; //"Gu4aD7+bYTVtmSveoPIWTRtzD3M="; //string serverKeyIdentifier = "po3h4Y4J8ITs/pW3acuRjpT8V1o="; //string clientKeyIdentifier = "Gu4aD7+bYTVtmSveoPIWTRtzD3M="; store = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore); store.OpenRead(); X509CertificateCollection coll; if (which == "server") { coll = store.FindCertificateByKeyIdentifier(Convert.FromBase64String(serverKeyIdentifier)); } else { coll = store.FindCertificateByKeyIdentifier(Convert.FromBase64String(clientKeyIdentifier)); } if (coll.Count > 0) { X509Certificate cert = (X509Certificate)coll[0]; RSA rsa = cert.Key; token = new X509SecurityToken(cert); } return(token); }
public bool IsContactCertificateInStore(string strContactID) { bool bRetVal = false; X509CertificateStore certStore = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore); if (certStore == null) { throw new Exception("Error opening Local Machine Store"); } if (certStore.OpenRead()) { X509CertificateCollection certColl = certStore.FindCertificateBySubjectName(strContactID); if (certColl.Count == 0) { bRetVal = false; } else { bRetVal = true; } } // Close the certificate store certStore.Close(); return(bRetVal); }
/// <summary> /// Retrieve the X509 certificate for a given subject name and location /// </summary> /// <param name="location">either CurrentUser store or LocalMachine store</param> /// <param name="subject">subject name</param> /// <returns>X509Certificate object</returns> public static X509Certificate SearchCertificateBySubjectName(string location, string subject) { X509CertificateStore x509Store = null; if (location == "CurrentUser") { x509Store = X509CertificateStore.CurrentUserStore(X509CertificateStore.MyStore); } else { x509Store = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore); } bool open = x509Store.OpenRead(); X509Certificate certificate = null; foreach (X509Certificate cert in x509Store.Certificates) { if (subject.ToUpper() == cert.GetName().ToUpper()) { certificate = cert; break; } } return(certificate); }
/** * this is the constructor for the GUI, it does the following: * 1. set up the DAO objects to access the local database * 2. add any active meetings in the database to the field in the GUI * 3. extract my X.509 certificate from the local store * 4. instantiate 5 "dummy" resources, add them to resource list * */ public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // dbConnect = "DSN=TotalRecall;UID=TotalRecallUser;PWD=totalrecall;DATABASE=TotalRecall"; mDAO = new MeetingDAO(dbConnect); pDAO = new ParticipantDAO(dbConnect); rDAO = new ResourceDAO(dbConnect); cDAO = new ContactDAO(dbConnect); cmDAO = new ContextMsgDAO(dbConnect); strSelectedMtg = ""; ArrayList lstMtgs = mDAO.GetMeetingIDs(enuMeetingState.Active); foreach (string s in lstMtgs) { m_boxMtgs.Items.Add(s); } strMyUrl = "http://localhost/TotalRecall/InfoAgent.asmx?wsdl"; store = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore); store.OpenRead(); strMyName = "CN=Omar"; certCol = store.FindCertificateBySubjectName(strMyName); cert = (X509Certificate)certCol[0]; certToken = new X509SecurityToken(cert); lstResources = new ArrayList(); for (int i = 0; i < 5; i++) { Resource res = new Resource(); res.ID = "res" + (i + 1); res.Name = "Foo" + (i + 1) + ".txt"; res.Url = "file:///c:\\" + res.Name; rDAO.AddNewResource(res); lstResources.Add(res); } foreach (Resource r in lstResources) { m_boxResources.Items.Add(r.ID); } }
public static X509SecurityToken GetServerToken() { X509SecurityToken token = null; X509CertificateStore store = null; // For server, open the LocalMachine Certificate Store and try Personal store. store = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore); token = RetrieveTokenFromStore(store, ServerBase64KeyId); return(token); }
/// <summary> /// Get the certificate from the store as provided by FIS /// </summary> public X509Certificate GetCertificate(string certificateName) { X509Certificate cert = null; // First check local machine store var certificateStore = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore); certificateStore.OpenRead(); foreach (X509Certificate certificate in certificateStore.Certificates) { if (certificate.SimpleDisplayName.EqualsIgnoreCase(certificateName)) { cert = certificate; break; } } // If not found, check root if (cert == null) { certificateStore = X509CertificateStore.LocalMachineStore(X509CertificateStore.RootStore); certificateStore.OpenRead(); foreach (X509Certificate certificate in certificateStore.Certificates) { if (certificate.SimpleDisplayName.EqualsIgnoreCase(certificateName)) { cert = certificate; break; } } } certificateStore.Close(); certificateStore.Dispose(); if (cert == null) { _logger.Trace("------------ Error -------------- GetCertificate. Certificate not found"); } return(cert); }
public X509Certificate GetContactCertificate(string strContactID) { X509CertificateStore certStore = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore); if (certStore == null) { throw new Exception("Error opening Local Machine Store"); } X509Certificate cert = null; if (certStore.OpenRead()) { X509CertificateCollection certColl = certStore.FindCertificateBySubjectName(strContactID); if (certColl.Count == 1) { cert = certColl[0]; } } // Close the certificate store certStore.Close(); return(cert); }
/** * this constructor does the following: * 1. read in the X.509 certificate from the machine store * 2. get the localhost IP address * 3. create an executor / executor context for the local InfoAgent * 4. create the DAO objects to access contents in the database * 5. update the existing meetings with all meetings in the database * */ public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // store = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore); store.OpenRead(); strMyId = "CN=Omar"; certCol = store.FindCertificateBySubjectName(strMyId); cert = (X509Certificate)certCol[0]; certToken = new X509SecurityToken(cert); me = new MeetingParticipant(); me.Name = cert.GetName(); me.Role = enuMeetingParticipantRole.Organizer; strFileLocation = "TotalRecall/InfoAgent.asmx?wsdl"; string strHost = Dns.GetHostName(); IPHostEntry entry = Dns.Resolve(strHost); string strIP = ""; if (entry.AddressList.Length > 0) { IPAddress addr = new IPAddress(entry.AddressList[0].Address); strIP = addr.ToString(); } else { m_boxInvite.Text = "ERROR getting host IP"; return; } StringBuilder strbldUrl = new StringBuilder(strIP); strbldUrl.Append(strFileLocation); me.Location = strbldUrl.ToString(); //create my infoagent strMyUrl = "http://localhost/TotalRecall/InfoAgent.asmx?wsdl"; ProxyGenRequest pxyreq = new ProxyGenRequest(); pxyreq.ProxyPath = ""; pxyreq.ServiceName = "InfoAgent"; pxyreq.WsdlUrl = strMyUrl; ProxyPolicyMutator mymutator = new ProxyPolicyMutator(); mymutator.ProxyName = pxyreq.ServiceName; // Ensure the name of the file generated is unique string strMySuffix = ""; int nMyCode = Guid.NewGuid().GetHashCode(); if (nMyCode < 0) { nMyCode = nMyCode * -1; } strMySuffix = nMyCode.ToString(); pxyreq.ServiceName = pxyreq.ServiceName + "_" + strMySuffix; ProxyGen myPxyGen = new ProxyGen(); myPxyGen.Mutator = mymutator; string strMyAssembly = ""; try { strMyAssembly = myPxyGen.GenerateAssembly(pxyreq); } catch (Exception excep) { string strString = excep.Message; } myctx = new ExecContext(); myctx.ServiceName = pxyreq.Namespace + "." + mymutator.ProxyName; myctx.Assembly = strMyAssembly; myexec = new Executor(); myexec.Settings.ExpectSignedResponse = true; myexec.Settings.SigningCertificate = cert; dbConnect = "DSN=TotalRecall;UID=TotalRecallUser;PWD=totalrecall;DATABASE=TotalRecall"; mDAO = new MeetingDAO(dbConnect); pDAO = new ParticipantDAO(dbConnect); rDAO = new ResourceDAO(dbConnect); cDAO = new ContactDAO(dbConnect); strSelectedMtg = ""; ArrayList lstMtgs = mDAO.GetMeetingIDs(enuMeetingState.Active); foreach (string s in lstMtgs) { m_boxMtgs.Items.Add(s); } }