2 * keySizePref.cpp - set/examime max RSA key size per system
9 #include <CoreFoundation/CoreFoundation.h>
10 #include <security_utilities/simpleprefs.h>
12 #define kRSAKeySizePrefsDomain "com.apple.crypto"
13 #define kRSAMaxKeySizePref CFSTR("RSAMaxKeySize")
14 #define kRSAMacPublicExponentPref CFSTR("RSAMaxPublicExponent")
16 static void usage(char **argv
)
19 printf(" %s set keysize|pubexpsize <val>\n", argv
[0]);
20 printf(" %s get keysize|pubexpsize\n", argv
[0]);
21 printf(" %s illegal -- set illegally large values for both\n", argv
[0]);
25 int main(int argc
, char **argv
)
28 CFStringRef which
= NULL
;
31 bool doIllegal
= false;
36 if(!strcmp(argv
[1], "set")) {
42 else if(!strcmp(argv
[1], "get")) {
47 else if(!strcmp(argv
[1], "illegal")) {
57 if(!strcmp(argv
[2], "keysize")) {
58 which
= kRSAMaxKeySizePref
;
59 cWhich
= "Max Key Size";
61 else if(!strcmp(argv
[2], "pubexpsize")) {
62 which
= kRSAMacPublicExponentPref
;
63 cWhich
= "Max Public Exponent";
70 if(doSet
|| doIllegal
) {
71 MutableDictionary
*prefs
= NULL
;
74 prefs
= new MutableDictionary(kRSAKeySizePrefsDomain
, Dictionary::US_System
);
77 /* create a new one */
78 prefs
= new MutableDictionary();
82 SInt64 bigBad
= 0x100000000LL
;
83 CFNumberRef cfVal
= CFNumberCreate(NULL
, kCFNumberSInt64Type
, &bigBad
);
84 prefs
->setValue(kRSAMaxKeySizePref
, cfVal
);
85 prefs
->setValue(kRSAMacPublicExponentPref
, cfVal
);
90 /* this means "remove" */
91 prefs
->removeValue(which
);
94 CFNumberRef cfVal
= CFNumberCreate(NULL
, kCFNumberSInt32Type
, &iVal
);
95 prefs
->setValue(which
, cfVal
);
98 bool success
= prefs
->writePlistToPrefs(kRSAKeySizePrefsDomain
,
99 Dictionary::US_System
);
102 printf("Both prefs set to 0x100000000LL\n");
105 printf("%s preference removed.\n", cWhich
);
108 printf("%s set to %lu\n", cWhich
, (unsigned long) iVal
);
112 printf("***Error setting %s\n", cWhich
);
119 Dictionary
prefs(kRSAKeySizePrefsDomain
, Dictionary::US_System
);
120 CFNumberRef cfVal
= (CFNumberRef
)prefs
.getValue(which
);
122 printf("...no %s pref found\n", cWhich
);
125 if(CFGetTypeID(cfVal
) != CFNumberGetTypeID()) {
126 printf("***Badly formatted %s pref (1)\n", cWhich
);
130 if(!CFNumberGetValue(cfVal
, kCFNumberSInt32Type
, &u
)) {
131 printf("***Badly formatted %s pref (2)\n", cWhich
);
133 printf("%s preference is currently %lu\n", cWhich
, (unsigned long)u
);
136 printf("...no %s prefs found\n", kRSAKeySizePrefsDomain
);