letsencrypt.storage

Renewable certificates storage.

letsencrypt.storage.config_with_defaults(config=None)[source]

Merge supplied config, if provided, on top of builtin defaults.

letsencrypt.storage.add_time_interval(base_time, interval, textparser=<parsedatetime.Calendar instance>)[source]

Parse the time specified time interval, and add it to the base_time

The interval can be in the English-language format understood by parsedatetime, e.g., ‘10 days’, ‘3 weeks’, ‘6 months’, ‘9 hours’, or a sequence of such intervals like ‘6 months 1 week’ or ‘3 days 12 hours’. If an integer is found with no associated unit, it is interpreted by default as a number of days.

Parameters:
  • base_time (datetime.datetime) – The time to be added with the interval.
  • interval (str) – The time interval to parse.
Returns:

The base_time plus the interpretation of the time interval.

Return type:

datetime.datetime

class letsencrypt.storage.RenewableCert(config_filename, cli_config)[source]

Bases: object

Renewable certificate.

Represents a lineage of certificates that is under the management of the Let’s Encrypt client, indicated by the existence of an associated renewal configuration file.

Note that the notion of “current version” for a lineage is maintained on disk in the structure of symbolic links, and is not explicitly stored in any instance variable in this object. The RenewableCert object is able to determine information about the current (or other) version by accessing data on disk, but does not inherently know any of this information except by examining the symbolic links as needed. The instance variables mentioned below point to symlinks that reflect the notion of “current version” of each managed object, and it is these paths that should be used when configuring servers to use the certificate managed in a lineage. These paths are normally within the “live” directory, and their symlink targets – the actual cert files – are normally found within the “archive” directory.

Variables:
  • cert (str) – The path to the symlink representing the current version of the certificate managed by this lineage.
  • privkey (str) – The path to the symlink representing the current version of the private key managed by this lineage.
  • chain (str) – The path to the symlink representing the current version of the chain managed by this lineage.
  • fullchain (str) – The path to the symlink representing the current version of the fullchain (combined chain and cert) managed by this lineage.
  • configuration (configobj.ConfigObj) – The renewal configuration options associated with this lineage, obtained from parsing the renewal configuration file and/or systemwide defaults.
_consistent()[source]

Are the files associated with this lineage self-consistent?

Returns:Whether the files stored in connection with this lineage appear to be correct and consistent with one another.
Return type:bool
_fix()[source]

Attempt to fix defects or inconsistencies in this lineage.

Todo

Currently unimplemented.

Returns the kind and path of all symlinks used in recovery.

Returns:list of (kind, symlink) tuples
Return type:list

Fixes symlinks in the event of an incomplete version update.

If there is no problem with the current symlinks, this function has no effect.

current_target(kind)[source]

Returns full path to which the specified item currently points.

Parameters:kind (str) – the lineage member item (“cert”, “privkey”, “chain”, or “fullchain”)
Returns:The path to the current version of the specified member.
Return type:str or None
current_version(kind)[source]

Returns numerical version of the specified item.

For example, if kind is “chain” and the current chain link points to a file named “chain7.pem”, returns the integer 7.

Parameters:kind (str) – the lineage member item (“cert”, “privkey”, “chain”, or “fullchain”)
Returns:the current version of the specified member.
Return type:int
version(kind, version)[source]

The filename that corresponds to the specified version and kind.

Warning

The specified version may not exist in this lineage. There is no guarantee that the file path returned by this method actually exists.

Parameters:
  • kind (str) – the lineage member item (“cert”, “privkey”, “chain”, or “fullchain”)
  • version (int) – the desired version
Returns:

The path to the specified version of the specified member.

Return type:

str

available_versions(kind)[source]

Which alternative versions of the specified kind of item exist?

The archive directory where the current version is stored is consulted to obtain the list of alternatives.

Parameters:kind (str) – the lineage member item ( cert, privkey, chain, or fullchain)
Returns:all of the version numbers that currently exist
Return type:list of int
newest_available_version(kind)[source]

Newest available version of the specified kind of item?

Parameters:kind (str) – the lineage member item (cert, privkey, chain, or fullchain)
Returns:the newest available version of this member
Return type:int
latest_common_version()[source]

Newest version for which all items are available?

Returns:the newest available version for which all members (cert, ``privkey, chain, and fullchain) exist
Return type:int
next_free_version()[source]

Smallest version newer than all full or partial versions?

