ios SSL_ERROR_SSL(1):库内操作失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51912404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:46:30  来源:igfitidea点击:

SSL_ERROR_SSL(1): operation failed within the library

iosswiftalamofirespotifyboringssl

提问by George_E

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

我得到了一些SSL Errors(这导致我的项目停止/挂起而没有崩溃,因为我在DispatchGroup等待请求),我不知道它们是如何引起的,它们是什么,或者如何处理它。

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

我已经粗略地阅读了很多关于这个问题的页面,但没有太多文档或有同样问题的人。我曾尝试更改 info.plist但这似乎没有帮助。两者都plist如下所示:(accounts.spotify.com是访问令牌请求的 URL 的域)

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 DispatchGroupwaiting for this request but the code stops.

当我向服务器发出请求时,我可以看到我的代码失败了。(这是在我的框架中)。如前所述,我正在DispatchGroup等待这个请求,但代码停止了。

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

2018-08-18 21:36:45.747984+0100 Songvote[4854:1517160] [BoringSSL]boringssl_session_errorlog(224) [C2.1:2][0x107d7c600] [boringssl_SSL_session 操作失败]

2018-08-18 21:36:45.748123+0100 Songvote[4854:1517160] [BoringSSL]boringssl_session_handshake_error_print(205) [C2.1:2][0x107d7c600:28104SSL_ROUTLES_004SSL_0400000:4854:1517160SSL:4854:1517160SSL /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_SSL_session 操作失败]

2018-08-18 21:36:45.748432+0100 Songvote[4854:1517160] [BoringSSL]boringssl_session_handshake_error_print(205) [C2.1:2][0x107d7c600:28104300:2800000000000000004SSL_0481004SSL_0x107d7c600:281004SSL_4854:1517160SSL:4854:1517160]SSL /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_SSL_session 操作失败]

2018-08-18 21:36:45.754640+0100 Songvote[4854:1517160] [BoringSSL]boringssl_session_handshake_error_print(205) [C2.1:2][0x107d7c600:28104SSL_3600:4854:1517160]SSL 例程:281004SSL_04004SSL_040004SSL_040004SSL_04004SSL /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_SSL_session 操作失败]

2018-08-18 21:36:45.754796+0100 Songvote[4854:1517160] [BoringSSL]boringssl_session_handshake_error_print(205) [C2.1:2][0x107d7c600:2810479600:285479600:2810004SSL_0407d7c600:281004ssl_0x107d7c600:281004ssl0:4854:1517160SSL /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][0x107e1b4c6c] 状态获取输出帧失败

2018-08-18 21:38:43.427656+0100 Songvote[4854:1517503] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C1.1:2][0x107e1b4c6c] 状态获取输出帧失败

2018-08-18 21:38:43.429723+0100 Songvote[4854:1517503] TIC 读取状态 [1:0x0]: 1:57

2018-08-18 21:38:43.429976+0100 Songvote[4854:1517503] TIC 读取状态 [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][0x107d7c606] 状态输出失败

2018-08-18 21:38:46.008664+0100 Songvote[4854:1517503] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C2.1:2][0x107d7c606] 状态输出失败

2018-08-18 21:38:46.010037+0100 Songvote[4854:1517503] TIC 读取状态 [2:0x0]: 1:57

2018-08-18 21:38:46.010215+0100 Songvote[4854:1517503] TIC 读取状态 [2:0x0]: 1:57

enter image description here

在此处输入图片说明

This is all for a Spotifyrequest through Alamofirewhich previously worked and now mysteriously doesn't. It does not work on my device ORthe simulator.

这完全是针对以前有效但现在神秘无效的Spotify请求Alamofire。它不适用于我的设备模拟器。

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 .swiftfiles to my project, and still get the logs.

这是 Spotify 服务器上的问题吗?还是 Xcode 10 中的错误?我将框架.swift文件移到了我的项目中,但仍然可以获取日志。

I also get these errors before my request, strange .

在我提出要求之前,我也收到了这些错误,很奇怪。

This is what a handshake error is, but I don't do any configuring of this:

这就是握手错误,但我没有对此进行任何配置:

The SSL handshake is initiated when your browser issues a secure connection request to a Web server. The server sends a public key to your computer, and your computer checks the certificate against a known list of certificate authorities. ... Test your SSL functionality by intentionally causing the handshake to fail.

