Skip to content

Commit 14b3370

Browse files
authored
Merge pull request #164 from Venafi/support-tpp-25.1
Support TPP v25.1 and higher
2 parents 2ebfbe1 + ba2cd7a commit 14b3370

File tree

7 files changed

+93
-18
lines changed

7 files changed

+93
-18
lines changed

vcert/common.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2019 Venafi, Inc.
2+
# Copyright 2019-2025 Venafi, Inc.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -632,6 +632,12 @@ def auth(self):
632632
"""
633633
raise NotImplementedError
634634

635+
def get_version(self):
636+
"""
637+
Gets version string
638+
"""
639+
raise NotImplementedError
640+
635641
def request_cert(self, request, zone):
636642
"""
637643
Making request to certificate. It will generate CSR from data if CSR not specified, generate key if required and send to server for signing. Set request.id for retrieving certificate.
@@ -765,5 +771,5 @@ def __new__(cls, value, description):
765771
return obj
766772

767773
FAKE = 100, "Connector for testing purposes"
768-
TPP = 200, "Trust Protection Platfom"
774+
TPP = 200, "Trust Protection Platform"
769775
VAAS = 400, "Venafi as a Service"

vcert/connection_cloud.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2019 Venafi, Inc.
2+
# Copyright 2019-2025 Venafi, Inc.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -340,6 +340,9 @@ def auth(self):
340340
if status == HTTPStatus.OK:
341341
return data
342342

