public SecRecord(SecKind secKind) { var kind = SecClass.FromSecKind(secKind); _queryDict = CFMutableDictionary.Create(); _queryDict.SetValue(SecClassKey, kind); }
static SafeSecIdentityHandle FindIdentity(Predicate <SafeSecCertificateHandle> filter) { Initialize(); /* * Unfortunately, SecItemCopyMatching() does not allow any search * filters when looking up an identity. * * The following lookup will return all identities from the keychain - * we then need need to find the right one. */ using (var query = CFMutableDictionary.Create()) { query.SetValue(SecClassKey, SecClassIdentity); query.SetValue(CFBoolean.True.Handle, ReturnRef); query.SetValue(MatchLimitAll, MatchLimit); var status = SecItemCopyMatching(query.Handle, out var ptr); if (status != SecStatusCode.Success || ptr == IntPtr.Zero) { return(null); } using (var array = new CFArray(ptr, false)) { for (int i = 0; i < array.Count; i++) { var item = array[i]; if (!MonoCertificatePal.IsSecIdentity(item)) { throw new InvalidOperationException(); } using (var identity = new SafeSecIdentityHandle(item)) using (var certificate = MonoCertificatePal.GetCertificate(identity)) { if (filter(certificate)) { return(new SafeSecIdentityHandle(item)); } } } } } return(null); }