r3088 - in trunk/libmikey: include/libmikey keyagreement mikey

mikma at minisip.org mikma at minisip.org
Thu Jan 4 20:05:52 CET 2007


Author: mikma
Date: 2007-01-04 20:05:51 +0100 (Thu, 04 Jan 2007)
New Revision: 3088

Modified:
   trunk/libmikey/include/libmikey/KeyAgreementDHHMAC.h
   trunk/libmikey/include/libmikey/MikeyException.h
   trunk/libmikey/include/libmikey/MikeyMessage.h
   trunk/libmikey/include/libmikey/MikeyPayloadSP.h
   trunk/libmikey/keyagreement/KeyAgreementDHHMAC.cxx
   trunk/libmikey/mikey/MikeyMessage.cxx
   trunk/libmikey/mikey/MikeyMessageDHHMAC.cxx
   trunk/libmikey/mikey/MikeyMessagePKE.cxx
   trunk/libmikey/mikey/MikeyMessagePSK.cxx
   trunk/libmikey/mikey/MikeyPayloadHDR.cxx
   trunk/libmikey/mikey/MikeyPayloadKEMAC.cxx
   trunk/libmikey/mikey/MikeyPayloadSP.cxx
Log:
Reduce code duplication in libmikey by:

* Using KeyAgreementDHBase as super class of KeyAgreementDHHMAC, and
* using verifyKemac and verifyV where possible
* implementing MikeyPayloads::verifyMac.



Modified: trunk/libmikey/include/libmikey/KeyAgreementDHHMAC.h
===================================================================
--- trunk/libmikey/include/libmikey/KeyAgreementDHHMAC.h	2007-01-04 17:08:45 UTC (rev 3087)
+++ trunk/libmikey/include/libmikey/KeyAgreementDHHMAC.h	2007-01-04 19:05:51 UTC (rev 3088)
@@ -30,7 +30,7 @@
 #include<libmikey/libmikey_config.h>
 
 #include<libmikey/keyagreement_psk.h>
-#include<libmcrypto/OakleyDH.h>
+#include<libmikey/keyagreement_dh.h>
 #include<libmutil/mtypes.h>
 
 /**
@@ -38,41 +38,15 @@
  * for Multimedia Internet KEYing (MIKEY)
  * RFC 4650
  */
-class LIBMIKEY_API KeyAgreementDHHMAC : public KeyAgreementPSK{
+class LIBMIKEY_API KeyAgreementDHHMAC : public virtual KeyAgreementPSK,
+					public virtual KeyAgreementDHBase{
 	public:
-		KeyAgreementDHHMAC( byte_t * psk, int pskLength,
-				    int groupValue = -1 );
+		KeyAgreementDHHMAC( byte_t * psk, int pskLength );
 		~KeyAgreementDHHMAC();
 
 		int32_t type();
 
-		int setGroup( int group );
-		int group();
-
-// 		void setAuthKey( int macAlg, byte_t *authKey,
-// 				 unsigned int authKeyLength );
-// 		int getMacAlg();
-
-		void setPeerKey( byte_t * peerKey, int peerKeyLength );
-		int peerKeyLength();
-		byte_t * peerKey();
-
-		int publicKeyLength();
-		byte_t * publicKey();
-
-		int computeTgk();
-
 		MikeyMessage* createMessage();
-
-	private:
-		OakleyDH * dh;
-
-		byte_t * peerKeyPtr;
-		int peerKeyLengthValue;
-
-// 		byte_t * m_authKey;
-// 		unsigned int m_authKeyLength;
-// 		int m_macAlg;
 };
 
 #endif

Modified: trunk/libmikey/include/libmikey/MikeyException.h
===================================================================
--- trunk/libmikey/include/libmikey/MikeyException.h	2007-01-04 17:08:45 UTC (rev 3087)
+++ trunk/libmikey/include/libmikey/MikeyException.h	2007-01-04 19:05:51 UTC (rev 3088)
@@ -34,9 +34,9 @@
  * @version 0.01
  */
 
-#include<libmikey/MikeyMessage.h>
 #include<libmutil/Exception.h>
 
+class MikeyMessage;
 
 
 class LIBMIKEY_API MikeyException : public Exception{

Modified: trunk/libmikey/include/libmikey/MikeyMessage.h
===================================================================
--- trunk/libmikey/include/libmikey/MikeyMessage.h	2007-01-04 17:08:45 UTC (rev 3087)
+++ trunk/libmikey/include/libmikey/MikeyMessage.h	2007-01-04 19:05:51 UTC (rev 3088)
@@ -93,7 +93,8 @@
 				byte_t * authKey,
 				int encrAlg, int macAlg,
 				bool kemacOnly = false );
-		bool verifyKemac( KeyAgreementPSK* ka ) const;
+		bool verifyKemac( KeyAgreementPSK* ka,
+				  bool kemacOnly = false );
 
 		void addCertificatePayloads( MRef<certificate_chain *> certChain );
 		MRef<certificate_chain*> extractCertificateChain() const;
@@ -131,6 +132,11 @@
 		 */
 		void setRawMessageData( byte_t *data );
 
+		bool verifyMac( KeyAgreementPSK* ka, int macAlg,
+				const byte_t* receivedMac,
+				const byte_t* macInput,
+				unsigned int macInputLength ) const;
+
 		std::list<MikeyPayload *> payloads;
 
 	private:

Modified: trunk/libmikey/include/libmikey/MikeyPayloadSP.h
===================================================================
--- trunk/libmikey/include/libmikey/MikeyPayloadSP.h	2007-01-04 17:08:45 UTC (rev 3087)
+++ trunk/libmikey/include/libmikey/MikeyPayloadSP.h	2007-01-04 19:05:51 UTC (rev 3088)
@@ -139,6 +139,8 @@
 		virtual int length();
 		//Return number of policy param entries
 		int noOfPolicyParam();
+		std::string debugDump();
+
 		uint8_t policy_no;
 		uint8_t prot_type;
 		

Modified: trunk/libmikey/keyagreement/KeyAgreementDHHMAC.cxx
===================================================================
--- trunk/libmikey/keyagreement/KeyAgreementDHHMAC.cxx	2007-01-04 17:08:45 UTC (rev 3087)
+++ trunk/libmikey/keyagreement/KeyAgreementDHHMAC.cxx	2007-01-04 19:05:51 UTC (rev 3088)
@@ -24,34 +24,18 @@
 */
 
 #include<config.h>
-#include<libmcrypto/rand.h>
 #include<libmikey/MikeyMessage.h>
 #include<libmikey/MikeyException.h>
 #include<libmikey/KeyAgreementDHHMAC.h>
-#include<libmcrypto/OakleyDH.h>
 
 #include<string>
 
 using namespace std;
 
 KeyAgreementDHHMAC::KeyAgreementDHHMAC( unsigned char * pskPtr,
-					int pskLengthValue,
-					int groupValue )
+					int pskLengthValue )
 		:KeyAgreementPSK(pskPtr, pskLengthValue),
