Skip to content

Commit 87081b3

Browse files
committed
- Added example for Service generated CSR on TPP.
1 parent 10614f6 commit 87081b3

1 file changed

Lines changed: 3 additions & 29 deletions

File tree

examples/get_cert_service_tpp.py

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from __future__ import print_function
1919

20-
from vcert import (CertificateRequest, Connection, RevocationRequest, CSR_ORIGIN_SERVICE)
20+
from vcert import (CertificateRequest, venafi_connection, RevocationRequest, CSR_ORIGIN_SERVICE)
2121
import string
2222
import random
2323
import logging
@@ -36,12 +36,11 @@ def main():
3636
zone = environ.get("TPP_ZONE")
3737
server_trust_bundle = environ.get('TPP_TRUST_BUNDLE')
3838

39-
4039
# Connection will be chosen automatically based on which arguments are passed.
4140
# If token is passed Venafi Cloud connection will be used.
4241
# If user, password, and URL Venafi Platform (TPP) will be used.
43-
conn = Connection(url=url, user=user, password=password,
44-
http_request_kwargs={"verify": server_trust_bundle})
42+
conn = venafi_connection(url=url, user=user, password=password,
43+
http_request_kwargs={"verify": server_trust_bundle})
4544
# If your TPP server certificate signed with your own CA, or available only via proxy, you can specify
4645
# a trust bundle using requests vars:
4746
# conn = Connection(url=url, token=token, user=user, password=password,
@@ -90,31 +89,6 @@ def main():
9089
fn.write(new_request.private_key_pem)
9190
fn.close()
9291

93-
revocation_req = RevocationRequest(req_id=request.id, comments="Just for test")
94-
print("Revoke", conn.revoke_cert(revocation_req))
95-
96-
print("Trying to sign CSR")
97-
csr_pem = open("example-csr.pem", "rb").read()
98-
csr_request = CertificateRequest(csr=csr_pem.decode())
99-
# zone_config = conn.read_zone_conf(zone)
100-
# request.update_from_zone_config(zone_config)
101-
conn.request_cert(csr_request, zone)
102-
103-
# and wait for signing
104-
while True:
105-
cert = conn.retrieve_cert(csr_request)
106-
if cert:
107-
break
108-
else:
109-
time.sleep(5)
110-
111-
# after that print cert and key
112-
print(cert.full_chain)
113-
# and save into file
114-
f = open("/tmp/signed-cert.pem", "w")
115-
f.write(cert.full_chain)
116-
f.close()
117-
11892

11993
def random_word(length):
12094
letters = string.ascii_lowercase

0 commit comments

Comments
 (0)