简体   繁体   English

将自签名证书添加到 iPhone 模拟器?

[英]Adding a self-signed certificate to iPhone Simulator?

I have a self-signed certificate at the endpoint of my API.我的 API 端点有一个自签名证书。 I'm trying to test some things using the simulator but am getting "untrusted server certificate".我正在尝试使用模拟器测试一些东西,但得到的是“不受信任的服务器证书”。

I have tried to use safari on the simulator to download the.crt file, but that doesn't seem to work.我试过在模拟器上使用safari下载.crt文件,但是好像不行。

Where does iPhone Simulator get its keychain from? iPhone 模拟器从哪里获得它的钥匙串? How can I add a trusted certificate so my application will work?如何添加受信任的证书以使我的应用程序正常运行?

I got it to work by creating a CA and then adding a CA certificate using the iPhone provisioning tool.我通过创建一个 CA 然后使用 iPhone 配置工具添加一个 CA 证书来让它工作。 Then I was able to have a certificate signed by that CA certificate on the API server and the NSConnection just worked.然后我能够在 API 服务器上获得由该 CA 证书签名的证书,并且 NSConnection 正常工作。 I was not able to get it to work using a self-signed certificate for some reason.由于某种原因,我无法使用自签名证书让它工作。 I need to re-attempt this using the provisioning software.我需要使用配置软件重新尝试此操作。

My real question is how do I get this to work on the simulator?我真正的问题是如何让它在模拟器上运行? I would think that the simulator uses the keychain of the actual computer.我认为模拟器使用实际计算机的钥匙串。

Just for Info, if someone still runs into that problem:仅供参考,如果有人仍然遇到该问题:

simply drag & drop your .cer Files into your running Simulator window.只需将您的 .cer 文件拖放到正在运行的模拟器窗口中即可。 You'll see Safari flashing and then the import dialog for your Certificate (or Certificate Authority)...您将看到 Safari 闪烁,然后是您的证书(或证书颁发机构)的导入对话框...

Working for iOS 7 Simulator (and i Think did work for iOS 6 too).适用于 iOS 7 Simulator(我认为也适用于 iOS 6)。

For those who find that the dragging and dropping of the certificate on the Simulator isn't working, there was a recent change that adds an extra step .对于那些发现在模拟器上拖放证书不起作用的人,最近有一个更改,增加了一个额外的步骤

The Simulator must be explicitly told to trust the root CA.必须明确告知模拟器信任根 CA。 Do this by going to:通过以下方式执行此操作:

General -> About -> Certificate Trust Settings -> "Enable Full Trust for Root Certificate" for your particular certificate常规 -> 关于 -> 证书信任设置 -> 为您的特定证书“启用根证书的完全信任”

See the full answer here :此处查看完整答案

I had this same issue for months and today I FINALLY solved it with:几个月来我遇到了同样的问题,今天我终于用以下方法解决了它:

ADVTrustStore ADVTrustStore

You are going to want to use a project called ADVTrustStore from github.您将要使用来自 github 的名为ADVTrustStore的项目。 It does some fancy magic but it will correctly install certificates into your root trust-store on the simulator.它有一些奇特的魔法,但它会正确地将证书安装到模拟器上的根信任库中。

Steps to install a custom cert安装自定义证书的步骤

# Clone the repo
git clone https://github.com/ADVTOOLS/ADVTrustStore.git

# Enter the repo directory
cd ADVTrustStore/

# Copy your .crt file 
cp somewhere/something.crt my.crt

# conver to a .pem file
openssl x509 -in my.crt -out my.pem -outform PEM

# Install the pem in the simulators
./iosCertTrustManager.py -a my.pem

Using this process I was able to get GoogleStreetView images to render correctly while behind a corporate firewall using SSL resigning with self-signed certificates使用此过程,我能够使用 SSL 重新签名并使用自签名证书在企业防火墙后面正确呈现 GoogleStreetView 图像

Background背景

I was using CharlesProxy and i noticed it was correctly installing certificates into the Simulator but they did not show up in the Settings - Profiles section.我正在使用 CharlesProxy,我注意到它正确地将证书安装到模拟器中,但它们没有显示在设置 - 配置文件部分。 Then after some searching I discovered this tool.然后经过一番搜索,我发现了这个工具。 There are probably a few other tools out there but in my case the drag-and-drop never worked correctly for all cases.可能还有其他一些工具,但就我而言,拖放从未在所有情况下都能正常工作。 Safari would be fine but not my applications. Safari 会很好,但不是我的应用程序。

