javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated - exception

Simple codes
public class Demo {
public static void main(String[] args) {
HttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httpget = new HttpGet("https://banweb.cityu.edu.hk/");
HttpResponse response = httpclient.execute(httpget);
} catch (Exception e) {
e.printStackTrace();
}
}
}
I have 2 desktops (A and B), 2 laptops (A and B), 3 android devices (A, B and C) and 3 android emulators (SDK v2.1, v4.0 and v4.03). When above code is run in desktop A, android emulator v4.0 and v4.0.3, it throws "javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated". But the code works fine in other devices and emulators.
Can anyone tell me why the same code shows different results in different machines?
Your help is appreciated.

See this message post: SSL "Peer Not Authenticated" error with HttpClient 4.1
I think the issue is related to whether the machine/environment that you are using has access to the system wide root certificates. If the OS is newer it may recognize ( and verify/trust?) your signed certificate. However, if the JRE/JDK is not aware of the root CA store then it may not work.
I have a basic app that is working in Netbeans but not after I deploy the JavaFX project. I have added my root certificate to the keystore but it is still not working.

It may be that one of the machines is behind a proxy and the other is not?

Related

After copying setted up Chrome profile to another computer it misses cookies and installed extensions

I set up a Chrome profile with extension and some authorization cookies. It works good on my computer if I run it from the code. But when I copy this profile to another computer and run it from the code, then all the extensions and cookies of this profile are missing.
Why is it so? And how can I deal with it?
It is expected behavior.
See this code to launch browser with extension :
public static void main(String[] args){
System.setProperty("webdriver.chrome.driver", "F:\\Automation\\chromedriver.exe");
String pathToExtension = "C:\\Users\\USER_DELL_2014_07\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 3\\Extensions\\bhlhnicpbhignbdhedgjhgdocnmhomnp\\2.0_0";
ChromeOptions options = new ChromeOptions();
options.addArguments("load-extension=" + pathToExtension);
WebDriver driver = new ChromeDriver(options);
driver.manage().window().maximize();
}
pathToExtension which have value : C:\\Users\\USER_DELL_2014_07\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 3\\Extensions\\bhlhnicpbhignbdhedgjhgdocnmhomnp\\2.0_0
This path will be different for second machine because of USER_DELL_2014_07 this.
Hope this will be helpful.

Azure Mobile Services authentication not working with Windows Phone 8.1 Universal app

I'm adding Azure Mobile Services authentication to a Universal Windows project. It's all set up and working properly on the server and in the Windows Store version of the app, however I can't get it to work with the Windows Phone 8.1 version of the app. I actually have two different apps that I've been working on with the same problem, so I created a test app based strictly on the steps outlined in this article. The sample app has one button on the UI that will attempt authenticate the user with Twitter when pressed.
The flow that I am seeing from the UI is:
Press the button
Screen goes black for a moment
Screen displays "Resuming..." with a spinner
InvalidOperationException gets caught
The exception details:
System.InvalidOperationException was caught
HResult=-2146233079
Message=Authentication was cancelled by the user.
Source=mscorlib
StackTrace:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.WindowsAzure.MobileServices.MobileServiceAuthentication.<LoginAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at MobileAuthTest.MainPage.<AuthenticateAsync>d__3.MoveNext()
InnerException:
The code I am using is copied almost verbatim from the article, but I'll paste it here too:
private async void Button_Click(object sender, RoutedEventArgs e)
{
await this.AuthenticateAsync();
}
// Define a method that performs the authentication process
// using a Twitter sign-in.
private async Task AuthenticateAsync()
{
while (user == null)
{
string message;
try
{
// Change 'MobileService' to the name of your MobileServiceClient instance.
// Sign-in using Twitter authentication.
user = await App.mobileService
.LoginAsync(MobileServiceAuthenticationProvider.Twitter);
message =
string.Format("You are now signed in - {0}", user.UserId);
}
catch (InvalidOperationException)
{
message = "You must log in. Login Required";
}
var dialog = new MessageDialog(message);
dialog.Commands.Add(new UICommand("OK"));
await dialog.ShowAsync();
}
}
And this override is in App.xaml.cs:
protected override void OnActivated(IActivatedEventArgs args)
{
// Windows Phone 8.1 requires you to handle the respose from the WebAuthenticationBroker.
#if WINDOWS_PHONE_APP
if (args.Kind == ActivationKind.WebAuthenticationBrokerContinuation)
{
// Completes the sign-in process started by LoginAsync.
// Change 'MobileService' to the name of your MobileServiceClient instance.
mobileService.LoginComplete(args as WebAuthenticationBrokerContinuationEventArgs);
}
#endif
base.OnActivated(args);
}
My testing is all on a real Windows Phone 8.1 device (Nokia 920 with 8.1 update).
It's also worth pointing out that the project I'm currently trying to get this to work in is also using Xamarin.Forms for Android, iOS and Windows Phone (I wanted a comparison between Xamarin.Forms for Windows Phone and Universal apps for Windows Phone). All of the apps work, EXCEPT for the two Windows Phone apps. The Xamarin.Forms Windows Phone app is a Windows Phone Silverlight 8.1 app which acts the same as described above for the Universal WP, but fails with the error, "Authentication failed with HTTP response code 0."
I've searched around and haven't found any other cases of people encountering the same issue I am. Is there something I need to do that is so simple nobody feels the need to say it in writing?
Well, it turns out that the issue I am seeing may just be my device. I sent the sample app to another dev for testing and he had no issues. I also was able to successfully log in with both the sample app and the real app on the simulator. That isn't exactly a thorough test sample, but it's enough for me to stop banging my head on this desk.

