Skip to content

Commit 6dd008a

Browse files
authored
Merge pull request #54 from 1nfiniteloop/x509-uplift-reviewed
Updated x509 modules to match openssl 1.1.0h API, reviewed
2 parents d7febf2 + f291205 commit 6dd008a

File tree

10 files changed

+3207
-1935
lines changed

10 files changed

+3207
-1935
lines changed

CONTRIBUTING.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Summary
2+
3+
This instruction describes how to pragmatically upgrade the openssl d-bindings
4+
to match the C-headers version, in this case current version is 1.1.0h.
5+
6+
## Steps
7+
8+
### Preparation
9+
10+
1. Get d-step tool with:
11+
```
12+
curl \
13+
--location \
14+
https://github.com/jacob-carlborg/dstep/releases/download/v1.0.0/dstep-1.0.0-linux-x86_64.tar.xz \
15+
| tar -x --xz --location /usr/local/bin
16+
```
17+
See more @ <https://github.com/jacob-carlborg/dstep/releases>.
18+
2. Clone openssl with `git clone https://github.com/openssl/openssl` and
19+
checkout correct tag, example `cd openssl && git checkout OpenSSL_1_1_0h`.
20+
3. Headers with suffix ".h.in" need to be parsed to .h before generation,
21+
Configure openssl with `./configure` and build generated file with
22+
`make build_generated`.
23+
24+
### Check dependencies
25+
26+
A good approach is to convert the files in ascending order for no of
27+
dependencies. Example when converting x509, use order: `x509_vfy.h` which
28+
is used by 1 other file, `x509v3.h` is used by 3 other files, `x509.h`
29+
is used by 11 other files.
30+
31+
```
32+
grep -r 'include <openssl/x509_vfy.h>$' C/
33+
grep -r 'include <openssl/x509v3.h>$' C/
34+
grep -r 'include <openssl/x509.h>$' C/
35+
```
36+
37+
### Generate module from C header
38+
39+
1. Generate d-module from the openssl c-header with
40+
`dstep --space-after-function-name=false -Iinclude/ include/openssl/<file>`. Commit the change.
41+
42+
### Manual patching
43+
44+
Below is a checklist for common known issues which needs manual work:
45+
46+
1. d-step doesn't resolve includes. Translate "import" statements from
47+
`#include` in header-file accordingly, and possible check in the old .d-file
48+
for special cases.
49+
2. Function aliases in C-headers without argument list, example
50+
`#define alias-name function` are generated as enum types. This gives
51+
compilation error similar to "missing argument for parameter #1".
52+
Replace "enum" with "alias" accordingly.
53+
3. Many struct definitions is removed, instead a declaration ia added into
54+
`ossl_typ.d`, Example `grep -r 'struct X509_pubkey_st' C/` shows that struct
55+
definition is removed from `x509.h` and instead a declaration is added in
56+
`ossl_typ.h`. Other types might be removed, check the header-file and adjust
57+
accordingly if the type is missing when compiling.
58+
4. Check the header-file for "ifdef|ifndef", search for "OPENSSL_*" where some
59+
statements has historically been translated into "version" in d-modules.
60+
5. Macros `STACK_OF`, `DEFINE_STACK_OF`: in version 1.1.0h the macro `STACK_OF`
61+
in `safestack.d` has changed. During generation it's properly expanded into
62+
a type prefixed with `stack_st`. Since other dependent modules might not be
63+
uplifted, a declaration sometimes need to be inserted to make it
64+
compile. It will result in "type missing "stack_st_...". Check in which
65+
header the macro `DEFINE_STACK_OF(<type>)` is defined in and manually add
66+
`struct stack_st_<type-name>` to make it compile. However these functions
67+
will not work properly during linkage until `safestack.d` is uplifted,
68+
see macro `DEFINE_STACK_OF` in safestack.h.
69+

deimos/openssl/asn1.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,8 @@ ASN1_OBJECT* d2i_ASN1_OBJECT(ASN1_OBJECT** a,const(ubyte)** pp,
820820
mixin(DECLARE_ASN1_ITEM!"ASN1_OBJECT");
821821

822822
/+mixin DECLARE_STACK_OF!(ASN1_OBJECT);+/
823+
struct stack_st_ASN1_OBJECT; // define type to make it compile, needed until this module and safestack.d is converted and supports "DEFINE_STACK_OF"
824+
823825
mixin DECLARE_ASN1_SET_OF!(ASN1_OBJECT);
824826

825827
ASN1_STRING* ASN1_STRING_new();

deimos/openssl/conf.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ struct CONF_VALUE
7878
char* value;
7979
}
8080

