Skip to Content
author's profile photo Former Member
Former Member

how to call afaria api to add Certificate authority server property in a afaria7 sp5 tenant

Hi Expert,

we are working on afaria apis to automate the process of assigning CA server property for a tenant . where i am call server property api service.

but i don't know how to set property like server address, CA type etc. for a tenant.

any help will be apreciated.

BR,

Saurabh

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Dec 02, 2014 at 05:12 PM

    What type of CA were you attempting to add? For a simple SCEP CA entry, see below:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using ServerProps_AddCA.AfariaServerProperties;
    
    namespace ServerProps_AddCA
    {
        class Program
        {
            static void Main(string[] args)
            {
                string apiAddress = "10.10.10.10";
                string apiUserDomain = "domain.com";
                string apiUserName = "afaria";
                string apiUserPass = "mysupersecretpassword";
                string serverTransmitterID = "mytransmitterid";
    
                string response = string.Empty;
    
                Console.Write("Enter the API Server address or hit enter for default: ");
                response = Console.ReadLine();
                if (!string.IsNullOrWhiteSpace(response))
                {
                    apiAddress = response;
                    Console.Write("Enter the API Service Account UserName or hit enter for default: ");
                    response = Console.ReadLine();
                    if (!string.IsNullOrWhiteSpace(response))
                    {
                        apiUserName = response;
                        Console.Write("Enter the API Service Account User Domain or hit enter for default: ");
                        response = Console.ReadLine();
                        if (!string.IsNullOrWhiteSpace(response))
                        {
                            apiUserDomain = response;
                        }
    
                        Console.Write("Enter the API Service Account User Password or hit enter for default: ");
                        response = Console.ReadLine();
                        if (!string.IsNullOrWhiteSpace(response))
                        {
                            apiUserPass = response;
                        }
                    }
                }
                using (ServerPropertiesServiceClient svcServerProperties = new ServerPropertiesServiceClient("NetTcpBinding_IServerPropertiesService"
                                                                                                        , "net.tcp://" + apiAddress + ":7982/AfariaService/ServerProperties"))
                {
                    svcServerProperties.ClientCredentials.Windows.ClientCredential.Domain = apiUserDomain;
                    svcServerProperties.ClientCredentials.Windows.ClientCredential.UserName = apiUserName;
                    svcServerProperties.ClientCredentials.Windows.ClientCredential.Password = apiUserPass;
                    svcServerProperties.InitContext(Guid.NewGuid().ToString());
    
                    Console.Write("Enter the Tenant ID # or hit enter for system tenant(0): ");
                    int tenantID = 0;
                    response = Console.ReadLine();
                    if (!string.IsNullOrWhiteSpace(response))
                    {
                        int.TryParse(response, out tenantID);
                    }
                    svcServerProperties.SetTenantIdContext(tenantID);
                    svcServerProperties.SetServerIdContext(serverTransmitterID);
    
                    string caName = "New CA-" + Guid.NewGuid().ToString("N");
                    string caDescription = "New CA Description";
                    string caAddress = "127.0.0.1";
                    CertificateAuthorityConfigurationScep caConfig = new CertificateAuthorityConfigurationScep();
                    caConfig.CertificateRequest = new CertificateRequestV002();
                    caConfig.ServerAccess = new ServerAccessSettings();
                    caConfig.ServerAccess.Address = caAddress;
                    caConfig.CertificateRenewalDays = 21;
    
                  
                    try
                    {
    
                        //if (svcServerProperties.ValidateCertificateAuthoritySettingsV002(caConfig, null, 60))
                        //{
                        Console.WriteLine("Attempting to add CA entry...");
                        svcServerProperties.AddCertificateAuthorityDefinedSettingInfoV002(caName, caDescription, caConfig);
                        Console.WriteLine("Hooray! Success!");
                        //}
                    }
                    catch(Exception ex)
                    {
                        Console.WriteLine("Exception occurred: " + ex.Message + "\r\n" + ex.StackTrace);
                        if(ex.InnerException != null)
                        {
                            Console.WriteLine("\r\nInner exception: " + ex.InnerException.Message + "\r\n"+ ex.InnerException.StackTrace);
                        }
                    }
    
                    if (svcServerProperties.ChannelFactory.State != System.ServiceModel.CommunicationState.Faulted)
                    {
                        svcServerProperties.CloseContext();
                    }
                }
                Console.Write("\r\n\r\nPress a key to exit...");
                Console.ReadKey();
            }
        }
    }
    
    
    
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.