public AuthenticatorWindow() {
    SESecurityManager.addPasswordListener(this);

    // System.out.println( "AuthenticatorWindow");

    Map cache = COConfigurationManager.getMapParameter(CONFIG_PARAM, new HashMap());

    try {
      Iterator it = cache.entrySet().iterator();

      while (it.hasNext()) {

        Map.Entry entry = (Map.Entry) it.next();

        String key = (String) entry.getKey();
        Map value = (Map) entry.getValue();

        String user = new String((byte[]) value.get("user"), "UTF-8");
        char[] pw = new String((byte[]) value.get("pw"), "UTF-8").toCharArray();

        auth_cache.put(key, new authCache(key, new PasswordAuthentication(user, pw), true));
      }

    } catch (Throwable e) {

      COConfigurationManager.setParameter(CONFIG_PARAM, new HashMap());

      Debug.printStackTrace(e);
    }
  }
Exemple #2
0
  public static void setAZTracker(URL tracker_url, boolean az_tracker) {
    String key = tracker_url.getHost() + ":" + tracker_url.getPort();

    synchronized (az_trackers) {
      boolean changed = false;

      if (az_trackers.get(key) == null) {

        if (az_tracker) {

          az_trackers.put(key, new Long(SystemTime.getCurrentTime()));

          changed = true;
        }
      } else {

        if (!az_tracker) {

          if (az_trackers.remove(key) != null) {

            changed = true;
          }
        }
      }

      if (changed) {

        COConfigurationManager.setParameter("Tracker Client AZ Instances", az_trackers);
      }
    }
  }
Exemple #3
0
  public static String adjustHostFromHosting(String host_in) {
    if (tracker_ip.length() > 0) {

      String address_type = AENetworkClassifier.categoriseAddress(host_in);

      String target_ip = (String) override_map.get(address_type);

      if (target_ip == null) {

        target_ip = tracker_ip;
      }

      if (host_in.equals("127.0.0.1")) {

        // System.out.println( "adjustHostFromHosting: " + host_in + " -> " + tracker_ip );

        return (target_ip);
      }

      if (host_in.equals(bind_ip)) {

        // System.out.println( "adjustHostFromHosting: " + host_in +  " -> " + tracker_ip );

        return (target_ip);
      }
    }

    return (host_in);
  }
  private void notifyParameterListeners(String parameter) {
    ParameterListener[] listeners;

    synchronized (parameterListenerz) {
      listeners = parameterListenerz.get(parameter);
    }

    if (listeners == null) {
      return;
    }

    for (ParameterListener listener : listeners) {

      if (listener != null) {

        try {
          listener.parameterChanged(parameter);

        } catch (Throwable e) {

          Debug.printStackTrace(e);
        }
      }
    }
  }
  public void addParameterListener(String parameter, ParameterListener new_listener) {
    if (parameter == null || new_listener == null) {

      return;
    }

    synchronized (parameterListenerz) {
      ParameterListener[] listeners = parameterListenerz.get(parameter);

      if (listeners == null) {

        parameterListenerz.put(parameter, new ParameterListener[] {new_listener});

      } else {

        ParameterListener[] new_listeners = new ParameterListener[listeners.length + 1];

        if (Constants.IS_CVS_VERSION && listeners.length > 100) {
          Debug.out(parameter);
        }

        int pos;

        if (new_listener instanceof PriorityParameterListener) {

          new_listeners[0] = new_listener;

          pos = 1;

        } else {

          new_listeners[listeners.length] = new_listener;

          pos = 0;
        }

        for (int i = 0; i < listeners.length; i++) {

          ParameterListener existing_listener = listeners[i];

          if (existing_listener == new_listener) {

            return;
          }

          new_listeners[pos++] = existing_listener;
        }

        if (DEBUG_PARAMETER_LISTENERS) {

          System.out.println(parameter + "->" + new_listeners.length);
        }

        parameterListenerz.put(parameter, new_listeners);
      }
    }
  }
  private void updateExportableParameter(String key) {
    Object o_value = getParameter(key);

    String value;

    if (o_value == null) {

      value = null;

    } else if (o_value instanceof byte[]) {

      try {
        value = new String((byte[]) o_value, "UTF-8");

      } catch (UnsupportedEncodingException e) {

        value = null;
      }
    } else {

      value = String.valueOf(o_value);
    }

    synchronized (exported_parameters) {
      String[] entry = exported_parameters.get(key);

      if (entry != null) {

        String existing = entry[1];

        if (existing != value) {

          if (existing == null || value == null || !existing.equals(value)) {

            entry[1] = value;

            if (!exported_parameters_dirty) {

              exported_parameters_dirty = true;

              new DelayedEvent(
                  "epd",
                  5000,
                  new AERunnable() {

                    @Override
                    public void runSupport() {
                      exportParameters();
                    }
                  });
            }
          }
        }
      }
    }
  }
  private ConfigurationManager(Map data) {
    // default state of play for config initialised from map is debug log files off unless already
    // specified

    if (data.get("Logger.DebugFiles.Enabled") == null) {

      data.put("Logger.DebugFiles.Enabled", new Long(0));
    }

    propertiesMap = new ConcurrentHashMapWrapper<String, Object>(data);
  }
  public void removeParameterListener(String parameter, ParameterListener listener) {

    if (parameter == null || listener == null) {
      return;
    }

    synchronized (parameterListenerz) {
      ParameterListener[] listeners = parameterListenerz.get(parameter);

      if (listeners == null) {

        return;
      }

      if (listeners.length == 1) {

        if (listeners[0] == listener) {

          parameterListenerz.remove(parameter);
        }
      } else {

        ParameterListener[] new_listeners = new ParameterListener[listeners.length - 1];

        int pos = 0;

        for (int i = 0; i < listeners.length; i++) {

          ParameterListener existing_listener = listeners[i];

          if (existing_listener != listener) {

            if (pos == new_listeners.length) {

              return;
            }

            new_listeners[pos++] = existing_listener;
          }
        }

        if (DEBUG_PARAMETER_LISTENERS) {

          System.out.println(parameter + "->" + new_listeners.length);
        }

        parameterListenerz.put(parameter, new_listeners);
      }
    }
  }
  public void registerExportedParameter(String name, String key) {
    synchronized (exported_parameters) {
      String[] entry = exported_parameters.get(key);

      if (entry == null) {

        entry = new String[] {name, imported_parameters.remove(name)};

        exported_parameters.put(key, entry);
      }
    }

    addParameterListener(key, exportable_parameter_listener);

    updateExportableParameter(key);
  }
  public void setAuthenticationOutcome(
      String realm, String protocol, String host, int port, boolean success) {
    try {
      this_mon.enter();

      String tracker = protocol + "://" + host + ":" + port + "/";

      String auth_key = realm + ":" + tracker;

      authCache cache = (authCache) auth_cache.get(auth_key);

      if (cache != null) {

        cache.setOutcome(success);
      }
    } finally {

      this_mon.exit();
    }
  }
