swarmauri_crypto_paramiko 0.3.0.dev3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,405 @@
1
+ """Paramiko-backed crypto provider with sealing support.
2
+
3
+ Implements the ICrypto contract using:
4
+ - AES-256-GCM for symmetric encrypt/decrypt
5
+ - RSA-OAEP(SHA-256) for:
6
+ • wrapping the session key to many recipients (KEM+AEAD mode)
7
+ • sealing/unsealing (direct public-key encryption of plaintext) for small payloads
8
+
9
+ Notes
10
+ -----
11
+ - This provider expects RSA public keys in OpenSSH format via ``KeyRef.public``.
12
+ - For unwrap/unseal, a PEM-encoded RSA private key is expected in ``KeyRef.material``.
13
+ - Sealing has a size limit: len(plaintext) <= (modulus_bytes - 2*hash_len - 2).
14
+ For larger payloads, use AES-GCM + RSA-OAEP key-wrap (encrypt_for_many with enc_alg="AES-256-GCM").
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import secrets
20
+ from typing import Any, Dict, Iterable, Literal, Optional
21
+ from enum import Enum
22
+
23
+ from cryptography.hazmat.primitives import hashes, serialization
24
+ from cryptography.hazmat.primitives.asymmetric import padding, rsa
25
+ from cryptography.hazmat.primitives.ciphers.aead import AESGCM
26
+
27
+ from swarmauri_core.crypto.types import (
28
+ AEADCiphertext,
29
+ Alg,
30
+ MultiRecipientEnvelope,
31
+ RecipientInfo,
32
+ UnsupportedAlgorithm,
33
+ WrappedKey,
34
+ KeyRef,
35
+ IntegrityError,
36
+ )
37
+
38
+ from swarmauri_base.crypto.CryptoBase import CryptoBase
39
+ from swarmauri_base.ComponentBase import ComponentBase
40
+
41
+
42
+ _SEAL_ALG = "RSA-OAEP-SHA256-SEAL"
43
+ _WRAP_ALG = "RSA-OAEP-SHA256"
44
+ _AEAD_DEFAULT = "AES-256-GCM"
45
+
46
+
47
+ @ComponentBase.register_type(CryptoBase, "ParamikoCrypto")
48
+ class ParamikoCrypto(CryptoBase):
49
+ """Concrete implementation of the ICrypto contract using AES-GCM and RSA-OAEP."""
50
+
51
+ type: Literal["ParamikoCrypto"] = "ParamikoCrypto"
52
+
53
+ def supports(self) -> Dict[str, Iterable[Alg]]:
54
+ return {
55
+ "encrypt": (_AEAD_DEFAULT,),
56
+ "decrypt": (_AEAD_DEFAULT,),
57
+ "wrap": (_WRAP_ALG,),
58
+ "unwrap": (_WRAP_ALG,),
59
+ # NEW:
60
+ "seal": (_SEAL_ALG,),
61
+ "unseal": (_SEAL_ALG,),
62
+ }
63
+
64
+ # ────────────────────────── helpers ──────────────────────────
65
+
66
+ def _normalize_aead_alg(self, alg: Any) -> Alg:
67
+ if isinstance(alg, Enum):
68
+ alg = alg.value
69
+ alg = alg or _AEAD_DEFAULT
70
+ if alg == "AES256_GCM":
71
+ alg = _AEAD_DEFAULT
72
+ return alg
73
+
74
+ @staticmethod
75
+ def _load_rsa_pub_ssh(pub_bytes: bytes):
76
+ return serialization.load_ssh_public_key(pub_bytes)
77
+
78
+ @staticmethod
79
+ def _load_rsa_priv_pem(pem_bytes: bytes):
80
+ return serialization.load_pem_private_key(pem_bytes, password=None)
81
+
82
+ @staticmethod
83
+ def _seal_size_check(pubkey, pt_len: int):
84
+ # RSA OAEP max input: k - 2*hLen - 2
85
+ if not isinstance(pubkey, rsa.RSAPublicKey):
86
+ raise UnsupportedAlgorithm("Sealing requires an RSA public key")
87
+ k = (pubkey.key_size + 7) // 8
88
+ hlen = hashes.SHA256().digest_size
89
+ max_in = k - 2 * hlen - 2
90
+ if pt_len > max_in:
91
+ raise IntegrityError(
92
+ f"Plaintext too large for {_SEAL_ALG}: {pt_len} > {max_in}. "
93
+ f"Use encrypt_for_many(enc_alg='{_AEAD_DEFAULT}') instead."
94
+ )
95
+
96
+ # ────────────────────────── symmetric AEAD ──────────────────────────
97
+
98
+ async def encrypt(
99
+ self,
100
+ key: KeyRef,
101
+ pt: bytes,
102
+ *,
103
+ alg: Optional[Alg] = None,
104
+ aad: Optional[bytes] = None,
105
+ nonce: Optional[bytes] = None,
106
+ ) -> AEADCiphertext:
107
+ alg = self._normalize_aead_alg(alg)
108
+ if alg != _AEAD_DEFAULT:
109
+ raise UnsupportedAlgorithm(f"Unsupported AEAD algorithm: {alg}")
110
+
111
+ if key.material is None:
112
+ raise ValueError(
113
+ "KeyRef.material must contain symmetric key bytes for AEAD"
114
+ )
115
+ if len(key.material) not in (16, 24, 32):
116
+ raise ValueError("KeyRef.material must be 16/24/32 bytes for AES-GCM")
117
+
118
+ nonce = nonce or secrets.token_bytes(12)
119
+ aead = AESGCM(key.material)
120
+ ct_with_tag = aead.encrypt(nonce, pt, aad)
121
+ ct, tag = ct_with_tag[:-16], ct_with_tag[-16:]
122
+ return AEADCiphertext(
123
+ kid=key.kid,
124
+ version=key.version,
125
+ alg=alg,
126
+ nonce=nonce,
127
+ ct=ct,
128
+ tag=tag,
129
+ aad=aad,
130
+ )
131
+
132
+ async def decrypt(
133
+ self,
134
+ key: KeyRef,
135
+ ct: AEADCiphertext,
136
+ *,
137
+ aad: Optional[bytes] = None,
138
+ ) -> bytes:
139
+ if self._normalize_aead_alg(ct.alg) != _AEAD_DEFAULT:
140
+ raise UnsupportedAlgorithm(f"Unsupported AEAD algorithm: {ct.alg}")
141
+ if key.material is None:
142
+ raise ValueError(
143
+ "KeyRef.material must contain symmetric key bytes for AEAD"
144
+ )
145
+
146
+ aead = AESGCM(key.material)
147
+ blob = ct.ct + ct.tag
148
+ return aead.decrypt(ct.nonce, blob, aad or ct.aad)
149
+
150
+ # ─────────────────────────── sealing ───────────────────────────
151
+ # (direct RSA-OAEP of plaintext; for small payloads only)
152
+
153
+ async def seal(
154
+ self,
155
+ recipient: KeyRef,
156
+ pt: bytes,
157
+ *,
158
+ alg: Optional[Alg] = _SEAL_ALG,
159
+ ) -> bytes:
160
+ if alg != _SEAL_ALG:
161
+ raise UnsupportedAlgorithm(f"Unsupported seal alg: {alg}")
162
+ if recipient.public is None:
163
+ raise ValueError("KeyRef.public must contain OpenSSH RSA public key bytes")
164
+
165
+ rsa_pub = self._load_rsa_pub_ssh(recipient.public)
166
+ self._seal_size_check(rsa_pub, len(pt))
167
+
168
+ sealed = rsa_pub.encrypt(
169
+ pt,
170
+ padding.OAEP(
171
+ mgf=padding.MGF1(algorithm=hashes.SHA256()),
172
+ algorithm=hashes.SHA256(),
173
+ label=None,
174
+ ),
175
+ )
176
+ return sealed
177
+
178
+ async def unseal(
179
+ self,
180
+ recipient_priv: KeyRef,
181
+ sealed: bytes,
182
+ *,
183
+ alg: Optional[Alg] = _SEAL_ALG,
184
+ ) -> bytes:
185
+ if alg != _SEAL_ALG:
186
+ raise UnsupportedAlgorithm(f"Unsupported seal alg: {alg}")
187
+ if recipient_priv.material is None:
188
+ raise ValueError(
189
+ "KeyRef.material must contain PEM-encoded RSA private key bytes"
190
+ )
191
+
192
+ priv = self._load_rsa_priv_pem(recipient_priv.material)
193
+ return priv.decrypt(
194
+ sealed,
195
+ padding.OAEP(
196
+ mgf=padding.MGF1(algorithm=hashes.SHA256()),
197
+ algorithm=hashes.SHA256(),
198
+ label=None,
199
+ ),
200
+ )
201
+
202
+ # ───────────── hybrid encrypt-for-many via RSA-OAEP (KEM+AEAD) ─────────────
203
+
204
+ async def encrypt_for_many(
205
+ self,
206
+ recipients: Iterable[KeyRef],
207
+ pt: bytes,
208
+ *,
209
+ enc_alg: Optional[Alg] = None,
210
+ recipient_wrap_alg: Optional[Alg] = None,
211
+ aad: Optional[bytes] = None,
212
+ nonce: Optional[bytes] = None,
213
+ ) -> MultiRecipientEnvelope:
214
+ # 1) Sealed-style variant (per-recipient ciphertext; no shared ct)
215
+ if enc_alg == _SEAL_ALG:
216
+ recip_infos: list[RecipientInfo] = []
217
+ for r in recipients:
218
+ if r.public is None:
219
+ raise ValueError(
220
+ "Recipient KeyRef.public must contain OpenSSH RSA public key bytes"
221
+ )
222
+ rsa_pub = self._load_rsa_pub_ssh(r.public)
223
+ self._seal_size_check(rsa_pub, len(pt))
224
+ sealed = rsa_pub.encrypt(
225
+ pt,
226
+ padding.OAEP(
227
+ mgf=padding.MGF1(algorithm=hashes.SHA256()),
228
+ algorithm=hashes.SHA256(),
229
+ label=None,
230
+ ),
231
+ )
232
+ recip_infos.append(
233
+ RecipientInfo(
234
+ kid=r.kid,
235
+ version=r.version,
236
+ wrap_alg=_SEAL_ALG,
237
+ wrapped_key=sealed,
238
+ nonce=None,
239
+ )
240
+ )
241
+
242
+ # Shared fields empty for sealed variant
243
+ return MultiRecipientEnvelope(
244
+ enc_alg=_SEAL_ALG,
245
+ nonce=b"",
246
+ ct=b"",
247
+ tag=b"",
248
+ recipients=tuple(recip_infos),
249
+ aad=None, # AAD is not bound in RSA-seal mode
250
+ )
251
+
252
+ # 2) Default KEM+AEAD path (shared AES-GCM ct + RSA-wrapped CEK)
253
+ enc_alg = self._normalize_aead_alg(enc_alg)
254
+ if enc_alg != _AEAD_DEFAULT:
255
+ raise UnsupportedAlgorithm(f"Unsupported enc_alg: {enc_alg}")
256
+ wrap_alg = recipient_wrap_alg or _WRAP_ALG
257
+ if wrap_alg != _WRAP_ALG:
258
+ raise UnsupportedAlgorithm(f"Unsupported wrap_alg: {wrap_alg}")
259
+
260
+ k = secrets.token_bytes(32) # 256-bit session key
261
+ iv = nonce or secrets.token_bytes(12)
262
+ aead = AESGCM(k)
263
+ ct_with_tag = aead.encrypt(iv, pt, aad)
264
+ ct, tag = ct_with_tag[:-16], ct_with_tag[-16:]
265
+
266
+ recip_infos: list[RecipientInfo] = []
267
+ for r in recipients:
268
+ if r.public is None:
269
+ raise ValueError(
270
+ "Recipient KeyRef.public must contain OpenSSH RSA public key bytes"
271
+ )
272
+ rsa_pub = self._load_rsa_pub_ssh(r.public)
273
+ enc_k = rsa_pub.encrypt(
274
+ k,
275
+ padding.OAEP(
276
+ mgf=padding.MGF1(algorithm=hashes.SHA256()),
277
+ algorithm=hashes.SHA256(),
278
+ label=None,
279
+ ),
280
+ )
281
+ recip_infos.append(
282
+ RecipientInfo(
283
+ kid=r.kid,
284
+ version=r.version,
285
+ wrap_alg=wrap_alg,
286
+ wrapped_key=enc_k,
287
+ )
288
+ )
289
+
290
+ return MultiRecipientEnvelope(
291
+ enc_alg=enc_alg,
292
+ nonce=iv,
293
+ ct=ct,
294
+ tag=tag,
295
+ recipients=tuple(recip_infos),
296
+ aad=aad,
297
+ )
298
+
299
+ # ────────────────────────── raw RSA wrap/unwrap ─────────────────────
300
+
301
+ async def wrap(
302
+ self,
303
+ kek: KeyRef,
304
+ *,
305
+ dek: Optional[bytes] = None,
306
+ wrap_alg: Optional[Alg] = None,
307
+ nonce: Optional[bytes] = None,
308
+ aad: Optional[bytes] = None,
309
+ ) -> WrappedKey:
310
+ """Wrap a DEK with the given KEK.
311
+
312
+ Supports two modes:
313
+ * RSA-OAEP when ``wrap_alg`` is ``_WRAP_ALG`` (the legacy behaviour)
314
+ * AES-GCM when ``wrap_alg`` matches the default AEAD algorithm. In
315
+ this mode ``kek.material`` must provide the symmetric key bytes and
316
+ a random nonce will be generated when one isn't supplied.
317
+ """
318
+
319
+ wrap_alg = wrap_alg or _WRAP_ALG
320
+ if wrap_alg == _WRAP_ALG:
321
+ if kek.public is None:
322
+ raise ValueError(
323
+ "KeyRef.public must contain OpenSSH RSA public key bytes"
324
+ )
325
+ rsa_pub = self._load_rsa_pub_ssh(kek.public)
326
+ if dek is None:
327
+ dek = secrets.token_bytes(32)
328
+ wrapped = rsa_pub.encrypt(
329
+ dek,
330
+ padding.OAEP(
331
+ mgf=padding.MGF1(algorithm=hashes.SHA256()),
332
+ algorithm=hashes.SHA256(),
333
+ label=None,
334
+ ),
335
+ )
336
+ return WrappedKey(
337
+ kek_kid=kek.kid,
338
+ kek_version=kek.version,
339
+ wrap_alg=wrap_alg,
340
+ nonce=nonce,
341
+ wrapped=wrapped,
342
+ )
343
+
344
+ alg = self._normalize_aead_alg(wrap_alg)
345
+ if alg != _AEAD_DEFAULT:
346
+ raise UnsupportedAlgorithm(f"Unsupported wrap_alg: {wrap_alg}")
347
+ if kek.material is None:
348
+ raise ValueError(
349
+ "KeyRef.material must contain symmetric key bytes for AES-GCM wrap"
350
+ )
351
+ if len(kek.material) not in (16, 24, 32):
352
+ raise ValueError("KeyRef.material must be 16/24/32 bytes for AES-GCM")
353
+ if dek is None:
354
+ dek = secrets.token_bytes(32)
355
+ nonce = nonce or secrets.token_bytes(12)
356
+ aead = AESGCM(kek.material)
357
+ ct_with_tag = aead.encrypt(nonce, dek, aad)
358
+ ct, tag = ct_with_tag[:-16], ct_with_tag[-16:]
359
+ return WrappedKey(
360
+ kek_kid=kek.kid,
361
+ kek_version=kek.version,
362
+ wrap_alg=wrap_alg,
363
+ nonce=nonce,
364
+ wrapped=ct,
365
+ tag=tag,
366
+ )
367
+
368
+ async def unwrap(
369
+ self,
370
+ kek: KeyRef,
371
+ wrapped: WrappedKey,
372
+ *,
373
+ aad: Optional[bytes] = None,
374
+ ) -> bytes:
375
+ """Unwrap a previously wrapped key."""
376
+
377
+ if wrapped.wrap_alg == _WRAP_ALG:
378
+ if kek.material is None:
379
+ raise ValueError(
380
+ "KeyRef.material must contain PEM-encoded RSA private key bytes"
381
+ )
382
+ priv = self._load_rsa_priv_pem(kek.material)
383
+ return priv.decrypt(
384
+ wrapped.wrapped,
385
+ padding.OAEP(
386
+ mgf=padding.MGF1(algorithm=hashes.SHA256()),
387
+ algorithm=hashes.SHA256(),
388
+ label=None,
389
+ ),
390
+ )
391
+
392
+ alg = self._normalize_aead_alg(wrapped.wrap_alg)
393
+ if alg != _AEAD_DEFAULT:
394
+ raise UnsupportedAlgorithm(f"Unsupported wrap_alg: {wrapped.wrap_alg}")
395
+ if kek.material is None:
396
+ raise ValueError(
397
+ "KeyRef.material must contain symmetric key bytes for AES-GCM unwrap"
398
+ )
399
+ if wrapped.nonce is None:
400
+ raise ValueError("WrappedKey.nonce required for AES-GCM unwrap")
401
+ if wrapped.tag is None:
402
+ raise ValueError("WrappedKey.tag required for AES-GCM unwrap")
403
+ aead = AESGCM(kek.material)
404
+ blob = wrapped.wrapped + wrapped.tag
405
+ return aead.decrypt(wrapped.nonce, blob, aad)
@@ -0,0 +1,3 @@
1
+ from .ParamikoCrypto import ParamikoCrypto
2
+
3
+ __all__ = ["ParamikoCrypto"]
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2025] [Jacob Stewart @ Swarmauri]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,118 @@
1
+ Metadata-Version: 2.3
2
+ Name: swarmauri_crypto_paramiko
3
+ Version: 0.3.0.dev3
4
+ Summary: Paramiko-backed RSA + AES-GCM crypto provider for Swarmauri
5
+ License: Apache-2.0
6
+ Author: Swarmauri
7
+ Author-email: opensource@swarmauri.com
8
+ Requires-Python: >=3.10,<3.13
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Natural Language :: English
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Development Status :: 3 - Alpha
16
+ Classifier: Topic :: Security :: Cryptography
17
+ Classifier: Intended Audience :: Developers
18
+ Requires-Dist: cryptography (>=41)
19
+ Requires-Dist: paramiko (>=3.4)
20
+ Requires-Dist: swarmauri_base
21
+ Requires-Dist: swarmauri_core
22
+ Description-Content-Type: text/markdown
23
+
24
+ ![Swamauri Logo](https://res.cloudinary.com/dbjmpekvl/image/upload/v1730099724/Swarmauri-logo-lockup-2048x757_hww01w.png)
25
+
26
+ <p align="center">
27
+ <a href="https://pypi.org/project/swarmauri_crypto_paramiko/">
28
+ <img src="https://img.shields.io/pypi/dm/swarmauri_crypto_paramiko" alt="PyPI - Downloads"/></a>
29
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_crypto_paramiko/">
30
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_crypto_paramiko.svg"/></a>
31
+ <a href="https://pypi.org/project/swarmauri_crypto_paramiko/">
32
+ <img src="https://img.shields.io/pypi/pyversions/swarmauri_crypto_paramiko" alt="PyPI - Python Version"/></a>
33
+ <a href="https://pypi.org/project/swarmauri_crypto_paramiko/">
34
+ <img src="https://img.shields.io/pypi/l/swarmauri_crypto_paramiko" alt="PyPI - License"/></a>
35
+ <a href="https://pypi.org/project/swarmauri_crypto_paramiko/">
36
+ <img src="https://img.shields.io/pypi/v/swarmauri_crypto_paramiko?label=swarmauri_crypto_paramiko&color=green" alt="PyPI - swarmauri_crypto_paramiko"/></a>
37
+ </p>
38
+
39
+ ---
40
+
41
+ ## Swarmauri Crypto Paramiko
42
+
43
+ Paramiko-backed crypto provider implementing the `ICrypto` contract via `CryptoBase`.
44
+
45
+ - AES-256-GCM symmetric encrypt/decrypt
46
+ - RSA-OAEP(SHA-256) wrap/unwrap
47
+ - Multi-recipient hybrid envelopes using OpenSSH public keys
48
+
49
+ ## Installation
50
+
51
+ ```bash
52
+ pip install swarmauri_crypto_paramiko
53
+ ```
54
+
55
+ ## Usage
56
+
57
+ ### Symmetric AEAD Encryption
58
+
59
+ ```python
60
+ from swarmauri_crypto_paramiko import ParamikoCrypto
61
+ from swarmauri_core.crypto.types import KeyRef, KeyType, KeyUse, ExportPolicy
62
+
63
+ crypto = ParamikoCrypto()
64
+
65
+ sym = KeyRef(
66
+ kid="sym1",
67
+ version=1,
68
+ type=KeyType.SYMMETRIC,
69
+ uses=(KeyUse.ENCRYPT, KeyUse.DECRYPT),
70
+ export_policy=ExportPolicy.SECRET_WHEN_ALLOWED,
71
+ material=b"\x00" * 32,
72
+ )
73
+
74
+ ct = await crypto.encrypt(sym, b"hello")
75
+ pt = await crypto.decrypt(sym, ct)
76
+ ```
77
+
78
+ ### RSA Key Wrapping/Unwrapping
79
+
80
+ ```python
81
+ import paramiko
82
+ from cryptography.hazmat.primitives import serialization
83
+ from swarmauri_core.crypto.types import KeyRef, KeyType, KeyUse, ExportPolicy
84
+
85
+ crypto = ParamikoCrypto()
86
+
87
+ key = paramiko.RSAKey.generate(2048)
88
+ pub_line = f"{key.get_name()} {key.get_base64()}\n".encode()
89
+ priv_pem = key.key.private_bytes(
90
+ encoding=serialization.Encoding.PEM,
91
+ format=serialization.PrivateFormat.PKCS8,
92
+ encryption_algorithm=serialization.NoEncryption(),
93
+ )
94
+
95
+ recipient = KeyRef(
96
+ kid="rsa1",
97
+ version=1,
98
+ type=KeyType.RSA,
99
+ uses=(KeyUse.WRAP, KeyUse.UNWRAP),
100
+ export_policy=ExportPolicy.PUBLIC_ONLY,
101
+ public=pub_line,
102
+ material=priv_pem,
103
+ )
104
+
105
+ wrapped = await crypto.wrap(recipient)
106
+ unwrapped = await crypto.unwrap(recipient, wrapped)
107
+ ```
108
+
109
+ ### Hybrid Envelope for Multiple Recipients
110
+
111
+ ```python
112
+ env = await crypto.encrypt_for_many([recipient], b"secret")
113
+ ```
114
+
115
+ ## Entry point
116
+
117
+ The provider is registered under the `swarmauri.cryptos` entry-point as `ParamikoCrypto`.
118
+
@@ -0,0 +1,7 @@
1
+ swarmauri_crypto_paramiko/ParamikoCrypto.py,sha256=6MvCKQXsRK9d0OZjwrWqpsEokPdtv8ljmAaQoZHvcu4,14287
2
+ swarmauri_crypto_paramiko/__init__.py,sha256=SYZFBZCXIQnNkjmA4nmzbNgdRnoKQ9I80NJ9AgPBwfc,73
3
+ swarmauri_crypto_paramiko-0.3.0.dev3.dist-info/LICENSE,sha256=djUXOlCxLVszShEpZXshZ7v33G-2qIC_j9KXpWKZSzQ,11359
4
+ swarmauri_crypto_paramiko-0.3.0.dev3.dist-info/METADATA,sha256=dKbtnQSDUWI7c7JsG0V6AkdrXFGlBpXa3Rhw6QGNsRQ,3866
5
+ swarmauri_crypto_paramiko-0.3.0.dev3.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
6
+ swarmauri_crypto_paramiko-0.3.0.dev3.dist-info/entry_points.txt,sha256=fJd3ojGFXXguIVn5QupZW-tn3v_E6EYYRyottnEE1zs,160
7
+ swarmauri_crypto_paramiko-0.3.0.dev3.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.1.3
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,6 @@
1
+ [peagen.plugins.cryptos]
2
+ paramiko_crypto=swarmauri_crypto_paramiko:ParamikoCrypto
3
+
4
+ [swarmauri.cryptos]
5
+ ParamikoCrypto=swarmauri_crypto_paramiko:ParamikoCrypto
6
+