Skip to content

Commit 38a8876

Browse files
committed
fix: moved parameters in configuration
1 parent 508f1e8 commit 38a8876

File tree

4 files changed

+13
-61
lines changed

4 files changed

+13
-61
lines changed

pyeudiw/tests/satosa/test_backend.py

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
NOW,
2929
leaf_cred_jwk,
3030
leaf_wallet_jwk,
31-
ta_ec,
32-
ta_ec_signed,
31+
3332
ta_jwk,
3433
trust_chain_wallet,
3534
trust_chain_issuer
@@ -42,6 +41,8 @@
4241
INTERNAL_ATTRIBUTES,
4342
PRIVATE_JWK,
4443
WALLET_INSTANCE_ATTESTATION,
44+
DEFAULT_X509_CHAIN,
45+
DEFAULT_X509_LEAF_JWK
4546
)
4647
from pyeudiw.trust.handler.interface import TrustHandlerInterface
4748
from pyeudiw.trust.model.trust_source import TrustSourceData, TrustEvaluationType
@@ -55,8 +56,6 @@
5556
from pyeudiw.tests.x509.test_x509 import gen_chain
5657
from pyeudiw.x509.verify import der_list_to_pem_list
5758
from pyeudiw.jwk.parse import parse_pem
58-
from cryptojwt.jwk.jwk import key_from_jwk_dict
59-
from cryptography.hazmat.primitives.asymmetric import rsa
6059

6160
PKEY = {
6261
'KTY': 'EC2',
@@ -109,54 +108,14 @@ def issue_sd_jwt(specification: dict, settings: dict, issuer_key: JWK, holder_ke
109108
def _mock_auth_callback_function(context: Context, internal_data: InternalData):
110109
return JsonResponse({"response": "Authentication successful"}, status="200")
111110

112-
def base64url_to_int(val):
113-
import base64
114-
import binascii
115-
return int.from_bytes(base64.urlsafe_b64decode(val + '=='), 'big')
116111
class TestOpenID4VPBackend:
117112
@pytest.fixture(autouse=True)
118113
def create_backend(self):
119114
db_engine_inst = DBEngine(CONFIG["storage"])
120115

121-
jwk = {
122-
"kty": "RSA",
123-
"use": "sig",
124-
"alg": "RS256",
125-
"kid": "m00NPAelNBnG_wK2R5EpI_k-GWCHEUySamQYubgFjCg",
126-
"d": "nMsnqz0lPHN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Q32rQuqNUnv4lRb4GYcZI41SCsZnQFw4dBsTRXaXknlFr0PfkhvXyfVlYwU6i5U8DgfO0-xzTwErGUIrs4vZFyjRFauDA3JlvLWn0rpXFp-sELM87PhLfpjDiBFz_EFtM7kJw7GhTMCFnsgVpAEpQ8sesXLPiTPNts2_D5SW8",
132-
"dq": "jWlucLrtFGOjDRuyLjT9l__uWZ4vk6kZRHsWMwWGRBhd0ezx-CT0em1hPMcNE1vvYqKAfG2xU4pjaB_JB9nnG73TvMBI7xwwwWsGihXQ5bqjc_uWPAxCKpKM_qFYuI2lMkaxctqL4gkE1-LRVpVv9uGa4YZh3ct_BSvTr9ZNpA8",
133-
"qi": "kn9Etj4a2erCUmoZUQalPjHxCRYm5Q3wAkFIRGSQADA51mkwQHyTYqXbHcmXn2ZgXBVI6XDWJB51Me-NCPfITTlusqxvATF7Q-QJtdK_FbgNtcVRNc1FMq_M7VBHA1i9wJR7T4t57aywfXPmlsA5TToTDRe-ybdw0C3ys4KQATs"
134-
}
135-
136-
# Extract components from JWK
137-
_n = base64url_to_int(jwk['n'])
138-
_e = base64url_to_int(jwk['e'])
139-
_d = base64url_to_int(jwk['d'])
140-
_p = base64url_to_int(jwk['p'])
141-
_q = base64url_to_int(jwk['q'])
142-
_dp = base64url_to_int(jwk['dp'])
143-
_dq = base64url_to_int(jwk['dq'])
144-
_qi = base64url_to_int(jwk['qi'])
145-
146-
# Create RSA private key
147-
private_key = rsa.RSAPrivateNumbers(
148-
p=_p,
149-
q=_q,
150-
d=_d,
151-
dmp1=_dp,
152-
dmq1=_dq,
153-
iqmp=_qi,
154-
public_numbers=rsa.RSAPublicNumbers(e=_e, n=_n)
155-
).private_key()
156-
157-
self.chain = der_list_to_pem_list(gen_chain(leaf_private_key=private_key))
116+
self.chain = der_list_to_pem_list(DEFAULT_X509_CHAIN)
158117
issuer_pem = self.chain[-1]
159-
self.x509_leaf_private_key = jwk
118+
self.x509_leaf_private_key = DEFAULT_X509_LEAF_JWK
160119

161120
db_engine_inst.add_trust_anchor(
162121
entity_id="ca.example.com",

pyeudiw/trust/dynamic.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ def get_public_keys(
188188
if handler.get_handled_trust_material_name() == key:
189189
status, trust_source = handler.validate_trust_material(
190190
trust_material,
191-
trust_source,
192-
self.db_engine
191+
trust_source
193192
)
194193

195194
if status:

pyeudiw/trust/handler/federation.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,12 @@ def validate_trust_material(
172172
self,
173173
trust_chain: list[str],
174174
trust_source: TrustSourceData,
175-
db_engine: DBEngine
176175
) -> dict[bool, TrustSourceData]:
177176
"""
178177
Validate the trust chain of the trust source.
179178
180179
:param trust_source: The trust source
181180
:type trust_source: TrustSourceData
182-
:param db_engine: The database engine
183-
:type db_engine: DBEngine
184181
185182
:returns: If the trust chain is valid
186183
:rtype: bool

pyeudiw/trust/handler/x509.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ def __init__(
2626
relying_party_certificate_chains_by_ca: dict[str, Union[list[bytes], list[str]]],
2727
private_keys: list[dict[str, str]],
2828
client_id_scheme: str = "x509_san_uri",
29+
certificate_authorities: list[str] = [],
2930
**kwargs
3031
):
3132
self.client_id = client_id
3233
self.client_id_scheme = client_id_scheme
34+
self.certificate_authorities = certificate_authorities
3335

3436
if not relying_party_certificate_chains_by_ca:
3537
raise InvalidTrustHandlerConfiguration("No x509 certificate chains provided in the configuration")
@@ -92,7 +94,6 @@ def validate_trust_material(
9294
self,
9395
x5c: list[str],
9496
trust_source: TrustSourceData,
95-
db_engine: DBEngine
9697
) -> dict[bool, TrustSourceData]:
9798
chain = pem_list_to_der_list(x5c)
9899

@@ -102,19 +103,15 @@ def validate_trust_material(
102103

103104
issuer = get_trust_anchor_from_x5c(chain)
104105

105-
try:
106-
trust_anchor = db_engine.get_trust_anchor(issuer)
107-
except Exception:
108-
logger.error(f"Invalid x509 certificate chain. Trust anchor not found")
106+
if not issuer:
107+
logger.error(f"Invalid x509 certificate chain. Issuer not found")
109108
return False, trust_source
110109

111-
anchor_x509 = trust_anchor.get("x509")
112-
113-
if not anchor_x509:
114-
logger.error(f"Invalid x509 certificate chain. Trust anchor x509 not found")
110+
if not issuer in self.certificate_authorities:
111+
logger.error(f"Invalid x509 certificate chain. Issuer not found in the list of trusted CAs")
115112
return False, trust_source
116113

117-
issuer_pem = anchor_x509["pem"]
114+
issuer_pem = self.certificate_authorities[issuer]
118115

119116
try:
120117
issuer_jwk = parse_pem(issuer_pem)

0 commit comments

Comments
 (0)