Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
75 user(s) are online (58 user(s) are browsing Forums)

Members: 0
Guests: 75

more...

Headlines






AmiSSL usage (compliling) question
Just popping in
Joined:
2007/2/10 13:46
Posts: 24
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 sizeoftokenInit ); 

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

const 
unsigned char *token tokenResponse;
const 
size_t tokenSize sizeoftokenResponse ); 

typedef struct MechType_st {
    
ASN1_OBJECT *mechType
SPNEGO_MECHTYPE;

DECLARE_ASN1_FUNCTIONSSPNEGO_MECHTYPE )
DEFINE_STACK_OFSPNEGO_MECHTYPE )

ASN1_SEQUENCESPNEGO_MECHTYPE )  = {
    
ASN1_SIMPLESPNEGO_MECHTYPE,mechType,ASN1_OBJECT )
ASN1_SEQUENCE_ENDSPNEGO_MECHTYPE )

IMPLEMENT_ASN1_FUNCTIONSSPNEGO_MECHTYPE )

typedef struct NegTokenInit_st {
    
STACK_OFSPNEGO_MECHTYPE ) *mechTypeList;     
    
ASN1_BIT_STRING *reqFlags;
    
ASN1_OCTET_STRING *mechToken;
    
ASN1_OCTET_STRING *mechListMIC;
SPNEGO_NEGTOKENINIT;

DECLARE_ASN1_FUNCTIONSSPNEGO_NEGTOKENINIT )

ASN1_SEQUENCESPNEGO_NEGTOKENINIT ) = {
    
ASN1_IMP_SEQUENCE_OFSPNEGO_NEGTOKENINITmechTypeListSPNEGO_MECHTYPE),
    
ASN1_EXP_OPTSPNEGO_NEGTOKENINITreqFlagsASN1_BIT_STRING),
    
ASN1_EXP_OPTSPNEGO_NEGTOKENINITmechTokenASN1_OCTET_STRING),
    
ASN1_EXP_OPTSPNEGO_NEGTOKENINITmechListMICASN1_OCTET_STRING)
ASN1_SEQUENCE_ENDSPNEGO_NEGTOKENINIT )   

IMPLEMENT_ASN1_FUNCTIONSSPNEGO_NEGTOKENINIT )



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

DECLARE_ASN1_FUNCTIONSSPNEGO_NEGTOKENRESP )

ASN1_SEQUENCESPNEGO_NEGTOKENRESP ) = {
    
ASN1_EXP_OPTSPNEGO_NEGTOKENRESPnegStateASN1_ENUMERATED),
    
ASN1_IMP_OPTSPNEGO_NEGTOKENRESPsupportedMechSPNEGO_MECHTYPE),
    
ASN1_EXP_OPTSPNEGO_NEGTOKENRESPresponseTokenASN1_OCTET_STRING),
    
ASN1_EXP_OPTSPNEGO_NEGTOKENRESPmechListMICASN1_OCTET_STRING)
ASN1_SEQUENCE_ENDSPNEGO_NEGTOKENRESP )   

IMPLEMENT_ASN1_FUNCTIONSSPNEGO_NEGTOKENRESP )



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

DECLARE_ASN1_FUNCTIONSSPNEGO_NEGOTIATIONTOKEN )
DECLARE_ASN1_PRINT_FUNCTIONSPNEGO_NEGOTIATIONTOKEN )

ASN1_CHOICESPNEGO_NEGOTIATIONTOKEN ) = {
    
ASN1_EXP_OPTSPNEGO_NEGOTIATIONTOKENtoken.NegTokenInitSPNEGO_NEGTOKENINIT,),
    
ASN1_EXP_OPTSPNEGO_NEGOTIATIONTOKENtoken.NegTokenRespSPNEGO_NEGTOKENRESP,)
ASN1_CHOICE_ENDSPNEGO_NEGOTIATIONTOKEN )   

IMPLEMENT_ASN1_FUNCTIONSSPNEGO_NEGOTIATIONTOKEN )
IMPLEMENT_ASN1_PRINT_FUNCTIONSPNEGO_NEGOTIATIONTOKEN )

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

                if( 
NegTokenInit->reqFlags == NULL 
                    
printf"treqFlags: Not presentn" ); 

                if( 
NegTokenInit->mechToken == NULL 
                    
printf"tmechToken: Not presentn" ); 

                if( 
NegTokenInit->mechListMIC == NULL 
                    
printf"tmechListMIC: Not presentn" ); 

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


                if( 
NegTokenResp->supportedMech == NULL 
                    
printf"tsupportedMech: Not presentn" ); 
                else {
                    
char buff[1024];
                    
OBJ_obj2txt(buff1024NegTokenResp->supportedMech->mechType0);
                    
printf"tsupportedMech: %sn",buff ); 
                }

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

                break;
            default:
                
printf"tType: Unknown, value %dn",negToken->type ); 
        }
    }
    else {
        
printf"No token providedn" ); 
    }
}

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


        
SPNEGO_NEGOTIATIONTOKEN_freenegToken );
    }
    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",);

        
sk_SPNEGO_MECHTYPE_pushnegToken->token.NegTokenInit->mechTypeList,mechType );

        const 
unsigned char mechToken[] = "x4ex54x4cx4dx53x53x50x00x01x00x00x00x35x82x08xe2x00x00x00x00x28x00x00x00x00x00x00x00x28x00x00x00x35x0ex00x00x00x00x00x0f";
        const 
size_t mechTokenSize sizeofmechToken ); 
        
ASN1_OCTET_STRING_setnegToken->token.NegTokenInit->mechToken,mechToken,mechTokenSize );

        
buffer NULL;
        
size_t bufferSize i2d_SPNEGO_NEGOTIATIONTOKENnegToken,NULL );

        
printf"Required buffer size for DER encoding of ASN1 structure: %zun",bufferSize );

        
SPNEGO_NEGOTIATIONTOKEN_printnegToken );

        
ERR_load_crypto_strings();
        
ERR_print_errors_fp(stderr);

        
SPNEGO_NEGOTIATIONTOKEN_freenegToken );
    }
    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.1gcc -static -I./includes/ -I/opt/sdk/AmiSSL/include/ -o example example.-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:32warning‘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:48notein 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:29notein expansion of macro ‘SKM_DEFINE_STACK_OF’
  138 
# define DEFINE_STACK_OF(t) SKM_DEFINE_STACK_OF(t, t, t)
      
|                             ^~~~~~~~~~~~~~~~~~~
example.c:20:1notein expansion of macro ‘DEFINE_STACK_OF’
   20 
DEFINE_STACK_OFSPNEGO_MECHTYPE )
      | ^~~~~~~~~~~~~~~
/
opt/sdk/AmiSSL/include/openssl/safestack.h:23:32warning‘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:50notein 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:29notein expansion of macro ‘SKM_DEFINE_STACK_OF’
  138 
# define DEFINE_STACK_OF(t) SKM_DEFINE_STACK_OF(t, t, t)
      
|                             ^~~~~~~~~~~~~~~~~~~
example.c:20:1notein expansion of macro ‘DEFINE_STACK_OF’
   20 
DEFINE_STACK_OFSPNEGO_MECHTYPE )
      | ^~~~~~~~~~~~~~~
/
opt/ppc-amigaos/lib/gcc/ppc-amigaos/10.1.0/../../../../ppc-amigaos/bin/ldcannot find -lssl
/opt/ppc-amigaos/lib/gcc/ppc-amigaos/10.1.0/../../../../ppc-amigaos/bin/ldcannot find -lcrypto
collect2
errorld 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?

   Report Go to top

Re: AmiSSL usage (compliling) question
Just popping in
Joined:
2007/2/10 13:46
Posts: 24
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.

   Report Go to top

Re: AmiSSL usage (compliling) question
Just popping in
Joined:
2007/2/10 13:46
Posts: 24
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



   Report Go to top

Re: AmiSSL usage (compliling) question
Just popping in
Joined:
2006/12/23 18:30
From UK
Posts: 74
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.

   Report Go to top

Re: AmiSSL usage (compliling) question
Just popping in
Joined:
2007/2/10 13:46
Posts: 24
@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?



   Report Go to top





[Advanced Search]



Powered by XOOPS 2.0 © 2001-2016 The XOOPS Project