Certificate Types
Certificate Base Class (cert.FullCert)
A full certificate contains both a certificate and private key.
Source code in certified/cert_base.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
cert_pem
property
Blob: The PEM-encoded certificate for this CA. Add this to your
trust store to trust this CA.
__init__(cert_bytes, private_key_bytes, get_pw=None)
Create from an existing cert and private key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cert_bytes
|
bytes
|
The bytes of the certificate in PEM format |
required |
private_key_bytes
|
bytes
|
The bytes of the private key in PEM format |
required |
get_pw
|
PWCallback
|
get the password used to decrypt the key (if a password was set) |
None
|
Source code in certified/cert_base.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
create_csr()
Generate a CSR.
Source code in certified/cert_base.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
Certificate Authority Class (CA)
Bases: FullCert
CA-s are used only to sign other certificates.
Separating CA-s from the LeafCert-s used to authenticate
TLS participants is required if one wants to use keys
for either signing or key derivation, but not both.
Note that while elliptic curve keys can technically be used for both signing and key exchange, this is considered bad cryptographic practice. Instead, users should generate separate signing and ECDH keys.
Source code in certified/ca.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
__init__(cert_bytes, private_key_bytes, get_pw=None)
Load a CA from an existing cert and private key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cert_bytes
|
bytes
|
The bytes of the certificate in PEM format |
required |
private_key_bytes
|
bytes
|
The bytes of the private key in PEM format |
required |
get_pw
|
PWCallback
|
called to get the password to decrypt the key (if a password was set) |
None
|
Source code in certified/ca.py
61 62 63 64 65 66 67 68 69 70 71 72 | |
configure_trust(ctx)
Configure the given context object to trust certificates signed by this CA.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
SSLContext
|
The SSL context to be modified. |
required |
Source code in certified/ca.py
243 244 245 246 247 248 249 250 251 | |
issue_cert(info, not_before=None, not_after=None, path_length=None)
Issue the certificate described by info.
Do not use this function unless you understand
how the resulting certificate will be used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info
|
CertInfo
|
the certificate |
required |
not_before
|
Optional[datetime]
|
Set the validity start date (notBefore) of the certificate.
This argument type is |
None
|
not_after
|
Optional[datetime]
|
Set the expiry date (notAfter) of the certificate. This
argument type is |
None
|
path_length
|
Optional[int]
|
desired path length (None for end-entity) |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
cert |
Certificate
|
The newly-generated certificate. |
Source code in certified/ca.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
leaf_cert(name, san, not_before=None, not_after=None, key_type='ed25519')
Issues a certificate. The certificate can be used for either servers or clients.
emails, hosts, and uris ultimately end up as "Subject Alternative Names", which are what modern programs are supposed to use when checking identity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Name
|
x509 name (see |
required |
san
|
SubjectAlternativeName
|
subject alternate names -- see encode.SAN |
required |
not_before
|
Optional[datetime]
|
Set the validity start date (notBefore) of the certificate.
This argument type is |
None
|
not_after
|
Optional[datetime]
|
Set the expiry date (notAfter) of the certificate. This
argument type is |
None
|
key_type
|
str
|
Set the type of key that is used for the certificate. By default this is an ed25519 based key. |
'ed25519'
|
Returns:
| Name | Type | Description |
|---|---|---|
LeafCert |
LeafCert
|
the newly-generated certificate. |
Source code in certified/ca.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
new(name, san=None, path_length=0, key_type='ed25519', parent_cert=None)
classmethod
Generate a new CA (root if parent_cert is None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Name
|
the subject of the key |
required |
san
|
Optional[SubjectAlternativeName]
|
the subject alternate name, including domains, emails, and uri-s |
None
|
path_length
|
int
|
max number of child CA-s allowed in a trust chain |
0
|
key_type
|
str
|
cryptographic algorithm for key use |
'ed25519'
|
parent_cert
|
Optional[CA]
|
parent who will sign this CA (None = self-sign) |
None
|
Source code in certified/ca.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
sign_biscuit(builder)
Sign the biscuit being created.
Do not sign biscuits unless you understand
their potential use.
Note: You can use to_base64 on the result to produce a token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
builder
|
BiscuitBuilder
|
the Biscuit just before signing |
required |
Example:
from certified import encode ca = CA.new(encode.person_name("Andrew Jackson")) ca.sign_biscuit(BiscuitBuilder( "user({user_id}); check if time($time), $time < {expiration};", { 'user_id': '1234', 'expiration': datetime.now(tz=timezone.utc) >>> + timedelta(days=1) } ))
Source code in certified/ca.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
End Entity Certificate Class (LeafCert)
Bases: FullCert
A server or client certificate plus private key.
Leaf certificates are used to authenticate parties in a TLS session.
Attributes:
| Name | Type | Description |
|---|---|---|
cert_chain_pems |
list of `Blob` objects
|
The zeroth entry in this list is the actual PEM-encoded certificate, and any entries after that are the rest of the certificate chain needed to reach the root CA. |
private_key_and_cert_chain_pem |
`Blob`
|
A single |
Source code in certified/ca.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
configure_cert(ctx)
Configure the given context object to present this certificate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
SSLContext
|
The SSL context to be modified. |
required |
Source code in certified/ca.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |