1

着信 SSL 接続を検出する tcp サーバーがあり (こちらを参照)、次のことを行います。

BIO* initialize(SSL_CTX *context, int socket){
    BIO *bio = NULL;
    SSL *ssl = SSL_new(context);
    SSL_set_fd(ssl, socket);
    if (SSL_accept(ssl) == -1){
        return NULL; //error
    }
    //what do I do here??
    bio = BIO_new_ssl(context, 1); //this seems wrong...
    return bio;
}

BIO オブジェクトの作成方法がわかりません。また、ドキュメントが非常にわかりにくいです。どんな助けでも大歓迎です。ありがとう!

4

1 に答える 1

1

これは、私の古い学生プロジェクト (2006 年頃) の抜粋です。質問に光を当てることを願っています。私は BIO_new_ssl() ではなく SSL_set_bio() を使用しています。

SSL_CTX *ctx = setup_server_ctx("root.pem", NULL);
SSL_CTX *ssl = SSL_new(ctx);
if (NULL == ssl) {
   fprintf(stderr, "Error creating SSL context.\n")
   goto err;
}
BIO *acc = BIO_new_accept(port);

if (BIO_do_accept(acc) <= 0) {
   fprintf(stderr, "Error accepting connection.\n");
   goto err;
}

BIO *client = BIO_pop(acc);
SSL_set_bio(ssl, client, client);

if (0 >= SSL_accept(ssl)) {
    fprintf(stderr, "Error accepting SSL connection\n");
    goto end;
}   

SSL_write(ssl, SOME_MESSAGE, strlen(SOME_MESSAGE));
char buf[BUF_SIZE + 1]= {0};
int ret = SSL_read(ssl, buf, BUF_SIZE);
if (ret <= 0) { 
   break;
}   

/* do some more stuff */

SSL_get_shutdown(ssl);
于 2012-07-25T16:49:38.690 に答える