343+
def get_version(self):
344+
raise NotImplementedError
345+
343346
def _get_app_details_by_name(self, app_name):
344347
"""
345348
:param str app_name:

vcert/connection_fake.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2022 Venafi, Inc.
2+
# Copyright 2022-2025 Venafi, Inc.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -112,6 +112,9 @@ def __str__(self):
112112
def auth(self):
113113
return fake_user()
114114

115+
def get_version(self):
116+
return "25.1.0.3419"
117+
115118
def register(self, email):
116119
return fake_user(email)
117120

vcert/connection_tpp_abstract.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2020 Venafi, Inc.
2+
# Copyright 2020-2025 Venafi, Inc.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -52,6 +52,7 @@ class URLS:
5252
REVOKE_TOKEN = API_TOKEN_URL + "revoke/token" # type: str
5353

5454
AUTHORIZE = API_BASE_URL + "authorize/"
55+
VERSION = API_BASE_URL + "systemstatus/version"
5556
CERTIFICATE_REQUESTS = API_BASE_URL + "certificates/request"
5657
CERTIFICATE_RETRIEVE = API_BASE_URL + "certificates/retrieve"
5758
FIND_POLICY = API_BASE_URL + "config/findpolicy"
@@ -99,6 +100,13 @@ def __init__(self):
99100
def auth(self):
100101
raise NotImplementedError
101102

103+
def get_version(self):
104+
args = { self.ARG_URL: URLS.VERSION }
105+
status, data = self.get(args=args)
106+
if status != HTTPStatus.OK:
107+
raise ServerUnexptedBehavior(f"Server returns {status} status on get version")
108+
return data['Version']
109+
102110
def request_cert(self, request, zone):
103111
request_data = {
104112
'PolicyDN': self._normalize_zone(zone),
@@ -591,14 +599,35 @@ def set_policy(self, zone, policy_spec):
591599
self._set_policy_attr(name, SPA.TPP_STATE, [tpp_policy.state.value], tpp_policy.state.locked)
592600
if tpp_policy.country:
593601
self._set_policy_attr(name, SPA.TPP_COUNTRY, [tpp_policy.country.value], tpp_policy.state.locked)
594-
if tpp_policy.key_algo:
595-
self._set_policy_attr(name, SPA.TPP_KEY_ALGORITHM, [tpp_policy.key_algo.value], tpp_policy.key_algo.locked)
596-
if tpp_policy.key_bit_str:
597-
self._set_policy_attr(name, SPA.TPP_KEY_BIT_STR, [tpp_policy.key_bit_str.value],
598-
tpp_policy.key_bit_str.locked)
599-
if tpp_policy.elliptic_curve:
600-
self._set_policy_attr(name, SPA.TPP_ELLIPTIC_CURVE, [tpp_policy.elliptic_curve.value],
601-
tpp_policy.elliptic_curve.locked)
602+
603+
# Check the TPP version is 25.x or greater
604+
tpp_version_number = -1
605+
tpp_version = self.get_version()
606+
if tpp_version and "." in tpp_version:
607+
tpp_version_number = int(tpp_version.split(".")[0])
608+
if tpp_version_number >= 25:
609+
# Create "PKIX Parameter Set" attributes
610+
if tpp_policy.pkix_parameter_set:
611+
self._set_policy_attr(name, SPA.TPP_PKIX_PARAMETER_SET_POLICY, [tpp_policy.pkix_parameter_set.value], tpp_policy.pkix_parameter_set.locked)
612+
else:
613+
# For backward compatibility, if the "PKIX Parameter Set" is not set, we need to set it using the "Key Algorithm",
614+
# "Key Bit Strength" and "Elliptic Curve" attribute values
615+
pkixOid = tpp_policy.pkix_parameter_set_from_old_key_attributes()
616+
if pkixOid:
617+
self._set_policy_attr(name, SPA.TPP_PKIX_PARAMETER_SET_POLICY, [pkixOid], tpp_policy.key_algo.locked)
618+
self._set_policy_attr(name, SPA.TPP_PKIX_PARAMETER_SET_POLICY_DEFAULT, [pkixOid], tpp_policy.key_algo.locked)
619+
if tpp_policy.pkix_parameter_set_default:
620+
self._set_policy_attr(name, SPA.TPP_PKIX_PARAMETER_SET_POLICY_DEFAULT, [tpp_policy.pkix_parameter_set_default.value], tpp_policy.pkix_parameter_set_default.locked)
621+
else:
622+
if tpp_policy.key_algo:
623+
self._set_policy_attr(name, SPA.TPP_KEY_ALGORITHM, [tpp_policy.key_algo.value], tpp_policy.key_algo.locked)
624+
if tpp_policy.key_bit_str:
625+
self._set_policy_attr(name, SPA.TPP_KEY_BIT_STR, [tpp_policy.key_bit_str.value],
626+
tpp_policy.key_bit_str.locked)
627+
if tpp_policy.elliptic_curve:
628+
self._set_policy_attr(name, SPA.TPP_ELLIPTIC_CURVE, [tpp_policy.elliptic_curve.value],
629+
tpp_policy.elliptic_curve.locked)
630+
602631
if tpp_policy.management_type:
603632
self._set_policy_attr(name, SPA.TPP_MANAGEMENT_TYPE, [tpp_policy.management_type.value],
604633
tpp_policy.management_type.locked)

vcert/policy/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2021 Venafi, Inc.
2+
# Copyright 2021-2025 Venafi, Inc.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -62,6 +62,8 @@ def __init__(self):
6262
TPP_PROHIBIT_WILDCARD = 'Prohibit Wildcard'
6363
TPP_DOMAIN_SUFFIX_WHITELIST = 'Domain Suffix Whitelist'
6464
TPP_ORG_UNIT = 'Organizational Unit'
65+
TPP_PKIX_PARAMETER_SET_POLICY = 'PKIX Parameter Set Policy'
66+
TPP_PKIX_PARAMETER_SET_POLICY_DEFAULT = 'PKIX Parameter Set Policy Default'
6567
TPP_KEY_ALGORITHM = 'Key Algorithm'
6668
TPP_KEY_BIT_STR = 'Key Bit Strength'
6769
TPP_ELLIPTIC_CURVE = 'Elliptic Curve'

vcert/policy/pm_tpp.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2021 Venafi, Inc.
2+
# Copyright 2021-2025 Venafi, Inc.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -56,6 +56,8 @@ def __init__(self):
5656
self.city = None
5757
self.state = None
5858
self.country = None
59+
self.pkix_parameter_set = None
60+
self.pkix_parameter_set_default = None
5961
self.key_algo = None
6062
self.key_bit_str = None
6163
self.elliptic_curve = None
@@ -72,6 +74,31 @@ def __init__(self):
7274
self.allow_private_key_reuse = None
7375
self.want_renewal = None
7476

77+
def pkix_parameter_set_from_old_key_attributes(self):
78+
"""
79+
For backward compatibility, if the "PKIX Parameter Set" is not set, we need to set it using the "Key Algorithm",
80+
"Key Bit Strength" and "Elliptic Curve" attribute values
81+
"""
82+
_key_algorithms_to_pkix = {
83+
"RSA": {
84+
"1024": "1.3.6.1.4.1.28783.10.1.1.1024",
85+
"2048": "1.3.6.1.4.1.28783.10.1.1.2048",
86+
"3072": "1.3.6.1.4.1.28783.10.1.1.3072",
87+
"4096": "1.3.6.1.4.1.28783.10.1.1.4096",
88+
},
89+
"ECC": {
90+
"P256": "1.3.6.1.4.1.28783.10.2.1.256",
91+
"P384": "1.3.6.1.4.1.28783.10.2.1.384",
92+
"P521": "1.3.6.1.4.1.28783.10.2.1.521",
93+
},
94+
}
95+
if self.key_algo and self.key_algo.value and self.key_algo.value in _key_algorithms_to_pkix:
96+
if self.key_algo.value.upper() != 'RSA' and self.elliptic_curve and self.elliptic_curve.value and self.elliptic_curve.value in _key_algorithms_to_pkix[self.key_algo.value]:
97+
return _key_algorithms_to_pkix[self.key_algo.value][self.elliptic_curve.value]
98+
if self.key_bit_str and self.key_bit_str.value and str(self.key_bit_str.value) in _key_algorithms_to_pkix[self.key_algo.value]:
99+
return _key_algorithms_to_pkix[self.key_algo.value][str(self.key_bit_str.value)]
100+
return None
101+
75102
def to_policy_spec(self):
76103
"""
77104
:rtype: PolicySpecification

