Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

X509_NAME macro in C won't compile

Tags:

c

openssl

This is a silly compilation error, but for the life of me I can't find out what's wrong. I have spent hours on it, but I have made no progress at all. And I certainly don't understand enough about OpenSSL to understand what an X509_NAME is.

I'm compiling a small C file whose function it is to print out an error message if anyone calls one of the 30 or so functions in the file, to indicate that the 30 SSL functions are not supported by the C program. Each function is about 3 lines long (see below). The calling interface is copied from the OpenSSL openssl/X509.h file for win32. (I'm running Windows10 x64, but compiling with VStudio 2017 command line set up for 32bits).

Here is the original interface from the openssl/x509.h include file:

int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len);

Since the original x509.h include file says inside that "the definition for X509_NAME on Win32 is located in wincrypt.h," I copied the definition for the X509_NAME macro directly into my source file as shown below.

The code for my simple error message function follows. I just copied the interface definition from the openssl/x509.h file and made it into a function:

#define X509_NAME ((LPCSTR) 7) /* copied from wincrypt.h */
int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len) {
    print_error (E_NO_SSL_SUPPORT);
    return (-1);
}

When I try to compile the code with the VS 2017 command line compiler for 32bits, I get these error messages. Line 236 contains the troublesome code line int X509_NAME_....

cl   /c /Od /nologo /MT /I. "-I..\s" ..\s\stubssl.c
stubssl.c
..\s\stubssl.c(236): error C2143: syntax error: missing ')' before '('
..\s\stubssl.c(236): error C2091: function returns function
..\s\stubssl.c(236): error C2059: syntax error: ')'
..\s\stubssl.c(236): error C2143: syntax error: missing ')' before 'constant'
..\s\stubssl.c(236): error C2143: syntax error: missing '{' before 'constant'
..\s\stubssl.c(236): error C2059: syntax error: 'constant'
..\s\stubssl.c(242): error C2059: syntax error: '<parameter-list>'
c:\stubssl\winxp\make.exe: *** [stubssl.obj] Error 2

I get the same kind of error with another function that is a bit simpler (but that also uses the X509_NAME macro). It starts on line 242 (see the error messages above).

X509_NAME *X509_get_subject_name(X509 *a) {
    hio_oerror (E_NO_SSL_SUPPORT);
    return (NULL);
}

Does anyone have any idea how I might try to resolve this problem? It seems so simple, yet it has been very elusive for me to solve. I can't imagine how I can be missing ')' before '(' in those lines.

EDIT: My include files in stubssl.c:

#define WIN32_LEAN_AND_MEAN
#include "openssl/ssl.h"
#include "openssl/x509.h"
#include "openssl/bio.h"
#include "openssl/pem.h"
like image 406
Kevin Avatar asked Sep 11 '25 07:09

Kevin


1 Answers

In openSSL, X509_NAME is a type, but <wincrypt.h> defines it as a value (((LPCSTR) 7)). Don't define it yourself, but use the openSSL header, don't include <wincrypt.h> and #define WIN32_LEAN_AND_MEAN to avoid it being included through other windows headers.

like image 83
a3f Avatar answered Sep 12 '25 21:09

a3f