Click here to Skip to main content
13,087,941 members (63,844 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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) {
		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) {
		return 0;}
    //  Set maximum timeouts for reading an writing (in millisec)

    success = socket.SendString("CLIENT PC: Hello Merchant! -EOM-");
    if (success != true) {
		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 )
		return 0;
	//PRINT "CLIENT PC: Hello Client! -EOM-" on the "PC as a client" side
	  //	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];
		success=socket.SendString((const char *)MN);
                  if (success != true) {
		return 0; }
		success = socket.SendString(Digital_Certificate);
		if (success != true) {
		return 0; }
		success = socket.SendString(digitalSignature);
		if (success != true) {
		return 0; }
	//  Close the connection with the server
	//  Wait a max of 20 seconds (20000 millsec)
	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

Posted 22-May-13 11:29am
Updated 22-May-13 11:44am
CPallini 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 22-May-13 21:19pm
CPallini 23-May-13 1:42am
Thank you, Sergey.
raniam 25-May-13 4:57am
yes thank you, I've made a copy of the digitalSignature and it worked
lewax00 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 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;
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":

// 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.

// 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");


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";

CkCert * c = browser.Pass_Certificate();

CkString cert = browser.Convert_Cert_into_String(c);

HANDLE hConsole3;
hConsole3 = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole3, 10);
char mn[4096];

HANDLE hConsole4;
hConsole4 = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole4, 14);

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);


Best Regards
shailesh91082 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
Please Sign up or sign in to vote.

Solution 1

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 23 May 2013
Copyright © CodeProject, 1999-2017
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