| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/http/http_auth_gssapi_posix.h" | 5 #include "net/http/http_auth_gssapi_posix.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 16 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
| 17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 18 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
| 19 | 19 |
| 20 // These are defined for the GSSAPI library: | 20 // These are defined for the GSSAPI library: |
| 21 // Paraphrasing the comments from gssapi.h: | 21 // Paraphrasing the comments from gssapi.h: |
| 22 // "The implementation must reserve static storage for a | 22 // "The implementation must reserve static storage for a |
| 23 // gss_OID_desc object for each constant. That constant | 23 // gss_OID_desc object for each constant. That constant |
| 24 // should be initialized to point to that gss_OID_desc." | 24 // should be initialized to point to that gss_OID_desc." |
| 25 // These are encoded using ASN.1 BER encoding. |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 static gss_OID_desc GSS_C_NT_USER_NAME_VAL = { | 28 static gss_OID_desc GSS_C_NT_USER_NAME_VAL = { |
| 28 10, | 29 10, |
| 29 const_cast<char*>("\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x01") | 30 const_cast<char*>("\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x01") |
| 30 }; | 31 }; |
| 31 static gss_OID_desc GSS_C_NT_MACHINE_UID_NAME_VAL = { | 32 static gss_OID_desc GSS_C_NT_MACHINE_UID_NAME_VAL = { |
| 32 10, | 33 10, |
| 33 const_cast<char*>("\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02") | 34 const_cast<char*>("\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02") |
| 34 }; | 35 }; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 gss_OID GSS_C_NT_USER_NAME = &GSS_C_NT_USER_NAME_VAL; | 69 gss_OID GSS_C_NT_USER_NAME = &GSS_C_NT_USER_NAME_VAL; |
| 69 gss_OID GSS_C_NT_MACHINE_UID_NAME = &GSS_C_NT_MACHINE_UID_NAME_VAL; | 70 gss_OID GSS_C_NT_MACHINE_UID_NAME = &GSS_C_NT_MACHINE_UID_NAME_VAL; |
| 70 gss_OID GSS_C_NT_STRING_UID_NAME = &GSS_C_NT_STRING_UID_NAME_VAL; | 71 gss_OID GSS_C_NT_STRING_UID_NAME = &GSS_C_NT_STRING_UID_NAME_VAL; |
| 71 gss_OID GSS_C_NT_HOSTBASED_SERVICE_X = &GSS_C_NT_HOSTBASED_SERVICE_X_VAL; | 72 gss_OID GSS_C_NT_HOSTBASED_SERVICE_X = &GSS_C_NT_HOSTBASED_SERVICE_X_VAL; |
| 72 gss_OID GSS_C_NT_HOSTBASED_SERVICE = &GSS_C_NT_HOSTBASED_SERVICE_VAL; | 73 gss_OID GSS_C_NT_HOSTBASED_SERVICE = &GSS_C_NT_HOSTBASED_SERVICE_VAL; |
| 73 gss_OID GSS_C_NT_ANONYMOUS = &GSS_C_NT_ANONYMOUS_VAL; | 74 gss_OID GSS_C_NT_ANONYMOUS = &GSS_C_NT_ANONYMOUS_VAL; |
| 74 gss_OID GSS_C_NT_EXPORT_NAME = &GSS_C_NT_EXPORT_NAME_VAL; | 75 gss_OID GSS_C_NT_EXPORT_NAME = &GSS_C_NT_EXPORT_NAME_VAL; |
| 75 | 76 |
| 76 namespace net { | 77 namespace net { |
| 77 | 78 |
| 78 // These are encoded using ASN.1 BER encoding. | 79 // Exported mechanism for GSSAPI. We always use SPNEGO: |
| 79 | 80 |
| 80 // This one is used by Firefox's nsAuthGSSAPI class. | 81 // iso.org.dod.internet.security.mechanism.snego (1.3.6.1.5.5.2) |
| 81 gss_OID_desc CHROME_GSS_KRB5_MECH_OID_DESC_VAL = { | 82 gss_OID_desc CHROME_GSS_SPNEGO_MECH_OID_DESC_VAL = { |
| 82 9, | 83 6, |
| 83 const_cast<char*>("\x2a\x86\x48\x86\xf7\x12\x01\x02\x02") | 84 const_cast<char*>("\x2b\x06\x01\x05\x05\x02") |
| 84 }; | 85 }; |
| 85 | 86 |
| 86 gss_OID_desc CHROME_GSS_C_NT_HOSTBASED_SERVICE_X_VAL = { | 87 gss_OID CHROME_GSS_SPNEGO_MECH_OID_DESC = |
| 87 6, | 88 &CHROME_GSS_SPNEGO_MECH_OID_DESC_VAL; |
| 88 const_cast<char*>("\x2b\x06\x01\x05\x06\x02") | |
| 89 }; | |
| 90 | |
| 91 gss_OID_desc CHROME_GSS_C_NT_HOSTBASED_SERVICE_VAL = { | |
| 92 10, | |
| 93 const_cast<char*>("\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04") | |
| 94 }; | |
| 95 | |
| 96 gss_OID CHROME_GSS_C_NT_HOSTBASED_SERVICE_X = | |
| 97 &CHROME_GSS_C_NT_HOSTBASED_SERVICE_X_VAL; | |
| 98 gss_OID CHROME_GSS_C_NT_HOSTBASED_SERVICE = | |
| 99 &CHROME_GSS_C_NT_HOSTBASED_SERVICE_VAL; | |
| 100 gss_OID CHROME_GSS_KRB5_MECH_OID_DESC = | |
| 101 &CHROME_GSS_KRB5_MECH_OID_DESC_VAL; | |
| 102 | 89 |
| 103 // Debugging helpers. | 90 // Debugging helpers. |
| 104 namespace { | 91 namespace { |
| 105 | 92 |
| 106 std::string DisplayStatus(OM_uint32 major_status, | 93 std::string DisplayStatus(OM_uint32 major_status, |
| 107 OM_uint32 minor_status) { | 94 OM_uint32 minor_status) { |
| 108 if (major_status == GSS_S_COMPLETE) | 95 if (major_status == GSS_S_COMPLETE) |
| 109 return "OK"; | 96 return "OK"; |
| 110 return base::StringPrintf("0x%08X 0x%08X", major_status, minor_status); | 97 return base::StringPrintf("0x%08X 0x%08X", major_status, minor_status); |
| 111 } | 98 } |
| (...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 // TODO(cbentzel): Just do this on the first pass? | 844 // TODO(cbentzel): Just do this on the first pass? |
| 858 std::string spn_principal = WideToASCII(spn); | 845 std::string spn_principal = WideToASCII(spn); |
| 859 gss_buffer_desc spn_buffer = GSS_C_EMPTY_BUFFER; | 846 gss_buffer_desc spn_buffer = GSS_C_EMPTY_BUFFER; |
| 860 spn_buffer.value = const_cast<char*>(spn_principal.c_str()); | 847 spn_buffer.value = const_cast<char*>(spn_principal.c_str()); |
| 861 spn_buffer.length = spn_principal.size() + 1; | 848 spn_buffer.length = spn_principal.size() + 1; |
| 862 OM_uint32 minor_status = 0; | 849 OM_uint32 minor_status = 0; |
| 863 gss_name_t principal_name = GSS_C_NO_NAME; | 850 gss_name_t principal_name = GSS_C_NO_NAME; |
| 864 OM_uint32 major_status = library_->import_name( | 851 OM_uint32 major_status = library_->import_name( |
| 865 &minor_status, | 852 &minor_status, |
| 866 &spn_buffer, | 853 &spn_buffer, |
| 867 CHROME_GSS_C_NT_HOSTBASED_SERVICE, | 854 GSS_C_NT_HOSTBASED_SERVICE, |
| 868 &principal_name); | 855 &principal_name); |
| 869 int rv = MapImportNameStatusToError(major_status); | 856 int rv = MapImportNameStatusToError(major_status); |
| 870 if (rv != OK) { | 857 if (rv != OK) { |
| 871 LOG(ERROR) << "Problem importing name from " | 858 LOG(ERROR) << "Problem importing name from " |
| 872 << "spn \"" << spn_principal << "\"\n" | 859 << "spn \"" << spn_principal << "\"\n" |
| 873 << DisplayExtendedStatus(library_, major_status, minor_status); | 860 << DisplayExtendedStatus(library_, major_status, minor_status); |
| 874 return rv; | 861 return rv; |
| 875 } | 862 } |
| 876 ScopedName scoped_name(principal_name, library_); | 863 ScopedName scoped_name(principal_name, library_); |
| 877 | 864 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 897 if (rv != OK) { | 884 if (rv != OK) { |
| 898 LOG(ERROR) << "Problem initializing context. \n" | 885 LOG(ERROR) << "Problem initializing context. \n" |
| 899 << DisplayExtendedStatus(library_, major_status, minor_status) | 886 << DisplayExtendedStatus(library_, major_status, minor_status) |
| 900 << '\n' | 887 << '\n' |
| 901 << DescribeContext(library_, scoped_sec_context_.get()); | 888 << DescribeContext(library_, scoped_sec_context_.get()); |
| 902 } | 889 } |
| 903 return rv; | 890 return rv; |
| 904 } | 891 } |
| 905 | 892 |
| 906 } // namespace net | 893 } // namespace net |
| OLD | NEW |