23 #include <ksslconfig.h>
27 #include <QtCore/QString>
28 #include <QtCore/QFile>
38 #define sk_new kossl->sk_new
39 #define sk_push kossl->sk_push
40 #define sk_free kossl->sk_free
41 #define sk_value kossl->sk_value
42 #define sk_num kossl->sk_num
43 #define sk_dup kossl->sk_dup
44 #define sk_pop kossl->sk_pop
53 kossl = KOSSL::self();
60 if (_pkey) kossl->EVP_PKEY_free(_pkey);
63 X509* x5 = sk_X509_pop(_caStack);
67 sk_X509_free(_caStack);
69 if (_pkcs) kossl->PKCS12_free(_pkcs);
80 if (base64.isEmpty())
return NULL;
81 QByteArray qba = QByteArray::fromBase64(base64.toLatin1());
95 PKCS12 *newpkcs = NULL;
97 if (!qf.open(QIODevice::ReadOnly))
100 FILE *
fp = fdopen(qf.handle(),
"r");
101 if (!fp)
return NULL;
103 newpkcs = KOSSL::self()->d2i_PKCS12_fp(fp, &newpkcs);
107 KOSSL::self()->ERR_clear_error();
115 if (!c->
parse(password)) {
135 return (0 == kossl->PKCS12_newpass(_pkcs,
136 pold.isNull() ? (
char *)
"" : (
char *)pold.toLatin1().constData(),
137 pnew.isNull() ? (
char *)
"" : (
char *)pnew.toLatin1().constData()));
150 if (_pkey) kossl->EVP_PKEY_free(_pkey);
153 X509* x5 = sk_X509_pop(_caStack);
155 kossl->X509_free(x5);
157 sk_X509_free(_caStack);
163 int rc = kossl->PKCS12_parse(_pkcs, pass.toLatin1(), &_pkey, &x, &_caStack);
178 kossl->ERR_clear_error();
202 len = kossl->i2d_PKCS12(_pkcs, NULL);
204 char *buf =
new char[len];
205 p = (
unsigned char *)buf;
206 kossl->i2d_PKCS12(_pkcs, &p);
207 base64 = QByteArray::fromRawData(buf, len).toBase64();
220 if (!out.open(QIODevice::WriteOnly))
return false;
222 int fd = out.handle();
223 FILE *
fp = fdopen(fd,
"w");
226 unlink(filename.toLatin1());
230 kossl->i2d_PKCS12_fp(fp, _pkcs);
247 if (1 != kossl->X509_check_private_key(_cert->
getCert(), _pkey)) {