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.

SSecurityRSAAES.h 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Copyright (C) 2022 Dinglan Peng
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. #ifndef __S_SECURITY_RSAAES_H__
  19. #define __S_SECURITY_RSAAES_H__
  20. #ifndef HAVE_NETTLE
  21. #error "This header should not be included without HAVE_NETTLE defined"
  22. #endif
  23. #include <nettle/rsa.h>
  24. #include <rfb/SSecurity.h>
  25. #include <rdr/InStream.h>
  26. #include <rdr/OutStream.h>
  27. #include <rdr/RandomStream.h>
  28. namespace rfb {
  29. class SSecurityRSAAES : public SSecurity {
  30. public:
  31. SSecurityRSAAES(SConnection* sc, rdr::U32 secType,
  32. int keySize, bool isAllEncrypted);
  33. virtual ~SSecurityRSAAES();
  34. virtual bool processMsg();
  35. virtual const char* getUserName() const;
  36. virtual int getType() const { return secType; }
  37. virtual SConnection::AccessRights getAccessRights() const
  38. {
  39. return accessRights;
  40. }
  41. static StringParameter keyFile;
  42. static BoolParameter requireUsername;
  43. private:
  44. void cleanup();
  45. void loadPrivateKey();
  46. void loadPKCS1Key(const rdr::U8* data, size_t size);
  47. void loadPKCS8Key(const rdr::U8* data, size_t size);
  48. void writePublicKey();
  49. bool readPublicKey();
  50. void writeRandom();
  51. bool readRandom();
  52. void setCipher();
  53. void writeHash();
  54. bool readHash();
  55. void clearSecrets();
  56. void writeSubtype();
  57. bool readCredentials();
  58. void verifyUserPass();
  59. void verifyPass();
  60. int state;
  61. int keySize;
  62. bool isAllEncrypted;
  63. rdr::U32 secType;
  64. struct rsa_private_key serverKey;
  65. struct rsa_public_key clientKey;
  66. rdr::U32 serverKeyLength;
  67. rdr::U8* serverKeyN;
  68. rdr::U8* serverKeyE;
  69. rdr::U32 clientKeyLength;
  70. rdr::U8* clientKeyN;
  71. rdr::U8* clientKeyE;
  72. rdr::U8 serverRandom[32];
  73. rdr::U8 clientRandom[32];
  74. CharArray username;
  75. CharArray password;
  76. SConnection::AccessRights accessRights;
  77. rdr::InStream* rais;
  78. rdr::OutStream* raos;
  79. rdr::InStream* rawis;
  80. rdr::OutStream* rawos;
  81. rdr::RandomStream rs;
  82. };
  83. }
  84. #endif