Skip to content

Commit efb30bc

Browse files
metsmakristelmerilain
authored andcommitted
Validate signatures with RSA PSS key type
IB-8519 Signed-off-by: Raul Metsma <[email protected]>
1 parent 3cff576 commit efb30bc

File tree

5 files changed

+217
-24
lines changed

5 files changed

+217
-24
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ jobs:
132132
container: ubuntu:${{ matrix.container }}
133133
strategy:
134134
matrix:
135-
container: ['22.04', '24.04', '24.10', '25.04']
135+
container: ['22.04', '24.04', '25.04']
136136
arch: ['amd64', 'arm64']
137137
env:
138138
DEBIAN_FRONTEND: noninteractive
@@ -164,15 +164,12 @@ jobs:
164164
runs-on: ${{ matrix.image }}
165165
strategy:
166166
matrix:
167-
toolset: [143, 142]
167+
toolset: [143]
168168
platform: [x86, x64, arm64]
169169
include:
170170
- toolset: 143
171171
image: windows-2022
172172
vcvars: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvarsall.bat"
173-
- toolset: 142
174-
image: windows-2019
175-
vcvars: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\VC\\Auxiliary\\Build\\vcvarsall.bat"
176173
- platform: x86
177174
setenv: amd64_x86
178175
- platform: x64

prepare_osx_build_environment.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function xmlsec {
5757
tar xf ${XMLSEC_DIR}.tar.gz
5858
cd ${XMLSEC_DIR}
5959
patch -Np1 -i ../vcpkg-ports/xmlsec/xmlsec1-1.3.5.legacy.patch
60+
patch -Np1 -i ../vcpkg-ports/xmlsec/xmlsec1-1.3.7.rsapss.patch
6061
case "${ARGS}" in
6162
*iphone*) CONFIGURE="--host=aarch64-apple-darwin --enable-static --disable-shared --without-libxslt" ;;
6263
*) CONFIGURE="--disable-static --enable-shared" ;;

vcpkg-ports/xmlsec/CMakeLists.txt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ FILE(GLOB SOURCESXMLSECOPENSSL
1818
# Generate xmlexports with fixed definition of XMLSEC_STATIC
1919
file(READ include/xmlsec/exports.h EXPORTS_H)
2020
if(BUILD_SHARED_LIBS)
21-
string(REPLACE "!defined(XMLSEC_STATIC)" "1" EXPORTS_H "${EXPORTS_H}")
21+
string(REPLACE "!defined(XMLSEC_STATIC)" "1" EXPORTS_H "${EXPORTS_H}")
2222
else()
23-
string(REPLACE "!defined(XMLSEC_STATIC)" "0" EXPORTS_H "${EXPORTS_H}")
23+
string(REPLACE "!defined(XMLSEC_STATIC)" "0" EXPORTS_H "${EXPORTS_H}")
2424
endif()
2525
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/exports.h "${EXPORTS_H}")
2626

2727
message(STATUS "Reading version info from configure.ac")
2828

2929
file(STRINGS "configure.ac"
30-
_xmlsec_version_defines REGEX "XMLSEC_VERSION_(MAJOR|MINOR|SUBMINOR)=([0-9]+)$")
30+
_xmlsec_version_defines REGEX "XMLSEC_VERSION_(MAJOR|MINOR|SUBMINOR)=([0-9]+)$")
3131

