Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible solution for error 65 (missing signature) for XCUITest @ real device #6955

Closed
mykola-mokhnach opened this issue Oct 6, 2016 · 8 comments

Comments

@mykola-mokhnach
Copy link
Collaborator

Currently many people complain they cannot automate tests for real iOS devices using XCUITest driver because of this annoying error 65. The error means, that driver source cannot be signed properly and thus cannot be installed on real device even if the same action works as expected from Xcode on the same machine.
I spent some time investigating the problem and it looks like the main source of it is Accessibility restrictions in Mac OS, because I see "No user interaction is allowed" error in Xcode logs. This happens because the private key, which the tool tries to use, is stored in the system keychain and the parent process has no access to it.
And here is possible solution:

For now all that Appium does is just execution of xcodebuild with necessary arguments using Subprocess helper class. My proposal is to change it the way that if we run not on a Simulator then a shell script will be executed instead of xcodebuild, which includes the following commands:

KEYCHAIN_PATH=<path_to_custom_keychain>
KEYCHAIN_PASSWORD=<keychain_access_password>
security -v list-keychains -s "$KEYCHAIN_PATH"
security -v unlock-keychain -p $KEYCHAIN_PASSWORD "$KEYCHAIN_PATH"
security set-keychain-settings -t 3600 -l "$KEYCHAIN_PATH"
xcodebuild <build_args>

The custom keychain should be prepared manually using the following commands:

security create-keychain -p [keychain_password] MyKeychain.keychain
security import MyPrivateKey.p12 -t agg -k MyKeychain.keychain -P [p12_Password] -A

MyPrivateKey.p12 is my private development key exported from the system keychain.

I have tested it via SSH console (because it's not reproducible if one just executes xcodebuild via local Terminal) and it worked. Please think about including that into the next Appium build.

Information source: http://stackoverflow.com/questions/16550594/jenkins-xcode-build-works-codesign-fails

@imurchie FYI

@triager triager added the Needs Triage bugs which are not yet confirmed label Oct 6, 2016
@imurchie
Copy link
Contributor

imurchie commented Oct 6, 2016

Interesting. Thanks for this! I will look into it.

@imurchie
Copy link
Contributor

imurchie commented Oct 6, 2016

First pass at this: appium/appium-xcuitest-driver#217

@imurchie imurchie removed the Needs Triage bugs which are not yet confirmed label Apr 13, 2017
@chanugithub
Copy link

chanugithub commented Nov 16, 2017

@mykola-mokhnach @imurchie I am trying to pass these capabilities (key chain path and keychainpassword) but got this error, any idea?

[XCUITest] Error: Unable to launch WebDriverAgent because of xcodebuild failure: "Command 'security -v unlock-keychain -p v /Users/Chanakya/Desktop/Certificates.p12' exited with code 49". Make sure you follow the tutorial at https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md. Try to remove the WebDriverAgentRunner application from the device if it is installed and reboot the device.
at XCUITestDriver.quitAndUninstall$ (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/driver.js:395:13)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at
at process._tickCallback (internal/process/next_tick.js:188:7)
Error: Unable to launch WebDriverAgent because of xcodebuild failure: "Command 'security -v unlock-keychain -p v /Users/Chanakya/Desktop/Certificates.p12' exited with code 49". Make sure you follow the tutorial at https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md. Try to remove the WebDriverAgentRunner application from the device if it is installed and reboot the device.
at XCUITestDriver.quitAndUninstall$ (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/driver.js:395:13)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at
at process._tickCallback (internal/process/next_tick.js:188:7)
[debug] [XCUITest] 'pgrep -nif xcodebuild.*18e20052fc6d9a7676a519e63cbbcb62fe818fb8' didn't detect any matching processes. Return code: 1
[debug] [XCUITest] Cannot find xcodebuild's process id, so unable to retrieve DerivedData folder path
[XCUITest] No WebDriverAgent derived data available, so unable to clear system files
[debug] [iOSLog] Stopping iOS log capture
[MJSONWP] Encountered internal error running command: Error: Unable to launch WebDriverAgent because of xcodebuild failure: "Command 'security -v unlock-keychain -p v /Users/Chanakya/Desktop/Certificates.p12' exited with code 49". Make sure you follow the tutorial at https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md. Try to remove the WebDriverAgentRunner application from the device if it is installed and reboot the device.
at XCUITestDriver.quitAndUninstall$ (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/driver.js:395:13)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at
at process._tickCallback (internal/process/next_tick.js:188:7)
[HTTP] <-- POST /wd/hub/session 500 17848 ms - 543

@imurchie
Copy link
Contributor

What happens if you manually run the command security -v unlock-keychain -p v /Users/Chanakya/Desktop/Certificates.p12?

@chanugithub
Copy link

chanugithub commented Nov 16, 2017

@imurchie I got the below error

unlock-keychain "-p" "v" "/Users/Chanakya/Desktop/Certificates.p12"
security: SecKeychainUnlock /Users/Chanakya/Desktop/Certificates.p12: The specified keychain is not a valid keychain file.

But i am able to build succeed in xcode with this key, and in 'keychain Access' it is displayed as valid and expires in may 2018, something fishy here. my coworker also use exact same configuration inlcuding team id and certificates etc, he was able to launch the native app but fails for me with code sign error

@chanugithub
Copy link

@imurchie @mykola-mokhnach Finally i was able to find the solution, it was actually Apple certificates in 'key chain access' which now i set to 'system default' and previously it was in 'Always trust' mode, If anyone had valid code sign dev ids but get messed up with keychains then this is the core solution

@SoundaryaBhavanam
Copy link

@mykola-mokhnach I tried this configuration, but still facing same code sign issue. Before i was able to proceed at-least on devices.
#12137

@SoundaryaBhavanam
Copy link

when i do test though terminal with the below command everything is going though
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=UDID' test

but still though jenkins not able to run more than 2 devices

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants