Function

SecKeychainAddInternetPassword

Adds a new Internet password to a keychain.

Declaration

OSStatus SecKeychainAddInternetPassword(SecKeychainRef keychain, UInt32 serverNameLength, const char *serverName, UInt32 securityDomainLength, const char *securityDomain, UInt32 accountNameLength, const char *accountName, UInt32 pathLength, const char *path, UInt16 port, SecProtocolType protocol, SecAuthenticationType authenticationType, UInt32 passwordLength, const void *passwordData, SecKeychainItemRef  _Nullable *itemRef);

Parameters

keychain

A reference to the keychain in which to store an Internet password. Pass NULL to specify the user’s default keychain.

serverNameLength

The length of the serverName character string.

serverName

A UTF-8 encoded character string representing the server name.

securityDomainLength

The length of the securityDomain character string.

securityDomain

A UTF-8 encoded character string representing the security domain. This parameter is optional. Pass NULL if the protocol does not require it.

accountNameLength

The length of the accountName character string.

accountName

A UTF-8 encoded character string representing the account name.

pathLength

The length of the path character string.

path

A UTF-8 encoded character string representing the path.

port

The TCP/IP port number. If no specific port number is associated with this password, pass 0.

protocol

The protocol associated with this password. See SecProtocolType for a description of possible values.

authenticationType

The authentication scheme used. See SecAuthenticationType for a description of possible values. Pass the constant kSecAuthenticationTypeDefault, to specify the default authentication scheme.

passwordLength

The length of the passwordData buffer.

passwordData

A pointer to a buffer containing the password data to be stored in the keychain.

itemRef

On return, a pointer to a reference to the new keychain item. Pass NULL if you don’t want to obtain this object. You must allocate the memory for this pointer. You must call the CFRelease function to release this object when you are finished using it.

Return Value

A result code. See Security Framework Result Codes. The result code errSecNoDefaultKeychain indicates that no default keychain could be found. The result code errSecDuplicateItem indicates that you tried to add a password that already exists in the keychain. The result code errSecDataTooLarge indicates that you tried to add more data than is allowed for a structure of this type.

Discussion

This function adds a new Internet server password to the specified keychain. Required parameters to identify the password are serverName and accountName (you cannot pass NULL for both parameters). In addition, some protocols may require an optional securityDomain when authentication is requested. This function optionally returns a reference to the newly added item.

This function sets the initial access rights for the new keychain item so that the application creating the item is given trusted access.

This function automatically calls the function SecKeychainUnlock to display the Unlock Keychain dialog box if the keychain is currently locked.

See Also

Legacy Password Storage

SecKeychainFindInternetPassword

Finds the first Internet password based on the attributes passed.

SecKeychainAddGenericPassword

Adds a new generic password to a keychain.

SecKeychainFindGenericPassword

Finds the first generic password based on the attributes passed.

SecProtocolType

The protocol type associated with an Internet password.

SecAuthenticationType

The authentication type to use for an Internet password.

SecPasswordRef

Contains information about a password.