2017-10-25 11 views
0

iOS 앱이 유효한 인증서가있는 백엔드 서버와 통신합니다. 개발하는 동안 내 IOS 응용 프로그램은 자체 서명 된 루트 인증서로 서명 된 인증서가있는 내부 테스트 서버와 통신하도록 구성됩니다.테스트를 위해 iOS 시뮬레이터에 맞춤 CA 루트 인증서를 자동으로 설치할 수 있습니까?

내가 여기에 배치하지 지침을 사용하여 내 자체 서명 루트에 의해 서명 연결을 신뢰하는 내 응용 프로그램을 구성 할 수 있습니다 아이폰 OS 11 이전 : 응용 프로그램을 작성하지 않고 ATS를 우회하는

https://developer.apple.com/library/content/technotes/tn2232/_index.html#//apple_ref/doc/uid/DTS40012884-CH1-SECCUSTOMCERT 그러나 아이폰 OS 11은 더 이상 가능 info.plist에서의 ATS 예외. 이 스레드는 Apple의 몇 가지 설명을 포함합니다 : https://forums.developer.apple.com/thread/89694

그럼 iOS에서 어떻게 모든 종류의 자동화 된 방식으로 모든 iOS 시뮬레이터에 내 사용자 지정 CA 루트를 설치할 수 있습니까?

답변

2

iOS 11이 다중 앱 UI 테스트를 지원하기 때문에 iOS 시스템이 Safari 및 설정 앱을 사용하여 내 맞춤 CA 루트를 설치하도록 UI 테스트를 만들었습니다. UI 테스트 소스는 다음과 같습니다.

import XCTest 

class InstallRootCerts: XCTestCase { 

    override func setUp() { 
     super.setUp() 
     continueAfterFailure = false 
     XCUIApplication().launch() 
    } 

    override func tearDown() { 
     super.tearDown() 
    } 

    func testInstallTestingRootCertOnDevice() { 

     // Set test time env var ROOT_CA to point to your custom CA's .cer file. 
     let cert = ProcessInfo.processInfo.environment["ROOT_CA"] 
     // Set test time env var ROOT_CA_NAME to contain the name of your CA. 
     let caName = ProcessInfo.processInfo.environment["ROOT_CA_NAME"] 

     let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari") 

     let settings = XCUIApplication(bundleIdentifier: "com.apple.Preferences") 

     safari.activate() 

     XCTAssertNotNil(cert) 

     let certUrl = "file://\(cert!)" 

     if safari.otherElements["URL"].exists { 
      safari.otherElements["URL"].tap() 
     } 

     let addressBar = safari.textFields["URL"] 

     addressBar.typeText(certUrl) 

     safari.buttons["Go"].tap() 

     safari.buttons["Allow"].tap() 

     XCTAssertTrue(settings.wait(for: .runningForeground, timeout: 30)) 

     if !settings.staticTexts["Verified"].exists { 
      settings.buttons["Install"].tap() 
      settings.buttons["Install"].tap() 
      settings.sheets.buttons["Install"].tap() 
     } 

     // Now trust the root certificate 
     settings.buttons["Cancel"].tap() 
     XCTAssertTrue(safari.wait(for: .runningForeground, timeout: 120)) 
     settings.activate() 
     XCTAssertTrue(settings.wait(for: .runningForeground, timeout: 120)) 

     settings.buttons["General"].tap() 
     settings.cells["About"].tap() 
     settings.cells["Certificate Trust Settings"].tap() 
     let cell = settings.cells.containing(.staticText, identifier: caName) 
     let toggle = cell.switches.firstMatch 
     if toggle.value as? String != "1" { 
      toggle.tap() 
      settings.buttons["Continue"].tap() 
     } 

    } 

} 

이 테스트 케이스는 iOS 11.0을 실행하는 시뮬레이터에서만 작동합니다. .cer 파일을 웹 서버에 놓고 http를 통해 열면 실제 장치로 작업 할 수 있다고 생각합니다.

이 테스트 케이스는 Xcode 서버의 Bot으로 실행하거나 모든 시뮬레이터에서 로컬로 실행하여 설정할 수 있습니다. 이것은 내가 아는 해킹이다.