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

Erfolgreiche ePaper selbst erstellen

Machen Sie aus Ihren PDF Publikationen ein blätterbares Flipbook mit unserer einzigartigen Google optimierten e-Paper Software.

16 {<br />

17 BIO_puts( bio, req );<br />

18 BIO_flush( bio );<br />

19 printf( "%s", req );<br />

20 }<br />

21<br />

22 void print_smtp_response( BIO *bio )<br />

23 {<br />

24 char buf[256];<br />

7.4 Client-/Server-Beispiel: SMTP <strong>mit</strong> SARTTLS 391<br />

25<br />

26 do<br />

27 {<br />

28 BIO_gets( bio, buf, 256 );<br />

29 printf( "%s", buf );<br />

30 } while( ( strlen( buf ) > 3 ) && ( buf[3] == ’-’ ) );<br />

31 }<br />

32<br />

33 BIO *build_tcp_chain( int socket )<br />

34 {<br />

35 BIO *buf, *tcp;<br />

36<br />

37 /* gepuffertes BIO zur TCP-Kommunikation erstellen */<br />

38 if( ( ! ( buf = BIO_new( BIO_f_buffer() ) ) ) ||<br />

39 ( ! ( tcp = BIO_new_socket( socket , BIO_CLOSE ) ) ) )<br />

40 return( NULL );<br />

41<br />

42 /* BIO-Kette "buffer -> socket" erstellen */<br />

43 return( BIO_push( buf, tcp ) );<br />

44 }<br />

45<br />

46 BIO *build_ssl_chain( BIO *bio )<br />

47 {<br />

48 BIO *buf, *ssl;<br />

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

50<br />

51 /* <strong>SSL</strong>-Kontext <strong>mit</strong> Standardeinstellungen erstellen */<br />

52 if( ( ctx = openssl_create_ssl_ctx() ) == NULL )<br />

53 return( NULL );<br />

54<br />

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

56 if( ( ssl = BIO_new_ssl( ctx, 1 ) ) == NULL )<br />

57 return( NULL );<br />

58<br />

59 /* erst die BIO-Kette "ssl -> socket" <strong>und</strong> da<strong>mit</strong> ... */<br />

60 ssl = BIO_push( ssl, BIO_pop( bio ) );<br />

61 /* die BIO-Kette "buffer -> ssl -> socket" erstellen */<br />

62 ssl = BIO_push( bio, ssl );<br />

63<br />

64 /* Verbindung aufbauen <strong>und</strong> <strong>SSL</strong>-Handshake durchführen */

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

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!