home *** CD-ROM | disk | FTP | other *** search
/ ftp.muug.mb.ca / 2014.06.ftp.muug.mb.ca.tar / ftp.muug.mb.ca / pub / openh323.tar.gz / openh323.tar / openh323 / include / h235auth.h < prev    next >
C/C++ Source or Header  |  2003-04-29  |  10KB  |  356 lines

  1. /*
  2.  * h235auth.h
  3.  *
  4.  * H.235 authorisation PDU's
  5.  *
  6.  * Open H323 Library
  7.  *
  8.  * Copyright (c) 1998-2001 Equivalence Pty. Ltd.
  9.  *
  10.  * The contents of this file are subject to the Mozilla Public License
  11.  * Version 1.0 (the "License"); you may not use this file except in
  12.  * compliance with the License. You may obtain a copy of the License at
  13.  * http://www.mozilla.org/MPL/
  14.  *
  15.  * Software distributed under the License is distributed on an "AS IS"
  16.  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  17.  * the License for the specific language governing rights and limitations
  18.  * under the License.
  19.  *
  20.  * The Original Code is Open H323 Library.
  21.  *
  22.  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
  23.  *
  24.  * Contributor(s): Fⁿrbass Franz <franz.fuerbass@infonova.at>
  25.  *
  26.  * $Log: h235auth.h,v $
  27.  * Revision 1.15  2003/04/30 00:28:50  robertj
  28.  * Redesigned the alternate credentials in ARQ system as old implementation
  29.  *   was fraught with concurrency issues, most importantly it can cause false
  30.  *   detection of replay attacks taking out an endpoint completely.
  31.  *
  32.  * Revision 1.14  2003/04/01 04:47:48  robertj
  33.  * Abstracted H.225 RAS transaction processing (RIP and secondary thread) in
  34.  *   server environment for use by H.501 peer elements.
  35.  *
  36.  * Revision 1.13  2003/02/25 06:48:14  robertj
  37.  * More work on PDU transaction abstraction.
  38.  *
  39.  * Revision 1.12  2003/02/11 04:43:22  robertj
  40.  * Fixed use of asymmetrical authentication schemes such as MD5.
  41.  *
  42.  * Revision 1.11  2003/02/01 13:31:14  robertj
  43.  * Changes to support CAT authentication in RAS.
  44.  *
  45.  * Revision 1.10  2003/01/08 04:40:31  robertj
  46.  * Added more debug tracing for H.235 authenticators.
  47.  *
  48.  * Revision 1.9  2002/09/16 01:14:15  robertj
  49.  * Added #define so can select if #pragma interface/implementation is used on
  50.  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
  51.  *
  52.  * Revision 1.8  2002/09/03 06:19:36  robertj
  53.  * Normalised the multi-include header prevention ifdef/define symbol.
  54.  *
  55.  * Revision 1.7  2002/08/05 10:03:47  robertj
  56.  * Cosmetic changes to normalise the usage of pragma interface/implementation.
  57.  *
  58.  * Revision 1.6  2002/08/05 05:17:37  robertj
  59.  * Fairly major modifications to support different authentication credentials
  60.  *   in ARQ to the logged in ones on RRQ. For both client and server.
  61.  * Various other H.235 authentication bugs and anomalies fixed on the way.
  62.  *
  63.  * Revision 1.5  2002/05/17 03:39:28  robertj
  64.  * Fixed problems with H.235 authentication on RAS for server and client.
  65.  *
  66.  * Revision 1.4  2001/12/06 06:44:42  robertj
  67.  * Removed "Win32 SSL xxx" build configurations in favour of system
  68.  *   environment variables to select optional libraries.
  69.  *
  70.  * Revision 1.3  2001/09/14 00:13:37  robertj
  71.  * Fixed problem with some athenticators needing extra conditions to be
  72.  *   "active", so make IsActive() virtual and add localId to H235AuthSimpleMD5
  73.  *
  74.  * Revision 1.2  2001/09/13 01:15:18  robertj
  75.  * Added flag to H235Authenticator to determine if gkid and epid is to be
  76.  *   automatically set as the crypto token remote id and local id.
  77.  *
  78.  * Revision 1.1  2001/08/10 11:03:49  robertj
  79.  * Major changes to H.235 support in RAS to support server.
  80.  *
  81.  */
  82.  
  83. #ifndef __OPAL_H235AUTH_H
  84. #define __OPAL_H235AUTH_H
  85.  
  86. #ifdef P_USE_PRAGMA
  87. #pragma interface
  88. #endif
  89.  
  90.  
  91. class H323TransactionPDU;
  92. class H225_CryptoH323Token;
  93. class H225_ArrayOf_AuthenticationMechanism;
  94. class H225_ArrayOf_PASN_ObjectId;
  95. class H235_ClearToken;
  96. class H235_AuthenticationMechanism;
  97. class PASN_ObjectId;
  98. class PASN_Sequence;
  99. class PASN_Array;
  100.  
  101.  
  102. /** This abtract class embodies an H.235 authentication mechanism.
  103.     NOTE: descendants must have a Clone() function for correct operation.
  104. */
  105. class H235Authenticator : public PObject
  106. {
  107.     PCLASSINFO(H235Authenticator, PObject);
  108.   public:
  109.     H235Authenticator();
  110.  
  111.     virtual void PrintOn(
  112.       ostream & strm
  113.     ) const;
  114.  
  115.     virtual const char * GetName() const = 0;
  116.  
  117.     virtual BOOL PrepareTokens(
  118.       PASN_Array & clearTokens,
  119.       PASN_Array & cryptoTokens
  120.     );
  121.  
  122.     virtual H235_ClearToken * CreateClearToken();
  123.     virtual H225_CryptoH323Token * CreateCryptoToken();
  124.  
  125.     virtual BOOL Finalise(
  126.       PBYTEArray & rawPDU
  127.     );
  128.  
  129.     enum ValidationResult {
  130.       e_OK = 0,     /// Security parameters and Msg are ok, no security attacks
  131.       e_Absent,     /// Security parameters are expected but absent
  132.       e_Error,      /// Security parameters are present but incorrect
  133.       e_InvalidTime,/// Security parameters indicate peer has bad real time clock
  134.       e_BadPassword,/// Security parameters indicate bad password in token
  135.       e_ReplyAttack,/// Security parameters indicate an attack was made
  136.       e_Disabled    /// Security is disabled by local system
  137.     };
  138.  
  139.     virtual ValidationResult ValidateTokens(
  140.       const PASN_Array & clearTokens,
  141.       const PASN_Array & cryptoTokens,
  142.       const PBYTEArray & rawPDU
  143.     );
  144.  
  145.     virtual ValidationResult ValidateClearToken(
  146.       const H235_ClearToken & clearToken
  147.     );
  148.  
  149.     virtual ValidationResult ValidateCryptoToken(
  150.       const H225_CryptoH323Token & cryptoToken,
  151.       const PBYTEArray & rawPDU
  152.     );
  153.  
  154.     virtual BOOL IsCapability(
  155.       const H235_AuthenticationMechanism & mechansim,
  156.       const PASN_ObjectId & algorithmOID
  157.     ) = 0;
  158.  
  159.     virtual BOOL SetCapability(
  160.       H225_ArrayOf_AuthenticationMechanism & mechansims,
  161.       H225_ArrayOf_PASN_ObjectId & algorithmOIDs
  162.     ) = 0;
  163.  
  164.     virtual BOOL UseGkAndEpIdentifiers() const;
  165.  
  166.     virtual BOOL IsSecuredPDU(
  167.       unsigned rasPDU,
  168.       BOOL received
  169.     ) const;
  170.  
  171.     virtual BOOL IsActive() const;
  172.  
  173.     void Enable(
  174.       BOOL enab = TRUE
  175.     ) { enabled = enab; }
  176.     void Disable() { enabled = FALSE; }
  177.  
  178.     const PString & GetRemoteId() const { return remoteId; }
  179.     void SetRemoteId(const PString & id) { remoteId = id; }
  180.  
  181.     const PString & GetLocalId() const { return localId; }
  182.     void SetLocalId(const PString & id) { localId = id; }
  183.  
  184.     const PString & GetPassword() const { return password; }
  185.     void SetPassword(const PString & pw) { password = pw; }
  186.  
  187.  
  188.   protected:
  189.     BOOL AddCapability(
  190.       unsigned mechanism,
  191.       const PString & oid,
  192.       H225_ArrayOf_AuthenticationMechanism & mechansims,
  193.       H225_ArrayOf_PASN_ObjectId & algorithmOIDs
  194.     );
  195.  
  196.     BOOL     enabled;
  197.  
  198.     PString  remoteId;      // ID of remote entity
  199.     PString  localId;       // ID of local entity
  200.     PString  password;      // shared secret
  201.  
  202.     unsigned sentRandomSequenceNumber;
  203.     unsigned lastRandomSequenceNumber;
  204.     unsigned lastTimestamp;
  205.     int      timestampGracePeriod;
  206.  
  207.     PMutex mutex;
  208. };
  209.  
  210.  
  211. PDECLARE_LIST(H235Authenticators, H235Authenticator)
  212.   public:
  213.     void PreparePDU(
  214.       H323TransactionPDU & pdu,
  215.       PASN_Array & clearTokens,
  216.       unsigned clearOptionalField,
  217.       PASN_Array & cryptoTokens,
  218.       unsigned cryptoOptionalField
  219.     ) const;
  220.  
  221.     H235Authenticator::ValidationResult ValidatePDU(
  222.       const H323TransactionPDU & pdu,
  223.       const PASN_Array & clearTokens,
  224.       unsigned clearOptionalField,
  225.       const PASN_Array & cryptoTokens,
  226.       unsigned cryptoOptionalField,
  227.       const PBYTEArray & rawPDU
  228.     ) const;
  229. };
  230.  
  231.  
  232.  
  233.  
  234. /** This class embodies a simple MD5 based authentication.
  235.     The users password is concatenated with the 4 byte timestamp and 4 byte
  236.     random fields and an MD5 generated and sent/verified
  237. */
  238. class H235AuthSimpleMD5 : public H235Authenticator
  239. {
  240.     PCLASSINFO(H235AuthSimpleMD5, H235Authenticator);
  241.   public:
  242.     H235AuthSimpleMD5();
  243.  
  244.     PObject * Clone() const;
  245.  
  246.     virtual const char * GetName() const;
  247.  
  248.     virtual H225_CryptoH323Token * CreateCryptoToken();
  249.  
  250.     virtual ValidationResult ValidateCryptoToken(
  251.       const H225_CryptoH323Token & cryptoToken,
  252.       const PBYTEArray & rawPDU
  253.     );
  254.  
  255.     virtual BOOL IsCapability(
  256.       const H235_AuthenticationMechanism & mechansim,
  257.       const PASN_ObjectId & algorithmOID
  258.     );
  259.  
  260.     virtual BOOL SetCapability(
  261.       H225_ArrayOf_AuthenticationMechanism & mechansim,
  262.       H225_ArrayOf_PASN_ObjectId & algorithmOIDs
  263.     );
  264.  
  265.     virtual BOOL IsSecuredPDU(
  266.       unsigned rasPDU,
  267.       BOOL received
  268.     ) const;
  269. };
  270.  
  271.  
  272. /** This class embodies a RADIUS compatible based authentication (aka Cisco
  273.     Access Token or CAT).
  274.     The users password is concatenated with the 4 byte timestamp and 1 byte
  275.     random fields and an MD5 generated and sent/verified via the challenge
  276.     field.
  277. */
  278. class H235AuthCAT : public H235Authenticator
  279. {
  280.     PCLASSINFO(H235AuthCAT, H235Authenticator);
  281.   public:
  282.     H235AuthCAT();
  283.  
  284.     PObject * Clone() const;
  285.  
  286.     virtual const char * GetName() const;
  287.  
  288.     virtual H235_ClearToken * CreateClearToken();
  289.  
  290.     virtual ValidationResult ValidateClearToken(
  291.       const H235_ClearToken & clearToken
  292.     );
  293.  
  294.     virtual BOOL IsCapability(
  295.       const H235_AuthenticationMechanism & mechansim,
  296.       const PASN_ObjectId & algorithmOID
  297.     );
  298.  
  299.     virtual BOOL SetCapability(
  300.       H225_ArrayOf_AuthenticationMechanism & mechansim,
  301.       H225_ArrayOf_PASN_ObjectId & algorithmOIDs
  302.     );
  303.  
  304.     virtual BOOL IsSecuredPDU(
  305.       unsigned rasPDU,
  306.       BOOL received
  307.     ) const;
  308. };
  309.  
  310.  
  311. #if P_SSL
  312.  
  313. /** This class embodies the H.235 "base line Procedure 1" from Annex D.
  314. */
  315. class H235AuthProcedure1 : public H235Authenticator
  316. {
  317.     PCLASSINFO(H235AuthProcedure1, H235Authenticator);
  318.   public:
  319.     H235AuthProcedure1();
  320.  
  321.     PObject * Clone() const;
  322.  
  323.     virtual const char * GetName() const;
  324.  
  325.     virtual H225_CryptoH323Token * CreateCryptoToken();
  326.  
  327.     virtual BOOL Finalise(
  328.       PBYTEArray & rawPDU
  329.     );
  330.  
  331.     virtual ValidationResult ValidateCryptoToken(
  332.       const H225_CryptoH323Token & cryptoToken,
  333.       const PBYTEArray & rawPDU
  334.     );
  335.  
  336.     virtual BOOL IsCapability(
  337.       const H235_AuthenticationMechanism & mechansim,
  338.       const PASN_ObjectId & algorithmOID
  339.     );
  340.  
  341.     virtual BOOL SetCapability(
  342.       H225_ArrayOf_AuthenticationMechanism & mechansim,
  343.       H225_ArrayOf_PASN_ObjectId & algorithmOIDs
  344.     );
  345.  
  346.     virtual BOOL UseGkAndEpIdentifiers() const;
  347. };
  348.  
  349. #endif
  350.  
  351.  
  352. #endif //__OPAL_H235AUTH_H
  353.  
  354.  
  355. /////////////////////////////////////////////////////////////////////////////
  356.