向 iphone 模拟器添加自签名证书?

我在 API 的端点有一个自签名证书。我正在尝试使用模拟器测试一些东西,但我得到了“不受信任的服务器证书”。

我曾试图在模拟器上使用 safari 下载.crt 文件,但似乎没有用。

IPhone 模拟器从哪里得到它的密钥链? 我怎样才能添加一个可信的证书,使我的应用程序将工作?

更新

我通过创建一个 CA,然后使用 iPhone 供应工具添加一个 CA 证书使它工作。然后我就能够在 API 服务器上获得一个由 CA 证书签名的证书,而 NSConnection 刚刚起作用了。由于某种原因,我无法使用自签名证书使它工作。我需要使用供应软件重新尝试。

我真正的问题是,我怎样才能让它在模拟器上工作?我认为模拟器使用的是实际计算机的钥匙链。

58824 次浏览

Take a look at the shell script Charles uses to install their self signed cert into the simulator's keychain. 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.

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. I tried to only insert a single row with the following sqlite, but I couldn't get it working.

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).

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. Copying the entire TrustStore.sqlite3 from the backup into the simulator worked just fine.

Just for Info, if someone still runs into that problem:

simply drag & drop your .cer Files into your running Simulator window. You'll see Safari flashing and then the import dialog for your Certificate (or Certificate Authority)...

Working for iOS 7 Simulator (and i Think did work for iOS 6 too).

Take a look at the iostrust Ruby gem: http://github.com/yageek/iostrust

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. 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

You are going to want to use a project called ADVTrustStore from github. 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

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. 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.

For anyone use OS X Catalina, please check this : https://forums.developer.apple.com/thread/124056.

Catalina is currently blocking access to Desktop, Documents and Downloads folder. I moved certificate files to Shared folder and drag and drop the files to simulator from there.

Dragging and drop used to work but it didn't work on XCode 12 for me. What worked for me was opening Safari browser on Simulator and then typing the file URL for the .crt certificate file. 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.

For IOS14, after the dragging, you need go to:

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

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.

What worked was exporting the development cert from Keychain Access and downloading that with Safari in the simulator. 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.