LoginSignup
11
16

More than 5 years have passed since last update.

マイナンバーカードでSSHするまで

Last updated at Posted at 2017-05-20

はじめに

これはマイナンバーカードでSSHするまでの備忘録である.
大元はhamanoさんのこの記事を参考にしている -> マイナンバーカードでSSHする
自分がハマったところで他の人がはまらないように...
2017年 6/17に追記しました.hamanoさんご指摘ありがとうございます!

環境

ツール バージョン
OS OS X 10.12.5
カードリーダー ACR1251CL-NTTCom -

OpenSCカードドライバを用意する

OpenSCはスマートカード用のツールやライブラリーを提供するプロジェクトだ.
今回はフォークされたJPKIブランチを利用した.(確認してないだけで本家にマージされている模様)

$ git clone https://github.com/jpki/OpenSC.git
$ ./bootstrap
$ ./configure
$ make
$ make install

./bootstrap

$ ./bootstrapを実行したところ下記のエラーが出た.

$ ./bootstrap                                                                                                                                                                            [jpki]
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal -I m4 --output=aclocal.m4t
Can't exec "aclocal": No such file or directory at /usr/local/Cellar/autoconf/2.69/share/autoconf/Autom4te/FileUtils.pm line 326.
autoreconf: failed to run aclocal: No such file or directory

ググるとCan't exec "aclocal": No such file or directoryの対処法

"aclocal"というのは、"automake"パッケージに含まれているそうです。

とのことだったのでこれを入れる
$ brew install automake

再度実行するが, またエラー.

./bootstrap                                                                                                                                                                            [jpki]
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force -I m4
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/local/Cellar/autoconf/2.69/bin/autoconf --force
configure.ac:287: error: possibly undefined macro: AC_LIBTOOL_WIN32_DLL
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
configure.ac:288: error: possibly undefined macro: AC_LIBTOOL_RC
configure.ac:289: error: possibly undefined macro: AC_PROG_LIBTOOL
autoreconf: /usr/local/Cellar/autoconf/2.69/bin/autoconf failed with exit status: 1

これまたググるとundefined macro: AC_PROG_LIBTOOL

I guess (g)libtool is missing. Looks like you use brew install libtool maybe brew install libtool fix the problem.

とのことだったので入れる.
brew install libtool
すると, 成功🙆‍♂️

./bootstrap                                                                                                                                                                            [jpki]
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force -I m4
autoreconf: configure.ac: tracing
autoreconf: running: glibtoolize --copy --force
glibtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, '.'.
glibtoolize: copying file './ltmain.sh'
glibtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
glibtoolize: copying file 'm4/libtool.m4'
glibtoolize: copying file 'm4/ltoptions.m4'
glibtoolize: copying file 'm4/ltsugar.m4'
glibtoolize: copying file 'm4/ltversion.m4'
glibtoolize: copying file 'm4/lt~obsolete.m4'
glibtoolize: Remember to add 'LT_INIT' to configure.ac.
autoreconf: running: /usr/local/Cellar/autoconf/2.69/bin/autoconf --force
autoreconf: running: /usr/local/Cellar/autoconf/2.69/bin/autoheader --force
autoreconf: running: automake --add-missing --copy --force-missing
configure.ac:58: installing './compile'
configure.ac:57: installing './config.guess'
configure.ac:57: installing './config.sub'
configure.ac:28: installing './install-sh'
configure.ac:28: installing './missing'
src/common/Makefile.am: installing './depcomp'
autoreconf: Leaving directory `.'

./configure も実行し成功.
あとはmakeするだけ.

$ make
$ make install

SSHする(失敗)

認証用の公開鍵をOpenSCを用いて抽出する. そしてauthorized_keysに突っ込む.
hamanoさんのポストにあった--read-ssh-keyというオプションはなくなっていたので--read-public-keyを指定.

hamanoさんご本人から指摘をいただき, 修正したら--read-ssh-keyの読み込みに成功しました!
opensslの環境が必要だとのこと. 本稿では下記との整合性を保つため--read-public-keyのまま進めます.

$ pkcs15-tool --read-public-key 1 > id_rsa.pub
私はわかりやすいようにmynumber.pubにリネームしたので
$ pkcs15-tool --read-public-key 1 > mynumber2.pub

だがしかしここで詰まる
意気揚々と指定された形で下のようにsshしようとするが、鍵を読んでくれない....

$ ssh -I /usr/local/lib/opensc-pkcs11.so hostname
Enter passphrase for key '/Users/shuya/.ssh/id_rsa':

困ったと思いググるとこんなブログポストが
YubiKeyのPIVカードでSSHする

SSHする(成功)

上記のポストでは公開鍵をssh-keygen越しに抽出しているのでこれを試す.
$ ssh-keygen -D /usr/local/lib/opensc-pkcs11.so > mynumber.pub
恐る恐る, これでsshしてみると...

$ ssh -I /usr/local/lib/opensc-pkcs11.so  HOSTNAME
Enter PIN for 'User Authentication PIN (JPKI)': 


Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-71-generic x86_64)

Last login: Sat May 20 19:49:16 2017 from xxxxxxxx
ccx02:~> 

成功 :)

参考

Can't exec "aclocal": No such file or directoryの対処法
undefined macro: AC_PROG_LIBTOOL
YubiKeyのPIVカードでSSHする

11
16
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
16