Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SSL Certificate and Public Key Pinning
QtWS25 Last Chance

SSL Certificate and Public Key Pinning

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 1 Posters 2.6k Views
  • 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.
  • J Offline
    J Offline
    jeremiah
    wrote on 22 Apr 2016, 17:04 last edited by jeremiah
    #1

    Does QT support certificate pinning? I am not finding much when searching documentation and google.

    To give more clarification: we are looking to do more to stop the MITM attacks. One way is to store a hash of the server's public key in the client when the client is built, so that when the client reaches out to the server for the first time for the server's public key, it can hash that key and compare it to its stored hash to ensure it's legitimate. And then do the compare for each request.

    Thoughts? There a better way to achieve this result?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jeremiah
      wrote on 22 Apr 2016, 17:45 last edited by
      #2

      will i have to manually do the public key comparison myself, or does QT have this built in?

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jeremiah
        wrote on 22 Apr 2016, 20:31 last edited by
        #3

        here is how i solved it:

        connected to encrypted signal

        QObject::connect(&mgr, SIGNAL(encrypted(QNetworkReply*)), this, SLOT(on_Encrypted(QNetworkReply*)));
        

        then in the slot, check and verify if using pinning and check the hash

        void on_Encrypted(QNetworkReply *reply){
               if (useCertPinning) {
                QSslCertificate cert = reply->sslConfiguration().peerCertificate();
        
                QString serverHash = QCryptographicHash::hash(cert.publicKey().toDer(),QCryptographicHash::Sha256).toBase64();
                
                if (pinningHash.compare(serverHash) != 0) {
                    qDebug()<< "Public Key Hashes don't match, abort";
                    reply->abort();
                }
        
            }
        }
        
        1 Reply Last reply
        0

        2/3

        22 Apr 2016, 17:45

        • Login

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