【发布时间】:2018-08-23 16:47:27
【问题描述】:
还有其他几个问题讨论了从 LaunchAgents 访问钥匙串。
其中一个关键是here,其中joensson 提到您需要在应用plist 中设置<SessionCreate>。
我已经这样做了,现在我的应用程序列表看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.ionic.python.ionic-fs-watcher.startup</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/IonicFSWatcher.app/Contents/MacOS/ionic-fs-watcher</string>
<string>--debug</string>
<string>/Users/timothy/ionicprotected</string>
<string>--scan</string>
</array>
<key>UserName</key>
<string>timothy</string>
<key>SessionCreate</key>
<true />
</dict>
</plist>
该应用是一个python应用,使用pyinstaller创建,使用pkgbuild打包,安装via the command line。
从命令行运行时应用程序运行良好。如果应用程序第一次运行,用户会收到允许访问钥匙串的提示,应用程序会从那里继续。
但是,当它以LaunchAgent 启动时,我在尝试访问钥匙串时得到返回码 9216。这是我用来测试的确切命令序列:
# Window 1
sudo launchctl unload -w ~/Library/LaunchAgents/com.ionic.python.ionic-fs-watcher.startup.plist
sudo launchctl load -w ~/Library/LaunchAgents/com.ionic.python.ionic-fs-watcher.startup.plist
sudo launchctl debug system/com.ionic.python.ionic-fs-watcher.startup --stdout --stderr
# Window 2
sudo launchctl kickstart -k -p system/com.ionic.python.ionic-fs-watcher.startup
在 python 脚本中,我一直在通过运行一些子命令并捕获输出进行调试。
# OK
status, output = commands.getstatusoutput("security list-keychains")
logger.error("Keychain list :%s (retcode = %s)" % (
output, status
))
# OK
status, output = commands.getstatusoutput("security find-generic-password -a 'Ionic Security' ")
logger.error("Keychain list item :%s (retcode = %s)" % (
output, status
))
# Fails, with error code: 9216
# Prompts immediately when running from command line
status, output = commands.getstatusoutput("security find-generic-password -a 'Ionic Security' -g")
logger.error("Keychain access :%s (retcode = %s)" % (
output, status
))
该部分代码的输出如下所示:
# Correctly shows both keychains
ERROR:root:Keychain list : "/Users/timothy/Library/Keychains/login.keychain"
"/Library/Keychains/System.keychain" (retcode = 0)
# Correctly lists information about keychain item
ERROR:root:Keychain list item :keychain: "/Users/timothy/Library/Keychains/login.keychain"
<redacted>
# Fail
ERROR:root:Keychain access : (retcode = 9216)
这些相同的命令在命令行中可以正常工作,最后一个 (-g) 会提示允许访问钥匙串。
我还尝试在KeyChain Access 应用程序中打开com.ionicsecurity.client.sdk 的条目,并设置“允许所有应用程序访问此项目”单选按钮。之后,从 cli 中获取值不再导致提示 但应用返回相同的错误代码。
我搜索了有关错误代码 9216 的信息,但没有结果。通过security errors 实用程序运行代码只会给出
$ security error 9216
Error: 0x00002400 9216 unknown error 9216=2400
任何有关如何在作为 LaunchAgent 运行时获得对钥匙串的应用程序访问权限的帮助将不胜感激!
【问题讨论】:
-
可能相关:这是一个用户LaunchAgent,但是plist文件有
root:wheel权限。我想弄清楚如何在这里解决这个问题:stackoverflow.com/questions/49290174/… -
这是 100% 相关的。当我试图弄清楚如何在没有
sudo的情况下启动代理时,这让我走上了正确的道路。
标签: macos keychain launchd launchdagent ionicsecurity