|
|
dbb109 |
From 5081b5ef7c6338ff5b19520ef828a8a1aaf7631d Mon Sep 17 00:00:00 2001
|
|
|
dbb109 |
From: Rob Crittenden <rcritten@redhat.com>
|
|
|
dbb109 |
Date: Fri, 1 May 2020 16:22:20 -0400
|
|
|
dbb109 |
Subject: [PATCH] Ensure that files read in have a trailing new-line
|
|
|
dbb109 |
|
|
|
dbb109 |
In SCEP when retrieving the CA chain the certificates passed in
|
|
|
dbb109 |
on the command-line (RA agent and CA cert) area printed along with
|
|
|
dbb109 |
the contents of what was retrieved remotely.
|
|
|
dbb109 |
|
|
|
dbb109 |
If one of the filesystem certificates lacks a newline then the
|
|
|
dbb109 |
output will be jumbled like:
|
|
|
dbb109 |
|
|
|
dbb109 |
-----END CERTIFICATE----------BEGIN CERTIFICATE-----\n
|
|
|
dbb109 |
|
|
|
dbb109 |
https://bugzilla.redhat.com/show_bug.cgi?id=1814976
|
|
|
dbb109 |
---
|
|
|
dbb109 |
src/submit-u.c | 8 +++++
|
|
|
dbb109 |
tests/039-fromfile/expected.out | 4 +++
|
|
|
dbb109 |
tests/039-fromfile/run.sh | 55 +++++++++++++++++++++++++++++++++
|
|
|
dbb109 |
tests/Makefile.am | 6 ++--
|
|
|
dbb109 |
tests/tools/Makefile.am | 6 +++-
|
|
|
dbb109 |
tests/tools/fromfile.c | 52 +++++++++++++++++++++++++++++++
|
|
|
dbb109 |
6 files changed, 128 insertions(+), 3 deletions(-)
|
|
|
dbb109 |
create mode 100644 tests/039-fromfile/expected.out
|
|
|
dbb109 |
create mode 100755 tests/039-fromfile/run.sh
|
|
|
dbb109 |
create mode 100644 tests/tools/fromfile.c
|
|
|
dbb109 |
|
|
|
dbb109 |
diff --git a/src/submit-u.c b/src/submit-u.c
|
|
|
dbb109 |
index dda2edb..191526b 100644
|
|
|
dbb109 |
--- a/src/submit-u.c
|
|
|
dbb109 |
+++ b/src/submit-u.c
|
|
|
dbb109 |
@@ -100,6 +100,14 @@ cm_submit_u_from_file(const char *filename)
|
|
|
dbb109 |
}
|
|
|
dbb109 |
if (csr == NULL) {
|
|
|
dbb109 |
csr = strdup("");
|
|
|
dbb109 |
+ } else {
|
|
|
dbb109 |
+ int length = strlen(csr);
|
|
|
dbb109 |
+ if (csr[length-1] != '\n') {
|
|
|
dbb109 |
+ length += 1;
|
|
|
dbb109 |
+ csr = realloc(csr, length + 1);
|
|
|
dbb109 |
+ csr[length - 1] = '\n';
|
|
|
dbb109 |
+ csr[length] = '\0';
|
|
|
dbb109 |
+ }
|
|
|
dbb109 |
}
|
|
|
dbb109 |
return csr;
|
|
|
dbb109 |
}
|
|
|
dbb109 |
diff --git a/tests/039-fromfile/expected.out b/tests/039-fromfile/expected.out
|
|
|
dbb109 |
new file mode 100644
|
|
|
dbb109 |
index 0000000..9191a57
|
|
|
dbb109 |
--- /dev/null
|
|
|
dbb109 |
+++ b/tests/039-fromfile/expected.out
|
|
|
dbb109 |
@@ -0,0 +1,4 @@
|
|
|
dbb109 |
+[trailing_nl]
|
|
|
dbb109 |
+Ok
|
|
|
dbb109 |
+[no_trailing_nl]
|
|
|
dbb109 |
+Ok
|
|
|
dbb109 |
diff --git a/tests/039-fromfile/run.sh b/tests/039-fromfile/run.sh
|
|
|
dbb109 |
new file mode 100755
|
|
|
dbb109 |
index 0000000..8bae773
|
|
|
dbb109 |
--- /dev/null
|
|
|
dbb109 |
+++ b/tests/039-fromfile/run.sh
|
|
|
dbb109 |
@@ -0,0 +1,55 @@
|
|
|
dbb109 |
+#!/bin/bash -e
|
|
|
dbb109 |
+
|
|
|
dbb109 |
+cd $tmpdir
|
|
|
dbb109 |
+
|
|
|
dbb109 |
+cat > $tmpdir/trailing_nl <<- EOF
|
|
|
dbb109 |
+-----BEGIN CERTIFICATE-----
|
|
|
dbb109 |
+MIIDjjCCAnagAwIBAgIRAO1VmyXYM0f7pbXVdEGtRPMwDQYJKoZIhvcNAQELBQAw
|
|
|
dbb109 |
+UDEgMB4GA1UEAwwXTG9jYWwgU2lnbmluZyBBdXR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ile trailing_nl
|
|
|
dbb109 |
+$toolsdir/fromfile no_trailing_nl
|
|
|
dbb109 |
diff --git a/tests/Makefile.am b/tests/Makefile.am
|
|
|
dbb109 |
index 562b027..1fe7e55 100644
|
|
|
dbb109 |
--- a/tests/Makefile.am
|
|
|
dbb109 |
+++ b/tests/Makefile.am
|
|
|
dbb109 |
@@ -151,7 +151,8 @@ EXTRA_DIST = \
|
|
|
dbb109 |
037-rekey2/run.sh \
|
|
|
dbb109 |
038-ms-v2-template/expected.out \
|
|
|
dbb109 |
038-ms-v2-template/extract-extdata.py \
|
|
|
dbb109 |
- 038-ms-v2-template/run.sh
|
|
|
dbb109 |
+ 038-ms-v2-template/run.sh \
|
|
|
dbb109 |
+ 039-fromfile/run.sh
|
|
|
dbb109 |
|
|
|
dbb109 |
subdirs = \
|
|
|
dbb109 |
001-keyiread \
|
|
|
dbb109 |
@@ -193,7 +194,8 @@ subdirs = \
|
|
|
dbb109 |
035-json \
|
|
|
dbb109 |
036-getcert \
|
|
|
dbb109 |
037-rekey2 \
|
|
|
dbb109 |
- 038-ms-v2-template
|
|
|
dbb109 |
+ 038-ms-v2-template \
|
|
|
dbb109 |
+ 039-fromfile
|
|
|
dbb109 |
|
|
|
dbb109 |
if HAVE_DBM_NSSDB
|
|
|
dbb109 |
subdirs += \
|
|
|
dbb109 |
diff --git a/tests/tools/Makefile.am b/tests/tools/Makefile.am
|
|
|
dbb109 |
index 9988b8c..d927e9b 100644
|
|
|
dbb109 |
--- a/tests/tools/Makefile.am
|
|
|
dbb109 |
+++ b/tests/tools/Makefile.am
|
|
|
dbb109 |
@@ -15,7 +15,7 @@ endif
|
|
|
dbb109 |
noinst_PROGRAMS = keyiread keygen csrgen submit certread certsave oid2name \
|
|
|
dbb109 |
name2oid iterate prefs dates listnicks pem2base base2pem \
|
|
|
dbb109 |
dparse payload checksig base64 cadata citerate casave hooks \
|
|
|
dbb109 |
- libexecdir canon srv addcinfo ls json json-utf8 printenv
|
|
|
dbb109 |
+ libexecdir canon srv addcinfo ls json json-utf8 printenv fromfile
|
|
|
dbb109 |
noinst_LIBRARIES = libtools.a
|
|
|
dbb109 |
if HAVE_OPENSSL
|
|
|
dbb109 |
noinst_PROGRAMS += pk7parse pk7env scepgen pk7verify pk7decrypt
|
|
|
dbb109 |
@@ -36,3 +36,7 @@ citerate_SOURCES = citerate.c ../../src/store-gen.c
|
|
|
dbb109 |
|
|
|
dbb109 |
srv_SOURCES = srv.c ../../src/srvloc.c
|
|
|
dbb109 |
srv_LDADD = $(LDADD)
|
|
|
dbb109 |
+
|
|
|
dbb109 |
+fromfile_CFLAGS = $(AM_CFLAGS)
|
|
|
dbb109 |
+fromfile_SOURCES = fromfile.c
|
|
|
dbb109 |
+fromfile_LDADD = $(top_srcdir)/src/submit-u.c $(LDADD) $(UUID_LIBS)
|
|
|
dbb109 |
diff --git a/tests/tools/fromfile.c b/tests/tools/fromfile.c
|
|
|
dbb109 |
new file mode 100644
|
|
|
dbb109 |
index 0000000..c1d2694
|
|
|
dbb109 |
--- /dev/null
|
|
|
dbb109 |
+++ b/tests/tools/fromfile.c
|
|
|
dbb109 |
@@ -0,0 +1,52 @@
|
|
|
dbb109 |
+/*
|
|
|
dbb109 |
+ * Copyright (C) 2020 Red Hat, Inc.
|
|
|
dbb109 |
+ *
|
|
|
dbb109 |
+ * This program is free software: you can redistribute it and/or modify
|
|
|
dbb109 |
+ * it under the terms of the GNU General Public License as published by
|
|
|
dbb109 |
+ * the Free Software Foundation, either version 3 of the License, or
|
|
|
dbb109 |
+ * (at your option) any later version.
|
|
|
dbb109 |
+ *
|
|
|
dbb109 |
+ * This program is distributed in the hope that it will be useful,
|
|
|
dbb109 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
dbb109 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
dbb109 |
+ * GNU General Public License for more details.
|
|
|
dbb109 |
+ *
|
|
|
dbb109 |
+ * You should have received a copy of the GNU General Public License
|
|
|
dbb109 |
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
dbb109 |
+ */
|
|
|
dbb109 |
+
|
|
|
dbb109 |
+#include <sys/types.h>
|
|
|
dbb109 |
+#include <errno.h>
|
|
|
dbb109 |
+#include <stdlib.h>
|
|
|
dbb109 |
+#include <stdio.h>
|
|
|
dbb109 |
+#include <string.h>
|
|
|
dbb109 |
+
|
|
|
dbb109 |
+#include <time.h>
|
|
|
dbb109 |
+#include <krb5.h>
|
|
|
dbb109 |
+
|
|
|
dbb109 |
+#include "../../src/config.h"
|
|
|
dbb109 |
+#include "../../src/submit-u.h"
|
|
|
dbb109 |
+
|
|
|
dbb109 |
+int
|
|
|
dbb109 |
+main(int argc, char **argv)
|
|
|
dbb109 |
+{
|
|
|
dbb109 |
+ int i, result = 0;
|
|
|
dbb109 |
+ char *cert;
|
|
|
dbb109 |
+
|
|
|
dbb109 |
+ for (i = 1; i < argc; i++) {
|
|
|
dbb109 |
+ printf("[%s]\n", argv[i]);
|
|
|
dbb109 |
+ cert = cm_submit_u_from_file(argv[i]);
|
|
|
dbb109 |
+ if (cert == NULL) {
|
|
|
dbb109 |
+ printf("OOM error\n");
|
|
|
dbb109 |
+ result = 1;
|
|
|
dbb109 |
+ }
|
|
|
dbb109 |
+ else if (cert[strlen(cert) - 1] != '\n') {
|
|
|
dbb109 |
+ printf("Missing trailing newline\n");
|
|
|
dbb109 |
+ result = 1;
|
|
|
dbb109 |
+ } else {
|
|
|
dbb109 |
+ printf("Ok\n");
|
|
|
dbb109 |
+ }
|
|
|
dbb109 |
+ free(cert);
|
|
|
dbb109 |
+ }
|
|
|
dbb109 |
+ return result;
|
|
|
dbb109 |
+}
|
|
|
dbb109 |
--
|
|
|
dbb109 |
2.21.1
|
|
|
dbb109 |
|