- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个 Java 应用程序 - 将在 App Engine 上运行 - 它会定期检查我们的网络应用程序使用的 SSL 证书,并在它们即将过期时向我们发出警告。
我希望使用下面的代码,如果证书在 2 周内过期,它会抛出异常(我通过删除一些错误检查来简化它)。
GregorianCalendar cal = new GregorianCalendar();
cal.add(Calendar.DAY_OF_YEAR, 14);
Date twoWeeksInTheFuture = cal.getTime();
URL url = new URL(https_url);
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
// Need the following line in order to establish a connection with the server
con.getResponseCode();
Certificate[] certs = con.getServerCertificates();
Certificate certificate = certs[0];
X509Certificate x509Certificate = (X509Certificate) certificate;
x509Certificate.checkValidity(twoWeeksInTheFuture);
该代码在 App Engine 之外运行良好(例如,在 Java 类的主要方法中)。但是,在 App Engine 中运行时会抛出以下异常:
java.lang.ClassCastException: com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection cannot be cast to javax.net.ssl.HttpsURLConnection
at com.bronzelabs.httpschecker.servlets.cron.HttpsChecker.doGet(HttpsChecker.java:101)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
HttpsURLConnection 在 whitelist of allowed classes 中所以必须有一种方法可以在 App Engine 上使用这个类(好吧,你会假设)。看起来您不能使用 URL.openConnection()。
有谁知道建立 HTTPS 连接(在 App Engine 上使用 Java)和查看 SSL 证书详细信息的方法?
注意:我看过 Google 的 URLFetchService。似乎没有任何方法可以访问证书(只有 HTTP 请求的内容)。
最佳答案
正如您(正确地)观察到的那样,在标准环境中无法使用内置的 URLFetchService 来执行此操作。有关您可以使用 URLFetchService 和 HTTPS 执行的操作的详细信息,请参阅 here .您可以使用第三方库来执行此操作,但是 request proxying也可能是一个障碍(试试 sockets API ,也许吧?);你可以尝试使用 flexible environment而不是取决于您的用例。
关于java - 在 Google App Engine 上使用 HttpsURLConnection 检索证书详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39878599/
我有一个在 eclipse 中开发的类(在同一台计算机上),我正试图将它带到 Android Studio 中。 Android Studio 给我一个错误,它无法解析符号 HttpsURLConne
我试图使这个curl请求从Java可执行: curl -H 'Accept: application/vnd.twitchtv.v2+json' \ -d "channel[status]=testi
我正在使用 HttpsURLConnection 连接客户端应用程序。我正在为 1 个用户请求发送多个请求(例如登录、dosearch 和 getResult)。 对于第一个用户的请求(服务器第一个请
我必须每 5 分钟从我的 Minecraft 服务器向其他服务器 (Https) 中的 API 发出 https 请求,以交换 secret 信息。此 Java 代码是否足够安全,能够抵御中间人攻击?
我正在尝试根据 How do a send an HTTPS request through a proxy in Java? 使用代理访问 https 网页 但是我遇到了一个奇怪的问题:HttpsU
我创建了一个HttpsURLConnection,如下所示: try { URL url = new URL( host );
我有一个简单的客户端-服务器应用程序,它通过 REST API 下载文件。当我使用基本的 http 身份验证时,文件是通过 ssl 发送的。 //my download loop HttpsURLCo
我尝试过解决这个问题,但没有找到好的解决方案。我刚刚用 httsurlconnection 打开了一个套接字并关闭了。但是,我打开的套接字没有关闭,并且套接字状态为 CLOSE_WAIT。这是我的代码
我正在尝试使用 HttpsURLConnection 与网站建立 HTTPS 连接,然后执行 PUT 请求。当我尝试从 HttpsURLConnection.getOutputStream() 创建
我正在使用以下代码进行发布请求 public String executeHttpPost(String uri, String data) { HttpURLConnection conn
我有一个针对 ICS 及更高版本的应用程序,我正在尝试使用 HttpsURLConnection 和 HttpResponseCache 来缓存网络服务响应。它使用 etag 发出请求,如果未修改,服
我是 android 编程的新手。我遵循了 api 示例 https://developer.android.com/reference/java/net/HttpURLConnection.html
我正在尝试向服务器发送客户端证书。我正在 HttpURLConnection 上构建 SSLSocketFactory。 我认为我需要通过 SSLSocketFactory 知道的 KeyManage
我的代码向网站发出 POST 请求,但响应看起来像是加密的,带有奇怪的字符。当我将我的应用配置为使用 fiddler 代理时,响应有效。我怎样才能让我的应用解密这个响应? public class L
我编写了一个应用程序来测试 servlet 的性能。我编写的代码可以很好地满足某些请求。如果我增加更多连接,有时我会收到“写入字节数过多”异常。 int startRange = 0, endRang
我正在尝试制作一个固定 ssl 证书的应用程序。我有一个使用 HttpsURLConnection 创建服务器连接的类。当我使用普通互联网连接进行连接时,它连接正常。当我使用代理 (mitmproxy
这个问题在这里已经有了答案: Get SSL Version used in HttpsURLConnection - Java (1 个回答) 关闭 5 年前。
我有一个使用 HttpsUrlConnection 执行 POST 请求的代码,该代码工作正常,但我的一些用户拥有带有封闭用户组的 SIM 卡,他们需要在他们的 apn 设置中设置代理。如果他们设置代
我遇到了似乎无法解决的 HttpsURLConnection 问题。基本上,我正在向服务器发送一些信息,如果其中一些数据有误,服务器会向我发送一个 500 响应代码。但是,它还在响应中发送了一条消息,
我希望有人可以帮助我解决间歇性连接问题通过 HttpsURLConnection 使用代码。我使用的代码是下面: HttpsURLConnection conn = (HttpsURLConnecti
我是一名优秀的程序员,十分优秀!