🐔

git の signingkey にフィンガープリントを指定する時は末尾に感嘆符が必要

に公開
1

Discussion

conjLobconjLob

以下 man ページ gpg(1) の「HOW TO SPECIFY A USER ID」項から引用します。

By key Id.
This format is deduced from the length of the string and its content or 0x prefix. The key Id of an X.509 certificate are the low 64 bits of its SHA-1 fingerprint. The use of key Ids is just a shortcut, for all automated processing the fingerprint should be used.

When using gpg an exclamation mark (!) may be appended to force using the specified primary or secondary key and not to try and calculate which primary or secondary key to use.

The last four lines of the example give the key ID in their long form as internally used by the OpenPGP protocol. You can see the long key ID using the option --with-colons.

234567C4
0F34E556E
01347A56A
0xAB123456

234AABBCC34567C4
0F323456784E56EAB
01AB3FED1347A5612
0x234AABBCC34567C4

By fingerprint.
This format is deduced from the length of the string and its content or the 0x prefix. Note, that only the 20 byte version fingerprint is available with gpgsm (i.e. the SHA-1 hash of the certificate).

When using gpg an exclamation mark (!) may be appended to force using the specified primary or secondary key and not to try and calculate which primary or secondary key to use.

The best way to specify a key Id is by using the fingerprint. This avoids any ambiguities in case that there are duplicated key IDs.

1234343434343434C434343434343434
123434343434343C3434343434343734349A3434
0E12343434343434343434EAB3484343434343434
0xE12343434343434343434EAB3484343434343434

「This format is deduced from the length of the string and its content or the 0x prefix.」とあるように、指定されたパラメータがキー ID またはフィンガープリントであるかは、特定の長さの16進数であるか、または明示的にプレフィックス 0x が指定されているかで判定されます。そのため、サフィックス ! は必須ではないかと思われます。

実際、ソースコードを見てみると16進数の長さで条件分岐していました。
0x もほかの & などのプレフィックスとは違い、必須ではないようです。
https://git.gnupg.org/cgi-bin/gitweb.cgi?p=gnupg.git;a=blob;f=common/userids.c;h=00f26b720e04e9a02ba624281ae844ba95bfaa00;hb=refs/heads/STABLE-BRANCH-2-2

また、! を付けない場合は、セカンダリキーを指定してもそれのプライマリキーに紐づく署名可能なキーが自動的に選択されるようです。したがって、単にプライマリキーとセカンダリキーのセット全体を指定したい場合はプライマリキーのフィンガープリントを ! 無しで指定し、特定のセカンダリキーの使用を強制したい場合は ! を付けるのが良さそうです。