Skip to content

Commit

Permalink
Merge branch 'refs/heads/trunk' into deprecate_messagetype_enum_text
Browse files Browse the repository at this point in the history
  • Loading branch information
srieteja committed May 14, 2024
2 parents 0d727f3 + 1e4e8c1 commit eae5494
Show file tree
Hide file tree
Showing 30 changed files with 219 additions and 69 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/at_libraries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ jobs:
- at_contact
- at_server_status
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5

- uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 # v1.6.4
with:
sdk: stable

- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: 'stable'
cache-dependency-path: tools/osv-scanner/go.sum
Expand Down Expand Up @@ -66,13 +66,13 @@ jobs:
- at_commons
- at_utils
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5

- uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 # v1.6.4
with:
sdk: stable

- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: 'stable'
cache-dependency-path: tools/osv-scanner/go.sum
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
- at_onboarding_cli_functional_tests

steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5

- uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 # v1.6.4
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1
with:
egress-policy: audit

- name: 'Checkout Repository'
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- name: 'Dependency Review'
uses: actions/dependency-review-action@5bbc3ba658137598168acb2ab73b21c432dd411b # v4.2.5
uses: actions/dependency-review-action@0c155c5e8556a497adf53f2c18edabf945ed8e70 # v4.3.2
2 changes: 1 addition & 1 deletion .github/workflows/melos_bootstrap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
melos-bootstrap:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1 # v2.16.0
with:
channel: "stable"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ jobs:

steps:
- name: "Checkout code"
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
with:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1
uses: ossf/scorecard-action@dc50aa9510b46c811795eb24b2f1ba02a914e534 # v2.3.3
with:
results_file: results.sarif
results_format: sarif
Expand All @@ -59,7 +59,7 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: SARIF file
path: results.sarif
Expand Down
2 changes: 2 additions & 0 deletions packages/at_auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 2.0.3
- fix: Add optional parameters to the "atAuth" method in "AtAuthInterface"
## 2.0.2
- fix: set default value for app name and device name if they are not passed in the onboarding request.
## 2.0.1
Expand Down
2 changes: 0 additions & 2 deletions packages/at_auth/example/authenticate.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:io';

import 'package:args/args.dart';
import 'package:at_auth/at_auth.dart';
import 'package:at_auth/src/at_auth_impl.dart';
Expand Down
1 change: 0 additions & 1 deletion packages/at_auth/example/enrollment_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ void main(List<String> args) async {
help: 'root server domain',
mandatory: false,
defaultsTo: 'root.atsign.org');
;
final argResults = parser.parse(args);
AtLookUp atLookUp =
AtLookupImpl(argResults['atsign'], argResults['rootDomain'], 64);
Expand Down
12 changes: 11 additions & 1 deletion packages/at_auth/lib/src/auth_interface.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import 'package:at_auth/at_auth.dart';
import 'package:at_auth/src/auth/pkam_authenticator.dart';
import 'package:at_chops/at_chops.dart';
import 'package:at_lookup/at_lookup.dart';

import 'auth/cram_authenticator.dart';

/// This abstract class defines the interface for authentication and enrollment
/// with an @protocol server.
Expand All @@ -15,5 +20,10 @@ abstract class AtAuthInterface {
/// This method facilitates the authentication process.
///
/// Returns an instance of [AtAuth].
AtAuth atAuth();
AtAuth atAuth(
{AtLookUp? atLookUp,
AtChops? atChops,
CramAuthenticator? cramAuthenticator,
PkamAuthenticator? pkamAuthenticator,
AtEnrollmentBase? atEnrollmentBase});
}
2 changes: 1 addition & 1 deletion packages/at_auth/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: at_auth
description: Package that implements common logic for onboarding/authenticating an atsign to a secondary server
version: 2.0.2
version: 2.0.3
homepage: https://atsign.com/
repository: https://github.com/atsign-foundation/at_libraries

Expand Down
18 changes: 18 additions & 0 deletions packages/at_cli_commons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
## 1.1.0

- feat: Add `maxConnectAttempts` parameter to CLIBase. The default is 20,
i.e. 20 attempts to connect, with a 3-second delay between attempts. When
used in scripts this is important, as the previous behaviour (retry
forever) is usually not what is required.

## 1.0.5

- fix: Make CLIBase write progress messages to stderr, not stdout

## 1.0.4

- fix: handle malformed atsigns (no leading `@`) in CLIBase constructor
- build: updated dependencies

## 1.0.3

- Added `example/` package, moved code samples from `bin/` to `example/`

## 1.0.2

