Skip to content

Commit 36ce16f

Browse files
authored
Merge pull request gost-engine#489 from VladGud/fix-openssl-3-6
Fix OpenSSL 3.6 compatibility and update gost-engine NID handling
2 parents 6dc5945 + 56b8931 commit 36ce16f

15 files changed

Lines changed: 669 additions & 195 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: CI
22
on: [push, pull_request]
33

44
env:
5-
OPENSSL_BRANCH: openssl-3.4.2
5+
OPENSSL_BRANCH: openssl-3.6
66
USE_RPATH: yes
77
PATCH_OPENSSL: 0
88
GOST_PROVIDER_ENABLE_ONLINE_TESTS: 1

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: "CodeQL"
22

33
env:
4-
OPENSSL_BRANCH: openssl-3.4.2
4+
OPENSSL_BRANCH: openssl-3.6
55
#RPATH: "-Wl,-rpath=${PREFIX}/lib"
66
#PREFIX: ${HOME}/opt
77
#PATH: ${PREFIX}/bin:${PATH}

.github/workflows/coverity.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
if: ${{ github.repository_owner == 'gost-engine' || github.event_name == 'workflow_dispatch' }}
1212
env:
13-
OPENSSL_BRANCH: openssl-3.4.2
13+
OPENSSL_BRANCH: openssl-3.6
1414
USE_RPATH: yes
1515
PATCH_OPENSSL: 1
1616
GOST_PROVIDER_ENABLE_ONLINE_TESTS: 0

.github/workflows/windows.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
with:
1313
repository: openssl/openssl
1414
path: openssl
15-
ref: openssl-3.4.2
15+
ref: openssl-3.6
1616
fetch-depth: 0
1717
- run: echo "::set-output name=head::$(git -C openssl describe --always --long)"
1818
id: openssl
@@ -49,7 +49,7 @@ jobs:
4949
- run: cmake --build .
5050
- name: Run tests
5151
run: |
52-
$env:PATH = "$pwd\openssl\_dest\Program Files\OpenSSL\bin;$env:PATH"
5352
$env:OPENSSL_ENGINES = "$pwd\bin\Debug"
5453
$env:OPENSSL_MODULES = "$pwd\bin\Debug"
54+
Copy-Item -Path "$pwd\openssl\_dest\Program Files\OpenSSL\bin\*.dll" -Destination "$pwd\bin\Debug"
5555
ctest -C Debug --output-on-failure

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ if (ASAN)
4848
set(SKIP_PERL_TESTS 1)
4949
endif()
5050

51+
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
52+
set(SKIP_PERL_TESTS 1)
53+
endif()
54+
5155
set(CMAKE_C_STANDARD 90)
5256
CHECK_FUNCTION_EXISTS(clock_gettime HAVE_CLOCK_GETTIME_C)
5357
CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_CLOCK_GETTIME_RT)
@@ -322,6 +326,12 @@ if(TLS13_PATCHED_OPENSSL)
322326
set_tests_properties(mgm-with-provider
323327
PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT_PROVIDER}")
324328
set_property(TARGET test_mgm APPEND PROPERTY COMPILE_DEFINITIONS ENGINE_DIR="${OUTPUT_DIRECTORY}")
329+
330+
add_executable(test_tls13handshake test_tls13handshake.c)
331+
target_link_libraries(test_tls13handshake OpenSSL::Crypto OpenSSL::SSL)
332+
add_test(NAME test-tls13handshake-with-provider COMMAND test_tls13handshake)
333+
set_tests_properties(test-tls13handshake-with-provider
334+
PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT_PROVIDER}")
325335
endif()
326336

327337
if(NOT SKIP_PERL_TESTS)

gost_crypt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ GOST_cipher magma_ecb_cipher = {
251251
.do_cipher = magma_cipher_do_ecb,
252252
};
253253

254-
GOST_cipher magma_mgm_cipher = {
254+
GOST_cipher magma_mgm_cipher = {
255255
.nid = NID_undef,
256256
.template = &magma_template_cipher,
257257
.block_size = 1,
@@ -264,7 +264,7 @@ GOST_cipher magma_ecb_cipher = {
264264
.ctrl = gost_magma_mgm_ctrl,
265265
.cleanup = gost_magma_mgm_cleanup,
266266
.ctx_size = sizeof(gost_mgm_ctx)
267-
};
267+
};
268268

269269
static void magma_NID_callback (int nid)
270270
{
@@ -1164,7 +1164,7 @@ static int gost_magma_mgm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
11641164
case EVP_CTRL_TLSTREE:
11651165
{
11661166
unsigned char newkey[32];
1167-
if (gost_tlstree(NID_magma_mgm,
1167+
if (gost_tlstree(OBJ_sn2nid(SN_magma_mgm),
11681168
(const unsigned char *)mctx->ks.g_ks.cctx.master_key,
11691169
newkey, (const unsigned char *)ptr, mctx->tlstree_mode)
11701170
> 0) {

gost_eng.c

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -331,33 +331,55 @@ static int gost_engine_destroy(ENGINE* e) {
331331
* Following is the glue that populates the ENGINE structure and that
332332
* binds it to OpenSSL libraries
333333
*/
334-
335334
static GOST_NID_JOB *missing_NIDs[] = {
336335
&kuznyechik_mgm_NID,
337336
&magma_mgm_NID,
338337
};
339338

339+
static int create_new_nid_for_gost_nid_job(GOST_NID_JOB *job) {
340+
int nid = OBJ_new_nid(1);
341+
ASN1_OBJECT *obj =
342+
ASN1_OBJECT_create(nid, NULL, 0, job->sn, job->ln);
343+
344+
if (!obj || OBJ_add_object(obj) == NID_undef) {
345+
OPENSSL_free(obj);
346+
return 0;
347+
}
348+
349+
job->asn1 = obj;
350+
job->callback(nid);
351+
352+
return 1;
353+
}
354+
340355
static int create_NIDs() {
341-
int i;
342-
int new_nid = OBJ_new_nid(OSSL_NELEM(missing_NIDs));
356+
int i, nid;
357+
343358
for (i = 0; i < OSSL_NELEM(missing_NIDs); i++) {
344359
GOST_NID_JOB *job = missing_NIDs[i];
345-
ASN1_OBJECT *obj =
346-
ASN1_OBJECT_create(new_nid + i, NULL, 0, job->sn, job->ln);
347-
job->asn1 = obj;
348-
if (!obj || OBJ_add_object(obj) == NID_undef) {
349-
OPENSSL_free(obj);
360+
361+
nid = OBJ_sn2nid(job->sn);
362+
if (nid != NID_undef) {
363+
job->callback(nid);
364+
continue;
365+
}
366+
367+
if (!create_new_nid_for_gost_nid_job(job)) {
350368
return 0;
351369
}
352-
(*missing_NIDs[i]->callback)(new_nid + i);
353370
}
354371
return 1;
355372
}
356373

357-
static void free_NIDs() {
374+
static void free_NIDs(void) {
358375
int i;
376+
359377
for (i = 0; i < OSSL_NELEM(missing_NIDs); i++) {
360-
ASN1_OBJECT_free(missing_NIDs[i]->asn1);
378+
GOST_NID_JOB *job = missing_NIDs[i];
379+
if (job->asn1) {
380+
ASN1_OBJECT_free(job->asn1);
381+
job->asn1 = NULL;
382+
}
361383
}
362384
}
363385

gost_grasshopper_cipher.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ static int gost_grasshopper_mgm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void
11051105
case EVP_CTRL_TLSTREE:
11061106
{
11071107
unsigned char newkey[32];
1108-
if (gost_tlstree(NID_kuznyechik_mgm,
1108+
if (gost_tlstree(OBJ_sn2nid(SN_kuznyechik_mgm),
11091109
mctx->ks.gh_ks.master_key.k.b, newkey,
11101110
(const unsigned char *)ptr, mctx->tlstree_mode)
11111111
> 0) {

gost_keyexpimp.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <openssl/buffer.h>
1313

1414
#include "gost_lcl.h"
15+
#include "gost_gost2015.h"
16+
#include "gost_grasshopper_cipher.h"
1517
#include "e_gost_err.h"
1618

1719
static uint32_t be32(uint32_t host)
@@ -267,51 +269,40 @@ int gost_tlstree(int cipher_nid, const unsigned char *in, unsigned char *out,
267269
unsigned char ko1[32], ko2[32];
268270
int ret;
269271

270-
switch (cipher_nid) {
271-
case NID_magma_cbc:
272+
if (cipher_nid == NID_magma_cbc) {
272273
c1 = 0x00000000C0FFFFFF;
273274
c2 = 0x000000FEFFFFFFFF;
274275
c3 = 0x00F0FFFFFFFFFFFF;
275-
break;
276-
case NID_grasshopper_cbc:
276+
} else if (cipher_nid == NID_grasshopper_cbc) {
277277
c1 = 0x00000000FFFFFFFF;
278278
c2 = 0x0000F8FFFFFFFFFF;
279279
c3 = 0xC0FFFFFFFFFFFFFF;
280-
break;
281-
case NID_magma_mgm:
282-
switch (mode) {
283-
case TLSTREE_MODE_S: // TLS_GOSTR341112_256_WITH_MAGMA_MGM_S
280+
} else if (cipher_nid == magma_mgm_cipher.nid) {
281+
if (mode == TLSTREE_MODE_S) { // TLS_GOSTR341112_256_WITH_MAGMA_MGM_S
284282
c1 = 0x000000fcffffffff;
285283
c2 = 0x00e0ffffffffffff;
286284
c3 = 0xffffffffffffffff;
287-
break;
288-
case TLSTREE_MODE_L: // TLS_GOSTR341112_256_WITH_MAGMA_MGM_L
285+
} else if (mode == TLSTREE_MODE_L) { // TLS_GOSTR341112_256_WITH_MAGMA_MGM_L
289286
c1 = 0x000000000000e0ff;
290287
c2 = 0x000000c0ffffffff;
291288
c3 = 0x80ffffffffffffff;
292-
break;
293-
default:
289+
} else {
294290
return 0;
295291
}
296-
break;
297-
case NID_kuznyechik_mgm:
298-
switch (mode) {
299-
case TLSTREE_MODE_S: // TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_S
292+
} else if (cipher_nid == grasshopper_mgm_cipher.nid) {
293+
if (mode == TLSTREE_MODE_S) { // TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_S
300294
c1 = 0x000000e0ffffffff;
301295
c2 = 0x0000ffffffffffff;
302296
c3 = 0xf8ffffffffffffff;
303-
break;
304-
case TLSTREE_MODE_L: // TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_L
297+
} else if (mode == TLSTREE_MODE_L) { // TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_L
305298
c1 = 0x00000000000000f8;
306299
c2 = 0x00000000f0ffffff;
307300
c3 = 0x00e0ffffffffffff;
308-
break;
309-
default:
301+
} else {
310302
return 0;
311303
}
312-
break;
313-
default:
314-
return 0;
304+
} else {
305+
return 0; /* неизвестный cipher_nid */
315306
}
316307
#ifndef L_ENDIAN
317308
BUF_reverse((unsigned char *)&seq, tlsseq, 8);

gost_lcl.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,6 @@ EVP_CTRL_SET_TLSTREE_PARAMS definition in OpenSSL is expected."
3737
# define EVP_CTRL_SET_TLSTREE_PARAMS 0xFF
3838
# endif
3939

40-
# ifndef NID_magma_mgm
41-
# if defined(_MSC_VER)
42-
# pragma message("Gost-engine is built against not fully supported version of OpenSSL. \
43-
NID_magma_mgm definition in OpenSSL is expected. No magma mgm functionality is \
44-
guaranteed.")
45-
# else
46-
# warning "Gost-engine is built against not fully supported version of OpenSSL. \
47-
NID_magma_mgm definition in OpenSSL is expected. No magma mgm functionality is \
48-
guaranteed."
49-
# endif
50-
# define NID_magma_mgm ((int)(INT_MAX - 1))
51-
# endif
52-
53-
# ifndef NID_kuznyechik_mgm
54-
# if defined(_MSC_VER)
55-
# pragma message("Gost-engine is built against not fully supported version of OpenSSL. \
56-
NID_kuznyechik_mgm definition in OpenSSL is expected. No magma mgm functionality is \
57-
guaranteed.")
58-
# else
59-
# warning "Gost-engine is built against not fully supported version of OpenSSL. \
60-
NID_kuznyechik_mgm definition in OpenSSL is expected. No kuznyechik mgm functionality is \
61-
guaranteed."
62-
# endif
63-
# define NID_kuznyechik_mgm ((int)(INT_MAX - 2))
64-
# endif
65-
6640
/* Control commands */
6741
# define GOST_PARAM_CRYPT_PARAMS 0
6842
# define GOST_PARAM_PBE_PARAMS 1

0 commit comments

Comments
 (0)