sasl_authenticator.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef COMMON_SASL_AUTHENTICATOR_H_
  19. #define COMMON_SASL_AUTHENTICATOR_H_
  20. #include "libhdfs++/status.h"
  21. namespace hdfs {
  22. class DigestMD5AuthenticatorTest_TestResponse_Test;
  23. /**
  24. * A specialized implementation of RFC 2831 for the HDFS
  25. * DataTransferProtocol.
  26. *
  27. * The current lacks the following features:
  28. * * Encoding the username, realm, and password in ISO-8859-1 when
  29. * it is required by the RFC. They are always encoded in UTF-8.
  30. * * Checking whether the challenges from the server are
  31. * well-formed.
  32. * * Specifying authzid, digest-uri and maximum buffer size.
  33. * * Supporting QOP other than the auth level.
  34. **/
  35. class DigestMD5Authenticator {
  36. public:
  37. Status EvaluateResponse(const std::string &payload, std::string *result);
  38. DigestMD5Authenticator(const std::string &username, const std::string &password,
  39. bool mock_nonce = false);
  40. private:
  41. Status GenerateFirstResponse(std::string *result);
  42. Status GenerateResponseValue(std::string *response_value);
  43. Status ParseFirstChallenge(const std::string &payload);
  44. static size_t NextToken(const std::string &payload, size_t off, std::string *tok);
  45. void GenerateCNonce();
  46. std::string username_;
  47. std::string password_;
  48. std::string nonce_;
  49. std::string cnonce_;
  50. std::string realm_;
  51. std::string qop_;
  52. unsigned nonce_count_;
  53. const bool TEST_mock_cnonce_;
  54. friend class DigestMD5AuthenticatorTest_TestResponse_Test;
  55. };
  56. }
  57. #endif