vcert/policy/policy_spec.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2021 Venafi, Inc.
2+
# Copyright 2021-2025 Venafi, Inc.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -76,19 +76,21 @@ def __init__(self, orgs=None, org_units=None, localities=None, states=None, coun
7676

7777
class KeyPair:
7878
def __init__(self, key_types=None, rsa_key_sizes=None, elliptic_curves=None, service_generated=None,
79-
reuse_allowed=None):
79+
reuse_allowed=None, pkix_parameter_set=None):
8080
"""
8181
:param list[str] key_types:
8282
:param list[int] rsa_key_sizes:
8383
:param list[str] elliptic_curves:
8484
:param bool service_generated:
8585
:param bool reuse_allowed:
86+
:param list[str] pkix_parameter_set
8687
"""
8788
self.key_types = key_types if key_types else []
8889
self.rsa_key_sizes = rsa_key_sizes if rsa_key_sizes else []
8990
self.elliptic_curves = elliptic_curves if elliptic_curves else []
9091
self.service_generated = service_generated
9192
self.reuse_allowed = reuse_allowed
93+
self.pkix_parameter_set = pkix_parameter_set if pkix_parameter_set else []
9294

9395

9496
class SubjectAltNames:
@@ -143,14 +145,17 @@ def __init__(self, org=None, org_units=None, locality=None, state=None, country=
143145

144146

145147
class DefaultKeyPair:
146-
def __init__(self, key_type=None, rsa_key_size=None, elliptic_curve=None, service_generated=None):
148+
def __init__(self, key_type=None, rsa_key_size=None, elliptic_curve=None, service_generated=None,
149+
pkix_parameter_set_default=None):
147150
"""
148151
:param str key_type:
149152
:param int rsa_key_size:
150153
:param str elliptic_curve:
151154
:param bool service_generated:
155+
:param str pkix_parameter_set_default:
152156
"""
153157
self.key_type = key_type
154158
self.rsa_key_size = rsa_key_size
155159
self.elliptic_curve = elliptic_curve
156160
self.service_generated = service_generated
161+
self.pkix_parameter_set_default = pkix_parameter_set_default

0 commit comments

Comments
 (0)