Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
95 user(s) are online (48 user(s) are browsing Forums)

Members: 2
Guests: 93

walkero, A__P, more...

Support us!

Headlines

 
  Register To Post  

AmiSSL usage (compliling) question
Just popping in
Just popping in


See User information
Hi everybody,

I'm playing around with encoding/decoding of ASN1 DER data records. For that i made under mac a simple test program:

#include <openssl/asn1.h>
#include <openssl/asn1t.h>
#include <openssl/objects.h>
#include <openssl/err.h>

const unsigned char tokenInit[] = { 0xa0,0x3e,0x30,0x3c,0xa0,0x0e,0x30,0x0c,0x06,0x0a,0x2b,0x06,0x01,0x04,0x01,0x82,0x37,0x02,0x02,0x0a,0xa2,0x2a,0x04,0x28,0x4e,0x54,0x4c,0x4d,0x53,0x53,0x50,0x00,0x01,0x00,0x00,0x00,0x35,0x82,0x08,0xe2,0x00,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x35,0x0e,0x00,0x00,0x00,0x00,0x00,0x0f };
const 
size_t tokenInitSize = sizeof( tokenInit ); 

const 
unsigned char tokenResponse[] = { 0xa1,0x81,0xa2,0x30,0x81,0x9f,0xa0,0x03,0x0a,0x01,0x01,0xa1,0x0c,0x06,0x0a,0x2b,0x06,0x01,0x04,0x01,0x82,0x37,0x02,0x02,0x0a,0xa2,0x81,0x89,0x04,0x81,0x86,0x4e,0x54,0x4c,0x4d,0x53,0x53,0x50,0x00,0x02,0x00,0x00,0x00,0x06,0x00,0x06,0x00,0x38,0x00,0x00,0x00,0x35,0x82,0x89,0x62,0x57,0xcd,0x8f,0xad,0x37,0xf8,0x89,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x48,0x00,0x3e,0x00,0x00,0x00,0x06,0x01,0xb0,0x1d,0x0f,0x00,0x00,0x00,0x54,0x00,0x4f,0x00,0x4d,0x00,0x01,0x00,0x06,0x00,0x54,0x00,0x4f,0x00,0x4d,0x00,0x02,0x00,0x06,0x00,0x54,0x00,0x4f,0x00,0x4d,0x00,0x03,0x00,0x12,0x00,0x74,0x00,0x6f,0x00,0x6d,0x00,0x2e,0x00,0x6c,0x00,0x6f,0x00,0x63,0x00,0x61,0x00,0x6c,0x00,0x04,0x00,0x0a,0x00,0x6c,0x00,0x6f,0x00,0x63,0x00,0x61,0x00,0x6c,0x00,0x07,0x00,0x08,0x00,0x00,0xc1,0xea,0x2e,0x73,0xbf,0xd7,0x01,0x00,0x00,0x00,0x00 };
const 
size_t tokenResponseSize = sizeof( tokenResponse ); 

const 
unsigned char *token = tokenResponse;
const 
size_t tokenSize = sizeof( tokenResponse ); 

typedef struct MechType_st {
    
ASN1_OBJECT *mechType; 
} 
SPNEGO_MECHTYPE;

DECLARE_ASN1_FUNCTIONS( SPNEGO_MECHTYPE )
DEFINE_STACK_OF( SPNEGO_MECHTYPE )

ASN1_SEQUENCE( SPNEGO_MECHTYPE )  = {
    
ASN1_SIMPLE( SPNEGO_MECHTYPE,mechType,ASN1_OBJECT )
} 
ASN1_SEQUENCE_END( SPNEGO_MECHTYPE )

IMPLEMENT_ASN1_FUNCTIONS( SPNEGO_MECHTYPE )

typedef struct NegTokenInit_st {
    
STACK_OF( SPNEGO_MECHTYPE ) *mechTypeList;     
    
ASN1_BIT_STRING *reqFlags;
    
ASN1_OCTET_STRING *mechToken;
    
ASN1_OCTET_STRING *mechListMIC;
} 
SPNEGO_NEGTOKENINIT;

DECLARE_ASN1_FUNCTIONS( SPNEGO_NEGTOKENINIT )

