You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.4 KiB

4 years ago
  1. #if MYSQL_6_9
  2. // Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  3. //
  4. // MySQL Connector/NET is licensed under the terms of the GPLv2
  5. // <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
  6. // MySQL Connectors. There are special exceptions to the terms and
  7. // conditions of the GPLv2 as it is applied to this software, see the
  8. // FLOSS License Exception
  9. // <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
  10. //
  11. // This program is free software; you can redistribute it and/or modify
  12. // it under the terms of the GNU General Public License as published
  13. // by the Free Software Foundation; version 2 of the License.
  14. //
  15. // This program is distributed in the hope that it will be useful, but
  16. // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  18. // for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License along
  21. // with this program; if not, write to the Free Software Foundation, Inc.,
  22. // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  23. //#define BOUNCY_CASTLE_INCLUDED
  24. using System;
  25. using System.Collections.Generic;
  26. using System.IO;
  27. using System.Security.Cryptography;
  28. using System.Text;
  29. using Externals.MySql.Data.Common;
  30. using Externals.MySql.Data.MySqlClient.Properties;
  31. namespace Externals.MySql.Data.MySqlClient.Authentication
  32. {
  33. /// <summary>
  34. /// The implementation of the sha256_password authentication plugin.
  35. /// </summary>
  36. internal class Sha256AuthenticationPlugin : MySqlAuthenticationPlugin
  37. {
  38. private byte[] rawPubkey;
  39. public override string PluginName
  40. {
  41. get { return "sha256_password"; }
  42. }
  43. protected override byte[] MoreData(byte[] data)
  44. {
  45. rawPubkey = data;
  46. byte[] buffer = GetPassword() as byte[];
  47. return buffer;
  48. }
  49. public override object GetPassword()
  50. {
  51. if (Settings.SslMode != MySqlSslMode.None)
  52. {
  53. // send as clear text, since the channel is already encrypted
  54. byte[] passBytes = this.Encoding.GetBytes(Settings.Password);
  55. byte[] buffer = new byte[passBytes.Length + 1];
  56. Array.Copy(passBytes, 0, buffer, 0, passBytes.Length);
  57. buffer[passBytes.Length] = 0;
  58. return buffer;
  59. }
  60. else
  61. {
  62. throw new NotImplementedException( "You can use sha256 plugin only in SSL connections in this implementation." );
  63. }
  64. }
  65. }
  66. }
  67. #endif