JavaFX WebEngine connection timeout - https

This very simple code:
final WebView browser = new WebView();
final WebEngine engine = browser.getEngine();
engine.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() {
#Override
public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) {
if (engine.getLoadWorker().getException() != null && newState == State.FAILED) {
LogUtil.getLog().error("Fallo al cargar la página", engine.getLoadWorker().getException());
}
}
});
final String url = webBean.getURL();
engine.load(url);
when loading an URL using https succeeds in JDK1.7.0_80 in a MacOSX, but fails in Windows using the same JDK version. The exception is a 'connection timeout'. The only difference I can see is that the Windows environment uses a proxy, but the same https URL in the same Windows environment and using the same proxy but with an external browser loads without problems too.
I'm really stucked with this problem.

Related

Xamarin Forms: System.Net.Http.HttpClient connect via https and ServerCertificateValidationCallback not hitted

In Xamarin Forms app I am using System.Net.Http.HttpClient to establish connection to server via https. Visual Studio version 16.5.4, Xamarin Forms version 4.5.0.617, android: target framework: Android 9.0 (Pie), iOS: SDK version 13.4. I want to accept only one certificate that comes from CA. Just after start, before first request, I am validating server certificate by:
private const string SupportedPublicKey = "118SDD782...HA4JD";
public static void SetUp()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback += ValidateServerCertficate;
}
private static bool ValidateServerCertficate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
var certKey = certificate?.GetPublicKeyString();
return SupportedPublicKey == certificate?.GetPublicKeyString();
}
Program is hitting breakpoint at SetUp method, but the breakpoint inside event is never hitted. I have put there Console.WriteLine() there methods to check if debugger is broken, but console is clear, so program never reach that code.
Right now application on both platforms, on emulators and real devices, behaves like it accepts all certificates, no matter where they come from and connect to other servers via https.
I have tried to change project properties on android: HttpClient implementation from "default" to "Managed" and "android" and on iOS: from "managed(default)" to "NSUrlSession (iOS 7+)" and "CFNetwork (iOS 6+)" to but there is no effect.
How can I fix it?
Try to change your code to use the new HttpClientHandler.ServerCertificateCustomValidationCallback APIs from .NET Core.
public static void SetUp()
{
HttpClientHandler httpClientHandler = new HttpClientHandler();
httpClientHandler.ServerCertificateCustomValidationCallback = ValidateServerCertficate;
}
private static bool ValidateServerCertficate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
var certKey = certificate?.GetPublicKeyString();
return SupportedPublicKey == certificate?.GetPublicKeyString();
}
You could refer this on github

I am facing issue in executing our Selenium test on safari browser on Mac machine

We are facing issue in switching to the new window on safari browser. Below is our code used for switching the window.
public void switchToWindow() {
Set<String> availableWindows = driver.getWindowHandles();
for (String strWinHandle : availableWindows) {
driver.switchTo().window(strWinHandle);
}
}
In availableWindows, it returns all window handles but instead of switching to new window, it is switching to parent window.
Above code works fine on all other browsers.
Selenium version - 3.11.0
Safari version - 11.1.1
You can try the following code.
public void switchToWindow() {
String curWinHandle = driver.getWindowHandle();
Set<String> availableWindows = driver.getWindowHandles();
for (String strWinHandle : availableWindows) {
if(!curWinHandle.equals(strWinHandle))
driver.switchTo().window(strWinHandle);
}
}

Xamarin PCL self signed certificat for Android and IOS

I'm trying to pass my full Rest service from http to https.
I created a self-signed certificate, I had it to IIS Express. I validate it on google Chrome and it work perfectly fine with postman. My rest service work in http and https.
I use a PCL project (IOS and Android) everything is working fine with http request but I have exception with https request. the exception message is null.
I tried to create a test certificate directly from Visual Studio 2015 but the button is disabled in properties ->Signing.
I also tried to install my self-signed certificate as a Trusted Root but no success for the communication between my simulator and my rest Service.
my code
public partial class MainPage : ContentPage
{
private string url = string.Empty;
private HttpClient _client;
public MainPage()
{
InitializeComponent();
switch (Device.RuntimePlatform)
{
case Device.iOS:
_client = new HttpClient(new NSUrlSessionHandler());
break;
case Device.Android:
_client = new HttpClient();
break;
}
_client = new HttpClient();
test();
}
private async void test()
{
//url = "http://192.168.1.106:9630/PrototypeB.svc/Test";
url = "https://192.168.1.106:44301/PrototypeB.svc/Test";
try
{
var _content = await _client.GetStringAsync(url);
List<Test> _posts = JsonConvert.DeserializeObject<List<Test>>(_content);
}
catch (HttpRequestException e)
{
string test = e.Message;
}
catch (Exception e)
{
string test = e.Message;
}
}
}
How can I communicate with my Android and IOS Simulator with https and self-signed certificate?
You can use ServicePointManager to ignore the certificate validation check.
Execute the code in your iOS and Android platforms like this:
System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) => {
return true;
};
References:
Untrusted HTTPS
certificate
HTTPS ignore
certificate
Ignore SSL certificate errors in Xamarin.Forms (PCL)
SSL Validation in
PCL
Also, ModernHttpClient Pro provide this feature, but it is not free.

404 error when using https with signalR

I am using signalR over https and I have seeming done everything off this site:
https://weblog.west-wind.com/posts/2013/Sep/23/Hosting-SignalR-under-SSLhttps
Yet, I am still getting a 404 error when I signalr is trying to connect.
https://localhost:9000//negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22logshub%22%7D%5D&_=1438785507850 404 (Not Found)
This is my OWIN startup program starting on https://*:9000
class Program
{
static void Main(string[] args)
{
string dbFile = "logDB.sqlite";
if (!File.Exists(dbFile))
{
SQLiteDataProviderCreator.Create();
SQLiteDataProviderCreator.CreateDataBase();
}
IDataProvider provider = new SQLiteDataProvider("Data Source=logdb.sqlite;Version=3;PRAGMA journal_mode=WAL;Pooling=True;Max Pool Size=100;");
LogsModule.Provider = provider;
using (WebApp.Start<Startup>("https://*:9000/"))
{
Console.WriteLine("Launched site on Port 9000");
Console.WriteLine("Press [enter] to quit...");
Console.ReadLine();
}
}
}
And here the javascript that is supposed to allow it to connect over https.
var hubUrl = "https://localhost:9000/signalr";
$.connection.hub.url = hubUrl;
$.connection.hub.logging = true;
I also created a cert using makecert and bound it to the endpoint 0.0.0.0:9000.
Had a similar issue where I had to run the program as administrator.
For anyone else that comes across this.
The hubUrl should normally be:
var hubUrl = "https://localhost:9000/signalr/hubs";
This is even shown in the link provided.
Also, needs to ensure that the hub script is loaded prior to this script:
<script src='https://localhost:9000/signalr/hubs'></script>

HttpWebRequest and WebClient returning NotFound on Windows Phone 7 but not i normal console application

I'm trying to download a regular JSON string from this url https://valueboxtest.lb.dk/mobile/categories from a Windows Phone 7 Application.
I have tried to both use WebClient and HttpWebRequest. They both throw an exception
“The remote server returned an error: NotFound”
This is the code for using the WebClient
var webClient = new WebClient();
webClient.DownloadStringCompleted += (client_DownloadStringCompleted);
webClient.DownloadStringAsync(new Uri("https://valueboxtest.lb.dk/mobile/categories"));
The eventhandler then just show the content, but e.Result throws the above mentioned exception:
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null && !e.Cancelled) MessageBox.Show(e.Result);
}
For the HttpWebRequest my code looks as follows:
var httpReq = (HttpWebRequest)WebRequest.Create(new Uri("https://valueboxtest.lb.dk/mobile/categories"));
httpReq.BeginGetResponse(HTTPWebRequestCallBack, httpReq);
With the following callback:
private void HTTPWebRequestCallBack(IAsyncResult result)
{
var httpRequest = (HttpWebRequest)result.AsyncState;
var response = httpRequest.EndGetResponse(result);
var stream = response.GetResponseStream();
var reader = new StreamReader(stream);
this.Dispatcher.BeginInvoke(
new delegateUpdate(update),
new Object[] { reader.ReadToEnd() }
);
}
And with the delegate method
delegate void delegateUpdate(string content);
private void update(string content)
{
MessageBox.Show(content);
}
Running it in a console application
Everything works just fine and the JSON string is returned with no problems and I am able to print the result to the console.
Different URL does work on WP7
The weird thing is that the URL http://mobiforge.com/rssfeed actually works fine in both of the above mentioned scenarios.
This issue occurs both in the Emulator and on an actual device.
What could be wrong? Is the REST service returning the data in misbehaving way? I really hope you can help me!
Note: I'm not running Fiddler2 at the same time!
The reason is because that site does not have a valid certificate. Just try it on Mobile Internet Explorer and you'll get the prompt about an issue with the certificate.
How to ignore SSL certificates
Mobile devices are stricter when it comes to SSL certificates.
If you want to get this app into a production environment, you'll either need to write a wrapper for this server (if it's not your own), or get a valid certificate. In the short-term, for testing, you can add a certificate into your device.
Here's a tool which might help you install a certificate.

Resources