/// <summary> /// Load a CA instance based on the CA type in the configuration file /// </summary> /// <param name="ConfigFile">Full pathname of the CA config file</param> /// <param name="Password">Password to access key material</param> /// <returns>OSCA CA instance or null</returns> public static ICA LoadCA(string ConfigFile, string Password) { // Read in the configuration XDocument config = XDocument.Load(ConfigFile); string version = config.Element("OSCA").Attribute("version").Value; XElement ca = config.Element("OSCA").Element("CA"); // Version 2.x CA (basically either fips or simple) if ((version == "2.0") || (version == "2.1")) { bool fipsMode = Convert.ToBoolean(ca.Element("fips140").Value); if (fipsMode) { return(new fipsCA(ConfigFile)); } else { return(new simpleCA(ConfigFile, Password)); } } // Version 3.x CA - CA type based on CA_TYPE if ((version == "3.0") || (version == "3.1")) { CA_Type caType = Utility.SetCA_Type(ca.Element("caType").Value); switch (caType) { case CA_Type.sysCA: return(new sysCA(ConfigFile)); case CA_Type.bcCA: return(new bcCA(ConfigFile, Password)); case CA_Type.dhTA: return(new dhTA(ConfigFile)); case CA_Type.cngCA: return(new cngCA(ConfigFile)); default: return(null); // Should never see this } } return(null); }
/// <summary> /// Load up the properties of the CA from the CA config file /// </summary> /// <param name="ConfigFileName">Pathname of the CA config file</param> public CaControl(string ConfigFileName) { configFileName = ConfigFileName; XDocument doc; if (XmlSigning.VerifyXmlFile(configFileName)) { doc = XDocument.Load(ConfigFileName); } else { throw new GeneralSecurityException("Signature failed on CA config file"); } XElement config = doc.Element("OSCA").Element("CA"); version = doc.Element("OSCA").Attribute("version").Value; name = config.Element("name").Value; role = config.Element("type").Value; created = config.Element("created").Value; dbFileLocation = config.Element("dbFileLocation").Value; publicKeyAlgorithm = config.Element("publicKeyAlgorithm").Value + "-" + config.Element("publicKeySize").Value; signatureAlgorithm = config.Element("signatureAlgorithm").Value; fips140 = Convert.ToBoolean(config.Element("fips140").Value); lastSerial = config.Element("lastSerial").Value; crlFileLocation = config.Element("crlFileLocation").Value; lastCRL = config.Element("lastCRL").Value; crlInterval = config.Element("crlInterval").Value; profilesLocation = config.Element("profilesLocation").Value; certificate = null; currentCerts = new CaDB(dbFileLocation, CertStatus.Current); revokedCerts = new CaDB(dbFileLocation, CertStatus.Revoked); expiredCerts = new CaDB(dbFileLocation, CertStatus.Expired); profiles = new profileDB(profilesLocation); if ((version == "3.0") || (version == "3.1")) { caType = Utility.SetCA_Type(config.Element("caType").Value); } }
/// <summary> /// Construct a CA object /// <remarks> Derived classes should call this before doing anything else</remarks> /// </summary> /// <param name="ConfigFile">Full pathname to config file</param> /// <param name="Password">Password for key file</param> /// <exception cref="GeneralSecurityException">Signature failed on CA config file</exception> public OSCA_CA(string ConfigFile) { this.configFile = ConfigFile; // Read in the configuration XDocument config; if (XmlSigning.VerifyXmlFile(configFile)) { config = XDocument.Load(configFile); } else { throw new GeneralSecurityException("Signature failed on CA config file"); } this.version = config.Element("OSCA").Attribute("version").Value; this.ca = config.Element("OSCA").Element("CA"); this.name = ca.Element("name").Value; this.type = ca.Element("type").Value; this.dbFileLocation = ca.Element("dbFileLocation").Value; this.publicKeyAlgorithm = ca.Element("publicKeyAlgorithm").Value; this.publicKeySize = ca.Element("publicKeySize").Value; this.signatureAlgorithm = ca.Element("signatureAlgorithm").Value; this.fips140 = Convert.ToBoolean(ca.Element("fips140").Value); this.lastSerial = ca.Element("lastSerial").Value; this.crlFileLocation = ca.Element("crlFileLocation").Value; this.lastCRL = ca.Element("lastCRL").Value; this.crlInterval = Convert.ToDouble(ca.Element("crlInterval").Value); this.profilesLocation = ca.Element("profilesLocation").Value; if ((version == "3.0") || (version == "3.1")) { this.caType = Utility.SetCA_Type(ca.Element("caType").Value); } }