66
77from .exceptions import CFSSLException , CFSSLRemoteException
88
9+ from .models .config_key import ConfigKey
10+
911
1012class CFSSL (object ):
1113 """ It provides Python bindings to a remote CFSSL server via HTTP(S).
@@ -23,8 +25,7 @@ def auth_sign(self, token, request, datetime=None, remote_address=None):
2325
2426 Args:
2527 token: (str) The authentication token.
26- request: (mixed) Signing request document (e.g. as
27- documented in endpoint_sign.txt, but not JSON encoded).
28+ request: (cfssl.CertificateRequest) Signing request document.
2829 datetime: (datetime.datetime) Authentication timestamp.
2930 remote_address: (str) An address used in making the request.
3031 Returns:
@@ -33,7 +34,7 @@ def auth_sign(self, token, request, datetime=None, remote_address=None):
3334 """
3435 data = self ._clean_mapping ({
3536 'token' : token ,
36- 'request' : request ,
37+ 'request' : request . to_api () ,
3738 'datetime' : datetime ,
3839 'remote_address' : remote_address ,
3940 })
@@ -65,11 +66,11 @@ def bundle(self, certificate, private_key=None,
6566
6667 If only the ``domain`` parameter is present, the following
6768 parameter is valid:
68-
69+
6970 ip: (str) The IP address of the remote host; this will fetch the
7071 certificate from the IP, and verify that it is valid for the
7172 domain name.
72-
73+
7374 Returns:
7475 (dict) Object repesenting the bundle, with the following keys:
7576 * bundle contains the concatenated list of PEM certificates
@@ -162,42 +163,45 @@ def init_ca(self, hosts, names, common_name=None, key=None, ca=None):
162163 """ It initializes a new certificate authority.
163164
164165 Args:
165- hosts: (list) Of SANs (subject alternative names ) for the
166- requested CA certificate.
167- names: (list) the certificate subject for the requested CA
168- certificate.
166+ hosts: (iter of cfssl.Host) Subject Alternative Name(s ) for the
167+ requested CA certificate.
168+ names: (iter of cfssl.SubjectInfo) The Subject Info(s) for the
169+ requested CA certificate.
169170 common_name: (str) the common name for the certificate subject in
170171 the requested CA certificate.
171- key: the key algorithm and size for the newly generated private key,
172- default to ECDSA-256.
173- ca: the CA configuration of the requested CA, including CA pathlen
174- and CA default expiry.
172+ key: (cfssl.ConfigKey) Cipher and strength to use for certificate.
173+ ca: (cfssl.ConfigServer) the CA configuration of the requested CA,
174+ including CA pathlen and CA default expiry.
175175 Returns:
176176 (dict) Mapping with two keys:
177177 * private key: (str) a PEM-encoded CA private key.
178178 * certificate: (str) a PEM-encoded self-signed CA certificate.
179179 """
180+ key = key or ConfigKey ()
180181 data = self ._clean_mapping ({
181- 'hosts' : hosts ,
182- 'names' : names ,
182+ 'hosts' : [
183+ host .to_api () for host in hosts
184+ ],
185+ 'names' : [
186+ name .to_api () for name in names
187+ ],
183188 'CN' : common_name ,
184- 'key' : key ,
185- 'ca' : ca ,
189+ 'key' : key . to_api () ,
190+ 'ca' : ca and ca . to_api () or None ,
186191 })
187192 return self .call ('init_ca' , 'POST' , data = data )
188193
189194 def new_key (self , hosts , names , common_name = None , key = None , ca = None ):
190195 """ It generates and returns a new private key + CSR.
191196
192197 Args:
193- hosts: (list) Of SANs (subject alternative names ) for the
194- requested CA certificate.
195- names: (list) the certificate subject for the requested CA
196- certificate.
198+ hosts: (iter of cfssl.Host) Subject Alternative Name(s ) for the
199+ requested certificate.
200+ names: (iter of cfssl.SubjectInfo) The Subject Info(s) for the
201+ requested certificate.
197202 CN: (str) the common name for the certificate subject in the
198203 requestedrequested CA certificate.
199- key: the key algorithm and size for the newly generated private key,
200- default to ECDSA-256.
204+ key: (cfssl.ConfigKey) Cipher and strength to use for certificate.
201205 ca: the CA configuration of the requested CA, including CA pathlen
202206 and CA default expiry.
203207 Returns:
@@ -208,8 +212,12 @@ def new_key(self, hosts, names, common_name=None, key=None, ca=None):
208212 certificate request
209213 """
210214 data = self ._clean_mapping ({
211- 'hosts' : hosts ,
212- 'names' : names ,
215+ 'hosts' : [
216+ host .to_api () for host in hosts
217+ ],
218+ 'names' : [
219+ name .to_api () for name in names
220+ ],
213221 'CN' : common_name ,
214222 'key' : key ,
215223 'ca' : ca ,
@@ -220,7 +228,8 @@ def new_cert(self, request, label=None, profile=None, bundle=None):
220228 """ It generates and returns a new private key and certificate.
221229
222230 Args:
223- request: (dict) Specifying the certificate request.
231+ request: (cfssl.CertificateRequest) CSR to be used for
232+ certificate creation.
224233 label: (str) Specifying which signer to be appointed to sign
225234 the CSR, useful when interacting with cfssl server that stands
226235 in front of a remote multi-root CA signer.
@@ -238,7 +247,7 @@ def new_cert(self, request, label=None, profile=None, bundle=None):
238247 if the bundle parameter was set).
239248 """
240249 data = self ._clean_mapping ({
241- 'request' : request ,
250+ 'request' : request . to_api () ,
242251 'label' : label ,
243252 'profile' : profile ,
244253 'bundle' : bundle ,
@@ -269,12 +278,12 @@ def scan(self, host, ip=None, timeout=None, family=None, scanner=None):
269278 """ It scans servers to determine the quality of their TLS setup.
270279
271280 Args:
272- host: the hostname (optionally including port) to scan.
273- ip: IP Address to override DNS lookup of host.
274- timeout: The amount of time allotted for the scan to complete
281+ host: (cfssl.Host) The host to scan.
282+ ip: (str) IP Address to override DNS lookup of host.
283+ timeout: (str) The amount of time allotted for the scan to complete
275284 (default: 1 minute).
276- family: regular expression specifying scan famil(ies) to run.
277- scanner: regular expression specifying scanner(s) to run.
285+ family: (str) regular expression specifying scan famil(ies) to run.
286+ scanner: (str) regular expression specifying scanner(s) to run.
278287 Returns:
279288 (dict) Mapping with keys for each scan family. Each of these
280289 objects contains keys for each scanner run in that family
@@ -290,7 +299,7 @@ def scan(self, host, ip=None, timeout=None, family=None, scanner=None):
290299 * output: (dict) Arbitrary data retrieved during the scan.
291300 """
292301 data = self ._clean_mapping ({
293- 'host' : host ,
302+ 'host' : host . to_api () ,
294303 'ip' : ip ,
295304 'timeout' : timeout ,
296305 'family' : family ,
@@ -314,8 +323,8 @@ def sign(self, certificate_request, hosts=None, subject=None,
314323 """ It signs and returns a certificate.
315324
316325 Args:
317- certificate_request: (str) the CSR bytes to be signed in PEM.
318- hosts: (iter) of SAN (subject alternative .names)
326+ certificate_request: (str) the CSR bytes to be signed ( in PEM) .
327+ hosts: (iter of cfssl.Host ) of SAN (subject alternative .names)
319328 which overrides the ones in the CSR
320329 subject: (str) The certificate subject which overrides
321330 the ones in the CSR.
@@ -324,19 +333,22 @@ def sign(self, certificate_request, hosts=None, subject=None,
324333 label: (str) Specifying which signer to be appointed to sign
325334 the CSR, useful when interacting with a remote multi-root CA
326335 signer.
327- profile: (str) Specifying the signing profile for the signer,
328- useful when interacting with a remote multi-root CA signer.
336+ profile: (cfssl.ConfigServer) Specifying the signing profile for
337+ the signer, useful when interacting with a remote multi-root
338+ CA signer.
329339 Returns:
330340 (str) A PEM-encoded certificate that has been signed by the
331341 server.
332342 """
333343 data = self ._clean_mapping ({
334- 'certificate_request' : certificate_request ,
335- 'hosts' : hosts ,
344+ 'certificate_request' : certificate_request .to_api (),
345+ 'hosts' : [
346+ host .to_api () for host in hosts
347+ ],
336348 'subject' : subject ,
337349 'serial_sequence' : serial_sequence ,
338350 'label' : label ,
339- 'profile' : profile ,
351+ 'profile' : profile . to_api () ,
340352 })
341353 result = self .call ('sign' , 'POST' , data = data )
342354 return result ['certificate' ]
0 commit comments