Advertisement
Vaerys_Dawn

SSL handshake exception

Sep 3rd, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.41 KB | None | 0 0
  1. //Message
  2.  
  3. $$fixit >>> customcommands >>> sendFileURL >>> https://my.mixtape.moe/ypzgwd.png
  4.  
  5. //Error
  6. 11:47:43.006 [GuildCreateGroup-Thread-5] ERROR javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
  7.         at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
  8.         at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)
  9.         at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
  10.         at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
  11.         at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1497)
  12.         at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:212)
  13.         at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979)
  14.         at sun.security.ssl.Handshaker.process_record(Handshaker.java:914)
  15.         at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062)
  16.         at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
  17.         at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
  18.         at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
  19.         at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
  20.         at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
  21.         at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1512)
  22.         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
  23.         at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
  24.         at com.github.vaerys.main.Utility.sendFileURL(Utility.java:297)
  25.         at com.github.vaerys.handlers.CCHandler.handleCommand(CCHandler.java:133)
  26.         at com.github.vaerys.handlers.CCHandler.<init>(CCHandler.java:52)
  27.         at com.github.vaerys.handlers.MessageHandler.<init>(MessageHandler.java:43)
  28.         at com.github.vaerys.main.AnnotationListener.onMessageReceivedEvent(AnnotationListener.java:77)
  29.         at sx.blah.discord.api.events.EventDispatcher$MethodEventHandler.handle(EventDispatcher.java:723)
  30.         at sx.blah.discord.api.events.EventDispatcher.lambda$null$19(EventDispatcher.java:653)
  31.         at sx.blah.discord.api.events.EventDispatcher$$Lambda$48/921814994.run(Unknown Source)
  32.         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  33.         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  34.         at java.lang.Thread.run(Thread.java:745)
  35. Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
  36.         at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387)
  37.         at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
  38.         at sun.security.validator.Validator.validate(Validator.java:260)
  39.         at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)
  40.         at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)
  41.         at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
  42.         at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1479)
  43.         ... 23 more
  44. Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
  45.         at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:145)
  46.         at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:131)
  47.         at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
  48.         at sun.security.validator.P
  49.  
  50. //Code
  51. public static IMessage sendFileURL(String message, String imageURL, IChannel channel, boolean loadMessage) {
  52.         IMessage toDelete = null;
  53.         if (loadMessage) {
  54.             toDelete = sendMessage("`Loading...`", channel).get();
  55.         }
  56.         IMessage sentMessage = null;
  57.         try {
  58.             //setup for the stream
  59.             final HttpURLConnection connection = (HttpURLConnection) new URL(imageURL).openConnection();
  60.             connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) " + "AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31");
  61.             InputStream stream = connection.getInputStream();
  62.             sentMessage = (IMessage) XRequestBuffer.request(() -> {
  63.                 try {
  64.                     //set up the file name
  65.                     URL url = new URL(imageURL);
  66.                     String filename = FilenameUtils.getName(url.getPath());
  67.                     if (filename.equalsIgnoreCase("giphy.gif")) {
  68.                         return sendMessage(message + " " + imageURL, channel).get();
  69.                     }
  70.                     //checks if url is valid
  71.                     if (!isImageLink(filename)) {
  72.                         return sendMessage(message + " " + imageURL, channel).get();
  73.                     }
  74.                     //sends message/files
  75.                     if (StringUtils.containsOnly(message, "\n") || (message == null) || message.equals("") && imageURL != null) {
  76.                         return channel.sendFile("", stream, filename);
  77.                     } else if (message != null && !message.isEmpty() && imageURL != null) {
  78.                         return channel.sendFile(removeMentions(message), false, stream, filename);
  79.                     } else {
  80.                         logger.debug("Error sending File to channel with id: " + channel.getStringID() + " on guild with id: " + channel.getGuild().getStringID() +
  81.                                 ".\n" + Constants.PREFIX_EDT_LOGGER_INDENT + "Reason: No file to send");
  82.                         return null;
  83.                     }
  84.                 } catch (DiscordException e) {
  85.                     if (e.getMessage().contains("CloudFlare")) {
  86.                         return sendFileURL(message, imageURL, channel, false);
  87.                     } else {
  88.                         sendStack(e);
  89.                         return null;
  90.                     }
  91.                 } catch (MalformedURLException e) {
  92.                     return sendMessage(message + " " + imageURL, channel).get();
  93.                 } catch (IOException e) {
  94.                     sendStack(e);
  95.                     return null;
  96.                 } catch (MissingPermissionsException e) {
  97.                     logger.debug("Error sending File to channel with id: " + channel.getStringID() + " on guild with id: " + channel.getGuild().getStringID() +
  98.                             ".\n" + Constants.PREFIX_EDT_LOGGER_INDENT + "Reason: Missing permissions.");
  99.                     return sendMessage(message + " <" + imageURL + ">", channel).get();
  100.                 }
  101.             }).get();
  102.             stream.close();
  103.         } catch (MalformedURLException e) {
  104.             sendStack(e);
  105.         } catch (IOException e) {
  106.             sendStack(e);
  107.         }
  108.         if (loadMessage && toDelete != null) {
  109.             deleteMessage(toDelete);
  110.         }
  111.         return sentMessage;
  112.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement