IdSASLSKey.pas 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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:42 PM czhower
  18. Name changes
  19. Rev 1.3 1/25/2004 2:17:54 PM JPMugaas
  20. Should work better. Removed one GPF in S/Key.
  21. Rev 1.2 1/21/2004 4:03:18 PM JPMugaas
  22. InitComponent
  23. Rev 1.1 10/19/2003 5:57:20 PM DSiders
  24. Added localization comments.
  25. Rev 1.0 5/10/2003 10:08:14 PM JPMugaas
  26. SKEY SASL mechanism as defined in RFC 2222. Note that this is obsolete and
  27. you should use RFC 2444 for new designs. This is only provided for backwards
  28. compatibility.
  29. }
  30. unit IdSASLSKey;
  31. interface
  32. {$i IdCompilerDefines.inc}
  33. uses
  34. IdSASLUserPass, IdSASL;
  35. {
  36. S/KEY SASL mechanism based on RFC 2222.
  37. NOte that this is depreciated and S/Key is a trademark of BelCore. This unit
  38. is only provided for backwards compatiability with some older systems.
  39. New designs should use IdSASLOTP (RFC 2444) which is more flexible and uses a
  40. better hash (MD5 and SHA1).
  41. }
  42. type
  43. TIdSASLSKey = class(TIdSASLUserPass)
  44. protected
  45. procedure InitComponent; override;
  46. public
  47. function IsReadyToStart: Boolean; override;
  48. class function ServiceName: TIdSASLServiceName; override;
  49. function TryStartAuthenticate(const AHost, AProtocolName : String; var VInitialResponse: String): Boolean; override;
  50. function StartAuthenticate(const AChallenge, AHost, AProtocolName : String) : String; override;
  51. function ContinueAuthenticate(const ALastResponse, AHost, AProtocolName : String): String; override;
  52. end;
  53. implementation
  54. uses
  55. IdFIPS, IdGlobal, IdGlobalProtocols, IdOTPCalculator, SysUtils;
  56. const
  57. SKEYSERVICENAME = 'SKEY'; {do not localize}
  58. { TIdSASLSKey }
  59. function TIdSASLSKey.ContinueAuthenticate(const ALastResponse, AHost, AProtocolName : String): String;
  60. var
  61. LBuf, LSeed : String;
  62. LCount : UInt32;
  63. begin
  64. LBuf := Trim(ALastResponse);
  65. LCount := IndyStrToInt(Fetch(LBuf), 0);
  66. LSeed := Fetch(LBuf);
  67. Result := TIdOTPCalculator.GenerateSixWordKey('md4', LSeed, GetPassword, LCount); {do not localize}
  68. end;
  69. procedure TIdSASLSKey.InitComponent;
  70. begin
  71. inherited InitComponent;
  72. //less than 1000 because MD4 is broken and this is depreciated
  73. FSecurityLevel := 900;
  74. end;
  75. function TIdSASLSKey.IsReadyToStart: Boolean;
  76. begin
  77. Result := not GetFIPSMode;
  78. end;
  79. class function TIdSASLSKey.ServiceName: TIdSASLServiceName;
  80. begin
  81. Result := SKEYSERVICENAME;
  82. end;
  83. function TIdSASLSKey.TryStartAuthenticate(const AHost, AProtocolName : String;
  84. var VInitialResponse: String): Boolean;
  85. begin
  86. VInitialResponse := GetUsername;
  87. Result := True;
  88. end;
  89. function TIdSASLSKey.StartAuthenticate(const AChallenge, AHost, AProtocolName : String): String;
  90. begin
  91. Result := GetUsername;
  92. end;
  93. end.