Changeset 9795 in ntrip for trunk/BNC/src/bncnetqueryv2.cpp


Ignore:
Timestamp:
Jul 22, 2022, 1:34:16 PM (21 months ago)
Author:
stuerze
Message:

consideration of client SSL certificates, if they are available

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/src/bncnetqueryv2.cpp

    r9742 r9795  
    3636
    3737  bncSettings settings;
    38   _sslIgnoreErrors =
    39      (Qt::CheckState(settings.value("sslIgnoreErrors").toInt()) == Qt::Checked);
    40 
    41   if (_secure && !QSslSocket::supportsSsl()) {
    42     BNC_CORE->slotMessage("No SSL support, install OpenSSL run-time libraries", true);
    43     stop();
    44   }
     38  _sslIgnoreErrors = (Qt::CheckState(settings.value("sslIgnoreErrors").toInt()) == Qt::Checked);
     39
     40  if (_secure ) {
     41    if (!QSslSocket::supportsSsl()) {
     42      BNC_CORE->slotMessage("No SSL support, install OpenSSL run-time libraries", true);
     43      stop();
     44    }
     45    // Generate filenames to consider a potential client certificate
     46    _crtFileName = settings.value("sslClientCertPath").toString() + _url.host() + QString(".%1.crt").arg(_url.port());
     47    _keyFileName = settings.value("sslClientCertPath").toString() + _url.host() + QString(".%1.key").arg(_url.port());
     48  }
     49
     50
    4551}
    4652
     
    122128  if (_url.scheme().isEmpty()) {
    123129    if (_secure) {
     130      _url.setPort(443);
    124131      _url.setScheme("https");
    125132    }
     
    134141  // Network Request
    135142  // ---------------
     143  bncSslConfig sslConfig = BNC_SSL_CONFIG;
     144
     145  if (_secure) {
     146    QFile clientCrtFile(_crtFileName);
     147    QFile privateKeyFile(_keyFileName);
     148    if ( clientCrtFile.exists() && privateKeyFile.exists()) {
     149      // set local certificate if available
     150      clientCrtFile.open(QIODevice::ReadOnly);
     151      QSslCertificate clientCrt(&clientCrtFile);
     152      sslConfig.setLocalCertificate(clientCrt);
     153      // set private key if available
     154      privateKeyFile.open(QIODevice::ReadOnly);
     155      QSslKey privateKey(&privateKeyFile, QSsl::Rsa);
     156      sslConfig.setPrivateKey(privateKey);
     157    }
     158  }
     159
    136160  QNetworkRequest request;
    137   request.setSslConfiguration(BNC_SSL_CONFIG);
     161  request.setSslConfiguration(sslConfig);
    138162  request.setUrl(_url);
    139163  request.setRawHeader("Host"         , _url.host().toLatin1());
Note: See TracChangeset for help on using the changeset viewer.