【发布时间】:2016-10-13 11:59:02
【问题描述】:
我正在尝试使用以下命令将 pkcs#12 证书导入 OS X 钥匙串:
security import filename -k ~/Library/Keychains/login.keychain -P password -f pkcs12
在 python 中,我像这样使用subprocess:
if os.path.isfile(_file) and platform.system() == 'Darwin':
keychain = os.path.expanduser('~/Library/Keychains/login.keychain')
command_line = 'security import {} -k {} -P {} -f pkcs12'.format(_file, keychain, password)
logger.info('Importing {} into OS X KeyChain.'.format(_file))
return subprocess.call(shlex.split(command_line))
但是我收到此错误消息:
security: SecKeychainItemImport: One or more parameters passed to a function were not valid.
我什至尝试过使用shell=True,但后来我得到了security 的用法,就好像我传递了一些错误的论点一样。
Usage: security [-h] [-i] [-l] [-p prompt] [-q] [-v] [command] [opt ...]
...
...
但是,当从命令行运行它时,该命令按预期工作:
security import <filename> -k <home>/Library/Keychains/login.keychain -P DTWLDHPYNBWBJB3 -f pkcs12
1 identity imported.
1 certificate imported.
有什么想法吗?从非交互式控制台运行security 时是否有限制?
任何python库都可以实现相同的功能吗?
问候
【问题讨论】:
标签: python macos keychain pkcs#12 pyopenssl