In an attempt to bypass Box file/folder IDs and supporting a number of other services as well I decided to implement with WebDAV since I'm somewhat familiar with it on my linux box. I chose a library based on JackRabbit modified to work on Android which seemed to suit my needs. However, it wasn't long until I ran into a problem.
When attempting to list Box's root entries, multiStatus.getResponses() returns an empty array. When accessing another webdav server I get the responses as expected. Both servers return status code 207, as expected.
My code is below, any thoughts?
EDIT: I can move a file, though listing a directory's entries won't work :/
String host = "https://www.box.com/dav/";
//String host = "http://demo.sabredav.org/";
hostConfig = new HostConfiguration();
hostConfig.setHost(host);
HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
int maxHostConnections = 20;
params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
connectionManager.setParams(params);
client = new HttpClient(connectionManager);
Credentials creds = new UsernamePasswordCredentials("BOXEMAILADDRESS", "MYBOXPASSWORD");
//Credentials creds = new UsernamePasswordCredentials("testuser", "test");
client.getState().setCredentials(AuthScope.ANY, creds);
client.setHostConfiguration(hostConfig);
try
{
String propfindUri = host;
DavMethod method = new PropFindMethod(propfindUri, DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_1);
client.executeMethod(method);
Log.i("Status: " + method.getStatusCode());
MultiStatus multiStatus = method.getResponseBodyAsMultiStatus();
MultiStatusResponse[] responses = multiStatus.getResponses();
Log.i("Length: " + responses.length);
for(MultiStatusResponse response : responses)
{
Log.i("File: " + response.getHref());
}
}
catch (Exception e)
{
Log.printStackTrace(e);
}
While Box has some support for WebDAV, we only officially support it for iOS at the moment. Our testing has shown that our implementation of DAV works pretty well with the Windows native DAV client, as well as the Panic-Transmit Mac-specific client. Though the interactions there are not completely perfect.
Box WebDAV does not work well with the native osX (Mac) webDAV client. Expect huge delays as it looks like that client tries to load the whole tree before it displays anything.
Linux users may be able to tell you here on StackTrace which of the various OS webDAV clients/libs they've tried and which ones have worked better than others.
We do have plans to turn the crank and 10x improve our webDAV support sometime later this year, but we do not have a specific date, and just the nature of webDAV clients is such that even when we fix many of the issues with it, some client experiences on webDAV may still suck. For that reason we may only officially endorse a couple webDAV clients/libs per platform.
Hope that helps.
Related
I am downloading Assetbundles using the UnitywebRequest method from HTTPS, however the UnityWebRequest.SendWebRequest seems to take its sweet time to actually start receiving any data.
public static IEnumerator DownloadMenuAssetBundle(string fileName)
{
string path = Path.Combine(Globals.Platform, fileName);
UnityWebRequest www = new UnityWebRequest(FileManager.RequestFile(path));//this returns the complete url to the bundle e.g https://mywebsite.com/unity/myBundle
www.downloadHandler = new DownloadHandlerBuffer();
www.SendWebRequest();
while (!www.isDone)
{
Debug.Log("response: " + www.responseCode);
if (www.isNetworkError)
{
Debug.Log(www.error);
}
Debug.Log("downloaded:" + www.downloadedBytes);
yield return null;
}
Debug.Log("downloaded bytes: " + www.downloadedBytes);
Debug.Log("final response:" + www.responseCode);
if (www.error != null)
{
Debug.LogError("Encountered error while downloading: <color=blue>" + fileName + "</color>: " + www.error);
}
else
{
//rest of the logic, this works
}
Debug.Log("response: " + www.downloadedBytes); will return 0 for a random amount of time (ranging from a few to up to a couple minutes at times). But www. isNetworkError is never hit, and once bytes do start to be received it'll download the entire thing in a couple of miliseconds.
Previously i was using the exact same script on a http server and it worked flawlessly without any delays, but once i switched over to https it started taking a while. The delay also does not happen in the editor (Unity version 2017.2.1f1 runtime version .net 3.5 with 2.0 subset api compability) but happens on all my mobile devices (Oneplus 3, samsung galaxy s8, samsung galaxy s6).
At first www.responseCode returned a 301 Moved Permanently, i resolved this by using the new https url instead of the http url hoping this would fix it. However it didn't and now i only get 200 OK.
It is also an inconsistent issue because the timing it takes isn't ever the same, neither does it even happen all the time (but does most of the time)
Can this be an issue by the security layer taking additional time or the server taking its time to respond? if this is the issue how would i be able to track this down (though i doubt this as it works well in the editor)?
EDIT: workaround
I got around the issue by using a WWW class instead of UnityWebRequest. the delay is completely gone now but no SSL certificate validation is being done as Unity seems to deny them by default. I wouldn't really call it a fix but works for now.
Always trouble with UnityWebRequest - sometimes nothing makes sense with UnityWebRequests...
You can try to replace
UnityWebRequest www = new UnityWebRequest(FileManager.RequestFile(path));
with
UnityWebRequest www = new UnityWebRequestAssetBundle(FileManager.RequestFile(path), 0);
Optional for testing:
Also I think your while loop is not "save" to catch the network error.
I would prefer the following like mentioned in the documentation
UnityWebRequest www = new UnityWebRequestAssetBundle(FileManager.RequestFile(path);
yield return www.SendWebRequest();
if (request.isNetworkError || request.isHttpError)
{
Debug.Log(www.error.ToString());
}
else
{
// for testing only // if yield return www.SendWebRequest(); is working as expected www.isDone = true here!
while (!www.isDone)
{
Debug.Log("Something is wrong! " + www.responseCode);
yield return new WaitForSeconds(0.1f);
}
// do whatever you want
}
Hope this helps.
I'm building an app with the Entity Framework on Xamarin that lets me compare some data. But when I start my "fetchdata" function, I receive the Error:
System.Data.SqlClient.SqlException (0x80131904): Snix_Connect (provider: SNI_PN7, error: 35 - SNI_ERROR_35)Snix_Connect (provider: SNI_PN7, error: 35 - SNI_ERROR_35)
I see many posts about Xamarin / Android & that it is not possible to get a connection to a SQL Server. Is there any way to fetch data from a SQL Server with .NET Core on Xamarin?
This is the string I put into SQL_Class folder with Sql_Common.cs
Fill up the brace brackets with actual parameters (removing the brace brakets too).
public static string SQL_connection_string = #"data source={server_address};initial catalog={database_name};user id={user_id};password={password};Connect Timeout={seconds}";
Then I access whenever I need it from any xamarin code just like we use in our asp.net c#
This works for me on my app without any issues.
using (SqlConnection Sql_Connection = new SqlConnection(Sql_Common.saralEHR_connection_string))
But as #Jason mentioned in his first reply, I too would get once again check the security part. I fexperienced before publishing Package to Google Play, they encrypt the App files with Hash Key Code and then only it gets upload to server
Yes it is possible (HuurrAYY!):
Im new in .net core, c# and so on and for me it was a hell of a work to get it working..
So here for the other noobs who are seeking for Help:
GuideĀ“s i used:
Building Android Apps with Entity Framework
https://medium.com/#yostane/data-persistence-in-xamarin-using-entity-framework-core-e3a58bdee9d1
https://blog.xamarin.com/building-android-apps-entity-framework/
Scaffolding
https://cmatskas.com/scaffolding-dbcontext-and-models-with-entityframework-core-2-0-and-the-cli/
How i did it:
Build your normal Xamarin app.
create new .net solution like in the tutorials (DONT WRITE YOUR Entity Framework CLASSES)
create a third solution what has to be a .net core console application
Scaffold your DB in your CONSOLE application move all created classes & folders in your "xamarin .net" solution & change the namespaces
Ready to Go!
Side Node: NuGets you need in every solution:
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.SqlServer
[EDIT: NuGets you need in every solution]
I am doing this way (working snippet):
string connectionString = #"data source={server};initial catalog={database};user id={user};password={password};Connect Timeout=10";
string databaseTable = "{table name}";
string selectQuery = String.Format("SELECT count(*) as Orders FROM {0}", databaseTable);
try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
//open connection
connection.Open();
SqlCommand command = new SqlCommand(selectQuery, connection);
command.Connection = connection;
command.CommandText = selectQuery;
var result = command.ExecuteScalar().ToString();
//check if there is result
if(result != null)
{
OrdersLabel.Text = result;
}
}
}
catch (Exception ex)
{
OrdersLabel.Text = ex.Message;
}
It is working fine, but API call more elegant.
I hope it helps.
My code used to work, it does not work anymore, I tried troubleshooting and can't figure out why.
I have this piece of code in my PHP:
$android_id_01 = $_GET['pmysql_room_id'];
$android_id_02 = "";
$f = fopen("00_android_id_01.txt", "w");
fwrite($f, print_r($android_id_01, true));
fclose($f);
$f = fopen("00_android_id_02.txt", "w");
fwrite($f, print_r($android_id_02, true));
fclose($f);
For troubleshooting I created two android IDs ($android_id_01 and $android_id_02) which are both empty (The first one is From Android and the second one I created directly from PHP).
Now when I launch my Android device, the PHP file is executed from server side and both the text files are created empty and identical. Now my code only works when I use $android_id_02 and not $android_id_01 from the code below:
if ($android_id == '')
{
//my code
}
(Yes when I use either one of the $android_id_01 OR $android_id_02 I rename it to $android_id and comment out the other one)
My question is, although this was working yesterday, why does it work with $android_id_02 = ""; and not $android_id_01 = $_GET['pmysql_room_id']; even though they are both empty????
I don't know what changed from yesterday to today.
Ok after a bit of troubleshooting I found a solution, strange though.
On the server side "display_errors" under PHP settings must be turned off. Somehow having this on interferes with the json_encode sent back to android client. (even though my code is not generating any errors)
I got a task at my job to reverse engineer an application.
I've been using Charles Proxy several times with other applications without any problems and have also tried Fiddler. I've always been able to monitor the request/responses made.
But the application that I'm trying now does now show any activity in either Charles or Fiddler. First I thought that they check the certificate and kill the connection but the application works as normal without any hiccups.
Is there any way for an application to be able to avoid the proxy settings or what am I missing?
I've been using apktool as well as dex2jar and found this peace of code. Probably not 100% correct but it can give you some clues of what happening.
public final void a(int paramInt1, int paramInt2)
{
this.b = paramInt2;
InetSocketAddress localInetSocketAddress = new InetSocketAddress(InetAddress.getByName(this.a), this.b);
while (true)
{
try
{
SSLContext localSSLContext = SSLContext.getInstance("TLS");
X509TrustManager[] arrayOfX509TrustManager = new X509TrustManager[1];
arrayOfX509TrustManager[0] = new c(this);
localSSLContext.init(null, arrayOfX509TrustManager, new SecureRandom());
this.e = ((SSLSocket)localSSLContext.getSocketFactory().createSocket());
this.e.connect(localInetSocketAddress, paramInt1);
this.d.clear();
if (Arrays.asList(this.e.getSupportedProtocols()).contains("TLSv1.2"))
{
this.d.add("TLSv1.2");
String[] arrayOfString1 = (String[])this.d.toArray(new String[this.d.size()]);
SSLSocket localSSLSocket1 = this.e;
if (arrayOfString1.length > 0)
localSSLSocket1.setEnabledProtocols(arrayOfString1);
this.c.clear();
if (!Arrays.asList(this.e.getSupportedCipherSuites()).contains("TLS_RSA_WITH_AES_256_CBC_SHA"))
break label374;
this.c.add("TLS_RSA_WITH_AES_256_CBC_SHA");
String[] arrayOfString2 = (String[])this.c.toArray(new String[this.c.size()]);
SSLSocket localSSLSocket2 = this.e;
if (arrayOfString2.length > 0)
localSSLSocket2.setEnabledCipherSuites(arrayOfString2);
e.a().a(this.e.getLocalAddress().getAddress());
e.a().a(this.e.getLocalPort());
a(5000);
this.e.startHandshake();
a(0);
return;
}
}
catch (Exception localException)
{
throw new IOException(localException.toString());
}
if (Arrays.asList(this.e.getSupportedProtocols()).contains("TLSv1.1"))
{
this.d.add("TLSv1.1");
}
else if (Arrays.asList(this.e.getSupportedProtocols()).contains("TLSv1"))
{
this.d.add("TLSv1");
continue;
label374: if (Arrays.asList(this.e.getSupportedCipherSuites()).contains("TLS_RSA_WITH_AES_128_CBC_SHA"))
this.c.add("TLS_RSA_WITH_AES_128_CBC_SHA");
else if (Arrays.asList(this.e.getSupportedCipherSuites()).contains("SSL_RSA_WITH_3DES_EDE_CBC_SHA"))
this.c.add("SSL_RSA_WITH_3DES_EDE_CBC_SHA");
else if (Arrays.asList(this.e.getSupportedCipherSuites()).contains("DES-CBC3-SHA"))
this.c.add("DES-CBC3-SHA");
}
}
}
Don't know that much about TLS 1.2 but I know its suppose to be more robust? But can it avoid the proxy?
I've also dumped the traffic using Wireshark, that worked but the information is encrypted, as expected, so its not much of use.
Any help would be appreciated.
This code will probably avoid proxy because is making direct socket. If you are using some higher level api, like HttpURLConnection, it respect proxy settings.
http://developer.android.com/reference/java/net/HttpURLConnection.html
You can try using SandroProxy to find out on which port communication is made.
http://code.google.com/p/sandrop/issues/detail?id=76
Go to HTTP tab and pres play button on acction bar
SandroProxy will listen on two new ports 8020 -> web , 8021 -> websockets for chrome devtools
start chrome from PC with url http your_device_ip:8020
Check Connection tab, last two columns are process uid and names(can be more than one)
To capture data you can also use SandroProxy and force iptable redirects. You will need rooted phone.
btw: send by sandroproxy support :)
You could try using something like adb forward 80 3456 against the device or emulator to have all port 80 traffic redirected to 3456 on your workstation. Then have your proxy listen on that port.
I am programming an authentication service in Android and this one includes a server part written in java.
I do the same operations in both parts executing these two pieces of codes in Android and Server:
ANDROID:
String genChallengeResponse(String challenge, String message) {
String Hmac_ALG = "HmacSHA256";
SecretKey key = new SecretKeySpec(challenge.getBytes(), Hmac_ALG);
Mac m = Mac.getInstance(Hmac_ALG);
m.init(key);
m.update(password.getBytes());
byte[] mac = m.doFinal();
return new String(Base64.encode(mac, Base64.DEFAULT));
}
SERVER:
String genChallengeResponse(String challenge, String message) {
String Hmac_ALG = "HmacSHA256";
SecretKey key = new SecretKeySpec(challenge.getBytes(), Hmac_ALG);
Mac m = Mac.getInstance(Hmac_ALG);
m.init(key);
m.update(password.getBytes());
byte[] mac = m.doFinal();
return new String(Base64.encodeBase64(mac));
}
Starting from the same challenge and message these are the results:
Android: n2EaLpQr0uKgkZKhCQzwuIFeeLjzZKerZcETVNcfla4=
Server: n2EaLpQr0uKgkZKhCQzwuD9eeLjzZKerZcETVNcfla4=
^^
These are different just for TWO CHARACTERS.
The problem is that this strange behaviour does not appear in every pair of String passed to the functions...
I tried to use the UTF-8 in each system, but nothing changes...
Do someone knows what is the problem? If this is a known problem...
(is important to say that the problem is the same using Android 2.2 or also 4.0, then the problem is not the operating system, I think).
Can't comment yet therefore as answer:
I found out a few weeks ago that Android's Base64 uses different settings for the Linefeeds (check here: http://developer.android.com/reference/android/util/Base64.html )
I think in my case it was NO_WRAP missing.Perhaps one of the other options (NO_PADDING or URL-Safe, does the tested password contain + or - ?) could change your results...