iOS 应用关于弥补安全优化问题

1.log输出会被中奖者截获,暴露信息,影响app得性能前端

在工程里面的pch文件加入如下代码git

// 调试状态github

#define LMLog(...) NSLog(__VA_ARGS__)安全

 

#else服务器

//  发布状态微信

#define LMLog(...)app

#endif /* PersonLife_pch */函数

#ifdef DEBUGpost

#define NSLog(...) NSLog(__VA_ARGS__)性能

#define debugMethod() NSLog(@"%s", __func__)

#else

#define NSLog(...)

#define debugMethod()

而后在工程里面写product---scheme,编辑成release

调试开发阶段编辑成debug模式 进行调试开发

 

2.登陆请求最好用post请求,把用户信息放在请求体里面更加安全

若是是H5的登陆页作登陆的,则须要后台把前端用到的参数拼在get请求后面,在H5后面MD5加密在拼在get请求的后面的参数,更加安全

3.作代码混淆

提升代码的安全性,使代码变得难读,推荐使用ZMConfuse,在github上可搜索到

使用方法:在终端 cd + ZMConfus ,把混淆的工程拷贝到当前目录下,根据需求修改.sh文件

再次打开工程,会报一些错误 ,修改pch的路径就好,在终端拖入终端,点回车便可 执行脚本命令

再次打开工程,就出现混淆的代码,对类,属性,方法,函数进行混淆,是代码彻底失去了可读性。

(注意文件名和类的命名的规则,需注意如同样找不到对应的错误,会报编译错误,形成混淆错误)

4.使用新设备时须要进行验证受权  ---如微信

不一样设备重复登陆校验问题 :第一次登陆帐号绑定设备uuid,用第二部手机时再次登陆同一帐号时,服务器首先比较uuid uuid 不一样注销当前掉当前的用户 弹出alert 用手机验证码进行验证,验证成功绑定uuid,实现微信号一对多的存储在服务端后台中实现帐号登陆  以此类推,实现不一样设备重复登陆校验。

5.https的双重验证问题  须要后台提供相关的证书进行认证便可

这里是系统验证的方法

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {

     //直接验证服务器是否被认证(serverTrust),这种方式直接忽略证书验证,信任该connect

     SecTrustRef serverTrust = [[challenge protectionSpace] serverTrust];

     return [[challenge sender] useCredential: [NSURLCredential credentialForTrust: serverTrust]

     forAuthenticationChallenge: challenge];

    

    if ([[[challenge protectionSpace] authenticationMethod] isEqualToString: NSURLAuthenticationMethodServerTrust]) {

        do

        {

            SecTrustRef serverTrust = [[challenge protectionSpace] serverTrust];

            NSCAssert(serverTrust != nil, @"serverTrust is nil");

            if(nil == serverTrust)

                break; /* failed */

            NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"证书名称" ofType:@"cer"];//自签名证书

            NSData* caCert = [NSData dataWithContentsOfFile:cerPath];

            

            NSString *cerPath2 = [[NSBundle mainBundle] pathForResource:@"证书名称" ofType:@"cer"];//SSL证书

            NSData * caCert2 = [NSData dataWithContentsOfFile:cerPath2];

            

            NSCAssert(caCert != nil, @"caCert is nil");

            if(nil == caCert)

                break; /* failed */

            

            NSCAssert(caCert2 != nil, @"caCert2 is nil");

            if (nil == caCert2) {

                break;

            }

            

            SecCertificateRef caRef = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)caCert);

            NSCAssert(caRef != nil, @"caRef is nil");

            if(nil == caRef)

                break; /* failed */

            

            SecCertificateRef caRef2 = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)caCert2);

            NSCAssert(caRef2 != nil, @"caRef2 is nil");

            if(nil == caRef2)

                break; /* failed */

            

            NSArray *caArray = @[(__bridge id)(caRef),(__bridge id)(caRef2)];

            

            NSCAssert(caArray != nil, @"caArray is nil");

            if(nil == caArray)

                break; /* failed */

            

            OSStatus status = SecTrustSetAnchorCertificates(serverTrust, (__bridge CFArrayRef)caArray);

            NSCAssert(errSecSuccess == status, @"SecTrustSetAnchorCertificates failed");

            if(!(errSecSuccess == status))

                break; /* failed */

            

            SecTrustResultType result = -1;

            status = SecTrustEvaluate(serverTrust, &result);

            if(!(errSecSuccess == status))

                break; /* failed */

            NSLog(@"stutas:%d",(int)status);

            NSLog(@"Result: %d", result);

            

            BOOL allowConnect = (result == kSecTrustResultUnspecified) || (result == kSecTrustResultProceed);

            if (allowConnect) {

                NSLog(@"success");

            }else {

                NSLog(@"error");

            }

            if(! allowConnect)

            {

                break; /* failed */

            }

            

#if 0

            /* Treat kSecTrustResultConfirm and kSecTrustResultRecoverableTrustFailure as success */

            /*   since the user will likely tap-through to see the dancing bunnies */

            if(result == kSecTrustResultDeny || result == kSecTrustResultFatalTrustFailure || result == kSecTrustResultOtherError)

                break; /* failed to trust cert (good in this case) */

#endif

            

            // The only good exit point

            NSLog(@"信任该证书");

            return [[challenge sender] useCredential: [NSURLCredential credentialForTrust: serverTrust]

                          forAuthenticationChallenge: challenge];

            

        }

        while(0);

    }

    

    // Bad dog

    return [[challenge sender] cancelAuthenticationChallenge: challenge];

    

}

 

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {

    

    return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];

}

 //目前APP检测遇到这些问题,已解决 但愿有所能对你帮助   共勉

相关文章
相关标签/搜索