~ubuntu-branches/ubuntu/gutsy/kde4libs/gutsy

« back to all changes in this revision

Viewing changes to kio/kssl/ksslcertificate.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-02-21 11:00:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070221110012-6kw8khr9knv6lmg1
Tags: 3.80.3-0ubuntu1
New upstream unstable release

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include <kcodecs.h>
39
39
#include <klocale.h>
40
40
#include <qdatetime.h>
41
 
#include <ktempfile.h>
 
41
#include <ktemporaryfile.h>
42
42
 
43
43
#include <sys/types.h>
44
44
 
201
201
        rc = i18n("Signature Algorithm: ");
202
202
        rc += (i == NID_undef)?i18n("Unknown"):QString(d->kossl->OBJ_nid2ln(i));
203
203
 
204
 
        rc += "\n";
 
204
        rc += '\n';
205
205
        rc += i18n("Signature Contents:");
206
206
        n = d->m_cert->signature->length;
207
207
        s = (char *)d->m_cert->signature->data;
208
208
        for (i = 0; i < n; i++) {
209
209
                if (i%20 != 0) rc += ':';
210
 
                else rc += "\n";
 
210
                else rc += '\n';
211
211
                rc.append(QChar(hv[(s[i]&0xf0)>>4]));
212
212
                rc.append(QChar(hv[s[i]&0x0f]));
213
213
        }
338
338
                #ifndef NO_RSA
339
339
                        if (pkey->type == EVP_PKEY_RSA) {
340
340
                                x = d->kossl->BN_bn2hex(pkey->pkey.rsa->n);
341
 
                                rc = i18n("Key type: RSA (%1 bit)", strlen(x)*4) + "\n";
 
341
                                rc = i18n("Key type: RSA (%1 bit)", strlen(x)*4) + '\n';
342
342
 
343
343
                                rc += i18n("Modulus: ");
344
344
                                for (unsigned int i = 0; i < strlen(x); i++) {
345
345
                                        if (i%40 != 0 && i%2 == 0)
346
346
                                                rc += ':';
347
347
                                        else if (i%40 == 0)
348
 
                                                rc += "\n";
 
348
                                                rc += '\n';
349
349
                                        rc += x[i];
350
350
                                }
351
 
                                rc += "\n";
 
351
                                rc += '\n';
352
352
                                d->kossl->OPENSSL_free(x);
353
353
 
354
354
                                x = d->kossl->BN_bn2hex(pkey->pkey.rsa->e);
361
361
                        if (pkey->type == EVP_PKEY_DSA) {
362
362
                                x = d->kossl->BN_bn2hex(pkey->pkey.dsa->p);
363
363
                                // hack - this may not be always accurate
364
 
                                rc = i18n("Key type: DSA (%1 bit)", strlen(x)*4) + "\n";
 
364
                                rc = i18n("Key type: DSA (%1 bit)", strlen(x)*4) + '\n';
365
365
 
366
366
                                rc += i18n("Prime: ");
367
367
                                for (unsigned int i = 0; i < strlen(x); i++) {
368
368
                                        if (i%40 != 0 && i%2 == 0)
369
369
                                                rc += ':';
370
370
                                        else if (i%40 == 0)
371
 
                                                rc += "\n";
 
371
                                                rc += '\n';
372
372
                                        rc += x[i];
373
373
                                }
374
 
                                rc += "\n";
 
374
                                rc += '\n';
375
375
                                d->kossl->OPENSSL_free(x);
376
376
 
377
377
                                x = d->kossl->BN_bn2hex(pkey->pkey.dsa->q);
380
380
                                        if (i%40 != 0 && i%2 == 0)
381
381
                                                rc += ':';
382
382
                                        else if (i%40 == 0)
383
 
                                                rc += "\n";
 
383
                                                rc += '\n';
384
384
                                        rc += x[i];
385
385
                                }
386
 
                                rc += "\n";
 
386
                                rc += '\n';
387
387
                                d->kossl->OPENSSL_free(x);
388
388
 
389
389
                                x = d->kossl->BN_bn2hex(pkey->pkey.dsa->g);
392
392
                                        if (i%40 != 0 && i%2 == 0)
393
393
                                                rc += ':';
394
394
                                        else if (i%40 == 0)
395
 
                                                rc += "\n";
 
395
                                                rc += '\n';
396
396
                                        rc += x[i];
397
397
                                }
