Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
HI...
 
I'm working on an SSL client/server application, and I've generated a digital signature, and whenever I pass it to another function, the value of the digital signature changes in the middle of the function.
int CLIENT::SSL_client_side(const char * MN, bool l, const char * digitalSignature, CkString Digital_Certificate)
 {
   CkSocket socket;
 
   bool success;
   success = socket.UnlockComponent("*******************");
   if (success != true) {
		printf("%s\n",socket.lastErrorText());
		return 0;}
 
    bool ssl;
    ssl = true;
    long maxWaitMillisec;
    maxWaitMillisec = 60000;
 
	//  The SSL server hostname may be an IP address, a domain name,
	//  or "localhost".  You'll need to change this:
    const char * sslServerHost;
    sslServerHost = "******";
    long sslServerPort;
    sslServerPort = 8123;
 

 
    //  Connect to the SSL server:
    success = socket.Connect(sslServerHost,sslServerPort,ssl,maxWaitMillisec);
    if (success != true) {
    printf("%s\n",socket.lastErrorText());
		return 0;}
 
    //  Set maximum timeouts for reading an writing (in millisec)
    socket.put_MaxReadIdleMs(50000);
    socket.put_MaxSendIdleMs(50000);
 

    success = socket.SendString("CLIENT PC: Hello Merchant! -EOM-");
    if (success != true) {
		printf("%s\n",socket.lastErrorText());
		return 0;}
 
	//CONNECTION 1: The "MERCHANT as a server"(in this example) is going to send
	//a "Hello Client! -EOM-" message.  Where the "PC as a client" will Read it:
    const char * receivedMsg;
    receivedMsg = socket.receiveUntilMatch("-EOM-");
	if (receivedMsg == 0 )
	 {
		printf("%s\n",socket.lastErrorText());
		return 0;
	 }
 
	//PRINT "CLIENT PC: Hello Client! -EOM-" on the "PC as a client" side
    printf("%s\n",receivedMsg);
 
	  //	cout<<"\n"<<DigSignature;      not good
	//CONNECTION 1: The "PC as a client" will display a message: "Enter your
	//Mobile Number:", and the user will enter his mobile number.
	//The Mobile Number will be sent to the "MERCHANT as a server"
	if (l == true)
	 {
 
		char MN[4096];
		printf("ENTER YOUR MOBILE NUMBER:");
		gets(MN);  
 
		success=socket.SendString((const char *)MN);
                  if (success != true) {
		printf("%s\n",socket.lastErrorText());
		return 0; }
 
		success = socket.SendString(Digital_Certificate);
		if (success != true) {
		printf("%s\n",socket.lastErrorText());
		return 0; }
 
		success = socket.SendString(digitalSignature);
		if (success != true) {
		printf("%s\n",socket.lastErrorText());
		return 0; }
	}
	//  Close the connection with the server
	//  Wait a max of 20 seconds (20000 millsec)
	//socket.Close(20000);
	//socket.Close(20000);
	//getch();
	return 0;
 }
And to be very specific, the contents of the digital Signature changes right after the following statement:
success = socket.Connect(sslServerHost,sslServerPort,ssl,maxWaitMillisec);
 
Please, need help
 
Regards.
Posted 22-May-13 12:29pm
raniam438
Edited 22-May-13 12:44pm
CPallini329K
v2
Comments
CPallini at 22-May-13 17:49pm
   
Probably another thread is accessing that buffer. You might try (as debug technique) to copy the digitalSignature buffer on the very first statement of your function and use such copy in the rest of the function.
Sergey Alexandrovich Kryukov at 22-May-13 21:19pm
   
5!
—SA
CPallini at 23-May-13 1:42am
   
Thank you, Sergey.
:-)
raniam at 25-May-13 4:57am
   
yes thank you, I've made a copy of the digitalSignature and it worked
lewax00 at 22-May-13 17:50pm
   
Can you add the code that you generate that value in, and the code from that point to where this function is called (i.e. I assume it's a function, so the point from that function call to the call to this one)? I've seen some similar problems in the past, so it might be related (and if it is, I know how to fix it).
raniam at 23-May-13 8:47am
   
This is the function that generates the Digital Signature:
 
const char * CLIENT::Generate_RSA_DigitalSignature(const char * MNumber, CkCert * DigSig_Dig_Certificate1)
{
CkPrivateKey *pkey = 0;
pkey = DigSig_Dig_Certificate1->ExportPrivateKey();
if (pkey == 0 ) {
printf("%s\n",DigSig_Dig_Certificate1->lastErrorText()); }
 
const char * pkeyXml;
// Get the private key in XML format:
pkeyXml = pkey->getXml();
//delete pkey;
//cout<<"\n"<<pkeyXml;
CkRsa rsa;
 
// Any string argument automatically begins the 30-day trial.
 
bool success = rsa.UnlockComponent("***********************");
if (success != true) {
printf("RSA component unlock failed\n"); }
 

// Import the private key into the RSA component:
success = rsa.ImportPrivateKey(pkeyXml);
if (success != true) {
printf("%s\n",rsa.lastErrorText()); }
 
cout<<"\nPrivate Key: "<<pkeyXml<<"\n";
// This example will sign a string, and receive the signature
// in a hex-encoded string. Therefore, set the encoding mode
// to "hex":
rsa.put_EncodingMode("hex");
 
// If some other non-Chilkat application or web service is going to be verifying
// the signature, it is important to match the byte-ordering.
// The LittleEndian property may be set to true
// for little-endian byte ordering,
// or false for big-endian byte ordering.
// Microsoft apps typically use little-endian, while
// OpenSSL and other services (such as Amazon CloudFront)
// use big-endian.
rsa.put_LittleEndian(false);
 

// Sign the string using the sha-1 hash algorithm.
// Other valid choices are "md2" and "md5".
const char * hexSig;
hexSig = rsa.signStringENC(MNumber,"sha-1");
 
//printf("%s\n",hexSig);
 
//printf("Success!\n");
return hexSig;
}
 
and this is the main function that calls the Generate_RSA_DigitalSignature function:
 
int _tmain(int argc, _TCHAR* argv[])
{
cout<<"CLIENT SIDE\n";
cout<<"===========\n\n";
 
CkCert * c = browser.Pass_Certificate();
//printf("%s\n",c->subjectDN());
 
CkString cert = browser.Convert_Cert_into_String(c);
cout<<cert;
 
HANDLE hConsole3;
hConsole3 = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole3, 10);
char mn[4096];
printf("ENTER YOUR MOBILE NUMBER:");
 
HANDLE hConsole4;
hConsole4 = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole4, 14);
gets(mn);
 

const char * Digital_Signature = browser.Generate_RSA_DigitalSignature(mn, c);
cout<<"\nDigital Signature: \n"<<Digital_Signature;
 
//CONNECTION 1 (client.h)
//************************
//SSL conncection between the "PC as a client" and the "MERCHANT as a server"
int a = browser.SSL_client_side(mn,true,Digital_Signature,cert);
cout<<"\n\n";
 

getch();
}
 
Best Regards
shailesh91082 at 23-May-13 13:20pm
   
There does not seems to be any code which could modify the value of the digitalSignature.
could you add the code which calls this function ??

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Clean your build and rebuild it....some times this solved this type of problem;
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 565
1 Maciej Los 359
2 Kornfeld Eliyahu Peter 309
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,303
1 DamithSL 4,764
2 Maciej Los 4,306
3 Kornfeld Eliyahu Peter 3,914
4 Sergey Alexandrovich Kryukov 3,538


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 23 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100