Package com.isode.dsapi.x509
Class PendingIdentity
java.lang.Object
com.isode.dsapi.x509.PendingIdentity
Convenience class that wraps information about a CertificateRequest
and associated Key in a single object representing an Identity
that the user has started to create but that he hasn't yet been
matched with a certificate from a CA.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionPendingIdentity
(CsrGenerator csrgen) Create a new object out of a CsrGenerator, and synthesize a filename for itPendingIdentity
(String reqFilename, String passphrase) Create an object by loading the components from the filesystem -
Method Summary
Modifier and TypeMethodDescriptionvoid
generateCertificateRequest
(String subjectDn, Extensions exts) Generate certificate requestvoid
generateKeys
(String algorithm, int keySize, String ecCurve) Generated the Certificate Request for the identity being represented .String[]
Return possible filename which should be used to read the certificate for this PendingIdentity.Extract the CertificateRequest objectDetermine the time when this object was created.Return a filename suitable for saving the CSR.getDN()
Return a DN representing the subject of this certificate request.Return the subject DN of this PendingIdentity, or the string "[invalid]" if the subject cannot be determined.getKey()
Extract the SSLKey object.Return a filename suitable for saving the key.Return a filename suitable for saving the key passphrase file.Get the parent directory of the pending identity.Return a filename suitable for saving the CSR in PEM format.Get the Pending Identity TypeReturn a filename which should be used as the PKCS#12 file for this PendingIdentity.boolean
isOnDisk()
Determine if the pending identity exists on diskboolean
Remove from disk any files that correspond with this PendingIdentity.boolean
removeFiles
(String identityParentDir) Remove from disk any files that correspond with this PendingIdentity.void
saveToDisk
(String directory, String passphrase, boolean makeNameUnique) Save this PendingIdentity to disk in a specified directory.void
saveToDisk
(String directory, String passphrase, boolean writePassphrase, boolean makeNameUnique) Save this PendingIdentity to disk in a specified directory.void
setFilename
(String fileName) Set the simple name(without extension) of the files that would be generated.toString()
Return a String containing the subject DN of this PendingIdentity.
-
Constructor Details
-
PendingIdentity
Create a new object out of a CsrGenerator, and synthesize a filename for it- Parameters:
csrgen
-
-
PendingIdentity
Create an object by loading the components from the filesystem- Parameters:
reqFilename
- the name of the CSR file. This will be a String ending in ".p10". The same filename, with ".p10" replaced with ".pem" will be read in order to obtain the key.passphrase
- the passphrase to be used to decrypt the key file.- Throws:
CryptoException
- if one or other of the files cannot be found, or if passphrase does not decrypt the key file.IllegalArgumentException
- if csrFilename doesn't end with ".p10"
-
-
Method Details
-
getParentDirectory
Get the parent directory of the pending identity.- Returns:
- directory containing all files related to a pending identity (passphrase and csr file)
-
toString
Return a String containing the subject DN of this PendingIdentity. This makes the class suitable for use in a ListBrowser. -
getDNString
Return the subject DN of this PendingIdentity, or the string "[invalid]" if the subject cannot be determined.- Returns:
- subject dn
-
getDN
Return a DN representing the subject of this certificate request.- Returns:
- a DN, or null if the subject string can't be parsed into a DN.
-
getCertificateRequest
Extract the CertificateRequest object- Returns:
- the CertificateRequest contained in this object.
-
getKey
Extract the SSLKey object.- Returns:
- the SSLKey in this object.
-
setFilename
Set the simple name(without extension) of the files that would be generated. For example if filename is 123456 ,then it would generate files 123456.p10, 123456.pem and so on- Parameters:
fileName
- simple file name without extension- Since:
- 15.0
-
getCsrFilename
Return a filename suitable for saving the CSR. This is the filename only, i.e. no directory specification is included.- Returns:
- a filename.
-
getPemCsrFilename
Return a filename suitable for saving the CSR in PEM format. This is the filename only, i.e. no directory specification is included.- Returns:
- a filename.
-
getKeyFilename
Return a filename suitable for saving the key. This is the filename only, i.e. no directory specification is included.- Returns:
- a filename.
-
getKeyPphrFilename
Return a filename suitable for saving the key passphrase file. This is the filename only, i.e. no directory specification is included.- Returns:
- a filename.
- Since:
- 15.0
-
getCertFilenames
Return possible filename which should be used to read the certificate for this PendingIdentity. This is the filenames only, i.e. no directory specification is included.- Returns:
- filenames, not null
-
getPKCS12Filename
Return a filename which should be used as the PKCS#12 file for this PendingIdentity. This is the filename only, i.e. no directory specification is included.- Returns:
- a filename.
-
getCreationTime
Determine the time when this object was created. For an object which has been created but not saved to disk, this will be the time when it was instantiated. For an object restored from disk, this will be the modification time of the disk file containing the PKCS#10 CSR (which may not be the same as the time when the initial request was created).- Returns:
- an approximate time when this PendingIdentity was created.
-
saveToDisk
public void saveToDisk(String directory, String passphrase, boolean writePassphrase, boolean makeNameUnique) throws IOException Save this PendingIdentity to disk in a specified directory. This will save the Certificate Request in a ".p10" file, and the encrypted key in a ".pem" file.- Parameters:
directory
- the directory in which to save the files representing this PendingIdentitypassphrase
- the passphrase to use to encrypt sensitive datawritePassphrase
- true if the passphrase should be saved in a "filename".pem.pphr file and false otherwisemakeNameUnique
- if this is true, a unique name will be generated for saving the files.- Throws:
IOException
- if a problem occurred writing the files.- Since:
- 15.0
-
saveToDisk
public void saveToDisk(String directory, String passphrase, boolean makeNameUnique) throws IOException Save this PendingIdentity to disk in a specified directory. This will save the Certificate Request in a ".p10" file, and the encrypted key in a ".pem" file.- Parameters:
directory
- the directory in which to save the files representing this PendingIdentitypassphrase
- the passphrase to use to encrypt sensitive datamakeNameUnique
- if this is true, a unique name will be generated for saving the files. The function will check for the presence of csr filename and append a number until it becomes a unique name. The same name will be used for the key and passphrase file.- Throws:
IOException
- if a problem occurred writing the files.
-
removeFiles
public boolean removeFiles()Remove from disk any files that correspond with this PendingIdentity. This will remove the CSR (.p10) and key (.pem) files if they exist. It is expected that after calling this method, the object won't be used any more. Note that this method should be used to remove files if the identity has been created using the constructorPendingIdentity(String, String)
where the parent directory was known- Returns:
- true if the files were deleted, false otherwise.
- See Also:
-
removeFiles
Remove from disk any files that correspond with this PendingIdentity. This will remove the CSR (.p10) and key (.pem) files if they exist. It is expected that after calling this method, the object won't be used any more.- Parameters:
identityParentDir
- the directory where the identity files are present, should not be null- Returns:
- true if the files were deleted, false otherwise.
- Since:
- 15.1
- See Also:
-
generateCertificateRequest
Generate certificate request- Parameters:
subjectDn
- subject of the requestexts
- extensions- Throws:
CryptoException
- if there is error while generating the request
-
generateKeys
Generated the Certificate Request for the identity being represented . It ensures that Key is not generated if the options have not been changed since its last call.- Parameters:
algorithm
- - Public Key AlgorithmkeySize
- - Key SizeecCurve
- curve to be used for ECDSA keys, can be null for other algorithms- Throws:
CryptoException
- if there is an error generating Certificate Request from Crypto Library
-
getPendingIdType
Get the Pending Identity Type- Returns:
- Pending Identity Type
-
isOnDisk
public boolean isOnDisk()Determine if the pending identity exists on disk- Returns:
- true if it comes from disk (
PendingIdentity(String, String)
or has been written to disk (, #saveToDisk(String, String, boolean, boolean)
and false otherwise
-