示例#1
0
  /**
   * @param context if null, use the default format (Mozilla/5.0 (Linux; U; Android %s)
   *     AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 %sSafari/534.30).
   * @return
   */
  public static String getUserAgent(Context context) {
    String webUserAgent = null;
    if (context != null) {
      try {
        Class sysResCls = Class.forName("com.android.internal.R$string");
        Field webUserAgentField = sysResCls.getDeclaredField("web_user_agent");
        Integer resId = (Integer) webUserAgentField.get(null);
        webUserAgent = context.getString(resId);
      } catch (Throwable ignored) {
      }
    }
    if (TextUtils.isEmpty(webUserAgent)) {
      webUserAgent =
          "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 %sSafari/533.1";
    }

    Locale locale = Locale.getDefault();
    StringBuffer buffer = new StringBuffer();
    // Add version
    final String version = Build.VERSION.RELEASE;
    if (version.length() > 0) {
      buffer.append(version);
    } else {
      // default to "1.0"
      buffer.append("1.0");
    }
    buffer.append("; ");
    final String language = locale.getLanguage();
    if (language != null) {
      buffer.append(language.toLowerCase());
      final String country = locale.getCountry();
      if (country != null) {
        buffer.append("-");
        buffer.append(country.toLowerCase());
      }
    } else {
      // default to "en"
      buffer.append("en");
    }
    // add the model for the release build
    if ("REL".equals(Build.VERSION.CODENAME)) {
      final String model = Build.MODEL;
      if (model.length() > 0) {
        buffer.append("; ");
        buffer.append(model);
      }
    }
    final String id = Build.ID;
    if (id.length() > 0) {
      buffer.append(" Build/");
      buffer.append(id);
    }
    return String.format(webUserAgent, buffer, "Mobile ");
  }
示例#2
0
  public static void main(String[] args) throws Exception {
    try {
      Class.forName("javax.security.auth.kerberos.KerberosPrincipal");
      System.out.println("Kerberos is present, nothing to test");
      return;
    } catch (ClassNotFoundException okay) {
    }

    // test SSLSocket
    try (Socket s = SSLSocketFactory.getDefault().createSocket()) {
      SSLSocket sslSocket = (SSLSocket) s;

      checkNotSupported(sslSocket.getSupportedCipherSuites());

      // attempt to enable each of the Kerberos cipher suites
      for (String kcs : KERBEROS_CIPHER_SUITES) {
        String[] suites = {kcs};
        try {
          sslSocket.setEnabledCipherSuites(suites);
          throw new RuntimeException(
              "SSLSocket.setEnabledCipherSuitessuites allowed "
                  + kcs
                  + " but Kerberos not supported");
        } catch (IllegalArgumentException expected) {
        }
      }
    }

    // test SSLServerSocket
    try (ServerSocket ss = SSLServerSocketFactory.getDefault().createServerSocket()) {
      SSLServerSocket sslSocket = (SSLServerSocket) ss;

      checkNotSupported(sslSocket.getSupportedCipherSuites());

      // attempt to enable each of the Kerberos cipher suites
      for (String kcs : KERBEROS_CIPHER_SUITES) {
        String[] suites = {kcs};
        try {
          sslSocket.setEnabledCipherSuites(suites);
          throw new RuntimeException(
              "SSLSocket.setEnabledCipherSuitessuites allowed "
                  + kcs
                  + " but Kerberos not supported");
        } catch (IllegalArgumentException expected) {
        }
      }
    }
  }