KeyGen.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //---------------------------------------------------------------------------
  2. #ifndef KeyGenH
  3. #define KeyGenH
  4. //---------------------------------------------------------------------------
  5. enum TKeyType { ktRSA1, ktRSA2, ktDSA };
  6. typedef unsigned TEntropyBit;
  7. class TKeyGenerationThread;
  8. class TKeyGenerator;
  9. enum TKeyGeneratorState { kgInitializing, kgInitialized, kgGenerating, kgComplete };
  10. enum TKeyGenerationComplete { kgInProgress, kgSuccess, kgFailure };
  11. enum TKeyFormat { kfPutty, kfOpenSSH, kfSSHCom };
  12. typedef void __fastcall (__closure *TKeyGeneratorGenerating)
  13. (TKeyGenerator * Generator, int Range, int Position, TKeyGenerationComplete Complete);
  14. //---------------------------------------------------------------------------
  15. struct ssh2_userkey;
  16. struct RSAKey;
  17. struct dss_key;
  18. //---------------------------------------------------------------------------
  19. class TKeyGenerator : public TObject
  20. {
  21. friend class TKeyGenerationThread;
  22. private:
  23. AnsiString FComment;
  24. int FKeySize;
  25. TKeyType FKeyType;
  26. TEntropyBit * FEntropy;
  27. int FEntropyGot;
  28. int FEntropyRequired;
  29. AnsiString FFingerprint;
  30. TKeyGeneratorState FState;
  31. int FGenerationRange;
  32. int FGenerationPosition;
  33. TKeyGeneratorGenerating FOnGenerating;
  34. AnsiString FPublicKey;
  35. TKeyGenerationThread * FThread;
  36. AnsiString __fastcall GetAuthorizedKeysLine();
  37. AnsiString __fastcall GetFingerprint();
  38. bool __fastcall GetIsSSH2();
  39. struct ssh2_userkey * FSSH2Key;
  40. int __fastcall GetPercentGenerated();
  41. AnsiString __fastcall GetPublicKey();
  42. void __fastcall SetComment(AnsiString value);
  43. void __fastcall SetKeySize(int value);
  44. void __fastcall SetKeyType(TKeyType value);
  45. protected:
  46. // both written by TKeyGenerationThread (from different thread)
  47. RSAKey * FRSAKey;
  48. dss_key * FDSSKey;
  49. // called by TKeyGenerationThread (from main VCL thread)
  50. void __fastcall ProgressUpdate(int Range, int Position, TKeyGenerationComplete Complete);
  51. void __fastcall ResetKey();
  52. public:
  53. __fastcall TKeyGenerator();
  54. virtual __fastcall ~TKeyGenerator();
  55. void __fastcall AddEntropy(TEntropyBit Entropy);
  56. void __fastcall Generate();
  57. void __fastcall SaveKey(const AnsiString FileName,
  58. const AnsiString Passphrase, TKeyFormat Format);
  59. void __fastcall StartGenerationThread();
  60. __property AnsiString AuthorizedKeysLine = { read = GetAuthorizedKeysLine };
  61. __property AnsiString Comment = { read = FComment, write = SetComment };
  62. __property int EntropyGot = { read = FEntropyGot };
  63. __property int EntropyRequired = { read = FEntropyRequired };
  64. __property AnsiString Fingerprint = { read = GetFingerprint };
  65. __property bool IsSSH2 = { read = GetIsSSH2 };
  66. __property TKeyGeneratorState State = { read = FState };
  67. __property int KeySize = { read = FKeySize, write = SetKeySize };
  68. __property TKeyType KeyType = { read = FKeyType, write = SetKeyType };
  69. __property TKeyGeneratorGenerating OnGenerating = { read = FOnGenerating, write = FOnGenerating };
  70. __property int PercentGenerated = { read = GetPercentGenerated };
  71. __property AnsiString PublicKey = { read = GetPublicKey };
  72. };
  73. //---------------------------------------------------------------------------
  74. #endif