r3114 - in trunk: libmcrypto/include/libmcrypto libmcrypto/source
libmcrypto/source/gnutls libmcrypto/source/openssl
libmikey/include/libmikey libmikey/mikey
xuan at minisip.org
xuan at minisip.org
Sun Jan 14 16:35:25 CET 2007
Author: xuan
Date: 2007-01-14 16:35:24 +0100 (Sun, 14 Jan 2007)
New Revision: 3114
Modified:
trunk/libmcrypto/include/libmcrypto/SipSim.h
trunk/libmcrypto/include/libmcrypto/SipSimSmartCardGD.h
trunk/libmcrypto/include/libmcrypto/SipSimSoft.h
trunk/libmcrypto/include/libmcrypto/SmartCard.h
trunk/libmcrypto/include/libmcrypto/rand.h
trunk/libmcrypto/source/SipSimSmartCardGD.cxx
trunk/libmcrypto/source/SipSimSoft.cxx
trunk/libmcrypto/source/gnutls/rand.cxx
trunk/libmcrypto/source/openssl/rand.cxx
trunk/libmikey/include/libmikey/MikeyPayloadRAND.h
trunk/libmikey/mikey/MikeyMessageDH.cxx
trunk/libmikey/mikey/MikeyPayloadRAND.cxx
Log:
added getRandomVaule function to SipSim class;
added random value generating function from the smart card in Rand class;
added the smart card random value generation when the MikeyMessageDH is constructed.
Modified: trunk/libmcrypto/include/libmcrypto/SipSim.h
===================================================================
--- trunk/libmcrypto/include/libmcrypto/SipSim.h 2007-01-11 18:56:26 UTC (rev 3113)
+++ trunk/libmcrypto/include/libmcrypto/SipSim.h 2007-01-14 15:35:24 UTC (rev 3114)
@@ -49,6 +49,8 @@
int & signatureLength,
bool doHash,
int hash_alg=HASH_SHA1) = 0;
+
+ virtual bool getRandomValue(unsigned char * randomPtr, unsigned long randomLength) = 0;
virtual void setCertificateChain(MRef<certificate_chain *> c){certChain = c;}
virtual MRef<certificate_chain *> getCertificateChain(){return certChain;}
Modified: trunk/libmcrypto/include/libmcrypto/SipSimSmartCardGD.h
===================================================================
--- trunk/libmcrypto/include/libmcrypto/SipSimSmartCardGD.h 2007-01-11 18:56:26 UTC (rev 3113)
+++ trunk/libmcrypto/include/libmcrypto/SipSimSmartCardGD.h 2007-01-14 15:35:24 UTC (rev 3114)
@@ -54,7 +54,7 @@
/* This method returns pointer which points to an expected length of random value
It is the user's responsibility to free the allocated memory by calling delete.
the randomLength is in bits*/
- unsigned char * getRandomValue(unsigned long randomLength);
+ bool getRandomValue(unsigned char * randomPtr, unsigned long randomLength);
bool getSignature(unsigned char * dataPtr, int dataLength, unsigned char *signaturePtr, int& signatureLength,
bool doHash, int hash_alg=HASH_SHA1);
Modified: trunk/libmcrypto/include/libmcrypto/SipSimSoft.h
===================================================================
--- trunk/libmcrypto/include/libmcrypto/SipSimSoft.h 2007-01-11 18:56:26 UTC (rev 3113)
+++ trunk/libmcrypto/include/libmcrypto/SipSimSoft.h 2007-01-14 15:35:24 UTC (rev 3114)
@@ -21,8 +21,9 @@
int & signatureLength,
bool doHash,
int hash_alg=HASH_SHA1);
+
+ virtual bool getRandomValue(unsigned char * randomPtr, unsigned long randomLength);
-
private:
};
Modified: trunk/libmcrypto/include/libmcrypto/SmartCard.h
===================================================================
--- trunk/libmcrypto/include/libmcrypto/SmartCard.h 2007-01-11 18:56:26 UTC (rev 3113)
+++ trunk/libmcrypto/include/libmcrypto/SmartCard.h 2007-01-14 15:35:24 UTC (rev 3114)
@@ -56,10 +56,6 @@
virtual bool verifyPin(int verifyMode) = 0;
virtual bool changePin( const char * newPinCode) = 0;
- /* General smart card member function */
- virtual unsigned char * getRandomValue(unsigned long randomLength) = 0;
- //virtual unsigned char * getCertificate();
-
protected:
/* This is used each time right before you read from or write on smart card. To check out whether the connection has been established */
Modified: trunk/libmcrypto/include/libmcrypto/rand.h
===================================================================
--- trunk/libmcrypto/include/libmcrypto/rand.h 2007-01-11 18:56:26 UTC (rev 3113)
+++ trunk/libmcrypto/include/libmcrypto/rand.h 2007-01-14 15:35:24 UTC (rev 3114)
@@ -26,6 +26,8 @@
#include <libmcrypto/config.h>
#include <stddef.h>
+#include <libmutil/MemObject.h>
+#include <libmcrypto/SipSim.h>
class LIBMCRYPTO_API Rand {
public:
@@ -35,6 +37,7 @@
* Generate cryptographically strong random data
*/
static bool randomize(void *buffer, size_t length);
+ static bool randomize(void *buffer, size_t length, MRef<SipSim *> sim);
};
#endif
Modified: trunk/libmcrypto/source/SipSimSmartCardGD.cxx
===================================================================
--- trunk/libmcrypto/source/SipSimSmartCardGD.cxx 2007-01-11 18:56:26 UTC (rev 3113)
+++ trunk/libmcrypto/source/SipSimSmartCardGD.cxx 2007-01-14 15:35:24 UTC (rev 3114)
@@ -261,24 +261,19 @@
throw SmartCardException("Either the smart card connection has not been established or access level is not sufficient");
}
-unsigned char * SipSimSmartCardGD::getRandomValue(unsigned long randomLength){
+bool SipSimSmartCardGD::getRandomValue(unsigned char * randomPtr, unsigned long randomLength){
if(establishedConnection == true && verifiedCard == 1 && blockedCard == 0){
+
unsigned char * tempBuffer;
- unsigned char * randomValuePtr;
-
- unsigned long randomLengthInBytes;
- randomLengthInBytes = randomLength/8;
sendBufferLength = 5;
- recvBufferLength = 2 + randomLengthInBytes;
+ recvBufferLength = 2 + randomLength;
clearBuffer();
sendBuffer = new unsigned char[sendBufferLength];
recvBuffer = new unsigned char[recvBufferLength];
- randomValuePtr = new unsigned char[randomLengthInBytes];
memset(sendBuffer, 0, sendBufferLength);
memset(recvBuffer, 0, recvBufferLength);
- memset(randomValuePtr, 0, randomLengthInBytes);
- tempBuffer = (unsigned char *) &randomLengthInBytes;
+ tempBuffer = (unsigned char *) &randomLength;
sendBuffer[0] = 0xB0;
sendBuffer[1] = 0x40;
@@ -288,22 +283,24 @@
transmitApdu(sendBufferLength, sendBuffer, recvBufferLength, recvBuffer);
- sw_1_2 = recvBuffer[randomLengthInBytes] << 8 | recvBuffer[randomLengthInBytes + 1];
+ sw_1_2 = recvBuffer[randomLength] << 8 | recvBuffer[randomLength + 1];
switch(sw_1_2){
case 0x9000:
break;
case 0x6008:
clearBuffer();
- throw SmartCardException("failed to generate random value from G&D smart card");
+ return false;
+ //throw SmartCardException("failed to generate random value from G&D smart card");
default:
clearBuffer();
- throw SmartCardException("Unknown state value was returned when generating random value");
+ return false;
+ //throw SmartCardException("Unknown state value was returned when generating random value");
}
- memcpy(randomValuePtr, recvBuffer,randomLengthInBytes);
+ memcpy(randomPtr, recvBuffer,randomLength);
clearBuffer();
- return randomValuePtr;
+ return true;
}
else
throw SmartCardException("unconnected card or the user doesn't have proper access level. Correct userPinCode is required");
Modified: trunk/libmcrypto/source/SipSimSoft.cxx
===================================================================
--- trunk/libmcrypto/source/SipSimSoft.cxx 2007-01-11 18:56:26 UTC (rev 3113)
+++ trunk/libmcrypto/source/SipSimSoft.cxx 2007-01-14 15:35:24 UTC (rev 3114)
@@ -1,6 +1,7 @@
-#include<config.h>
-#include<libmcrypto/SipSimSoft.h>
+#include <config.h>
+#include <libmcrypto/SipSimSoft.h>
+#include <libmcrypto/rand.h>
using namespace std;
@@ -28,4 +29,8 @@
return true;
}
+bool SipSimSoft::getRandomValue(unsigned char * randomPtr, unsigned long randomLength)
+{
+ Rand::randomize(randomPtr, randomLength);
+}
Modified: trunk/libmcrypto/source/gnutls/rand.cxx
===================================================================
--- trunk/libmcrypto/source/gnutls/rand.cxx 2007-01-11 18:56:26 UTC (rev 3113)
+++ trunk/libmcrypto/source/gnutls/rand.cxx 2007-01-14 15:35:24 UTC (rev 3114)
@@ -31,3 +31,8 @@
gcry_randomize(buffer, length, GCRY_STRONG_RANDOM);
return true;
}
+
+bool Rand::randomize(void *buffer, size_t length, MRef<SipSim *> sim)
+{
+ return sim->getRandomValue((unsigned char *) buffer, length);
+}
Modified: trunk/libmcrypto/source/openssl/rand.cxx
===================================================================
--- trunk/libmcrypto/source/openssl/rand.cxx 2007-01-11 18:56:26 UTC (rev 3113)
+++ trunk/libmcrypto/source/openssl/rand.cxx 2007-01-14 15:35:24 UTC (rev 3114)
@@ -30,3 +30,8 @@
{
return RAND_bytes((unsigned char*)buffer, length);
}
+
+bool Rand::randomize(void * buffer, size_t length, MRef<SipSim *> sim)
+{
+ return sim->getRandomValue((unsigned char*)buffer, length);
+}
Modified: trunk/libmikey/include/libmikey/MikeyPayloadRAND.h
===================================================================
--- trunk/libmikey/include/libmikey/MikeyPayloadRAND.h 2007-01-11 18:56:26 UTC (rev 3113)
+++ trunk/libmikey/include/libmikey/MikeyPayloadRAND.h 2007-01-14 15:35:24 UTC (rev 3114)
@@ -28,6 +28,7 @@
#include<libmikey/libmikey_config.h>
#include<libmikey/MikeyPayload.h>
+#include<libmcrypto/SipSim.h>
#define MIKEYPAYLOAD_RAND_PAYLOAD_TYPE 11
@@ -41,6 +42,7 @@
// FIXME almost same prototype, leads to mistake!!
MikeyPayloadRAND( int randlen, byte_t * rand_data );
MikeyPayloadRAND( byte_t * start, int lengthLimit );
+ MikeyPayloadRAND(MRef<SipSim *> sim);
~MikeyPayloadRAND();
virtual int length();
Modified: trunk/libmikey/mikey/MikeyMessageDH.cxx
===================================================================
--- trunk/libmikey/mikey/MikeyMessageDH.cxx 2007-01-11 18:56:26 UTC (rev 3113)
+++ trunk/libmikey/mikey/MikeyMessageDH.cxx 2007-01-14 15:35:24 UTC (rev 3114)
@@ -52,7 +52,10 @@
unsigned int csbId = ka->csbId();
if( !csbId ){
- Rand::randomize( &csbId, sizeof( csbId ));
+ if(ka->useSim)
+ Rand::randomize( &csbId, sizeof( csbId ), ka->getSim());
+ else
+ Rand::randomize( &csbId, sizeof( csbId ));
ka->setCsbId( csbId );
}
@@ -67,7 +70,11 @@
addPolicyToPayload( ka ); //Is in MikeyMessage.cxx
MikeyPayloadRAND * payload;
- addPayload( payload = new MikeyPayloadRAND() );
+
+ if(ka->useSim)
+ addPayload(payload = new MikeyPayloadRAND(ka->getSim()));
+ else
+ addPayload( payload = new MikeyPayloadRAND() );
//keep a copy of the random value!
ka->setRand( payload->randData(),
Modified: trunk/libmikey/mikey/MikeyPayloadRAND.cxx
===================================================================
--- trunk/libmikey/mikey/MikeyPayloadRAND.cxx 2007-01-11 18:56:26 UTC (rev 3113)
+++ trunk/libmikey/mikey/MikeyPayloadRAND.cxx 2007-01-14 15:35:24 UTC (rev 3114)
@@ -79,6 +79,13 @@
}
+MikeyPayloadRAND::MikeyPayloadRAND(MRef<SipSim *> sim):MikeyPayload(){
+ this->payloadTypeValue = MIKEYPAYLOAD_RAND_PAYLOAD_TYPE;
+ randLengthValue = 16;
+ randDataPtr = new byte_t[ randLengthValue ];
+ Rand::randomize(randDataPtr, randLengthValue, sim);
+}
+
MikeyPayloadRAND::~MikeyPayloadRAND(){
if( randDataPtr ){
delete [] randDataPtr;
More information about the Minisip-devel
mailing list