LDSignature
¶
A class for signing and verifying Linked Data signatures using the RSA signature algorithm.
Attributes:
Name | Type | Description |
---|---|---|
private_key |
RSAPrivateKey
|
The RSA private key used for signing. |
public_key |
RSAPublicKey
|
The corresponding RSA public key. |
Methods:
Name | Description |
---|---|
sign |
dict, creator: str, private_key: rsa.RSAPrivateKey, options: dict = None, created: datetime.datetime = None) -> dict: Signs the provided document using the specified RSA private key. |
verify |
dict, public_key: rsa.RSAPublicKey | str) -> bool: Verifies the signature of the provided document against the given public key. |
Source code in libs/apsig/src/apsig/ld_signature.py
18 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 48 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 |
|
sign(doc, creator, private_key, options=None, created=None)
¶
Signs the provided document using the specified RSA private key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc
|
dict
|
The document to be signed. |
required |
creator
|
str
|
The identifier of the creator of the document. |
required |
private_key
|
RSAPrivateKey
|
The RSA private key used for signing. |
required |
options
|
dict
|
Additional signing options. Defaults to None. |
None
|
created
|
datetime
|
The timestamp when the signature is created. Defaults to the current UTC time if not provided. |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
The signed document containing the original data and the signature. |
Source code in libs/apsig/src/apsig/ld_signature.py
44 45 46 47 48 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 |
|
verify(doc, public_key, raise_on_fail=False)
¶
Verifies the signature of the provided document against the given public key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc
|
dict
|
The signed document to verify. |
required |
public_key
|
RSAPublicKey | str
|
The RSA public key in PEM format or as a multibase-encoded string. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
Union[str, None]
|
True if the signature is valid; otherwise, an exception is raised. |
Raises:
Type | Description |
---|---|
MissingSignature
|
If the signature section is missing in the document. |
UnknownSignature
|
If the signature type is not recognized. |
VerificationFailed
|
If the signature verification fails. |
Source code in libs/apsig/src/apsig/ld_signature.py
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 |
|
draftVerifier
¶
Source code in libs/apsig/src/apsig/draft/verify.py
17 18 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 48 49 |
|
verify(public_pem, method, url, headers, body=b'')
staticmethod
¶
Verifies the digital signature of an HTTP request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
public_pem
|
str
|
The public key in PEM format used to verify the signature. |
required |
method
|
str
|
The HTTP method (e.g., "GET", "POST"). |
required |
url
|
str
|
The URL of the request. |
required |
headers
|
dict
|
A dictionary of HTTP headers, including the signature and other relevant information. |
required |
body
|
bytes
|
The request body. Defaults to an empty byte string. |
b''
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
tuple[bool, str]
|
A tuple containing: - bool: True if the signature is valid, False otherwise. - str: A message indicating the result of the verification. |
Raises:
Type | Description |
---|---|
ValueError
|
If the signature header is missing or if the algorithm is unsupported. |
Source code in libs/apsig/src/apsig/draft/verify.py
18 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 48 49 |
|
draft
¶
Signer
¶
Source code in libs/apsig/src/apsig/draft/sign.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 48 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 |
|
__init__(headers, private_key, method, url, key_id, body=b'')
¶
Signs an HTTP request with a digital signature.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
private_key
|
RSAPrivateKey
|
The RSA private key used to sign the request. |
required |
method
|
str
|
The HTTP method (e.g., "GET", "POST"). |
required |
url
|
str
|
The URL of the request. |
required |
headers
|
dict
|
A dictionary of HTTP headers that will be signed. |
required |
key_id
|
str
|
The key identifier to include in the signature header. |
required |
body
|
bytes
|
The request body. Defaults to an empty byte string. |
b''
|
Returns:
Name | Type | Description |
---|---|---|
dict |
None
|
The HTTP headers with the signature added. |
Raises:
Type | Description |
---|---|
ValueError
|
If the signing process fails due to invalid parameters. |
Source code in libs/apsig/src/apsig/draft/sign.py
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 48 49 50 51 52 53 |
|
Verifier
¶
Source code in libs/apsig/src/apsig/draft/verify.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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
__init__(public_pem, method, url, headers, body=b'')
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
public_pem
|
str
|
The public key in PEM format used to verify the signature. |
required |
method
|
str
|
The HTTP method (e.g., "GET", "POST"). |
required |
url
|
str
|
The URL of the request. |
required |
headers
|
dict
|
A dictionary of HTTP headers, including the signature and other relevant information. |
required |
body
|
bytes
|
The request body. Defaults to an empty byte string. |
b''
|
Source code in libs/apsig/src/apsig/draft/verify.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
verify(raise_on_fail=False)
¶
Verifies the digital signature of an HTTP request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raise_on_fail
|
bool
|
Return error on failure. defaults to False. |
False
|
Returns:
Raises:
Type | Description |
---|---|
ValueError
|
If the signature header is missing or if the algorithm is unsupported. |
Source code in libs/apsig/src/apsig/draft/verify.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 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 |
|
sign
¶
Signer
¶
Source code in libs/apsig/src/apsig/draft/sign.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 48 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 |
|
__init__(headers, private_key, method, url, key_id, body=b'')
¶
Signs an HTTP request with a digital signature.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
private_key
|
RSAPrivateKey
|
The RSA private key used to sign the request. |
required |
method
|
str
|
The HTTP method (e.g., "GET", "POST"). |
required |
url
|
str
|
The URL of the request. |
required |
headers
|
dict
|
A dictionary of HTTP headers that will be signed. |
required |
key_id
|
str
|
The key identifier to include in the signature header. |
required |
body
|
bytes
|
The request body. Defaults to an empty byte string. |
b''
|
Returns:
Name | Type | Description |
---|---|---|
dict |
None
|
The HTTP headers with the signature added. |
Raises:
Type | Description |
---|---|
ValueError
|
If the signing process fails due to invalid parameters. |
Source code in libs/apsig/src/apsig/draft/sign.py
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 48 49 50 51 52 53 |
|
verify
¶
Verifier
¶
Source code in libs/apsig/src/apsig/draft/verify.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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
__init__(public_pem, method, url, headers, body=b'')
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
public_pem
|
str
|
The public key in PEM format used to verify the signature. |
required |
method
|
str
|
The HTTP method (e.g., "GET", "POST"). |
required |
url
|
str
|
The URL of the request. |
required |
headers
|
dict
|
A dictionary of HTTP headers, including the signature and other relevant information. |
required |
body
|
bytes
|
The request body. Defaults to an empty byte string. |
b''
|
Source code in libs/apsig/src/apsig/draft/verify.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
verify(raise_on_fail=False)
¶
Verifies the digital signature of an HTTP request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raise_on_fail
|
bool
|
Return error on failure. defaults to False. |
False
|
Returns:
Raises:
Type | Description |
---|---|
ValueError
|
If the signature header is missing or if the algorithm is unsupported. |
Source code in libs/apsig/src/apsig/draft/verify.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 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 |
|
draftVerifier
¶
Source code in libs/apsig/src/apsig/draft/verify.py
17 18 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 48 49 |
|
verify(public_pem, method, url, headers, body=b'')
staticmethod
¶
Verifies the digital signature of an HTTP request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
public_pem
|
str
|
The public key in PEM format used to verify the signature. |
required |
method
|
str
|
The HTTP method (e.g., "GET", "POST"). |
required |
url
|
str
|
The URL of the request. |
required |
headers
|
dict
|
A dictionary of HTTP headers, including the signature and other relevant information. |
required |
body
|
bytes
|
The request body. Defaults to an empty byte string. |
b''
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
tuple[bool, str]
|
A tuple containing: - bool: True if the signature is valid, False otherwise. - str: A message indicating the result of the verification. |
Raises:
Type | Description |
---|---|
ValueError
|
If the signature header is missing or if the algorithm is unsupported. |
Source code in libs/apsig/src/apsig/draft/verify.py
18 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 48 49 |
|
ld_signature
¶
LDSignature
¶
A class for signing and verifying Linked Data signatures using the RSA signature algorithm.
Attributes:
Name | Type | Description |
---|---|---|
private_key |
RSAPrivateKey
|
The RSA private key used for signing. |
public_key |
RSAPublicKey
|
The corresponding RSA public key. |
Methods:
Name | Description |
---|---|
sign |
dict, creator: str, private_key: rsa.RSAPrivateKey, options: dict = None, created: datetime.datetime = None) -> dict: Signs the provided document using the specified RSA private key. |
verify |
dict, public_key: rsa.RSAPublicKey | str) -> bool: Verifies the signature of the provided document against the given public key. |
Source code in libs/apsig/src/apsig/ld_signature.py
18 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 48 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 |
|
sign(doc, creator, private_key, options=None, created=None)
¶
Signs the provided document using the specified RSA private key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc
|
dict
|
The document to be signed. |
required |
creator
|
str
|
The identifier of the creator of the document. |
required |
private_key
|
RSAPrivateKey
|
The RSA private key used for signing. |
required |
options
|
dict
|
Additional signing options. Defaults to None. |
None
|
created
|
datetime
|
The timestamp when the signature is created. Defaults to the current UTC time if not provided. |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
The signed document containing the original data and the signature. |
Source code in libs/apsig/src/apsig/ld_signature.py
44 45 46 47 48 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 |
|
verify(doc, public_key, raise_on_fail=False)
¶
Verifies the signature of the provided document against the given public key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc
|
dict
|
The signed document to verify. |
required |
public_key
|
RSAPublicKey | str
|
The RSA public key in PEM format or as a multibase-encoded string. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
Union[str, None]
|
True if the signature is valid; otherwise, an exception is raised. |
Raises:
Type | Description |
---|---|
MissingSignature
|
If the signature section is missing in the document. |
UnknownSignature
|
If the signature type is not recognized. |
VerificationFailed
|
If the signature verification fails. |
Source code in libs/apsig/src/apsig/ld_signature.py
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 |
|