ios,alamofire5:需要相当于curl --key foo.key --cert foo,pem --location --request GET 'https://bar.baz/foo"

2023-12-08

除了用于 pin 证书的公钥之外,我还有一个私钥。

如何向服务器进行身份验证?

$ file *
foo.der:         data
foo.private.der: data

使用 openssl 派生自

foo.key: PEM RSA private key
foo.pem: PEM certificate

我需要的是与此等效的 alamofire:

卷曲 --key foo.key --cert foo.pem --location --request GET 'https://somhostofmine/v1/welcome/'

$curl --key ./client_key.pem --cert ./client.pem --location --request GET 'https://someurl' “你好沃尔德!”

works

$curl --cert ./client.pem --location --request GET 'https://someurl/v1/welcome/' curl: (58) 无法设置私钥文件: './client.pem' 类型 PEM

does not

因此,在没有私钥的情况下使用证书本身的建议是行不通的。

我们是在这里处理证书固定还是考虑到私钥的存在,这是这里的其他内容???


您可以创建一个ServerTrustManager将每个主机名作为参数传递给您的评估器。 用于公钥固定使用PublicKeysTrustEvaluator像这样:

let evaluators: [String : ServerTrustEvaluating] = [
    "your.host.com": PublicKeysTrustEvaluator(performDefaultValidation: false, validateHost: false)
]
let serverTrustManager = ServerTrustManager(evaluators: evaluators)

用于证书固定使用PinnedCertificatesTrustEvaluator像这样:

let evaluators: [String : ServerTrustEvaluating] = [
    "your.host.com": PinnedCertificatesTrustEvaluator(
        acceptSelfSignedCertificates: true,
        performDefaultValidation: false,
        validateHost: false
    )
]
let serverTrustManager = ServerTrustManager(evaluators: evaluators)

这两种方法都需要将您的证书包含在捆绑包中,如下所示.cer or .der file.

创建您的后ServerTrustManager将它传递给Session实例并将其用于您的请求:

let session = Session(serverTrustManager: serverTrustManager)

如果您想要在如何验证服务器上有更复杂的逻辑,或者必须在域中使用通配符,则必须子类化ServerTrustManager并覆盖serverTrustEvaluator(forHost:)功能:

class MyServerTrustManager: ServerTrustManager {
    init() {
        super.init(evaluators: [:])
    }
    
