Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking!: Reorganize atchops #770

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open

Conversation

XavierChanth
Copy link
Member

- What I did

Breaking:

  • Removed AtEncryptionKeyPair and AtPkamKeyPair in favor of the abstract AtSymmetricKeyPair
    (although breaking, today it only requires an additional cast in some places from AtSymmetricKeyPair to AtRSAKeyPair?)
    However, this future proofs the API in preparation for supporting different key types / algos for pkam and shared encryption, it is actually the other parts of the API that need to be adapted which will element the need for the cast
  • Corrected type naming inconsistencies (breaking)

Non-breaking:

  • split algorithms directory into encryption,signing,hashing,padding
  • moved all at_platform specific stuff into at_platform directory
  • Modified keys stored in classes to decode to raw bytes on construction so we don't decode every time we do an operation
  • Added constructor / getters for the keys so that they offer both raw bytes & base64 as options, preserving backward compatibility on the interfaces.

- How I did it

- How to verify it

- Description for the changelog
breaking!: Reorganize atchops

@@ -36,7 +37,8 @@ void main(List<String> args) async {
atChops = AtChopsImpl(atChopsKeys);
}

var atEncryptionKeyPair = atChops.atChopsKeys.atEncryptionKeyPair;
var atEncryptionKeyPair =
atChops.atChopsKeys.atEncryptionKeyPair as AtRSAKeyPair?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of the place we need the cast, atChopsKeys has been generalized

@@ -1,34 +1,16 @@
library at_chops;
// export cryptography wrappers
export 'src/hashing/hashing.dart';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added files named after the directories in src to make export management easier.

@@ -65,7 +66,7 @@ class _AtKeysCryptoImpl implements AtKeysCrypto {
String hashKey =
await _getHashKey(passPhrase, _hashingAlgoType, hashParams: hashParams);

AESKey aesKey = AESKey(hashKey);
AtAESKey aesKey = AtAESKey(hashKey);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed to prevent namespace collisions with other packages.


AtChopsKeys get atChopsKeys => _atChopsKeys;
const AtChops.init();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constructor does nothing, it only exists to allow the class to be extended.


/// Default self encryption key
SymmetricKey? selfEncryptionKey;

/// APKAM symmetric key created during new enrollment
SymmetricKey? apkamSymmetricKey;

/// EnrollmentId associated with pkam keys
String? enrollmentId;
Copy link
Member Author

@XavierChanth XavierChanth Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added enrollmentId so that AtAuthKeys in at_auth can be casted to and from AtChopsKeys (without losing information).

/// These parameters are particularly useful when working with algorithms
/// like Argon2id, which can be adjusted for performance and security needs.

class ArgonHashParams extends HashParams {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from a separate file to be with it's hashing algorithm implementation


class HashParams {}

class DefaultHashingAlgo extends Md5HashingAlgo {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've taken all the DefaultXXXAlgo and named them after their proper algorithm, then extended each of them to become the new DefaultAlgo. They still all conform to the same interface.

import 'dart:typed_data';

/// Represents a key pair for asymmetric public-private key encryption/decryption
abstract class AsymmetricKeyPair<Pub extends AtPublicKey,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AsymmetricKeyPairs can now be flavored with covariants of AtPublicKey and AtPrivateKey. Non breaking change, as they still conform to the same interface.

final String _aesKey;
class AtAESKey extends SymmetricKey {
@override
final Uint8List raw;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed so that the stored member is the raw bytes rather than the base64 encoded string. This should reduce decrypt/encrypt latency as we don't need to decode every time now.

@@ -1 +1,11 @@
enum EncryptionKeyType { rsa2048, rsa4096, ecc, aes128, aes192, aes256 }
enum EncryptionKeyType {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be a blocker later...

Sometimes we want to infer an algo, but when we infer from a runtimeType we don't always have the key size, nor care about the key size.

But also, when we get the algo used to encrypt / sign from a string, it's useful to have the algo. It's questionable whether it's useful to have the size. Maybe we need to make this a sealed class later, but, then it's not open to extension...

@XavierChanth XavierChanth requested review from gkc and removed request for gkc February 18, 2025 21:29
@XavierChanth
Copy link
Member Author

Setting back to draft, more work to be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant