|
1 |
| -# -*- coding: UTF-8 -*- |
2 |
| -# |
3 |
| -# Copyright 2019-2023 Flávio Gonçalves Garcia |
| 1 | +# Copyright 2019-2025 Flavio Garcia |
4 | 2 | # Copyright 2016-2017 Veeti Paananen under MIT License
|
5 | 3 | #
|
6 | 4 | # Licensed under the Apache License, Version 2.0 (the "License");
|
|
28 | 26 | with warnings.catch_warnings():
|
29 | 27 | warnings.simplefilter("ignore")
|
30 | 28 | from cryptography import x509
|
31 |
| -from cryptography.x509 import NameOID, DNSName, SubjectAlternativeName |
| 29 | +from cryptography.x509 import NameOID, DNSName |
32 | 30 | from cryptography.hazmat.backends import default_backend
|
33 | 31 | from cryptography.hazmat.primitives.asymmetric import padding
|
34 | 32 | from cryptography.hazmat.primitives.asymmetric.rsa import (
|
@@ -90,6 +88,13 @@ def certbot_key_data_to_int(key_data: dict) -> dict:
|
90 | 88 | return key_data_int
|
91 | 89 |
|
92 | 90 |
|
| 91 | +def generate_ari_data(cert): |
| 92 | + aki_b64 = base64.urlsafe_b64encode(get_certificate_aki(cert).encode()) |
| 93 | + serial_b64 = base64.urlsafe_b64encode( |
| 94 | + get_certificate_serial(cert).encode()) |
| 95 | + return f"{aki_b64}.{serial_b64}" |
| 96 | + |
| 97 | + |
93 | 98 | def generate_header(account_key):
|
94 | 99 | """
|
95 | 100 | Creates a new request header for the specified account key.
|
@@ -234,6 +239,18 @@ def get_issuer_certificate_domain_name(cert):
|
234 | 239 | return cn.value
|
235 | 240 |
|
236 | 241 |
|
| 242 | +def get_certificate_aki(cert): |
| 243 | + for ext in cert.extensions: |
| 244 | + if isinstance(ext.value, x509.AuthorityKeyIdentifier): |
| 245 | + hex = ext.value.key_identifier.hex() |
| 246 | + return ":".join(hex[i:i+2] for i in range(0, len(hex), 2)) |
| 247 | + |
| 248 | + |
| 249 | +def get_certificate_serial(cert): |
| 250 | + hex = format(cert.serial_number, "x") |
| 251 | + return ":".join(hex[i:i+2] for i in range(0, len(hex), 2)) |
| 252 | + |
| 253 | + |
237 | 254 | def get_certificate_domain_name(cert):
|
238 | 255 | for ext in cert.extensions:
|
239 | 256 | if isinstance(ext.value, x509.SubjectAlternativeName):
|
|
0 commit comments