@@ -174,64 +174,6 @@ def revoke_cert(self, request):
174174
175175 raise ServerUnexptedBehavior
176176
177- def renew_cert (self , request , reuse_key = False ):
178- if not request .id and not request .thumbprint :
179- log .debug ("Request id or thumbprint must be specified for TPP" )
180- raise CertificateRenewError
181- if not request .id and request .thumbprint :
182- request .id = self .search_by_thumbprint (request .thumbprint )
183- if reuse_key :
184- log .debug ("Trying to renew certificate %s" % request .id )
185- status , data = self ._post (URLS .CERTIFICATE_RENEW , data = {"CertificateDN" : request .id })
186- if not data ['Success' ]:
187- raise CertificateRenewError
188- return
189- cert = self .retrieve_cert (request )
190- cert = x509 .load_pem_x509_certificate (cert .cert .encode (), default_backend ())
191- for a in cert .subject :
192- if a .oid == x509 .NameOID .COMMON_NAME :
193- request .common_name = a .value
194- elif a .oid == x509 .NameOID .COUNTRY_NAME :
195- request .country = a .value
196- elif a .oid == x509 .NameOID .LOCALITY_NAME :
197- request .locality = a .value
198- elif a .oid == x509 .NameOID .STATE_OR_PROVINCE_NAME :
199- request .province = a .value
200- elif a .oid == x509 .NameOID .ORGANIZATION_NAME :
201- request .organization = a .value
202- elif a .oid == x509 .NameOID .ORGANIZATIONAL_UNIT_NAME :
203- request .organizational_unit = a .value
204- for e in cert .extensions :
205- if e .oid == x509 .OID_SUBJECT_ALTERNATIVE_NAME :
206- request .san_dns = list ([x .value for x in e .value if isinstance (x , x509 .DNSName )])
207- request .email_addresses = list ([x .value for x in e .value if isinstance (x , x509 .RFC822Name )])
208- request .ip_addresses = list ([x .value .exploded for x in e .value if isinstance (x , x509 .IPAddress )])
209- # remove header bytes from ASN1 encoded UPN field before setting it in the request object
210- upns = []
211- for x in e .value :
212- if isinstance (x , x509 .OtherName ):
213- upns .append (x .value [2 ::])
214- request .user_principal_names = upns
215- request .uniform_resource_identifiers = list (
216- [x .value for x in e .value if isinstance (x , x509 .UniformResourceIdentifier )])
217- if cert .signature_algorithm_oid in (AlgOID .ECDSA_WITH_SHA1 , AlgOID .ECDSA_WITH_SHA224 , AlgOID .ECDSA_WITH_SHA256 ,
218- AlgOID .ECDSA_WITH_SHA384 , AlgOID .ECDSA_WITH_SHA512 ):
219- request .key_type = (KeyType .ECDSA , KeyType .ALLOWED_CURVES [0 ])
220- else :
221- request .key_type = KeyType (KeyType .RSA , 2048 ) # todo: make parsing key size
222- if not request .csr :
223- request .build_csr ()
224- status , data = self ._post (URLS .CERTIFICATE_RENEW ,
225- data = {"CertificateDN" : request .id , "PKCS10" : request .csr })
226- if status == HTTPStatus .OK :
227- if "CertificateDN" in data :
228- request .id = data ['CertificateDN' ]
229- log .debug ("Certificate successfully requested with request id %s." % request .id )
230- return True
231-
232- log .error ("Request status is not %s. %s." % HTTPStatus .OK , status )
233- raise CertificateRequestError
234-
235177 @staticmethod
236178 def _parse_zone_config_to_policy (data ):
237179 # todo: parse over values to regexps (dont forget tests!)
@@ -284,28 +226,14 @@ def _parse_zone_data_to_object(data):
284226 return z
285227
286228 def read_zone_conf (self , tag ):
287- status , data = self ._post (URLS .ZONE_CONFIG , {"PolicyDN" : self ._get_policy_dn (tag )})
229+ status , data = self ._post (URLS .ZONE_CONFIG , {"PolicyDN" : self ._normalize_zone (tag )})
288230 if status != HTTPStatus .OK :
289231 raise ServerUnexptedBehavior ("Server returns %d status on reading zone configuration." % status )
290232 return self ._parse_zone_data_to_object (data )
291233
292234 def import_cert (self , request ):
293235 raise NotImplementedError
294236
295- def search_by_thumbprint (self , thumbprint ):
296- """
297- :param str thumbprint:
298- """
299- thumbprint = re .sub (r'[^\dabcdefABCDEF]' , "" , thumbprint )
300- thumbprint = thumbprint .upper ()
301- status , data = self ._get (URLS .CERTIFICATE_SEARCH , params = {"Thumbprint" : thumbprint })
302- if status != HTTPStatus .OK :
303- raise ServerUnexptedBehavior
304-
305- if not data ['Certificates' ]:
306- raise ClientBadData ("Certificate not found by thumbprint" )
307- return data ['Certificates' ][0 ]['DN' ]
308-
309237 def _read_config_dn (self , dn , attribute_name ):
310238 status , data = self ._post (URLS .CONFIG_READ_DN , {
311239 "ObjectDN" : dn ,
0 commit comments