ASN1_SEQUENCE( SPNEGO_NEGTOKENINIT ) = {
    
ASN1_IMP_SEQUENCE_OF( SPNEGO_NEGTOKENINIT, mechTypeList, SPNEGO_MECHTYPE, 0 ),
    
ASN1_EXP_OPT( SPNEGO_NEGTOKENINIT, reqFlags, ASN1_BIT_STRING, 1 ),
    
ASN1_EXP_OPT( SPNEGO_NEGTOKENINIT, mechToken, ASN1_OCTET_STRING, 2 ),
    
ASN1_EXP_OPT( SPNEGO_NEGTOKENINIT, mechListMIC, ASN1_OCTET_STRING, 3 )
} 
ASN1_SEQUENCE_END( SPNEGO_NEGTOKENINIT )   

IMPLEMENT_ASN1_FUNCTIONS( SPNEGO_NEGTOKENINIT )



typedef struct NegTokenResp_st {
    
ASN1_ENUMERATED *negState;
    
SPNEGO_MECHTYPE *supportedMech;
    
ASN1_OCTET_STRING *responseToken;
    
ASN1_OCTET_STRING *mechListMIC;
} 
SPNEGO_NEGTOKENRESP;

DECLARE_ASN1_FUNCTIONS( SPNEGO_NEGTOKENRESP )

ASN1_SEQUENCE( SPNEGO_NEGTOKENRESP ) = {
    
ASN1_EXP_OPT( SPNEGO_NEGTOKENRESP, negState, ASN1_ENUMERATED, 0 ),
    
ASN1_IMP_OPT( SPNEGO_NEGTOKENRESP, supportedMech, SPNEGO_MECHTYPE, 1 ),
    
ASN1_EXP_OPT( SPNEGO_NEGTOKENRESP, responseToken, ASN1_OCTET_STRING, 2 ),
    
ASN1_EXP_OPT( SPNEGO_NEGTOKENRESP, mechListMIC, ASN1_OCTET_STRING, 3 )
} 
ASN1_SEQUENCE_END( SPNEGO_NEGTOKENRESP )   

IMPLEMENT_ASN1_FUNCTIONS( SPNEGO_NEGTOKENRESP )



typedef struct NegotiationToken_st {
    
int type;
    
union {
        
SPNEGO_NEGTOKENINIT *NegTokenInit;
        
SPNEGO_NEGTOKENRESP *NegTokenResp;
    } 
token;
} 
SPNEGO_NEGOTIATIONTOKEN;

DECLARE_ASN1_FUNCTIONS( SPNEGO_NEGOTIATIONTOKEN )
DECLARE_ASN1_PRINT_FUNCTION( SPNEGO_NEGOTIATIONTOKEN )

ASN1_CHOICE( SPNEGO_NEGOTIATIONTOKEN ) = {
    
ASN1_EXP_OPT( SPNEGO_NEGOTIATIONTOKEN, token.NegTokenInit, SPNEGO_NEGTOKENINIT,0 ),
    
ASN1_EXP_OPT( SPNEGO_NEGOTIATIONTOKEN, token.NegTokenResp, SPNEGO_NEGTOKENRESP,1 )
} 
ASN1_CHOICE_END( SPNEGO_NEGOTIATIONTOKEN )   

IMPLEMENT_ASN1_FUNCTIONS( SPNEGO_NEGOTIATIONTOKEN )
IMPLEMENT_ASN1_PRINT_FUNCTION( SPNEGO_NEGOTIATIONTOKEN )

void SPNEGO_NEGOTIATIONTOKEN_print( SPNEGO_NEGOTIATIONTOKEN *negToken ) {
    if( 
negToken != NULL ) {
        
printf( "Token provided.\n" ); 
        switch( 
negToken->type ) {
            case 
0:
                
printf( "\tType: NegTokenInit\n" ); 
                
SPNEGO_NEGTOKENINIT *NegTokenInit = negToken->token.NegTokenInit;
                if( 
NegTokenInit->mechTypeList == NULL ) 
                    
printf( "\tmechTypeList: Not present\n" ); 

                if( 
NegTokenInit->reqFlags == NULL ) 
                    
printf( "\treqFlags: Not present\n" ); 

                if( 
NegTokenInit->mechToken == NULL ) 
                    
printf( "\tmechToken: Not present\n" ); 

                if( 
NegTokenInit->mechListMIC == NULL ) 
                    
printf( "\tmechListMIC: Not present\n" ); 

                break;
            case 
1:
                
printf( "\tType: NegTokenResp\n" ); 
                
SPNEGO_NEGTOKENRESP *NegTokenResp = negToken->token.NegTokenResp;
                if( 
NegTokenResp->negState == NULL ) 
                    
printf( "\tnegState: Not present\n" ); 


                if( 
NegTokenResp->supportedMech == NULL ) 
                    
printf( "\tsupportedMech: Not present\n" ); 
                else {
                    
char buff[1024];
                    
OBJ_obj2txt(buff, 1024, NegTokenResp->supportedMech->mechType, 0);
                    
printf( "\tsupportedMech: %s\n",buff ); 
                }

                if( 
NegTokenResp->responseToken == NULL ) 
                    
printf( "\tresponseToken: Not present\n" ); 
                
                if( 
NegTokenResp->mechListMIC == NULL ) 
                    
printf( "\tmechListMIC: Not present\n" ); 
                

                break;
            default:
                
printf( "\tType: Unknown, value %d\n",negToken->type ); 
        }
    }
    else {
        
printf( "No token provided\n" ); 
    }
}

