As part of testing an SCEP server, I have been sending a lot of SCEP requests to my iOS device to create RSA key pairs.
During the course of the enrollment process, some of the CSRs have actually been signed by the SCEP server and returned back to the device.
However, I would like to remove the old keys / certs from the device to start fresh, as the certificate list in the device is way too long (imagine how many trial&error steps I have gone through).
Problem is, some of these certs do NOT show up under Settings/General/Profile. They ONLY show up when I go to a VPN entry and select Certificate as the authentication method.
QUESTION:
Is there way to ask an iOS device to remove the keys / certs from its KeyChain?
In the end, I came up with 2 options:
On a jailbroken device, one can use the Keychain Viewer application (version 0.4) to help the process. Here's how I did it:
dpkg -i keychainviewer0.4_beta.deb
)rowid
of the item.chmod u+r /private/var/Keychains/keychain-2.db
sqlite3 /private/var/Keychains/keychain-2.db
WARNING: BELOW LINES ARE DESTRUCTIVE!
BACKUP YOUR ENTIRE Keychains
DIRECTORY. BETTER YET, TAKE A BACKUP OF YOUR ENTIRE DEVICE IN CASE THINGS GO WRONG.
PROCEED AT YOUR OWN PERIL!
DELETE FROM keys WHERE labl IN (SELECT DISTINCT(labl) FROM cert WHERE rowid=_row_id_you_want_);
DELETE FROM cert WHERE rowid=_row_id_you_want_;
Another version of this is based on the Issuer of the certificate that you want to delete. In that case, you would do the following:
rowid
of the certificate you would like to delete.SELECT quote(issr) FROM cert WHERE rowid=_row_id_you_want_;
X'F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0'
This is the hex notation of the issuer name's binary blob as stored in the Keychain DB (I think this is the encrypted form).DELETE FROM keys WHERE labl in (SELECT DISTINCT(labl) FROM cert WHERE issr=X'F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0');
DELETE FROM cert WHERE issr=X'F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0');