IdSASLOTP.pas 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. {
  2. $Project$
  3. $Workfile$
  4. $Revision$
  5. $DateUTC$
  6. $Id$
  7. This file is part of the Indy (Internet Direct) project, and is offered
  8. under the dual-licensing agreement described on the Indy website.
  9. (http://www.indyproject.org/)
  10. Copyright:
  11. (c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
  12. }
  13. {
  14. $Log$
  15. }
  16. {
  17. Rev 1.4 2004.02.03 5:45:12 PM czhower
  18. Name changes
  19. Rev 1.3 1/21/2004 4:03:16 PM JPMugaas
  20. InitComponent
  21. Rev 1.2 10/19/2003 5:57:18 PM DSiders
  22. Added localization comments.
  23. Rev 1.1 5/10/2003 10:10:44 PM JPMugaas
  24. Bug fixes.
  25. Rev 1.0 12/16/2002 03:27:22 AM JPMugaas
  26. Initial version of IdSASLOTP. This is the OTP (One-Time-only password) SASL
  27. mechanism.
  28. }
  29. {This is based on RFC2444}
  30. unit IdSASLOTP;
  31. interface
  32. {$i IdCompilerDefines.inc}
  33. uses
  34. IdSASL,
  35. IdSASLUserPass;
  36. type
  37. TIdSASLOTP = class(TIdSASLUserPass)
  38. protected
  39. function GenerateOTP(const AResponse, APassword: String): String;
  40. procedure InitComponent; override;
  41. public
  42. class function ServiceName: TIdSASLServiceName; override;
  43. function TryStartAuthenticate(const AHost, AProtocolName : String; var VInitialResponse: String): Boolean; override;
  44. function StartAuthenticate(const AChallenge, AHost, AProtocolName : String): String; override;
  45. function ContinueAuthenticate(const ALastResponse, AHost, AProtocolName : String): String; override;
  46. end;
  47. implementation
  48. uses
  49. IdGlobal, IdOTPCalculator;
  50. { TIdSASLOTP }
  51. function TIdSASLOTP.ContinueAuthenticate(const ALastResponse, AHost, AProtocolName : String): String;
  52. begin
  53. Result := GenerateOTP(ALastResponse, GetPassword);
  54. end;
  55. procedure TIdSASLOTP.InitComponent;
  56. begin
  57. inherited InitComponent;
  58. FSecurityLevel := 1000;
  59. end;
  60. class function TIdSASLOTP.ServiceName: TIdSASLServiceName;
  61. begin
  62. Result := 'OTP'; {Do not translate}
  63. end;
  64. function TIdSASLOTP.TryStartAuthenticate(const AHost, AProtocolName : string;
  65. var VInitialResponse: String): Boolean;
  66. begin
  67. VInitialResponse := GetUsername;
  68. Result := True;
  69. end;
  70. function TIdSASLOTP.StartAuthenticate(const AChallenge, AHost, AProtocolName : string): String;
  71. begin
  72. Result := GetUsername;
  73. end;
  74. function TIdSASLOTP.GenerateOTP(const AResponse, APassword: String): String;
  75. var
  76. LKey: String;
  77. begin
  78. if TIdOTPCalculator.GenerateSixWordKey(AResponse, APassword, LKey) then begin
  79. Result := 'word:' + LKey; {do not localize}
  80. end else begin
  81. Result := '';
  82. end;
  83. end;
  84. end.