(
path: Path, basename: str, key_size: int, organization=None, cn=None
)
| 561 | |
| 562 | @staticmethod |
| 563 | def create_store( |
| 564 | path: Path, basename: str, key_size: int, organization=None, cn=None |
| 565 | ) -> None: |
| 566 | path.mkdir(parents=True, exist_ok=True) |
| 567 | |
| 568 | organization = organization or basename |
| 569 | cn = cn or basename |
| 570 | |
| 571 | key: rsa.RSAPrivateKeyWithSerialization |
| 572 | ca: x509.Certificate |
| 573 | key, ca = create_ca(organization=organization, cn=cn, key_size=key_size) |
| 574 | |
| 575 | # Dump the CA plus private key. |
| 576 | with CertStore.umask_secret(): |
| 577 | # PEM format |
| 578 | (path / f"{basename}-ca.pem").write_bytes( |
| 579 | key.private_bytes( |
| 580 | encoding=serialization.Encoding.PEM, |
| 581 | format=serialization.PrivateFormat.TraditionalOpenSSL, |
| 582 | encryption_algorithm=serialization.NoEncryption(), |
| 583 | ) |
| 584 | + ca.public_bytes(serialization.Encoding.PEM) |
| 585 | ) |
| 586 | |
| 587 | # PKCS12 format for Windows devices |
| 588 | (path / f"{basename}-ca.p12").write_bytes( |
| 589 | pkcs12.serialize_key_and_certificates( # type: ignore |
| 590 | name=basename.encode(), |
| 591 | key=key, |
| 592 | cert=ca, |
| 593 | cas=None, |
| 594 | encryption_algorithm=serialization.NoEncryption(), |
| 595 | ) |
| 596 | ) |
| 597 | |
| 598 | # Dump the certificate in PEM format |
| 599 | pem_cert = ca.public_bytes(serialization.Encoding.PEM) |
| 600 | (path / f"{basename}-ca-cert.pem").write_bytes(pem_cert) |
| 601 | # Create a .cer file with the same contents for Android |
| 602 | (path / f"{basename}-ca-cert.cer").write_bytes(pem_cert) |
| 603 | |
| 604 | # Dump the certificate in PKCS12 format for Windows devices |
| 605 | (path / f"{basename}-ca-cert.p12").write_bytes( |
| 606 | pkcs12.serialize_key_and_certificates( |
| 607 | name=basename.encode(), |
| 608 | key=None, # type: ignore |
| 609 | cert=ca, |
| 610 | cas=None, |
| 611 | encryption_algorithm=serialization.NoEncryption(), |
| 612 | ) |
| 613 | ) |
| 614 | |
| 615 | (path / f"{basename}-dhparam.pem").write_bytes(DEFAULT_DHPARAM) |
| 616 | |
| 617 | def add_cert_file( |
| 618 | self, spec: str, path: Path, passphrase: bytes | None = None |
no test coverage detected