public void TestGenerate() { CertificateModel model = new CertificateModel(); // Delete the certificate if it exists. Defines.CertificatesDirectoryCommandServerPfx.Delete(); // Create a new certificate model.Generate(); // Certificate exists Defines.CertificatesDirectoryCommandServerPfx.Refresh(); Assert.IsTrue(Defines.CertificatesDirectoryCommandServerPfx.Exists); // Loads the certificates var loadedCertificate = new X509Certificate2(Defines.CertificatesDirectoryCommandServerPfx.FullName, model.Password); // Certificate can be loaded. Assert.IsNotNull(loadedCertificate); Assert.IsNotNull(loadedCertificate.PrivateKey); }
/// <summary> /// Generates a server pfx file used by the command server with the specified password within the arguments. /// </summary> /// <param name="arguments"> /// <para>The arguments for this command</para> /// <para>Expecting "password", but it is optional. If no password is supplied a random password will be generated</para> /// </param> public static ServiceMessage CommandServerGenerateCertificate(IDictionary<String, String> arguments) { var model = new CertificateModel(); if (arguments != null && arguments.Count > 0) { model.Password = arguments.First().Value; } else { model.RandomizePassword(); } model.Generate(); return new ServiceMessage() { Name = "result", Arguments = new Dictionary<String, String>() { { "Command", "CommandServerCreateCertificate" }, { "Success", model.Exists.ToString() }, { "Message", String.Format("Created certificate with password: {0}", model.Password) }, { "Password", model.Password } } }; }