-		 dh( NULL ), peerKeyPtr( NULL ), peerKeyLengthValue( 0 ){
-// 		 m_authKey( NULL ),
-// 		 m_authKeyLength( 0 ), m_macAlg( 0 ){
-	dh = new OakleyDH();
-	if( dh == NULL )
-	{
-		throw MikeyException( "Could not create "
-				          "DH parameters." );
-	}
-
-	if( groupValue >= 0 && setGroup( groupValue ) ){
-		throw MikeyException( "Could not set the  "
-				      "DH group." );
-	}
+		 KeyAgreementDHBase(){
 }
 
 KeyAgreementDHHMAC::~KeyAgreementDHHMAC(){
@@ -61,75 +45,6 @@
 	return KEY_AGREEMENT_TYPE_DHHMAC;
 }
 
-int KeyAgreementDHHMAC::setGroup( int groupValue ){
-	if( !dh->setGroup( groupValue ) )
-		return 1;
-
-	uint32_t len = dh->secretLength();
-
-	if( len != tgkLength() || !tgk() ){
-		setTgk( NULL, len );
-	}
-
-	return 0;
-}
-
-int KeyAgreementDHHMAC::group(){
-	return dh->group();
-
-}
-
-// void KeyAgreementDHHMAC::setAuthKey( int macAlg, byte_t *authKey,
-// 				     unsigned int authKeyLength ){
-// 	m_macAlg = macAlg;
-// 	m_authKey = authKey;
-// 	m_authKeyLength = authKeyLength;
-// }
-
-// int KeyAgreementDHHMAC::getMacAlg(){
-// 	return m_macAlg;
-// }
-
-void KeyAgreementDHHMAC::setPeerKey( unsigned char * peerKeyPtr,
-			      int peerKeyLengthValue ){
-	if( this->peerKeyPtr )
-		delete[] this->peerKeyPtr;
-
-	this->peerKeyPtr = new unsigned char[ peerKeyLengthValue ];
-	this->peerKeyLengthValue = peerKeyLengthValue;
-	memcpy( this->peerKeyPtr, peerKeyPtr, peerKeyLengthValue );
-
-}
-
-int KeyAgreementDHHMAC::peerKeyLength(){
-	return peerKeyLengthValue;
-}
-
-unsigned char * KeyAgreementDHHMAC::peerKey(){
-	return peerKeyPtr;
-}
-
-int KeyAgreementDHHMAC::publicKeyLength(){
-	return dh->publicKeyLength();
-}
-
-unsigned char * KeyAgreementDHHMAC::publicKey(){
-	unsigned char * publicKey;
-	uint32_t length = publicKeyLength();
-	publicKey = new unsigned char[ length ];
-	dh->getPublicKey( publicKey, length );
-	return publicKey;
-
-}
-
-int KeyAgreementDHHMAC::computeTgk(){
-	assert( peerKeyPtr );
-
-	int res = dh->computeSecret( peerKeyPtr, peerKeyLengthValue,
-				     tgk(), tgkLength() );
-	return res;
-}
-
 MikeyMessage* KeyAgreementDHHMAC::createMessage(){
 	return MikeyMessage::create( this );
 }

Modified: trunk/libmikey/mikey/MikeyMessage.cxx
===================================================================
--- trunk/libmikey/mikey/MikeyMessage.cxx	2007-01-04 17:08:45 UTC (rev 3087)
+++ trunk/libmikey/mikey/MikeyMessage.cxx	2007-01-04 19:05:51 UTC (rev 3088)
@@ -817,7 +817,7 @@
 }
 
 bool MikeyPayloads::verifySignature( MRef<certificate*> cert ){
-	MikeyPayloadSIGN* sig = (MikeyPayloadSIGN*)extractPayload(MIKEYPAYLOAD_SIGN_PAYLOAD_TYPE);
+	MikeyPayloadSIGN* sig = dynamic_cast<MikeyPayloadSIGN*>(extractPayload(MIKEYPAYLOAD_SIGN_PAYLOAD_TYPE));
 
 	if( !sig ){
 		return false;
@@ -830,51 +830,41 @@
 	return res > 0;
 }
 
-bool MikeyPayloads::verifyKemac( KeyAgreementPSK* ka ) const{
+bool MikeyPayloads::verifyKemac( KeyAgreementPSK* ka,
+				 bool kemacOnly ){
 	int macAlg;
 	byte_t * receivedMac;
 	byte_t * macInput;
 	unsigned int macInputLength;
 	MikeyPayloadKEMAC * kemac;
 
-	kemac = (MikeyPayloadKEMAC *) extractPayload(MIKEYPAYLOAD_KEMAC_PAYLOAD_TYPE);
+	kemac = dynamic_cast<MikeyPayloadKEMAC *>(extractPayload(MIKEYPAYLOAD_KEMAC_PAYLOAD_TYPE));
+
+	if( !kemac ){
+		return false;
+	}
+
 	macAlg = kemac->macAlg();
 	receivedMac = kemac->macData();
 		
-	macInputLength = kemac->length();
-	macInput = new byte_t[macInputLength];
+	if( kemacOnly ){
+		macInputLength = kemac->length();
+		macInput = new byte_t[macInputLength];
+		kemac->writeData( macInput, macInputLength );
+		macInput[0] = MIKEYPAYLOAD_LAST_PAYLOAD;
+	}
+	else{
+		macInputLength = rawMessageLength();
+		macInput = new byte_t[macInputLength];
+		memcpy( macInput, rawMessageData(), rawMessageLength() );
+	}
 
-	kemac->writeData( macInput, macInputLength );
-	macInput[0] = MIKEYPAYLOAD_LAST_PAYLOAD;
 	macInputLength -= 20; // Subtract mac data
+	bool ret = verifyMac( ka, macAlg, receivedMac,
+			      macInput, macInputLength );
 
-	byte_t authKey[20];
-	byte_t computedMac[20];
-	unsigned int computedMacLength;
-	
-	switch( macAlg ){
-		case MIKEY_MAC_HMAC_SHA1_160:
-			ka->genTranspAuthKey( authKey, 20 );
-
-			hmac_sha1( authKey, 20,
-				   macInput,
-				   macInputLength,
-				   computedMac, &computedMacLength );
-
-			for( int i = 0; i < 20; i++ ){
-				if( computedMac[i] != receivedMac[i] ){
-					ka->setAuthError(
-						"MAC mismatch."
-					);
-					return false;
-				}
-			}
-			return true;
-		case MIKEY_MAC_NULL:
-			return true;
-		default:
-			throw MikeyException( "Unknown MAC algorithm" );
-	}
+	delete[] macInput;
+	return ret;
 }
 
 bool MikeyPayloads::verifyV( KeyAgreementPSK* ka ){
@@ -885,7 +875,12 @@
 	MikeyPayloadV * v;
 	uint64_t t_sent = ka->tSent();
 
-	v = (MikeyPayloadV *)extractPayload(MIKEYPAYLOAD_V_PAYLOAD_TYPE );
+	v = dynamic_cast<MikeyPayloadV*>(extractPayload(MIKEYPAYLOAD_V_PAYLOAD_TYPE));
+
+	if( !v ){
+		return false;
+	}
+
 	macAlg = v->macAlg();
 	receivedMac = v->verData();
 	// macInput = raw_messsage without mac / sent_t
@@ -898,8 +893,17 @@
 			(byte_t)((t_sent >> (i*8))&0xFF);
 	}
 
-	// TODO Refactor code duplication
+	bool ret = verifyMac( ka, macAlg, receivedMac,
+			      macInput, macInputLength );
 
+	delete[] macInput;
+	return ret;
+}
+
+bool MikeyPayloads::verifyMac( KeyAgreementPSK* ka, int macAlg,
+			       const byte_t* receivedMac,
+			       const byte_t* macInput,
+			       unsigned int macInputLength ) const{
 	byte_t authKey[20];
 	byte_t computedMac[20];
 	unsigned int computedMacLength;

Modified: trunk/libmikey/mikey/MikeyMessageDHHMAC.cxx
===================================================================
--- trunk/libmikey/mikey/MikeyMessageDHHMAC.cxx	2007-01-04 17:08:45 UTC (rev 3087)
+++ trunk/libmikey/mikey/MikeyMessageDHHMAC.cxx	2007-01-04 19:05:51 UTC (rev 3088)
@@ -38,8 +38,6 @@
 #include<libmikey/MikeyPayloadRAND.h>
 #include<libmikey/MikeyPayloadT.h>
 
-#include<libmcrypto/hmac.h>
-
 #include<map>
 
 using namespace std;
@@ -185,9 +183,12 @@
 			new MikeyPayloadERR( MIKEY_ERR_TYPE_UNSPEC ) );
 	}
 
