-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/truenas/middleware
- Loading branch information
Showing
7 changed files
with
89 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/middlewared/middlewared/api/v25_04_0/crypto_ca_profiles.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from typing import final | ||
|
||
from middlewared.api.base import BaseModel | ||
|
||
__all__ = ("CAProfilesArgs", "CAProfilesModel", "CAProfilesResult") | ||
|
||
# Defines the default lifetime of a certificate | ||
# (https://support.apple.com/en-us/HT211025) | ||
DEFAULT_LIFETIME_DAYS = 397 | ||
|
||
|
||
@final | ||
class KeyUsageModel(BaseModel): | ||
enabled: bool = True | ||
key_cert_sign: bool = True | ||
crl_sign: bool = True | ||
extension_critical: bool = True | ||
|
||
|
||
@final | ||
class BasicConstraintsModel(BaseModel): | ||
enabled: bool = True | ||
ca: bool = True | ||
extension_critical: bool = True | ||
|
||
|
||
@final | ||
class ExtendedKeyUsageModel(BaseModel): | ||
enabled: bool = True | ||
extension_critical: bool = True | ||
usages: list[str] = ["SERVER_AUTH"] | ||
|
||
|
||
@final | ||
class CertExtensionsModel(BaseModel): | ||
KeyUsage: KeyUsageModel = KeyUsageModel() | ||
BasicConstraints: BasicConstraintsModel = BasicConstraintsModel() | ||
ExtentedKeyUsage: ExtendedKeyUsageModel = ExtendedKeyUsageModel() | ||
|
||
|
||
@final | ||
class CAProfilesModel(BaseModel): | ||
key_length: int = 2048 | ||
key_type: str = "RSA" | ||
lifetime: int = DEFAULT_LIFETIME_DAYS | ||
digest_algorithm: str = "SHA256" | ||
cert_extensions: CertExtensionsModel = CertExtensionsModel() | ||
|
||
|
||
class CAProfilesArgs(BaseModel): | ||
pass | ||
|
||
|
||
class CAProfilesResult(BaseModel): | ||
result: CAProfilesModel = CAProfilesModel() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 11 additions & 40 deletions
51
src/middlewared/middlewared/plugins/crypto_/ca_profiles.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,20 @@ | ||
from middlewared.schema import accepts, Dict, returns | ||
from middlewared.api import api_method | ||
from middlewared.api.current import ( | ||
CAProfilesArgs, | ||
CAProfilesModel, | ||
CAProfilesResult, | ||
) | ||
from middlewared.service import Service | ||
|
||
from .utils import DEFAULT_LIFETIME_DAYS | ||
|
||
|
||
class CertificateAuthorityService(Service): | ||
|
||
class Config: | ||
cli_namespace = 'system.certificate.authority' | ||
|
||
PROFILES = { | ||
'CA': { | ||
'key_length': 2048, | ||
'key_type': 'RSA', | ||
'lifetime': DEFAULT_LIFETIME_DAYS, | ||
'digest_algorithm': 'SHA256', | ||
'cert_extensions': { | ||
'KeyUsage': { | ||
'enabled': True, | ||
'key_cert_sign': True, | ||
'crl_sign': True, | ||
'extension_critical': True | ||
}, | ||
'BasicConstraints': { | ||
'enabled': True, | ||
'ca': True, | ||
'extension_critical': True | ||
}, | ||
'ExtendedKeyUsage': { | ||
'enabled': True, | ||
'extension_critical': False, | ||
'usages': ['SERVER_AUTH'] | ||
} | ||
} | ||
} | ||
} | ||
cli_namespace = "system.certificate.authority" | ||
|
||
@accepts(roles=['CERTIFICATE_AUTHORITY_READ']) | ||
@returns(Dict( | ||
'certificate_authority_profiles', | ||
*[Dict(profile, additional_attrs=True) for profile in PROFILES] | ||
)) | ||
@api_method(CAProfilesArgs, CAProfilesResult, roles=["CERTIFICATE_AUTHORITY_READ"]) | ||
async def profiles(self): | ||
""" | ||
Returns a dictionary of predefined options for specific use cases i.e OpenVPN certificate authority | ||
configurations which can be used for creating certificate authorities. | ||
Returns a dictionary of predefined options for | ||
creating certificate authority requests. | ||
""" | ||
return self.PROFILES | ||
return CAProfilesModel().model_dump(by_alias=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters