iOS plus

利用终端远程导入p12证书

2020-02-27  本文已影响0人  收纳箱

1.常规UI操作

Xcode利用codesign进行签名的时候,可能需要用户进行授权。这时会有一个弹窗,让用户输入Mac开机密码并选择一次/总是可以访问

codesign的keychain访问权限

1.1 问题

2. 终端操作

help                                 Show all commands, or show usage for a command.
list-keychains                       Display or manipulate the keychain search list.
list-smartcards                      Display available smartcards.
default-keychain                     Display or set the default keychain.
login-keychain                       Display or set the login keychain.
create-keychain                      Create keychains and add them to the search list.
delete-keychain                      Delete keychains and remove them from the search list.
lock-keychain                        Lock the specified keychain.
unlock-keychain                      Unlock the specified keychain.
set-keychain-settings                Set settings for a keychain.
set-keychain-password                Set password for a keychain.
show-keychain-info                   Show the settings for keychain.
dump-keychain                        Dump the contents of one or more keychains.
create-keypair                       Create an asymmetric key pair.
add-generic-password                 Add a generic password item.
add-internet-password                Add an internet password item.
add-certificates                     Add certificates to a keychain.
find-generic-password                Find a generic password item.
delete-generic-password              Delete a generic password item.
set-generic-password-partition-list  Set the partition list of a generic password item.
find-internet-password               Find an internet password item.
delete-internet-password             Delete an internet password item.
set-internet-password-partition-list Set the partition list of a internet password item.
find-key                             Find keys in the keychain
set-key-partition-list               Set the partition list of a key.
find-certificate                     Find a certificate item.
find-identity                        Find an identity (certificate + private key).
delete-certificate                   Delete a certificate from a keychain.
delete-identity                      Delete an identity (certificate + private key) from a keychain.
set-identity-preference              Set the preferred identity to use for a service.
get-identity-preference              Get the preferred identity to use for a service.
create-db                            Create a db using the DL.
export                               Export items from a keychain.
import                               Import items into a keychain.
export-smartcard                     Export items from a smartcard.
cms                                  Encode or decode CMS messages.
install-mds                          Install (or re-install) the MDS database.
add-trusted-cert                     Add trusted certificate(s).
remove-trusted-cert                  Remove trusted certificate(s).
dump-trust-settings                  Display contents of trust settings.
user-trust-settings-enable           Display or manipulate user-level trust settings.
trust-settings-export                Export trust settings.
trust-settings-import                Import trust settings.
verify-cert                          Verify certificate(s).
authorize                            Perform authorization operations.
authorizationdb                      Make changes to the authorization policy database.
execute-with-privileges              Execute tool with privileges.
leaks                                Run /usr/bin/leaks on this process.
error                                Display a descriptive message for the given error code(s).
create-filevaultmaster-keychain      Create a keychain containing a key pair for FileVault recovery use.
smartcards                           Enable, disable or list disabled smartcard tokens.
translocate-create                   Create a translocation point for the provided path
translocate-policy-check             Check whether a path would be translocated.
translocate-status-check             Check whether a path is translocated.
translocate-original-path            Find the original path for a translocated path.
requirement-evaluate                 Evaluate a requirement against a cert chain.

2.1 方式①

2.2 方式②

security import
Usage: import inputfile [-k keychain] [-t type] [-f format] [-w] [-P passphrase] [options...]
    -k  Target keychain to import into
    -t  Type = pub|priv|session|cert|agg
    -f  Format = openssl|openssh1|openssh2|bsafe|raw|pkcs7|pkcs8|pkcs12|netscape|pemseq
    -w  Specify that private keys are wrapped and must be unwrapped on import
    -x  Specify that private keys are non-extractable after being imported
    -P  Specify wrapping passphrase immediately (default is secure passphrase via GUI)
    -a  Specify name and value of extended attribute (can be used multiple times)
    -A  Allow any application to access the imported key without warning (insecure, not recommended!)
    -T  Specify an application which may access the imported key (multiple -T options are allowed)
Use of the -P option is insecure

    Import items into a keychain.

我们发现security import方法中可以提供完全-A和部分应用-T的访问权限。

//解锁钥匙串
security unlock-keychain -p pwd ~/Library/Keychains/login.keychain-db
//导入证书
security import $p12_file_path -k ~/Library/Keychains/login.keychain-db -P $pwd -T /usr/bin/codesign
security set-key-partition-list -S apple-tool:,apple: -s -k $pwd ~/Library/Keychains/login.keychain-db

解释一下其中几个参数:

所以以上的命令作用为:给 login.keychain中用于codesign的 private key,写入苹果产品的权限。

注意:set-key-partition-lis 对 key 的操作是重写,不是追加。

set-key-partition-list
Usage: set-key-partition-list [options...] [keychain]
    -a  Match "application label" string
    -c  Match "creator" (four-character code)
    -d  Match keys that can decrypt
    -D  Match "description" string
    -e  Match keys that can encrypt
    -j  Match "comment" string
    -l  Match "label" string
    -r  Match keys that can derive
    -s  Match keys that can sign
    -t  Type of key to find: one of "symmetric", "public", or "private"
    -u  Match keys that can unwrap
    -v  Match keys that can verify
    -w  Match keys that can wrap
    -S  Comma-separated list of allowed partition IDs
    -k  password for keychain (required)
    If no keychains are specified to search, the default search list is used.
    Set the partition list of a key.
上一篇下一篇

猜你喜欢

热点阅读