Esempio n. 1
0
        public void Add_Certificate()
        {
#if MONOMAC && !NET
            Stream certStream = typeof(KeyChainTest).Assembly.GetManifestResourceStream("xammac_tests.Security.openssl_crt.der");
#else
            Stream certStream = typeof(KeyChainTest).Assembly.GetManifestResourceStream("monotouchtest.Security.openssl_crt.der");
#endif
            NSData data = NSData.FromStream(certStream);

            var query = new SecRecord(SecKind.Certificate)
            {
                Label = $"Internet Widgits Pty Ltd",
            };
            var rec = query.Clone();
            rec.SetValueRef(new SecCertificate(data));

            try {
                // delete any existing certificates first.
                SecKeyChain.Remove(query);
                // add the new certificate
                var rc = SecKeyChain.Add(rec);
                Assert.That(rc, Is.EqualTo(SecStatusCode.Success), "Add_Certificate");
            } finally {
                // clean up after ourselves
                SecKeyChain.Remove(query);
            }
        }
Esempio n. 2
0
        SecStatusCode SetID(Guid setID)
        {
            var queryRec = new SecRecord(SecKind.GenericPassword)
            {
                Service = RecordService,
                Account = RecordAccount,
            };
            var record = queryRec.Clone();

            record.Generic    = NSData.FromString(Convert.ToString(setID), NSStringEncoding.UTF8);
            record.Accessible = SecAccessible.Always;
            record.Label      = RecordLabel;
            SecStatusCode code = SecKeyChain.Add(record);

            if (code == SecStatusCode.DuplicateItem)
            {
                code = RemoveID();
                if (code == SecStatusCode.Success)
                {
                    code = SecKeyChain.Add(record);
                }
            }
            return(code);
        }
Esempio n. 3
0
        static SecStatusCode SetID(Guid setID)
        {
            var queryRec = new SecRecord(SecKind.GenericPassword)
            {
                Service = "KEYCHAIN_SERVICE",
                Label   = "KEYCHAIN_SERVICE",
                Account = "KEYCHAIN_ACCOUNT"
            };
            var record = queryRec.Clone();

            record.Generic    = NSData.FromString(Convert.ToString(setID), NSStringEncoding.UTF8);
            record.Accessible = SecAccessible.Always;
            SecStatusCode code = SecKeyChain.Add(record);

            if (code == SecStatusCode.DuplicateItem)
            {
                code = SecKeyChain.Remove(queryRec);
                if (code == SecStatusCode.Success)
                {
                    code = SecKeyChain.Add(record);
                }
            }
            return(code);
        }