For anyone use OS X Catalina, please check this : https://forums.developer.apple.com/thread/124056 .对于使用 OS X Catalina 的任何人,请查看: https : //forums.developer.apple.com/thread/124056

Catalina is currently blocking access to Desktop, Documents and Downloads folder. Catalina 当前阻止访问桌面、文档和下载文件夹。 I moved certificate files to Shared folder and drag and drop the files to simulator from there.我将证书文件移动到共享文件夹,然后将文件从那里拖放到模拟器中。

Take a look at the shell script Charles uses to install their self signed cert into the simulator's keychain.看看 Charles 用来将他们的自签名证书安装到模拟器钥匙串中的 shell 脚本。 http://www.charlesproxy.com/documentation/faqs/ssl-connections-from-within-iphone-applications/ http://www.charlesproxy.com/documentation/faqs/ssl-connections-from-within-iphone-applications/

See also:也可以看看:

It looks like installing your own certificate in the simulator may require installing it on a device via Safari and then copying the resulting row from the device's TrustStore.sqlite3 into the simulator's.看起来在模拟器中安装您自己的证书可能需要通过 Safari 将其安装在设备上,然后将结果行从设备的TrustStore.sqlite3到模拟器的。

Dragging and drop used to work but it didn't work on XCode 12 for me.拖放曾经可以工作,但对我来说在 XCode 12 上不起作用。 What worked for me was opening Safari browser on Simulator and then typing the file URL for the .crt certificate file.对我有用的是在模拟器上打开 Safari 浏览器,然后输入 .crt 证书文件的文件 URL。 Ex.前任。

file:///Users/[folder_path]/[certificate.crt]

After that you have to goto Simulator Settings and install the certificate by navigating into General > Profiles section.之后,您必须转到 Simulator Settings 并通过导航到 General > Profiles 部分来安装证书。

For IOS14, after the dragging, you need go to:对于IOS14,拖拽后,你需要去:

General -> Profile -> select you profile -> install

and then:进而:

General -> About -> Certificate Trust Settings -> "Enable Full Trust for Root Certificate" for your particular certificate

see also https://developer.apple.com/library/archive/qa/qa1948/_index.html另见https://developer.apple.com/library/archive/qa/qa1948/_index.html

Using iPhone Backup Extractor , I copied my iPhone's TrustStore.sqlite3 into ~/Library/Application Support/iPhone Simulator/6.0/Library/Keychains , overwriting the existing file.使用iPhone Backup Extractor ,我将 iPhone 的TrustStore.sqlite3复制到~/Library/Application Support/iPhone Simulator/6.0/Library/Keychains ,覆盖现有文件。 I tried to only insert a single row with the following sqlite, but I couldn't get it working.我试图只插入带有以下 sqlite 的一行,但我无法让它工作。

sqlite3 ~/backup/iOS\ Files/TrustStore.sqlite3
sqlite3>.mode insert
sqlite3>.output working.sql
sqlite3>select * from tsettings;
sqlite3>.quit

Now, working.sql has the entire contents of the tsettings table (in my case, 1 row).现在, working.sql拥有 tsettings 表的全部内容(在我的例子中,是 1 行)。

sqlite3 ~/Library/Application\ Support/iPhone\ Simulator/6.0/Library/Keychains/TrustStore.sqlite3
sqlite3>INSERT INTO tsettings VALUES(X'...
sqlite3>.quit

Again, the above sqlite commands didn't work for me, but might be a good starting point for someone else.同样,上面的 sqlite 命令对我不起作用,但对其他人来说可能是一个很好的起点。 Copying the entire TrustStore.sqlite3 from the backup into the simulator worked just fine.将整个TrustStore.sqlite3从备份复制到模拟器工作得很好。

看看iostrust Ruby gem: http : iostrust

When I started I couldn't get "Enable Full Trust for Root Certificate" to show up.当我开始时,我无法显示“为根证书启用完全信任”。 I was using the certs I generated for nginx with openssl.我正在使用我为 nginx 和 openssl 生成的证书。

What worked was exporting the development cert from Keychain Access and downloading that with Safari in the simulator.有效的是从 Keychain Access 导出开发证书并在模拟器中使用 Safari 下载它。 Then the "Enable Full Trust for Root Certificate" showed up and I was able to get my application working.然后出现了“为根证书启用完全信任”,我能够让我的应用程序正常工作。

Also, like people above have said dragging and dropping the cert on to the simulator doesn't work anymore.此外,就像上面的人所说的那样,将证书拖放到模拟器上不再有效。 You can download the cert with Safari.您可以使用 Safari 下载证书。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM