owncloud / ios-library

MIT License
77 stars 90 forks source link

Cannot upload file using SSL even though I even accept invalid SSL certificates #130

Open slashburn opened 8 years ago

slashburn commented 8 years ago

Hi there,

I would like to add SSL support for my app. For testing purposes, I use an self generated Let's encrypt SSL certificate from my web host to protect my my URL. Now I would like to upload a file using the HTTPS instead of the HTTP protocol.

As shown in the owncloud example project (AppDelegate), I configured my OCCommunication object to accept invalid SSL certificates. I also set a the "Allow Arbitrary load flag" in my own project (not the owncloud project). The configuration looks like this :

import AFNetworking

let ocCommunication = OCCommunication()
ocCommunication.setCredentialsWithUser(userName, andPassword: password)

let securityPolicy  = AFSecurityPolicy.defaultPolicy()
securityPolicy.allowInvalidCertificates = true;
ocCommunication.securityPolicy = securityPolicy

I installed the AFNetworking 2.6. version via Cocoapods to have access to the AFNetworking library The request looks like this:

var operation : NSOperation? = nil
operation = ocCommunication.uploadFile(folderURL.path, toDestiny: fileURL, onCommunication: ocCommunication,
            progressUpload: ({ (bytesWrote, totalBytesWrote, totalBytesExpectedToWrite) in
                //this method is not called
            }),
            successRequest: ({(response, redirectedServer) in
                // success case ...
            }),
            failureRequest: ({ (response, redirectedServer, error) in
                //this is where the error occurs
                print(response)
                print(error)
            }),
            failureBeforeRequest: ({ error in
               //not called
            }),
            shouldExecuteAsBackgroundTaskWithExpirationHandler: ({
                operation?.cancel()
            }))
operation?.start()

The output of the error message is:

<NSHTTPURLResponse: 0x130c44fb0> { URL: https:/[myURL.de]/remote.php/webdav/4690FDD4-D350-4513-9797-451A76FD7591.zip } { status code: 401, headers { "Accept-Language" = "de-DE;q=1, en-DE;q=0.9"; Authorization = "Basic abcdefghi"; "Content-Length" = 2680387; "User-Agent" = "MyApp/1.0 (iPhone; iOS 9.3.1; Scale/2.00)"; } } Error Domain=com.owncloud Code=401 "(null)"

My request is somehow unauthorized. If I try to upload a file using curl with HTTPS, it works perfectly fine. I also see the green HTTPS lock when I open the site in the browser window. Does anyone have an idea what I'm doing wrong?