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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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, uint32_t 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. static StringParameter keyFile;
  38. static BoolParameter requireUsername;
  39. private:
  40. void cleanup();
  41. void loadPrivateKey();
  42. void loadPKCS1Key(const uint8_t* data, size_t size);
  43. void loadPKCS8Key(const uint8_t* data, size_t size);
  44. void writePublicKey();
  45. bool readPublicKey();
  46. void writeRandom();
  47. bool readRandom();
  48. void setCipher();
  49. void writeHash();
  50. bool readHash();
  51. void clearSecrets();
  52. void writeSubtype();
  53. bool readCredentials();
  54. void verifyUserPass();
  55. void verifyPass();
  56. int state;
  57. int keySize;
  58. bool isAllEncrypted;
  59. uint32_t secType;
  60. struct rsa_private_key serverKey;
  61. struct rsa_public_key clientKey;
  62. uint32_t serverKeyLength;
  63. uint8_t* serverKeyN;
  64. uint8_t* serverKeyE;
  65. uint32_t clientKeyLength;
  66. uint8_t* clientKeyN;
  67. uint8_t* clientKeyE;
  68. uint8_t serverRandom[32];
  69. uint8_t clientRandom[32];
  70. char username[256];
  71. char password[256];
  72. rdr::InStream* rais;
  73. rdr::OutStream* raos;
  74. rdr::InStream* rawis;
  75. rdr::OutStream* rawos;
  76. rdr::RandomStream rs;
  77. };
  78. }
  79. #endif