SSL_ERROR_SSL(1): operation failed within the libr

2020-05-14 02:35发布

I am getting some SSL Errors (which are causing my project to stop/hang with no crash as I have a DispatchGroup waiting for the request), which I don't know how they are caused, what they are, or what to do about it.

I have read numerous pages roughly about this problem, but there are not much documentation or people having the same problem. I have tried changing the info.plist but that doesn't seem to have helped. Both plist's look like this: (accounts.spotify.com is the domain for the URL of the access token request)

enter image description here

I can see that my code is failing when I make a request to the server. (This is in my framework). As mentioned earlier, I have a DispatchGroup waiting for this request but the code stops.

self.currentToken = try self.spotifyRequest("https://accounts.spotify.com/api/token", method: .post, parameters: parameters)

My request method:

private func spotifyRequest(_ url: URLConvertible, method: HTTPMethod, parameters: Parameters? = nil, headers: HTTPHeaders? = nil) throws -> JSONStandard {
    // Create a dispatch group to handle threads
    let group = DispatchGroup()
    group.enter()

    // Status of the request (starts as nil)
    var status: JSONStandard?


    DispatchQueue.global(qos: .userInitiated).async {
        Alamofire.request(url, method: method, parameters: parameters, headers: headers).responseJSON(completionHandler: { response in
            // Check if response is valid
            if let requestResponse = response.result.value as? JSONStandard {
                status = requestResponse
            } else {
                status = nil
            }

            // Let the next tasks be completed, it has finished waiting for the request
            group.leave()
        })
    }


    // Wait for a result
    group.wait()

    // Return value or throw an error
    if let safeStatus = status {
        return safeStatus
    } else {
        getAccessToken()
        throw SpotifyError.failedToCompleteRequest
    }
}

I'm not exactly sure what caused the problem, because all I did was slightly edit and archive the framework again.

However, earlier it worked on both (as I am using this universal framework script)

Here is my crash log (which I can't understand any of!):

2018-08-18 21:36:45.747984+0100 Songvote[4854:1517160] [BoringSSL] boringssl_session_errorlog(224) [C2.1:2][0x107d7c600] [boringssl_session_read] SSL_ERROR_SSL(1): operation failed within the library

2018-08-18 21:36:45.748123+0100 Songvote[4854:1517160] [BoringSSL] boringssl_session_handshake_error_print(205) [C2.1:2][0x107d7c600] 4427428040:error:100000d7:SSL routines:OPENSSL_internal:SSL_HANDSHAKE_FAILURE:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-109.200.32/ssl/ssl_lib.cc:1081:

2018-08-18 21:36:45.748238+0100 Songvote[4854:1517160] [BoringSSL] boringssl_session_errorlog(224) [C2.1:2][0x107d7c600] [boringssl_session_read] SSL_ERROR_SSL(1): operation failed within the library

2018-08-18 21:36:45.748432+0100 Songvote[4854:1517160] [BoringSSL] boringssl_session_handshake_error_print(205) [C2.1:2][0x107d7c600] 4427428040:error:100000d7:SSL routines:OPENSSL_internal:SSL_HANDSHAKE_FAILURE:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-109.200.32/ssl/ssl_lib.cc:1081:

2018-08-18 21:36:45.754554+0100 Songvote[4854:1517160] [BoringSSL] boringssl_session_errorlog(224) [C2.1:2][0x107d7c600] [boringssl_session_read] SSL_ERROR_SSL(1): operation failed within the library

2018-08-18 21:36:45.754640+0100 Songvote[4854:1517160] [BoringSSL] boringssl_session_handshake_error_print(205) [C2.1:2][0x107d7c600] 4427428040:error:100000d7:SSL routines:OPENSSL_internal:SSL_HANDSHAKE_FAILURE:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-109.200.32/ssl/ssl_lib.cc:1081:

2018-08-18 21:36:45.754717+0100 Songvote[4854:1517160] [BoringSSL] boringssl_session_errorlog(224) [C2.1:2][0x107d7c600] [boringssl_session_read] SSL_ERROR_SSL(1): operation failed within the library

2018-08-18 21:36:45.754796+0100 Songvote[4854:1517160] [BoringSSL] boringssl_session_handshake_error_print(205) [C2.1:2][0x107d7c600] 4427428040:error:100000d7:SSL routines:OPENSSL_internal:SSL_HANDSHAKE_FAILURE:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-109.200.32/ssl/ssl_lib.cc:1081:

2018-08-18 21:38:43.427156+0100 Songvote[4854:1517503] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C1.1:2][0x107e1b4c0] get output frames failed, state 8196

