2 * idPref.cpp - maniuplate Identity Prefs
9 #include <clAppUtils/identPicker.h>
10 #include <Security/Security.h>
11 #include <CoreFoundation/CoreFoundation.h>
13 static void usage(char **argv
)
15 printf("usage: %s set|get [options]\n", argv
[0]);
17 printf(" -p prefName\n");
18 printf(" -k keychain\n");
22 int main(int argc
, char **argv
)
25 SecKeychainRef kcRef
= NULL
;
26 char *prefName
= NULL
;
29 if((argc
< 2) || (argv
[1][0] == 'h')) {
32 if(!strcmp(argv
[1], "get")) {
35 else if(!strcmp(argv
[1], "set")) {
39 printf("Bad op argument\n");
47 while ((arg
= getopt(argc
, argv
, "p:k:h")) != -1) {
62 if(prefName
== NULL
) {
63 printf("***You must specify a preference name via -p.\n");
66 CFStringRef prefStr
= CFStringCreateWithCString(NULL
, prefName
, kCFStringEncodingASCII
);
68 printf("***Error converting pref name '%s' to CFString.\n", prefName
);
74 ortn
= SecKeychainOpen(kcName
, &kcRef
);
76 cssmPerror("SecKeychainOpen", ortn
);
81 SecIdentityRef idRef
= NULL
;
83 ortn
= sslSimpleIdentPicker(kcRef
, &idRef
);
85 printf("Error picking identity; aborting.\n");
88 ortn
= SecIdentitySetPreference(idRef
, prefStr
, 0);
90 cssmPerror("SecIdentitySetPreference", ortn
);
93 printf("...Identity preference set for name '%s'.\n", prefName
);
96 ortn
= SecIdentityCopyPreference(prefStr
, 0, NULL
, &idRef
);
98 cssmPerror("SecIdentityCopyPreference", ortn
);
101 SecCertificateRef certRef
= NULL
;
102 ortn
= SecIdentityCopyCertificate(idRef
, &certRef
);
104 cssmPerror("SecIdentityCopyCertificate", ortn
);
107 char *idName
= kcItemPrintableName((SecKeychainItemRef
)certRef
);
108 printf("Identity for prefName '%s' found : '%s'\n",