How to fetch Bukkit versions from a Java application?

Discussion in 'Bukkit Discussion' started by Assist, Apr 16, 2014.

Thread Status:
Not open for further replies.
  1. I've tried using Jsoup to connect to https://dl.bukkit.org/downloads/craftbukkit/, but I get a
    Code:java
    1. sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

    I'm trying to get the latest recommended, beta and dev versions. Any ideas?
     
  2. Offline

    Alshain01

    Use the ServerMods API

    http://wiki.bukkit.org/ServerMods_API

    EDIT: Sorry I misread, nevermind. I'm not sure how to do that, but there is probably some way to parse the Maven repository XML files to get what you want.
     
  3. Offline

    obnoxint

    Hello Assist ,

    the problem here is that the JRE doesn't find a key in the keystore. You can either install the key and point the JVM to your keystore or do it the hacky way and implement a TrustManager which simply trusts everything.
    Code:java
    1.  
    2. // Create a trust manager that does not validate certificate chains
    3. TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
    4. public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {};
    5. public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {};
    6. public X509Certificate[] getAcceptedIssuers() {return null;};
    7. }};
    8.  
    9. // Install the all-trusting trust manager
    10. SSLContext sc = SSLContext.getInstance("SSL");
    11. sc.init(null, trustAllCerts, new java.security.SecureRandom());
    12. HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    13.  
    14. // Create all-trusting host name verifier
    15. HostnameVerifier allHostsValid = new HostnameVerifier() {
    16. @Override
    17. public boolean verify(String hostname, SSLSession session) {
    18. return true;
    19. }
    20. };
    21.  
    22. // Install the all-trusting host verifier
    23. HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
    24.  

    As soon as you've successfully compromised the security of the JVM you can access HTTPS URLs like any other URL.

    This code
    Code:java
    1.  
    2. String u = "[url]https://dl.bukkit.org/downloads/craftbukkit/[/url]";
    3. URL url = new URL(u);
    4. Document doc = Jsoup.parse(url.openStream(), "UTF-8", u);
    5.  
    6. Elements elements = new Elements();
    7. elements.addAll(doc.getElementsByClass("chan-rb"));
    8. elements.addAll(doc.getElementsByClass("chan-beta"));
    9. elements.addAll(doc.getElementsByClass("chan-dev"));
    10.  
    11. for (Element el1 : elements) {
    12. for (Element el2 : el1.getElementsByTag("span")){
    13. System.out.println(el2.text());
    14. }
    15. }

    results in this output:
    Code:text
    1.  
    2. 1.6.4-R2.0
    3. 1.7.2-R0.3
    4. 1.7.8-R0.1
    5.  
     
    Assist and Necrodoom like this.
  4. obnoxint
    Thanks! Works like a charm.
     
Thread Status:
Not open for further replies.

Share This Page