-
 	if( ka->group() != ((MikeyPayloadDH *)i)->group() ){
-		ka->setGroup( ((MikeyPayloadDH *)i)->group() );
+		if( ka->setGroup( ((MikeyPayloadDH *)i)->group() ) ){
+			error = true;
+			errorMessage->addPayload(
+				new MikeyPayloadERR( MIKEY_ERR_TYPE_INVALID_DH ) );
+		}
 	}
 
 	ka->setPeerKey( ((MikeyPayloadDH *)i)->dhKey(),
@@ -204,30 +205,15 @@
 		errorMessage->addPayload( 
 			new MikeyPayloadERR( MIKEY_ERR_TYPE_UNSPEC ) );
 	}	
+	else{
+		ka->macAlg = ((MikeyPayloadKEMAC*)i)->macAlg();;
+	}
 
-	// KMAC
-#define kemac ((MikeyPayloadKEMAC *)i)
-	int encrAlg = kemac->encrAlg();
-	int macAlg  = kemac->macAlg();
-
-	byte_t* encrKey = NULL;
-	byte_t* iv = NULL;
-	unsigned int encrKeyLength = 0;
-
-
-	error |= !deriveTranspKeys( ka, encrKey, iv, encrKeyLength,
-				    encrAlg, macAlg, 0, errorMessage );
-// 	ka->setAuthKey( macAlg, authKey, authKeyLength);
-
-	if( encrKey )
-		delete[] encrKey;
-	if( iv )
-		delete[] iv;
-
 	if( error ){
 		throw MikeyExceptionMessageContent( errorMessage );
 	}
