github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/src/tao/tao_rpc.h (about)

     1  //  File: tao_rpc.h
     2  //  Author: Tom Roeder <tmroeder@google.com>
     3  //
     4  //  Description: RPC client stub for channel-based Tao implementations.
     5  //
     6  //  Copyright (c) 2013, Google Inc.  All rights reserved.
     7  //
     8  // Licensed under the Apache License, Version 2.0 (the "License");
     9  // you may not use this file except in compliance with the License.
    10  // You may obtain a copy of the License at
    11  //
    12  //     http://www.apache.org/licenses/LICENSE-2.0
    13  //
    14  // Unless required by applicable law or agreed to in writing, software
    15  // distributed under the License is distributed on an "AS IS" BASIS,
    16  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    17  // See the License for the specific language governing permissions and
    18  // limitations under the License.
    19  #ifndef TAO_TAO_RPC_H_
    20  #define TAO_TAO_RPC_H_
    21  
    22  #include <string>
    23  
    24  #include "tao/message_channel.h"
    25  #include "tao/tao.h"
    26  #include "tao/tao_rpc.pb.h"
    27  
    28  namespace tao {
    29  using std::string;
    30  
    31  /// A class that sends Tao requests and responses over a channel between Tao
    32  /// hosts and Tao hosted programs.
    33  class TaoRPC : public Tao {
    34   public:
    35    /// Construct a TaoRPC.
    36    /// @param channel The channel over which to send and receive messages.
    37    /// Ownership is taken.
    38    explicit TaoRPC(MessageChannel *channel) : channel_(channel) {}
    39  
    40    void Close() { channel_->Close(); }
    41  
    42    bool SerializeToString(string *params) const;
    43  
    44    static TaoRPC *DeserializeFromString(const string &params);
    45  
    46    /// Tao implementation.
    47    /// @{
    48    bool GetTaoName(string *name);
    49    bool ExtendTaoName(const string &subprin);
    50    bool GetRandomBytes(size_t size, string *bytes);
    51    bool GetSharedSecret(size_t size, const string &policy,
    52                                 string *bytes);
    53    bool Attest(const string &message, string *attestation);
    54    bool Seal(const string &data, const string &policy, string *sealed);
    55    bool Unseal(const string &sealed, string *data, string *policy);
    56  
    57    bool InitCounter(const string& label, int64_t& c);
    58    bool GetCounter(const string &label, int64_t* c);
    59    bool RollbackProtectedSeal(const string& label, const string &data, const string &policy, string *sealed);
    60    bool RollbackProtectedUnseal(const string &sealed, string *data, string *policy);
    61  
    62    string GetRecentErrorMessage() const { return failure_msg_; }
    63    string ResetRecentErrorMessage() {
    64      string msg = failure_msg_;
    65      failure_msg_ = "";
    66      return msg;
    67    }
    68    /// @}
    69  
    70   protected:
    71    /// The channel over which to send and receive messages.
    72    unique_ptr<MessageChannel> channel_;
    73  
    74    /// Most recent RPC failure message, if any.
    75    string failure_msg_;
    76  
    77    /// Most recent RPC sequence number.
    78    unsigned int last_seq_;
    79  
    80   private:
    81    /// Do an RPC request/response interaction with the host Tao.
    82    /// @param op The operation.
    83    /// @param req The request to send.
    84    /// @param[out] data The returned data, if not nullptr.
    85    /// @param[out] policy The returned policy, if not nullptr.
    86    bool Request(const string &op, const TaoRPCRequest &req, string *data,
    87                 string *policy, int64_t* counter);
    88  
    89    DISALLOW_COPY_AND_ASSIGN(TaoRPC);
    90  };
    91  }  // namespace tao
    92  
    93  #endif  // TAO_TAO_RPC_H_