Beispiel #1
0
        /// <summary>
        /// Store the PPKData with the specified property.
        /// </summary>
        /// <param name="ppkData">The PPK to store.</param>
        /// <param name="prop">The property PPK belongs to.</param>
        /// <param name="persist">If true save in store.</param>
        /// <param name="inTable">If true save in Policy HashTable.</param>
        /// <param name="isRA">.</param>
        /// <param name="PPKtype">.</param>
        public static void StorePPKData(byte[] ppkData, string prop, bool persist, bool inTable, bool isRA, string PPKtype)
        {
            Domain domain;

            if (inTable && PPKtype == CertType)
            {
                if (isRA)
                {
                    CertPolicy.StoreRACertificate(ppkData, prop);
                }
                else
                {
                    CertPolicy.StoreCertificate(ppkData, prop);
                }
            }
            if (persist)
            {
                // Save the cert in the store.
                Store store = Store.GetStore();
                if (isRA)
                {
                    domain = store.GetDomain(store.DefaultDomain);
                }
                else
                {
                    domain = store.GetDomain(store.LocalDomain);
                }

                // Check for an existing cert in the store.
                Node    cn = null;
                ICSList nodeList;
                if (isRA)
                {
                    nodeList = domain.Search(raProperty, prop, SearchOp.Equal);
                }
                else
                {
                    nodeList = domain.Search(hostProperty, prop, SearchOp.Equal);
                }
                foreach (ShallowNode sn in nodeList)
                {
                    cn = new Node(domain, sn);
                    if (!cn.IsType(PPKtype))
                    {
                        cn = null;
                        continue;
                    }
                    break;
                }

                if (cn == null)
                {
                    // The cert/rsa doesn't exist ... create it.
                    cn = new Node(certificateProperty + " for " + prop);
                    domain.SetType(cn, PPKtype);
                    if (isRA)
                    {
                        cn.CollisionPolicy = CollisionPolicy.ServerWins;
                        cn.Properties.ModifyNodeProperty(new Property(raProperty, prop));
                    }
                    else
                    {
                        cn.Properties.ModifyNodeProperty(new Property(hostProperty, prop));
                    }
                }
                cn.Properties.ModifyNodeProperty(new Property(certificateProperty, Convert.ToBase64String(ppkData)));
                domain.Commit(cn);
                log.Debug("committed the storage of certificate into domain");
            }
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        public static void LoadRACertsFromStore()
        {
            Store  store    = Store.GetStore();
            string domainID = store.DefaultDomain;

            // We need to get rid of any duplicate certificates that may exist.
            Hashtable ht            = new Hashtable();
            ArrayList nodesToDelete = new ArrayList();

            Domain  domain = store.GetDomain(domainID);
            ICSList certs  = domain.GetNodesByType(CertType);

            ht.Clear();
            nodesToDelete.Clear();

            foreach (ShallowNode sn in certs)
            {
                Node node = new Node(domain, sn);
                try
                {
                    string nodeProperty = node.Properties.GetSingleProperty(raProperty).Value.ToString();
                    if (nodeProperty != null)
                    {
                        if (ht.Contains(nodeProperty))
                        {
                            // A duplicate exists, use the most recent one.
                            Node dupNode = (Node)ht[nodeProperty];

                            DateTime nodeTime    = (DateTime)node.Properties.GetSingleProperty(PropertyTags.NodeCreationTime).Value;
                            DateTime dupNodeTime = (DateTime)dupNode.Properties.GetSingleProperty(PropertyTags.NodeCreationTime).Value;

                            if (dupNodeTime > nodeTime)
                            {
                                nodesToDelete.Add(node);
                                node = dupNode;
                            }
                            else
                            {
                                nodesToDelete.Add(dupNode);
                                ht[nodeProperty] = node;
                            }
                        }
                        else
                        {
                            ht.Add(nodeProperty, node);
                        }
                        string sCert       = node.Properties.GetSingleProperty(certificateProperty).Value.ToString();
                        byte[] certificate = Convert.FromBase64String(sCert);
                        CertPolicy.StoreRACertificate(certificate, nodeProperty);
                    }
                }
                catch {}
            }

            if (nodesToDelete.Count > 0)
            {
                try
                {
                    domain.Commit(domain.Delete((Node[])(nodesToDelete.ToArray(typeof(Node)))));
                }
                catch {}
            }
        }