398
 
                                rc += "\n";
 
398
                                rc += '\n';
399
399
                                d->kossl->OPENSSL_free(x);
400
400
 
401
401
                                x = d->kossl->BN_bn2hex(pkey->pkey.dsa->pub_key);
404
404
                                        if (i%40 != 0 && i%2 == 0)
405
405
                                                rc += ':';
406
406
                                        else if (i%40 == 0)
407
 
                                                rc += "\n";
 
407
                                                rc += '\n';
408
408
                                        rc += x[i];
409
409
                                }
410
 
                                rc += "\n";
 
410
                                rc += '\n';
411
411
                                d->kossl->OPENSSL_free(x);
412
412
                        }
413
413
                #endif
990
990
        thecert.prepend(header);
991
991
 
992
992
        if (thecert[thecert.length()-1] != '\n')
993
 
                thecert += "\n";
 
993
                thecert += '\n';
994
994
 
995
995
        thecert.append(footer);
996
996
 
1003
1003
 
1004
1004
// what a piece of crap this is
1005
1005
QByteArray KSSLCertificate::toNetscape() {
1006
 
QByteArray qba;
 
1006
        QByteArray qba;
1007
1007
#ifdef KSSL_HAVE_SSL
1008
 
ASN1_HEADER ah;
1009
 
ASN1_OCTET_STRING os;
1010
 
KTempFile ktf;
 
1008
        ASN1_HEADER ah;
 
1009
        ASN1_OCTET_STRING os;
 
1010
        KTemporaryFile ktf;
 
1011
        ktf.open();
 
1012
        FILE *ktf_fs = fopen(ktf.fileName().toAscii(), "r+");
1011
1013
 
1012
1014
        os.data = (unsigned char *)NETSCAPE_CERT_HDR;
1013
1015
        os.length = strlen(NETSCAPE_CERT_HDR);
1015
1017
        ah.data = (char *)getCert();
1016
1018
        ah.meth = d->kossl->X509_asn1_meth();
1017
1019
 
1018
 
        d->kossl->ASN1_i2d_fp(ktf.fstream(),(unsigned char *)&ah);
1019
 
 
1020
 
        ktf.close();
1021
 
 
1022
 
        QFile qf(ktf.name());
 
1020
        d->kossl->ASN1_i2d_fp(ktf_fs,(unsigned char *)&ah);
 
1021
        fclose(ktf_fs);
 
1022
 
 
1023
        QFile qf(ktf.fileName());
1023
1024
        qf.open(QIODevice::ReadOnly);
1024
1025
        char *buf = new char[qf.size()];
1025
1026
        qf.read(buf, qf.size());
1027
1028
        qf.close();
1028
1029
        delete[] buf;
1029
1030
 
1030
 
        ktf.unlink();
1031
 
 
1032
1031
#endif
1033
1032
return qba;
1034
1033
}
1038
1037
QString KSSLCertificate::toText() {
1039
1038
QString text;
1040
1039
#ifdef KSSL_HAVE_SSL
1041
 
KTempFile ktf;
1042
 
 
1043
 
        d->kossl->X509_print(ktf.fstream(), getCert());
1044
 
        ktf.close();
1045
 
 
1046
 
        QFile qf(ktf.name());
 
1040
        KTemporaryFile ktf;
 
1041
        ktf.open();
 
1042
        FILE *ktf_fs = fopen(ktf.fileName().toAscii(), "r+");
 
1043
 
 
1044
        d->kossl->X509_print(ktf_fs, getCert());
 
1045
        fclose(ktf_fs);
 
1046
 
 
1047
        QFile qf(ktf.fileName());
1047
1048
        qf.open(QIODevice::ReadOnly);
1048
1049
        char *buf = new char[qf.size()+1];
1049
1050
        qf.read(buf, qf.size());
1051
1052
        text = buf;
1052
1053
        delete[] buf;
1053
1054
        qf.close();
1054
 
        ktf.unlink();
1055
1055
#endif
1056
1056
return text;
1057
1057
}