« Return to Thread: Hello and problem detecting signed data files

Hello and problem detecting signed data files

by Jean-Claude Bauer :: Rate this Message:

Reply to Author | View in Thread

A little context:
        - downloaded and built on SUSE/Linux 10.3
        - make
        - make stestlib  (BTW created "testlib" as exec file, not stestlib)
        - execution of testlib: all tests successful (yeah)

I rewrote my code to skip the file reading and just use some local data
and tried to remove as much irrelevant material as possible:

--code------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include "./cryptlib.h"

void printErrorAttributeInfo( const CRYPT_HANDLE cryptHandle )
        {
        int errorType, errorLocus;
        int status;

        status = cryptGetAttribute( cryptHandle, CRYPT_ATTRIBUTE_ERRORTYPE,

&errorType );
        cryptGetAttribute( cryptHandle, CRYPT_ATTRIBUTE_ERRORLOCUS,
&errorLocus );
        if( cryptStatusOK( status ) && errorType != CRYPT_ERRTYPE_NONE )
                printf( "  Error info attributes report locus %d, type
%d.\n",
                                errorLocus, errorType );
        }

void printExtError( const CRYPT_HANDLE cryptHandle,
                                        const char *functionName, const
int functionStatus,
                                        const int lineNo )
        {
        char errorMessage[ 512 ];
        int errorCode, errorMessageLength, status, msgStatus;

        printf( "%s failed with error code %d, line %d.\n", functionName,
                        functionStatus, lineNo );
        status = cryptGetAttribute( cryptHandle,
CRYPT_ATTRIBUTE_INT_ERRORCODE,

&errorCode );
        msgStatus = cryptGetAttributeString( cryptHandle,

         CRYPT_ATTRIBUTE_INT_ERRORMESSAGE,

         errorMessage, &errorMessageLength );
        if( cryptStatusError( status ) )
                {
                printf( "Read of error attributes failed with error code
%d, "
                                "line %d.\n", status, __LINE__ );
                return;
                }
        if( !errorCode && cryptStatusError( msgStatus ) )
                {
                puts( "  No extended error information available." );
                printErrorAttributeInfo( cryptHandle );
                return;
                }
        if( errorCode )
                printf( "  Extended error code = %d (0x%X).\n", errorCode,
                                errorCode );
        if( cryptStatusOK( msgStatus ) )
                {
                errorMessage[ errorMessageLength ] = '\0';
                printf( "  Error message = %s'%s'.\n",
                                ( errorMessageLength > ( 80 - 21 ) ) ?
"\n  " : "",
                                errorMessage );
                }
        else
                puts( "." );
        printErrorAttributeInfo( cryptHandle );
        }

void verifySignature()
{
   CRYPT_ENVELOPE cryptEnvelope;
   int bytesCopied;
   CRYPT_OBJECT_INFO cryptObjectInfo;
   CRYPT_ATTRIBUTE_TYPE requiredAttribute;
   CRYPT_USER cryptUser = CRYPT_UNUSED;
   void *message;
   int cryptlibReturnValue;
   int status;
   int value = -1;

   cryptlibReturnValue = cryptCreateEnvelope( &cryptEnvelope, cryptUser,
CRYPT_FORMAT_CRYPTLIB );
                                             /* was AUTO format before
=> error BADDATA (-32) on push */
   if cryptStatusError(cryptlibReturnValue) {
      printf(" create envelope cryptlib error %d\n", cryptlibReturnValue);

printExtError(cryptEnvelope,"cryptCreateEnvelope",cryptlibReturnValue,0);
      return;
   }  else printf("created the envelope...\n");


   cryptlibReturnValue = cryptPushData( cryptEnvelope, "What is going on
here ?", 23, &bytesCopied );
   if cryptStatusError(cryptlibReturnValue) {
      printf("Pushed data into the envelope, code %d, bytes copied
%d\n",cryptlibReturnValue,bytesCopied);
      printExtError(cryptEnvelope,"cryptPushData",cryptlibReturnValue,1);
      return;
   }  else printf("pushed the data (%d bytes)...\n",bytesCopied);


   cryptlibReturnValue =
cryptGetAttribute(cryptEnvelope,CRYPT_ATTRIBUTE_CURRENT,
&requiredAttribute);
   if cryptStatusError(cryptlibReturnValue) {
      printf("Get current attribute from envelope, ret code %d,
attribute %d\n",cryptlibReturnValue,requiredAttribute);

printExtError(cryptEnvelope,"cryptGetAttribute",cryptlibReturnValue,2);
   } else printf("read the attributes...\n");
}

int main( int argc, char **argv )
{
   int status;
   status = cryptInit();
   verifySignature();
   status = cryptEnd();
}
--/code----------------------------------------------------------------

Execution results:

created the envelope...
pushed the data (23 bytes)...
Get current attribute from envelope, ret code -2, attribute -1
cryptGetAttribute failed with error code -2, line 2.
Read of error attributes failed with error code -2, line 35.

Note that this example pushes garbage into the envelope so the results
could be normal. When I use a buffer into which I copy files though, I
get the same results - regardless if the file is actually a signed
object or not (example files in cryptlib/test/certs.

These results are the same whether linking static or shared or with/wo
threads.

sorry about the ugly code (it's been a while).

best regards

jcb
--

Jean-Claude Bauer
ClearBUS - Responsable Technique

email: Jean-Claude.Bauer@...
tél: +33 (0)975 601 444

_______________________________________________
Cryptlib mailing list
Cryptlib@... via Mail: cryptlib-request@...
Archive: ftp://ftp.franken.de/pub/crypt/cryptlib/archives/
http://news.gmane.org/gmane.comp.encryption.cryptlib
Posts from non-subscribed addresses are blocked to prevent spam, please
subscribe in order to post messages.

 « Return to Thread: Hello and problem detecting signed data files