Changeset 846 for trunk/src/network/ssl


Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
1 deleted
25 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/network/ssl/qssl.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/src/network/ssl/qssl.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/src/network/ssl/qsslcertificate.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    260260/*!
    261261    Returns the certificate's serial number string in decimal format.
     262
     263
     264
    262265*/
    263266QByteArray QSslCertificate::serialNumber() const
    264267{
    265     if (d->serialNumberString.isEmpty() && d->x509)
    266         d->serialNumberString =
    267             QByteArray::number(qlonglong(q_ASN1_INTEGER_get(d->x509->cert_info->serialNumber)));
    268 
     268    if (d->serialNumberString.isEmpty() && d->x509) {
     269        ASN1_INTEGER *serialNumber = d->x509->cert_info->serialNumber;
     270        // if we cannot convert to a long, just output the hexadecimal number
     271        if (serialNumber->length > 4) {
     272            QByteArray hexString;
     273            hexString.reserve(serialNumber->length * 3);
     274            for (int a = 0; a < serialNumber->length; ++a) {
     275                hexString += QByteArray::number(serialNumber->data[a], 16).rightJustified(2, '0');
     276                hexString += ':';
     277            }
     278            hexString.chop(1);
     279            d->serialNumberString = hexString;
     280        } else {
     281            d->serialNumberString = QByteArray::number(qlonglong(q_ASN1_INTEGER_get(serialNumber)));
     282        }
     283    }
    269284    return d->serialNumberString;
    270285}
     
    534549    int startIndex = 0;
    535550    if (pathPrefix.trimmed().isEmpty()) {
    536         startIndex = 2;
    537         pathPrefix = QLatin1String(".");
     551        if(path.startsWith(QLatin1Char('/'))) {
     552            pathPrefix = path.left(path.indexOf(QRegExp(QLatin1String("[\\*\\?\\[]"))));
     553            pathPrefix = path.left(path.lastIndexOf(QLatin1Char('/')));
     554        } else {
     555            startIndex = 2;
     556            pathPrefix = QLatin1String(".");
     557        }
    538558    }
    539559
     
    697717static bool matchLineFeed(const QByteArray &pem, int *offset)
    698718{
    699     char ch;
     719    char ch;
    700720
    701721    // ignore extra whitespace at the end of the line
  • trunk/src/network/ssl/qsslcertificate.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/src/network/ssl/qsslcertificate_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/src/network/ssl/qsslcipher.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/src/network/ssl/qsslcipher.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/src/network/ssl/qsslcipher_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/src/network/ssl/qsslconfiguration.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    486486  Returns this connection's CA certificate database. The CA certificate
    487487  database is used by the socket during the handshake phase to
    488   validate the peer's certificate. It can be moodified prior to the
    489   handshake with addCaCertificate(), addCaCertificates(), and
    490   setCaCertificates().
     488  validate the peer's certificate. It can be modified prior to the
     489  handshake with setCaCertificates(), or with \l{QSslSocket}'s
     490  \l{QSslSocket::}{addCaCertificate()} and
     491  \l{QSslSocket::}{addCaCertificates()}.
    491492
    492493  \sa setCaCertificates()
  • trunk/src/network/ssl/qsslconfiguration.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/src/network/ssl/qsslconfiguration_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/src/network/ssl/qsslerror.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/src/network/ssl/qsslerror.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/src/network/ssl/qsslkey.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/src/network/ssl/qsslkey.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/src/network/ssl/qsslkey_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/src/network/ssl/qsslsocket.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    211211    signal. This mode is the default for clients.
    212212
    213     \value AutoVerifyPeer QSslSocket will automaticaly use QueryPeer for
     213    \value AutoVerifyPeer QSslSocket will automaticaly use QueryPeer for
    214214    server sockets and VerifyPeer for client sockets.
    215215
     
    297297#include <QtCore/qdebug.h>
    298298#include <QtCore/qdir.h>
    299 #include <QtCore/qdatetime.h>
    300299#include <QtCore/qmutex.h>
     300
    301301#include <QtNetwork/qhostaddress.h>
    302302#include <QtNetwork/qhostinfo.h>
     
    575575
    576576    The default mode is AutoVerifyPeer, which tells QSslSocket to use
    577     VerifyPeer for clients, QueryPeer for clients.
     577    VerifyPeer for clientss.
    578578
    579579    \sa setPeerVerifyMode(), peerVerifyDepth(), mode()
     
    595595
    596596    The default mode is AutoVerifyPeer, which tells QSslSocket to use
    597     VerifyPeer for clients, QueryPeer for clients.
     597    VerifyPeer for clientss.
    598598
    599599    Setting this mode after encryption has started has no effect on the
     
    13301330    Returns the current default CA certificate database. This database
    13311331    is originally set to your system's default CA certificate database.
    1332     If no system default database is found, Qt will provide its own
    1333     default database. You can override the default CA certificate database
     1332    If no system default database is found,
     1333    . You can override the default CA certificate database
    13341334    with your own CA certificate database using setDefaultCaCertificates().
    13351335
     
    13451345
    13461346/*!
    1347     This function provides a default CA certificate database
    1348     shipped together with Qt. The CA certificate database
     1347    This function provides CA certificate database
     1348    . The CA certificate database
    13491349    returned by this function is used to initialize the database
    13501350    returned by defaultCaCertificates(). You can replace that database
     
    13551355QList<QSslCertificate> QSslSocket::systemCaCertificates()
    13561356{
    1357     QSslSocketPrivate::ensureInitialized();
     1357   
    13581358    return QSslSocketPrivate::systemCaCertificates();
    13591359}
     
    14041404        return false;
    14051405
    1406     QTime stopWatch;
     1406    Q stopWatch;
    14071407    stopWatch.start();
    14081408
     
    14441444    d->readyReadEmittedPointer = &readyReadEmitted;
    14451445
    1446     QTime stopWatch;
     1446    Q stopWatch;
    14471447    stopWatch.start();
    14481448
     
    14811481        return d->plainSocket->waitForBytesWritten(msecs);
    14821482
    1483     QTime stopWatch;
     1483    Q stopWatch;
    14841484    stopWatch.start();
    14851485
     
    15191519        return d->plainSocket->waitForDisconnected(msecs);
    15201520
    1521     QTime stopWatch;
     1521    Q stopWatch;
    15221522    stopWatch.start();
    15231523
     
    15571557bool QSslSocket::supportsSsl()
    15581558{
    1559     return QSslSocketPrivate::ensureInitialized();
     1559    return QSslSocketPrivate::();
    15601560}
    15611561
     
    19661966    QMutexLocker locker(&globalData()->mutex);
    19671967    const QSslConfigurationPrivate *global = globalData()->config.constData();
     1968
     1969
     1970
     1971
     1972
    19681973
    19691974    ptr->ref = 1;
     
    20312036}
    20322037
     2038
     2039
     2040
     2041
     2042
     2043
     2044
     2045
     2046
     2047
     2048
     2049
     2050
     2051
    20332052/*!
    20342053    \internal
  • trunk/src/network/ssl/qsslsocket.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/src/network/ssl/qsslsocket_openssl.cpp

    r788 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    5252#include <QtCore/qdir.h>
    5353#include <QtCore/qdiriterator.h>
     54
    5455#include <QtCore/qfile.h>
    5556#include <QtCore/qfileinfo.h>
     
    5859#include <QtCore/qurl.h>
    5960#include <QtCore/qvarlengtharray.h>
    60 
    61 static void initNetworkResources()
    62 {
    63     // Initialize resources
    64     Q_INIT_RESOURCE(network);
    65 }
     61#include <QLibrary> // for loading the security lib for the CA store
    6662
    6763QT_BEGIN_NAMESPACE
    6864
    69 // Useful defines
    70 #define SSL_ERRORSTR() QString::fromLocal8Bit(q_ERR_error_string(q_ERR_get_error(), NULL))
     65#if defined(Q_OS_MAC)
     66#define kSecTrustSettingsDomainSystem 2 // so we do not need to include the header file
     67    PtrSecCertificateGetData QSslSocketPrivate::ptrSecCertificateGetData = 0;
     68    PtrSecTrustSettingsCopyCertificates QSslSocketPrivate::ptrSecTrustSettingsCopyCertificates = 0;
     69    PtrSecTrustCopyAnchorCertificates QSslSocketPrivate::ptrSecTrustCopyAnchorCertificates = 0;
     70#elif defined(Q_OS_WIN)
     71    PtrCertOpenSystemStoreW QSslSocketPrivate::ptrCertOpenSystemStoreW = 0;
     72    PtrCertFindCertificateInStore QSslSocketPrivate::ptrCertFindCertificateInStore = 0;
     73    PtrCertCloseStore QSslSocketPrivate::ptrCertCloseStore = 0;
     74#elif defined(Q_OS_SYMBIAN)
     75#include <e32base.h>
     76#include <e32std.h>
     77#include <e32debug.h>
     78#include <QtCore/private/qcore_symbian_p.h>
     79#endif
     80
     81bool QSslSocketPrivate::s_libraryLoaded = false;
     82bool QSslSocketPrivate::s_loadedCiphersAndCerts = false;
    7183
    7284/* \internal
     
    147159static unsigned long id_function()
    148160{
    149     return (unsigned long)QThread::currentThreadId();
     161    return ()QThread::currentThreadId();
    150162}
    151163} // extern "C"
     
    154166    : ssl(0),
    155167      ctx(0),
     168
    156169      readBio(0),
    157170      writeBio(0),
     
    258271
    259272        // ### Bad error code
    260         q->setErrorString(QSslSocket::tr("Error creating SSL context (%1)").arg(SSL_ERRORSTR()));
     273        q->setErrorString(QSslSocket::tr("Error creating SSL context (%1)").arg(()));
    261274        q->setSocketError(QAbstractSocket::UnknownSocketError);
    262275        emit q->error(QAbstractSocket::UnknownSocketError);
     
    283296    if (!q_SSL_CTX_set_cipher_list(ctx, cipherString.data())) {
    284297        // ### Bad error code
    285         q->setErrorString(QSslSocket::tr("Invalid or empty cipher list (%1)").arg(SSL_ERRORSTR()));
     298        q->setErrorString(QSslSocket::tr("Invalid or empty cipher list (%1)").arg(()));
    286299        q->setSocketError(QAbstractSocket::UnknownSocketError);
    287300        emit q->error(QAbstractSocket::UnknownSocketError);
     
    290303
    291304    // Add all our CAs to this store.
    292     foreach (const QSslCertificate &caCertificate, q->caCertificates())
     305    QList<QSslCertificate> expiredCerts;
     306    foreach (const QSslCertificate &caCertificate, q->caCertificates()) {
     307        // add expired certs later, so that the
     308        // valid ones are used before the expired ones
     309        if (! caCertificate.isValid()) {
     310            expiredCerts.append(caCertificate);
     311        } else {
     312            q_X509_STORE_add_cert(ctx->cert_store, (X509 *)caCertificate.handle());
     313        }
     314    }
     315    // now add the expired certs
     316    foreach (const QSslCertificate &caCertificate, expiredCerts) {
    293317        q_X509_STORE_add_cert(ctx->cert_store, (X509 *)caCertificate.handle());
     318
    294319
    295320    // Register a custom callback to get all verification errors.
     
    299324        // Require a private key as well.
    300325        if (configuration.privateKey.isNull()) {
    301             q->setErrorString(QSslSocket::tr("Cannot provide a certificate with no key, %1").arg(SSL_ERRORSTR()));
     326            q->setErrorString(QSslSocket::tr("Cannot provide a certificate with no key, %1").arg(()));
    302327            emit q->error(QAbstractSocket::UnknownSocketError);
    303328            return false;
     
    306331        // Load certificate
    307332        if (!q_SSL_CTX_use_certificate(ctx, (X509 *)configuration.localCertificate.handle())) {
    308             q->setErrorString(QSslSocket::tr("Error loading local certificate, %1").arg(SSL_ERRORSTR()));
     333            q->setErrorString(QSslSocket::tr("Error loading local certificate, %1").arg(()));
    309334            emit q->error(QAbstractSocket::UnknownSocketError);
    310335            return false;
     
    312337
    313338        // Load private key
    314         EVP_PKEY *pkey = q_EVP_PKEY_new();
     339        pkey = q_EVP_PKEY_new();
     340        // before we were using EVP_PKEY_assign_R* functions and did not use EVP_PKEY_free.
     341        // this lead to a memory leak. Now we use the *_set1_* functions which do not
     342        // take ownership of the RSA/DSA key instance because the QSslKey already has ownership.
    315343        if (configuration.privateKey.algorithm() == QSsl::Rsa)
    316             q_EVP_PKEY_assign_RSA(pkey, (RSA *)configuration.privateKey.handle());
     344            q_EVP_PKEY__RSA(pkey, (RSA *)configuration.privateKey.handle());
    317345        else
    318             q_EVP_PKEY_assign_DSA(pkey, (DSA *)configuration.privateKey.handle());
     346            q_EVP_PKEY__DSA(pkey, (DSA *)configuration.privateKey.handle());
    319347        if (!q_SSL_CTX_use_PrivateKey(ctx, pkey)) {
    320             q->setErrorString(QSslSocket::tr("Error loading private key, %1").arg(SSL_ERRORSTR()));
     348            q->setErrorString(QSslSocket::tr("Error loading private key, %1").arg(()));
    321349            emit q->error(QAbstractSocket::UnknownSocketError);
    322350            return false;
     
    325353        // Check if the certificate matches the private key.
    326354        if (!q_SSL_CTX_check_private_key(ctx)) {
    327             q->setErrorString(QSslSocket::tr("Private key does not certify public key, %1").arg(SSL_ERRORSTR()));
     355            q->setErrorString(QSslSocket::tr("Private key does not certify public key, %1").arg(()));
    328356            emit q->error(QAbstractSocket::UnknownSocketError);
    329357            return false;
     
    345373    if (!(ssl = q_SSL_new(ctx))) {
    346374        // ### Bad error code
    347         q->setErrorString(QSslSocket::tr("Error creating SSL session, %1").arg(SSL_ERRORSTR()));
     375        q->setErrorString(QSslSocket::tr("Error creating SSL session, %1").arg(()));
    348376        q->setSocketError(QAbstractSocket::UnknownSocketError);
    349377        emit q->error(QAbstractSocket::UnknownSocketError);
     
    360388    if (!readBio || !writeBio) {
    361389        // ### Bad error code
    362         q->setErrorString(QSslSocket::tr("Error creating SSL session: %1").arg(SSL_ERRORSTR()));
     390        q->setErrorString(QSslSocket::tr("Error creating SSL session: %1").arg(()));
    363391        q->setSocketError(QAbstractSocket::UnknownSocketError);
    364392        emit q->error(QAbstractSocket::UnknownSocketError);
     
    389417    \internal
    390418
    391     Declared static in QSslSocketPrivate, makes sure the SSL libraries have
    392     been initialized.
     419    D
     420    .
    393421*/
    394 bool QSslSocketPrivate::ensureInitialized()
     422
     423bool QSslSocketPrivate::supportsSsl()
     424{
     425    return ensureLibraryLoaded();
     426}
     427
     428bool QSslSocketPrivate::ensureLibraryLoaded()
    395429{
    396430    if (!q_resolveOpenSslSymbols())
     
    399433    // Check if the library itself needs to be initialized.
    400434    QMutexLocker locker(openssl_locks()->initLock());
    401     static int q_initialized = false;
    402     if (!q_initialized) {
    403         q_initialized = true;
    404 
    405         // Initialize resources
    406         initNetworkResources();
     435    if (!s_libraryLoaded) {
     436        s_libraryLoaded = true;
    407437
    408438        // Initialize OpenSSL.
     
    441471                return false;
    442472        }
    443 
    444         resetDefaultCiphers();
    445         setDefaultCaCertificates(systemCaCertificates());
    446473    }
    447474    return true;
     475
     476
     477
     478
     479
     480
     481
     482
     483
     484
     485
     486
     487
     488
     489
     490
     491
     492
     493
     494
     495
     496
     497
     498
     499
     500
     501
     502
     503
     504
     505
     506
     507
     508
     509
     510
     511
     512
     513
     514
     515
     516
     517
     518
     519
     520
     521
     522
     523
     524
     525
     526
     527
     528
     529
     530
     531
     532
     533
     534
     535
     536
    448537}
    449538
     
    481570}
    482571
     572
     573
     574
     575
     576
     577
     578
     579
     580
     581
     582
     583
     584
     585
     586
     587
     588
     589
     590
     591
     592
     593
     594
     595
     596
     597
     598
     599
     600
     601
     602
     603
     604
     605
     606
     607
     608
     609
     610
     611
     612
     613
     614
     615
     616
     617
     618
     619
     620
     621
     622
     623
     624
     625
     626
     627
     628
     629
     630
     631
     632
     633
     634
     635
     636
     637
     638
     639
     640
     641
     642
     643
     644
     645
     646
     647
     648
     649
     650
     651
     652
     653
     654
     655
     656
     657
     658
     659
     660
     661
     662
     663
     664
     665
     666
     667
     668
     669
     670
     671
     672
     673
     674
     675
     676
     677
     678
     679
     680
     681
     682
     683
     684
     685
     686
     687
     688
     689
     690
     691
     692
     693
     694
     695
     696
     697
     698
     699
     700
     701
     702
     703
     704
     705
     706
     707
     708
     709
     710
     711
     712
     713
     714
     715
     716
     717
     718
     719
     720
     721
     722
     723
     724
     725
     726
     727
     728
     729
     730
     731
     732
     733
     734
     735
     736
     737
     738
     739
     740
     741
     742
     743
     744
     745
    483746QList<QSslCertificate> QSslSocketPrivate::systemCaCertificates()
    484747{
    485     // Qt provides a default bundle of certificates
    486     QFile caBundle(QLatin1String(":/trolltech/network/ssl/qt-ca-bundle.crt"));
    487     if (caBundle.open(QIODevice::ReadOnly | QIODevice::Text))
    488         return QSslCertificate::fromDevice(&caBundle);
    489 
    490     // Unreachable; return no bundle.
    491     return QList<QSslCertificate>();
     748    ensureInitialized();
     749#ifdef QSSLSOCKET_DEBUG
     750    QElapsedTimer timer;
     751    timer.start();
     752#endif
     753    QList<QSslCertificate> systemCerts;
     754#if defined(Q_OS_MAC)
     755    CFArrayRef cfCerts;
     756    OSStatus status = 1;
     757
     758    OSStatus SecCertificateGetData (
     759       SecCertificateRef certificate,
     760       CSSM_DATA_PTR data
     761    );
     762
     763    if (ptrSecCertificateGetData) {
     764        if (ptrSecTrustSettingsCopyCertificates)
     765            status = ptrSecTrustSettingsCopyCertificates(kSecTrustSettingsDomainSystem, &cfCerts);
     766        else if (ptrSecTrustCopyAnchorCertificates)
     767            status = ptrSecTrustCopyAnchorCertificates(&cfCerts);
     768        if (!status) {
     769            CFIndex size = CFArrayGetCount(cfCerts);
     770            for (CFIndex i = 0; i < size; ++i) {
     771                SecCertificateRef cfCert = (SecCertificateRef)CFArrayGetValueAtIndex(cfCerts, i);
     772                CSSM_DATA data;
     773                CSSM_DATA_PTR dataPtr = &data;
     774                if (ptrSecCertificateGetData(cfCert, dataPtr)) {
     775                    qWarning("error retrieving a CA certificate from the system store");
     776                } else {
     777                    int len = data.Length;
     778                    char *rawData = reinterpret_cast<char *>(data.Data);
     779                    QByteArray rawCert(rawData, len);
     780                    systemCerts.append(QSslCertificate::fromData(rawCert, QSsl::Der));
     781                }
     782            }
     783        }
     784        else {
     785           // no detailed error handling here
     786           qWarning("could not retrieve system CA certificates");
     787        }
     788    }
     789#elif defined(Q_OS_WIN)
     790    if (ptrCertOpenSystemStoreW && ptrCertFindCertificateInStore && ptrCertCloseStore) {
     791        HCERTSTORE hSystemStore;
     792#if defined(Q_OS_WINCE)
     793        hSystemStore = ptrCertOpenSystemStoreW(CERT_STORE_PROV_SYSTEM_W,
     794                                               0,
     795                                               0,
     796                                               CERT_STORE_NO_CRYPT_RELEASE_FLAG|CERT_SYSTEM_STORE_CURRENT_USER,
     797                                               L"ROOT");
     798#else
     799        hSystemStore = ptrCertOpenSystemStoreW(0, L"ROOT");
     800#endif
     801        if(hSystemStore) {
     802            PCCERT_CONTEXT pc = NULL;
     803            while(1) {
     804                pc = ptrCertFindCertificateInStore( hSystemStore, X509_ASN_ENCODING, 0, CERT_FIND_ANY, NULL, pc);
     805                if(!pc)
     806                    break;
     807                QByteArray der((const char *)(pc->pbCertEncoded), static_cast<int>(pc->cbCertEncoded));
     808                QSslCertificate cert(der, QSsl::Der);
     809                systemCerts.append(cert);
     810            }
     811            ptrCertCloseStore(hSystemStore, 0);
     812        }
     813    }
     814#elif defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
     815    QSet<QString> certFiles;
     816    QList<QByteArray> directories;
     817    directories << "/etc/ssl/certs/"; // (K)ubuntu, OpenSUSE, Mandriva, MeeGo ...
     818    directories << "/usr/lib/ssl/certs/"; // Gentoo, Mandrake
     819    directories << "/usr/share/ssl/"; // Centos, Redhat, SuSE
     820    directories << "/usr/local/ssl/"; // Normal OpenSSL Tarball
     821    directories << "/var/ssl/certs/"; // AIX
     822    directories << "/usr/local/ssl/certs/"; // Solaris
     823    directories << "/opt/openssl/certs/"; // HP-UX
     824
     825    QDir currentDir;
     826    QStringList nameFilters;
     827    nameFilters << QLatin1String("*.pem") << QLatin1String("*.crt");
     828    currentDir.setNameFilters(nameFilters);
     829    for (int a = 0; a < directories.count(); a++) {
     830        currentDir.setPath(QLatin1String(directories.at(a)));
     831        QDirIterator it(currentDir);
     832        while(it.hasNext()) {
     833            it.next();
     834            // use canonical path here to not load the same certificate twice if symlinked
     835            certFiles.insert(it.fileInfo().canonicalFilePath());
     836        }
     837    }
     838    QSetIterator<QString> it(certFiles);
     839    while(it.hasNext()) {
     840        systemCerts.append(QSslCertificate::fromPath(it.next()));
     841    }
     842    systemCerts.append(QSslCertificate::fromPath(QLatin1String("/etc/pki/tls/certs/ca-bundle.crt"), QSsl::Pem)); // Fedora, Mandriva
     843    systemCerts.append(QSslCertificate::fromPath(QLatin1String("/usr/local/share/certs/ca-root-nss.crt"), QSsl::Pem)); // FreeBSD's ca_root_nss
     844
     845#elif defined(Q_OS_SYMBIAN)
     846    QList<QByteArray> certs;
     847    QScopedPointer<CSymbianCertificateRetriever> retriever(CSymbianCertificateRetriever::NewL());
     848
     849    retriever->GetCertificates(certs);
     850    foreach (const QByteArray &encodedCert, certs) {
     851        QSslCertificate cert(encodedCert, QSsl::Der);
     852        if (!cert.isNull()) {
     853#ifdef QSSLSOCKET_DEBUG
     854            qDebug() << "imported certificate: " << cert.issuerInfo(QSslCertificate::CommonName);
     855#endif
     856            systemCerts.append(cert);
     857        }
     858    }
     859#endif
     860#ifdef QSSLSOCKET_DEBUG
     861    qDebug() << "systemCaCertificates retrieval time " << timer.elapsed() << "ms";
     862    qDebug() << "imported " << systemCerts.count() << " certificates";
     863#endif
     864
     865    return systemCerts;
    492866}
    493867
     
    544918                if (writtenBytes <= 0) {
    545919                    // ### Better error handling.
    546                     q->setErrorString(QSslSocket::tr("Unable to write data: %1").arg(SSL_ERRORSTR()));
     920                    q->setErrorString(QSslSocket::tr("Unable to write data: %1").arg(()));
    547921                    q->setSocketError(QAbstractSocket::UnknownSocketError);
    548922                    emit q->error(QAbstractSocket::UnknownSocketError);
     
    607981                } else {
    608982                    // ### Better error handling.
    609                     q->setErrorString(QSslSocket::tr("Unable to decrypt data: %1").arg(SSL_ERRORSTR()));
     983                    q->setErrorString(QSslSocket::tr("Unable to decrypt data: %1").arg(()));
    610984                    q->setSocketError(QAbstractSocket::UnknownSocketError);
    611985                    emit q->error(QAbstractSocket::UnknownSocketError);
     
    6811055                plainSocket->disconnectFromHost();
    6821056                break;
     1057
     1058
     1059
     1060
     1061
     1062
     1063
     1064
    6831065            default:
    684                 // ### Handle errors better.
    685                 q->setErrorString(QSslSocket::tr("Error while reading: %1").arg(SSL_ERRORSTR()));
     1066                // SSL_ERROR_WANT_CONNECT, SSL_ERROR_WANT_ACCEPT: can only happen with a
     1067                // BIO_s_connect() or BIO_s_accept(), which we do not call.
     1068                // SSL_ERROR_WANT_X509_LOOKUP: can only happen with a
     1069                // SSL_CTX_set_client_cert_cb(), which we do not call.
     1070                // So this default case should never be triggered.
     1071                q->setErrorString(QSslSocket::tr("Error while reading: %1").arg(getErrorsFromOpenSsl()));
    6861072                q->setSocketError(QAbstractSocket::UnknownSocketError);
    6871073                emit q->error(QAbstractSocket::UnknownSocketError);
     
    7781164            break;
    7791165        default:
    780             // ### Handle errors better
    781             q->setErrorString(QSslSocket::tr("Error during SSL handshake: %1").arg(SSL_ERRORSTR()));
     1166            q->setErrorString(QSslSocket::tr("Error during SSL handshake: %1").arg(getErrorsFromOpenSsl()));
    7821167            q->setSocketError(QAbstractSocket::SslHandshakeFailedError);
    7831168#ifdef QSSLSOCKET_DEBUG
     
    8161201            QString commonName = configuration.peerCertificate.subjectInfo(QSslCertificate::CommonName);
    8171202
    818             QRegExp regexp(commonName, Qt::CaseInsensitive, QRegExp::Wildcard);
    819             if (!regexp.exactMatch(peerName)) {
     1203            if (!isMatchingHostname(commonName.toLower(), peerName.toLower())) {
    8201204                bool matched = false;
    8211205                foreach (const QString &altName, configuration.peerCertificate
    8221206                         .alternateSubjectNames().values(QSsl::DnsEntry)) {
    823                     regexp.setPattern(altName);
    824                     if (regexp.exactMatch(peerName)) {
     1207                    if (isMatchingHostname(altName.toLower(), peerName.toLower())) {
    8251208                        matched = true;
    8261209                        break;
    8271210                    }
    8281211                }
     1212
    8291213                if (!matched) {
    8301214                    // No matches in common names or alternate names.
     
    9231307        ctx = 0;
    9241308    }
     1309
     1310
     1311
     1312
     1313
    9251314}
    9261315
     
    9511340}
    9521341
     1342
     1343
     1344
     1345
     1346
     1347
     1348
     1349
     1350
     1351
     1352
     1353
     1354
     1355
     1356
     1357
     1358
     1359
     1360
     1361
     1362
     1363
     1364
     1365
     1366
     1367
     1368
     1369
     1370
     1371
     1372
     1373
     1374
     1375
     1376
     1377
     1378
     1379
     1380
     1381
     1382
     1383
     1384
     1385
     1386
     1387
     1388
     1389
     1390
     1391
     1392
     1393
     1394
    9531395QT_END_NAMESPACE
  • trunk/src/network/ssl/qsslsocket_openssl_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    9898    SSL *ssl;
    9999    SSL_CTX *ctx;
     100
    100101    BIO *readBio;
    101102    BIO *writeBio;
     
    116117    static QSslCipher QSslCipher_from_SSL_CIPHER(SSL_CIPHER *cipher);
    117118    static QList<QSslCertificate> STACKOFX509_to_QSslCertificates(STACK_OF(X509) *x509);
     119
     120
    118121};
     122
     123
     124
     125
     126
     127
     128
     129
     130
     131
     132
     133
     134
     135
     136
     137
     138
     139
     140
     141
     142
     143
     144
     145
     146
     147
     148
     149
     150
     151
     152
     153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
     175
     176
    119177
    120178QT_END_NAMESPACE
  • trunk/src/network/ssl/qsslsocket_openssl_symbols.cpp

    r788 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4343#include "qsslsocket_openssl_symbols_p.h"
    4444
    45 #include <QtCore/qlibrary.h>
     45#ifdef Q_OS_WIN
     46# include <private/qsystemlibrary_p.h>
     47#else
     48# include <QtCore/qlibrary.h>
     49#endif
    4650#include <QtCore/qmutex.h>
    4751#include <private/qmutexpool_p.h>
     
    120124DEFINEFUNC(const EVP_CIPHER *, EVP_des_ede3_cbc, DUMMYARG, DUMMYARG, return 0, return)
    121125DEFINEFUNC3(int, EVP_PKEY_assign, EVP_PKEY *a, a, int b, b, char *c, c, return -1, return)
     126
     127
    122128DEFINEFUNC(void, EVP_PKEY_free, EVP_PKEY *a, a, return, DUMMYARG)
    123129DEFINEFUNC(DSA *, EVP_PKEY_get1_DSA, EVP_PKEY *a, a, return 0, return)
     
    333339            .split(QLatin1Char(':'), QString::SkipEmptyParts);
    334340#  endif
    335     paths << QLatin1String("/usr/lib") << QLatin1String("/usr/local/lib");
     341    paths << QLatin1String("/usr/lib") << QLatin1String("/usr/local/lib");
    336342
    337343    QStringList foundSsls;
     
    348354}
    349355# endif
     356
     357
     358
     359
     360
     361
     362
     363
     364
     365
     366
     367
     368
     369
     370
     371
     372
     373
     374
     375
     376
     377
     378
     379
     380
     381
     382
    350383
    351384static QPair<QLibrary*, QLibrary*> loadOpenSsl()
     
    355388    pair.second = 0;
    356389
    357 # ifdef Q_OS_WIN
    358     QLibrary *ssleay32 = new QLibrary(QLatin1String("ssleay32"));
    359     if (!ssleay32->load()) {
    360         // Cannot find ssleay32.dll
    361         delete ssleay32;
    362         return pair;
    363     }
    364 
    365     QLibrary *libeay32 = new QLibrary(QLatin1String("libeay32"));
    366     if (!libeay32->load()) {
    367         delete ssleay32;
    368         delete libeay32;
    369         return pair;
    370     }
    371 
    372     pair.first = ssleay32;
    373     pair.second = libeay32;
    374     return pair;
    375 # elif defined(Q_OS_SYMBIAN)
     390# if defined(Q_OS_SYMBIAN)
    376391     QLibrary *libssl = new QLibrary(QLatin1String("libssl"));
    377392    if (!libssl->load()) {
     
    506521# endif
    507522}
     523
    508524
    509525bool q_resolveOpenSslSymbols()
     
    520536    triedToResolveSymbols = true;
    521537
     538
     539
     540
    522541    QPair<QLibrary *, QLibrary *> libs = loadOpenSsl();
     542
    523543    if (!libs.first || !libs.second)
    524544        // failed to load them
     
    549569    RESOLVEFUNC(EVP_des_ede3_cbc, 919, libs.second )
    550570    RESOLVEFUNC(EVP_PKEY_assign, 859, libs.second )
     571
     572
    551573    RESOLVEFUNC(EVP_PKEY_free, 867, libs.second )
    552574    RESOLVEFUNC(EVP_PKEY_get1_DSA, 869, libs.second )
     
    671693    RESOLVEFUNC(EVP_des_ede3_cbc)
    672694    RESOLVEFUNC(EVP_PKEY_assign)
     695
     696
    673697    RESOLVEFUNC(EVP_PKEY_free)
    674698    RESOLVEFUNC(EVP_PKEY_get1_DSA)
     
    794818QDateTime q_getTimeFromASN1(const ASN1_TIME *aTime)
    795819{
    796     char lBuffer[24];
    797     char *pBuffer = lBuffer;
    798 
    799820    size_t lTimeLength = aTime->length;
    800821    char *pString = (char *) aTime->data;
    801822
    802823    if (aTime->type == V_ASN1_UTCTIME) {
     824
     825
     826
     827
    803828        if ((lTimeLength < 11) || (lTimeLength > 17))
    804829            return QDateTime();
     
    807832        pBuffer += 10;
    808833        pString += 10;
     834
     835
     836
     837
     838
     839
     840
     841
     842
     843
     844
     845
     846
     847
     848
     849
     850
     851
     852
     853
     854
     855
     856
     857
     858
     859
     860
     861
     862
     863
     864
     865
     866
     867
     868
     869
     870
     871
     872
     873
     874
     875
     876
     877
     878
     879
     880
     881
     882
     883
     884
     885
     886
     887
     888
     889
     890
     891
     892
     893
     894
     895
     896
     897
     898
     899
     900
     901
     902
     903
    809904    } else {
    810         if (lTimeLength < 13)
    811             return QDateTime();
    812 
    813         memcpy(pBuffer, pString, 12);
    814         pBuffer += 12;
    815         pString += 12;
    816     }
    817 
    818     if ((*pString == 'Z') || (*pString == '-') || (*pString == '+')) {
    819         *pBuffer++ = '0';
    820         *pBuffer++ = '0';
    821     } else {
    822         *pBuffer++ = *pString++;
    823         *pBuffer++ = *pString++;
    824         // Skip any fractional seconds...
    825         if (*pString == '.') {
    826             pString++;
    827             while ((*pString >= '0') && (*pString <= '9'))
    828                 pString++;
    829         }
    830     }
    831 
    832     *pBuffer++ = 'Z';
    833     *pBuffer++ = '\0';
    834 
    835     time_t lSecondsFromUCT;
    836     if (*pString == 'Z') {
    837         lSecondsFromUCT = 0;
    838     } else {
    839         if ((*pString != '+') && (*pString != '-'))
    840             return QDateTime();
    841 
    842         lSecondsFromUCT = ((pString[1] - '0') * 10 + (pString[2] - '0')) * 60;
    843         lSecondsFromUCT += (pString[3] - '0') * 10 + (pString[4] - '0');
    844         lSecondsFromUCT *= 60;
    845         if (*pString == '-')
    846             lSecondsFromUCT = -lSecondsFromUCT;
    847     }
    848 
    849     tm lTime;
    850     lTime.tm_sec = ((lBuffer[10] - '0') * 10) + (lBuffer[11] - '0');
    851     lTime.tm_min = ((lBuffer[8] - '0') * 10) + (lBuffer[9] - '0');
    852     lTime.tm_hour = ((lBuffer[6] - '0') * 10) + (lBuffer[7] - '0');
    853     lTime.tm_mday = ((lBuffer[4] - '0') * 10) + (lBuffer[5] - '0');
    854     lTime.tm_mon = (((lBuffer[2] - '0') * 10) + (lBuffer[3] - '0')) - 1;
    855     lTime.tm_year = ((lBuffer[0] - '0') * 10) + (lBuffer[1] - '0');
    856     if (lTime.tm_year < 50)
    857         lTime.tm_year += 100; // RFC 2459
    858 
    859     QDate resDate(lTime.tm_year + 1900, lTime.tm_mon + 1, lTime.tm_mday);
    860     QTime resTime(lTime.tm_hour, lTime.tm_min, lTime.tm_sec);
    861     QDateTime result(resDate, resTime, Qt::UTC);
    862     result = result.addSecs(lSecondsFromUCT);
    863     return result;
     905        qWarning("unsupported date format detected");
     906        return QDateTime();
     907    }
     908
    864909}
    865910
  • trunk/src/network/ssl/qsslsocket_openssl_symbols_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    228228const EVP_CIPHER *q_EVP_des_ede3_cbc();
    229229int q_EVP_PKEY_assign(EVP_PKEY *a, int b, char *c);
     230
     231
    230232void q_EVP_PKEY_free(EVP_PKEY *a);
    231233RSA *q_EVP_PKEY_get1_RSA(EVP_PKEY *a);
  • trunk/src/network/ssl/qsslsocket_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    6767QT_BEGIN_NAMESPACE
    6868
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
    6991class QSslSocketPrivate : public QTcpSocketPrivate
    7092{
     
    91113    QString verificationPeerName;
    92114
    93     static bool ensureInitialized();
     115    static bool supportsSsl();
     116    static void ensureInitialized();
    94117    static void deinitialize();
    95118    static QList<QSslCipher> defaultCiphers();
     
    107130    static void addDefaultCaCertificates(const QList<QSslCertificate> &certs);
    108131
     132
     133
     134
     135
     136
     137
     138
     139
     140
     141
    109142    // The socket itself, including private slots.
    110143    QTcpSocket *plainSocket;
    111144    void createPlainSocket(QIODevice::OpenMode openMode);
     145
     146
    112147    void _q_connectedSlot();
    113148    void _q_hostFoundSlot();
     
    127162    virtual void disconnected() = 0;
    128163    virtual QSslCipher sessionCipher() const = 0;
     164
     165
     166
     167
     168
     169
     170
    129171};
    130172
  • trunk/src/network/ssl/ssl.pri

    r788 r846  
    3232               ssl/qsslsocket_openssl_symbols.cpp
    3333
    34     # Include Qt's default CA bundle
    35     RESOURCES += network.qrc
    36 
    3734    # Add optional SSL libs
    3835    LIBS_PRIVATE += $$OPENSSL_LIBS
Note: See TracChangeset for help on using the changeset viewer.