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.

CSecurityRSAAES.h 2.4KB

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