iOS 應用關於彌補安全最佳化問題

來源:互聯網
上載者:User

標籤:輸出   工程   end   裝置   spec   nil   目錄   tps   .sh   

1.log輸出會被中獎者截獲,暴露資訊,影響app得效能

在工程裡面的pch檔案加入以下代碼

// 調試狀態

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

 

#else

//  發布狀態

#define LMLog(...)

#endif /* PersonLife_pch */

#ifdef DEBUG

#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檢測遇到這些問題,已解決 希望有所能對你協助   共勉

 

iOS 應用關於彌補安全最佳化問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.