Windows Phone 8 app crashes when redirecting between pages

I am developing a hybrid app which works fine on android and ios. But in windows, at times application crashes when redirecting between pages. I am getting following error messages in Visual Studio output window.
System.SystemException
Microsoft.Phone.Interop.ni.dll but was not handled in user code
It breaks the application at following point in App.xaml.cs.
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
}
I have no idea which part of code is causing this and I have never seen any such crash before.
Please throw some light on this issue!
Thanking you in anticipation!

Geolocator.GetGeopositionAsync throw "Class not registered" exception c#

I run next code in blank project and got "Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))"
private Windows.Devices.Geolocation.Geolocator locator = new Windows.Devices.Geolocation.Geolocator();
private async void Button_Click(object sender, RoutedEventArgs e)
{
try
{
var position = await this.locator.GetGeopositionAsync();
}
catch (Exception ex)
{
//Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
}
}
Also, I tried to run Geolocation Sample 8.1 (c# and JS) but got the same exception and I tried to run this sample not on 1 PC and not on 1 network. All the same.
I have win8.1 rtm and VS2013 RC on my laptop.
Also, I run this code and Microsoft sample on ARM tablet with 8.1 Pro preview (with GNSS module) and on tablet(i5-3317U Processor and without GPS module) with 8.1 rtm. I didn't get this exception and all works fine. So I think it only occured on PC/Simulator.
How to test GeoLocation app on PC/Simulator?
The code works, I tested this on my computer:
private async void Button_Click(object sender, RoutedEventArgs e)
{
var locator = new Windows.Devices.Geolocation.Geolocator();
var position = await locator.GetGeopositionAsync();
}
I tested both on Windows 8 with Visual Studio 2012 as well as Windows 8.1 (Preview) and Visual Studio 2013 (preview). As long as the capabilities were set there were no problems. I did not download the sample, the code is fairly straight forward to write even for complex scenarios. Look at the sample for inspiration, but code your own. Always easier not having to debug somebody elses logic :)
Code was tested 'on pc' as well as simulator (although there shouldn't be a difference since the simulator IS your PC as it remote desktop's to your own computer)
Make sure that you set capabilities for location:
Use the location option in the simulator to set a specific address if you want:
My breakpoint
If all fails, do the usual. Uninstall the app, clean and rebuild, restart computer and Visual Studio, and check that the location capability is set by using getting the charm bar once the app is installed and running, and select permissions. It should say that it has permissions, see below:
Best of luck!
Test this code on 8.0 - work fine.
On 8.1 rtm still got class not registered exception.
I think I need to add some library, but don't know where.
UPD:
I found where is problem.
I have Pro N version of win 8.1. In Pro N this code throw exception.
On Enterprise and Pro versions all work fine.
As said "zedkommander" above, error com from "N" version of windows 8.
But he didn't give the solution, so i'm going to give it :
Microsoft employee confirmed this problem :
This behaviour is indeed specific to the ā€œNā€ editions. For geolocation to work on N-editions of Windows, the Microsoft Media Feature Pack needs to be installed.
Geolocation has a dependency on WPD (Windows Portable Devices) infrastructure which is not present in N editions until the feature pack is installed.
If you want to fix it, you need to install "Microsoft Media Feature Pack" by clicking here : https://www.microsoft.com/fr-fr/download/details.aspx?id=30685

Windows Phone 8 Server Connection

I am want to make a 'hello world' application whereby I can send some data/make a request to a server or a WCF service. A simple query, save, delete etc application. I am targeting this learning app to be on the Windows Phone 8 platform.
I have done some work in WCF and RavenDB in the past but, not sure what to do in this situation.
Can someone please give me some tips/tutorials on how to achieve this please?
I used WCF to create a Service. The Service contained an Interface which were operations that were exposed and they were implemented in a different file. I then created a windows phone app and added the Service Reference by providing a URL to the service. The code to query the service was simply:
private void button1_Click(object sender, RoutedEventArgs e)
{
ServiceReference1.Service1Client myClient = new Service1Client();
myClient.AddNumbersCompleted += new EventHandler<AddNumbersCompletedEventArgs>(myClient_AddNumbersCompleted);
myClient.AddNumbersAsync(textBox1.Text, textBox2.Text);
}
void myClient_AddNumbersCompleted(object sender, AddNumbersCompletedEventArgs e)
{
textBlock1.Text = "Answer:" + e.Result.ToString();
}