コード例 #1
0
ファイル: ACMESharpManager.cs プロジェクト: egbonrelu/certify
 public string GetVaultPath()
 {
     using (var vlt = (LocalDiskVault)ACMESharpUtils.GetVault(this.vaultProfile))
     {
         this.vaultFolderPath = vlt.RootPath;
     }
     return(this.vaultFolderPath);
 }
コード例 #2
0
ファイル: ACMESharpManager.cs プロジェクト: egbonrelu/certify
 public VaultInfo LoadVaultFromFile()
 {
     lock (VAULT_LOCK)
     {
         using (var vlt = ACMESharpUtils.GetVault(this.vaultProfile))
         {
             OpenVaultStorage(vlt, true);
             var v = vlt.LoadVault();
             return(v);
         }
     }
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: huqiji/LEGainer
        /// <summary>
        /// 初始化vault
        /// </summary>
        public static void InitializeVault()
        {
            string baseuri = ACMESharpUtils.WELL_KNOWN_BASE_SERVICES[ACMESharpUtils.WELL_KNOWN_LE];

            using (var vlt = ACMESharpUtils.GetVault())
            {
                vlt.InitStorage(true);
                var v = new VaultInfo
                {
                    Id              = ACMESharp.Vault.Util.EntityHelper.NewId(),
                    Alias           = "ztimage",
                    Label           = string.Empty,
                    Memo            = string.Empty,
                    BaseService     = string.Empty,
                    BaseUri         = baseuri,
                    ServerDirectory = new ACMESharp.AcmeServerDirectory()
                };
                vlt.SaveVault(v);
            }
        }
コード例 #4
0
ファイル: ACMESharpManager.cs プロジェクト: egbonrelu/certify
 public bool DeleteRegistrationInfo(Guid id)
 {
     using (var vlt = ACMESharpUtils.GetVault(this.vaultProfile))
     {
         lock (VAULT_LOCK)
         {
             try
             {
                 OpenVaultStorage(vlt, true);
                 vaultConfig.Registrations.Remove(id);
                 vlt.SaveVault(vaultConfig);
                 return(true);
             }
             catch (Exception e)
             {
                 // TODO: Logging of errors.
                 System.Diagnostics.Debug.WriteLine(e.Message);
                 return(false);
             }
         }
     }
 }
コード例 #5
0
ファイル: ACMESharpManager.cs プロジェクト: egbonrelu/certify
        internal bool DeleteIdentifierByDNS(string dns)
        {
            using (var vlt = ACMESharpUtils.GetVault(this.vaultProfile))
            {
                try
                {
                    lock (VAULT_LOCK)
                    {
                        OpenVaultStorage(vlt, true);
                        if (vaultConfig.Identifiers != null)
                        {
                            var         idsToRemove = vaultConfig.Identifiers.Values.Where(i => i.Dns == dns);
                            List <Guid> removing    = new List <Guid>();
                            foreach (var identifier in idsToRemove)
                            {
                                removing.Add(identifier.Id);
                            }
                            foreach (var identifier in removing)
                            {
                                vaultConfig.Identifiers.Remove(identifier);
                            }

                            vlt.SaveVault(vaultConfig);
                        }
                    }

                    return(true);
                }
                catch (Exception e)
                {
                    // TODO: Logging of errors.
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    return(false);
                }
            }
        }
コード例 #6
0
ファイル: ACMESharpManager.cs プロジェクト: egbonrelu/certify
        public bool InitVault(bool staging = true)
        {
            string apiURI = ACMESharpUtils.WELL_KNOWN_BASE_SERVICES[ACMESharpUtils.WELL_KNOWN_LESTAGE];

            if (!staging)
            {
                //live api
                apiURI = ACMESharpUtils.WELL_KNOWN_BASE_SERVICES[ACMESharpUtils.WELL_KNOWN_LE];
            }

            bool vaultExists = false;

            lock (VAULT_LOCK)
            {
                using (var vlt = ACMESharpUtils.GetVault(this.vaultProfile))
                {
                    OpenVaultStorage(vlt, true);
                    var v = vlt.LoadVault(false);
                    if (v != null)
                    {
                        vaultExists = true;
                    }
                }
            }

            if (!vaultExists)
            {
                var baseUri = apiURI;
                if (string.IsNullOrEmpty(baseUri))
                {
                    throw new InvalidOperationException("either a base service or URI is required");
                }

                lock (VAULT_LOCK)
                {
                    using (var vlt = ACMESharpUtils.GetVault(this.vaultProfile))
                    {
                        this.LogAction("InitVault", "Creating Vault");

                        OpenVaultStorage(vlt, true);

                        var v = new VaultInfo
                        {
                            Id              = EntityHelper.NewId(),
                            BaseUri         = baseUri,
                            ServerDirectory = new AcmeServerDirectory()
                        };

                        vlt.SaveVault(v);
                    }
                }
            }
            else
            {
                this.LogAction("InitVault", "Vault exists.");
            }

            this.vaultFolderPath = GetVaultPath();

            return(true);
        }
コード例 #7
0
ファイル: ACMESharpManager.cs プロジェクト: egbonrelu/certify
        public void CleanupVault(Guid?identifierToRemove = null, bool includeDupeIdentifierRemoval = false)
        {
            //remove duplicate identifiers etc

            lock (VAULT_LOCK)
            {
                using (var vlt = ACMESharpUtils.GetVault(this.vaultProfile))
                {
                    OpenVaultStorage(vlt, true);
                    var v = vlt.LoadVault();

                    List <Guid> toBeRemoved = new List <Guid>();
                    if (identifierToRemove != null)
                    {
                        if (v.Identifiers.Keys.Any(i => i == (Guid)identifierToRemove))
                        {
                            toBeRemoved.Add((Guid)identifierToRemove);
                        }
                    }
                    else
                    {
                        //find all orphaned identified or identifiers with no certificate
                        if (v.Identifiers != null)
                        {
                            foreach (var k in v.Identifiers.Keys)
                            {
                                var identifier = v.Identifiers[k];

                                var certs = v.Certificates.Values.Where(c => c.IdentifierRef == identifier.Id);
                                if (!certs.Any())
                                {
                                    toBeRemoved.Add(identifier.Id);
                                }
                            }
                        }
                    }

                    foreach (var i in toBeRemoved)
                    {
                        v.Identifiers.Remove(i);
                    }
                    //

                    //find and remove certificates with no valid identifier in vault or with empty settings
                    toBeRemoved = new List <Guid>();

                    if (v.Certificates != null)
                    {
                        foreach (var c in v.Certificates)
                        {
                            if (
                                String.IsNullOrEmpty(c.IssuerSerialNumber)  //no valid issuer serial
                                ||
                                !v.Identifiers.ContainsKey(c.IdentifierRef) //no existing Identifier
                                )
                            {
                                toBeRemoved.Add(c.Id);
                            }
                        }

                        foreach (var i in toBeRemoved)
                        {
                            v.Certificates.Remove(i);
                        }
                    }

                    /*if (includeDupeIdentifierRemoval)
                     * {
                     *  //remove identifiers where the dns occurs more than once
                     *  foreach (var i in v.Identifiers)
                     *  {
                     *      var count = v.Identifiers.Values.Where(l => l.Dns == i.Dns).Count();
                     *      if (count > 1)
                     *      {
                     *          //identify most recent Identifier (based on assigned, non-expired cert), delete all the others
                     *
                     *          toBeRemoved.Add(i.Id);
                     *      }
                     *  }
                     * }*/

                    // Remove VaultInfo.ServerDirectory.* where * value contains
                    // "adding-random-entries-to-the-directory" v.ServerDirectory.
                    vlt.SaveVault(v);
                }
            }
        }