    override func serverTrustEvaluator(forHost host: String) throws -> ServerTrustEvaluating? {
        guard host.hasSuffix(".host.com") else {
            return try super.serverTrustEvaluator(forHost: host)
        }
        return PublicKeysTrustEvaluator(performDefaultValidation: false, validateHost: false)
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ios,alamofire5:需要相当于curl --key foo.key --cert foo,pem --location --request GET 'https://bar.baz/foo" 的相关文章

  • 如何使用MKMapView完成加载委托,可能的“完成显示”委托?

    当用户在选择注释后点击 保存 时 我尝试保存地图视图的缩略图 当用户尚未放大该注释时会出现问题 因此尚未加载关闭缩放级别 这就是用户点击保存后我正在做的事情 将布尔值 saving 设置为 true 居中并放大注释 无动画 当调用mapVi
  • 使用 iPhone 摄像头检测心率 [重复]

    这个问题在这里已经有答案了 可能的重复 使用摄像头检测心率 https stackoverflow com questions 9274027 detecting heart rate using the camera 我正在研究 iOS
  • Swift 闭包作为 AnyObject

    我尝试使用这个方法 class addMethod 在 Obj c 中使用如下 class addMethod self class selector eventHandler imp implementationWithBlock han
  • CBPeripheral 名称有时为 null

    我正在开发一个应用程序来与蓝牙 LE 外围设备进行通信 我目前正在测试的外围设备是其中之一these http www ti com tool cc2540dk mini 有趣的是 有时当我发现它时 我会得到它的正确名称 SimpleBLE
  • 如何在 ios 7 上更改重新排序控制图像

    我正在寻找一种更改重新排序控件图像和大小的方法 我使用此代码来更改重新排序图像 void tableView UITableView tableView willDisplayCell UITableViewCell cell forRow
  • 防止UIScrollView的UIPanGestureRecognizer遮挡UIScreenEdgePanGestureRecognizer

    我有一个UIScrollView它填满了我应用程序的一页上的屏幕 但我希望允许用户从屏幕边缘平移以显示其后面的视图 问题是 UIScrollView 窃取了我的触摸UIScreenEdgePanGestureRecognizer在屏幕边缘
  • 使用 NSURLSessionDataTask 显示文件下载进度

    我想显示特定文件的文件下载进度 收到了多少字节 它与 NSURLSessionDownloadTask 配合得很好 我的问题是我想用 NSURLSessionDataTask 实现同样的效果 以下是将文件接收到 NSData 并写入文档文件
  • 如何在 Apple Watch Extension/App 和 iOS App 之间建立通信通道

    我正在探索 WatchKit SDK 当我有 WatchKit 应用程序时 是否可以在 WatchKit 应用程序上从 iPhone 应用程序设置值 例如文本 设置 我可以从 iPhone 应用程序调用 WatchKit 应用程序扩展中的函
  • Swift 3 错误:[_SwiftValue pointSize] 无法识别的选择器发送到实例

    我刚刚将我们的项目迁移到 swift 3 发现由于一个问题导致大量崩溃 由于未捕获的异常 NSInvalidArgumentException 而终止应用程序 原因 SwiftValue pointSize 发送到实例的无法识别的选择器 该
  • 自动布局、UIDynamics 和动画

    我对自动布局还很陌生 并且对如何为视图设置动画感到困惑 我读了很多 我知道你必须遵守限制 编辑它 然后包装layoutIfNeeded in an UIView动画块 但当真正要做的时候 我却有点失落 我很乐意有人能向我解释如何做这个动画
  • 暂停视频录制[关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我正在尝试创建一个应用程序 用户可以在其中从相机录制视频 该应用程序的功能之一必须是文件录制中的暂停 例如 用户通过按 开始 按钮开始
  • iOS中的performSelector有什么用

    的作用是什么执行选择器 比较 self btnClicked and self performSelector selector btnClicked void btnClicked NSLog Method Called 两者都对我来说工
  • 如何检测Retina高清显示屏?

    UIScreen有一个新的 nativeScaleiOS 8 中的属性 但文档没有提及它 property nonatomic readonly CGFloat nativeScale 还有一个scale属性 但文档说它是 2 用于视网膜显
  • 在后台任务中安排通知

    我正在为 iOS 开发一个日历 闹钟应用程序 它与网络服务器同步 当在服务器上添加活动时 会发出推送通知 以便 iOS 客户端可以获取新数据 并根据需要更新和安排下一次警报的时间 本地通知 但这仅在应用程序在客户端打开时才有效 我希望客户端
  • 线程 1:信号 SIGABRT - AppDelegate.h

    main m Journey Created by Julian Buscema on 2014 07 13 Copyright c 2014 Julian Buscema All rights reserved import
  • SpriteKitPhysicsBody非矩形碰撞

    pipeUp physicsBody SKPhysicsBody rectangleOfSize pipeUp size 在此编码中我使用了rectangleOfSize对于碰撞物理体 但如果我想按像素仅使用图像的形状 我应该使用什么而不是
  • 混合静态和动态 UITableViewController 内容会导致 NSRangeException

    我一直在寻找这个错误 并找到了一些具有类似行为的帖子 但没有解决问题的解决方案 我有一个 UITableViewController 在 SB 中声明为静态 它具有以下部分 第 0 部分 配方 是静态的 有 4 个单元格 第 1 部分 口味
  • 我可以知道 requireGestureRecognizerToFail 到底会做什么吗?

    谁能告诉我下面的代码行到底会做什么 我已经提到过Apples https developer apple com library ios documentation uikit reference UIGestureRecognizer C
  • iOS7 中“-webkit-overflow-scrolling: touch” 最初的屏幕外元素被破坏

    既然转基因种子已经发布了 我们现在可以谈谈了 看起来 iOS7 中的 webkit overflow scrolling touch 已损坏 最初不在屏幕上的元素的触摸事件不会触发 或者在某些情况下只是不可靠 这是一个例子
  • ActionScript、NetStream.Play.Failed iOS AIR 移动设备

    我正在尝试以类似于 Tiberiu Ionu Stan http stackoverflow com questions 2036107 aac mp4 not working in actionscript 3s netstream 的方

随机推荐