]>
git.siccegge.de Git - tooling/letool.git/blob - bin/newhost
2 # -*- coding: utf-8 -*-
3 # (C) Christoph Egger <christoph@christoph-egger.org>
5 from __future__
import print_function
10 from acme
import client
12 from acme
import messages
14 from cryptography
.hazmat
.backends
import default_backend
15 from cryptography
.hazmat
.primitives
.asymmetric
import rsa
16 from cryptography
.hazmat
.primitives
import serialization
18 from sicceggetools
.acme
import constants
21 logging
.getLogger().setLevel(logging
.INFO
)
23 if not os
.path
.exists("data"):
24 logging
.info("Creating data directory")
26 os
.chmod("data", 0700)
29 if not os
.path
.exists("data/account.key.pem"):
30 logging
.info("Creating account key")
31 private_key
= rsa
.generate_private_key(
32 public_exponent
=65537,
33 key_size
=constants
.KEY_SIZE
,
34 backend
=default_backend()
37 pem
= private_key
.private_bytes(
38 encoding
=serialization
.Encoding
.PEM
,
39 format
=serialization
.PrivateFormat
.TraditionalOpenSSL
,
40 encryption_algorithm
=serialization
.NoEncryption()
43 with
open("data/account.key.pem", "wb") as keyfd
:
46 logging
.info("Loading account key")
47 with
open("data/account.key.pem", "rb") as keyfd
:
48 private_key
= serialization
.load_pem_private_key(
51 backend
=default_backend()
54 if not os
.path
.exists("data/registration.json"):
55 logging
.info("registering")
56 acmeclient
= client
.Client(constants
.DIRECTORY_URL
, jose
.JWKRSA(key
=private_key
))
57 registration
= messages
.NewRegistration(contact
=constants
.CONTACT
)
58 registration
= acmeclient
.register(registration
)
59 registration
= acmeclient
.agree_to_tos(registration
)
61 with
open("data/registration.json", "wb") as regfd
:
62 regfd
.write(registration
.json_dumps_pretty())