]> git.saurik.com Git - apple/security.git/blob - OSX/sec/Security/SecPasswordGenerate.h
Security-57337.50.23.tar.gz
[apple/security.git] / OSX / sec / Security / SecPasswordGenerate.h
1 /*
2 * Copyright (c) 2000-2004,2013-2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /*!
25 @header SecPasswordGenerate
26 SecPassword implements logic to use the system facilities for acquiring a password,
27 optionally stored and retrieved from the user's keychain.
28 */
29
30 #ifndef _SECURITY_SECPASSWORDGENERATE_H_
31 #define _SECURITY_SECPASSWORDGENERATE_H_
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #include <CoreFoundation/CoreFoundation.h>
38 #include <Security/SecBase.h>
39
40 typedef uint32_t SecPasswordType;
41 enum {
42 kSecPasswordTypeSafari = 0,
43 kSecPasswordTypeiCloudRecovery = 1,
44 kSecPasswordTypeWifi = 2,
45 kSecPasswordTypePIN = 3
46 } __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
47
48 // Keys for external dictionaries with password generation requirements we read from plist.
49 extern CFStringRef kSecPasswordDefaultForType
50 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
51
52 extern CFStringRef kSecPasswordMinLengthKey
53 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
54 extern CFStringRef kSecPasswordMaxLengthKey
55 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
56 extern CFStringRef kSecPasswordAllowedCharactersKey
57 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
58 extern CFStringRef kSecPasswordRequiredCharactersKey
59 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
60
61 extern CFStringRef kSecPasswordDisallowedCharacters
62 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
63 extern CFStringRef kSecPasswordCantStartWithChars
64 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
65 extern CFStringRef kSecPasswordCantEndWithChars
66 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
67
68 extern CFStringRef kSecPasswordContainsNoMoreThanNSpecificCharacters
69 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
70 extern CFStringRef kSecPasswordContainsAtLeastNSpecificCharacters
71 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
72 extern CFStringRef kSecPasswordContainsNoMoreThanNConsecutiveIdenticalCharacters
73 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
74
75 extern CFStringRef kSecPasswordCharacters
76 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
77 extern CFStringRef kSecPasswordCharacterCount
78 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
79
80 extern CFStringRef kSecPasswordGroupSize
81 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
82 extern CFStringRef kSecPasswordNumberOfGroups
83 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
84 extern CFStringRef kSecPasswordSeparator
85 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
86
87
88 /*
89 @function SecPasswordCopyDefaultPasswordLength
90 @abstract Returns the default length/number of tuples of a defaultly generated password
91 @param type: default password types kSecPasswordTypeSafari, kSecPasswordTypeiCloudRecovery, kSecPasswordTypeWifi, kSecPasswordTypePIN
92 @param error: An error code will be returned if an unrecognized password type is passed to the routine.
93 @result Dictionary consisting of length of tuple and number of tuples or a NULL if the passed type isn't recognized.
94 */
95 CFDictionaryRef SecPasswordCopyDefaultPasswordLength(SecPasswordType type, CFErrorRef *error)
96 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
97
98
99 /*
100 @function SecPasswordIsPasswordWeak
101 @abstract Evalutes the weakness of a passcode. This function can take any type of passcode. Currently
102 the function evaluates passcodes with only ASCII characters
103 @param passcode a string of any length and type (4 or 6 digit digit PIN, complex passcode)
104 @result True if the password is weak, False if the password is strong.
105 */
106
107 bool SecPasswordIsPasswordWeak(CFStringRef passcode)
108 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
109
110 /*
111 @function SecPasswordIsPasswordWeak2
112 @abstract Evalutes the weakness of a passcode. This function can take any type of passcode. Currently
113 the function evaluates passcodes with only ASCII characters
114 @param passcode a string of any length and type (4 or 6 digit PIN, complex passcode)
115 @param isSimple is to indicate whether we're evaluating a 4 or 6 digit PIN or a complex passcode
116 @result True if the password is weak, False if the password is strong.
117 */
118
119 bool SecPasswordIsPasswordWeak2(bool isSimple, CFStringRef passcode)
120 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
121
122 /*
123 @function SecPasswordGenerate. Supports generating passwords for Safari, iCloud, Personal
124 Hotspot clients. Will also generate 4 or 6 digit pins.
125 @abstract Returns a generated password based on a set of constraints
126 @param type: type of password to generate. Pass enum types
127 kSecPasswordTypeSafari, kSecPasswordTypeiCloudRecovery, kSecPasswordTypeWifi, or kSecPasswordTypePIN
128 @param error: An error code will be returned if an error is encountered. Check SecBase.h for the list of codes.
129 @param passwordRequirements: a dictionary containing a set of password requirements.
130 ex: password type 'safari' requires at least: minLength, maxLength, string
131 of allowed characters, required characters
132 @return NULL or a CFStringRef password
133
134 *Note: This parameters is not required if kSecPasswordTypeiCloudRecovery or kSecPasswordTypePIN is supplied as the type.
135 If kSecPasswordTypeSafari or kSecPasswordTypeWifi is supplied, you must include these dictionary key/value pairs:
136 kSecPasswordMinLengthKey / CFNumberRef
137 kSecPasswordMaxLengthKey / CFNumberRef
138 kSecPasswordAllowedCharactersKey / CFStringRef
139 kSecPasswordRequiredCharactersKey / CFArrayRef of CFCharacterSetRefs
140
141 *Note: *If you would like a custom password type, file a bug in Sec Utilities requesting
142 a new type along with generation specifications (ex. should contain one upper case, one lower case etc)
143
144 *Note: Be sure to release the returned password when done using it.
145 */
146 CF_RETURNS_RETAINED CFStringRef SecPasswordGenerate(SecPasswordType type, CFErrorRef *error, CFDictionaryRef passwordRequirements)
147 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
148
149 CFStringRef SecPasswordCreateWithRandomDigits(int n, CFErrorRef *error)
150 __OSX_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0);
151
152 #ifdef __cplusplus
153 }
154 #endif
155
156 #endif /* !_SECURITY_SECPASSWORDGENERATE_H_ */