Skip to content

Commit 3437e90

Browse files
jstancekgregkh
authored andcommitted
sign-file,extract-cert: move common SSL helper functions to a header
commit 300e6d4116f956b035281ec94297dc4dc8d4e1d3 upstream. Couple error handling helpers are repeated in both tools, so move them to a common header. Signed-off-by: Jan Stancek <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Tested-by: R Nageswara Sastry <[email protected]> Reviewed-by: Neal Gompa <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Huacai Chen <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 16c54d6 commit 3437e90

File tree

5 files changed

+45
-71
lines changed

5 files changed

+45
-71
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4833,6 +4833,7 @@ S: Maintained
48334833
F: Documentation/admin-guide/module-signing.rst
48344834
F: certs/
48354835
F: scripts/sign-file.c
4836+
F: scripts/ssl-common.h
48364837
F: tools/certs/
48374838

48384839
CFAG12864B LCD DRIVER

certs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,5 @@ targets += x509_revocation_list
8484

8585
hostprogs := extract-cert
8686

87-
HOSTCFLAGS_extract-cert.o = $(shell $(HOSTPKG_CONFIG) --cflags libcrypto 2> /dev/null)
87+
HOSTCFLAGS_extract-cert.o = $(shell $(HOSTPKG_CONFIG) --cflags libcrypto 2> /dev/null) -I$(srctree)/scripts
8888
HOSTLDLIBS_extract-cert = $(shell $(HOSTPKG_CONFIG) --libs libcrypto 2> /dev/null || echo -lcrypto)

certs/extract-cert.c

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <openssl/err.h>
2424
#include <openssl/engine.h>
2525

26+
#include "ssl-common.h"
27+
2628
/*
2729
* OpenSSL 3.0 deprecates the OpenSSL's ENGINE API.
2830
*
@@ -40,41 +42,6 @@ void format(void)
4042
exit(2);
4143
}
4244

43-
static void display_openssl_errors(int l)
44-
{
45-
const char *file;
46-
char buf[120];
47-
int e, line;
48-
49-
if (ERR_peek_error() == 0)
50-
return;
51-
fprintf(stderr, "At main.c:%d:\n", l);
52-
53-
while ((e = ERR_get_error_line(&file, &line))) {
54-
ERR_error_string(e, buf);
55-
fprintf(stderr, "- SSL %s: %s:%d\n", buf, file, line);
56-
}
57-
}
58-
59-
static void drain_openssl_errors(void)
60-
{
61-
const char *file;
62-
int line;
63-
64-
if (ERR_peek_error() == 0)
65-
return;
66-
while (ERR_get_error_line(&file, &line)) {}
67-
}
68-
69-
#define ERR(cond, fmt, ...) \
70-
do { \
71-
bool __cond = (cond); \
72-
display_openssl_errors(__LINE__); \
73-
if (__cond) { \
74-
err(1, fmt, ## __VA_ARGS__); \
75-
} \
76-
} while(0)
77-
7845
static const char *key_pass;
7946
static BIO *wb;
8047
static char *cert_dst;

scripts/sign-file.c

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include <openssl/err.h>
3030
#include <openssl/engine.h>
3131

32+
#include "ssl-common.h"
33+
3234
/*
3335
* OpenSSL 3.0 deprecates the OpenSSL's ENGINE API.
3436
*
@@ -83,41 +85,6 @@ void format(void)
8385
exit(2);
8486
}
8587

86-
static void display_openssl_errors(int l)
87-
{
88-
const char *file;
89-
char buf[120];
90-
int e, line;
91-
92-
if (ERR_peek_error() == 0)
93-
return;
94-
fprintf(stderr, "At main.c:%d:\n", l);
95-
96-
while ((e = ERR_get_error_line(&file, &line))) {
97-
ERR_error_string(e, buf);
98-
fprintf(stderr, "- SSL %s: %s:%d\n", buf, file, line);
99-
}
100-
}
101-
102-
static void drain_openssl_errors(void)
103-
{
104-
const char *file;
105-
int line;
106-
107-
if (ERR_peek_error() == 0)
108-
return;
109-
while (ERR_get_error_line(&file, &line)) {}
110-
}
111-
112-
#define ERR(cond, fmt, ...) \
113-
do { \
114-
bool __cond = (cond); \
115-
display_openssl_errors(__LINE__); \
116-
if (__cond) { \
117-
errx(1, fmt, ## __VA_ARGS__); \
118-
} \
119-
} while(0)
120-
12188
static const char *key_pass;
12289

12390
static int pem_pw_cb(char *buf, int len, int w, void *v)

scripts/ssl-common.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* SPDX-License-Identifier: LGPL-2.1+ */
2+
/*
3+
* SSL helper functions shared by sign-file and extract-cert.
4+
*/
5+
6+
static void display_openssl_errors(int l)
7+
{
8+
const char *file;
9+
char buf[120];
10+
int e, line;
11+
12+
if (ERR_peek_error() == 0)
13+
return;
14+
fprintf(stderr, "At main.c:%d:\n", l);
15+
16+
while ((e = ERR_get_error_line(&file, &line))) {
17+
ERR_error_string(e, buf);
18+
fprintf(stderr, "- SSL %s: %s:%d\n", buf, file, line);
19+
}
20+
}
21+
22+
static void drain_openssl_errors(void)
23+
{
24+
const char *file;
25+
int line;
26+
27+
if (ERR_peek_error() == 0)
28+
return;
29+
while (ERR_get_error_line(&file, &line)) {}
30+
}
31+
32+
#define ERR(cond, fmt, ...) \
33+
do { \
34+
bool __cond = (cond); \
35+
display_openssl_errors(__LINE__); \
36+
if (__cond) { \
37+
errx(1, fmt, ## __VA_ARGS__); \
38+
} \
39+
} while (0)

0 commit comments

Comments
 (0)