comparison dstep/security/SecKeychain.d @ 11:07194b026fa4

Added bindings to a couple of frameworks, new license + some other things
author Jacob Carlborg <doob@me.com>
date Sat, 01 Aug 2009 15:03:28 +0200
parents
children
comparison
equal deleted inserted replaced
10:27e00625790b 11:07194b026fa4
1 /**
2 * Copyright: Copyright (c) 2009 Jacob Carlborg.
3 * Authors: Jacob Carlborg
4 * Version: Initial created: Jul 22, 2009
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
6 */
7 module dstep.security.SecKeychain;
8
9 import dstep.corefoundation.CFArray;
10 import dstep.corefoundation.CFBase;
11 import dstep.objc.bridge.TypeEncoding;
12 import dstep.security.SecBase;
13 import dstep.security.cssmapple;
14 import dstep.security.cssmtype;
15
16 alias uint SecAuthenticationType;
17 alias uint SecProtocolType;
18 alias uint SecKeychainEvent;
19 alias uint SecKeychainEventMask;
20
21 extern (C)
22 {
23 alias int function (uint, SecKeychainCallbackInfo*, void*) SecKeychainCallback;
24 }
25
26 // This is needed otherwise the enums will fail compiling with gdc
27 version (GNU)
28 {
29 private
30 {
31 const __kSecProtocolTypeFTP = getOSType!("ftp ");
32 const __kSecProtocolTypeFTPAccount = getOSType!("ftpa");
33 const __kSecProtocolTypeHTTP = getOSType!("http");
34 const __kSecProtocolTypeIRC = getOSType!("irc ");
35 const __kSecProtocolTypeNNTP = getOSType!("nntp");
36 const __kSecProtocolTypePOP3 = getOSType!("pop3");
37 const __kSecProtocolTypeSMTP = getOSType!("smtp");
38 const __kSecProtocolTypeSOCKS = getOSType!("sox ");
39 const __kSecProtocolTypeIMAP = getOSType!("imap");
40 const __kSecProtocolTypeLDAP = getOSType!("ldap");
41 const __kSecProtocolTypeAppleTalk = getOSType!("atlk");
42 const __kSecProtocolTypeAFP = getOSType!("afp ");
43 const __kSecProtocolTypeTelnet = getOSType!("teln");
44 const __kSecProtocolTypeSSH = getOSType!("ssh ");
45 const __kSecProtocolTypeFTPS = getOSType!("ftps");
46 const __kSecProtocolTypeHTTPS = getOSType!("htps");
47 const __kSecProtocolTypeHTTPProxy = getOSType!("htpx");
48 const __kSecProtocolTypeHTTPSProxy = getOSType!("htsx");
49 const __kSecProtocolTypeFTPProxy = getOSType!("ftpx");
50 const __kSecProtocolTypeCIFS = getOSType!("cifs");
51 const __kSecProtocolTypeSMB = getOSType!("smb ");
52 const __kSecProtocolTypeRTSP = getOSType!("rtsp");
53 const __kSecProtocolTypeRTSPProxy = getOSType!("rtsx");
54 const __kSecProtocolTypeDAAP = getOSType!("daap");
55 const __kSecProtocolTypeEPPC = getOSType!("eppc");
56 const __kSecProtocolTypeIPP = getOSType!("ipp ");
57 const __kSecProtocolTypeNNTPS = getOSType!("ntps");
58 const __kSecProtocolTypeLDAPS = getOSType!("ldps");
59 const __kSecProtocolTypeTelnetS = getOSType!("tels");
60 const __kSecProtocolTypeIMAPS = getOSType!("imps");
61 const __kSecProtocolTypeIRCS = getOSType!("ircs");
62 const __kSecProtocolTypePOP3S = getOSType!("pops");
63 const __kSecProtocolTypeCVSpserver = getOSType!("cvsp");
64 const __kSecProtocolTypeSVN = getOSType!("svn ");
65 const __kSecAuthenticationTypeNTLM = ((getOSType!("ntlm") >> 24) | ((getOSType!("ntlm") >> 8) & 0xff00) | ((getOSType!("ntlm") << 8) & 0xff0000) | (getOSType!("ntlm") & 0xff) << 24);
66 const __kSecAuthenticationTypeMSN = ((getOSType!("msna") >> 24) | ((getOSType!("msna") >> 8) & 0xff00) | ((getOSType!("msna") << 8) & 0xff0000) | (getOSType!("msna") & 0xff) << 24);
67 const __kSecAuthenticationTypeDPA = ((getOSType!("dpaa") >> 24) | ((getOSType!("dpaa") >> 8) & 0xff00) | ((getOSType!("dpaa") << 8) & 0xff0000) | (getOSType!("dpaa") & 0xff) << 24);
68 const __kSecAuthenticationTypeRPA = ((getOSType!("rpaa") >> 24) | ((getOSType!("rpaa") >> 8) & 0xff00) | ((getOSType!("rpaa") << 8) & 0xff0000) | (getOSType!("rpaa") & 0xff) << 24);
69 const __kSecAuthenticationTypeHTTPBasic = ((getOSType!("http") >> 24) | ((getOSType!("http") >> 8) & 0xff00) | ((getOSType!("http") << 8) & 0xff0000) | (getOSType!("http") & 0xff) << 24);
70 const __kSecAuthenticationTypeHTTPDigest = ((getOSType!("httd") >> 24) | ((getOSType!("httd") >> 8) & 0xff00) | ((getOSType!("httd") << 8) & 0xff0000) | (getOSType!("httd") & 0xff) << 24);
71 const __kSecAuthenticationTypeHTMLForm = ((getOSType!("form") >> 24) | ((getOSType!("form") >> 8) & 0xff00) | ((getOSType!("form") << 8) & 0xff0000) | (getOSType!("form") & 0xff) << 24);
72 const __kSecAuthenticationTypeDefault = ((getOSType!("dflt") >> 24) | ((getOSType!("dflt") >> 8) & 0xff00) | ((getOSType!("dflt") << 8) & 0xff0000) | (getOSType!("dflt") & 0xff) << 24);
73 const __kSecAuthenticationTypeAny = ((0 >> 24) | ((0 >> 8) & 0xff00) | ((0 << 8) & 0xff0000) | (0 & 0xff) << 24);
74 }
75 }
76
77 enum
78 {
79 kSecUnlockStateStatus = 1,
80 kSecReadPermStatus = 2,
81 kSecWritePermStatus = 4
82 }
83
84 enum
85 {
86 kSecAuthenticationTypeNTLM = ((getOSType!("ntlm") >> 24) | ((getOSType!("ntlm") >> 8) & 0xff00) | ((getOSType!("ntlm") << 8) & 0xff0000) | (getOSType!("ntlm") & 0xff) << 24),
87 kSecAuthenticationTypeMSN = ((getOSType!("msna") >> 24) | ((getOSType!("msna") >> 8) & 0xff00) | ((getOSType!("msna") << 8) & 0xff0000) | (getOSType!("msna") & 0xff) << 24),
88 kSecAuthenticationTypeDPA = ((getOSType!("dpaa") >> 24) | ((getOSType!("dpaa") >> 8) & 0xff00) | ((getOSType!("dpaa") << 8) & 0xff0000) | (getOSType!("dpaa") & 0xff) << 24),
89 kSecAuthenticationTypeRPA = ((getOSType!("rpaa") >> 24) | ((getOSType!("rpaa") >> 8) & 0xff00) | ((getOSType!("rpaa") << 8) & 0xff0000) | (getOSType!("rpaa") & 0xff) << 24),
90 kSecAuthenticationTypeHTTPBasic = ((getOSType!("http") >> 24) | ((getOSType!("http") >> 8) & 0xff00) | ((getOSType!("http") << 8) & 0xff0000) | (getOSType!("http") & 0xff) << 24),
91 kSecAuthenticationTypeHTTPDigest = ((getOSType!("httd") >> 24) | ((getOSType!("httd") >> 8) & 0xff00) | ((getOSType!("httd") << 8) & 0xff0000) | (getOSType!("httd") & 0xff) << 24),
92 kSecAuthenticationTypeHTMLForm = ((getOSType!("form") >> 24) | ((getOSType!("form") >> 8) & 0xff00) | ((getOSType!("form") << 8) & 0xff0000) | (getOSType!("form") & 0xff) << 24),
93 kSecAuthenticationTypeDefault = ((getOSType!("dflt") >> 24) | ((getOSType!("dflt") >> 8) & 0xff00) | ((getOSType!("dflt") << 8) & 0xff0000) | (getOSType!("dflt") & 0xff) << 24),
94 kSecAuthenticationTypeAny = ((0 >> 24) | ((0 >> 8) & 0xff00) | ((0 << 8) & 0xff0000) | (0 & 0xff) << 24)
95 }
96
97 enum
98 {
99 kSecProtocolTypeFTP = getOSType!("ftp "),
100 kSecProtocolTypeFTPAccount = getOSType!("ftpa"),
101 kSecProtocolTypeHTTP = getOSType!("http"),
102 kSecProtocolTypeIRC = getOSType!("irc "),
103 kSecProtocolTypeNNTP = getOSType!("nntp"),
104 kSecProtocolTypePOP3 = getOSType!("pop3"),
105 kSecProtocolTypeSMTP = getOSType!("smtp"),
106 kSecProtocolTypeSOCKS = getOSType!("sox "),
107 kSecProtocolTypeIMAP = getOSType!("imap"),
108 kSecProtocolTypeLDAP = getOSType!("ldap"),
109 kSecProtocolTypeAppleTalk = getOSType!("atlk"),
110 kSecProtocolTypeAFP = getOSType!("afp "),
111 kSecProtocolTypeTelnet = getOSType!("teln"),
112 kSecProtocolTypeSSH = getOSType!("ssh "),
113 kSecProtocolTypeFTPS = getOSType!("ftps"),
114 kSecProtocolTypeHTTPS = getOSType!("htps"),
115 kSecProtocolTypeHTTPProxy = getOSType!("htpx"),
116 kSecProtocolTypeHTTPSProxy = getOSType!("htsx"),
117 kSecProtocolTypeFTPProxy = getOSType!("ftpx"),
118 kSecProtocolTypeCIFS = getOSType!("cifs"),
119 kSecProtocolTypeSMB = getOSType!("smb "),
120 kSecProtocolTypeRTSP = getOSType!("rtsp"),
121 kSecProtocolTypeRTSPProxy = getOSType!("rtsx"),
122 kSecProtocolTypeDAAP = getOSType!("daap"),
123 kSecProtocolTypeEPPC = getOSType!("eppc"),
124 kSecProtocolTypeIPP = getOSType!("ipp "),
125 kSecProtocolTypeNNTPS = getOSType!("ntps"),
126 kSecProtocolTypeLDAPS = getOSType!("ldps"),
127 kSecProtocolTypeTelnetS = getOSType!("tels"),
128 kSecProtocolTypeIMAPS = getOSType!("imps"),
129 kSecProtocolTypeIRCS = getOSType!("ircs"),
130 kSecProtocolTypePOP3S = getOSType!("pops"),
131 kSecProtocolTypeCVSpserver = getOSType!("cvsp"),
132 kSecProtocolTypeSVN = getOSType!("svn "),
133 kSecProtocolTypeAny = 0
134 }
135
136 enum
137 {
138 kSecLockEvent = 1,
139 kSecUnlockEvent = 2,
140 kSecAddEvent = 3,
141 kSecDeleteEvent = 4,
142 kSecUpdateEvent = 5,
143 kSecPasswordChangedEvent = 6,
144 kSecDefaultChangedEvent = 9,
145 kSecDataAccessEvent = 10,
146 kSecKeychainListChangedEvent = 11,
147 kSecTrustSettingsChangedEvent = 12
148 }
149
150 enum
151 {
152 kSecLockEventMask = 1 << kSecLockEvent,
153 kSecUnlockEventMask = 1 << kSecUnlockEvent,
154 kSecAddEventMask = 1 << kSecAddEvent,
155 kSecDeleteEventMask = 1 << kSecDeleteEvent,
156 kSecUpdateEventMask = 1 << kSecUpdateEvent,
157 kSecPasswordChangedEventMask = 1 << kSecPasswordChangedEvent,
158 kSecDefaultChangedEventMask = 1 << kSecDefaultChangedEvent,
159 kSecDataAccessEventMask = 1 << kSecDataAccessEvent,
160 kSecKeychainListChangedMask = 1 << kSecKeychainListChangedEvent,
161 kSecTrustSettingsChangedEventMask = 1 << kSecTrustSettingsChangedEvent,
162 kSecEveryEventMask = 0xffffffff
163 }
164
165 enum SecPreferencesDomain
166 {
167 kSecPreferencesDomainUser,
168 kSecPreferencesDomainSystem,
169 kSecPreferencesDomainCommon,
170 kSecPreferencesDomainDynamic
171 }
172
173 struct SecKeychainSettings
174 {
175 uint version_;
176 ubyte lockOnSleep;
177 ubyte useLockInterval;
178 uint lockInterval;
179 }
180
181
182 struct SecKeychainCallbackInfo
183 {
184 uint version_;
185 SecKeychainItemRef item;
186 SecKeychainRef keychain;
187 int pid;
188 }
189
190 extern (C)
191 {
192 uint SecKeychainGetTypeID ();
193 int SecKeychainGetVersion (uint* returnVers);
194 int SecKeychainOpen (char* pathName, SecKeychainRef* keychain);
195 int SecKeychainCreate (char* pathName, uint passwordLength, void* password, ubyte promptUser, SecAccessRef initialAccess, SecKeychainRef* keychain);
196 int SecKeychainDelete (SecKeychainRef keychainOrArray);
197 int SecKeychainSetSettings (SecKeychainRef keychain, SecKeychainSettings* newSettings);
198 int SecKeychainCopySettings (SecKeychainRef keychain, SecKeychainSettings* outSettings);
199 int SecKeychainUnlock (SecKeychainRef keychain, uint passwordLength, void* password, ubyte usePassword);
200 int SecKeychainLock (SecKeychainRef keychain);
201 int SecKeychainLockAll ();
202 int SecKeychainCopyDefault (SecKeychainRef* keychain);
203 int SecKeychainSetDefault (SecKeychainRef keychain);
204 int SecKeychainCopySearchList (CFArrayRef* searchList);
205 int SecKeychainSetSearchList (CFArrayRef searchList);
206 int SecKeychainCopyDomainDefault (int domain, SecKeychainRef* keychain);
207 int SecKeychainSetDomainDefault (int domain, SecKeychainRef keychain);
208 int SecKeychainCopyDomainSearchList (int domain, CFArrayRef* searchList);
209 int SecKeychainSetDomainSearchList (int domain, CFArrayRef searchList);
210 int SecKeychainSetPreferenceDomain (int domain);
211 int SecKeychainGetPreferenceDomain (SecPreferencesDomain* domain);
212 int SecKeychainGetStatus (SecKeychainRef keychain, SecKeychainStatus* keychainStatus);
213 int SecKeychainGetPath (SecKeychainRef keychain, uint* ioPathLength, char* pathName);
214 int SecKeychainAttributeInfoForItemID (SecKeychainRef keychain, uint itemID, SecKeychainAttributeInfo** info);
215 int SecKeychainFreeAttributeInfo (SecKeychainAttributeInfo* info);
216 int SecKeychainAddCallback (SecKeychainCallback callbackFunction, uint eventMask, void* userContext);
217 int SecKeychainRemoveCallback (SecKeychainCallback callbackFunction);
218 int SecKeychainAddInternetPassword (SecKeychainRef keychain, uint serverNameLength, char* serverName, uint securityDomainLength, char* securityDomain, uint accountNameLength, char* accountName, uint pathLength, char* path, ushort port, uint protocol, uint authenticationType, uint passwordLength, void* passwordData, SecKeychainItemRef* itemRef);
219 int SecKeychainFindInternetPassword (CFTypeRef keychainOrArray, uint serverNameLength, char* serverName, uint securityDomainLength, char* securityDomain, uint accountNameLength, char* accountName, uint pathLength, char* path, ushort port, uint protocol, uint authenticationType, uint* passwordLength, void** passwordData, SecKeychainItemRef* itemRef);
220 int SecKeychainAddGenericPassword (SecKeychainRef keychain, uint serviceNameLength, char* serviceName, uint accountNameLength, char* accountName, uint passwordLength, void* passwordData, SecKeychainItemRef* itemRef);
221 int SecKeychainFindGenericPassword (CFTypeRef keychainOrArray, uint serviceNameLength, char* serviceName, uint accountNameLength, char* accountName, uint* passwordLength, void** passwordData, SecKeychainItemRef* itemRef);
222 int SecKeychainSetUserInteractionAllowed (ubyte state);
223 int SecKeychainGetUserInteractionAllowed (char* state);
224 int SecKeychainGetCSPHandle (SecKeychainRef keychain, CSSM_CSP_HANDLE* cspHandle);
225 int SecKeychainGetDLDBHandle (SecKeychainRef keychain, CSSM_DL_DB_HANDLE* dldbHandle);
226 int SecKeychainCopyAccess (SecKeychainRef keychain, SecAccessRef* access);
227 int SecKeychainSetAccess (SecKeychainRef keychain, SecAccessRef access);
228 }