int main( const int argc,const char *argv[] ) {
    const 
unsigned char *buffer = token;
    
SPNEGO_NEGOTIATIONTOKEN *negToken = d2i_SPNEGO_NEGOTIATIONTOKEN( NULL,&buffer,tokenSize );
    if( 
negToken != NULL ) {
        
printf( "Token decoded.\n" ); 
        
SPNEGO_NEGOTIATIONTOKEN_print( negToken );


        
SPNEGO_NEGOTIATIONTOKEN_free( negToken );
    }
    else {        
        
printf( "Decoding of token failed:\n" ); 

        
ERR_load_crypto_strings();
        
ERR_print_errors_fp(stderr);
    }

    
negToken = SPNEGO_NEGOTIATIONTOKEN_new();
    if( 
negToken != NULL ) {
        
negToken->type = 0;
        
negToken->token.NegTokenInit = SPNEGO_NEGTOKENINIT_new();
        
negToken->token.NegTokenInit->mechTypeList = sk_SPNEGO_MECHTYPE_new_null();
        
negToken->token.NegTokenInit->mechToken = ASN1_OCTET_STRING_new();

        
SPNEGO_MECHTYPE *mechType = SPNEGO_MECHTYPE_new();
        
mechType->mechType = OBJ_txt2obj( "1.3.6.1.4.1.311.2.2.10",0 );

        
sk_SPNEGO_MECHTYPE_push( negToken->token.NegTokenInit->mechTypeList,mechType );

        const 
unsigned char mechToken[] = "\x4e\x54\x4c\x4d\x53\x53\x50\x00\x01\x00\x00\x00\x35\x82\x08\xe2\x00\x00\x00\x00\x28\x00\x00\x00\x00\x00\x00\x00\x28\x00\x00\x00\x35\x0e\x00\x00\x00\x00\x00\x0f";
        const 
size_t mechTokenSize = sizeof( mechToken ); 
        
ASN1_OCTET_STRING_set( negToken->token.NegTokenInit->mechToken,mechToken,mechTokenSize );

        
buffer = NULL;
        
size_t bufferSize = i2d_SPNEGO_NEGOTIATIONTOKEN( negToken,NULL );

        
printf( "Required buffer size for DER encoding of ASN1 structure: %zu\n",bufferSize );

        
SPNEGO_NEGOTIATIONTOKEN_print( negToken );

        
ERR_load_crypto_strings();
        
ERR_print_errors_fp(stderr);

        
SPNEGO_NEGOTIATIONTOKEN_free( negToken );
    }
    else {
        
printf( "Creating of token failed.\n" ); 
    }
}


I can compile it under mac os with this command.

Quote:
gcc -L/usr/local/opt/openssl@3/lib -I/usr/local/opt/openssl@3/include -o example example.c -lssl -lcrypto


It compiles and executing it output some stuff, as expected.

Now i want to compile it for AmigaOS4. For that i'm using walkero docker image for cross compiling. My best guess how to instruct the compiler to compile this is as following:

Quote:
gcc -static -I./includes/ -I/opt/sdk/AmiSSL/include/ -o example example.c -lssl -lcrypto


That fails with a a lot of compile errors, where i have no clue what the cause is.

amidev@345c9e948f2a:/opt/code/ans.1$ gcc -static -I./includes/ -I/opt/sdk/AmiSSL/include/ -o example example.c -lssl -lcrypto
In file included from 
/opt/sdk/AmiSSL/include/openssl/crypto.h:26,
                 
from /opt/sdk/AmiSSL/include/openssl/bio.h:23,
                 
