Skip to content

Instantly share code, notes, and snippets.

@floehopper
Created September 25, 2009 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save floehopper/193415 to your computer and use it in GitHub Desktop.
Save floehopper/193415 to your computer and use it in GitHub Desktop.
void addInternetPassword(NSString *password, NSString *account,
NSString *server, NSString *itemLabel, NSString *path,
SecProtocolType protocol, int port)
{
OSStatus err;
SecKeychainItemRef item = nil;
const char *pathUTF8 = [path UTF8String];
const char *serverUTF8 = [server UTF8String];
const char *accountUTF8 = [account UTF8String];
const char *passwordUTF8 = [password UTF8String];
const char *itemLabelUTF8 = [itemLabel UTF8String];
//Create initial access control settings for the item:
SecAccessRef access = createAccess(itemLabel);
//Following is the lower-level equivalent to the
// SecKeychainAddInternetPassword function:
//Set up the attribute vector (each attribute consists
// of {tag, length, pointer}):
SecKeychainAttribute attrs[] = {
{ kSecLabelItemAttr, strlen(itemLabelUTF8), (char *)itemLabelUTF8 },
{ kSecAccountItemAttr, strlen(accountUTF8), (char *)accountUTF8 },
{ kSecServerItemAttr, strlen(serverUTF8), (char *)serverUTF8 },
{ kSecPortItemAttr, sizeof(int), (int *)&port },
{ kSecProtocolItemAttr, sizeof(SecProtocolType),
(SecProtocolType *)&protocol },
{ kSecPathItemAttr, strlen(pathUTF8), (char *)pathUTF8 }
};
SecKeychainAttributeList attributes = { sizeof(attrs) / sizeof(attrs[0]),
attrs };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment