Ejemplo n.º 1
0
void SsuCli::optModel(QStringList opt){
  QTextStream qout(stdout);
  QTextStream qerr(stderr);
  SsuDeviceInfo deviceInfo;

  if (opt.count() == 3 && opt.at(2) == "-s"){
    qout << deviceInfo.deviceModel();
    state = Idle;
  } else if (opt.count() == 2){
    qout << "Device model is: " << deviceInfo.deviceModel() << endl;
    state = Idle;
  }
}
Ejemplo n.º 2
0
// @todo the non-device specific repository resolving should move from deviceInfo to repomanager
QStringList SsuRepoManager::repos(bool rnd, SsuDeviceInfo &deviceInfo, int filter){
  QStringList result;

  // read the adaptation specific repositories, as well as the default
  // repositories; default repos are read through deviceInfo as an
  // adaptation is allowed to disable core repositories
  result = deviceInfo.repos(rnd, filter);

  // read the repositories of the available features. While devices have
  // a default list of features to be installed those are only relevant
  // for bootstrapping, so this code just operates on installed features
  SsuFeatureManager featureManager;
  result.append(featureManager.repos(rnd, filter));

  // read user-defined repositories from ssu.ini. This step needs to
  // happen at the end, after all other required repositories are
  // added already

  // TODO: in strict mode, filter the repository list from there
  SsuCoreConfig *ssuSettings = SsuCoreConfig::instance();

  bool updateMode = false;
  bool appInstallMode = false;

  if ((ssuSettings->deviceMode() & Ssu::UpdateMode) == Ssu::UpdateMode)
    updateMode = true;

  if ((ssuSettings->deviceMode() & Ssu::AppInstallMode) == Ssu::AppInstallMode){
    updateMode = true;
    appInstallMode = true;
  }

  if (filter == Ssu::NoFilter ||
      filter == Ssu::UserFilter){
    // user defined repositories, or ones overriding URLs for default ones
    // -> in update mode we need to check for each of those if it already
    //    exists. If it exists, keep it, if it does not, disable it
    ssuSettings->beginGroup("repository-urls");
    QStringList repoUrls = ssuSettings->allKeys();
    ssuSettings->endGroup();

    if (updateMode){
      foreach(const QString &key, repoUrls){
        if (result.contains(key))
          result.append(key);
      }
    } else {
Ejemplo n.º 3
0
void SsuCli::optRepos(QStringList opt){
  QTextStream qout(stdout);
  SsuRepoManager repoManager;
  SsuDeviceInfo deviceInfo;
  QHash<QString, QString> repoParameters, repoOverride;
  QString device="";
  bool rndRepo = false;
  int micMode=0, flagStart = 0;

  if ((ssu.deviceMode() & Ssu::RndMode) == Ssu::RndMode)
    rndRepo = true;

  if (opt.count() >= 3 && opt.at(2) == "-m"){
    micMode = 1;
    // TODO: read the default mic override variables from some config
    /*
    repoOverride.insert("release", "@RELEASE@");
    repoOverride.insert("rndRelease", "@RNDRELEASE@");
    repoOverride.insert("flavour", "@FLAVOUR@");
    repoOverride.insert("arch", "@ARCH@");
    */
  }

  if (opt.count() >= 3 + micMode){
    // first argument is flag
    if (opt.at(2 + micMode).contains("=")){
      flagStart = 2 + micMode;
    } else if (!opt.at(2 + micMode).contains("=") &&
               opt.count() == 3 + micMode) {
      // first (and only) argument is device)
      device = opt.at(2 + micMode);
    } else if(!opt.at(2 + micMode).contains("=") &&
              opt.count() > 3 + micMode &&
              opt.at(3 + micMode).contains("=")){
      // first argument is device, second flag
      device = opt.at(2 + micMode);
      flagStart = 3 + micMode;
    } else {
      state = UserError;
      return;
    }
  }

  if (flagStart != 0){
    for (int i=flagStart; i<opt.count(); i++){
      if (opt.at(i).count("=") != 1){
        qout << "Invalid flag: " << opt.at(i) << endl;
        state = Idle;
        return;
      }
      QStringList split = opt.at(i).split("=");
      repoOverride.insert(split.at(0), split.at(1));
    }
  }

  if (repoOverride.contains("rnd")){
    if (repoOverride.value("rnd") == "true")
      rndRepo = true;
    else if (repoOverride.value("rnd") == "false")
      rndRepo = false;
  }

  if (device != ""){
    deviceInfo.setDeviceModel(device);
    repoOverride.insert("model", device);
  }

  // TODO: rnd mode override needs to be implemented
  QStringList repos;

  // micMode? handle it and return, as it's a lot simpler than full mode
  if (micMode){
    repos = repoManager.repos(rndRepo, deviceInfo, Ssu::BoardFilter);
    foreach (const QString &repo, repos){
      QString repoName = repo;
      if (repo.endsWith("-debuginfo")){
        repoName = repo.left(repo.size() - 10);
        repoParameters.insert("debugSplit", "debug");
      } else if (repoParameters.value("debugSplit") == "debug")
        repoParameters.remove("debugSplit");

      QString repoUrl = ssu.repoUrl(repoName, rndRepo, repoParameters, repoOverride);
      qout << "repo --name=" << repo << "-"
           << (rndRepo ? repoOverride.value("rndRelease")
                       : repoOverride.value("release"))
           << " --baseurl=" << repoUrl << endl;
    }
    state = Idle;
    return;
  }
Ejemplo n.º 4
0
Archivo: ssu.cpp Proyecto: jvihrial/ssu
void Ssu::updateCredentials(bool force){
  SsuCoreConfig *settings = SsuCoreConfig::instance();
  SsuDeviceInfo deviceInfo;
  errorFlag = false;

  SsuLog *ssuLog = SsuLog::instance();

  if (deviceInfo.deviceUid() == ""){
    setError("No valid UID available for your device. For phones: is your modem online?");
    return;
  }

  QString ssuCaCertificate, ssuCredentialsUrl;
  ssuCaCertificate = SsuRepoManager::caCertificatePath();
  if (ssuCaCertificate.isEmpty()){
    setError("CA certificate for SSU not set ('_ca-certificate in domain')");
    return;
  }

  if (!settings->contains("credentials-url")){
    ssuCredentialsUrl = repoUrl("credentials-url");
    if (ssuCredentialsUrl.isEmpty()){
      setError("URL for credentials update not set (config key 'credentials-url')");
      return;
    }
  } else
    ssuCredentialsUrl = settings->value("credentials-url").toString();

  if (!isRegistered()){
    setError("Device is not registered.");
    return;
  }

  if (!force){
    // skip updating if the last update was less than 30 minutes ago
    QDateTime now = QDateTime::currentDateTime();

    if (settings->contains("lastCredentialsUpdate")){
      QDateTime last = settings->value("lastCredentialsUpdate").toDateTime();
      if (last >= now.addSecs(-1800)){
        ssuLog->print(LOG_DEBUG, QString("Skipping credentials update, last update was at %1")
                     .arg(last.toString()));
        emit done();
        return;
      }
    }
  }

  // check when the last update was, decide if an update is required
  QSslConfiguration sslConfiguration;
  if (!useSslVerify())
    sslConfiguration.setPeerVerifyMode(QSslSocket::VerifyNone);

  QSslKey privateKey(settings->value("privateKey").toByteArray(), QSsl::Rsa);
  QSslCertificate certificate(settings->value("certificate").toByteArray());

  QList<QSslCertificate> caCertificates;
  caCertificates << QSslCertificate::fromPath(ssuCaCertificate);
  sslConfiguration.setCaCertificates(caCertificates);

  sslConfiguration.setPrivateKey(privateKey);
  sslConfiguration.setLocalCertificate(certificate);

  QNetworkRequest request;
  request.setUrl(QUrl(ssuCredentialsUrl.arg(deviceInfo.deviceUid())));

  ssuLog->print(LOG_DEBUG, QString("Sending credential update request to %1")
               .arg(request.url().toString()));
  request.setSslConfiguration(sslConfiguration);

  pendingRequests++;
  manager->get(request);
}
Ejemplo n.º 5
0
Archivo: ssu.cpp Proyecto: jvihrial/ssu
void Ssu::sendRegistration(QString usernameDomain, QString password){
  errorFlag = false;

  QString ssuCaCertificate, ssuRegisterUrl;
  QString username, domainName;

  SsuLog *ssuLog = SsuLog::instance();
  SsuCoreConfig *settings = SsuCoreConfig::instance();
  SsuDeviceInfo deviceInfo;

  QNetworkRequest request;
  request.setAttribute(SSU_NETWORK_REQUEST_DOMAIN_DATA, domain());
  ssuLog->print(LOG_DEBUG, QString("Saving current domain before request: '%1'").arg(domain()));

  // Username can include also domain, (user@domain), separate those
  if (usernameDomain.contains('@')) {
      // separate domain/username and set domain
      username = usernameDomain.section('@', 0, 0);
      domainName = usernameDomain.section('@', 1, 1);
      setDomain(domainName);
  } else {
      // No domain defined
      username = usernameDomain;
      if (settings->contains("default-rnd-domain"))
        setDomain(settings->value("default-rnd-domain").toString());
  }

  ssuCaCertificate = SsuRepoManager::caCertificatePath();
  if (ssuCaCertificate.isEmpty()){
    setError("CA certificate for SSU not set ('_ca-certificate in domain')");
    return;
  }

  if (!settings->contains("register-url")){
    ssuRegisterUrl = repoUrl("register-url");
    if (ssuRegisterUrl.isEmpty()){
      setError("URL for SSU registration not set (config key 'register-url')");
      return;
    }
  } else
    ssuRegisterUrl = settings->value("register-url").toString();

  QString IMEI = deviceInfo.deviceUid();
  if (IMEI == ""){
    setError("No valid UID available for your device. For phones: is your modem online?");
    return;
  }

  QSslConfiguration sslConfiguration;
  if (!useSslVerify())
    sslConfiguration.setPeerVerifyMode(QSslSocket::VerifyNone);

  sslConfiguration.setCaCertificates(QSslCertificate::fromPath(ssuCaCertificate));

  request.setUrl(QUrl(QString(ssuRegisterUrl)
                      .arg(IMEI)
                   ));
  request.setSslConfiguration(sslConfiguration);
  request.setRawHeader("Authorization", "Basic " +
                       QByteArray(QString("%1:%2")
                                  .arg(username).arg(password)
                                  .toLatin1()).toBase64());
  request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

  QUrl form;

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
  QUrlQuery q;
  q.addQueryItem("protocolVersion", SSU_PROTOCOL_VERSION);
  q.addQueryItem("deviceModel", deviceInfo.deviceModel());
  if (!domain().isEmpty()){
    q.addQueryItem("domain", domain());
  }

  form.setQuery(q);
#else
  form.addQueryItem("protocolVersion", SSU_PROTOCOL_VERSION);
  form.addQueryItem("deviceModel", deviceInfo.deviceModel());
  if (!domain().isEmpty()){
    form.addQueryItem("domain", domain());
  }
#endif

  ssuLog->print(LOG_DEBUG, QString("Sending request to %1")
                .arg(request.url().url()));

  QNetworkReply *reply;

  pendingRequests++;
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
  reply = manager->post(request, form.query(QUrl::FullyEncoded).toStdString().c_str());
#else
  reply = manager->post(request, form.encodedQuery());
#endif
  // we could expose downloadProgress() from reply in case we want progress info

  QString homeUrl = settings->value("home-url").toString().arg(username);
  if (!homeUrl.isEmpty()){
    // clear header, the other request bits are reusable
    request.setHeader(QNetworkRequest::ContentTypeHeader, 0);
    request.setUrl(homeUrl + "/authorized_keys");
    ssuLog->print(LOG_DEBUG, QString("Trying to get SSH keys from %1").arg(request.url().toString()));
    pendingRequests++;
    manager->get(request);
  }
}