-#undef kemac
+
+// 	ka->computeTgk();
 }
 //-----------------------------------------------------------------------------------------------//
 //
@@ -404,6 +390,8 @@
 
 	delete errorMessage;
 
+// 	ka->computeTgk();
+
 	return NULL;
 }
 
@@ -416,12 +404,6 @@
 	}
 
 	MikeyPayload * payload = *(lastPayload());
-	int i;
-	int macAlg;
-	byte_t * receivedMac;
-	byte_t * macInput;
-	unsigned int macInputLength;
-	list<MikeyPayload *>::iterator payload_i;
  
 	if( ka->rand() == NULL ){
 		
@@ -443,56 +425,24 @@
 	}
 
 	
-	if( type() == HDR_DATA_TYPE_DHHMAC_INIT ||
-	    type() == HDR_DATA_TYPE_DHHMAC_RESP ){
-		MikeyPayloadKEMAC * kemac;
+	if( isInitiatorMessage() || isResponderMessage() ){
 		if( payload->payloadType() != MIKEYPAYLOAD_KEMAC_PAYLOAD_TYPE){
 			cerr << "Last payload type = " << (int)payload->payloadType() << endl;
 			throw MikeyException( 
 			   "DHHMAC init did not end with a KEMAC payload" );
 		}
 		
-
-		kemac = (MikeyPayloadKEMAC *)payload;
-		macAlg = kemac->macAlg();
-		receivedMac = kemac->macData();
-		macInput = rawMessageData();
-		macInputLength = rawMessageLength() - 20;
 		ka->setCsbId( csbId() );
+
+		if( !verifyKemac( ka, false ) ){
+			return true;
+		}
+		return false;
 	}
 	else{
 		throw MikeyException( "Invalide type for a DHHMAC message" );
 	}
 
-	byte_t authKey[20];
-	byte_t computedMac[20];
-	unsigned int computedMacLength;
-	
-	switch( macAlg ){
-		case MIKEY_MAC_HMAC_SHA1_160:
-			ka->genTranspAuthKey( authKey, 20 );
-
-			hmac_sha1( authKey, 20,
-				   macInput,
-				   macInputLength,
-				   computedMac, &computedMacLength );
-
-			for( i = 0; i < 20; i++ ){
-				if( computedMac[i] != receivedMac[i] ){
-					ka->setAuthError(
-						"MAC mismatch: the shared"
-						"key probably differs."
-					);
-					return true;
-				}
-			}
-			return false;
-		case MIKEY_MAC_NULL:
-			return false;
-		default:
-			throw MikeyException( "Unknown MAC algorithm" );
-	}
-
 }
 
 bool MikeyMessageDHHMAC::isInitiatorMessage() const{

Modified: trunk/libmikey/mikey/MikeyMessagePKE.cxx
===================================================================
--- trunk/libmikey/mikey/MikeyMessagePKE.cxx	2007-01-04 17:08:45 UTC (rev 3087)
+++ trunk/libmikey/mikey/MikeyMessagePKE.cxx	2007-01-04 19:05:51 UTC (rev 3088)
@@ -38,8 +38,6 @@
 #include <libmikey/MikeyPayloadKEMAC.h>
 #include <libmikey/MikeyPayloadV.h>
 #include <libmikey/MikeyPayloadPKE.h>
-#include <libmcrypto/aes.h>
-#include <libmcrypto/hmac.h>
 
 using namespace std;
 
@@ -115,6 +113,10 @@
 	MRef<certificate*> certResponder =
 		ka->peerCertificateChain()->get_first();
 
+	if( !certResponder ){
+		throw MikeyException( "PKE requires peer certificate" );
+	}
+
 	byte_t* env_key = ka->getEnvelopeKey();
 	int encEnvKeyLength = 8192; // TODO autodetect?
 	unsigned char* encEnvKey = new unsigned char[ encEnvKeyLength ];
@@ -468,7 +470,7 @@
 			throw MikeyException( "Decryption of envelope key failed" );
 		}
 
