Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Scaricare file da HTTPS

    ciao!

    per un programmino mi servirebbe scaricare una libreria dal web.
    solo che l'indirizzo è in HTTPS, e quando provo a scaricarlo da java mi da questo errore:
    codice:
    java.lang.RuntimeException: Could not generate DH keypair
    per il download sto usando la libreria Apache Commons IO, ma leggendo in giro non dovrebbe dipendere da quello.
    ed infatti ho trovato vari esempi tipo questo:
    codice:
        public void install() throws IOException, KeyManagementException, NoSuchAlgorithmException {
            TrustManager[] trustAllCerts;
            trustAllCerts = new TrustManager[]{
                new X509TrustManager() {
                    @Override
                    public X509Certificate[] getAcceptedIssuers() {
                        return null;
                    }
    
                    @Override
                    public void checkClientTrusted(
                            X509Certificate[] certs, String authType) {
                    }
    
                    @Override
                    public void checkServerTrusted(
                            X509Certificate[] certs, String authType) {
                    }
                }
            };
            SSLContext sc = SSLContext.getInstance("SSL");
            sc.init(null, trustAllCerts, new SecureRandom());
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
            FileUtils.copyURLToFile(new URL(remoteFile), new File(fileYdl), 20000, 20000);
            ydlEnd.setExecutable(true);
        }
    però non riesco ad applicarlo, nel senso che mi da cmq quell'errore.
    posso anche fare a meno di Apache Commons IO ovviamente.
    ma mi manca cmq qualcosa.

    avete qualche dritta??

  2. #2
    allora, ho provato a scaricare un altro file (una immagine png) da un altro sito web sempre HTTPS.
    il download è andato a buon fine.

    allora ho provato a scaricare quel binario usando python, e non ho avuto problemi.

    possibile che java abbia qualche restrizione di qualche tipo??

  3. #3
    ok ho risolto.

    prima ho aggiunto una libreria (usando maven):
    codice:
            <dependency>
                <groupId>org.bouncycastle</groupId>
                <artifactId>bcprov-jdk15on</artifactId>
                <version>1.58</version>
            </dependency>
    poi, prima di fare qualsiasi tipo di connessione:
    codice:
    Security.insertProviderAt(new BouncyCastleProvider(), 1);
    questo il trace dell'errore (che adesso non si presenta più):
    codice:
    javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair
        at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
        at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1959)
        at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1916)
        at sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1899)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1420)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
        at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1546)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
        at org.apache.commons.io.FileUtils.copyURLToFile(FileUtils.java:1506)
        at com.mp.ydl.InstallYDL.install(InstallYDL.java:39)
        at com.mp.ydl.MainWindow$3$1.doInBackground(MainWindow.java:69)
        at com.mp.ydl.MainWindow$3$1.doInBackground(MainWindow.java:64)
        at javax.swing.SwingWorker$1.call(SwingWorker.java:295)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at javax.swing.SwingWorker.run(SwingWorker.java:334)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
    Caused by: java.lang.RuntimeException: Could not generate DH keypair
        at sun.security.ssl.DHCrypt.<init>(DHCrypt.java:142)
        at sun.security.ssl.DHCrypt.<init>(DHCrypt.java:114)
        at sun.security.ssl.ClientHandshaker.serverKeyExchange(ClientHandshaker.java:711)
        at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:268)
        at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1026)
        at sun.security.ssl.Handshaker.process_record(Handshaker.java:961)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1072)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
        ... 16 more
    Caused by: java.security.InvalidAlgorithmParameterException: DH key size must be multiple of 64, and can only range from 512 to 2048 (inclusive). The specific key size 4096 is not supported
        at com.sun.crypto.provider.DHKeyPairGenerator.initialize(DHKeyPairGenerator.java:128)
        at java.security.KeyPairGenerator$Delegate.initialize(KeyPairGenerator.java:674)
        at sun.security.ssl.DHCrypt.<init>(DHCrypt.java:128)
        ... 24 more
    spero possa servire a qualcuno!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.