Exemple #11
0
  public static void setUDPProbeResult(URL tracker_url, boolean probe_ok) {
    String key = tracker_url.getHost();

    synchronized (udp_probe_results) {
      boolean changed = false;

      if (udp_probe_results.get(key) == null) {

        if (probe_ok) {

          // arbitrary max size here just in case something weird happens

          if (udp_probe_results.size() > 512) {

            udp_probe_results.clear();
          }

          udp_probe_results.put(key, new Long(SystemTime.getCurrentTime()));

          changed = true;
        }
      } else {

        if (!probe_ok) {

          if (udp_probe_results.remove(key) != null) {

            changed = true;
          }
        }
      }

      if (changed) {

        COConfigurationManager.setParameter("Tracker Client UDP Probe Results", udp_probe_results);
      }
    }
  }
  public void generate(IndentWriter writer) {
    writer.println("Configuration Details");

    try {
      writer.indent();

      writer.println(
          "version=" + Constants.AZUREUS_VERSION + ", subver=" + Constants.AZUREUS_SUBVER);

      writer.println("System Properties");

      try {
        writer.indent();

        Properties props = System.getProperties();

        Iterator it = new TreeSet(props.keySet()).iterator();

        while (it.hasNext()) {

          String key = (String) it.next();

          writer.println(key + "=" + props.get(key));
        }
      } finally {

        writer.exdent();
      }

      writer.println("Environment");

      try {
        writer.indent();

        Map<String, String> env = System.getenv();

        if (env == null) {

          writer.println("Not supported");

        } else {

          Iterator it = new TreeSet(env.keySet()).iterator();

          while (it.hasNext()) {

            String key = (String) it.next();

            writer.println(key + "=" + env.get(key));
          }
        }
      } finally {

        writer.exdent();
      }

      writer.println("Azureus Config");

      ConfigurationDefaults defaults = ConfigurationDefaults.getInstance();

      try {
        writer.indent();

        Set<String> keys =
            new TreeSet<String>(
                new Comparator<String>() {
                  public int compare(String o1, String o2) {
                    return (o1.compareToIgnoreCase(o2));
                  }
                });

        keys.addAll(propertiesMap.keySet());

        Iterator<String> it = keys.iterator();

        while (it.hasNext()) {

          String key = it.next();

          // don't dump crypto stuff

          if (ignoreKeyForDump(key)) {

            continue;
          }

          Object value = propertiesMap.get(key);

          boolean bParamExists = defaults.doesParameterDefaultExist(key.toString());

          if (!bParamExists) {

            key = "[NoDef] " + key;
          } else {

            Object def = defaults.getParameter(key);

            if (def != null && value != null) {

              if (!BEncoder.objectsAreIdentical(def, value)) {

                key = "-> " + key;
              }
            }
          }

          if (value instanceof Long) {

            writer.println(key + "=" + value);

          } else if (value instanceof List) {

            writer.println(
                key + "=" + BDecoder.decodeStrings((List) BEncoder.clone(value)) + "[list]");

          } else if (value instanceof Map) {

            writer.println(
                key + "=" + BDecoder.decodeStrings((Map) BEncoder.clone(value)) + "[map]");

          } else if (value instanceof byte[]) {

            byte[] b = (byte[]) value;

            boolean hex = false;

            for (int i = 0; i < b.length; i++) {

              char c = (char) b[i];

              if (!(Character.isLetterOrDigit(c)
                  || "\\ `¬\"£$%^&*()-_=+[{]};:'@#~,<.>/?'".indexOf(c) != -1)) {

                hex = true;

                break;
              }
            }
            writer.println(
                key + "=" + (hex ? ByteFormatter.nicePrint(b) : bytesToString((byte[]) value)));

          } else {

            writer.println(key + "=" + value + "[unknown]");
          }
        }
      } finally {

        writer.exdent();
      }
    } finally {

      writer.exdent();
    }
  }
  public PasswordAuthentication getAuthentication(
      String realm, String protocol, String host, int port) {
    try {
      this_mon.enter();

      String tracker = protocol + "://" + host + ":" + port + "/";

      InetAddress bind_ip = NetworkAdmin.getSingleton().getSingleHomedServiceBindAddress();

      String self_addr;

      // System.out.println( "auth req for " + realm + " - " + tracker );

      if (bind_ip == null || bind_ip.isAnyLocalAddress()) {

        self_addr = "127.0.0.1";

      } else {

        self_addr = bind_ip.getHostAddress();
      }

      // when the tracker is connected to internally we don't want to prompt
      // for the password. Here we return a special user and the password hash
      // which is picked up in the tracker auth code - search for "<internal>"!

      // also include the tracker IP as well as for scrapes these can occur on
      // a raw torrent which hasn't been modified to point to localhost

      if (host.equals(self_addr)
          || host.equals(COConfigurationManager.getStringParameter("Tracker IP", ""))) {

        try {
          byte[] pw = COConfigurationManager.getByteParameter("Tracker Password", new byte[0]);

          String str_pw = new String(Base64.encode(pw));

          return (new PasswordAuthentication("<internal>", str_pw.toCharArray()));

        } catch (Throwable e) {

          Debug.printStackTrace(e);
        }
      }

      String auth_key = realm + ":" + tracker;

      authCache cache = (authCache) auth_cache.get(auth_key);

      if (cache != null) {

        PasswordAuthentication auth = cache.getAuth();

        if (auth != null) {

          return (auth);
        }
      }

      String[] res = getAuthenticationDialog(realm, tracker);

      if (res == null) {

        return (null);

      } else {

        PasswordAuthentication auth = new PasswordAuthentication(res[0], res[1].toCharArray());

        boolean save_pw = res[2].equals("true");

        boolean old_entry_existed =
            auth_cache.put(auth_key, new authCache(auth_key, auth, save_pw)) != null;

        if (save_pw || old_entry_existed) {

          saveAuthCache();
        }

        return (auth);
      }
    } finally {

      this_mon.exit();
    }
  }