当您的浏览器向 Web 服务器发出安全连接请求时,将启动 SSL 握手。服务器将公钥发送到您的计算机,您的计算机会根据已知的证书颁发机构列表检查证书。... 通过故意导致握手失败来测试您的 SSL 功能。

I even tried checkout on an earlier version to reverse all changes (which definitely worked completely fine in earlier versions) using git, which had no affect on this.

我什至尝试使用 对早期版本进行 checkout 以反转所有更改(在早期版本中肯定可以正常工作)git,这对此没有影响。



Edit: The temporary solution:

编辑:临时解决方案:

It appears as though iOS 12 no longer works with these network requests. I sent a bug report to Apple 2 days ago, so hopefully they will fix this soon. So what did I do?

似乎 iOS 12 不再适用于这些网络请求。我 2 天前向 Apple 发送了一个错误报告,所以希望他们能尽快解决这个问题。那我做了什么?

Well, for now, my iPhone 7 is useless as I am on iOS 12 beta. So the only option for now is to run my project on the simulator. To do this (as if you are in Xcode 10 beta because the simulators are iOS 12), go to Xcode -> Preferences -> Components -> iOS 11.4 Simulatorand then download it. Now, when you select a simulator, select the ones that say iOS 11.4.

好吧,就目前而言,我的 iPhone 7 没用,因为我在使用 iOS 12 测试版。所以现在唯一的选择是在模拟器上运行我的项目。为此(就像您在 Xcode 10 beta 中一样,因为模拟器是 iOS 12),请转到Xcode -> Preferences -> Components -> iOS 11.4 Simulator然后下载它。现在,当您选择模拟器时,请选择显示iOS 11.4.

  • This part is no longer true.
  • 这部分不再正确。


What causes this?

这是什么原因造成的?

Although this error should not effect anything, it is caused when you run your project in iOS 12. As far as I know, this is NOT a security issue. However, my problem of my code not running was caused by a deadlock instead of what I thought to be was because of this error.

尽管此错误不会产生任何影响,但它是在您在 iOS 12 中运行项目时引起的。据我所知,这不是安全问题。但是,我的代码没有运行的问题是由死锁引起的,而不是我认为是因为这个错误。

Update: What Apple has done about my bug report

更新:Apple 对我的错误报告做了什么

Well, although I didn't receive a message or anything from Apple, the report is marked as a 'duplicate' as someone else had reported this before me. If I get any information about when it will be fixed, I will update it here.

好吧,虽然我没有收到来自 Apple 的消息或任何消息,但该报告被标记为“重复”,因为其他人在我之前已经报告过。如果我得到有关何时修复的任何信息,我会在此处更新。



If you have any questions, tips or pointers, please let me know! Thanks in advance!

如果您有任何问题、提示或指示,请告诉我!提前致谢!

采纳答案by Stephan Schlecht

Deadlock

僵局

I assume spotifyRequest will be called on the main thread.

我假设将在主线程上调用 spotifyRequest。

So if the main thread reaches the line

所以如果主线程到达该行

group.wait()

and this line of responseJSON completionHandler was not called yet:

而这行 responseJSON completionHandler 还没有被调用:

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.

然后主线程由于上面的 group.wait() 的调用而被阻塞。由于阻塞的主线程 group.leave() 不能被调用。经典僵局。

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: 
result: Optional(["access_token": XXX, "scope": user-read-email user-read-private, "token_type": Bearer, "expires_in": 3600]) error: nil
)) error: \(String(describing: ))") } } 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:

这在控制台中作为输出提供:

##代码##

see Screenshot: console output

见截图: 控制台输出

ATS Settings in info.plist

info.plist 中的 ATS 设置

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

Spotify 在其服务器上提供了有效的 TLS 证书链。因此不需要在 info.plist 中进行 ATS 设置。

SSL Warnings in Console

控制台中的 SSL 警告

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.

当我在像您一样的 iOS 12 模拟器上运行应用程序时,我在控制台中收到相同的 SSL 警告。尽管如此,连接已建立并且请求会传送数据。也许这在下一个测试版之一中消失了。

回答by Zhebzhik Babich

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

在任何响应调用中,我在模拟器中使用 codegen Swagger 都收到了相同的警告。但一切都奏效了。只有当我添加环境变量隐藏奇怪的不需要的 Xcode 日志时,此警告才消失