-		if( !verifyKemac( ka ) ){
+		if( !verifyKemac( ka, true ) ){
 			return true;
 		}
 

Modified: trunk/libmikey/mikey/MikeyMessagePSK.cxx
===================================================================
--- trunk/libmikey/mikey/MikeyMessagePSK.cxx	2007-01-04 17:08:45 UTC (rev 3087)
+++ trunk/libmikey/mikey/MikeyMessagePSK.cxx	2007-01-04 19:05:51 UTC (rev 3088)
@@ -38,8 +38,6 @@
 #include<libmikey/keyagreement_psk.h>
 #include<libmikey/MikeyPayloadSP.h>
 
-#include<libmcrypto/hmac.h>
-
 using namespace std;
 
 MikeyMessagePSK::MikeyMessagePSK(){
@@ -184,6 +182,7 @@
 			new MikeyPayloadERR( MIKEY_ERR_TYPE_UNSPEC ) );
 	}	
 
+	// FIXME i can be NULL
 	ka->setRand( ((MikeyPayloadRAND *)i)->randData(),
 			((MikeyPayloadRAND *)i)->randLength() );
 
@@ -203,6 +202,7 @@
 			new MikeyPayloadERR( MIKEY_ERR_TYPE_UNSPEC ) );
 	}	
 
+	// FIXME i can be NULL
 #define kemac ((MikeyPayloadKEMAC *)i)
 	int encrAlg = kemac->encrAlg();
 	int macAlg  = kemac->macAlg();
@@ -351,6 +351,7 @@
 			new MikeyPayloadERR( MIKEY_ERR_TYPE_UNSPEC ) );
 	}	
 
+	// FIXME i can be NULL
 	if( ((MikeyPayloadT*)i)->checkOffset( MAX_TIME_OFFSET ) ){
 		error = true;
 		errorMessage->addPayload( 
@@ -383,12 +384,6 @@
 	}
 
 	MikeyPayload * payload = *(lastPayload());
-	int i;
-	int macAlg;
-	byte_t * receivedMac;
-	byte_t * macInput;
-	unsigned int macInputLength;
-	list<MikeyPayload *>::iterator payload_i;
  
 	if( ka->rand() == NULL ){
 		
@@ -409,81 +404,38 @@
 			     randPayload->randLength() );
 	}
 
-	if( type() == HDR_DATA_TYPE_PSK_INIT )
+	if( isInitiatorMessage() )
 	{
-		MikeyPayloadKEMAC * kemac;
 		if( payload->payloadType() != MIKEYPAYLOAD_KEMAC_PAYLOAD_TYPE){
 			throw MikeyException( 
 			   "PSK init did not end with a KEMAC payload" );
 		}
 		
-
-		kemac = (MikeyPayloadKEMAC *)payload;
-		macAlg = kemac->macAlg();
-		receivedMac = kemac->macData();
-		macInput = rawMessageData();
-		macInputLength = rawMessageLength() - 20;
 		ka->setCsbId( csbId() );
+
+		if( !verifyKemac( ka, false ) ){
+			return true;
+		}
+
+		return false;
+
 	}