- docs: Added some code samples in bin/ directory
- docs: Added some class and method documentation to CLIBase
- docs: Updated README
- feat: Added static `fromCommandLineArgs` factory method to CLIBase

## 1.0.1

- Small edits to README

## 1.0.0

- Initial version.
62 changes: 40 additions & 22 deletions packages/at_cli_commons/lib/src/cli_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:logging/logging.dart';
import 'package:version/version.dart';

class CLIBase {
static const defaultMaxConnectAttempts = 20;
/// An ArgParser which has all of the options and flags required by [CLIBase]
/// Used by [fromCommandLineArgs] if the `parser` parameter isn't supplied.
static final ArgParser argsParser = ArgParser()
Expand All @@ -35,7 +36,11 @@ class CLIBase {
help: 'Root Domain',
defaultsTo: 'root.atsign.org')
..addFlag('verbose', abbr: 'v', negatable: false, help: 'More logging')
..addFlag('never-sync', negatable: false, help: 'Do not run sync');
..addFlag('never-sync', negatable: false, help: 'Do not run sync')
..addOption('max-connect-attempts',
help: 'Number of times to attempt to initially connect to atServer.'
' Note: there is a 3-second delay between connection attempts.',
defaultsTo: defaultMaxConnectAttempts.toString());

/// Constructs a CLIBase from a list of command-line arguments
/// and calls [init] on it.
Expand All @@ -61,15 +66,17 @@ class CLIBase {
}

CLIBase cliBase = CLIBase(
atSign: parsedArgs['atsign'],
atKeysFilePath: parsedArgs['key-file'],
nameSpace: parsedArgs['namespace'],
rootDomain: parsedArgs['root-domain'],
homeDir: getHomeDirectory(),
storageDir: parsedArgs['storage-dir'],
verbose: parsedArgs['verbose'],
cramSecret: parsedArgs['cram-secret'],
syncDisabled: parsedArgs['never-sync']);
atSign: parsedArgs['atsign'],
atKeysFilePath: parsedArgs['key-file'],
nameSpace: parsedArgs['namespace'],
rootDomain: parsedArgs['root-domain'],
homeDir: getHomeDirectory(),
storageDir: parsedArgs['storage-dir'],
verbose: parsedArgs['verbose'],
cramSecret: parsedArgs['cram-secret'],
syncDisabled: parsedArgs['never-sync'],
maxConnectAttempts: int.parse(parsedArgs['max-connect-attempts']),
);

await cliBase.init();

Expand All @@ -85,6 +92,7 @@ class CLIBase {
final String? downloadDir;
final String? cramSecret;
final bool syncDisabled;
final int maxConnectAttempts;

late final String atKeysFilePathToUse;
late final String localStoragePathToUse;
Expand All @@ -111,17 +119,19 @@ class CLIBase {
/// cliBase.logger.logger.level = Level.FINEST;
/// ```
/// Throws an [IllegalArgumentException] if the parameters fail validation.
CLIBase(
{required String atSign,
required this.nameSpace,
required this.rootDomain,
this.homeDir,
this.verbose = false,
this.atKeysFilePath,
this.storageDir,
this.downloadDir,
this.cramSecret,
this.syncDisabled = false}) {
CLIBase({
required String atSign,
required this.nameSpace,
required this.rootDomain,
this.homeDir,
this.verbose = false,
this.atKeysFilePath,
this.storageDir,
this.downloadDir,
this.cramSecret,
this.syncDisabled = false,
this.maxConnectAttempts = defaultMaxConnectAttempts,
}) {
this.atSign = AtUtils.fixAtSign(atSign);
if (homeDir == null) {
if (atKeysFilePath == null) {
Expand Down Expand Up @@ -188,9 +198,11 @@ class CLIBase {

bool authenticated = false;
Duration retryDuration = Duration(seconds: 3);
while (!authenticated) {
int attempts = 0;
while (!authenticated && attempts < maxConnectAttempts) {
try {
stderr.write(chalk.brightBlue('\r\x1b[KConnecting ... '));
attempts++;
await Future.delayed(Duration(
milliseconds:
1000)); // Pause just long enough for the retry to be visible
Expand All @@ -203,6 +215,12 @@ class CLIBase {
await Future.delayed(retryDuration);
}
}
if (!authenticated) {
stderr.writeln();
var msg = 'Failed to connect after $attempts attempts';
stderr.writeln(chalk.brightRed(msg));
throw SecondaryServerConnectivityException(msg);
}
stderr.writeln(chalk.brightGreen('Connected'));

// Get the AtClient which the onboardingService just authenticated
Expand Down
2 changes: 1 addition & 1 deletion packages/at_cli_commons/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: at_cli_commons
description: Library of useful stuff when building cli programs which use the AtClient SDK
version: 1.0.5
version: 1.1.0

repository: https://github.com/atsign-foundation/at_libraries/tree/trunk/packages/at_cli_commons
homepage: https://docs.atsign.com/
Expand Down
6 changes: 6 additions & 0 deletions packages/at_commons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 4.0.9
- feat: enroll verb syntax change for enroll:revoke:force and added new exception AtEnrollmentRevokeException
## 4.0.8
- fix: Add shared_key.atsign@atsign to reservedKey regex
## 4.0.7
- fix: Add fetch operation to enroll verb to get the enrollment details
## 4.0.6
- fix: max key length validation changes
- fix: PublicKey toString method should return 'cached:' when isCached is set in metadata
Expand Down
5 changes: 5 additions & 0 deletions packages/at_commons/lib/src/exception/at_exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ class AtInvalidEnrollmentException extends AtException {
AtInvalidEnrollmentException(message) : super(message);
}

/// Exception thrown when a client tries to revoke its own enrollment
class AtEnrollmentRevokeException extends AtEnrollmentException {
AtEnrollmentRevokeException(message) : super(message);
}

/// Exception thrown when the enrollment requests exceed the limit
/// in the given time window
class AtThrottleLimitExceeded extends AtException {
Expand Down
4 changes: 3 additions & 1 deletion packages/at_commons/lib/src/exception/error_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const Map error_codes = {
'ServerIsPausedException': 'AT0024',
'AtThrottleLimitException': 'AT0028',
'AtInvalidEnrollmentException': 'AT0029',
'AtEnrollmentRevokeException': 'AT0031'
};

// ignore: constant_identifier_names
Expand Down Expand Up @@ -53,5 +54,6 @@ const Map error_description = {
'AT0027': 'Apkam Access Revoked',
'AT0028': 'Too Many Requests',
'AT0029': 'Apkam Enrollment Expired',
'AT0030': 'Invalid Enrollment Status'
'AT0030': 'Invalid Enrollment Status',
'AT0031': 'Cannot revoke self enrollment'
};
26 changes: 20 additions & 6 deletions packages/at_commons/lib/src/utils/at_key_regex_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,23 @@ abstract class Regexes {

/// The following reserved keys are suffixed by the atsign. [ownershipFragment]
/// at the end represents the atsign
static const _reservedKeysWithAtsignSuffix = r'(((?<=private:)blocklist'
static const _reservedKeysWithAtsignSuffix = r'('
'('
'(?<=private:)'
'blocklist'
'|(?<=public:)signing_publickey'
'|(?<=$ownershipFragmentWithoutNamedGroup:)signing_privatekey'
'|(?<=^@($sharedWithFragment))shared_key'
'|(?<=public:)publickey)(?=$ownershipFragment))';

static const String namespaceFragment =
'''\\.(?<namespace>$charsInNamespace)''';
'|(?<=public:)publickey'
'|(shared_key\\.$ownershipFragmentWithoutAtPrefix)'
')(?=$ownershipFragment)'
')';

static const String namespaceFragment = '\\.(?<namespace>$charsInNamespace)';
static const String ownershipFragmentWithoutAtPrefix =
'(($charsInAtSign|$allowedEmoji){1,55})';
static const String ownershipFragment =
'''@(?<owner>($charsInAtSign|$allowedEmoji){1,55})''';
'@(?<owner>$ownershipFragmentWithoutAtPrefix)';
static const String ownershipFragmentWithoutNamedGroup =
'''@($charsInAtSign|$allowedEmoji){1,55}''';
static const String sharedWithFragment =
Expand All @@ -56,12 +63,19 @@ abstract class Regexes {
'''(?<visibility>(local:){1})$entityFragment''';

String get publicKey;

String get privateKey;

String get selfKey;

String get sharedKey;

String get cachedSharedKey;

String get cachedPublicKey;

String get reservedKey;

String get localKey;

static final Regexes _regexesWithMandatoryNamespace =
Expand Down
2 changes: 1 addition & 1 deletion packages/at_commons/lib/src/verb/operation_enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum MessageTypeEnum { key, @Deprecated('text based notification are deprecated'
String getMessageType(MessageTypeEnum? messageTypeEnum) =>
'$messageTypeEnum'.split('.').last;

enum EnrollOperationEnum { request, approve, deny, revoke, list, update }
enum EnrollOperationEnum { request, approve, deny, revoke, list, update, fetch }

String getEnrollOperation(EnrollOperationEnum? enrollOperationEnum) =>
'$enrollOperationEnum'.split('.').last;
Loading

0 comments on commit eae5494

Please sign in to comment.