Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: correct the SSL_CTX_set_info_callback(3) manual page #22224

Closed
wants to merge 2 commits into from

Conversation

mspncp
Copy link
Contributor

@mspncp mspncp commented Sep 29, 2023

The info callback is not prototyped correctly, and the code example fails to compile because of const-incorrectness.

The info callback is not prototyped correctly, and the code
example fails to compile because of const-incorrectness.
@mspncp mspncp added branch: master Merge to master branch issue: documentation The issue reports errors in (or missing) documentation branch: 3.0 Merge to openssl-3.0 branch branch: 3.1 Merge to openssl-3.1 labels Sep 29, 2023
@mspncp
Copy link
Contributor Author

mspncp commented Sep 29, 2023

Testcase

The implementation of apps_ssl_info_callback in the following test program was copied literally from the manual page. It fails with the following error, which can be fixed by constifying the first argument of apps_ssl_info_callback from SSL *s to const SSL *s.

make -k
cc -g -O0 -I/opt/openssl-dev/master/include -Wno-deprecated-declarations  -L/opt/openssl-dev/master/lib -Wl,--enable-new-dtags,-rpath,/opt/openssl-dev/master/lib  demo.c  -lcrypto -lssl -o demo
demo.c: In function 'main':
demo.c:40:37: warning: passing argument 2 of 'SSL_CTX_set_info_callback' from incompatible pointer type [-Wincompatible-pointer-types]
   40 |     SSL_CTX_set_info_callback(NULL, apps_ssl_info_callback);
      |                                     ^~~~~~~~~~~~~~~~~~~~~~
      |                                     |
      |                                     void (*)(SSL *, int,  int) {aka void (*)(struct ssl_st *, int,  int)}
In file included from demo.c:2:
/opt/openssl-dev/master/include/openssl/ssl.h:764:39: note: expected 'void (*)(const SSL *, int,  int)' {aka 'void (*)(const struct ssl_st *, int,  int)'} but argument is of type 'void (*)(SSL *, int,  int)' {aka 'void (*)(struct ssl_st *, int,  int)'}
  764 |                                void (*cb) (const SSL *ssl, int type, int val));
      |                                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
demo.c:41:33: warning: passing argument 2 of 'SSL_set_info_callback' from incompatible pointer type [-Wincompatible-pointer-types]
   41 |     SSL_set_info_callback(NULL, apps_ssl_info_callback);
      |                                 ^~~~~~~~~~~~~~~~~~~~~~
      |                                 |
      |                                 void (*)(SSL *, int,  int) {aka void (*)(struct ssl_st *, int,  int)}
/opt/openssl-dev/master/include/openssl/ssl.h:2183:35: note: expected 'void (*)(const SSL *, int,  int)' {aka 'void (*)(const struct ssl_st *, int,  int)'} but argument is of type 'void (*)(SSL *, int,  int)' {aka 'void (*)(struct ssl_st *, int,  int)'}
 2183 |                            void (*cb) (const SSL *ssl, int type, int val));
      |                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

demo.c

#include <openssl/bio.h>
#include <openssl/ssl.h>

BIO * bio_err = NULL;

void apps_ssl_info_callback(SSL *s, int where, int ret)
{
    const char *str;
    int w = where & ~SSL_ST_MASK;

    if (w & SSL_ST_CONNECT)
        str = "SSL_connect";
    else if (w & SSL_ST_ACCEPT)
        str = "SSL_accept";
    else
        str = "undefined";

    if (where & SSL_CB_LOOP) {
        BIO_printf(bio_err, "%s:%s\n", str, SSL_state_string_long(s));
    } else if (where & SSL_CB_ALERT) {
        str = (where & SSL_CB_READ) ? "read" : "write";
        BIO_printf(bio_err, "SSL3 alert %s:%s:%s\n", str,
                   SSL_alert_type_string_long(ret),
                   SSL_alert_desc_string_long(ret));
    } else if (where & SSL_CB_EXIT) {
        if (ret == 0) {
            BIO_printf(bio_err, "%s:failed in %s\n",
                       str, SSL_state_string_long(s));
        } else if (ret < 0) {
            BIO_printf(bio_err, "%s:error in %s\n",
                       str, SSL_state_string_long(s));
        }
    }
}



