API documentation of security
In this module we define important classes for signing, encryption etc. Please be aware that this module has not yet undergone a security audit and is still in an early version. Any suggestions for improvements will be very welcome.
JWK
Bases: BaseModel
The JSON Web Key (JWK) for Ed25519 as standardized in
https://datatracker.ietf.org/doc/html/rfc8037
Source code in src/sqooler/security.py
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 |
|
to_config_str()
Convert the JWK to a string that can be stored in a config file.
Source code in src/sqooler/security.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
JWSDict
Bases: BaseModel
A JSON Web Signature in a dictionary form. We follow the JWS standard as defined in RFC 7515.
https://datatracker.ietf.org/doc/html/rfc7515
Source code in src/sqooler/security.py
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 |
|
verify_signature(public_jwk)
Verify the integraty of JWS object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
public_jwk |
JWK
|
The public key to use for verification |
required |
Returns:
Type | Description |
---|---|
bool
|
if the signature can be verified |
Source code in src/sqooler/security.py
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 |
|
JWSFlat
Bases: BaseModel
A serialization of a JSON Web Signature in its flat JSON form. We follow the form described in section 3 and exemplified in Annex 7 of RFC 7515. Quite importantly we have no need of the unprotected header.
https://datatracker.ietf.org/doc/html/rfc7515
Source code in src/sqooler/security.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
JWSHeader
Bases: BaseModel
The header of a JWS object
Source code in src/sqooler/security.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
to_base64url()
Convert the header to a base64url encoded string.
Returns:
Name | Type | Description |
---|---|---|
bytes |
bytes
|
The base64url encoded header |
Source code in src/sqooler/security.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
create_jwk_pair(kid)
Create a pair of JWKs designed for signing and verification.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kid |
The key id of the key |
required |
Returns:
Name | Type | Description |
---|---|---|
JWK |
tuple[JWK, JWK]
|
The JWK object |
Source code in src/sqooler/security.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
|
datetime_handler(in_var)
Convert a datetime object to a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_var |
The object to convert |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The string representation of the object |
Source code in src/sqooler/security.py
50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
jwk_from_config_str(jwk_base64_str)
Create a JWK from a string that was stored in a config file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
jwk_base64_str |
The base64 encoded JWK |
required |
Returns:
Name | Type | Description |
---|---|---|
JWK |
JWK
|
The JWK object |
Source code in src/sqooler/security.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
payload_to_base64url(payload)
Convert an arbitrary payload to a base64url encoded string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
payload |
The dictionary to encode |
required |
Returns:
Name | Type | Description |
---|---|---|
bytes |
bytes
|
The base64url encoded header |
Source code in src/sqooler/security.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
public_from_private_jwk(private_jwk)
Create a public JWK from a private JWK.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
private_jwk |
The private JWK |
required |
Returns:
Name | Type | Description |
---|---|---|
JWK |
JWK
|
The public JWK |
Raises:
Type | Description |
---|---|
ValueError
|
If the private key is not intended for signing |
Source code in src/sqooler/security.py
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 |
|
sign_payload(payload, jwk)
Convert a payload to a JWS object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
payload |
The payload to convert |
required | |
jwk |
JWK
|
The private JWK to use for signing |
required |
Returns:
Name | Type | Description |
---|---|---|
JWSDict |
JWSDict
|
The JWS object |
Source code in src/sqooler/security.py
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 |
|