05.11.2013 Aufrufe

Zahn - Unix-Netzwerkprogramminerung mit Threads, Sockets und SSL

Zahn - Unix-Netzwerkprogramminerung mit Threads, Sockets und SSL

Zahn - Unix-Netzwerkprogramminerung mit Threads, Sockets und SSL

MEHR ANZEIGEN
WENIGER ANZEIGEN

Sie wollen auch ein ePaper? Erhöhen Sie die Reichweite Ihrer Titel.

YUMPU macht aus Druck-PDFs automatisch weboptimierte ePaper, die Google liebt.

7.2 Der <strong>SSL</strong>-Kontext 361<br />

aus der Beschreibung von Beispiel 7.1 hervor geht, kann openssl_lib_init()<br />

nur dann einen Fehler liefern, wen die PRNG-Initialisierung nicht gelingt. In<br />

diesem Fall bricht das Programm <strong>mit</strong> einer entsprechenden Meldung ab.<br />

1 #include <br />

2 #include <br />

3 #include <br />

4 #include <br />

5<br />

6 #include <br />

7 #include <br />

8 #include <br />

9<br />

10 #include "openssl -lib-init.h"<br />

Beispiel 7.3. bio-ssl-smtpcli1.c<br />

11<br />

12 int main( int argc, char *argv[] )<br />

13 {<br />

14 BIO *bio;<br />

15 <strong>SSL</strong>_CTX *ctx;<br />

16 char buf[256];<br />

17<br />

18 if( argc != 2 )<br />

19 {<br />

20 printf( "Usage: %s smtp-host\n", argv[0] );<br />

21 exit( EXIT_FAILURE );<br />

22 }<br />

23<br />

24 /* <strong>SSL</strong>-Bibliothek <strong>und</strong> PRNG initialisieren */<br />

25 if( ! openssl_lib_init() )<br />

26 {<br />

27 printf( "Library/PRNG initialization failed.\n" );<br />

28 exit( EXIT_FAILURE );<br />

29 }<br />

30<br />

31 /* <strong>SSL</strong>-Kontext für TLSv1 -Verbindungen erstellen */<br />

32 if( ( ctx = <strong>SSL</strong>_CTX_new( TLSv1_method() ) ) == NULL )<br />

33 {<br />

34 printf( "Can’t create <strong>SSL</strong> context ...\n" );<br />

35 ERR_print_errors_fp( stdout );<br />

36 exit( EXIT_FAILURE );<br />

37 }<br />

38<br />

39 /* gepuffertes BIO zur <strong>SSL</strong>-Kommunikation erstellen */<br />

40 if( ( bio = BIO_new_buffer_ssl_connect( ctx ) ) == NULL )<br />

41 {<br />

42 printf( "Can’t create <strong>SSL</strong> BIO ...\n" );

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!