3232
foreach(ver ${_xmlsec_version_defines})
33-
if(ver MATCHES "XMLSEC_VERSION_(MAJOR|MINOR|SUBMINOR)=([0-9]+)$")
34-
set(XMLSEC_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
35-
endif()
33+
if(ver MATCHES "XMLSEC_VERSION_(MAJOR|MINOR|SUBMINOR)=([0-9]+)$")
34+
set(XMLSEC_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
35+
endif()
3636
endforeach()
3737

3838
set(XMLSEC_VERSION ${XMLSEC_VERSION_MAJOR}.${XMLSEC_VERSION_MINOR}.${XMLSEC_VERSION_SUBMINOR})
@@ -61,9 +61,9 @@ add_library(xmlsec1 ${SOURCESXMLSEC})
6161
add_library(xmlsec1-openssl ${SOURCESXMLSECOPENSSL})
6262

6363
target_include_directories(xmlsec1 PUBLIC
64-
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
65-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
66-
$<INSTALL_INTERFACE:include>
64+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
65+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
66+
$<INSTALL_INTERFACE:include>
6767
)
6868
target_link_libraries(xmlsec1 PUBLIC LibXml2::LibXml2)
6969
target_link_libraries(xmlsec1-openssl PUBLIC xmlsec1 OpenSSL::Crypto)
@@ -89,26 +89,26 @@ set_target_properties(xmlsec1 xmlsec1-openssl PROPERTIES VERSION ${XMLSEC_VERSIO
8989

9090
set(XMLSEC_CORE_CFLAGS XMLSEC_NO_XSLT XMLSEC_CRYPTO_OPENSSL XMLSEC_NO_FTP XMLSEC_NO_HTTP)
9191
if(NOT BUILD_SHARED_LIBS)
92-
list(APPEND XMLSEC_CORE_CFLAGS XMLSEC_STATIC XMLSEC_NO_CRYPTO_DYNAMIC_LOADING)
92+
list(APPEND XMLSEC_CORE_CFLAGS XMLSEC_STATIC XMLSEC_NO_CRYPTO_DYNAMIC_LOADING)
9393
endif()
9494
set(XMLSEC_OPENSSL_CFLAGS XMLSEC_NO_MD5 XMLSEC_NO_RIPEMD160 XMLSEC_NO_GOST XMLSEC_NO_GOST2012)
9595

9696
target_compile_definitions(xmlsec1
97-
PRIVATE $<$<PLATFORM_ID:Windows>:XMLSEC_DL_WIN32>
98-
PUBLIC ${XMLSEC_CORE_CFLAGS}
97+
PRIVATE $<IF:$<PLATFORM_ID:Windows>,XMLSEC_DL_WIN32,XMLSEC_DL_LIBLTDL>
98+
PUBLIC ${XMLSEC_CORE_CFLAGS}
9999
)
100100
target_compile_definitions(xmlsec1-openssl PUBLIC ${XMLSEC_OPENSSL_CFLAGS})
101101

102102
install(TARGETS xmlsec1 xmlsec1-openssl
103-
EXPORT unofficial-xmlsec-targets
104-
RUNTIME DESTINATION bin
105-
LIBRARY DESTINATION lib
106-
ARCHIVE DESTINATION lib
103+
EXPORT unofficial-xmlsec-targets
104+
RUNTIME DESTINATION bin
105+
LIBRARY DESTINATION lib
106+
ARCHIVE DESTINATION lib
107107
)
108108

109109
install(EXPORT unofficial-xmlsec-targets
110-
NAMESPACE unofficial::xmlsec::
111-
DESTINATION share/unofficial-xmlsec
110+
NAMESPACE unofficial::xmlsec::
111+
DESTINATION share/unofficial-xmlsec
112112
)
113113

114114
if(INSTALL_HEADERS_TOOLS)
@@ -157,7 +157,7 @@ set(VERSION ${XMLSEC_VERSION})
157157
set(LIBXML_MIN_VERSION ${LIBXML2_VERSION_STRING})
158158
list(JOIN XMLSEC_CORE_CFLAGS " -D" XMLSEC_CORE_CFLAGS)
159159
set(XMLSEC_CORE_CFLAGS "-D${XMLSEC_CORE_CFLAGS} -I\${includedir}/xmlsec1")
160-
set(XMLSEC_CORE_LIBS "-lxmlsec1 -lltdl")
160+
set(XMLSEC_CORE_LIBS "-lxmlsec1")
161161
list(JOIN XMLSEC_OPENSSL_CFLAGS " -D" XMLSEC_OPENSSL_CFLAGS)
162162
set(XMLSEC_OPENSSL_CFLAGS "${XMLSEC_CORE_CFLAGS} -D${XMLSEC_OPENSSL_CFLAGS}")
163163
set(XMLSEC_OPENSSL_LIBS "-L\${libdir} -lxmlsec1-openssl ${XMLSEC_CORE_LIBS} -lcrypto")

vcpkg-ports/xmlsec/portfile.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ vcpkg_from_github(
1010
PATCHES
1111
pkgconfig_fixes.patch
1212
xmlsec1-1.3.5.legacy.patch
13+
xmlsec1-1.3.7.rsapss.patch
1314
)
1415

1516
file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}")
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
From a7e8464f2a2826820b94cc641ac0aae345641fc6 Mon Sep 17 00:00:00 2001
2+
From: Raul Metsma <[email protected]>
3+
Date: Thu, 26 Jun 2025 17:47:54 +0300
4+
Subject: [PATCH] (xmlsec-openssl) add supoprt for RSA PSS key type (#933)
5+
6+
---
7+
src/openssl/evp.c | 35 ++++++++++++++++++++++++++++++-----
8+
src/openssl/kt_rsa.c | 11 ++++++-----
9+
src/openssl/private.h | 11 ++++++++++-
10+
src/openssl/x509vfy.c | 1 -
11+
4 files changed, 46 insertions(+), 12 deletions(-)
12+
13+
diff --git a/src/openssl/evp.c b/src/openssl/evp.c
14+
index 97b7b6c2..a3e00006 100644
15+
--- a/src/openssl/evp.c
16+
+++ b/src/openssl/evp.c
17+
@@ -32,7 +32,6 @@
18+
#include <xmlsec/openssl/app.h>
19+
#include <xmlsec/openssl/crypto.h>
20+
#include <xmlsec/openssl/evp.h>
21+
-#include "openssl_compat.h"
22+
23+
#ifdef XMLSEC_OPENSSL_API_300
24+
#include <openssl/core_names.h>
25+
@@ -41,6 +40,8 @@
26+
27+
#include "../cast_helpers.h"
28+
#include "../keysdata_helpers.h"
29+
+#include "openssl_compat.h"
30+
+#include "private.h"
31+
32+
static int
33+
xmlSecOpenSSLGetBNValue(const xmlSecBufferPtr buf, BIGNUM **bigNum) {
34+
@@ -325,6 +326,8 @@ xmlSecOpenSSLEvpKeyAdopt(EVP_PKEY *pKey) {
35+
switch(EVP_PKEY_base_id(pKey)) {
36+
#ifndef XMLSEC_NO_RSA
37+
case EVP_PKEY_RSA:
38+
+ case EVP_PKEY_RSA2:
39+
+ case EVP_PKEY_RSA_PSS:
40+
data = xmlSecKeyDataCreate(xmlSecOpenSSLKeyDataRsaId);
41+
if(data == NULL) {
42+
xmlSecInternalError("xmlSecKeyDataCreate(xmlSecOpenSSLKeyDataRsaId)", NULL);
43+
@@ -3258,6 +3261,26 @@ done:
44+
45+
#ifndef XMLSEC_NO_RSA
46+
47+
+/**
48+
+ * xmlSecOpenSSLKeyValueRsaCheckKeyType:
49+
+ * @pKey: the EVP key to check
50+
+ *
51+
+ * Returns 0 if @pKey is a valid RSA key type, 1 if it is not, or a negative value if an error occurs.
52+
+ */
53+
+int
54+
+xmlSecOpenSSLKeyValueRsaCheckKeyType(EVP_PKEY* pKey) {
55+
+ xmlSecAssert2(pKey != NULL, -1);
56+
+
57+
+ switch(EVP_PKEY_base_id(pKey)) {
58+
+ case EVP_PKEY_RSA:
59+
+ case EVP_PKEY_RSA2:
60+
+ case EVP_PKEY_RSA_PSS:
61+
+ return(0);
62+
+ default:
63+
+ return(1);
64+
+ }
65+
+}
66+
+
67+
/*
68+
* @xmlSecOpenSSLKeyValueRsa: holds the parts of OpenSSL RSA key
69+
*/
70+
@@ -3430,7 +3453,7 @@ int
71+
xmlSecOpenSSLKeyDataRsaAdoptEvp(xmlSecKeyDataPtr data, EVP_PKEY* pKey) {
72+
xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecOpenSSLKeyDataRsaId), -1);
73+
xmlSecAssert2(pKey != NULL, -1);
74+
- xmlSecAssert2(EVP_PKEY_base_id(pKey) == EVP_PKEY_RSA, -1);
75+
+ xmlSecAssert2(xmlSecOpenSSLKeyValueRsaCheckKeyType(pKey) == 0, -1);
76+
77+
return(xmlSecOpenSSLEvpKeyDataAdoptEvp(data, pKey));
78+
}
79+
@@ -3535,9 +3558,11 @@ xmlSecOpenSSLKeyDataRsaGetRsa(xmlSecKeyDataPtr data) {
80+
xmlSecAssert2(xmlSecKeyDataCheckId(data, xmlSecOpenSSLKeyDataRsaId), NULL);
81+
82+
pKey = xmlSecOpenSSLKeyDataRsaGetEvp(data);
83+
- xmlSecAssert2((pKey == NULL) || (EVP_PKEY_base_id(pKey) == EVP_PKEY_RSA), NULL);
84+
-
85+
- return((pKey != NULL) ? EVP_PKEY_get0_RSA(pKey) : NULL);
86+
+ if (pKey == NULL) {
87+
+ return(NULL);
88+
+ }
89+
+ xmlSecAssert2(xmlSecOpenSSLKeyValueRsaCheckKeyType(pKey) == 0, NULL);
90+
+ return(EVP_PKEY_get0_RSA(pKey));
91+
}
92+
93+
static int
94+
diff --git a/src/openssl/kt_rsa.c b/src/openssl/kt_rsa.c
95+
index a1153499..d25c001e 100644
96+
--- a/src/openssl/kt_rsa.c
97+
+++ b/src/openssl/kt_rsa.c
98+
@@ -34,7 +34,6 @@
99+
100+
#include <xmlsec/openssl/crypto.h>
101+
#include <xmlsec/openssl/evp.h>
102+
-#include "openssl_compat.h"
103+
104+
#ifdef XMLSEC_OPENSSL_API_300
105+
#include <openssl/core_names.h>
106+
@@ -43,6 +42,8 @@
107+
108+
#include "../cast_helpers.h"
109+
#include "../transform_helpers.h"
110+
+#include "openssl_compat.h"
111+
+#include "private.h"
112+
113+
#ifndef XMLSEC_NO_RSA_PKCS15
114+
115+
@@ -162,7 +163,7 @@ xmlSecOpenSSLRsaPkcs1ProcessImpl(xmlSecOpenSSLRsaPkcs1CtxPtr ctx, const xmlSecBy
116+
117+
xmlSecAssert2(ctx != NULL, -1);
118+
xmlSecAssert2(ctx->pKey != NULL, -1);
119+
- xmlSecAssert2(EVP_PKEY_base_id(ctx->pKey) == EVP_PKEY_RSA, -1);
120+
+ xmlSecAssert2(xmlSecOpenSSLKeyValueRsaCheckKeyType(ctx->pKey) == 0, -1);
121+
xmlSecAssert2(inBuf != NULL, -1);
122+
xmlSecAssert2(inSize > 0, -1);
123+
xmlSecAssert2(outBuf != NULL, -1);
124+
@@ -364,7 +365,7 @@ xmlSecOpenSSLRsaPkcs1SetKey(xmlSecTransformPtr transform, xmlSecKeyPtr key) {
125+
xmlSecTransformGetName(transform));
126+
return(-1);
127+
}
128+
- xmlSecAssert2(EVP_PKEY_base_id(pKey) == EVP_PKEY_RSA, -1);
129+
+ xmlSecAssert2(xmlSecOpenSSLKeyValueRsaCheckKeyType(pKey) == 0, -1);
130+
131+
if (transform->operation == xmlSecTransformOperationEncrypt) {
132+
encrypt = 1;
133+
@@ -693,7 +694,7 @@ xmlSecOpenSSLRsaOaepProcessImpl(xmlSecOpenSSLRsaOaepCtxPtr ctx, const xmlSecByte
134+
135+
xmlSecAssert2(ctx != NULL, -1);
136+
xmlSecAssert2(ctx->pKey != NULL, -1);
137+
- xmlSecAssert2(EVP_PKEY_base_id(ctx->pKey) == EVP_PKEY_RSA, -1);
138+
+ xmlSecAssert2(xmlSecOpenSSLKeyValueRsaCheckKeyType(pKey) == 0, -1);
139+
xmlSecAssert2(inBuf != NULL, -1);
140+
xmlSecAssert2(inSize > 0, -1);
141+
xmlSecAssert2(outBuf != NULL, -1);
142+
@@ -1223,7 +1224,7 @@ xmlSecOpenSSLRsaOaepSetKey(xmlSecTransformPtr transform, xmlSecKeyPtr key) {
143+
xmlSecTransformGetName(transform));
144+
return(-1);
145+
}
146+
- xmlSecAssert2(EVP_PKEY_base_id(pKey) == EVP_PKEY_RSA, -1);
147+
+ xmlSecAssert2(xmlSecOpenSSLKeyValueRsaCheckKeyType(pKey) == 0, -1);
148+
149+
if (transform->operation == xmlSecTransformOperationEncrypt) {
150+
encrypt = 1;
151+
diff --git a/src/openssl/private.h b/src/openssl/private.h
152+
index 6940f5bd..cc58a0b2 100644
153+
--- a/src/openssl/private.h
154+
+++ b/src/openssl/private.h
155+
@@ -28,6 +28,16 @@ extern "C" {
156+
#endif /* __cplusplus */
157+
158+
159+
+/******************************************************************************
160+
+ *
161+
+ * RSA Util functions
162+
+ *
163+
+ ******************************************************************************/
164+
+#ifndef XMLSEC_NO_RSA
165+
+
166+
+int xmlSecOpenSSLKeyValueRsaCheckKeyType (EVP_PKEY* pKey);
167+
+
168+
+#endif /* XMLSEC_NO_RSA */
169+
170+
/******************************************************************************
171+
*
172+
@@ -85,7 +95,6 @@ int xmlSecOpenSSLX509Asn1TimeToTime (const ASN1_TIME
173+
STACK_OF(X509)* xmlSecOpenSSLKeyDataX509GetCerts (xmlSecKeyDataPtr data);
174+
STACK_OF(X509_CRL)* xmlSecOpenSSLKeyDataX509GetCrls (xmlSecKeyDataPtr data);
175+
176+
-
177+
#endif /* XMLSEC_NO_X509 */
178+
179+
#ifdef __cplusplus
180+
diff --git a/src/openssl/x509vfy.c b/src/openssl/x509vfy.c
181+
index 322f6661..fdede0fc 100644
182+
--- a/src/openssl/x509vfy.c
183+
+++ b/src/openssl/x509vfy.c
184+
@@ -34,7 +34,6 @@
185+
#include <xmlsec/openssl/crypto.h>
186+
#include <xmlsec/openssl/evp.h>
187+
#include <xmlsec/openssl/x509.h>
188+
-#include "openssl_compat.h"
189+
190+
#include <openssl/evp.h>
191+
#include <openssl/x509.h>
192+
--
193+
2.46.0
194+

0 commit comments

Comments
 (0)