2017-06-19 21 views
2

最近、私はrubygem grpcバージョン1.3.2を臨床試験として使用し、golangから構築されたgrpcサーバーに接続しようとしていました。私はGRPC.IOのドキュメントを調べ、それを自分のコードで使用しました。その文書は、特に言うしかしRubyのgrpc(v1.3.2)gem golangで完全に構築されたgrpcサーバーのSSL/TLS接続の問題

irb(main):017:0> GRPC::Core::Credentials.new(File.read(CA_FILE_PATH)) 
NameError: uninitialized constant GRPC::Core::Credentials 
     from (irb):17 
     from /usr/local/share/gems/gems/railties-4.2.1/lib/rails/commands/console.rb:110:in `start' 
     from /usr/local/share/gems/gems/railties-4.2.1/lib/rails/commands/console.rb:9:in `start' 
     from /usr/local/share/gems/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:68:in `console' 
     from /usr/local/share/gems/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!' 
     from /usr/local/share/gems/gems/railties-4.2.1/lib/rails/commands.rb:17:in `<top (required)>' 
     from bin/rails:4:in `require' 
     from bin/rails:4:in `<main>' 

creds = GRPC::Core::Credentials.new(load_certs) # load_certs typically loads a CA roots file 
stub = Helloworld::Greeter::Stub.new('myservice.example.com', creds) 

それから私は、ChannelCredentialsとはどちらかChannelCredentialsオブジェクトまたはシンボル(例えばことになっているcredsを渡って来た:this_channel_is_insecure )。それで、私は試してみました。

grpc gemのソースコード自体から次の機能を実行しました。この機能は、本命をロードするためのRSpecのテストケースで呼び出されました:

def load_certs 
     data_dir = "#{Rails.root}/certs" 
     files = ['ca.pem', 'server.key', 'server.pem'] 
     files.map { |f| File.open(File.join(data_dir, f)).read } 
end 

は、それから私は、私も試した、とそれを

channel_creds = GRPC::Core::ChannelCredentials.new(load_certs) 
stub = Helloworld::Greeter::Stub.new('myservice.example.com', channel_creds) 

しかし

E0619 09:59:10.410575570 14208 ssl_transport_security.c:601] Could not load any root certificate. 
E0619 09:59:10.410604954 14208 ssl_transport_security.c:1315] Cannot load server root certificates. 
E0619 09:59:10.410622519 14208 security_connector.c:837] Handshaker factory creation failed with TSI_INVALID_ARGUMENT. 

で失敗しまし上記を試して与えました:

channel_creds = GRPC::Core::ChannelCredentials.new(File.read(CA_FILE_PATH)) 
stub = Helloworld::Greeter::Stub.new('myservice.example.com', creds) 

B UT私が得たすべてのログまたはRPCサーバーからのエラーでした:

2017/06/16 10:52:34 transport: http2Server.HandleStreams failed to receive the preface from client: EOF 
2017/06/16 10:53:35 transport: http2Server.HandleStreams failed to receive the preface from client: EOF 
2017/06/16 10:53:59 transport: http2Server.HandleStreams failed to receive the preface from client: EOF 
2017/06/16 10:55:06 transport: http2Server.HandleStreams failed to receive the preface from client: EOF 

誰もが正常にSSL/TLSを使用してこのRubyのクライアントGolangサーバの組み合わせが有効にしようとしていますか?

答えて

0

credsをはいずれかChannelCredentialsが

はいクライアント・スタブ・コンストラクタ(credsを引数)の第2引数は、GRPC::Core::ChannelCredentialsオブジェクトまたは特異::this_channel_is_insecureいずれかでなければならないオブジェクトまたはシンボルであるとしますシンボル(後者が渡された場合、安全でない接続が使用されます)。

私はそれだけでクライアントの秘密鍵と証明書チェーンでチャンネルの資格を構築するために理にかなっているので

def load_certs 
    data_dir = "#{Rails.root}/certs" 
    files = ['ca.pem', 'server.key', 'server.pem'] 
    files.map { |f| File.open(File.join(data_dir, f)).read } 
end 

を使用してテストは、実際に、誤解を招くかもしれないことに注意したい(特定のテストは、私は信じていることキーと証明書チェーンは使用しません)。GRPC::Core::ChannelCredentialsコンストラクタで

使用することができる3つの形式が(それらの上に行くhttps://github.com/grpc/grpc/blob/master/src/ruby/ext/grpc/rb_channel_credentials.c#L128でコンストラクタコード上のコメントがあります)、ですが、オプションは次のとおりです。

  • Credentials.new()

  • Credentials.new(pem_root_certs)

  • すべての場合において
  • Credentials.new(pem_root_certs, pem_private_key, pem_cert_chain)

、ルート・ファイル、秘密鍵、および証明書チェーンのパラメータは、PEMエンコード文字列です。

引数が渡されない場合(Credentials.new()が使用される)、サーバルート証明書はthis header comment(サーバルート証明書パラメータがnullの場合の動作の説明を参照)に記載されているようになります。最後のコンストラクタは、クライアントが秘密鍵と証明書チェーンを使用する場合にのみ必要です。

0

これは確認できます。

channel_creds = GRPC::Core::ChannelCredentials.new(File.read("/home/user/.lnd/tls.cert")) 
stub = Lnrpc::Lightning::Stub.new("127.0.0.1:10009", channel_creds) 
obj = Lnrpc::GetInfoRequest.new 
pp stub.get_info(obj) 
関連する問題