File: NetworkAccessManager.cpp

package info (click to toggle)
wsjtx 2.3.0%2Brepack-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 63,524 kB
  • sloc: cpp: 59,051; f90: 34,130; python: 27,241; ansic: 11,205; fortran: 2,051; sh: 132; makefile: 109
file content (62 lines) | stat: -rw-r--r-- 2,238 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "Network/NetworkAccessManager.hpp"

#include <QString>
#include <QNetworkReply>

#include "moc_NetworkAccessManager.cpp"

NetworkAccessManager::NetworkAccessManager (QWidget * parent)
  : QNetworkAccessManager (parent)
  , parent_widget_ {parent}
{
  // handle SSL errors that have not been cached as allowed
  // exceptions and offer them to the user to add to the ignored
  // exception cache
  connect (this, &QNetworkAccessManager::sslErrors, this, &NetworkAccessManager::filter_SSL_errors);
}

void NetworkAccessManager::filter_SSL_errors (QNetworkReply * reply, QList<QSslError> const& errors)
{
  QString message;
  QList<QSslError> new_errors;
  for (auto const& error: errors)
    {
      if (!allowed_ssl_errors_.contains (error))
        {
          new_errors << error;
          message += '\n' + reply->request ().url ().toDisplayString () + ": " + error.errorString ();
        }
    }
  if (new_errors.size ())
    {
      QString certs;
      for (auto const& cert : reply->sslConfiguration ().peerCertificateChain ())
        {
          certs += cert.toText () + '\n';
        }
      if (MessageBox::Ignore == MessageBox::query_message (parent_widget_
                                                           , tr ("Network SSL/TLS Errors")
                                                           , message, certs
                                                           , MessageBox::Abort | MessageBox::Ignore))
        {
          // accumulate new SSL error exceptions that have been allowed
          allowed_ssl_errors_.append (new_errors);
          reply->ignoreSslErrors (allowed_ssl_errors_);
        }
    }
  else
    {
      // no new exceptions so silently ignore the ones already allowed
      reply->ignoreSslErrors (allowed_ssl_errors_);
    }
}

QNetworkReply * NetworkAccessManager::createRequest (Operation operation, QNetworkRequest const& request
                                                     , QIODevice * outgoing_data)
{
  auto reply = QNetworkAccessManager::createRequest (operation, request, outgoing_data);
  // errors are usually certificate specific so passing all cached
  // exceptions here is ok
  reply->ignoreSslErrors (allowed_ssl_errors_);
  return reply;
}