OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_HTTP_HTTP_AUTH_GSSAPI_POSIX_H_ |
| 6 #define NET_HTTP_HTTP_AUTH_GSSAPI_POSIX_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/native_library.h" |
| 11 #include "net/http/http_auth.h" |
| 12 |
| 13 #define GSS_USE_FUNCTION_POINTERS |
| 14 #include "net/third_party/gssapi/gssapi.h" |
| 15 |
| 16 class GURL; |
| 17 |
| 18 namespace net { |
| 19 |
| 20 class HttpRequestInfo; |
| 21 class ProxyInfo; |
| 22 |
| 23 // GSSAPILibrary is introduced so unit tests can mock the calls to the GSSAPI |
| 24 // library. The default implementation attempts to load one of the standard |
| 25 // GSSAPI library implementations, then simply passes the arguments on to |
| 26 // that implementation. |
| 27 class GSSAPILibrary { |
| 28 public: |
| 29 virtual ~GSSAPILibrary() {} |
| 30 |
| 31 virtual bool Init() = 0; |
| 32 virtual gssapi::OM_uint32 import_name( |
| 33 gssapi::OM_uint32* minor_status, |
| 34 const gssapi::gss_buffer_t input_name_buffer, |
| 35 const gssapi::gss_OID input_name_type, |
| 36 gssapi::gss_name_t* output_name) = 0; |
| 37 virtual gssapi::OM_uint32 release_name( |
| 38 gssapi::OM_uint32* minor_status, |
| 39 gssapi::gss_name_t* input_name) = 0; |
| 40 virtual gssapi::OM_uint32 release_buffer( |
| 41 gssapi::OM_uint32* minor_status, |
| 42 gssapi::gss_buffer_t buffer) = 0; |
| 43 virtual gssapi::OM_uint32 display_status( |
| 44 gssapi::OM_uint32* minor_status, |
| 45 gssapi::OM_uint32 status_value, |
| 46 int status_type, |
| 47 const gssapi::gss_OID mech_type, |
| 48 gssapi::OM_uint32* message_contex, |
| 49 gssapi::gss_buffer_t status_string) = 0; |
| 50 virtual gssapi::OM_uint32 init_sec_context( |
| 51 gssapi::OM_uint32* minor_status, |
| 52 const gssapi::gss_cred_id_t initiator_cred_handle, |
| 53 gssapi::gss_ctx_id_t* context_handle, |
| 54 const gssapi::gss_name_t target_name, |
| 55 const gssapi::gss_OID mech_type, |
| 56 gssapi::OM_uint32 req_flags, |
| 57 gssapi::OM_uint32 time_req, |
| 58 const gssapi::gss_channel_bindings_t input_chan_bindings, |
| 59 const gssapi::gss_buffer_t input_token, |
| 60 gssapi::gss_OID* actual_mech_type, |
| 61 gssapi::gss_buffer_t* output_token, |
| 62 gssapi::OM_uint32* ret_flags, |
| 63 gssapi::OM_uint32* time_rec) = 0; |
| 64 virtual gssapi::OM_uint32 wrap_size_limit( |
| 65 gssapi::OM_uint32* minor_status, |
| 66 const gssapi::gss_ctx_id_t context_handle, |
| 67 int conf_req_flag, |
| 68 gssapi::gss_qop_t qop_req, |
| 69 gssapi::OM_uint32 req_output_size, |
| 70 gssapi::OM_uint32* max_input_size) = 0; |
| 71 |
| 72 // Get the default GSSPILibrary instance. The object returned is a singleton |
| 73 // instance, and the caller should not delete it. |
| 74 static GSSAPILibrary* GetDefault(); |
| 75 }; |
| 76 |
| 77 class GSSAPISharedLibrary : public GSSAPILibrary { |
| 78 public: |
| 79 GSSAPISharedLibrary(); |
| 80 virtual ~GSSAPISharedLibrary(); |
| 81 |
| 82 // GSSAPILibrary methods: |
| 83 virtual bool Init(); |
| 84 virtual gssapi::OM_uint32 import_name( |
| 85 gssapi::OM_uint32* minor_status, |
| 86 const gssapi::gss_buffer_t input_name_buffer, |
| 87 const gssapi::gss_OID input_name_type, |
| 88 gssapi::gss_name_t* output_name); |
| 89 virtual gssapi::OM_uint32 release_name( |
| 90 gssapi::OM_uint32* minor_status, |
| 91 gssapi::gss_name_t* input_name); |
| 92 virtual gssapi::OM_uint32 release_buffer( |
| 93 gssapi::OM_uint32* minor_status, |
| 94 gssapi::gss_buffer_t buffer); |
| 95 virtual gssapi::OM_uint32 display_status( |
| 96 gssapi::OM_uint32* minor_status, |
| 97 gssapi::OM_uint32 status_value, |
| 98 int status_type, |
| 99 const gssapi::gss_OID mech_type, |
| 100 gssapi::OM_uint32* message_contex, |
| 101 gssapi::gss_buffer_t status_string); |
| 102 virtual gssapi::OM_uint32 init_sec_context( |
| 103 gssapi::OM_uint32* minor_status, |
| 104 const gssapi::gss_cred_id_t initiator_cred_handle, |
| 105 gssapi::gss_ctx_id_t* context_handle, |
| 106 const gssapi::gss_name_t target_name, |
| 107 const gssapi::gss_OID mech_type, |
| 108 gssapi::OM_uint32 req_flags, |
| 109 gssapi::OM_uint32 time_req, |
| 110 const gssapi::gss_channel_bindings_t input_chan_bindings, |
| 111 const gssapi::gss_buffer_t input_token, |
| 112 gssapi::gss_OID* actual_mech_type, |
| 113 gssapi::gss_buffer_t* output_token, |
| 114 gssapi::OM_uint32* ret_flags, |
| 115 gssapi::OM_uint32* time_rec); |
| 116 virtual gssapi::OM_uint32 wrap_size_limit( |
| 117 gssapi::OM_uint32* minor_status, |
| 118 const gssapi::gss_ctx_id_t context_handle, |
| 119 int conf_req_flag, |
| 120 gssapi::gss_qop_t qop_req, |
| 121 gssapi::OM_uint32 req_output_size, |
| 122 gssapi::OM_uint32* max_input_size); |
| 123 |
| 124 private: |
| 125 |
| 126 bool InitImpl(); |
| 127 base::NativeLibrary LoadSharedObject(); |
| 128 bool BindMethods(); |
| 129 |
| 130 static const char* kLibraryNames[]; |
| 131 |
| 132 bool initialized_; |
| 133 bool cached_initialize_value_; |
| 134 |
| 135 // Need some way to invalidate the library. |
| 136 base::NativeLibrary gssapi_library_; |
| 137 |
| 138 // Function pointers |
| 139 gssapi::gss_import_name_type import_name_; |
| 140 gssapi::gss_release_name_type release_name_; |
| 141 gssapi::gss_release_buffer_type release_buffer_; |
| 142 gssapi::gss_display_status_type display_status_; |
| 143 gssapi::gss_init_sec_context_type init_sec_context_; |
| 144 gssapi::gss_wrap_size_limit_type wrap_size_limit_; |
| 145 }; |
| 146 |
| 147 // TODO(cbentzel): Share code with HttpAuthSSPI. |
| 148 class HttpAuthGSSAPI { |
| 149 public: |
| 150 HttpAuthGSSAPI(const std::string& scheme, |
| 151 const gssapi::gss_OID gss_oid, |
| 152 GSSAPILibrary* library); |
| 153 ~HttpAuthGSSAPI(); |
| 154 |
| 155 bool NeedsIdentity() const; |
| 156 bool IsFinalRound() const; |
| 157 |
| 158 bool ParseChallenge(HttpAuth::ChallengeTokenizer* tok); |
| 159 |
| 160 int GenerateAuthToken(const std::wstring* username, |
| 161 const std::wstring* password, |
| 162 const std::wstring& origin, |
| 163 const HttpRequestInfo* request, |
| 164 const ProxyInfo* proxy, |
| 165 std::string* out_credentials); |
| 166 |
| 167 private: |
| 168 |
| 169 int OnFirstRound(const std::wstring* username, |
| 170 const std::wstring* password); |
| 171 int GetNextSecurityToken(const std::wstring& origin, |
| 172 gssapi::gss_buffer_t in_token, |
| 173 gssapi::gss_buffer_t* out_token); |
| 174 |
| 175 std::string scheme_; |
| 176 std::wstring username_; |
| 177 std::wstring password_; |
| 178 gssapi::gss_OID gss_oid_; |
| 179 GSSAPILibrary* library_; |
| 180 std::string decoded_server_auth_token_; |
| 181 gssapi::gss_ctx_id_t sec_context_; |
| 182 }; |
| 183 |
| 184 } // namespace net |
| 185 |
| 186 #endif // NET_HTTP_HTTP_AUTH_GSSAPI_POSIX_H_ |
OLD | NEW |