certbot-dns-realtimeregister 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,81 @@
1
+ Metadata-Version: 2.4
2
+ Name: certbot-dns-realtimeregister
3
+ Version: 0.1.3
4
+ Summary: Realtime Register DNS Authenticator plugin for Certbot
5
+ Author: PJ
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/PJEilers/certbot-realtimeregister-dns
8
+ Project-URL: Issues, https://github.com/PJEilers/certbot-realtimeregister-dns/issues
9
+ Keywords: certbot,letsencrypt,dns-01,acme,realtimeregister
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Plugins
12
+ Classifier: Intended Audience :: System Administrators
13
+ Classifier: Operating System :: POSIX :: Linux
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Topic :: Internet :: Name Service (DNS)
17
+ Classifier: Topic :: Security
18
+ Classifier: Topic :: System :: Systems Administration
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: certbot>=2.0
23
+ Requires-Dist: requests>=2.20
24
+ Provides-Extra: test
25
+ Requires-Dist: pytest; extra == "test"
26
+ Requires-Dist: requests-mock; extra == "test"
27
+ Dynamic: license-file
28
+
29
+ # certbot-dns-realtimeregister
30
+
31
+ [Certbot](https://certbot.eff.org/) DNS authenticator plugin for
32
+ [Realtime Register](https://www.realtimeregister.com/). It completes `dns-01`
33
+ challenges by adding and then removing `_acme-challenge` TXT records through
34
+ the [Realtime Register API](https://dm.realtimeregister.com/docs/api/), which
35
+ also lets you issue wildcard certificates.
36
+
37
+ ## Installation
38
+
39
+ ```bash
40
+ pip install certbot-dns-realtimeregister # or: pip install -e . from a checkout
41
+ certbot plugins # should list dns-realtimeregister
42
+ ```
43
+
44
+ ## Credentials
45
+
46
+ Create an API key (the user bound to the API key needs the `UPDATE_DNS_ZONE` permission)
47
+ on your profile page in the Realtime Register portal
48
+ (see [Access and Authentication](https://dm.realtimeregister.com/docs/api/access)),
49
+ then copy [`credentials.ini.example`](credentials.ini.example) and fill in your key:
50
+
51
+ ```ini
52
+ dns_realtimeregister_api_key = <your-api-key>
53
+ # Optional, defaults to production (https://api.yoursrs.com).
54
+ # dns_realtimeregister_api_url = https://api.yoursrs-ote.com
55
+ ```
56
+
57
+ ```bash
58
+ chmod 600 ~/.secrets/certbot/realtimeregister.ini
59
+ ```
60
+
61
+ ## Usage
62
+
63
+ ```bash
64
+ certbot certonly \
65
+ --authenticator dns-realtimeregister \
66
+ --dns-realtimeregister-credentials ~/.secrets/certbot/realtimeregister.ini \
67
+ -d example.com -d '*.example.com'
68
+ ```
69
+
70
+ | Option | Description |
71
+ |---|---|
72
+ | `--dns-realtimeregister-credentials` | Path to the credentials INI file (required) |
73
+ | `--dns-realtimeregister-propagation-seconds` | Seconds to wait for DNS propagation (default: 60) |
74
+
75
+ ## Development
76
+
77
+ ```bash
78
+ python3 -m venv .venv
79
+ .venv/bin/pip install -e '.[test]'
80
+ .venv/bin/pytest
81
+ ```
@@ -0,0 +1,53 @@
1
+ # certbot-dns-realtimeregister
2
+
3
+ [Certbot](https://certbot.eff.org/) DNS authenticator plugin for
4
+ [Realtime Register](https://www.realtimeregister.com/). It completes `dns-01`
5
+ challenges by adding and then removing `_acme-challenge` TXT records through
6
+ the [Realtime Register API](https://dm.realtimeregister.com/docs/api/), which
7
+ also lets you issue wildcard certificates.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ pip install certbot-dns-realtimeregister # or: pip install -e . from a checkout
13
+ certbot plugins # should list dns-realtimeregister
14
+ ```
15
+
16
+ ## Credentials
17
+
18
+ Create an API key (the user bound to the API key needs the `UPDATE_DNS_ZONE` permission)
19
+ on your profile page in the Realtime Register portal
20
+ (see [Access and Authentication](https://dm.realtimeregister.com/docs/api/access)),
21
+ then copy [`credentials.ini.example`](credentials.ini.example) and fill in your key:
22
+
23
+ ```ini
24
+ dns_realtimeregister_api_key = <your-api-key>
25
+ # Optional, defaults to production (https://api.yoursrs.com).
26
+ # dns_realtimeregister_api_url = https://api.yoursrs-ote.com
27
+ ```
28
+
29
+ ```bash
30
+ chmod 600 ~/.secrets/certbot/realtimeregister.ini
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ```bash
36
+ certbot certonly \
37
+ --authenticator dns-realtimeregister \
38
+ --dns-realtimeregister-credentials ~/.secrets/certbot/realtimeregister.ini \
39
+ -d example.com -d '*.example.com'
40
+ ```
41
+
42
+ | Option | Description |
43
+ |---|---|
44
+ | `--dns-realtimeregister-credentials` | Path to the credentials INI file (required) |
45
+ | `--dns-realtimeregister-propagation-seconds` | Seconds to wait for DNS propagation (default: 60) |
46
+
47
+ ## Development
48
+
49
+ ```bash
50
+ python3 -m venv .venv
51
+ .venv/bin/pip install -e '.[test]'
52
+ .venv/bin/pytest
53
+ ```
@@ -0,0 +1,47 @@
1
+ """
2
+ The `~certbot-dns-realtimeregister:dns-realtimeregister` plugin automates the
3
+ process of completing a ``dns-01`` challenge (`~acme.challenges.DNS01`) by
4
+ creating, and subsequently removing, TXT records using the Realtime Register API.
5
+
6
+ Named Arguments
7
+ ---------------
8
+
9
+ ========================================== ===================================
10
+ ``--dns-realtimeregister-credentials`` Realtime Register credentials INI
11
+ file. (Required)
12
+ ``--dns-realtimeregister-propagation-seconds`` The number of seconds to wait for
13
+ DNS to propagate before asking the
14
+ ACME server to verify the DNS
15
+ record. (Default: 60)
16
+ ========================================== ===================================
17
+
18
+ Credentials
19
+ -----------
20
+
21
+ Use of this plugin requires an API key, which can be generated on your profile
22
+ page in the Realtime Register portal.
23
+
24
+ .. code-block:: ini
25
+ :name: credentials.ini
26
+ :caption: Example credentials file:
27
+
28
+ # Realtime Register API key
29
+ dns_realtimeregister_api_key = AetWiqG3cMTW57dsPjFRr83R4gALWpVJ89ZE4yJ4FC4=
30
+ # Optional, defaults to production. Use the OT&E environment for testing:
31
+ # dns_realtimeregister_api_url = https://api.yoursrs-ote.com
32
+
33
+ The path to this file can be provided interactively or using the
34
+ ``--dns-realtimeregister-credentials`` command-line argument. Protect it with
35
+ ``chmod 600``; anyone with this key can modify your DNS zones.
36
+
37
+ Examples
38
+ --------
39
+
40
+ .. code-block:: bash
41
+
42
+ certbot certonly \\
43
+ --authenticator dns-realtimeregister \\
44
+ --dns-realtimeregister-credentials ~/.secrets/certbot/realtimeregister.ini \\
45
+ -d example.com \\
46
+ -d '*.example.com'
47
+ """
@@ -0,0 +1 @@
1
+ """Internal implementation of the certbot-dns-realtimeregister plugin."""
@@ -0,0 +1,120 @@
1
+ """Thin client for the Realtime Register DNS zone API."""
2
+ import logging
3
+ from typing import Any, Dict, List, Optional
4
+
5
+ import requests
6
+ from certbot import errors
7
+ from certbot.plugins import dns_common
8
+
9
+ logger = logging.getLogger(__name__)
10
+
11
+ DEFAULT_API_URL = "https://api.yoursrs.com"
12
+ TIMEOUT = 30
13
+
14
+
15
+ class RealtimeRegisterClient:
16
+ """Adds and removes TXT records in Realtime Register DNS zones."""
17
+
18
+ def __init__(self, api_key: str, api_url: Optional[str] = None) -> None:
19
+ self.api_url = (api_url or DEFAULT_API_URL).rstrip("/")
20
+ self.session = requests.Session()
21
+ self.session.headers.update({
22
+ "Authorization": f"ApiKey {api_key}",
23
+ "Content-Type": "application/json",
24
+ "Accept": "application/json",
25
+ })
26
+
27
+ def add_txt_record(self, domain: str, record_name: str, record_content: str,
28
+ record_ttl: int) -> None:
29
+ """Add a TXT record to the zone that contains `domain`.
30
+
31
+ :raises certbot.errors.PluginError: if the zone can't be found or updated
32
+ """
33
+ zone_id = self._find_zone_id(domain)
34
+ records = self._get_records(zone_id)
35
+ if any(self._matches(r, record_name, record_content) for r in records):
36
+ logger.debug("TXT record %s already present in zone %s", record_name, zone_id)
37
+ return
38
+ records.append({
39
+ "name": record_name,
40
+ "type": "TXT",
41
+ "content": record_content,
42
+ "ttl": record_ttl,
43
+ })
44
+ self._update_records(zone_id, records)
45
+ logger.debug("Added TXT record %s to zone %s", record_name, zone_id)
46
+
47
+ def del_txt_record(self, domain: str, record_name: str, record_content: str) -> None:
48
+ """Remove a TXT record from the zone that contains `domain`.
49
+
50
+ Failures are logged rather than raised, since cleanup is best-effort.
51
+ """
52
+ try:
53
+ zone_id = self._find_zone_id(domain)
54
+ records = self._get_records(zone_id)
55
+ remaining = [r for r in records if not self._matches(r, record_name, record_content)]
56
+ if len(remaining) == len(records):
57
+ logger.debug("TXT record %s not found in zone %s", record_name, zone_id)
58
+ return
59
+ self._update_records(zone_id, remaining)
60
+ logger.debug("Removed TXT record %s from zone %s", record_name, zone_id)
61
+ except errors.PluginError as e:
62
+ logger.warning("Encountered error deleting TXT record: %s", e)
63
+
64
+ def _find_zone_id(self, domain: str) -> int:
65
+ for guess in dns_common.base_domain_name_guesses(domain):
66
+ data = self._request("GET", "/v2/dns/zones", params={"name": guess})
67
+ for zone in data.get("entities", []):
68
+ if zone.get("name", "").rstrip(".").lower() == guess.lower():
69
+ logger.debug("Found zone %s (id %s) for %s", guess, zone["id"], domain)
70
+ return zone["id"]
71
+ raise errors.PluginError(
72
+ f"Unable to find a Realtime Register DNS zone for {domain}. "
73
+ "Make sure the zone exists and the API key has access to it.")
74
+
75
+ def _get_records(self, zone_id: int) -> List[Dict[str, Any]]:
76
+ zone = self._request("GET", f"/v2/dns/zones/{zone_id}", params={"fields": "id,records"})
77
+ return [self._clean_record(r) for r in zone.get("records") or []]
78
+
79
+ def _update_records(self, zone_id: int, records: List[Dict[str, Any]]) -> None:
80
+ self._request("POST", f"/v2/dns/zones/{zone_id}/update", json={"records": records})
81
+
82
+ def _request(self, method: str, path: str, **kwargs: Any) -> Dict[str, Any]:
83
+ url = self.api_url + path
84
+ try:
85
+ response = self.session.request(method, url, timeout=TIMEOUT, **kwargs)
86
+ except requests.RequestException as e:
87
+ raise errors.PluginError(f"Error communicating with Realtime Register API: {e}")
88
+ if not response.ok:
89
+ raise errors.PluginError(
90
+ f"Realtime Register API returned {response.status_code} for "
91
+ f"{method} {path}: {self._error_message(response)}")
92
+ if not response.content:
93
+ return {}
94
+ try:
95
+ return response.json()
96
+ except ValueError:
97
+ return {}
98
+
99
+ @staticmethod
100
+ def _error_message(response: requests.Response) -> str:
101
+ try:
102
+ body = response.json()
103
+ except ValueError:
104
+ return response.text or response.reason
105
+ message = body.get("message") or response.reason
106
+ if body.get("type"):
107
+ message = f"{body['type']}: {message}"
108
+ return message
109
+
110
+ @staticmethod
111
+ def _clean_record(record: Dict[str, Any]) -> Dict[str, Any]:
112
+ # Only send fields the update endpoint accepts.
113
+ return {k: record[k] for k in ("name", "type", "content", "ttl", "prio")
114
+ if record.get(k) is not None}
115
+
116
+ @staticmethod
117
+ def _matches(record: Dict[str, Any], name: str, content: str) -> bool:
118
+ return (record.get("type") == "TXT"
119
+ and record.get("name", "").rstrip(".").lower() == name.rstrip(".").lower()
120
+ and record.get("content", "").strip('"') == content)
@@ -0,0 +1,59 @@
1
+ """DNS Authenticator for Realtime Register."""
2
+ import logging
3
+ from typing import Any, Callable, Optional
4
+
5
+ from certbot import errors
6
+ from certbot.plugins import dns_common
7
+ from certbot.plugins.dns_common import CredentialsConfiguration
8
+
9
+ from certbot_dns_realtimeregister._internal.client import RealtimeRegisterClient
10
+
11
+ logger = logging.getLogger(__name__)
12
+
13
+ ACCOUNT_URL = "https://dm.realtimeregister.com/docs/api/access"
14
+
15
+
16
+ class Authenticator(dns_common.DNSAuthenticator):
17
+ """DNS Authenticator for Realtime Register
18
+
19
+ This Authenticator uses the Realtime Register API to fulfill a dns-01 challenge.
20
+ """
21
+
22
+ description = ("Obtain certificates using a DNS TXT record (if you are using "
23
+ "Realtime Register for DNS).")
24
+ ttl = 60
25
+
26
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
27
+ super().__init__(*args, **kwargs)
28
+ self.credentials: Optional[CredentialsConfiguration] = None
29
+
30
+ @classmethod
31
+ def add_parser_arguments(cls, add: Callable[..., None],
32
+ default_propagation_seconds: int = 60) -> None:
33
+ super().add_parser_arguments(add, default_propagation_seconds)
34
+ add("credentials", help="Realtime Register credentials INI file.")
35
+
36
+ def more_info(self) -> str:
37
+ return ("This plugin configures a DNS TXT record to respond to a dns-01 "
38
+ "challenge using the Realtime Register API.")
39
+
40
+ def _setup_credentials(self) -> None:
41
+ self.credentials = self._configure_credentials(
42
+ "credentials",
43
+ "Realtime Register credentials INI file",
44
+ {"api-key": f"API key for the Realtime Register API, see {ACCOUNT_URL}"},
45
+ )
46
+
47
+ def _perform(self, domain: str, validation_name: str, validation: str) -> None:
48
+ self._get_client().add_txt_record(domain, validation_name, validation, self.ttl)
49
+
50
+ def _cleanup(self, domain: str, validation_name: str, validation: str) -> None:
51
+ self._get_client().del_txt_record(domain, validation_name, validation)
52
+
53
+ def _get_client(self) -> RealtimeRegisterClient:
54
+ if not self.credentials: # pragma: no cover
55
+ raise errors.Error("Plugin has not been prepared.")
56
+ return RealtimeRegisterClient(
57
+ self.credentials.conf("api-key"),
58
+ self.credentials.conf("api-url"),
59
+ )
@@ -0,0 +1,81 @@
1
+ Metadata-Version: 2.4
2
+ Name: certbot-dns-realtimeregister
3
+ Version: 0.1.3
4
+ Summary: Realtime Register DNS Authenticator plugin for Certbot
5
+ Author: PJ
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/PJEilers/certbot-realtimeregister-dns
8
+ Project-URL: Issues, https://github.com/PJEilers/certbot-realtimeregister-dns/issues
9
+ Keywords: certbot,letsencrypt,dns-01,acme,realtimeregister
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Plugins
12
+ Classifier: Intended Audience :: System Administrators
13
+ Classifier: Operating System :: POSIX :: Linux
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Topic :: Internet :: Name Service (DNS)
17
+ Classifier: Topic :: Security
18
+ Classifier: Topic :: System :: Systems Administration
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: certbot>=2.0
23
+ Requires-Dist: requests>=2.20
24
+ Provides-Extra: test
25
+ Requires-Dist: pytest; extra == "test"
26
+ Requires-Dist: requests-mock; extra == "test"
27
+ Dynamic: license-file
28
+
29
+ # certbot-dns-realtimeregister
30
+
31
+ [Certbot](https://certbot.eff.org/) DNS authenticator plugin for
32
+ [Realtime Register](https://www.realtimeregister.com/). It completes `dns-01`
33
+ challenges by adding and then removing `_acme-challenge` TXT records through
34
+ the [Realtime Register API](https://dm.realtimeregister.com/docs/api/), which
35
+ also lets you issue wildcard certificates.
36
+
37
+ ## Installation
38
+
39
+ ```bash
40
+ pip install certbot-dns-realtimeregister # or: pip install -e . from a checkout
41
+ certbot plugins # should list dns-realtimeregister
42
+ ```
43
+
44
+ ## Credentials
45
+
46
+ Create an API key (the user bound to the API key needs the `UPDATE_DNS_ZONE` permission)
47
+ on your profile page in the Realtime Register portal
48
+ (see [Access and Authentication](https://dm.realtimeregister.com/docs/api/access)),
49
+ then copy [`credentials.ini.example`](credentials.ini.example) and fill in your key:
50
+
51
+ ```ini
52
+ dns_realtimeregister_api_key = <your-api-key>
53
+ # Optional, defaults to production (https://api.yoursrs.com).
54
+ # dns_realtimeregister_api_url = https://api.yoursrs-ote.com
55
+ ```
56
+
57
+ ```bash
58
+ chmod 600 ~/.secrets/certbot/realtimeregister.ini
59
+ ```
60
+
61
+ ## Usage
62
+
63
+ ```bash
64
+ certbot certonly \
65
+ --authenticator dns-realtimeregister \
66
+ --dns-realtimeregister-credentials ~/.secrets/certbot/realtimeregister.ini \
67
+ -d example.com -d '*.example.com'
68
+ ```
69
+
70
+ | Option | Description |
71
+ |---|---|
72
+ | `--dns-realtimeregister-credentials` | Path to the credentials INI file (required) |
73
+ | `--dns-realtimeregister-propagation-seconds` | Seconds to wait for DNS propagation (default: 60) |
74
+
75
+ ## Development
76
+
77
+ ```bash
78
+ python3 -m venv .venv
79
+ .venv/bin/pip install -e '.[test]'
80
+ .venv/bin/pytest
81
+ ```
@@ -0,0 +1,15 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ certbot_dns_realtimeregister/__init__.py
5
+ certbot_dns_realtimeregister.egg-info/PKG-INFO
6
+ certbot_dns_realtimeregister.egg-info/SOURCES.txt
7
+ certbot_dns_realtimeregister.egg-info/dependency_links.txt
8
+ certbot_dns_realtimeregister.egg-info/entry_points.txt
9
+ certbot_dns_realtimeregister.egg-info/requires.txt
10
+ certbot_dns_realtimeregister.egg-info/top_level.txt
11
+ certbot_dns_realtimeregister/_internal/__init__.py
12
+ certbot_dns_realtimeregister/_internal/client.py
13
+ certbot_dns_realtimeregister/_internal/dns_realtimeregister.py
14
+ tests/test_client.py
15
+ tests/test_dns_realtimeregister.py
@@ -0,0 +1,2 @@
1
+ [certbot.plugins]
2
+ dns-realtimeregister = certbot_dns_realtimeregister._internal.dns_realtimeregister:Authenticator
@@ -0,0 +1,6 @@
1
+ certbot>=2.0
2
+ requests>=2.20
3
+
4
+ [test]
5
+ pytest
6
+ requests-mock
@@ -0,0 +1,42 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "certbot-dns-realtimeregister"
7
+ version = "0.1.3"
8
+ description = "Realtime Register DNS Authenticator plugin for Certbot"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "PJ" }]
14
+ keywords = ["certbot", "letsencrypt", "dns-01", "acme", "realtimeregister"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Environment :: Plugins",
18
+ "Intended Audience :: System Administrators",
19
+ "Operating System :: POSIX :: Linux",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
22
+ "Topic :: Internet :: Name Service (DNS)",
23
+ "Topic :: Security",
24
+ "Topic :: System :: Systems Administration",
25
+ ]
26
+ dependencies = [
27
+ "certbot>=2.0",
28
+ "requests>=2.20",
29
+ ]
30
+
31
+ [project.urls]
32
+ Homepage = "https://github.com/PJEilers/certbot-realtimeregister-dns"
33
+ Issues = "https://github.com/PJEilers/certbot-realtimeregister-dns/issues"
34
+
35
+ [project.optional-dependencies]
36
+ test = ["pytest", "requests-mock"]
37
+
38
+ [project.entry-points."certbot.plugins"]
39
+ dns-realtimeregister = "certbot_dns_realtimeregister._internal.dns_realtimeregister:Authenticator"
40
+
41
+ [tool.setuptools.packages.find]
42
+ include = ["certbot_dns_realtimeregister*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,86 @@
1
+ """Tests for certbot_dns_realtimeregister._internal.client."""
2
+ import pytest
3
+ import requests_mock
4
+ from certbot import errors
5
+
6
+ from certbot_dns_realtimeregister._internal.client import RealtimeRegisterClient
7
+
8
+ API = "https://api.example.test"
9
+ ZONE_ID = 42
10
+ NAME = "_acme-challenge.example.com"
11
+ TOKEN = "validation-token"
12
+ EXISTING = {"name": "www.example.com", "type": "A", "content": "192.0.2.1", "ttl": 3600}
13
+
14
+
15
+ @pytest.fixture
16
+ def client():
17
+ return RealtimeRegisterClient("key", API)
18
+
19
+
20
+ @pytest.fixture
21
+ def api():
22
+ with requests_mock.Mocker() as m:
23
+ m.get(f"{API}/v2/dns/zones", json={"entities": []})
24
+ m.get(f"{API}/v2/dns/zones?name=example.com",
25
+ json={"entities": [{"id": ZONE_ID, "name": "example.com"}]})
26
+ m.post(f"{API}/v2/dns/zones/{ZONE_ID}/update", status_code=200)
27
+ yield m
28
+
29
+
30
+ def zone(*records):
31
+ return {"id": ZONE_ID, "records": list(records)}
32
+
33
+
34
+ def posted_records(api):
35
+ return [r.json() for r in api.request_history if r.method == "POST"][-1]["records"]
36
+
37
+
38
+ def test_add_sends_auth_and_appends_record(client, api):
39
+ api.get(f"{API}/v2/dns/zones/{ZONE_ID}", json=zone(EXISTING))
40
+
41
+ client.add_txt_record("sub.example.com", NAME, TOKEN, 60)
42
+
43
+ assert api.request_history[0].headers["Authorization"] == "ApiKey key"
44
+ assert posted_records(api) == [
45
+ EXISTING,
46
+ {"name": NAME, "type": "TXT", "content": TOKEN, "ttl": 60},
47
+ ]
48
+
49
+
50
+ def test_add_skips_duplicate(client, api):
51
+ api.get(f"{API}/v2/dns/zones/{ZONE_ID}",
52
+ json=zone({"name": NAME, "type": "TXT", "content": f'"{TOKEN}"', "ttl": 60}))
53
+
54
+ client.add_txt_record("example.com", NAME, TOKEN, 60)
55
+
56
+ assert not any(r.method == "POST" for r in api.request_history)
57
+
58
+
59
+ def test_add_zone_not_found(client, api):
60
+ with pytest.raises(errors.PluginError, match="Unable to find"):
61
+ client.add_txt_record("example.org", "_acme-challenge.example.org", TOKEN, 60)
62
+
63
+
64
+ def test_add_api_error(client, api):
65
+ api.get(f"{API}/v2/dns/zones/{ZONE_ID}", json=zone())
66
+ api.post(f"{API}/v2/dns/zones/{ZONE_ID}/update", status_code=400,
67
+ json={"type": "DnsConfigurationException", "message": "bad record"})
68
+
69
+ with pytest.raises(errors.PluginError, match="DnsConfigurationException: bad record"):
70
+ client.add_txt_record("example.com", NAME, TOKEN, 60)
71
+
72
+
73
+ def test_del_removes_only_matching_record(client, api):
74
+ other = {"name": NAME, "type": "TXT", "content": "other-token", "ttl": 60}
75
+ api.get(f"{API}/v2/dns/zones/{ZONE_ID}",
76
+ json=zone(EXISTING, other, {"name": NAME, "type": "TXT", "content": TOKEN, "ttl": 60}))
77
+
78
+ client.del_txt_record("example.com", NAME, TOKEN)
79
+
80
+ assert posted_records(api) == [EXISTING, other]
81
+
82
+
83
+ def test_del_swallows_errors(client, api):
84
+ api.get(f"{API}/v2/dns/zones/{ZONE_ID}", status_code=500, text="boom")
85
+
86
+ client.del_txt_record("example.com", NAME, TOKEN) # does not raise
@@ -0,0 +1,48 @@
1
+ """Tests for certbot_dns_realtimeregister._internal.dns_realtimeregister."""
2
+ import sys
3
+ import unittest
4
+ from unittest import mock
5
+
6
+ import pytest
7
+ from certbot.compat import os
8
+ from certbot.plugins import dns_test_common
9
+ from certbot.plugins.dns_test_common import DOMAIN
10
+ from certbot.tests import util as test_util
11
+
12
+ API_KEY = "an-api-key"
13
+
14
+
15
+ class AuthenticatorTest(test_util.TempDirTestCase, dns_test_common.BaseAuthenticatorTest):
16
+
17
+ def setUp(self):
18
+ from certbot_dns_realtimeregister._internal.dns_realtimeregister import Authenticator
19
+
20
+ super().setUp()
21
+
22
+ path = os.path.join(self.tempdir, "file.ini")
23
+ dns_test_common.write({"realtimeregister_api_key": API_KEY}, path)
24
+
25
+ self.config = mock.MagicMock(realtimeregister_credentials=path,
26
+ realtimeregister_propagation_seconds=0)
27
+ self.auth = Authenticator(self.config, "realtimeregister")
28
+
29
+ self.mock_client = mock.MagicMock()
30
+ self.auth._get_client = mock.MagicMock(return_value=self.mock_client)
31
+
32
+ @test_util.patch_display_util()
33
+ def test_perform(self, unused_mock_get_utility):
34
+ self.auth.perform([self.achall])
35
+
36
+ expected = [mock.call.add_txt_record(DOMAIN, "_acme-challenge." + DOMAIN, mock.ANY, mock.ANY)]
37
+ assert expected == self.mock_client.mock_calls
38
+
39
+ def test_cleanup(self):
40
+ self.auth._attempt_cleanup = True
41
+ self.auth.cleanup([self.achall])
42
+
43
+ expected = [mock.call.del_txt_record(DOMAIN, "_acme-challenge." + DOMAIN, mock.ANY)]
44
+ assert expected == self.mock_client.mock_calls
45
+
46
+
47
+ if __name__ == "__main__":
48
+ sys.exit(pytest.main(sys.argv[1:] + [__file__])) # pragma: no cover