24 #include "xml/conf.hxx"
26 #include <xsd/cxx/xml/dom/parsing-source.hxx>
32 #elif defined(__APPLE__)
33 #include <CoreFoundation/CoreFoundation.h>
46 void setValue(
const A &val,
bool lock,
bool global)
54 value = other;
return *
this;
67 std::auto_ptr<Configuration>
read(
const std::string &path)
throw(
IOException);
88 std::vector<XmlConf::OCSPConf>
ocsp;
112 using namespace digidoc;
115 #ifndef DIGIDOCPP_PATH_REGISTRY_KEY
116 #define DIGIDOCPP_PATH_REGISTRY_KEY "SOFTWARE\\Estonian ID Card\\digidocpp"
144 : logLevel(
Log::InfoType)
145 , pkcs12Disable(false)
160 std::string overrideConf =
util::File::env(
"DIGIDOCPP_OVERRIDE_CONF" );
161 if (!overrideConf.empty())
169 if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT(DIGIDOCPP_PATH_REGISTRY_KEY), 0, KEY_QUERY_VALUE, &hkey)==ERROR_SUCCESS)
171 DWORD dwSize = MAX_PATH *
sizeof(TCHAR);
172 TCHAR tcConfPath[MAX_PATH];
173 DWORD dwRet = RegQueryValueEx(hkey, TEXT(
"ConfigFile"), NULL, NULL, (LPBYTE)tcConfPath, &dwSize);
175 if (dwRet == ERROR_SUCCESS)
178 DEBUG(
"Failed to open registry key \"%s\" ConfigFile value ", DIGIDOCPP_PATH_REGISTRY_KEY);
180 #elif defined(FRAMEWORK)
181 CFStringRef identifier = CFStringCreateWithCString(0,
"ee.ria.digidocpp", kCFStringEncodingUTF8);
182 if(CFBundleRef bundle = CFBundleGetBundleWithIdentifier(identifier))
184 if(CFURLRef url = CFBundleCopyResourcesDirectoryURL(bundle))
187 if(CFURLGetFileSystemRepresentation(url,
TRUE, (UInt8 *)path, PATH_MAX))
196 CFRelease(identifier);
212 xml_schema::Properties props;
213 props.no_namespace_schema_location(
215 return configuration(path, xml_schema::Flags::dont_initialize, props);
217 catch(
const xml_schema::Exception&
e)
219 std::ostringstream oss;
221 THROW_IOEXCEPTION(
"Failed to parse configuration: %s - %s", path.c_str(), oss.str().c_str());
223 return std::auto_ptr<Configuration>(
new Configuration);
249 WARN(
"Failed to read global configuration '%s' file", e.
getMsg().c_str());
259 WARN(
"Failed to read user home configuration '%s' file", e.
getMsg().c_str());
297 DEBUG(
"digidoc::XmlConf::init(%s)", path.c_str());
298 std::auto_ptr<Configuration> conf = read(path);
301 Configuration::ParamSequence paramSeq = conf->param();
302 for( Configuration::ParamSequence::const_iterator it = paramSeq.begin(); it != paramSeq.end(); it++)
304 if(LOG_LEVEL.compare(it->name()) == 0)
305 logLevel.setValue(atoi(std::string(*it).c_str()), it->lock(), global);
306 else if(LOG_FILE.compare(it->name()) == 0)
307 logFile.setValue(*it, it->lock(), global);
308 else if(DIGEST_URI.compare(it->name()) == 0)
309 digestUri.setValue(*it, it->lock(), global);
310 else if(SIGNATURE_URI.compare(it->name()) == 0)
311 signatureUri.setValue(*it, it->lock(), global);
312 else if(MANIFEST_XSD_PATH.compare(it->name()) == 0)
313 manifestXsdPath.setValue(*it, it->lock(), global);
314 else if(XADES_XSD_PATH.compare(it->name()) == 0)
315 xadesXsdPath.setValue(*it, it->lock(), global);
316 else if(DSIG_XSD_PATH.compare(it->name()) == 0)
317 dsigXsdPath.setValue(*it, it->lock(), global);
318 else if(PKCS11_DRIVER_PATH.compare(it->name()) == 0)
319 pkcs11DriverPath.setValue(*it, it->lock(), global);
320 else if(CERT_STORE_PATH.compare(it->name()) == 0)
321 certStorePath.setValue(*it, it->lock(), global);
322 else if(PROXY_HOST.compare(it->name()) == 0)
323 proxyHost.setValue(*it, it->lock(), global);
324 else if(PROXY_PORT.compare(it->name()) == 0)
325 proxyPort.setValue(*it, it->lock(), global);
326 else if(PROXY_USER.compare(it->name()) == 0)
327 proxyUser.setValue(*it, it->lock(), global);
328 else if(PROXY_PASS.compare(it->name()) == 0)
329 proxyPass.setValue(*it, it->lock(), global);
330 else if(PKCS12_CERT.compare(it->name()) == 0)
331 pkcs12Cert.setValue(*it, it->lock(), global);
332 else if(PKCS12_PASS.compare(it->name()) == 0)
333 pkcs12Pass.setValue(*it, it->lock(), global);
334 else if(PKCS12_DISABLE.compare(it->name()) == 0)
335 pkcs12Disable.setValue((*it).compare(
"true") == 0, it->lock(), global);
337 WARN(
"Unknown configuration parameter %s", it->name().c_str());
340 Configuration::OcspSequence ocspSeq = conf->ocsp();
341 for( Configuration::OcspSequence::const_iterator it = ocspSeq.begin(); it != ocspSeq.end(); ++it)
350 catch(
const xml_schema::Exception&
e)
352 std::ostringstream oss;
464 for(std::vector<OCSPConf>::const_iterator
i =
d->
ocsp.begin();
i !=
d->
ocsp.end(); ++
i)
466 if(
i->issuer == issuer)
482 if( path.empty() )
return path;
558 if( d->proxyHost.locked )
572 if( d->proxyPort.locked )
586 if( d->proxyUser.locked )
600 if( d->proxyPass.locked )
615 if( d->pkcs12Cert.locked )
617 d->pkcs12Cert = cert;
629 if( d->pkcs12Pass.locked )
631 d->pkcs12Pass =
pass;
643 if( d->pkcs12Disable.locked )
645 d->pkcs12Disable = disable;
659 std::auto_ptr<Configuration> conf(
new Configuration);
664 Configuration::OcspSequence ocspSeq = conf->ocsp();
665 for(Configuration::OcspSequence::iterator it = ocspSeq.begin(); it != ocspSeq.end(); it++)
667 if (issuer.compare(it->issuer()) == 0)
673 if(url.size() || cert.size())
674 ocspSeq.push_back(Ocsp(url, cert, issuer));
677 catch(
const xml_schema::Exception&
e)
679 std::ostringstream oss;
681 THROW_IOEXCEPTION(
"(in set OCSP) Failed to parse configuration: %s", oss.str().c_str());
683 d->serializeUserConf(*conf);
695 std::auto_ptr<Configuration> conf(
new Configuration);
697 conf = read(USER_CONF_LOC);
700 Configuration::ParamSequence paramSeq = conf->param();
701 for(Configuration::ParamSequence::iterator it = paramSeq.begin(); it != paramSeq.end(); it++)
703 if(paramName.compare(it->name()) == 0)
710 paramSeq.push_back(Param(
value, paramName));
711 conf->param(paramSeq);
713 catch (
const xml_schema::Exception&
e)
715 std::ostringstream oss;
717 THROW_IOEXCEPTION(
"(in set %s) Failed to parse configuration: %s", paramName.c_str(), oss.str().c_str());
719 serializeUserConf(*conf);
733 std::ofstream ofs(enc.c_str());
736 xml_schema::NamespaceInfomap map;
739 configuration(ofs, pConf, map);