Exemplo n.º 1
0
pugi::xml_parse_result configuration::open_xml_document(pugi::xml_document &document, const std::string &filename)
{
    std::string search_filename = filename;
    pugi::xml_parse_result result;
    result = document.load_file(search_filename.c_str());
    if(result.status != pugi::status_ok)
    {
        search_filename = bundlepath().append(search_filename);
        result = document.load_file(search_filename.c_str());
    }
#if defined(__EDITOR__)

    if(result.status == pugi::status_ok)
    {
        configuration::set_filename(search_filename);
    }

#endif
    return result;
};
Exemplo n.º 2
0
bool QgsAuthPkcs12Edit::validateConfig()
{
  // required components
  QString bundlepath( lePkcs12Bundle->text() );

  bool bundlefound = QFile::exists( bundlepath );

  QgsAuthGuiUtils::fileFound( bundlepath.isEmpty() || bundlefound, lePkcs12Bundle );

  if ( !bundlefound )
  {
    writePkiMessage( lePkcs12Msg, tr( "Missing components" ), Invalid );
    return validityChange( false );
  }

  if ( !QCA::isSupported( "pkcs12" ) )
  {
    writePkiMessage( lePkcs12Msg, tr( "QCA library has no PKCS#12 support" ), Invalid );
    return validityChange( false );
  }

  // load the bundle
  QCA::SecureArray passarray;
  if ( !lePkcs12KeyPass->text().isEmpty() )
    passarray = QCA::SecureArray( lePkcs12KeyPass->text().toUtf8() );

  QCA::ConvertResult res;
  QCA::KeyBundle bundle( QCA::KeyBundle::fromFile( bundlepath, passarray, &res, QString( "qca-ossl" ) ) );

  if ( res == QCA::ErrorFile )
  {
    writePkiMessage( lePkcs12Msg, tr( "Failed to read bundle file" ), Invalid );
    return validityChange( false );
  }
  else if ( res == QCA::ErrorPassphrase )
  {
    writePkiMessage( lePkcs12Msg, tr( "Incorrect bundle password" ), Invalid );
    lePkcs12KeyPass->setPlaceholderText( QString( "Required passphrase" ) );
    return validityChange( false );
  }
  else if ( res == QCA::ErrorDecode )
  {
    writePkiMessage( lePkcs12Msg, tr( "Failed to decode (try entering password)" ), Invalid );
    return validityChange( false );
  }

  if ( bundle.isNull() )
  {
    writePkiMessage( lePkcs12Msg, tr( "Bundle empty or can not be loaded" ), Invalid );
    return validityChange( false );
  }

  // check for primary cert and that it is valid
  QCA::Certificate cert( bundle.certificateChain().primary() );
  if ( cert.isNull() )
  {
    writePkiMessage( lePkcs12Msg, tr( "Bundle client cert can not be loaded" ), Invalid );
    return validityChange( false );
  }

  // TODO: add more robust validation, including cert chain resolution
  QDateTime startdate( cert.notValidBefore() );
  QDateTime enddate( cert.notValidAfter() );
  QDateTime now( QDateTime::currentDateTime() );
  bool bundlevalid = ( now >= startdate && now <= enddate );

  writePkiMessage( lePkcs12Msg,
                   tr( "%1 thru %2" ).arg( startdate.toString() ).arg( enddate.toString() ),
                   ( bundlevalid ? Valid : Invalid ) );

  return validityChange( bundlevalid );
}