絶望的にドキュメントのない net/https でクライアント証明書付きSSL接続してみた。
ahttps = Net::HTTP.new('mimori.org',443)
ahttps.use_ssl = true
ahttps.ca_file = '/etc/ssl/certs/ca-bundle.crt'
ahttps.key = OpenSSL::PKey::RSA.new(File.read('/home/h/certs/tako.key'))
ahttps.cert = OpenSSL::X509::Certificate.new(File.read('/home/h/certs/tako.crt'))
ahttps.verify_mode = OpenSSL::SSL::VERIFY_PEER
ahttps.verify_depth = 5
ahttps.start { |w|
params = {}
params['old'] = "#{year}#{month}#{day}"
params['year'] = year.to_i
params['month'] = month.to_i # strip 0 on the head
params['day'] = day.to_i # strip 0 on the head
params['title'] = CGI::escape(title)
params['body'] = CGI::escape(NKF::nkf( '-m0 -Xed', body ))
params['replace'] = 'true'
paramarr = []
params.each { |key, value| paramarr.push("#{key}=#{value}") }
response = w.post('/~h/tdiary/update.rb', paramarr.join(";"))
puts "replace: #{params['old']}\n"
puts response.body
}
ドキュメントには key_file や cert_file にファイル名を指定できるようなことが書いてあったが、 ソース見たら定義してなかったよ。
改めてOpenSSL関係のドキュメントを探すもやっぱり全然なく、サンプルから該当部分を探した。
証明書オブジェクトやら秘密鍵オブジェクトを作るには、
OpenSSL::X509::Certificate.newやOpenSSL::PKey::RSA.newメソッドにPEM文字列を突っ込めばいいんじゃん、という結果だった。
WindowsのTortoiseSVNで日本語ファイル名でコミットしたところ、他のWindows上でも問題なく展開できたし、ViewCVSでも閲覧できる。
が、MacOSX上だと svn: Can't recode string というメッセージとともにコケる。
ちょっと回避方法は思いつかない。