-	else if( type() == HDR_DATA_TYPE_PSK_RESP )
+	else if( isResponderMessage() )
 	{
 		if( ka->csbId() != csbId() ){
 			ka->setAuthError( "CSBID mismatch\n" );
 			return true;
 		}
-		MikeyPayloadV * v;
-		uint64_t t_sent = ka->tSent();
-		if( payload->payloadType() != MIKEYPAYLOAD_V_PAYLOAD_TYPE ){
-			throw MikeyException( 
-			   "PSK response did not end with a V payload" );
-		}
 
-		v = (MikeyPayloadV *)payload;
-		macAlg = v->macAlg();
-		receivedMac = v->verData();
-		// macInput = raw_messsage without mac / sent_t
-		macInputLength = rawMessageLength() - 20 + 8;
-		macInput = new byte_t[macInputLength];
-		memcpy( macInput, rawMessageData(), rawMessageLength() - 20 );
-		
-		for( i = 0; i < 8; i++ ){
-			macInput[ macInputLength - i - 1 ] = 
-				(byte_t)((t_sent >> (i*8))&0xFF);
+		if( !verifyV( ka ) ){
+			return true;
 		}
+
+		return false;
 	}
 	else{
 		throw MikeyException( "Invalide type for a PSK message" );
 	}
-
-	byte_t authKey[20];
-	byte_t computedMac[20];
-	unsigned int computedMacLength;
-	
-	switch( macAlg ){
-		case MIKEY_MAC_HMAC_SHA1_160:
-			ka->genTranspAuthKey( authKey, 20 );
-
-			hmac_sha1( authKey, 20,
-				   macInput,
-				   macInputLength,
-				   computedMac, &computedMacLength );
-
-			for( i = 0; i < 20; i++ ){
-				if( computedMac[i] != receivedMac[i] ){
-					ka->setAuthError(
-						"MAC mismatch: the shared"
-						"key probably differs."
-					);
-					return true;
-				}
-			}
-			return false;
-		case MIKEY_MAC_NULL:
-			return false;
-		default:
-			throw MikeyException( "Unknown MAC algorithm" );
-	}
-
 }
 
 bool MikeyMessagePSK::isInitiatorMessage() const{

Modified: trunk/libmikey/mikey/MikeyPayloadHDR.cxx
===================================================================
--- trunk/libmikey/mikey/MikeyPayloadHDR.cxx	2007-01-04 17:08:45 UTC (rev 3087)
+++ trunk/libmikey/mikey/MikeyPayloadHDR.cxx	2007-01-04 19:05:51 UTC (rev 3088)
@@ -150,6 +150,18 @@
 		case HDR_DATA_TYPE_DH_RESP:
 			ret=ret+"<D-H resp>";
 			break;
+		case HDR_DATA_TYPE_DHHMAC_INIT:
+			ret=ret+"<D-H init>";
+			break;
+		case HDR_DATA_TYPE_DHHMAC_RESP:
+			ret=ret+"<D-H resp>";
+			break;
+		case HDR_DATA_TYPE_RSA_R_INIT:
+			ret=ret+"<RSA-R init>";
+			break;
+		case HDR_DATA_TYPE_RSA_R_RESP:
+			ret=ret+"<RSA-R resp>";
+			break;
 		case HDR_DATA_TYPE_ERROR:
 			ret=ret+"<Error>";
 			break;

Modified: trunk/libmikey/mikey/MikeyPayloadKEMAC.cxx
===================================================================
--- trunk/libmikey/mikey/MikeyPayloadKEMAC.cxx	2007-01-04 17:08:45 UTC (rev 3087)
+++ trunk/libmikey/mikey/MikeyPayloadKEMAC.cxx	2007-01-04 19:05:51 UTC (rev 3088)
@@ -23,6 +23,7 @@
 
 
 #include<config.h>
+#include<libmikey/MikeyMessage.h>
 #include<libmikey/MikeyPayloadKEMAC.h>
 #include<libmikey/MikeyException.h>
 #include<assert.h>

Modified: trunk/libmikey/mikey/MikeyPayloadSP.cxx
===================================================================
--- trunk/libmikey/mikey/MikeyPayloadSP.cxx	2007-01-04 17:08:45 UTC (rev 3087)
+++ trunk/libmikey/mikey/MikeyPayloadSP.cxx	2007-01-04 19:05:51 UTC (rev 3088)
@@ -132,3 +132,19 @@
 			i=param.erase(i);
 		}
 }
+
+std::string MikeyPayloadSP::debugDump(){
+	string ret = "MikeyPayloadSP: next_payload<" + itoa( nextPayloadTypeValue ) + "> ";
+
+	ret += string("policyNo: <") + itoa( policy_no ) + "> ";
+	ret += string("protType: <") + itoa( prot_type ) + ">\n";
+
+	list<MikeyPolicyParam *>::iterator i = param.begin();
+	for( ; i != param.end(); i++ ){
+		ret += string("type: <") + itoa( (*i)->type ) + "> ";
+		ret += string("value: <")
+		       + binToHex( (*i)->value, (*i)->length ) + ">\n";
+	}
+	
+	return ret;
+}



More information about the Minisip-devel mailing list