This module contains top-level classes and functions used by the Dogtag project.
Bases: object
Class representing a key/value pair.
This object is the basis of the representation of a ResourceMessage.
Bases: object
Class representing a list of attributes.
This class is needed because of a JavaMapper used in the REST API.
Bases: pki.PKIException
Bad Request Exception: return code = 400
Bases: pki.ResourceNotFoundException
Cert Not Found Exception: return code = 404
Bases: pki.PKIException
Conflicting Operation Exception: return code = 409
Bases: pki.PKIException
Forbidden Exception: return code = 403
Bases: pki.ResourceNotFoundException
Group Not Found Exception: return code = 404
Bases: pki.PKIException
Gone Exception: return code = 410
Bases: pki.ResourceNotFoundException
Key Not Found Exception: return code 404
Bases: object
Stores the information of the resteasy’s Link object sent by the server for a resource.
Bases: exceptions.Exception, pki.ResourceMessage
Base exception class for REST Interface
Bases: pki.ResourceNotFoundException
Profile Not Found Exception: return code = 404
Bases: object
Class to manage property files The contents of the property file are maintained internally as a list of properties.
Properties are strings of the format <name> <delimiter> <value> where ‘=’ is the default delimiter.
Get the value of the specified property.
Parameters: | name (str) – name of property to be fetched. |
---|---|
Returns: | str – value of property |
Find the index (position) of a property in a property file.
Parameters: | name (str) – name of property |
---|---|
Returns: | int – index of property. |
Insert property into the list of properties maintained by this object at the specified location (index).
Parameters: |
|
---|---|
Returns: | None |
Read from property file into the list of properties maintained by this object.
Returns: | None |
---|
Remove property from list of properties maintained by this object.
Parameters: | name (str) – name of property to be removed. |
---|---|
Returns: | None |
Remove property at specified index from the properties list.
Parameters: | index (int) – location of property to be removed. |
---|---|
Returns: | None |
Set value of specified property.
Parameters: |
|
---|---|
Returns: | None |
Bases: pki.ResourceNotFoundException
Request Not Found Exception: return code = 404
Bases: object
This class is the basis for the various types of key requests. It is essentially a list of attributes.
Bases: pki.PKIException
Not Found Exception: return code = 404
Bases: pki.PKIException
Unauthorized Exception: return code = 401
Bases: pki.ResourceNotFoundException
User Not Found Exception: return code = 404
Convert X.509 Name into NSS-style DN string.
See also: - https://cryptography.io/en/latest/x509/reference/#cryptography.x509.Name - https://cryptography.io/en/latest/x509/reference/#cryptography.x509.NameAttribute - https://cryptography.io/en/latest/x509/reference/#cryptography.x509.ObjectIdentifier
Parameters: | name (cryptography.x509.Name) – X.509 Name |
---|---|
Returns: | str – DN string. |
This function generates FIPS-compliant password.
See sftk_newPinCheck() in the following file: https://dxr.mozilla.org/nss/source/nss/lib/softoken/fipstokn.c
The minimum password length is FIPS_MIN_PIN Unicode characters.
If an ASCII uppercase letter is the first character of the password, the uppercase letter is not counted toward its character class.
If a digit is the last character of the password, the digit is not counted toward its character class.
The FIPS_MIN_PIN is defined in the following file: https://dxr.mozilla.org/nss/source/nss/lib/softoken/pkcs11i.h
#define FIPS_MIN_PIN 7
Return implementation version.
Returns: | str –implementation version |
---|
Get an input from the user. This is used, for example, in pkispawn and pkidestroy to obtain user input.
Parameters: |
|
---|---|
Returns: | str – value obtained from user input. |
Class used to associate an authentication session variable with a connection.
Bases: object
Class encapsulating and mirroring the functionality in the CertResource Java interface class defining the REST API for Certificate resources.
Approves a certificate enrollment request. If cert_review_response is None, a review request operation is performed to fetch the CertReviewResponse object. Requires as agent level authentication.
Assigns a certificate enrollment request. If cert_review_response is None, a review request operation is performed to fetch the CertReviewResponse object. Requires as agent level authentication.
Cancels a certificate enrollment request. If cert_review_response is None, a review request operation is performed to fetch the CertReviewResponse object. Requires as agent level authentication.
Fetches the enrollment request object for the given profile and sets values to its attributes using the values provided in the inputs dictionary. Returns the CertEnrollmentRequest object, which can be submitted to enroll a certificate.
A convenience method for enrolling a certificate for a given profile id. The inputs parameter should be a dictionary with values for the profile attributes for an enrollment request.
Calling this method with valid arguments, creates an enrollment request, submits it to the server, approves the certificate requests generated for the enrollment and returns a list of CertData objects for all the certificates generated as part of this enrollment.
Note: This method supports only certificate enrollment where only one agent approval is sufficient.
Requires an agent level authentication. Returns a list of CertEnrollmentResult objects.
Fetch the enrollment template for the given profile id. For the first time, the request is sent to the server. The retrieved CertEnrollmentRequest object is then cached locally for future requests. Returns a CerEnrollmentRequest object.
Get information of a certificate request with the given request ID. Returns a CertRequestInfo object.
Places a certificate on-hold. Calls the revoke_cert method with reason - CertRevokeRequest.REASON_CERTIFICATE_HOLD. Returns a CertRequestInfo object. This method requires an agent’s authentication cert in the connection object.
Return a CertDataInfoCollection object with a information about all the certificates that satisfy the search criteria. If cert_search_request=None, returns all the certificates.
Gets the list of profile templates supported by the CA. The values for start and size arguments determine the starting point and the length of the list. Returns a ProfileDataInfoCollection object.
Query for a list of certificates using the arguments passed. Returns a CertRequestInfoCollection object.
Rejects a certificate enrollment request. If cert_review_response is None, a review request operation is performed to fetch the CertReviewResponse object. Requires as agent level authentication.
Reviews a certificate. Returns a CertData object with a nonce. This method requires an agent’s authentication cert in the connection object.
Reviews a certificate enrollment request. Returns a CertReviewResponse object which contains the nonce from the server needed to perform an action on the request.
Revokes a CA certificate. Returns a CertRequestInfo object with information about the request. This method requires an agent’s authentication cert in the connection object.
Revokes a certificate. Returns a CertRequestInfo object with information about the request. This method requires an agent’s authentication cert in the connection object.
Submits the CertEnrollmentRequest object to the server. Returns a CertRequestInfoCollection object with information about the certificate requests enrolled at the CA.
Un-assigns a certificate enrollment request. If cert_review_response is None, a review request operation is performed to fetch the CertReviewResponse object. Requires as agent level authentication.
Un-revokes a revoked certificate. Returns a CertRequestInfo object. This method requires an agent’s authentication cert in the connection object.
Bases: object
Class containing certificate data as returned from getCert()
Bases: object
Class containing information contained in a CertRecord on the CA. This data is returned when searching/listing certificate records.
Bases: object
Class containing list of CertDataInfo objects and their respective link objects. This data is returned when searching/listing certificate records in the CA.
Bases: object
Bases: object
Class containing results of an enrollment request.
This structure contains information about the cert request generated and any certificates issued.
Bases: object
An object of this class stores represents a certificate request.
Bases: object
Class containing list of CertRequestInfo objects. This data is returned when listing certificate request records in the CA.
Bases: object
Class containing valid cert statuses.
Bases: pki.cert.CertEnrollmentRequest
An object of this class represent the response from the server when reviewing a certificate enrollment request. It contains a nonce required to perform action on the request.
Bases: object
An object of this class encapsulates all the parameters required for revoking a certificate.
Bases: object
An object of this class is used to store the search parameters and send them to server.
Class to encapsulate the connection between the client and a Dogtag subsystem.
Set the parameters used for authentication if username/password is to be used. Both username and password must not be None. Note that this method only sets the parameters. Actual authentication occurs when the connection is attempted,
Parameters: |
|
---|---|
Returns: | None |
Uses python-requests to issue a DEL request to the server.
Parameters: |
|
---|---|
Returns: | request.response – response from the server |
Raises : | Exception from python-requests in case the DEL was not successful, or returns an error code. |
Uses python-requests to issue a GET request to the server.
Parameters: |
|
---|---|
Returns: | request.response – response from the server |
Raises : | Exception from python-requests in case the GET was not successful, or returns an error code. |
Uses python-requests to issue a POST request to the server.
Parameters: |
|
---|---|
Returns: | request.response – response from the server |
Raises : | Exception from python-requests in case the POST was not successful, or returns an error code. |
Uses python-requests to issue a PUT request to the server.
Parameters: |
|
---|---|
Returns: | request.response – response from the server |
Raises : | Exception from python-requests in case the PUT was not successful, or returns an error code. |
Set the path to the PEM file containing the certificate and private key for the client certificate to be used for authentication to the server, when client certificate authentication is required. The private key may optionally be stored in a different path.
Parameters: |
|
---|---|
Returns: | None |
Raises : | Exception if path is empty or None. |
Temporary silence InsecureRequestWarning
PKIConnection is not able to verify HTTPS connections yet. This decorator catches the warning.
See : | https://fedorahosted.org/pki/ticket/1253 |
---|
Module containing crypto classes.
Bases: object
Abstract class containing methods to do cryptographic operations.
encrypt a symmetric key with the public key of a transport cert.
The mechanism is the type of symmetric key, which defaults to a 56 bit DES3 key.
Generate a session key to be used for wrapping data to the DRM This must return a 3DES 168 bit key
Unwrap data that has been key wrapped using AES KeyWrap
Bases: pki.crypto.CryptoProvider
Class that defines python-cryptography implementation of CryptoProvider. Requires a PEM file containing the agent cert to be initialized.
Note that all inputs and outputs are unencoded.
:param data Data to be wrapped :param wrapping_cert Public key to wrap data :param mechanism algorithm of symmetric key to be wrapped
Wrap (encrypt) data using the supplied asymmetric key
:param mechanism key wrapping mechanism :param data: data to unwrap :param wrapping_key: AES key used to wrap data :param nonce_iv Nonce data :return: unwrapped data
Unwrap the encrypted data which has been wrapped using a KeyWrap mechanism.
:param data Data to be unwrapped :param wrapping_key Symmetric key to unwrap data :param mechanism Mechanism to use when unwrapping :param nonce_iv iv data
Unwrap (decrypt) data using the supplied symmetric key
:param data Data to be wrapped :param wrapping_key Symmetric key to wrap data :param mechanism Mechanism to use for wrapping key :param nonce_iv Nonce for initialization vector
Wrap (encrypt) data using the supplied symmetric key
Bases: pki.crypto.CryptoProvider
Class that defines NSS implementation of CryptoProvider. Requires an NSS database to have been set up and initialized.
Note that all inputs and outputs are unencoded.
:param data Data to be wrapped :param wrapping_cert Public key to wrap data :param mechanism algorithm of symmetric key to be wrapped
Wrap (encrypt) data using the supplied asymmetric key
Returns a session key to be used when wrapping secrets for the DRM This will return a 168 bit 3DES key.
Returns a symmetric key.
Note that for fixed length keys, this length should be 0. If no length is provided, then the function will either use 0 (for fixed length keys) or the maximum available length for that algorithm and the token.
:param cert_nick Nickname for the certificate to be returned
Searches NSS database and returns SecItem object for this certificate.
:param mechanism Key wrapping mechanism :param data: Data to be unwrapped :param wrapping_key: Wrapping Key :param nonce_iv Nonce data :return: Unwrapped data
Return unwrapped data for data that has been keywrapped. For NSS, we only support 3DES - so something that has been keywrapped can be decrypted. This is precisely what we used to do before.
Set up contexts to do wrapping/unwrapping by symmetric keys.
Create an NSS database
Bases: json.encoder.JSONEncoder
A custom JSONEncoder class that knows how to encode core custom objects.
Custom objects are encoded as JSON object literals (ie, dicts) with one key, ‘TypeName’ where ‘TypeName’ is the actual name of the type to which the object belongs. That single key maps to another object literal which is just the __dict__ of the object encoded.
Reason for ignoring the error: E0202 - An attribute affected in json.encoder line 157 hide this method reported by pylint:
The error is in json.encoder.JSONEncoder class. There is a default method (which is overridden here) and also a class attribute self.default initialized in the init method of the class. The intention of such usage being that a custom default method object can be passed to init when creating an instance of JSONEncoder, which is then assigned to class’s default method. (which is valid) But pylint raises an issue due to the usage of same name for a method and an attribute in which case the attribute definition hides the method. The reason and example for the issue: (top rated comment)
http://stackoverflow.com/questions/12949064/python-what-happens- when-instance-variable-name-is-same-as-method-name
Module containing the Python client classes for the KeyClient and KeyRequestClient REST API on a DRM
Bases: pki.ResourceMessage
Class representing the data sent to the DRM when generating and archiving asymmetric keys in the DRM.
Bases: object
An instance of this class stores the decoded encrypted secret present in the KeyData object passed in the constructor. All the key retrieval requests return this object.
Bases: pki.ResourceMessage
Class representing the object sent to the DRM when archiving a secret.
Bases: object
Class that encapsulates and mirrors the functions in the KeyResource and KeyRequestResource Java classes in the DRM REST API.
Archive a secret (symmetric key or passphrase) on the DRM.
Refer to archive_key() comments for a description of client_key_id, data_type, key_algorithm and key_size.
This function is useful if the caller wants to do their own wrapping of the secret, or if the secret was generated on a separate client machine and the wrapping was done there.
The function returns a KeyRequestResponse object containing a KeyRequestInfo object with details about the archival request and key archived.
Archive a secret (symmetric key or passphrase) on the DRM.
Requires a user-supplied client ID. There can be only one active key with a specified client ID. If a record for a duplicate active key exists, a BadRequestException is thrown.
key_algorithm and key_size are applicable to symmetric keys only. If a symmetric key is being archived, these parameters are required.
private_data is the raw secret to be archived. It will be wrapped and sent to the DRM.
The function returns a KeyRequestResponse object containing a KeyRequestInfo object with details about the archival request and key archived.
Archive a secret (symmetric key or passphrase) on the DRM.
Refer to archive_key() comments for a description of client_key_id, data_type, key_algorithm and key_size.
pki_archive_options is the data to be archived wrapped in a PKIArchiveOptions structure,
The function returns a KeyRequestResponse object containing a KeyRequestInfo object with details about the archival request and key archived.
Generate and archive asymmetric keys in the DRM. Supports algorithms RSA and DSA. Valid key size for RSA = 256 + (16 * n), where n: 0-496 Valid key size for DSA = 512, 768, 1024. p,q,g params are not supported.
Return a KeyRequestResponse which contains a KeyRequestInfo object that describes the URL for the request and generated keys.
Generate and archive a symmetric key on the DRM.
Return a KeyRequestResponse which contains a KeyRequestInfo object that describes the URL for the request and generated key.
Get the info in the KeyRecord for the active secret in the DRM.
Get the info in the KeyRecord for a specific secret in the DRM.
Return a KeyRequestInfo object for a specific request.
List/Search archived secrets in the DRM.
See KRAClient.list_keys for the valid values of status. Returns a KeyInfoCollection object.
List/Search key requests in the DRM.
See KRAClient.list_requests for the valid values of request_state and request_type. Returns a KeyRequestInfoCollection object.
Decrypt the returned key and place in key.data
The data will either by encrypted using an encryption algorithm - in which case, the key data will contain an encryption algorithm OID, or it will be key wrapped - in which case, the key data will contain a key wrap mechanism name.
Only one of these should be present. If we are talking to an older server, and none is present, we will assume encryption.
Create a request to recover a secret.
To retrieve a symmetric key or passphrase, the only parameter that is required is the keyId. It is possible (but not required) to pass in the session keys/passphrase and nonceData for the retrieval at this time. Those parameters are documented in the docstring for retrieve_key below.
To retrieve an asymmetric key, the keyId and the the base-64 encoded certificate is required.
Retrieve a secret (passphrase or symmetric key) from the DRM.
This method will retrieve a key from the KRA given the key_id or request_id (one of which must be specified). The data is returned as a KeyData object (which is recast to a Key object).
If request_id is specified, then the value of key_id is ignored. Exceptions will be thrown if the caller is not the originator of the request, or the request is not approved.
If key_id is specified instead, the following behavior applies:
To ensure data security in transit, the data will be returned encrypted by a session key (168 bit 3DES symmetric key) - which is first wrapped (encrypted) by the public key of the DRM transport certificate before being sent to the DRM. The parameter trans_wrapped_session_key refers to this wrapped session key.
If the trans_wrapped_session_key is not provided by caller, the method will call CryptoProvider methods to generate and wrap the session key. The function will return the KeyData object with a private_data attribute which stores the unwrapped key information.
If the trans_wrapped_session_key is provided by the caller, the method will simply pass the data to the KRA, and will return the secret wrapped in the session key. The secret will still need to be unwrapped by the caller. The function will return the KeyData object, where the KeyData structure includes the wrapped secret and some nonce data to be used as a salt when unwrapping.
Retrieve a secret (passphrase or symmetric key) from the DRM using a passphrase.
This function generates a key recovery request, approves it, and retrieves the secret referred to by key_id. This assumes that only one approval is required to authorize the recovery.
The secret is secured in transit by wrapping the secret with a passphrase using PBE encryption.
There are two ways of using this function:
A passphrase is provided by the caller.
In this case, CryptoProvider methods will be called to create the data to securely send the passphrase to the DRM. Basically, three pieces of data will be sent:
The function will return the tuple (KeyData, unwrapped_secret)
The caller provides the trans_wrapped_session_key, session_wrapped_passphrase and nonce_data.
In this case, the data will simply be passed to the DRM. The function will return the secret encrypted by the passphrase using PBE Encryption. The secret will still need to be decrypted by the caller.
The function will return the tuple (KeyData, None)
Retrieve an asymmetric private key and return it as PKCS12 data.
This function generates a key recovery request, approves it, and retrieves the secret referred to by key_id in a PKCS12 file. This assumes that only one approval is required to authorize the recovery.
This function requires the following parameters: - key_id : the ID of the key - certificate: the certificate associated with the private key - passphrase: A passphrase for the pkcs12 file.
The function returns a KeyData object.
Retrieve a secret from the DRM.
@param: data - a KeyRecoveryRequest containing the keyId of the secret being retrieved, the request_id of the approved recovery request and a wrapping mechanism. More details at KRAClient.retrieve_key.
Returns a KeyData object containing the wrapped secret.
Bases: object
This is the object that contains the encoded wrapped secret when that secret is retrieved. It is used by the DRM to send information of the key in the key retrieval requests.
Bases: object
This is the object that contains information stored in the database record for an archived secret. It does not contain the secret itself.
Bases: object
This class represents data returned when searching the DRM archived secrets. Essentially, its a list of KeyInfo objects.
Bases: pki.ResourceMessage
Class representing the data sent to the DRM when either creating a request for the recovery of a secret, or, once the request is approved, retrieving the secret.
Bases: object
This class represents data about key requests (archival, recovery, key generation etc.) in the DRM.
Bases: object
This class represents the data returned when searching the key requests in the DRM. Essentially, its a list of KeyRequestInfo objects.
Bases: object
This class is returned when an archival, recovery or key generation request is created. It includes a KeyRequestInfo object with information about the created request, and a KeyData structure which contains the wrapped secret (if that operation is supported).
Bases: pki.ResourceMessage
Class representing the data sent to the DRM when generating and archiving a symmetric key in the DRM.
Module containing KRAClient class. This class should be used by Python clients to interact with the DRM to expose the functionality of the KeyClient and KeyRequestResource REST APIs.
Bases: object
This class represents the description of a ProfileAttribute. It stores information such as the syntax, constraint and default value of a profile attribute.
Bases: object
An object of this class contains the policy constraints applied to a ProfileInput used by a certificate enrollment request.
Add a PolicyConstraintValue to the policy_constraint_values list.
Returns a PolicyConstraintValue object with the given name. None, if there is no match.
Bases: object
Represents a PolicyConstraintValue
Bases: object
An object of this class contains information of the default usage of a specific ProfileInput.
Add a policy attribute to the attribute list. @param policy_attribute - A ProfileAttribute object
Add a profile parameter to the parameters list. @param policy_parameter - A ProfileParameter object.
Fetch the policy attribute with the given name from the attributes list.
Fetch a profile parameter with the given name from the parameters list.
Bases: object
An object of this class contains a name value pair of the policy name and the ProfilePolicy object.
Bases: object
An object of this class stores a list of ProfileSet objects.
Bases: object
This class represents an enrollment profile.
Fetches a ProfileInput with the given ProfileInput id. Returns None, if there is no matching input.
Fetches a ProfileOutput with the given ProfileOutput id. Returns None, if there is no matching output.
Fetches a ProfileInput with the given ProfileInput id. Returns None, if there is no matching input.
Reads the file for the serialized Profile object. Currently supports only data format in json.
Bases: object
Represents a profile attribute of a ProfileInput.
Bases: object
This class consists of methods for accessing the ProfileResource.
Reads the file for the serialized Profile object. Performs the profile create operation. Currently supports only data format in json.
Fetches information for the profile for the given profile id. Returns a ProfileData object.
Fetches the list of profiles. The start and size arguments provide pagination support. Returns a ProfileDataInfoCollection object.
Bases: object
Stores information about a profile
Bases: object
Represents a collection of ProfileDataInfo objects. Also encapsulates the links for the list of the objects stored.
Bases: object
This class encapsulates all the attributes of a profile to generate a specific property of a certificate. Ex. Subject name, Requestor Information etc.
Add a ProfileAttribute object to the config_attributes list.
Returns a ProfileAttribute object for the given name. None, if no match.
Returns a ProfileAttribute object with the given name. None, if there is no match in the config_attributes list.
Bases: object
This class defines the output of a certificate enrollment request using a profile.
Returns a ProfileAttribute object for the given name. None, if no match.
Bases: object
This class represents the policy a profile adheres to. An object of this class stores the default values for profile and the constraints present on the values of the attributes of the profile submitted for an enrollment request.
Bases: object
Class used to represent a configuration request to be submitted to the Java installation servlet during the execution of pkispawn.
This class is the python equivalent of the Java class: com.netscape.certsrv.system.ConfigurationRequest
Bases: object
Class used to represent the response from the Java configuration servlet during the execution of pkispawn.
This class is the python equivalent of the Java class: com.netscape.certsrv.system.ConfigurationRequest
Bases: object
Client used to get the security domain from a security domain CA. The connection details for the security domain CA are specified in a PKIConnection object used to construct this client.
Contact the security domain CA specified in the connection object used to construct this client and get the security domain using the old servlet-based interface. This method is useful when contacting old servers which do not provide the REST API.
Returns: | pki.system.SecurityDomainInfo |
---|
Bases: object
Class representing a security domain host.
Bases: object
Class representing the entire security domain. This is essentially a list of SecurityDomainSubsystem components.
Bases: object
Class representing a security domain subsystem. This is essentially a list of SecurityDomainHost objects of a particular subsystem type (ca, kra, tps, tks, ocsp).
Bases: object
Class used to represent the data for a system certificate, which is used in the data passed into and returned from the Java installation servlet during the execution of pkispawn.
This class is the python equivalent of the Java class: com.netscape.certsrv.system.SystemCertData
Bases: object
Client used to interact with the Java configuration servlet to configure a Dogtag subsystem during the execution of pkispawn.
The connection details for the system being configured are passed in the PKIConnection object used when constructing this object.
Contacts the server and invokes the Java configuration REST API to configure a Dogtag subsystem.
Parameters: | data (ConfigurationRequest) – Configuration request containing all the input needed to configure the subsystem |
---|---|
Returns: | ConfigurationResponse – response from configuration servlet. |
Module containing the Python client classes for the SystemCert REST API
Bases: object
Module containing utility functions and classes for the Dogtag python code
Copy a folder and its parents while preserving their attributes.
Copy a file or link while preserving its attributes.
Recursively copy a directory tree using copy2().
If exception(s) occur, an Error is raised with a list of reasons.
If the optional symlinks flag is true, symbolic links in the source tree result in symbolic links in the destination tree; if it is false, the contents of the files pointed to by symbolic links are copied.
The optional ignore argument is a callable. If given, it is called with the src parameter, which is the directory being visited by copytree(), and names which is the list of src contents, as returned by os.listdir():
callable(src, names) -> ignored_names
Since copytree() is called recursively, the callable will be called once for each directory that is copied. It returns a list of names relative to the src directory that should not be copied.
Consider this example code rather than the ultimate tool.