acra icon indicating copy to clipboard operation
acra copied to clipboard

4.7.0-RC.1 causes 401 response in acralyzer

Open Necrontyrr opened this issue 11 years ago • 8 comments

Sending request to http://my.server.net:5984/acra-wayaway/_design/acra-storage/_update/report/2e797c09-69cf-4675-b278-7918539827ad Request response : 401 : Unauthorized Failed to send crash report for 1443825776737-approved.stacktrace org.acra.sender.ReportSenderException: Error while sending JSON report via Http PUT at org.acra.sender.HttpSender.send(HttpSender.java:248) at org.acra.SendWorker.sendCrashReport(SendWorker.java:181) at org.acra.SendWorker.checkAndSendReports(SendWorker.java:140) at org.acra.SendWorker.run(SendWorker.java:76) Caused by: java.io.IOException: Host returned error code 401 at org.acra.util.HttpRequest.send(HttpRequest.java:148) at org.acra.sender.HttpSender.send(HttpSender.java:245) at org.acra.SendWorker.sendCrashReport(SendWorker.java:181)  at org.acra.SendWorker.checkAndSendReports(SendWorker.java:140)  at org.acra.SendWorker.run(SendWorker.java:76) 

The CouchDB log: [Fri, 02 Oct 2015 22:45:43 GMT] [info] [<0.9988.0>] - - PUT /acra-wayaway/_design/acra-storage/_update/report/2e797c09-69cf-4675-b278-7918539827ad 401

But if I roll back to version 4.6.2, all works fine (200 etc).

I'm guessing the credentials aren't sent correctly.

Necrontyrr avatar Oct 02 '15 22:10 Necrontyrr

I have same error with 4.7.0-RC.1

mdenissov avatar Oct 13 '15 08:10 mdenissov

I saw raw http request 4.6.2 send auth header Authorization : Basic...... 4.7.0-RC.1 doesn't send auth header

mdenissov avatar Oct 13 '15 10:10 mdenissov

Hi. yes I'm getting this error too! 401, {"error":"unauthorized","reason":"You are not authorized to access this db."} *username or password has not been changed and version 4.6.2 works normally. please fix it

sadeghshahroodi avatar Oct 13 '15 10:10 sadeghshahroodi

Thanks for the feedback guys, but I'm snowed under and am not going to get to this in the next week or two. Anyone else want to jump in?

william-ferguson-au avatar Oct 13 '15 10:10 william-ferguson-au

I think problem is in:

"I'm using URLConnection to connect to the main server. The server implements digest authentication. If I connect to the server with java library, the connection is successful. But if I use the same code for android, the connection is rejected for the reason - username and password do not match."

https://code.google.com/p/android/issues/detail?id=9579 http://stackoverflow.com/questions/3197814/urlconnection-working-with-java-code-but-not-for-android-use-in-digest-authent

mdenissov avatar Oct 13 '15 10:10 mdenissov

HttpRequest -> send ->

As a temporary solution i changed code:

    if ((login != null) && (password != null)) {
        Authenticator.setDefault(new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(login, password.toCharArray());
            }
        });
    }

to code:

    if ((login != null) && (password != null)) {
        String encoded = Base64.encodeToString((login + ":" + password).getBytes("UTF-8"), Base64.NO_WRAP);
        urlConnection.setRequestProperty("Authorization", "Basic " + encoded);
    }

But be careful, Base64.encodeToString work only from Android API 8.

mdenissov avatar Oct 13 '15 11:10 mdenissov

Use a home-grown implementation instead: http://androidcodemonkey.blogspot.com/2010/03/how-to-base64-encode-decode-android.html if need Base64 in android below API 8.

mdenissov avatar Oct 13 '15 12:10 mdenissov

Thanks @mdenissov

william-ferguson-au avatar Oct 28 '15 11:10 william-ferguson-au