81+
struct lhash_st_CONF_VALUE; // declare type to make it compile, needed until this module and lhash.d is uplifted to >= 1.1.0h and supports "DEFINE_LHASH_OF"
82+
8183
/+mixin DECLARE_STACK_OF!(CONF_VALUE);+/
8284
mixin DECLARE_LHASH_OF!(CONF_VALUE);
8385

deimos/openssl/crypto.d

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ public import deimos.openssl.symhacks;
142142
extern (C):
143143
nothrow:
144144

145+
alias OPENSSL_buf2hexstr = char* function(const ubyte*, long);
146+
alias OPENSSL_hexstr2buf = ubyte* function(const char*, long*);
147+
145148
/* Backward compatibility to SSLeay */
146149
/* This is more to be used to check the correct DLL is being used
147150
* in the MS world. */

deimos/openssl/ossl_typ.d

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,38 @@ alias ecdsa_method ECDSA_METHOD;
171171

172172
import deimos.openssl.x509;
173173
import deimos.openssl.x509_vfy;
174+
175+
struct ssl_dane_st;
176+
alias SSL_DANE = ssl_dane_st;
177+
178+
struct x509_st;
174179
alias x509_st X509;
175180
alias X509_algor_st X509_ALGOR;
181+
struct X509_crl_st;
176182
alias X509_crl_st X509_CRL;
177183
struct x509_crl_method_st;
178184
alias x509_crl_method_st X509_CRL_METHOD;
185+
struct x509_revoked_st;
179186
alias x509_revoked_st X509_REVOKED;
187+
struct X509_name_st;
180188
alias X509_name_st X509_NAME;
189+
struct X509_pubkey_st;
181190
alias X509_pubkey_st X509_PUBKEY;
191+
struct x509_store_st;
182192
alias x509_store_st X509_STORE;
183-
/*struct x509_store_ctx_st;*/
193+
struct x509_store_ctx_st;
184194
alias x509_store_ctx_st X509_STORE_CTX;
195+
struct x509_lookup_st;
196+
alias X509_LOOKUP = x509_lookup_st;
197+
198+
struct x509_object_st;
199+
alias X509_OBJECT = x509_object_st;
200+
struct x509_lookup_method_st;
201+
alias X509_LOOKUP_METHOD = x509_lookup_method_st;
202+
struct X509_VERIFY_PARAM_st;
203+
alias X509_VERIFY_PARAM = X509_VERIFY_PARAM_st;
204+
205+
struct pkcs8_priv_key_info_st;
185206
alias pkcs8_priv_key_info_st PKCS8_PRIV_KEY_INFO;
186207

187208
import deimos.openssl.x509v3;

deimos/openssl/pem.d

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,6 @@ mixin(DECLARE_PEM_rw!("X509", "X509")());
477477

478478
mixin(DECLARE_PEM_rw!("X509_AUX", "X509")());
479479

480-
mixin(DECLARE_PEM_rw!("X509_CERT_PAIR", "X509_CERT_PAIR")());
481-
482480
mixin(DECLARE_PEM_rw!("X509_REQ", "X509_REQ")());
483481
mixin(DECLARE_PEM_write!("X509_REQ_NEW", "X509_REQ")());
484482

deimos/openssl/safestack.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ mixin DECLARE_SPECIAL_STACK_OF!(OPENSSL_STRING, char);
126126
* nul-terminated. These should also be distinguished from "normal"
127127
* stacks. */
128128

129+
struct stack_st_OPENSSL_STRING; // declare type to make it compile, needed until this module is uplifted to >= 1.1.0h and supports "DECLARE_SPECIAL_STACK_OF"
130+
129131
alias void* OPENSSL_BLOCK;
130132
mixin DECLARE_SPECIAL_STACK_OF!(OPENSSL_BLOCK, void);
131133
/* SKM_sk_... stack macros are internal to safestack.h:

0 commit comments

Comments
 (0)