Is your feature request related to a problem? Please describe.
The current cyrptography is hard coded in SelfKeyCommands, SharedKeyCommands, PublicKeyCommands and both of AtClientImpl's notification handlers. An application cannot supply a different scheme.
NOTE: Metadata.AppMetadata — the field that would carry the cryptography scheme / provider — already exists on trunk but nothing in the repo reads or writes it.
Describe the solution you'd like
A new interface CryptographyProvider which defines 2 methods encrypt/decrypt. This is mirrors CryptoProvider in Dart.
The existing cryptography is moved into an implementation LegacyCryptographyProvider. This mirrors LegacyCryptoProvider in Dart.
RuntimeCryptographyProvider is a implementation with a map of registered implementations keyed by provider ids. It's encrypt/decrypt implementation will delegate to a registered implementation based on the key Metadata.AppMetadata. Where this is not set it will default.
AtClientImpl and the static command method it invokes to execute at server commands will be modified to invoke a CryptographyProvider.
AtClients builder will be modified to pass a RuntimeCryptographyProvider, with LegacyCryptoProvider as the default, to the AtClientImpl it constructs.
Dart mapping
| Dart |
Java |
CryptoProvider (crypto.dart) |
CryptographyProvider (api) |
CryptoProvider.id |
dropped — the id is the registry key, not provider behaviour |
CryptoContext {atClient, atKeysIo} (crypto.dart) |
dropped — (AtCommandExecutor, AtCommandExecutorContext) |
CryptoConfig {defaultProviderId, providers, lookup} (crypto.dart) |
dropped — RuntimeCryptographyProvider's builder |
CryptoConfig.lookup(id) linear scan over a List |
Map<CryptographyProviderId, CryptographyProvider> |
legacyCryptoProviderId = 'legacy' (crypto.dart) |
CryptographyProviderId.LEGACY — same wire literal |
CryptoRuntime (crypto_runtime.dart) |
RuntimeCryptographyProvider (impl.crypto) |
encryptForPut / encryptForNotification |
CryptographyProvider.encrypt |
decryptForGet / decryptForNotification / decryptForSyncConflict |
CryptographyProvider.decrypt |
LegacyCryptoProvider (legacy/legacy_crypto_provider.dart) |
LegacyCryptographyProvider (impl.crypto) |
LegacyEncryption.build / LegacyDecryption.build runtime key sniffing |
private methods per Keys.AtKey subtype |
SelfKeyEncryption / SelfKeyDecryption |
encryptSelfKey / decryptSelfKey |
SharedKeyEncryption / SharedByMeDecryption / SharedWithMeDecryption |
encryptSharedKey / decryptSharedKey |
AbstractAtKeyEncryption (shared-key management) |
the shared-key helpers inside LegacyCryptographyProvider |
AppMetadata.providerId (String, at_commons) |
Metadata.AppMetadata.providerId typed as CryptographyProviderId |
Describe alternatives you've considered
like for like mapping
Additional context
No response
Is your feature request related to a problem? Please describe.
The current cyrptography is hard coded in SelfKeyCommands, SharedKeyCommands, PublicKeyCommands and both of AtClientImpl's notification handlers. An application cannot supply a different scheme.
NOTE: Metadata.AppMetadata — the field that would carry the cryptography scheme / provider — already exists on trunk but nothing in the repo reads or writes it.
Describe the solution you'd like
A new interface CryptographyProvider which defines 2 methods encrypt/decrypt. This is mirrors CryptoProvider in Dart.
The existing cryptography is moved into an implementation LegacyCryptographyProvider. This mirrors LegacyCryptoProvider in Dart.
RuntimeCryptographyProvider is a implementation with a map of registered implementations keyed by provider ids. It's encrypt/decrypt implementation will delegate to a registered implementation based on the key Metadata.AppMetadata. Where this is not set it will default.
AtClientImpl and the static command method it invokes to execute at server commands will be modified to invoke a CryptographyProvider.
AtClients builder will be modified to pass a RuntimeCryptographyProvider, with LegacyCryptoProvider as the default, to the AtClientImpl it constructs.
Dart mapping
CryptoProvider(crypto.dart)CryptographyProvider(api)CryptoProvider.idCryptoContext {atClient, atKeysIo}(crypto.dart)(AtCommandExecutor, AtCommandExecutorContext)CryptoConfig {defaultProviderId, providers, lookup}(crypto.dart)RuntimeCryptographyProvider's builderCryptoConfig.lookup(id)linear scan over aListMap<CryptographyProviderId, CryptographyProvider>legacyCryptoProviderId = 'legacy'(crypto.dart)CryptographyProviderId.LEGACY— same wire literalCryptoRuntime(crypto_runtime.dart)RuntimeCryptographyProvider(impl.crypto)encryptForPut/encryptForNotificationCryptographyProvider.encryptdecryptForGet/decryptForNotification/decryptForSyncConflictCryptographyProvider.decryptLegacyCryptoProvider(legacy/legacy_crypto_provider.dart)LegacyCryptographyProvider(impl.crypto)LegacyEncryption.build/LegacyDecryption.buildruntime key sniffingKeys.AtKeysubtypeSelfKeyEncryption/SelfKeyDecryptionencryptSelfKey/decryptSelfKeySharedKeyEncryption/SharedByMeDecryption/SharedWithMeDecryptionencryptSharedKey/decryptSharedKeyAbstractAtKeyEncryption(shared-key management)LegacyCryptographyProviderAppMetadata.providerId(String, at_commons)Metadata.AppMetadata.providerIdtyped asCryptographyProviderIdDescribe alternatives you've considered
like for like mapping
Additional context
No response