我使用protobuf编译器编译了我的.proto文件,并收集了一些java文件。我为.proto文件中的每个项目收集了一个proto.java文件和一个.java文件,包括消息类型和每个rpc调用,例如: publicKeyRequest.java和Quote.java作为rpc和请求参数类型。
这是否需要所有文件,因为我似乎无法从服务器获得任何简单的响应。
我想生成一个对PublicKeyRequest rpc调用的请求,我生成了请求对象,但不知道如何通过通道实际发送它
这是完整的.proto文件:
syntax = "proto3";
option java_multiple_files = true;
option java_package = "io.grpc.decryptiondevice";
option java_outer_classname = "DecryptionDeviceProto";
package decryptiondevice;
service DecryptionDevice {
// Decryption Request RPC
//
// Request contains ciphertext and proof
// Returns the plaintext record
rpc DecryptRecord(DecryptionRequest) returns (Record) {}
// Get Signed Root Tree Hash RPC
//
// Caller provides a nonce
// Returns a signed RTH and nonce
rpc GetRootTreeHash(RootTreeHashRequest) returns (RootTreeHash) {}
// Get Public key RPC
//
// Returns a Remote attestation report containing the public key as user data
rpc GetPublicKey(PublicKeyRequest) returns (Quote) {}
}
// Decryption Request
// - Byte array containing ciphertext
// - Proofs represented as JSON trees
message DecryptionRequest {
bytes ciphertext = 1;
string proofOfPresence = 2;
string proofOfExtension = 3;
}
// A plaintext record
message Record {
bytes plaintext = 1;
}
// RTH request contains
// - A random nonce
message RootTreeHashRequest {
bytes nonce = 1;
}
// Root Tree Hash
// Random nonce used as message ID
// Signature over rth and nonce
message RootTreeHash {
bytes rth = 1;
bytes nonce = 2;
bytes sig = 3;
}
// Public key request message
message PublicKeyRequest {
bytes nonce = 1;
}
// Attestation Quote, containing the public key
message Quote {
string quote = 1; //some format.. to be defined later
//PEM formatted key
bytes RSA_EncryptionKey = 2;
bytes RSA_VerificationKey = 3;
}
这是我试图在客户端运行的代码:
public static void main(String[] args) {
DeviceClient client = new DeviceClient("localhost", 50051);
MannagedChanel channel = ManagedChannelBuilder.forAddress("localhost", 50051).usePlaintext(true);
ByteString nonce = ByteString.copyFromUtf8("someRandomString");
PublicKeyRequest keyRequest = PublicKeyRequest.newBuilder().setNonce(nonce).build();
//here I want to send this to the server
ByteString response = DecryptionDeviceProto.getKey(keyRequest, channel);//this line is not even close to being valid, but this is the sort thing I wish to achieve
Sys.out.println(response);
}
如果这是非常错误的道歉,我是gRPC的新手。 关于这个系统的几点:
任何帮助都会得到满足。感谢
答案 0 :(得分:1)
需要生成两组文件:Java Protobuf和Java gRPC。据我所知,对于除Go之外的所有语言,这些是两个单独的生成步骤(可以组合成一个protoc
调用,但它们在概念上是分开的。)
您似乎正在生成Java Protobuf代码,而不是Java gRPC代码。您需要使用protoc-gen-grpc-java
插件protoc
。如果您使用的是Maven或Gradle,请阅读grpc-java's README。如果您手动运行protoc,则可以下载pre-built binary from Maven Central并查看an answer to a similar question。