인디노트

non blocking SSL 본문

인증기술/OpenSSL

non blocking SSL

인디개발자 2018. 11. 16. 14:27

We do non blocking SSL by accepting the socket in the normal way  
(using accept, not SSL_accept), and then wrapping the socket in a BIO  
like this:

         BIO *sbio = BIO_new_socket(c->socket, BIO_NOCLOSE);
         SSL *ssl = SSL_new(ctx);
         SSL_set_bio(ssl, sbio, sbio);
         SSL_set_connect_state(ssl);

We then put the socket in the event loop, and on read and write events  
we called SSL_read and SSL_write as appropriate. The first time we  
call SSL_read, the proper handshake is completed.

One thing that you need to support for non blocking SSL to work  
properly is to take account the fact that during SSL_write, SSL may  
want to read from the socket, and during SSL_read, SSL may want to  
write. We keep track of whether a "ready to read" event should call  
SSL_read or SSL_write as appropriate, reacting to the  
SSL_ERROR_WANT_READ and SSL_ERROR_WANT_WRITE result codes.

Regards,
Graham


우리는 소켓을 일반적인 방법으로 받아들이고 (SSL_accept가 아닌 accept를 사용) SSL을 차단하지 않고 다음과 같이 BIO에 소켓을 래핑합니다.


          BIO * sbio = BIO_new_socket (c-> socket, BIO_NOCLOSE);

          SSL * ssl = SSL_new (ctx);

          SSL_set_bio (ssl, sbio, sbio);

          SSL_set_connect_state (ssl);


그런 다음 소켓을 이벤트 루프에 넣고 SSL_read 및 SSL_write라고하는 읽기 및 쓰기 이벤트에 적절하게 배치합니다. 처음으로 SSL_read를 호출하면 적절한 핸드 쉐이크가 완료됩니다.


블로킹하지 않는 SSL이 제대로 작동하려면 SSL_write 중에 SSL이 소켓에서 읽으 려하고 SSL_read 중에 SSL이 쓸 수 있다는 사실을 고려해야합니다. 우리는 "읽을 준비가되었습니다"이벤트가 SSL_ERROR_WANT_READ 및 SSL_ERROR_WANT_WRITE 결과 코드에 반응하여 적절하게 SSL_read 또는 SSL_write를 호출해야하는지 여부를 추적합니다.


문안 인사,

그레이엄

반응형

'인증기술 > OpenSSL' 카테고리의 다른 글

openssl_server.c  (0) 2019.01.21
An Introduction to OpenSSL Programming, Part I of II  (0) 2019.01.21
BIO client example  (0) 2018.11.15
ssl_client.c  (0) 2018.11.11
Openssl을 이용한 암호화 통신  (0) 2018.11.11
Comments