Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Connect To Remote Webservice using Soap
Forum Updated to NodeBB v4.3 + New Features

Connect To Remote Webservice using Soap

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hari krishna
    wrote on last edited by
    #1

    I am new to Qt, and in my application i need to connect to a remote service hosted in secure environment. I need to add certificates to the Network request inorder to process the request.

    @
    void QtSoapHttpTransport::submitRequest(QtSoapMessage &request, const QString &path)
    {
    QNetworkRequest networkReq;

    QFile    sslCertificateFile("Certificate1.cer");
    QFile    sslCertificateFileserver("Certificate2.cer");
    QSslConfiguration sslConfiguration;
    QSslCertificate  sslCertificate;
    QSslCertificate  sslCertificateserver;
    if ( (sslCertificateFile.open(QIODevice::ReadOnly)) &&
         sslCertificateFileserver.open(QIODevice::ReadOnly))
    {
         // Read certificates from file
         QByteArray aray = sslCertificateFile.readAll();
         qDebug() << aray;
    
         // Read server ceriticate file
         QByteArray arayserver = sslCertificateFileserver.readAll();
         qDebug() << arayserver;
         // Load Client
         QList<QSslCertificate> sslCertificateList = QSslCertificate::fromData(aray,QSsl::Pem);
         qDebug("Found certificates: %d", sslCertificateList.size());
         sslCertificate = sslCertificateList.takeAt(0);
         QByteArray testarray =  sslCertificate.digest(QCryptographicHash::Sha1);
         qDebug() << testarray;
    
         // Load Server
         QList<QSslCertificate> sslCertificateListserver = QSslCertificate::fromData(arayserver,QSsl::Der);
         sslCertificateserver = sslCertificateListserver.takeAt(0);
    
         QList<QSslCertificate> ceritifcates;
         ceritifcates.append(sslCertificate);
         ceritifcates.append(sslCertificateserver);
    
         QSslKey key(&sslCertificateFile, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
         qDebug() << "key isNull ? " << key.isNull();
         sslConfiguration.setPrivateKey(key);
    
         //sslConfiguration.setLocalCertificate(sslCertificate);
         sslConfiguration.setLocalCertificateChain(ceritifcates);
         sslConfiguration.setProtocol(QSsl::AnyProtocol);
    
         networkReq.setSslConfiguration(sslConfiguration);
    
    }
    
    networkReq.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("text/xml;charset=utf-8"));
    QByteArray array;
    array.append(soapAction);
    networkReq.setRawHeader("SOAPAction",array);
    
    QUrl url2 = path ; 
    networkReq.setUrl(url2);
    soapResponse.clear();
    networkRep = networkMgr.post(networkReq, request.toXmlString().toUtf8().constData());
    

    }
    @

    But i am not able to get the Certificate list using "QSslCertificate::fromData(arayserver,QSsl::Der);" . The list is empty. please let me know how to rectify the issue or please suggest any other way to access SSL Certified Service using Qt.

    Note: I have installed Open Ssl and i am configuring it in the project file like below
    @

    CONFIG += openssl
    LIBS += -L"C:/OpenSSL-Win32/lib" -llibeay32
    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      @
      if ( (sslCertificateFile.open(QIODevice::ReadOnly)) &&
      sslCertificateFileserver.open(QIODevice::ReadOnly))
      @

      You don't do anything in case either files fails to open, at least printing an error message would help find out. Also since your paths are relative, theses two files probably can't be found at run time.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hari krishna
        wrote on last edited by
        #3

        Thanks for the suggetions. I would implement them in my application.

        Apart from that my problem still persists. I am able to read the certificate as byte array but i am failing to create QsslCertificate using that certificate.

        I am using QSslCertificate::fromData. but the method is failing to create the certificate. The issue might be caused because fromData method is trying to read
        "-----BEGIN CERTIFICATE-----" macro inside my method. can you please suggest me possible solutions for the issue.

        This logic works fine with .pem certificates however the same logic fails with .cer certificates

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You should implement them now, you have somewhere an error occurring and one of them could be that one of these two files (or both) cannot be read but you don't check that. Don't assume it's working, validate.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved