forked from rohitcoderCdefense/vulnCodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CWE-312.m
25 lines (24 loc) · 1.38 KB
/
CWE-312.m
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
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
NSString *password = @"password";
NSString *username = @"username";
NSString *keychainItemName = @"keychainItemName";
NSString *keychainItemServiceName = @"keychainItemServiceName";
NSMutableDictionary *keychainItem = [[NSMutableDictionary alloc] init];
[keychainItem setObject:(__bridge id)kSecClassGenericPassword forKey:(__bridge id)kSecClass];
[keychainItem setObject:keychainItemName forKey:(__bridge id)kSecAttrAccount];
[keychainItem setObject:keychainItemServiceName forKey:(__bridge id)kSecAttrService];
[keychainItem setObject:username forKey:(__bridge id)kSecAttrLabel];
[keychainItem setObject:password forKey:(__bridge id)kSecValueData];
[keychainItem setObject:(__bridge id)kSecAttrAccessibleWhenUnlocked forKey:(__bridge id)kSecAttrAccessible];
[keychainItem setObject:(__bridge id)kSecAttrAccessibleWhenUnlockedThisDeviceOnly forKey:(__bridge id)kSecAttrAccessible];
OSStatus status = SecItemAdd((__bridge CFDictionaryRef)keychainItem, NULL);
if (status == errSecSuccess) {
NSLog(@"Successfully added the %@/%@ keychain item.", keychainItemServiceName, keychainItemName);
}
}
return 0;
}