21 #include <ksslcertificatehome.h>
22 #include <ksslcertificate.h>
23 #include <ksslpkcs12.h>
25 #include <kresolver.h>
26 #include <ksimpleconfig.h>
28 using namespace KNetwork;
30 TQStringList KSSLCertificateHome::getCertificateList() {
31 KSimpleConfig cfg(
"ksslcertificates",
false);
32 TQStringList list = cfg.groupList();
33 TQString defaultstr(
"<default>");
34 TQString blankstr(
"");
36 list.remove(defaultstr);
37 list.remove(blankstr);
44 void KSSLCertificateHome::setDefaultCertificate(TQString name, TQString host,
bool send,
bool prompt) {
45 KSimpleConfig cfg(
"ksslauthmap",
false);
50 cfg.setGroup(KResolver::domainToAscii(host));
52 cfg.writeEntry(
"certificate", name);
53 cfg.writeEntry(
"send", send);
54 cfg.writeEntry(
"prompt", prompt);
60 void KSSLCertificateHome::setDefaultCertificate(
KSSLPKCS12 *cert, TQString host,
bool send,
bool prompt) {
62 KSSLCertificateHome::setDefaultCertificate(cert->
name(), host, send, prompt);
67 bool KSSLCertificateHome::addCertificate(TQString filename, TQString password,
bool storePass) {
70 if (!pkcs)
return false;
72 KSSLCertificateHome::addCertificate(pkcs, storePass?password:TQString(
""));
80 bool KSSLCertificateHome::addCertificate(
KSSLPKCS12 *cert, TQString passToStore) {
81 if (!cert)
return false;
83 KSimpleConfig cfg(
"ksslcertificates",
false);
85 cfg.setGroup(cert->
name());
86 cfg.writeEntry(
"PKCS12Base64", cert->
toString());
87 cfg.writeEntry(
"Password", passToStore);
92 bool KSSLCertificateHome::deleteCertificate(
const TQString &filename,
const TQString &password) {
95 if (!pkcs)
return false;
97 bool ok = deleteCertificate(pkcs);
103 bool KSSLCertificateHome::deleteCertificate(
KSSLPKCS12 *cert) {
104 if (!cert)
return false;
106 return deleteCertificateByName(cert->
name());
109 bool KSSLCertificateHome::deleteCertificateByName(
const TQString &name) {
110 if (name.isEmpty())
return false;
112 KSimpleConfig cfg(
"ksslcertificates",
false);
114 bool ok = cfg.deleteGroup(name);
121 KSSLPKCS12* KSSLCertificateHome::getCertificateByName(TQString name, TQString password) {
122 KSimpleConfig cfg(
"ksslcertificates",
false);
123 if (!cfg.hasGroup(name))
return NULL;
132 KSSLPKCS12* KSSLCertificateHome::getCertificateByName(TQString name) {
133 KSimpleConfig cfg(
"ksslcertificates",
false);
134 if (!cfg.hasGroup(name))
return NULL;
143 bool KSSLCertificateHome::hasCertificateByName(TQString name) {
144 KSimpleConfig cfg(
"ksslcertificates",
false);
145 if (!cfg.hasGroup(name))
return false;
150 KSSLPKCS12* KSSLCertificateHome::getCertificateByHost(TQString host, TQString password, KSSLAuthAction *aa) {
151 return KSSLCertificateHome::getCertificateByName(KSSLCertificateHome::getDefaultCertificateName(host, aa), password);
156 TQString KSSLCertificateHome::getDefaultCertificateName(TQString host, KSSLAuthAction *aa) {
157 KSimpleConfig cfg(
"ksslauthmap",
false);
160 if (!cfg.hasGroup(host)) {
162 if (!cfg.hasGroup(KResolver::domainToAscii(host))) {
164 if (aa) *aa = AuthNone;
165 return TQString::null;
170 cfg.setGroup(KResolver::domainToAscii(host));
173 bool tmp = cfg.readBoolEntry(
"send",
false);
176 tmp = cfg.readBoolEntry(
"prompt",
false);
183 return cfg.readEntry(
"certificate",
"");
188 TQString KSSLCertificateHome::getDefaultCertificateName(KSSLAuthAction *aa) {
189 TDEConfig cfg(
"cryptodefaults",
false);
191 cfg.setGroup(
"Auth");
193 TQString am = cfg.readEntry(
"AuthMethod",
"");
196 else if (am ==
"prompt")
202 return cfg.readEntry(
"DefaultCert",
"");
207 KSSLPKCS12* KSSLCertificateHome::getDefaultCertificate(TQString password, KSSLAuthAction *aa) {
208 TQString name = KSSLCertificateHome::getDefaultCertificateName(aa);
209 KSimpleConfig cfg(
"ksslcertificates",
false);
211 if (name.isEmpty())
return NULL;
219 KSSLPKCS12* KSSLCertificateHome::getDefaultCertificate(KSSLAuthAction *aa) {
220 TQString name = KSSLCertificateHome::getDefaultCertificateName(aa);
221 KSimpleConfig cfg(
"ksslcertificates",
false);
223 if (name.isEmpty())
return NULL;
227 cfg.readEntry(
"Password",
""));
232 void KSSLCertificateHome::setDefaultCertificate(TQString name,
bool send,
bool prompt) {
233 KSimpleConfig cfg(
"ksslauthmap",
false);
235 cfg.setGroup(
"<default>");
236 cfg.writeEntry(
"defaultCertificate", name);
237 cfg.writeEntry(
"send", send);
238 cfg.writeEntry(
"prompt", prompt);
242 void KSSLCertificateHome::setDefaultCertificate(
KSSLPKCS12 *cert,
bool send,
bool prompt) {
244 KSSLCertificateHome::setDefaultCertificate(cert->
name(), send, prompt);
TQString name()
The name of this certificate.
TQString toString()
Convert to a Base64 string.
static KSSLPKCS12 * fromString(TQString base64, TQString password="")
Create a KSSLPKCS12 object from a Base64 in a TQString.
static KSSLPKCS12 * loadCertFile(TQString filename, TQString password="")
Create a KSSLPKCS12 object by reading a PKCS#12 file.