h235auth.h

Go to the documentation of this file.
00001 /*
00002  * h235auth.h
00003  *
00004  * H.235 authorisation PDU's
00005  *
00006  * Open H323 Library
00007  *
00008  * Copyright (c) 1998-2001 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Open H323 Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Contributor(s): Fürbass Franz <franz.fuerbass@infonova.at>
00025  *
00026  * $Log: h235auth.h,v $
00027  * Revision 1.22  2006/06/23 03:15:58  shorne
00028  * Updated H.235 class name
00029  *
00030  * Revision 1.21  2006/01/26 03:25:55  shorne
00031  * Caller Authentication added
00032  *
00033  * Revision 1.20  2005/11/30 13:05:01  csoutheren
00034  * Changed tags for Doxygen
00035  *
00036  * Revision 1.19  2005/02/13 23:54:48  csoutheren
00037  * Allow access to H.235 timestamp grace period
00038  * Thanks to Jan Willamowius
00039  *
00040  * Revision 1.18  2004/11/20 22:00:48  csoutheren
00041  * Added hacks for linker problem
00042  *
00043  * Revision 1.17  2004/11/12 06:04:42  csoutheren
00044  * Changed H235Authentiators to use PFactory
00045  *
00046  * Revision 1.16  2004/05/13 02:26:13  dereksmithies
00047  * Fixes so make docs does not generate warning messages about brackets.
00048  *
00049  * Revision 1.15  2003/04/30 00:28:50  robertj
00050  * Redesigned the alternate credentials in ARQ system as old implementation
00051  *   was fraught with concurrency issues, most importantly it can cause false
00052  *   detection of replay attacks taking out an endpoint completely.
00053  *
00054  * Revision 1.14  2003/04/01 04:47:48  robertj
00055  * Abstracted H.225 RAS transaction processing (RIP and secondary thread) in
00056  *   server environment for use by H.501 peer elements.
00057  *
00058  * Revision 1.13  2003/02/25 06:48:14  robertj
00059  * More work on PDU transaction abstraction.
00060  *
00061  * Revision 1.12  2003/02/11 04:43:22  robertj
00062  * Fixed use of asymmetrical authentication schemes such as MD5.
00063  *
00064  * Revision 1.11  2003/02/01 13:31:14  robertj
00065  * Changes to support CAT authentication in RAS.
00066  *
00067  * Revision 1.10  2003/01/08 04:40:31  robertj
00068  * Added more debug tracing for H.235 authenticators.
00069  *
00070  * Revision 1.9  2002/09/16 01:14:15  robertj
00071  * Added #define so can select if #pragma interface/implementation is used on
00072  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00073  *
00074  * Revision 1.8  2002/09/03 06:19:36  robertj
00075  * Normalised the multi-include header prevention ifdef/define symbol.
00076  *
00077  * Revision 1.7  2002/08/05 10:03:47  robertj
00078  * Cosmetic changes to normalise the usage of pragma interface/implementation.
00079  *
00080  * Revision 1.6  2002/08/05 05:17:37  robertj
00081  * Fairly major modifications to support different authentication credentials
00082  *   in ARQ to the logged in ones on RRQ. For both client and server.
00083  * Various other H.235 authentication bugs and anomalies fixed on the way.
00084  *
00085  * Revision 1.5  2002/05/17 03:39:28  robertj
00086  * Fixed problems with H.235 authentication on RAS for server and client.
00087  *
00088  * Revision 1.4  2001/12/06 06:44:42  robertj
00089  * Removed "Win32 SSL xxx" build configurations in favour of system
00090  *   environment variables to select optional libraries.
00091  *
00092  * Revision 1.3  2001/09/14 00:13:37  robertj
00093  * Fixed problem with some athenticators needing extra conditions to be
00094  *   "active", so make IsActive() virtual and add localId to H235AuthSimpleMD5
00095  *
00096  * Revision 1.2  2001/09/13 01:15:18  robertj
00097  * Added flag to H235Authenticator to determine if gkid and epid is to be
00098  *   automatically set as the crypto token remote id and local id.
00099  *
00100  * Revision 1.1  2001/08/10 11:03:49  robertj
00101  * Major changes to H.235 support in RAS to support server.
00102  *
00103  */
00104 
00105 #ifndef __OPAL_H235AUTH_H
00106 #define __OPAL_H235AUTH_H
00107 
00108 #ifdef P_USE_PRAGMA
00109 #pragma interface
00110 #endif
00111 
00112 class H323TransactionPDU;
00113 class H225_CryptoH323Token;
00114 class H225_ArrayOf_AuthenticationMechanism;
00115 class H225_ArrayOf_PASN_ObjectId;
00116 class H235_ClearToken;
00117 class H235_AuthenticationMechanism;
00118 class PASN_ObjectId;
00119 class PASN_Sequence;
00120 class PASN_Array;
00121 
00122 class H323SignalPDU;
00123 class H323Connection;
00124 class PSSLCertificate;
00125 
00126 namespace PWLibStupidLinkerHacks {
00127 extern int h235AuthLoader;
00128 };
00129 
00133 class H235Authenticator : public PObject
00134 {
00135     PCLASSINFO(H235Authenticator, PObject);
00136   public:
00137     H235Authenticator();
00138 
00139     virtual void PrintOn(
00140       ostream & strm
00141     ) const;
00142 
00143     virtual const char * GetName() const = 0;
00144 
00145     virtual BOOL PrepareTokens(
00146       PASN_Array & clearTokens,
00147       PASN_Array & cryptoTokens
00148     );
00149 
00150     virtual H235_ClearToken * CreateClearToken();
00151     virtual H225_CryptoH323Token * CreateCryptoToken();
00152 
00153     virtual BOOL Finalise(
00154       PBYTEArray & rawPDU
00155     );
00156 
00157     enum ValidationResult {
00158       e_OK = 0,     
00159       e_Absent,     
00160       e_Error,      
00161       e_InvalidTime,
00162       e_BadPassword,
00163       e_ReplyAttack,
00164       e_Disabled    
00165     };
00166 
00167     virtual ValidationResult ValidateTokens(
00168       const PASN_Array & clearTokens,
00169       const PASN_Array & cryptoTokens,
00170       const PBYTEArray & rawPDU
00171     );
00172 
00173     virtual ValidationResult ValidateClearToken(
00174       const H235_ClearToken & clearToken
00175     );
00176 
00177     virtual ValidationResult ValidateCryptoToken(
00178       const H225_CryptoH323Token & cryptoToken,
00179       const PBYTEArray & rawPDU
00180     );
00181 
00182     virtual BOOL IsCapability(
00183       const H235_AuthenticationMechanism & mechansim,
00184       const PASN_ObjectId & algorithmOID
00185     ) = 0;
00186 
00187     virtual BOOL SetCapability(
00188       H225_ArrayOf_AuthenticationMechanism & mechansims,
00189       H225_ArrayOf_PASN_ObjectId & algorithmOIDs
00190     ) = 0;
00191 
00192     virtual BOOL UseGkAndEpIdentifiers() const;
00193 
00194     virtual BOOL IsSecuredPDU(
00195       unsigned rasPDU,
00196       BOOL received
00197     ) const;
00198 
00199     virtual BOOL IsSecuredSignalPDU(
00200       unsigned signalPDU,
00201       BOOL received
00202     ) const;
00203 
00204     virtual BOOL IsActive() const;
00205 
00206     virtual void Enable(
00207       BOOL enab = TRUE
00208     ) { enabled = enab; }
00209     virtual void Disable() { enabled = FALSE; }
00210 
00211     virtual const PString & GetRemoteId() const { return remoteId; }
00212     virtual void SetRemoteId(const PString & id) { remoteId = id; }
00213 
00214     virtual const PString & GetLocalId() const { return localId; }
00215     virtual void SetLocalId(const PString & id) { localId = id; }
00216 
00217     virtual const PString & GetPassword() const { return password; }
00218     virtual void SetPassword(const PString & pw) { password = pw; }
00219 
00220     virtual int GetTimestampGracePeriod() const { return timestampGracePeriod; }
00221     virtual void SetTimestampGracePeriod(int grace) { timestampGracePeriod = grace; }
00222 
00223     enum Application {
00224         GKAdmission,            
00225         EPAuthentication,       
00226         AnyApplication          
00227     };
00228 
00229     Application GetApplication() { return usage; }  // Get Authentication Application
00230 
00231     virtual void SetConnection(H323Connection * con);   // Set the connection for EPAuthentication
00232 
00233   protected:
00234     BOOL AddCapability(
00235       unsigned mechanism,
00236       const PString & oid,
00237       H225_ArrayOf_AuthenticationMechanism & mechansims,
00238       H225_ArrayOf_PASN_ObjectId & algorithmOIDs
00239     );
00240 
00241     BOOL     enabled;
00242 
00243     PString  remoteId;      // ID of remote entity
00244     PString  localId;       // ID of local entity
00245     PString  password;      // shared secret
00246 
00247     unsigned sentRandomSequenceNumber;
00248     unsigned lastRandomSequenceNumber;
00249     unsigned lastTimestamp;
00250     int      timestampGracePeriod;
00251 
00252     Application usage;         
00253     H323Connection * connection;   
00254     PMutex mutex;
00255 };
00256 
00257 
00258 PDECLARE_LIST(H235Authenticators, H235Authenticator)
00259 #ifdef DOC_PLUS_PLUS
00260 {
00261 #endif
00262   public:
00263 // GKAdmission
00264     void PreparePDU(
00265       H323TransactionPDU & pdu,
00266       PASN_Array & clearTokens,
00267       unsigned clearOptionalField,
00268       PASN_Array & cryptoTokens,
00269       unsigned cryptoOptionalField
00270     ) const;
00271 
00272     H235Authenticator::ValidationResult ValidatePDU(
00273       const H323TransactionPDU & pdu,
00274       const PASN_Array & clearTokens,
00275       unsigned clearOptionalField,
00276       const PASN_Array & cryptoTokens,
00277       unsigned cryptoOptionalField,
00278       const PBYTEArray & rawPDU
00279     ) const;
00280 
00281 // EPAuthentication
00282     void PrepareSignalPDU(
00283       unsigned code,
00284       PASN_Array & clearTokens,
00285       PASN_Array & cryptoTokens
00286     ) const;
00287 
00288     H235Authenticator::ValidationResult ValidateSignalPDU(
00289       unsigned code,
00290       const PASN_Array & clearTokens,
00291       const PASN_Array & cryptoTokens,
00292       const PBYTEArray & rawPDU
00293     ) const;
00294 
00295 };
00296 
00297 class H235AuthenticatorInfo : public PObject
00298 {
00299     PCLASSINFO(H235AuthenticatorInfo, PObject);
00300 public:
00301         H235AuthenticatorInfo(PString username,PString password,BOOL ishashed);
00302         H235AuthenticatorInfo(PSSLCertificate * cert);
00303         PString UserName;
00304         PString Password;
00305         BOOL isHashed;
00306         PSSLCertificate * Certificate;
00307 };
00308 
00309 PDECLARE_LIST(H235AuthenticatorList, H235AuthenticatorInfo)
00310 #ifdef DOC_PLUS_PLUS
00311 {
00312 #endif
00313         BOOL HasUserName(PString UserName) const;
00314         void LoadPassword(PString UserName, PString & pass) const;
00315         void Add(PString username, PString password, BOOL isHashed = FALSE);
00316         PString PasswordEncrypt(const PString &clear) const;
00317         PString PasswordDecrypt(const PString &encrypt) const;
00318 };
00319 
00321 PDICTIONARY(H235AuthenticatorDict,PString,H235AuthenticatorInfo); 
00322 
00327 class H235AuthSimpleMD5 : public H235Authenticator
00328 {
00329     PCLASSINFO(H235AuthSimpleMD5, H235Authenticator);
00330   public:
00331     H235AuthSimpleMD5();
00332 
00333     PObject * Clone() const;
00334 
00335     virtual const char * GetName() const;
00336 
00337     virtual H225_CryptoH323Token * CreateCryptoToken();
00338 
00339     virtual ValidationResult ValidateCryptoToken(
00340       const H225_CryptoH323Token & cryptoToken,
00341       const PBYTEArray & rawPDU
00342     );
00343 
00344     virtual BOOL IsCapability(
00345       const H235_AuthenticationMechanism & mechansim,
00346       const PASN_ObjectId & algorithmOID
00347     );
00348 
00349     virtual BOOL SetCapability(
00350       H225_ArrayOf_AuthenticationMechanism & mechansim,
00351       H225_ArrayOf_PASN_ObjectId & algorithmOIDs
00352     );
00353 
00354     virtual BOOL IsSecuredPDU(
00355       unsigned rasPDU,
00356       BOOL received
00357     ) const;
00358 };
00359 
00360 
00367 class H235AuthCAT : public H235Authenticator
00368 {
00369     PCLASSINFO(H235AuthCAT, H235Authenticator);
00370   public:
00371     H235AuthCAT();
00372 
00373     PObject * Clone() const;
00374 
00375     virtual const char * GetName() const;
00376 
00377     virtual H235_ClearToken * CreateClearToken();
00378 
00379     virtual ValidationResult ValidateClearToken(
00380       const H235_ClearToken & clearToken
00381     );
00382 
00383     virtual BOOL IsCapability(
00384       const H235_AuthenticationMechanism & mechansim,
00385       const PASN_ObjectId & algorithmOID
00386     );
00387 
00388     virtual BOOL SetCapability(
00389       H225_ArrayOf_AuthenticationMechanism & mechansim,
00390       H225_ArrayOf_PASN_ObjectId & algorithmOIDs
00391     );
00392 
00393     virtual BOOL IsSecuredPDU(
00394       unsigned rasPDU,
00395       BOOL received
00396     ) const;
00397 };
00398 
00399 
00400 #if P_SSL
00401 
00402 namespace PWLibStupidLinkerHacks {
00403 extern int h235AuthProcedure1Loader;
00404 };
00405 
00409 class H2351_Authenticator : public H235Authenticator
00410 {
00411     PCLASSINFO(H2351_Authenticator, H235Authenticator);
00412   public:
00413     H2351_Authenticator();
00414 
00415     PObject * Clone() const;
00416 
00417     virtual const char * GetName() const;
00418 
00419     virtual H225_CryptoH323Token * CreateCryptoToken();
00420 
00421     virtual BOOL Finalise(
00422       PBYTEArray & rawPDU
00423     );
00424 
00425     virtual ValidationResult ValidateCryptoToken(
00426       const H225_CryptoH323Token & cryptoToken,
00427       const PBYTEArray & rawPDU
00428     );
00429 
00430     virtual BOOL IsCapability(
00431       const H235_AuthenticationMechanism & mechansim,
00432       const PASN_ObjectId & algorithmOID
00433     );
00434 
00435     virtual BOOL SetCapability(
00436       H225_ArrayOf_AuthenticationMechanism & mechansim,
00437       H225_ArrayOf_PASN_ObjectId & algorithmOIDs
00438     );
00439 
00440     virtual BOOL UseGkAndEpIdentifiers() const;
00441 };
00442 
00443 typedef H2351_Authenticator H235AuthProcedure1;  // Backwards interoperability
00444 
00445 #endif
00446 
00447 
00448 #endif //__OPAL_H235AUTH_H
00449 
00450 

Generated on Wed Feb 6 09:02:26 2008 for OpenH323 by  doxygen 1.5.4