From 5b7f0fcad39b499fecf05cb8667f4d35ea28f9ca Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Sat, 28 Sep 2013 17:19:14 +0400 Subject: [PATCH] Github: select 'Host' part of url for list of trusted hosts Before this commit we save 'https://mycompany.com/github' from settings and compare it with 'mycompany.com' from URI --- .../plugins/github/util/GithubSslSupport.java | 8 +++++++- .../plugins/github/util/GithubUrlUtil.java | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/plugins/github/src/org/jetbrains/plugins/github/util/GithubSslSupport.java b/plugins/github/src/org/jetbrains/plugins/github/util/GithubSslSupport.java index d2aa2f1568a8..e8b34c1ef332 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/util/GithubSslSupport.java +++ b/plugins/github/src/org/jetbrains/plugins/github/util/GithubSslSupport.java @@ -111,7 +111,13 @@ public class GithubSslSupport { } @CalledInAwt - public boolean askIfShouldProceed(final String host) { + public boolean askIfShouldProceed(final String url) { + String host = GithubUrlUtil.getHostFromUrl(url); + if (host == null) { + GithubUtil.LOG.warn("Bad SSL host: " + url); + return false; + } + final String BACK_TO_SAFETY = "No, I don't trust"; final String TRUST = "Proceed anyway"; //int choice = Messages.showDialog("The security certificate of " + host + " is not trusted. Do you want to proceed anyway?", diff --git a/plugins/github/src/org/jetbrains/plugins/github/util/GithubUrlUtil.java b/plugins/github/src/org/jetbrains/plugins/github/util/GithubUrlUtil.java index c208e4db0ec1..c93f648d0728 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/util/GithubUrlUtil.java +++ b/plugins/github/src/org/jetbrains/plugins/github/util/GithubUrlUtil.java @@ -16,6 +16,8 @@ package org.jetbrains.plugins.github.util; import com.intellij.openapi.util.text.StringUtil; +import org.apache.commons.httpclient.URI; +import org.apache.commons.httpclient.URIException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.github.api.GithubApiUtil; @@ -71,6 +73,19 @@ public class GithubUrlUtil { return "https://" + getGitHostWithoutProtocol(); } + /** + * E.g.: https://github.com/suffix/ -> github.com + */ + @Nullable + public static String getHostFromUrl(@NotNull String url) { + try { + return new URI(url, false).getHost(); + } + catch (URIException e) { + return null; + } + } + /** * E.g.: github.com * my.company.url