iOS Question how SecKeychainCreate ?

naifnas

Active Member
Licensed User
thanks you for replay

I already check it ..but how in b4i ?

IMO, the easiest solution is to keep data on own website (outside devices).

I need to save the device sequence because i have app ( photo sharing )
So I need any user who breaks the agreement and a law that I save the sequence of his device in a file and website when he logs in again he cannot because I blacklisted it.
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
How in B4i ?
B4X:
#If OBJC
#import "Security/Security.h"
<-- add your subroutines here -->.
#End If

Looks easy, but very doubt that you will find good Objective-C samples.

Meanwhile, I don't understand your problem. Typically user is identified by phone number. When user starts your app first time, he types a phone number and you send him a SMS message with access code.

The "blacklist" can be a list of phone numbers, which you will keep on own website. Of course, bad guy can change a phone number. But with similar success he can change a smartphone.
 
Upvote 0

naifnas

Active Member
Licensed User
thanks very much for you..
#If OBJC
#import "Security/Security.h"
<-- add your subroutines here -->.
#End If
i already try

Meanwhile, I don't understand your problem. Typically user is identified by phone number. When user starts your app first time, he types a phone number and you send him a SMS message with access code.
many user not like register by number mobile.
then not good safety way .
easy he change sim
better save UUID his
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
not good safety way

Take a look messengers. Viber, Whatsapp, Telegram etc. Using SMS garants that user typed valid phone number.
Of course, user can change a SIM. But how he will contact with friends ?

UUID ... As I remember, it's not fixed. After uninstall/install an app receives new UUID.
 
Upvote 0

naifnas

Active Member
Licensed User
this

B4X:
'***************************************
Sub Panel2_Click
Dim noMe As NativeObject=Me
Dim UserTxt As String
Dim PassTxt As String
Dim SomeTxt As String
Dim dict As String
dict="nameplace"
UserTxt="user"
PassTxt="pass"
SomeTxt="xxxxxxxxxx"
' save data in dict
noMe.RunMethod("saveUsername:::::",Array(Me,UserTxt,SomeTxt,PassTxt,dict))
End Sub

Sub Panel3_Click
Dim dict As String
Dim noMe As NativeObject=Me
' get data save from dict
dict="nameplace"
noMe.RunMethod("getCredentialsForServer:::",Array(Me,"GetUserPassTxt",dict))
End Sub

Sub Panel4_Click
Dim dict As String
Dim noMe As NativeObject=Me
dict="nameplace"
' remove it
noMe.RunMethod("removeAllCredentialsForServer:::",Array(Me,"GetResult",dict))

End Sub
Sub GetUserPassTxt(user As String, pass As String)
Log(user & pass)
End Sub
Sub GetResult(Result As String)
Log(Result )
End Sub

'*************************************
#If OBJC

#import "Security/Security.h"


-(void) saveUsername :(NSObject*)Trget :(NSString*)user :(NSString*)SomeTxt :(NSString*)pass :(NSString*)server {

// Create dictionary of search parameters
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:(__bridge id)(kSecClassInternetPassword), kSecClass, server, kSecAttrServer, kCFBooleanTrue, kSecReturnAttributes, nil];

// Remove any old values from the keychain
OSStatus err = SecItemDelete((__bridge CFDictionaryRef) dict);

// Create dictionary of parameters to add
NSData* passwordData = [pass dataUsingEncoding:NSUTF8StringEncoding];
// dict = [NSDictionary dictionaryWithObjectsAndKeys:(__bridge id)(kSecClassInternetPassword), kSecClass, server, kSecAttrServer, passwordData, kSecValueData, user, kSecAttrAccount, nil];
dict = [NSDictionary dictionaryWithObjectsAndKeys:(__bridge id)(kSecClassInternetPassword), kSecClass, server, kSecAttrServer, passwordData, kSecValueData, user, kSecAttrAccount , SomeTxt, kSecAttrAccount, nil];

// Try to save to keychain
err = SecItemAdd((__bridge CFDictionaryRef) dict, NULL);

}



-(void) getCredentialsForServer :(NSObject*)Trget :(NSString*)GetUserPassTxt :(NSString*)server {

// Create dictionary of search parameters
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:(__bridge id)(kSecClassInternetPassword), kSecClass, server, kSecAttrServer, kCFBooleanTrue, kSecReturnAttributes, kCFBooleanTrue, kSecReturnData, nil];

// Look up server in the keychain
NSDictionary* found = nil;
CFDictionaryRef foundCF;
OSStatus err = SecItemCopyMatching((__bridge CFDictionaryRef) dict, (CFTypeRef*)&foundCF);

// Check if found
found = (__bridge NSDictionary*)(foundCF);
if (!found)
return;

// Found
NSString* user = (NSString*) [found objectForKey:(__bridge id)(kSecAttrAccount)];
// NSString* SomeTxt =(NSString*) [found objectForKey:(__bridge id)(kSecAttrAccountm)];
NSString* pass = [[NSString alloc] initWithData:[found objectForKey:(__bridge id)(kSecValueData)] encoding:NSUTF8StringEncoding];


[self.__c CallSubDelayed3:self.bi :Trget :(GetUserPassTxt) :(user) :(pass) ];
}

//----------------------------------
-(void) removeAllCredentialsForServer :(NSObject*)Trget :(NSString*)GetResult :(NSString*)server {


NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:(__bridge id)(kSecClassInternetPassword), kSecClass, server, kSecAttrServer, kCFBooleanTrue, kSecReturnAttributes, kCFBooleanTrue, kSecReturnData, nil];

OSStatus err = SecItemDelete((__bridge CFDictionaryRef) dict);
[self.__c CallSubDelayed2:self.bi :Trget :(GetResult) :(@"Removeit") ];
}


#End If
 
Upvote 0

naifnas

Active Member
Licensed User
I added Data app in list then save in keychain
B4X:
    Dim l As List
    l.Initialize
    l.Add(DataApp)  <--------------- here
    noMe.RunMethod("addToKeychain:::" , Array(Me,l ,dict))

then to array then data then save
Objective-C:
............



-(void) addToKeychain:(NSObject*)Trget  :(NSArray *)array :(NSString *)aKey {





    NSData *serializedDictionary = [NSKeyedArchiver archivedDataWithRootObject:array];

............
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…