2018-08-18 21:38:43.427656+0100 Songvote[4854:1517503] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C1.1:2][0x107e1b4c0] get output frames failed, state 8196

2018-08-18 21:38:43.429723+0100 Songvote[4854:1517503] TIC Read Status [1:0x0]: 1:57

2018-08-18 21:38:43.429976+0100 Songvote[4854:1517503] TIC Read Status [1:0x0]: 1:57

2018-08-18 21:38:46.008365+0100 Songvote[4854:1517503] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C2.1:2][0x107d7c600] get output frames failed, state 8196

2018-08-18 21:38:46.008664+0100 Songvote[4854:1517503] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C2.1:2][0x107d7c600] get output frames failed, state 8196

2018-08-18 21:38:46.010037+0100 Songvote[4854:1517503] TIC Read Status [2:0x0]: 1:57

2018-08-18 21:38:46.010215+0100 Songvote[4854:1517503] TIC Read Status [2:0x0]: 1:57

enter image description here

This is all for a Spotify request through Alamofire which previously worked and now mysteriously doesn't. It does not work on my device OR the simulator.

Is this a problem relating to secure internet connections? Or is this another problem?

Some links to what I have looked at:

Edits:

Is this a problem on Spotify's servers? Or a bug in Xcode 10? I moved my framework .swift files to my project, and still get the logs.

I also get these errors before my request, strange

2条回答
干净又极端
2楼-- · 2020-05-14 03:03

I had the same warning with codegen Swagger in emulator on any response call. But all worked. This warning disappeared only when I added environment variable Hide strange unwanted Xcode logs

查看更多
再贱就再见
3楼-- · 2020-05-14 03:05

Deadlock

I assume spotifyRequest will be called on the main thread.

So if the main thread reaches the line

group.wait()

and this line of responseJSON completionHandler was not called yet:

group.leave()

then the main thread is blocked due to the call of group.wait() above. Due to the blocked main thread group.leave() can't be called. Classical deadlock.

Verfication

Setting a breakpoint to the line

if let safeStatus = status {

shows that this line is never called.

Minimal Example that is running

As a starting point here the code for a minimal example that delivers a result.

import UIKit
import Alamofire

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.contactSpotify {
            print ("result: \(String(describing: $0)) error: \(String(describing: $1))")
        }
    }

    func contactSpotify(completion: @escaping ([String: Any]?, Error?) -> Void) {
        let url = URL(string: "https://accounts.spotify.com/api/token")!
        Alamofire.request(url,
                          method: .post,
                          parameters: ["grant_type": "refresh_token",
                                       "client_id": "<someClientId>",
                                       "refresh_token": "<someRefreshToken>",
                                       "client_secret": "<someClientSecret>"])
            .validate()
            .responseJSON { response in
                guard response.result.isSuccess else {
                    completion(nil, response.result.error)
                    return
                }

                completion(response.result.value as? [String: Any], nil)
        }
    }

}

This gives as output in the console:

result: Optional(["access_token": XXX, "scope": user-read-email user-read-private, "token_type": Bearer, "expires_in": 3600]) error: nil

see Screenshot: console output

ATS Settings in info.plist

Spotify offers a valid TLS certificate chain on their server. So there is no need for ATS settings in info.plist.

SSL Warnings in Console

I get the same SSL warnings in the console when I run the application on an iOS 12 simulator like you. Nonetheless the connection is established and the request delivers data. Perhaps this is gone in one of the next betas.

查看更多
登录 后发表回答