help converting C code (gnutls)

Linux specific forum
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

help converting C code (gnutls)

Post by lexvictory »

im trying to convert this code to pb: http://www.gnu.org/software/gnutls/manu ... te-support
but my converted code fails on the handshake with "No supported cipher suites have been found."

my code is:

Code: Select all

ImportC "/usr/lib/libgnutls.so"
gnutls_global_init ()
gnutls_anon_allocate_client_credentials (*cred);pass pointer
gnutls_certificate_allocate_credentials (*cred)
gnutls_certificate_set_x509_trust_file (xcred, CAFILE.s, type)
gnutls_init (*session, type);type is client/server (?). pass pointer to a long
gnutls_set_default_priority (session)
gnutls_kx_set_priority (session, kx_priority)
gnutls_credentials_set (session, int, cred)
gnutls_transport_set_ptr (session, sd)
gnutls_handshake (session)
gnutls_perror (retcode)
gnutls_strerror(retcode)
gnutls_record_send (session, *buffer, bufferlen)
gnutls_record_recv (session, *buffer, *buffsize)
gnutls_bye (session, how)
gnutls_deinit (session)
gnutls_anon_free_client_credentials (anoncred)
gnutls_certificate_free_credentials (cred)
gnutls_global_deinit ()
EndImport

#GNUTLS_KX_ANON_DH = 4
#GNUTLS_CLIENT = 2
#GNUTLS_CRD_ANON = 2
#GNUTLS_SHUT_RDWR = 0
#GNUTLS_CRD_CERTIFICATE = 1
#GNUTLS_X509_FMT_PEM = 2



;program start
InitNetwork()


gnutls_global_init()
xcred.l
gnutls_certificate_allocate_credentials (@xcred)
CAFILE.s = "ca.pem"
gnutls_certificate_set_x509_trust_file (xcred, CAFILE, #GNUTLS_X509_FMT_PEM)
session.l
gnutls_init (@session, #GNUTLS_CLIENT)
gnutls_set_default_priority (session)
gnutls_credentials_set (session, #GNUTLS_CRD_CERTIFICATE, xcred)

connection = OpenNetworkConnection("sourceforge.net", 443)
gnutls_transport_set_ptr (session, ConnectionID(connection))
ret = gnutls_handshake (session)

If ret < 0
  Debug "*** Handshake failed"
  Debug PeekS(gnutls_strerror(ret))
  Goto finish
Else
  Debug "- Handshake was completed"
EndIf

MSG.s = "GET / HTTP/1.0"+#CRLF$+"HOST: sourceforge.net"+#CRLF$+#CRLF$
gnutls_record_send (session, @MSG, Len (MSG));

*buffer = AllocateMemory(1024)
ret = gnutls_record_recv (session, *buffer, 1024)
If ret = 0
  Debug "- Peer has closed the TLS connection"
  Goto finish;
ElseIf ret < 0
  Debug "*** Error: "+PeekS(gnutls_strerror(ret))
  Goto finish
EndIf
Debug "- Received "+Str(ret)+" bytes: "
Debug PeekS(*buffer)
FreeMemory(*buffer)

gnutls_bye (session, #GNUTLS_SHUT_RDWR)


finish:

  CloseNetworkConnection(connection)

  gnutls_deinit (session);

  gnutls_certificate_free_credentials (xcred)

  gnutls_global_deinit ();
any ideas what im doing wrong?


EDIT: fixed code, now working properly
also edited to add host header so sf.net would respond with a page rather than a redirect.
Last edited by lexvictory on Tue Oct 09, 2007 4:26 am, edited 3 times in total.
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

You probably want ImportC.
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

doesnt make a difference. its what i had it using originally
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

figured it out; i still had a function call to an anon credentials function...
i'd implemented the anon credentials one, then modified it for the certificate one...

now to implement cert checking... :shock:



opening post edited to fix mistake.
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Post Reply