-
Notifications
You must be signed in to change notification settings - Fork 5
/
EMKeychainItem.h
175 lines (143 loc) · 6.1 KB
/
EMKeychainItem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*Copyright (c) 2009 Extendmac, LLC. <[email protected]>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
//Version 1.0.1, Last Updated February 1st, 2010.
#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>
#import <Security/Security.h>
/*!
@abstract EMKeychainItem is a self-contained wrapper class for two-way communication with the keychain. You can add, retrieve, and remove both generic and internet keychain items.
@dicussion All keychain items have a username, password, and optionally a label.
*/
@interface EMKeychainItem : NSObject
{
@private
NSString *mUsername;
NSString *mPassword;
NSString *mLabel;
@protected
SecKeychainItemRef mCoreKeychainItem;
}
/*!
@abstract Returns whether or not errors are logged.
@discussion Errors occur whenever a keychain item fails to appropriately update a property, or when a given keychain item cannot be found.
*/
+ (BOOL)logsErrors;
//! @abstracts Sets whether or not errors are logged.
+ (void)setLogsErrors:(BOOL)logsErrors;
//! @abstracts Locks the keychain.
+ (void)lockKeychain;
//! @abstract Unlocks the keychain.
+ (void)unlockKeychain;
//! @abstract The keychain item's username.
@property (readwrite, copy) NSString *username;
//! @abstract The keychain item's password.
@property (readwrite, copy) NSString *password;
//! @abstract The keychain item's label.
@property (readwrite, copy) NSString *label;
/*!
@abstract Removes the receiver from the keychain.
@discussion After calling this method, you should generally discard of the receiver. The receiver cannot be "re-added" to the keychain; invoke either addGenericKeychainItemForServer:... or addInternetKeychainItemForServer:... instead.
*/
- (void)removeFromKeychain;
@end
#pragma mark -
/*!
@abstract An EMGenericKeychainItem wraps the functionality and data-members associated with a generic keychain item.
@discussion Generic keychain items have a service name in addition to the standard keychain item properties.
*/
@interface EMGenericKeychainItem : EMKeychainItem
{
@private
NSString *mServiceName;
}
//! @abstract The keychain item's service name.
@property (readwrite, copy) NSString *serviceName;
/*!
@abstract Returns, if possible, a generic keychain item that corresponds to the given service.
@param serviceName The service name. Cannot be nil.
@param username The username. Cannot be nil.
@result An EMGenericKeychainItem if the keychain item can be discovered. Otherwise, nil.
*/
+ (EMGenericKeychainItem *)genericKeychainItemForService:(NSString *)serviceName
withUsername:(NSString *)username;
/*!
@abstract Adds a keychain item for the given service.
@param serviceName The service name. Cannot be nil.
@param username The username. Cannot be nil.
@param password The password to associate with the username and service. Cannot be nil.
@result An EMGenericKeychainItem if the service can be added to the keychain. Otherwise, nil.
*/
+ (EMGenericKeychainItem *)addGenericKeychainItemForService:(NSString *)serviceName
withUsername:(NSString *)username
password:(NSString *)password;
@end
#pragma mark -
/*!
@abstract An EMInternetKeychainItem wraps the functionality and data-members associated with an internet keychain item.
@discussion Internet keychain items can optionally have a server, path, port, and protocol in addition to the standard keychain item properties.
*/
@interface EMInternetKeychainItem : EMKeychainItem
{
@private
NSString *mServer;
NSString *mPath;
NSInteger mPort;
SecProtocolType mProtocol;
}
/*!
@abstract Returns, if possible, an internet keychain item that corresponds to the given server.
@param server The server. Cannot be nil.
@param username The username. Cannot be nil.
@param path The path.
@param port The port.
@param protocol The protocol.
@result An EMInternetKeychainItem if the keychain item can be discovered. Otherwise, nil.
*/
+ (EMInternetKeychainItem *)internetKeychainItemForServer:(NSString *)server
withUsername:(NSString *)username
path:(NSString *)path
port:(NSInteger)port
protocol:(SecProtocolType)protocol;
/*!
@abstract Adds a keychain item for the given server.
@param server The server. Cannot be nil.
@param username The username. Cannot be nil.
@param password The password to associate with the server, username, path, port, and protocol. Cannot be nil.
@param path The path.
@param port The port.
@param protocol The protocol.
@result An EMInternetKeychainItem if the item can be added to the keychain. Otherwise, nil.
*/
+ (EMInternetKeychainItem *)addInternetKeychainItemForServer:(NSString *)server
withUsername:(NSString *)username
password:(NSString *)password
path:(NSString *)path
port:(NSInteger)port
protocol:(SecProtocolType)protocol;
//! @abstract The keychain item's server.
@property (readwrite, copy) NSString *server;
//! @abstract The keychain item's path.
@property (readwrite, copy) NSString *path;
//! @abstract The keychain item's port.
@property (readwrite, assign) NSInteger port;
//! @abstract The keychain item's protocol.
@property (readwrite, assign) SecProtocolType protocol;
@end