int main (int argc, char *argv[])
{
    SSL_CTX_set_info_callback(NULL, apps_ssl_info_callback);
    SSL_set_info_callback(NULL, apps_ssl_info_callback);

    return 0;
}

Makefile

OPENSSL_VERSION=master
OPENSSL_PREFIX=/opt/openssl-dev/${OPENSSL_VERSION}


OPENSSL_INCDIR=${OPENSSL_PREFIX}/include
OPENSSL_LIBDIR=${OPENSSL_PREFIX}/lib

CFLAGS=-g -O0 -I${OPENSSL_INCDIR} -Wno-deprecated-declarations
LDFLAGS=-L${OPENSSL_LIBDIR} -Wl,--enable-new-dtags,-rpath,${OPENSSL_LIBDIR}
LDLIBS=-lcrypto -lssl

all: demo

clean:
	rm -f demo *~ \#*#

@t8m t8m added triaged: documentation The issue/pr deals with documentation (errors) tests: exempted The PR is exempt from requirements for testing and removed issue: documentation The issue reports errors in (or missing) documentation labels Sep 29, 2023
@t8m t8m added the approval: review pending This pull request needs review by a committer label Sep 29, 2023
@mspncp
Copy link
Contributor Author

mspncp commented Sep 29, 2023

@t8m I forgot to check the getters, they needed to be fixed as well. Please reapprove.

@mspncp mspncp requested a review from t8m September 29, 2023 16:25
@mspncp
Copy link
Contributor Author

mspncp commented Sep 29, 2023

For your convenience:

void SSL_CTX_set_info_callback(SSL_CTX *ctx,
void (*cb) (const SSL *ssl, int type, int val));
void (*SSL_CTX_get_info_callback(SSL_CTX *ctx)) (const SSL *ssl, int type,
int val);

void SSL_set_info_callback(SSL *ssl,
void (*cb) (const SSL *ssl, int type, int val));
void (*SSL_get_info_callback(const SSL *ssl)) (const SSL *ssl, int type,
int val);

@paulidale paulidale added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Sep 30, 2023
@openssl-machine openssl-machine added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Oct 1, 2023
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

@t8m
Copy link
Member

t8m commented Oct 2, 2023

Merged to master, 3.1, and 3.0 branches. Thank you.

@t8m t8m closed this Oct 2, 2023
openssl-machine pushed a commit that referenced this pull request Oct 2, 2023
The info callback is not prototyped correctly, and the code
example fails to compile because of const-incorrectness.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #22224)
openssl-machine pushed a commit that referenced this pull request Oct 2, 2023
The info callback is not prototyped correctly, and the code
example fails to compile because of const-incorrectness.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #22224)

(cherry picked from commit 92986c0)
openssl-machine pushed a commit that referenced this pull request Oct 2, 2023
The info callback is not prototyped correctly, and the code
example fails to compile because of const-incorrectness.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #22224)

(cherry picked from commit 92986c0)
@mspncp mspncp deleted the doc-ssl-ctx-set-info-callback branch October 2, 2023 12:33
wanghao75 pushed a commit to openeuler-mirror/openssl that referenced this pull request Oct 9, 2023
The info callback is not prototyped correctly, and the code
example fails to compile because of const-incorrectness.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from openssl/openssl#22224)

(cherry picked from commit 92986c0)
Signed-off-by: fly2x <fly2x@hitls.org>
wanghao75 pushed a commit to openeuler-mirror/openssl that referenced this pull request Oct 9, 2023
The info callback is not prototyped correctly, and the code
example fails to compile because of const-incorrectness.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from openssl/openssl#22224)

Signed-off-by: fly2x <fly2x@hitls.org>
wanghao75 pushed a commit to openeuler-mirror/openssl that referenced this pull request Oct 9, 2023
The info callback is not prototyped correctly, and the code
example fails to compile because of const-incorrectness.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from openssl/openssl#22224)

(cherry picked from commit 92986c0)
Signed-off-by: fly2x <fly2x@hitls.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Merge to master branch branch: 3.0 Merge to openssl-3.0 branch branch: 3.1 Merge to openssl-3.1 tests: exempted The PR is exempt from requirements for testing triaged: documentation The issue/pr deals with documentation (errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants