예제 #1
0
        internal ConfigConsole(ConsoleSettings settings)
        {
            m_settings = settings;

            this.CreateClients();

            TokenSettings tokenSettings = null;

            try
            {
                string dataPath =
                    Path.Combine(
                        Path.Combine(
                            Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                            "DirectProject"),
                        "TokenSettings.xml");

                if (File.Exists(dataPath))
                {
                    string tokenSettingsXml = File.ReadAllText(dataPath);
                    tokenSettings = tokenSettingsXml.FromXml <TokenSettings>();
                }
                else
                {
                    Property[] properties       = m_propertyClient.GetProperties(new[] { "TokenSettings" });
                    string     tokenSettingsXml = properties.SingleOrDefault().Value;
                    tokenSettings = tokenSettingsXml.FromXml <TokenSettings>();
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }

            m_commands        = new Commands("ConfigConsole");
            m_commands.Error += PrintError;

            m_commands.Register(new AddressCommands(this, () => m_addressClient));
            m_commands.Register(new AnchorCommands(this, () => m_anchorClient));
            m_commands.Register(new CertificateCommands(this, () => m_certificateClient));
            if (tokenSettings != null)
            {
                m_commands.Register(new Pkcs11Commands(this, () => m_certificateClient, tokenSettings));
            }
            m_commands.Register(new DomainCommands(this, () => m_domainClient, () => m_addressClient));
            m_commands.Register(new DnsRecordCommands(this, () => m_dnsRecordClient));
            m_commands.Register(new PropertyCommands(this, () => m_propertyClient));
            m_commands.Register(new BlobCommands(this, () => m_blobClient));
            m_commands.Register(new SettingsCommands(this));
            m_commands.Register(new TestCommands(this));
            m_commands.Register(new BundleCommands(this, () => m_bundleClient));
            m_commands.Register(new MdnMonitorCommands(this, () => m_mdnMoniotrClient));
            m_commands.Register(new CertPolicyCommands(this, () => m_certPolicyClient));

            m_settings.HostAndPortChanged += HostAndPortChanged;
        }
예제 #2
0
        /// <summary>
        /// Finds slot containing the token that matches criteria specified in <see cref="TokenSettings"/> class
        /// </summary>
        /// <param name='pkcs11'>Initialized PKCS11 wrapper</param>
        /// <param name="settings"></param>
        /// <returns>Slot containing the token that matches criteria in <see cref="TokenSettings"/></returns>
        public static Slot FindSlot(Pkcs11 pkcs11, TokenSettings settings)
        {
            // Get list of available slots with token present
            var slots = pkcs11.GetSlotList(true);

            // No criteria, not go.
            if (settings.TokenLabel == null)
            {
                return(null);
            }

            foreach (var slot in slots)
            {
                TokenInfo tokenInfo = null;

                try
                {
                    tokenInfo = slot.GetTokenInfo();
                }
                catch (Pkcs11Exception ex)
                {
                    if (ex.RV != CKR.CKR_TOKEN_NOT_RECOGNIZED &&
                        ex.RV != CKR.CKR_TOKEN_NOT_PRESENT)
                    {
                        throw;
                    }
                }

                if (tokenInfo == null)
                {
                    continue;
                }

                if (!String.IsNullOrEmpty(settings.TokenLabel))
                {
                    if (0 != String.Compare(
                            settings.TokenLabel,
                            tokenInfo.Label,
                            StringComparison.Ordinal))
                    {
                        continue;
                    }
                }

                System.Console.WriteLine("tokenInfo.Label {0}", tokenInfo.Label);
                System.Console.WriteLine("tokenInfo.SerialNumber {0}", tokenInfo.SerialNumber);
                System.Console.WriteLine("tokenInfo.SlotId {0}", tokenInfo.SlotId);
                System.Console.WriteLine("tokenInfo.SessionCount {0}", tokenInfo.SessionCount);

                return(slot);
            }

            System.Console.WriteLine("Did not find an available slot with TokenLable:{0}", settings.TokenLabel);
            return(null);
        }
예제 #3
0
        internal ConfigConsole(ConsoleSettings settings)
        {
            m_settings = settings;

            this.CreateClients();

            TokenSettings tokenSettings = null;

            try
            {
                Property[] properties       = m_propertyClient.GetProperties(new[] { "TokenSettings" });
                string     tokenSettingsXml = properties.SingleOrDefault().Value;
                tokenSettings = tokenSettingsXml.FromXml <TokenSettings>();
            }
            catch (Exception)
            {
                //Acceptable to not have token settings.
            }

            m_commands        = new Commands("ConfigConsole");
            m_commands.Error += PrintError;

            m_commands.Register(new AddressCommands(this, () => m_addressClient));
            m_commands.Register(new AnchorCommands(this, () => m_anchorClient));
            m_commands.Register(new CertificateCommands(this, () => m_certificateClient));
            if (tokenSettings != null)
            {
                m_commands.Register(new Pkcs11Commands(this, () => m_certificateClient, tokenSettings));
            }
            m_commands.Register(new DomainCommands(this, () => m_domainClient, () => m_addressClient));
            m_commands.Register(new DnsRecordCommands(this, () => m_dnsRecordClient));
            m_commands.Register(new PropertyCommands(this, () => m_propertyClient));
            m_commands.Register(new BlobCommands(this, () => m_blobClient));
            m_commands.Register(new SettingsCommands(this));
            m_commands.Register(new TestCommands(this));
            m_commands.Register(new BundleCommands(this, () => m_bundleClient));
            m_commands.Register(new MdnMonitorCommands(this, () => m_mdnMoniotrClient));
            m_commands.Register(new CertPolicyCommands(this, () => m_certPolicyClient));

            m_settings.HostAndPortChanged += HostAndPortChanged;
        }