Skip to content

Commit

Permalink
Merge branch 'customizer' into 413-smartphone-as-a-container
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmer committed Jul 29, 2024
2 parents 6e4dc5c + 7b1d078 commit 6e43625
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 113 deletions.
7 changes: 2 additions & 5 deletions lib/model/push_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:convert';

import 'package:base32/base32.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:pi_authenticator_legacy/pi_authenticator_legacy.dart';

import '../utils/globals.dart';
import '../utils/identifiers.dart';
Expand Down Expand Up @@ -144,7 +143,7 @@ class PushRequest {
Logger.debug('Push request data ($data) is valid.', name: 'push_request.dart#verifyData');
}

Future<bool> verifySignature(PushToken token, {LegacyUtils legacyUtils = const LegacyUtils(), RsaUtils rsaUtils = const RsaUtils()}) async {
Future<bool> verifySignature(PushToken token, {RsaUtils rsaUtils = const RsaUtils()}) async {
//5NV6KJCFCLNQURT2ZTBRHHGY6FDXOCOR|http://192.168.178.22:5000/ttype/push|PIPU0000E793|Pick a Number!|privacyIDEA|0|["A", "B", "C"]
Logger.info('Adding push request to token', name: 'push_request_notifier.dart#newRequest');
String signedData = '$nonce|'
Expand All @@ -161,9 +160,7 @@ class PushRequest {
globalRef?.read(tokenProvider.notifier).updateToken(token, (p0) => p0.copyWith(url: uri, sslVerify: sslVerify));
}

bool isVerified = token.privateTokenKey == null
? await legacyUtils.verify(token.serial, signedData, signature)
: rsaUtils.verifyRSASignature(token.rsaPublicServerKey!, utf8.encode(signedData), base32.decode(signature));
bool isVerified = rsaUtils.verifyRSASignature(token.rsaPublicServerKey!, utf8.encode(signedData), base32.decode(signature));

if (!isVerified) {
Logger.warning(
Expand Down
11 changes: 3 additions & 8 deletions lib/utils/push_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import 'package:collection/collection.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:http/http.dart';
import 'package:pi_authenticator_legacy/pi_authenticator_legacy.dart';
import 'package:privacyidea_authenticator/repo/secure_push_request_repository.dart';
import 'package:privacyidea_authenticator/utils/pi_notifications.dart';

Expand Down Expand Up @@ -64,17 +63,15 @@ class PushProvider {
PrivacyideaIOClient get ioClient => _ioClient;
RsaUtils _rsaUtils;
RsaUtils get rsaUtils => _rsaUtils;
LegacyUtils _legacyUtils;


PushProvider._({
FirebaseUtils? firebaseUtils,
PrivacyideaIOClient? ioClient,
RsaUtils? rsaUtils,
LegacyUtils? legacyUtils,
}) : _firebaseUtils = firebaseUtils ?? FirebaseUtils(),
_ioClient = ioClient ?? const PrivacyideaIOClient(),
_rsaUtils = rsaUtils ?? const RsaUtils(),
_legacyUtils = legacyUtils ?? const LegacyUtils() {
_rsaUtils = rsaUtils ?? const RsaUtils() {
_initFirebase();
}

Expand Down Expand Up @@ -236,7 +233,7 @@ class PushProvider {
Logger.warning('No token found for serial ${pushRequest.serial}.', name: 'push_provider.dart#_handleIncomingRequestForeground');
return;
}
if (!await pushRequest.verifySignature(pushToken, rsaUtils: _rsaUtils, legacyUtils: _legacyUtils)) {
if (!await pushRequest.verifySignature(pushToken, rsaUtils: _rsaUtils)) {
Logger.warning('Signature verification failed.', name: 'push_provider.dart#_handleIncomingRequestForeground');
return;
}
Expand Down Expand Up @@ -434,8 +431,6 @@ class PlaceholderPushProvider implements PushProvider {
@override
PrivacyideaIOClient get ioClient => _ioClient;
@override
LegacyUtils _legacyUtils = const LegacyUtils();
@override
RsaUtils _rsaUtils = const RsaUtils();
@override
RsaUtils get rsaUtils => _rsaUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../../../model/enums/app_feature.dart';
import '../../../customization/application_customization.dart';

/// Only used for the app customizer
final applicationCustomizerProvider = StateProvider<ApplicationCustomization>((ref) {
return ApplicationCustomization.defaultCustomization;
return ApplicationCustomization.defaultCustomization.copyWith(disabledFeatures: AppFeature.values.toSet());
});
14 changes: 14 additions & 0 deletions lib/utils/riverpod/state_notifiers/token_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,23 @@ class TokenNotifier extends StateNotifier<TokenState> {
/// There is no need to use mutexes because the updating functions are always using the latest version of the updating tokens.
*/

/// Adds a new token and returns true if successful, false if not.
Future<bool> addNewToken(Token token) async {
final success = await _addOrReplaceToken(token);
await _handlePushTokensIfExist();
return success;
}

/// Adds or replaces a token and returns true if successful, false if not.
Future<bool> addOrReplaceToken(Token token) => _addOrReplaceToken(token);

/// Adds new tokens and returns the tokens that could not be added.
Future<List<Token>> addTokens(List<Token> tokens) async {
final failedTokens = await _addOrReplaceTokens(tokens);
await _handlePushTokensIfExist();
return failedTokens;
}

/// Adds or replaces a list of tokens and returns the tokens that could not be added or replaced.
Future<List<Token>> addOrReplaceTokens(List<Token> tokens) => _addOrReplaceTokens(tokens);

Expand Down
15 changes: 1 addition & 14 deletions lib/utils/rsa_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ import 'dart:convert';
import 'package:asn1lib/asn1lib.dart';
import 'package:base32/base32.dart';
import 'package:flutter/foundation.dart';
import 'package:pi_authenticator_legacy/pi_authenticator_legacy.dart';
import 'package:pointycastle/export.dart';
import 'package:privacyidea_authenticator/utils/globals.dart';

import '../l10n/app_localizations.dart';
import '../model/tokens/push_token.dart';
import '../utils/crypto_utils.dart';
import '../utils/identifiers.dart';
import '../utils/logger.dart';
import 'riverpod/riverpod_providers/state_providers/status_message_provider.dart';

class RsaUtils {
const RsaUtils();
Expand Down Expand Up @@ -220,16 +216,7 @@ class RsaUtils {
if (token.privateTokenKey != null) {
return createBase32Signature(token.rsaPrivateTokenKey!, utf8.encode(message));
}
// It is a legacy token so the operation could cause an exception
try {
return await const LegacyUtils().sign(token.serial, message);
} catch (error) {
final legacySigningErrorTitle = AppLocalizations.of(globalNavigatorKey.currentContext!)!.legacySigningErrorTitle(token.label);
final legacySigningErrorMessage = AppLocalizations.of(globalNavigatorKey.currentContext!)!.legacySigningErrorMessage;
globalRef?.read(statusMessageProvider.notifier).state = (legacySigningErrorTitle, legacySigningErrorMessage);

return null;
}
return null;
}

Future<AsymmetricKeyPair<RSAPublicKey, RSAPrivateKey>> generateRSAKeyPair() async {
Expand Down
1 change: 1 addition & 0 deletions lib/views/import_tokens_view/pages/import_start_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:file_selector/file_selector.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:path_provider/path_provider.dart';
import 'package:zxing2/qrcode.dart';
import 'package:zxing2/zxing2.dart';

import '../../../l10n/app_localizations.dart';
Expand Down
2 changes: 2 additions & 0 deletions lib/views/main_view/main_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../l10n/app_localizations.dart';
import '../../model/states/token_filter.dart';
import '../../utils/globals.dart';
import '../../utils/logger.dart';
import '../../utils/patch_notes_utils.dart';
import '../../utils/riverpod/riverpod_providers/state_notifier_providers/settings_provider.dart';
import '../../utils/riverpod/riverpod_providers/state_providers/token_filter_provider.dart';
Expand Down Expand Up @@ -42,6 +43,7 @@ class _MainViewState extends ConsumerState<MainView> {
void initState() {
super.initState();
final latestStartedVersion = globalRef?.read(settingsProvider).latestStartedVersion;
Logger.info('Latest started version: $latestStartedVersion', name: 'main_view.dart#initState');
if (latestStartedVersion == null || widget.disablePatchNotes) return;
WidgetsBinding.instance.addPostFrameCallback((_) {
PatchNotesUtils.showPatchNotesIfNeeded(context, latestStartedVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@ class _MainViewTokensListState extends ConsumerState<MainViewTokensList> {
),
),
),
],
);
],
);

}


ScrollPhysics _getScrollPhysics(bool allowToRefresh) =>
allowToRefresh ? const AlwaysScrollableScrollPhysics(parent: ClampingScrollPhysics()) : const BouncingScrollPhysics();
}
20 changes: 10 additions & 10 deletions lib/widgets/focused_item_as_overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,14 @@ class _FocusedItemOverlayState extends State<_FocusedItemOverlay> {
}
_disposeOverlay();
final screenSize = (globalRef?.read(appConstraintsProvider) ?? const BoxConstraints()).biggest;
final textScaler = MediaQuery.of(context).textScaler;
if (widget.tooltipWhenFocused != null) {
final textSize = textSizeOf(
text: widget.tooltipWhenFocused!,
style: Theme.of(context).textTheme.bodyLarge!,
maxWidth: MediaQuery.of(context).size.width / 3 * 2 -
maxWidth: screenSize.width / 3 * 2 -
(tooltipPadding.left + tooltipPadding.right + tooltipMargin.left + tooltipMargin.right + tooltipBorderWidth * 2),
textScaler: MediaQuery.of(context).textScaler,
textScaler: textScaler,
);

final overlaySize = Size(
Expand All @@ -167,6 +168,7 @@ class _FocusedItemOverlayState extends State<_FocusedItemOverlay> {
margin: tooltipMargin,
border: tooltipBorderWidth,
textStyle: Theme.of(context).textTheme.bodyLarge!,
onComplete: widget.onComplete,
),
),
);
Expand Down Expand Up @@ -216,20 +218,18 @@ class _FocusedItemOverlayState extends State<_FocusedItemOverlay> {
),
),
Positioned.fill(
child: Tooltip(
message: AppLocalizations.of(context)!.continueButton,
triggerMode: TooltipTriggerMode.longPress,

child: GestureDetector(

onTapDown: (details) {
widget.onComplete?.call();
},
child: Container(
height: double.maxFinite,
width: double.maxFinite,
color: Colors.transparent,
),
child: Text(
AppLocalizations.of(context)!.continueButton,
style: const TextStyle(fontSize: 0),
),
),

),
],
),
Expand Down
16 changes: 12 additions & 4 deletions lib/widgets/tooltip_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ class TooltipContainer extends StatelessWidget {
final EdgeInsets margin;
final double border;
final TextStyle textStyle;
final void Function()? onComplete;
const TooltipContainer(
this.tooltip, {
super.key,
required this.padding,
required this.margin,
required this.border,
required this.textStyle,
required this.onComplete,
});

@override
Expand All @@ -31,10 +33,16 @@ class TooltipContainer extends StatelessWidget {
),
],
),
child: Text(
tooltip,
style: textStyle,
textAlign: TextAlign.center,
child: GestureDetector(
onTapDown: (details) {
onComplete?.call();
},
child: Text(
tooltip,
style: textStyle,
textAlign: TextAlign.center,
),
),

);
}
Loading

0 comments on commit 6e43625

Please sign in to comment.