[openssl] master update

dev at ddvo.net dev at ddvo.net
Thu May 20 14:23:45 UTC 2021


The branch master has been updated
       via  ee56cec7332ca2c77ee425c544304ce25475db1c (commit)
       via  a37dbb466ce085bd054bf13604dceac6eb35b593 (commit)
      from  c6bf8bb8595311de424cd1b8ca0c2c7f725721c0 (commit)


- Log -----------------------------------------------------------------
commit ee56cec7332ca2c77ee425c544304ce25475db1c
Author: Dr. David von Oheimb <David.von.Oheimb at siemens.com>
Date:   Wed May 19 10:01:25 2021 +0200

    CMP test server: move apps/{,lib/}cmp_mock_srv.c and apps/{,include/}cmp_mock_srv.h
    
    Reviewed-by: Paul Dale <pauli at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/15343)

commit a37dbb466ce085bd054bf13604dceac6eb35b593
Author: Dr. David von Oheimb <David.von.Oheimb at siemens.com>
Date:   Wed May 19 09:54:11 2021 +0200

    apps/cmp.c: Move CMP server code portion to separate function
    
    Reviewed-by: Paul Dale <pauli at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/15343)

-----------------------------------------------------------------------

Summary of changes:
 apps/build.info                   |   2 +-
 apps/cmp.c                        | 150 ++++++++++++++++++++------------------
 apps/{ => include}/cmp_mock_srv.h |   0
 apps/{ => lib}/cmp_mock_srv.c     |   0
 test/build.info                   |   2 +-
 test/cmp_client_test.c            |   2 +-
 util/find-doc-nits                |   2 +-
 7 files changed, 83 insertions(+), 75 deletions(-)
 rename apps/{ => include}/cmp_mock_srv.h (100%)
 rename apps/{ => lib}/cmp_mock_srv.c (100%)

diff --git a/apps/build.info b/apps/build.info
index 308f4d94f8..020d129f8c 100644
--- a/apps/build.info
+++ b/apps/build.info
@@ -52,7 +52,7 @@ IF[{- !$disabled{'cms'} -}]
   $OPENSSLSRC=$OPENSSLSRC cms.c
 ENDIF
 IF[{- !$disabled{'cmp'} -}]
-  $OPENSSLSRC=$OPENSSLSRC cmp.c cmp_mock_srv.c
+  $OPENSSLSRC=$OPENSSLSRC cmp.c lib/cmp_mock_srv.c
 ENDIF
 
 IF[{- !$disabled{apps} -}]
diff --git a/apps/cmp.c b/apps/cmp.c
index f289943a55..5912090701 100644
--- a/apps/cmp.c
+++ b/apps/cmp.c
@@ -2552,6 +2552,84 @@ static int get_opts(int argc, char **argv)
     return 1;
 }
 
+#ifndef OPENSSL_NO_SOCK
+static int cmp_server(OSSL_CMP_CTX *srv_cmp_ctx) {
+    BIO *acbio;
+    BIO *cbio = NULL;
+    int keep_alive = 0;
+    int msgs = 0;
+    int retry = 1;
+    int ret = 1;
+
+    if ((acbio = http_server_init_bio(prog, opt_port)) == NULL)
+        return 0;
+    while (opt_max_msgs <= 0 || msgs < opt_max_msgs) {
+        char *path = NULL;
+        OSSL_CMP_MSG *req = NULL;
+        OSSL_CMP_MSG *resp = NULL;
+
+        ret = http_server_get_asn1_req(ASN1_ITEM_rptr(OSSL_CMP_MSG),
+                                       (ASN1_VALUE **)&req, &path,
+                                       &cbio, acbio, &keep_alive,
+                                       prog, opt_port, 0, 0);
+        if (ret == 0) { /* no request yet */
+            if (retry) {
+                ossl_sleep(1000);
+                retry = 0;
+                continue;
+            }
+            ret = 0;
+            goto next;
+        }
+        if (ret++ == -1) /* fatal error */
+            break;
+
+        ret = 0;
+        msgs++;
+        if (req != NULL) {
+            if (strcmp(path, "") != 0 && strcmp(path, "pkix/") != 0) {
+                (void)http_server_send_status(cbio, 404, "Not Found");
+                CMP_err1("expecting empty path or 'pkix/' but got '%s'",
+                         path);
+                OPENSSL_free(path);
+                OSSL_CMP_MSG_free(req);
+                goto next;
+            }
+            OPENSSL_free(path);
+            resp = OSSL_CMP_CTX_server_perform(cmp_ctx, req);
+            OSSL_CMP_MSG_free(req);
+            if (resp == NULL) {
+                (void)http_server_send_status(cbio,
+                                              500, "Internal Server Error");
+                break; /* treated as fatal error */
+            }
+            ret = http_server_send_asn1_resp(cbio, keep_alive,
+                                             "application/pkixcmp",
+                                             ASN1_ITEM_rptr(OSSL_CMP_MSG),
+                                             (const ASN1_VALUE *)resp);
+            OSSL_CMP_MSG_free(resp);
+            if (!ret)
+                break; /* treated as fatal error */
+        }
+    next:
+        if (!ret) { /* on transmission error, cancel CMP transaction */
+            (void)OSSL_CMP_CTX_set1_transactionID(srv_cmp_ctx, NULL);
+            (void)OSSL_CMP_CTX_set1_senderNonce(srv_cmp_ctx, NULL);
+        }
+        if (!ret || !keep_alive
+            || OSSL_CMP_CTX_get_status(srv_cmp_ctx) == -1
+             /* transaction closed by OSSL_CMP_CTX_server_perform() */) {
+            BIO_free_all(cbio);
+            cbio = NULL;
+        }
+    }
+
+    BIO_free_all(cbio);
+    BIO_free_all(acbio);
+    return ret;
+}
+#endif
+
 int cmp_main(int argc, char **argv)
 {
     char *configfile = NULL;
@@ -2682,80 +2760,10 @@ int cmp_main(int argc, char **argv)
 
 
     if (opt_port != NULL) { /* act as very basic CMP HTTP server */
-        /* TODO for readability, convert this block to separate function */
 #ifdef OPENSSL_NO_SOCK
         BIO_printf(bio_err, "Cannot act as server - sockets not supported\n");
 #else
-        BIO *acbio;
-        BIO *cbio = NULL;
-        int keep_alive = 0;
-        int msgs = 0;
-        int retry = 1;
-
-        if ((acbio = http_server_init_bio(prog, opt_port)) == NULL)
-            goto err;
-        while (opt_max_msgs <= 0 || msgs < opt_max_msgs) {
-            char *path = NULL;
-            OSSL_CMP_MSG *req = NULL;
-            OSSL_CMP_MSG *resp = NULL;
-
-            ret = http_server_get_asn1_req(ASN1_ITEM_rptr(OSSL_CMP_MSG),
-                                           (ASN1_VALUE **)&req, &path,
-                                           &cbio, acbio, &keep_alive,
-                                           prog, opt_port, 0, 0);
-            if (ret == 0) { /* no request yet */
-                if (retry) {
-                    ossl_sleep(1000);
-                    retry = 0;
-                    continue;
-                }
-                ret = 0;
-                goto next;
-            }
-            if (ret++ == -1) /* fatal error */
-                break;
-
-            ret = 0;
-            msgs++;
-            if (req != NULL) {
-                if (strcmp(path, "") != 0 && strcmp(path, "pkix/") != 0) {
-                    (void)http_server_send_status(cbio, 404, "Not Found");
-                    CMP_err1("expecting empty path or 'pkix/' but got '%s'",
-                             path);
-                    OPENSSL_free(path);
-                    OSSL_CMP_MSG_free(req);
-                    goto next;
-                }
-                OPENSSL_free(path);
-                resp = OSSL_CMP_CTX_server_perform(cmp_ctx, req);
-                OSSL_CMP_MSG_free(req);
-                if (resp == NULL) {
-                    (void)http_server_send_status(cbio,
-                                                  500, "Internal Server Error");
-                    break; /* treated as fatal error */
-                }
-                ret = http_server_send_asn1_resp(cbio, keep_alive,
-                                                 "application/pkixcmp",
-                                                 ASN1_ITEM_rptr(OSSL_CMP_MSG),
-                                                 (const ASN1_VALUE *)resp);
-                OSSL_CMP_MSG_free(resp);
-                if (!ret)
-                    break; /* treated as fatal error */
-            }
-        next:
-            if (!ret) { /* on transmission error, cancel CMP transaction */
-                (void)OSSL_CMP_CTX_set1_transactionID(srv_cmp_ctx, NULL);
-                (void)OSSL_CMP_CTX_set1_senderNonce(srv_cmp_ctx, NULL);
-            }
-            if (!ret || !keep_alive
-                || OSSL_CMP_CTX_get_status(srv_cmp_ctx) == -1
-                 /* transaction closed by OSSL_CMP_CTX_server_perform() */) {
-                BIO_free_all(cbio);
-                cbio = NULL;
-            }
-        }
-        BIO_free_all(cbio);
-        BIO_free_all(acbio);
+        ret = cmp_server(srv_cmp_ctx);
 #endif
         goto err;
     }
diff --git a/apps/cmp_mock_srv.h b/apps/include/cmp_mock_srv.h
similarity index 100%
rename from apps/cmp_mock_srv.h
rename to apps/include/cmp_mock_srv.h
diff --git a/apps/cmp_mock_srv.c b/apps/lib/cmp_mock_srv.c
similarity index 100%
rename from apps/cmp_mock_srv.c
rename to apps/lib/cmp_mock_srv.c
diff --git a/test/build.info b/test/build.info
index 842a7bbe35..58d75be5d4 100644
--- a/test/build.info
+++ b/test/build.info
@@ -529,7 +529,7 @@ IF[{- !$disabled{tests} -}]
   INCLUDE[cmp_server_test]=.. ../include ../apps/include
   DEPEND[cmp_server_test]=../libcrypto.a libtestutil.a
 
-  SOURCE[cmp_client_test]=cmp_client_test.c helpers/cmp_testlib.c ../apps/cmp_mock_srv.c
+  SOURCE[cmp_client_test]=cmp_client_test.c helpers/cmp_testlib.c ../apps/lib/cmp_mock_srv.c
   INCLUDE[cmp_client_test]=.. ../include ../apps/include
   DEPEND[cmp_client_test]=../libcrypto.a libtestutil.a
 
diff --git a/test/cmp_client_test.c b/test/cmp_client_test.c
index 35a7c30f92..3d9b37b3a2 100644
--- a/test/cmp_client_test.c
+++ b/test/cmp_client_test.c
@@ -11,7 +11,7 @@
 
 #include "helpers/cmp_testlib.h"
 
-#include "apps/cmp_mock_srv.h"
+#include "cmp_mock_srv.h"
 
 #ifndef NDEBUG /* tests need mock server, which is available only if !NDEBUG */
 
diff --git a/util/find-doc-nits b/util/find-doc-nits
index fd465f6d0b..815880ad01 100755
--- a/util/find-doc-nits
+++ b/util/find-doc-nits
@@ -1128,7 +1128,7 @@ if ( $opt_c ) {
     # See if each has a manpage.
     foreach my $cmd ( @commands ) {
         $cmd =~ s/\.c$//;
-        next if $cmd eq 'progs' || $cmd eq 'cmp_mock_srv' || $cmd eq 'vms_decc_init';
+        next if $cmd eq 'progs' || $cmd eq 'vms_decc_init';
         my @doc = ( grep { basename($_) eq "openssl-$cmd.pod"
                            # For "tsget" and "CA.pl" pod pages
                            || basename($_) eq "$cmd.pod" }


More information about the openssl-commits mailing list