]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
fix all the warnings in our demos and make them enableable
authorNeil Horman <nhorman@openssl.org>
Sat, 6 Apr 2024 02:20:54 +0000 (22:20 -0400)
committerNeil Horman <nhorman@openssl.org>
Fri, 12 Apr 2024 12:02:19 +0000 (08:02 -0400)
Fix up the warnings in the demos and make them configurable with
enable-demos

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from https://github.com/openssl/openssl/pull/24047)

15 files changed:
Configure
build.info
demos/bio/saccept.c
demos/bio/sconnect.c
demos/cipher/aesccm.c
demos/cipher/aesgcm.c
demos/cipher/aeskeywrap.c
demos/cipher/ariacbc.c
demos/digest/EVP_MD_demo.c
demos/digest/EVP_MD_stdin.c
demos/digest/EVP_MD_xof.c
demos/guide/quic-multi-stream.c
demos/pkey/EVP_PKEY_DSA_keygen.c
demos/pkey/EVP_PKEY_DSA_paramvalidate.c
demos/sslecho/main.c

index 3b6617c17719f2edde310a37ba395535358045bc..3c3909cfe526eb242f9b75e6eb01dab89e547edb 100755 (executable)
--- a/Configure
+++ b/Configure
@@ -77,6 +77,8 @@ EOF
 #               Generic OpenSSL-style methods relating to this support
 #               are always compiled but return NULL if the hardware
 #               support isn't compiled.
+#
+# enable-demos  Enable the building of the example code in the demos directory
 # no-hw         do not compile support for any crypto hardware.
 # [no-]threads  [don't] try to create a library that is suitable for
 #               multithreaded applications (default is "threads" if we
@@ -443,6 +445,7 @@ my @disablables = (
     "crypto-mdebug",
     "ct",
     "default-thread-pool",
+    "demos",
     "deprecated",
     "des",
     "devcryptoeng",
@@ -570,6 +573,7 @@ our %disabled = ( # "what"         => "comment"
                   "buildtest-c++"       => "default",
                   "crypto-mdebug"       => "default",
                   "crypto-mdebug-backtrace" => "default",
+                  "demos"               => "default",
                   "devcryptoeng"        => "default",
                   "ec_nistp_64_gcc_128" => "default",
                   "egd"                 => "default",
index ad780336d4619ca92f9a706e15537691ae0877c7..fdab98c103d6ffb52f7d9789a76c295e66387c8b 100644 (file)
@@ -1,10 +1,13 @@
 # Note that some of these directories are filtered in Configure.  Look for
 # %skipdir there for further explanations.
 
-SUBDIRS=crypto ssl apps util tools fuzz providers doc demos
+SUBDIRS=crypto ssl apps util tools fuzz providers doc
 IF[{- !$disabled{tests} -}]
   SUBDIRS=test
 ENDIF
+IF[{- !$disabled{demos} -}]
+  SUBDIRS=demos
+ENDIF
 IF[{- !$disabled{'deprecated-3.0'} -}]
   SUBDIRS=engines
 ENDIF
index 6da22ea440910831a2aea9ced66db7a0b2f592fe..d44c6242a24c5a435c4be474b40f6bfcffa5c816 100644 (file)
 
 static volatile int done = 0;
 
-void interrupt(int sig)
+static void interrupt(int sig)
 {
     done = 1;
 }
 
-void sigsetup(void)
+static void sigsetup(void)
 {
     struct sigaction sa;
 
index ef0787c30e80bf71a4a3f920ce07ecf789ba9c80..da7d0197f38f79555267421a19f73386f324548a 100644 (file)
@@ -51,7 +51,8 @@ int main(int argc, char *argv[])
 
     /* Enable trust chain verification */
     SSL_CTX_set_verify(ssl_ctx, SSL_VERIFY_PEER, NULL);
-    SSL_CTX_load_verify_locations(ssl_ctx, CAfile, NULL);
+    if (!SSL_CTX_load_verify_locations(ssl_ctx, CAfile, NULL))
+        goto err;
 
     /* Lets make a SSL structure */
     ssl = SSL_new(ssl_ctx);
index 3c4b9e7445339b5133a00bc5505e71163e6e97d7..49a054f9d3fb5dacf29a19b950254d891c4b30b9 100644 (file)
@@ -68,7 +68,7 @@ OSSL_LIB_CTX *libctx = NULL;
 const char *propq = NULL;
 
 
-int aes_ccm_encrypt(void)
+static int aes_ccm_encrypt(void)
 {
     int ret = 0;
     EVP_CIPHER_CTX *ctx;
@@ -155,7 +155,7 @@ err:
     return ret;
 }
 
-int aes_ccm_decrypt(void)
+static int aes_ccm_decrypt(void)
 {
     int ret = 0;
     EVP_CIPHER_CTX *ctx;
index 64fa8184f1372f70112d1d53fdc85cffd0ba26f9..40465b269c128b2bd7d079ede17dd9b87a58320c 100644 (file)
@@ -67,7 +67,7 @@ static const unsigned char gcm_tag[] = {
 OSSL_LIB_CTX *libctx = NULL;
 const char *propq = NULL;
 
-int aes_gcm_encrypt(void)
+static int aes_gcm_encrypt(void)
 {
     int ret = 0;
     EVP_CIPHER_CTX *ctx;
@@ -144,7 +144,7 @@ err:
     return ret;
 }
 
-int aes_gcm_decrypt(void)
+static int aes_gcm_decrypt(void)
 {
     int ret = 0;
     EVP_CIPHER_CTX *ctx;
index 3207b85663d19a4908f9a905ff54501e1b5342fb..4d5df4cd981f3d52bcade2815f68c88df826dd51 100644 (file)
@@ -53,7 +53,7 @@ static const unsigned char wrap_ct[] = {
 OSSL_LIB_CTX *libctx = NULL;
 const char *propq = NULL;
 
-int aes_wrap_encrypt(void)
+static int aes_wrap_encrypt(void)
 {
     int ret = 0;
     EVP_CIPHER_CTX *ctx;
@@ -111,7 +111,7 @@ err:
     return ret;
 }
 
-int aes_wrap_decrypt(void)
+static int aes_wrap_decrypt(void)
 {
     int ret = 0;
     EVP_CIPHER_CTX *ctx;
index de84d995ec928381f2a6349dc55c535525475d90..73605d2d6c09418318681f184f62e7d189647cad 100644 (file)
@@ -52,7 +52,7 @@ static const unsigned char cbc_ct[] = {
 OSSL_LIB_CTX *libctx = NULL;
 const char *propq = NULL;
 
-int aria_cbc_encrypt(void)
+static int aria_cbc_encrypt(void)
 {
     int ret = 0;
     EVP_CIPHER_CTX *ctx;
@@ -108,7 +108,7 @@ err:
     return ret;
 }
 
-int aria_cbc_decrypt(void)
+static int aria_cbc_decrypt(void)
 {
     int ret = 0;
     EVP_CIPHER_CTX *ctx;
index 279af82ead5cde0b7618c29a19cf460de9e4a049..3a1f0c7ba0bd7191b7db68e63d5d01f250cdd95a 100644 (file)
@@ -76,16 +76,16 @@ const unsigned char known_answer[] = {
     0x81, 0xca, 0x8f, 0x78, 0x29, 0x19, 0x9a, 0xfe,
 };
 
-int demonstrate_digest(void)
+static int demonstrate_digest(void)
 {
     OSSL_LIB_CTX *library_context;
     int ret = 0;
     const char *option_properties = NULL;
     EVP_MD *message_digest = NULL;
     EVP_MD_CTX *digest_context = NULL;
-    int digest_length;
+    unsigned int digest_length;
     unsigned char *digest_value = NULL;
-    int j;
+    unsigned int j;
 
     library_context = OSSL_LIB_CTX_new();
     if (library_context == NULL) {
index 409be9b78e8c4ba81a0dcedba6921cf3bdc867fb..2360af225573fe0048cb68d377a1785e19c6e9c8 100644 (file)
  * a BIO created to read from stdin
  */
 
-int demonstrate_digest(BIO *input)
+static int demonstrate_digest(BIO *input)
 {
     OSSL_LIB_CTX *library_context = NULL;
     int ret = 0;
     const char *option_properties = NULL;
     EVP_MD *message_digest = NULL;
     EVP_MD_CTX *digest_context = NULL;
-    int digest_length;
+    unsigned int digest_length;
     unsigned char *digest_value = NULL;
     unsigned char buffer[512];
-    int ii;
+    unsigned int ii;
 
     library_context = OSSL_LIB_CTX_new();
     if (library_context == NULL) {
index a70e4dc412a4d279b645a668f595b80e130bf398..9635e4539fc52aa4cce476f2ad9f4c0d8fd14524 100644 (file)
@@ -30,7 +30,7 @@
 const char message[] = "This is a test message.";
 
 /* Expected output when an output length of 20 bytes is used. */
-static const char known_answer[] = {
+static const unsigned char known_answer[] = {
   0x52, 0x97, 0x93, 0x78, 0x27, 0x58, 0x7d, 0x62,
   0x8b, 0x00, 0x25, 0xb5, 0xec, 0x39, 0x5e, 0x2d,
   0x7f, 0x3e, 0xd4, 0x19
index d31ea245c8015dc175f16d7be753a5524bfd058a..7ca25ff15cf27814c53855bb84896e5f9e32047f 100644 (file)
@@ -108,8 +108,8 @@ static BIO *create_socket_bio(const char *hostname, const char *port,
     return bio;
 }
 
-int write_a_request(SSL *stream, const char *request_start,
-                    const char *hostname)
+static int write_a_request(SSL *stream, const char *request_start,
+                           const char *hostname)
 {
     const char *request_end = "\r\n\r\n";
     size_t written;
index 579f5f790ac766c731a7ab21a3c4bb712fc9c430..42112bcbbcf066983830a5604fce8c243983d19a 100644 (file)
@@ -21,7 +21,7 @@
  * See the EVP_PKEY_DSA_paramgen demo if you need to
  * use non default parameters.
  */
-EVP_PKEY *dsa_genparams(OSSL_LIB_CTX *libctx, const char *propq)
+static EVP_PKEY *dsa_genparams(OSSL_LIB_CTX *libctx, const char *propq)
 {
     EVP_PKEY *dsaparamkey = NULL;
     EVP_PKEY_CTX *ctx = NULL;
index 4754789f9c9dfa25034c62d028307b9f8080489f..a56c1478692c12d6a4bb666acc6238d5dc73d45a 100644 (file)
@@ -55,8 +55,8 @@ static const char digest[] = "SHA384";
  * Create a new dsa param key that is the combination of an existing param key
  * plus extra parameters.
  */
-EVP_PKEY_CTX *create_merged_key(EVP_PKEY *dsaparams, const OSSL_PARAM *newparams,
-                                OSSL_LIB_CTX *libctx, const char *propq)
+static EVP_PKEY_CTX *create_merged_key(EVP_PKEY *dsaparams, const OSSL_PARAM *newparams,
+                                       OSSL_LIB_CTX *libctx, const char *propq)
 {
     EVP_PKEY_CTX *out = NULL;
     EVP_PKEY_CTX *ctx = NULL;
index 3114dcfcde708807839b73ea16189d3bf124e0e5..c75eac2bc374c1051f651bd19729d7e43049af8e 100644 (file)
@@ -29,7 +29,7 @@ typedef unsigned char   bool;
  */
 static volatile bool    server_running = true;
 
-int create_socket(bool isServer)
+static int create_socket(bool isServer)
 {
     int s;
     int optval = 1;
@@ -67,7 +67,7 @@ int create_socket(bool isServer)
     return s;
 }
 
-SSL_CTX* create_context(bool isServer)
+static SSL_CTX* create_context(bool isServer)
 {
     const SSL_METHOD *method;
     SSL_CTX *ctx;
@@ -87,7 +87,7 @@ SSL_CTX* create_context(bool isServer)
     return ctx;
 }
 
-void configure_server_context(SSL_CTX *ctx)
+static void configure_server_context(SSL_CTX *ctx)
 {
     /* Set the key and cert */
     if (SSL_CTX_use_certificate_chain_file(ctx, "cert.pem") <= 0) {
@@ -101,7 +101,7 @@ void configure_server_context(SSL_CTX *ctx)
     }
 }
 
-void configure_client_context(SSL_CTX *ctx)
+static void configure_client_context(SSL_CTX *ctx)
 {
     /*
      * Configure the client to abort the handshake if certificate verification
@@ -119,7 +119,7 @@ void configure_client_context(SSL_CTX *ctx)
     }
 }
 
-void usage(void)
+static void usage(void)
 {
     printf("Usage: sslecho s\n");
     printf("       --or--\n");
@@ -207,7 +207,10 @@ int main(int argc, char **argv)
 
             /* Create server SSL structure using newly accepted client socket */
             ssl = SSL_new(ssl_ctx);
-            SSL_set_fd(ssl, client_skt);
+            if (!SSL_set_fd(ssl, client_skt)) {
+                ERR_print_errors_fp(stderr);
+                exit(EXIT_FAILURE);
+            }
 
             /* Wait for SSL connection from the client */
             if (SSL_accept(ssl) <= 0) {
@@ -279,11 +282,17 @@ int main(int argc, char **argv)
 
         /* Create client SSL structure using dedicated client socket */
         ssl = SSL_new(ssl_ctx);
-        SSL_set_fd(ssl, client_skt);
+        if (!SSL_set_fd(ssl, client_skt)) {
+            ERR_print_errors_fp(stderr);
+            goto exit;
+        }
         /* Set hostname for SNI */
         SSL_set_tlsext_host_name(ssl, rem_server_ip);
         /* Configure server hostname check */
-        SSL_set1_host(ssl, rem_server_ip);
+        if (!SSL_set1_host(ssl, rem_server_ip)) {
+            ERR_print_errors_fp(stderr);
+            goto exit;
+        }
 
         /* Now do SSL connect with server */
         if (SSL_connect(ssl) == 1) {