from /opt/sdk/AmiSSL/include/openssl/asn1.h:19,
                 
from /opt/sdk/AmiSSL/include/amissl/amissl.h:21,
                 
from /opt/sdk/AmiSSL/include/proto/amissl.h:31,
                 
from /opt/sdk/AmiSSL/include/openssl/asn1.h:2,
                 
from example.c:1:
/
opt/sdk/AmiSSL/include/openssl/safestack.h:23:32: warning: ‘struct stack_st_SPNEGO_MECHTYPE’ declared inside parameter list will not be visible outside of this definition or declaration
   23 
| # define STACK_OF(type) struct stack_st_##type
      
|                                ^~~~~~~~~
/
opt/sdk/AmiSSL/include/amissl/inline.h:29:48: note: in expansion of macro ‘STACK_OF’
   29 
|     static ossl_inline int sk_##t1##_num(const STACK_OF(t1) *sk) \
      
|                                                ^~~~~~~~
/
opt/sdk/AmiSSL/include/openssl/safestack.h:138:29: note: in expansion of macro ‘SKM_DEFINE_STACK_OF’
  138 
| # define DEFINE_STACK_OF(t) SKM_DEFINE_STACK_OF(t, t, t)
      
|                             ^~~~~~~~~~~~~~~~~~~
example.c:20:1: note: in expansion of macro ‘DEFINE_STACK_OF’
   20 
| DEFINE_STACK_OF( SPNEGO_MECHTYPE )
      | ^~~~~~~~~~~~~~~
/
opt/sdk/AmiSSL/include/openssl/safestack.h:23:32: warning: ‘struct stack_st_SPNEGO_MECHTYPE’ declared inside parameter list will not be visible outside of this definition or declaration
   23 
| # define STACK_OF(type) struct stack_st_##type
      
|                                ^~~~~~~~~
/
opt/sdk/AmiSSL/include/amissl/inline.h:33:50: note: in expansion of macro ‘STACK_OF’
   33 
|     static ossl_inline t2 *sk_##t1##_value(const STACK_OF(t1) *sk, int idx) \
      
|                                                  ^~~~~~~~
/
opt/sdk/AmiSSL/include/openssl/safestack.h:138:29: note: in expansion of macro ‘SKM_DEFINE_STACK_OF’
  138 
| # define DEFINE_STACK_OF(t) SKM_DEFINE_STACK_OF(t, t, t)
      
|                             ^~~~~~~~~~~~~~~~~~~
example.c:20:1: note: in expansion of macro ‘DEFINE_STACK_OF’
   20 
| DEFINE_STACK_OF( SPNEGO_MECHTYPE )
      | ^~~~~~~~~~~~~~~
/
opt/ppc-amigaos/lib/gcc/ppc-amigaos/10.1.0/../../../../ppc-amigaos/bin/ld: cannot find -lssl
/opt/ppc-amigaos/lib/gcc/ppc-amigaos/10.1.0/../../../../ppc-amigaos/bin/ld: cannot find -lcrypto
collect2
: error: ld returned 1 exit status


The last two errors i can explain to myself. But nevertheless i'm clueless. Is it that AmiSSL doesn't support the used functions, or do i need to instruct the compiler in a special way?

Go to top
Re: AmiSSL usage (compliling) question
Just popping in
Just popping in


See User information
Ok, i was little overwhelm by the out. After changing the compile command to:

[quote]gcc -static -I./includes/ -I/opt/sdk/AmiSSL/include/ -o example example.c[quote]

Thus getting rid of the last error message which i understand. I got real errors during linking. The compile errors were just warnings.

[code]
....
/tmp/ccF3TpJ0.o: In function `sk_SPNEGO_MECHTYPE_new_null':
example.c:(.text+0x14): undefined reference to `OPENSSL_sk_new_null'
/tmp/ccF3TpJ0.o: In function `sk_SPNEGO_MECHTYPE_push':
example.c:(.text+0x5c): undefined reference to `OPENSSL_sk_push'
/tmp/ccF3TpJ0.o: In function `d2i_SPNEGO_MECHTYPE':
example.c:(.text+0xe0): undefined reference to `ASN1_item_d2i'
/tmp/ccF3TpJ0.o: In function `i2d_SPNEGO_MECHTYPE':
example.c:(.text+0x134): undefined reference to `ASN1_item_i2d'
/tmp/ccF3TpJ0.o: In function `SPNEGO_MECHTYPE_new':
example.c:(.text+0x178): undefined reference to `ASN1_item_new'
/tmp/ccF3TpJ0.o: In function `SPNEGO_MECHTYPE_free':
example.c:(.text+0x1c4): undefined reference to `ASN1_item_free'
/tmp/ccF3TpJ0.o: In function `d2i_SPNEGO_NEGTOKENINIT':
example.c:(.text+0x244): undefined reference to `ASN1_item_d2i'
/tmp/ccF3TpJ0.o: In function `i2d_SPNEGO_NEGTOKENINIT':
example.c:(.text+0x298): undefined reference to `ASN1_item_i2d'
/tmp/ccF3TpJ0.o: In function `SPNEGO_NEGTOKENINIT_new':
example.c:(.text+0x2dc): undefined reference to `ASN1_item_new'
/tmp/ccF3TpJ0.o: In function `SPNEGO_NEGTOKENINIT_free':
example.c:(.text+0x328): undefined reference to `ASN1_item_free'
/tmp/ccF3TpJ0.o: In function `d2i_SPNEGO_NEGTOKENRESP':
example.c:(.text+0x3a8): undefined reference to `ASN1_item_d2i'
/tmp/ccF3TpJ0.o: In function `i2d_SPNEGO_NEGTOKENRESP':
example.c:(.text+0x3fc): undefined reference to `ASN1_item_i2d'
/tmp/ccF3TpJ0.o: In function `SPNEGO_NEGTOKENRESP_new':
example.c:(.text+0x440): undefined reference to `ASN1_item_new'
/tmp/ccF3TpJ0.o: In function `SPNEGO_NEGTOKENRESP_free':
example.c:(.text+0x48c): undefined reference to `ASN1_item_free'
/tmp/ccF3TpJ0.o: In function `d2i_SPNEGO_NEGOTIATIONTOKEN':
example.c:(.text+0x50c): undefined reference to `ASN1_item_d2i'
/tmp/ccF3TpJ0.o: In function `i2d_SPNEGO_NEGOTIATIONTOKEN':
example.c:(.text+0x560): undefined reference to `ASN1_item_i2d'
/tmp/ccF3TpJ0.o: In function `SPNEGO_NEGOTIATIONTOKEN_new':
example.c:(.text+0x5a4): undefined reference to `ASN1_item_new'
/tmp/ccF3TpJ0.o: In function `SPNEGO_NEGOTIATIONTOKEN_free':
example.c:(.text+0x5f0): undefined reference to `ASN1_item_free'
/tmp/ccF3TpJ0.o: In function `SPNEGO_NEGOTIATIONTOKEN_print_ctx':
example.c:(.text+0x650): undefined reference to `ASN1_item_print'
/tmp/ccF3TpJ0.o: In function `SPNEGO_NEGOTIATIONTOKEN_print':
example.c:(.text+0x7c0): undefined reference to `OBJ_obj2txt'
/tmp/ccF3TpJ0.o: In function `main':
....
[code]

For them i need stubs, or call directly via the AmiSSL library the methods. I will write the stubs and see how far i come.

Go to top
Re: AmiSSL usage (compliling) question
Just popping in
Just popping in


See User information
Implementing the stubs methdos for AmiSSL, and removing the method:

ERR_print_errors

which isn't implemented by installed AmisSSL. It compiles and builds. Now i just need to test it



Go to top
Re: AmiSSL usage (compliling) question
Just popping in
Just popping in


See User information
It is impossible to support stdio OpenSSL functions in AmiSSL. However, try using the BIO versions of the functions instead, which will work fine. See test/https.c for an example of how to use ERR_print_errors().

Don't link with -lssl and -lcrypto. Just use -lamisslauto or -lamisslauto_newlib if you are not manually opening AmiSSL.

The stack/safestack stuff has always been a bit of headache - fortunately, this has been reworked a lot for OpenSSL 3.0 (now uses macros instead of inline functions). Did you get it working? You shouldn't need to create stubs for those functions - just make sure to compile with -D__USE_INLINE__ and it should be ok.

Go to top
Re: AmiSSL usage (compliling) question
Just popping in
Just popping in


See User information
@Futaura

I got it working (compiling) with writing my own stubs and explicitly open the library. I still got somewhere a bug during execution.

Whenever i get it to work, i maybe cleanup my code and switch to the suggested link and compile options provide by you.

Many folks states (or better suggest) that the BIO function are the "the way" to go, but i haven't got any grip on what that actually is. Mayb you are in for a short enlightening?



Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project