github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/src/support_libraries/tao_support/taosupport.h (about) 1 // Copyright (c) 2014, Google Inc. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 #include <string> 14 #include <stdlib.h> 15 16 #ifndef __TAOSUPPORT_H__ 17 #define __TAOSUPPORT_H__ 18 19 #include "tao/fd_message_channel.h" 20 #include "tao/tao_rpc.h" 21 #include "tao/util.h" 22 23 #include "agile_crypto_support.h" 24 25 #include "attestation.pb.h" 26 27 #include <openssl/rsa.h> 28 #include <openssl/x509.h> 29 #include <openssl/x509v3.h> 30 31 #include <string> 32 #include <list> 33 34 #ifndef byte 35 typedef unsigned char byte; 36 #endif 37 38 class TaoProgramData { 39 private: 40 41 // Has InitTao initialized me successfully? 42 bool initialized_; 43 44 // cipher suite 45 string cipher_suite_; 46 47 // Program path 48 string program_path_; 49 50 // Policy cert file name (including path). 51 string policy_cert_file_name_; 52 53 // network 54 string network_; 55 string address_; 56 string port_; 57 58 // What kind of Authority Service? 59 bool useSimpleService_; 60 61 // Channel to communicate with host. 62 tao::FDMessageChannel* msg_; 63 64 // Tao object interface 65 tao::Tao* tao_; 66 67 // Marshalled tao name (a Prin). 68 string marshalled_tao_name_; 69 70 // Printable tao name 71 string tao_name_; 72 73 string policy_cert_; 74 X509* policy_certificate_; 75 Verifier* policy_verifying_key_; 76 77 // host certificate. 78 string host_cert_file_name_; 79 string host_cert_; 80 std::list<string> host_cert_chain_; 81 82 // keys 83 Signer* program_signing_key_; 84 Verifier* verifying_key_; 85 Crypter* crypting_key_; 86 87 // Der encoded and parsed X509 program certificate. 88 string program_cert_; 89 X509* program_certificate_; 90 std::list<string> program_cert_chain_; 91 92 bool SealMaterial(string& to_seal, string* sealed); 93 bool UnsealMaterial(string& sealed, string* unsealed); 94 bool Attest(string& to_attest, string* attested); 95 96 bool SaveProgramData(tao_support::SavedProgramData& pd, string* out); 97 bool RecoverProgramData(string in, tao_support::SavedProgramData* pd); 98 99 bool InitProgramKeys(tao_support::SavedProgramData* pd); 100 bool GetProgramData(); 101 102 public: 103 TaoProgramData(); 104 ~TaoProgramData(); 105 106 void ClearProgramData(); 107 bool InitTao(string& cipher_suite, tao::FDMessageChannel* msg, tao::Tao* tao, 108 string& policy_key_path, string& host_key_path, string& program_path, 109 string& network, string& address, string& port, bool useSimpleService); 110 111 // Accessors 112 bool ExtendName(string& subprin); 113 bool GetTaoName(string* name); 114 115 void Print(); 116 117 bool GetCipherSuite(string* keyType); 118 119 bool GetPolicyCert(string* cert); 120 bool GetProgramCert(string* cert); 121 bool GetProgramKeyType(string* key_type); 122 EVP_PKEY* GetProgramKey(); 123 124 void SetPolicyCertificate(X509* c); 125 X509* GetPolicyCertificate(); 126 void SetProgramCertificate(X509* c); 127 X509* GetProgramCertificate(); 128 std::list<string>* GetProgramCertChain(); 129 130 bool InitCounter(string& label, int64_t& c); 131 bool GetCounter(string& label, int64_t* c); 132 bool RollbackProtectedSeal(string& label, string& data, string* sealed); 133 bool RollbackProtectedUnseal(string& sealed, string* data, string* policy); 134 135 private: 136 // This should be private. 137 bool RequestDomainServiceCert(string& request_string); 138 }; 139 140 class TaoChannel { 141 public: 142 SslChannel peer_channel_; 143 X509* peerCertificate_; 144 string peer_name_; 145 146 TaoChannel(); 147 ~TaoChannel(); 148 bool OpenTaoChannel(TaoProgramData& client_program_data, 149 string& serverAddress, string& port); 150 void CloseTaoChannel(); 151 bool SendRequest(int size, byte* out); 152 bool GetRequest(int* size, byte* in); 153 void Print(); 154 }; 155 #endif