Returns:the smallest version number that is larger than any version of any item currently stored in this lineage
Return type:int
has_pending_deployment()[source]

Is there a later version of all of the managed items?

Returns:True if there is a complete version of this lineage with a larger version number than the current version, and False otherwis
Return type:bool

Make the specified item point at the specified version.

(Note that this method doesn’t verify that the specified version exists.)

Parameters:
  • kind (str) – the lineage member item (“cert”, “privkey”, “chain”, or “fullchain”)
  • version (int) – the desired version

Change all member objects to point to the specified version.

Parameters:version (int) – the desired version
names(version=None)[source]

What are the subject names of this certificate?

(If no version is specified, use the current version.)

Parameters:version (int) – the desired version number
Returns:the subject names
Return type:list of str
Raises .CertStorageError:
 if could not find cert file.
autodeployment_is_enabled()[source]

Is automatic deployment enabled for this cert?

If autodeploy is not specified, defaults to True.

Returns:True if automatic deployment is enabled
Return type:bool
should_autodeploy(interactive=False)[source]

Should this lineage now automatically deploy a newer version?

This is a policy question and does not only depend on whether there is a newer version of the cert. (This considers whether autodeployment is enabled, whether a relevant newer version exists, and whether the time interval for autodeployment has been reached.)

Parameters:interactive (bool) – set to True to examine the question regardless of whether the renewal configuration allows automated deployment (for interactive use). Default False.
Returns:whether the lineage now ought to autodeploy an existing newer cert version
Return type:bool
ocsp_revoked(version=None)[source]

Is the specified cert version revoked according to OCSP?

Also returns True if the cert version is declared as intended to be revoked according to Let’s Encrypt OCSP extensions. (If no version is specified, uses the current version.)

This method is not yet implemented and currently always returns False.

Parameters:version (int) – the desired version number
Returns:whether the certificate is or will be revoked
Return type:bool
autorenewal_is_enabled()[source]

Is automatic renewal enabled for this cert?

If autorenew is not specified, defaults to True.

Returns:True if automatic renewal is enabled
Return type:bool
should_autorenew(interactive=False)[source]

Should we now try to autorenew the most recent cert version?

This is a policy question and does not only depend on whether the cert is expired. (This considers whether autorenewal is enabled, whether the cert is revoked, and whether the time interval for autorenewal has been reached.)

Note that this examines the numerically most recent cert version, not the currently deployed version.

Parameters:interactive (bool) – set to True to examine the question regardless of whether the renewal configuration allows automated renewal (for interactive use). Default False.
Returns:whether an attempt should now be made to autorenew the most current cert version in this lineage
Return type:bool
classmethod new_lineage(lineagename, cert, privkey, chain, renewalparams=None, config=None, cli_config=None)[source]

Create a new certificate lineage.

Attempts to create a certificate lineage – enrolled for potential future renewal – with the (suggested) lineage name lineagename, and the associated cert, privkey, and chain (the associated fullchain will be created automatically). Optional configurator and renewalparams record the configuration that was originally used to obtain this cert, so that it can be reused later during automated renewal.

Returns a new RenewableCert object referring to the created lineage. (The actual lineage name, as well as all the relevant file paths, will be available within this object.)

Parameters:
  • lineagename (str) – the suggested name for this lineage (normally the current cert’s first subject DNS name)
  • cert (str) – the initial certificate version in PEM format
  • privkey (str) – the private key in PEM format
  • chain (str) – the certificate chain in PEM format
  • renewalparams (configobj.ConfigObj) – parameters that should be used when instantiating authenticator and installer objects in the future to attempt to renew this cert or deploy new versions of it
  • config (configobj.ConfigObj) – renewal configuration defaults, affecting, for example, the locations of the directories where the associated files will be saved
  • cli_config (RenewerConfiguration) – parsed command line arguments
Returns:

the newly-created RenewalCert object

Return type:

storage.renewableCert

save_successor(prior_version, new_cert, new_privkey, new_chain)[source]

Save new cert and chain as a successor of a prior version.

Returns the new version number that was created.

Note

this function does NOT update links to deploy this version

Parameters:
  • prior_version (int) – the old version to which this version is regarded as a successor (used to choose a privkey, if the key has not changed, but otherwise this information is not permanently recorded anywhere)
  • new_cert (str) – the new certificate, in PEM format
  • new_privkey (str) – the new private key, in PEM format, or None, if the private key has not changed
  • new_chain (str) – the new chain, in PEM format
Returns:

the new version number that was created

Return type:

int