Skip to content

Commit a6ac408

Browse files
committed
feat(OCM): Implement ISigneCloudFederationProvider for deck
When an app recieves OCM notifications, core needs to be able to resolve the remote seerver that sent the notification so that it can verify the signature of the notification. This patch implements the ISignedCloudFederationProvider interface for the deck app, so that this can happen. Signed-off-by: Micke Nordin <kano@sunet.se>
1 parent 69d1b2d commit a6ac408

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

.php-cs-fixer.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"php":"8.4.24","version":"3.95.3","indent":"\t","lineEnding":"\n","rules":{"encoding":true,"full_opening_tag":true,"blank_line_after_namespace":true,"braces_position":{"allow_single_line_anonymous_functions":false},"class_definition":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"function_declaration":{"closure_function_spacing":"one"},"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ignore"},"modifier_keywords":{"elements":["property","method","const"]},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_after_imports":true,"single_space_around_construct":{"constructs_followed_by_a_single_space":["abstract","as","case","catch","class","do","else","elseif","final","for","foreach","function","if","interface","namespace","private","protected","public","static","switch","trait","try","use_lambda","while"],"constructs_preceded_by_a_single_space":["as","else","elseif","use_lambda"]},"spaces_inside_parentheses":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"align_multiline_comment":true,"array_indentation":true,"array_syntax":true,"binary_operator_spaces":{"default":"single_space"},"blank_line_after_opening_tag":true,"blank_lines_before_namespace":{"min_line_breaks":2,"max_line_breaks":2},"cast_spaces":{"space":"none"},"concat_space":{"spacing":"one"},"curly_braces_position":{"classes_opening_brace":"same_line","functions_opening_brace":"same_line"},"list_syntax":true,"lowercase_cast":true,"method_chaining_indentation":true,"no_extra_blank_lines":{"tokens":["attribute","extra","parenthesis_brace_block","return","square_brace_block","switch","throw","use","use_trait"]},"no_leading_import_slash":true,"no_short_bool_cast":true,"no_spaces_inside_parenthesis":true,"no_unused_imports":true,"no_whitespace_in_blank_line":true,"nullable_type_declaration_for_default_null_value":true,"nullable_type_declaration":{"syntax":"question_mark"},"operator_linebreak":{"position":"beginning"},"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"alpha"},"phpdoc_align":{"align":"left"},"phpdoc_single_line_var_spacing":true,"phpdoc_var_annotation_correct_order":true,"short_scalar_cast":true,"single_quote":{"strings_containing_single_quote_chars":false},"trailing_comma_in_multiline":{"elements":["parameters"]},"types_spaces":{"space":"none","space_multiple_catch":"none"},"type_declaration_spaces":{"elements":["function","property"]},"yoda_style":{"equal":false,"identical":false,"less_and_greater":false},"PhpCsFixerCustomFixers\/multiline_promoted_properties":true},"ruleCustomisationPolicyVersion":"null-policy","hashes":{"lib\/Db\/.conform.3651280.BoardMapper.php":"6d2f08ea9a6d1a9a39a5a4904a1ffd8a"}}

lib/Db/BoardMapper.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,22 @@ public function findByExternalId(int $externalId): array {
145145
return $this->findEntities($qb);
146146
}
147147

148+
/**
149+
* Used by ISignedCloudFederationProvider to resolve a board from a share token.
150+
*
151+
* @param string $shareToken
152+
* @return Board
153+
* @throws DoesNotExistException
154+
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
155+
*/
156+
public function findByShareToken(string $shareToken): Board {
157+
$qb = $this->db->getQueryBuilder();
158+
$qb->select('*')
159+
->from('deck_boards')
160+
->where($qb->expr()->eq('share_token', $qb->createNamedParameter($shareToken, IQueryBuilder::PARAM_STR)));
161+
return $this->findEntity($qb);
162+
}
163+
148164
public function findAllForUser(string $userId, ?int $since = null, bool $includeArchived = true, ?int $before = null,
149165
?string $term = null): array {
150166
$useCache = ($since === -1 && $includeArchived === true && $before === null && $term === null);

lib/Federation/DeckFederationProvider.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
use OCA\Deck\Db\BoardMapper;
1515
use OCA\Deck\Db\ChangeHelper;
1616
use OCA\Deck\Service\ConfigService;
17+
use OCP\AppFramework\Db\DoesNotExistException;
18+
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
1719
use OCP\Common\Exception\NotFoundException;
18-
use OCP\Federation\ICloudFederationProvider;
1920
use OCP\Federation\ICloudFederationShare;
2021
use OCP\Federation\ICloudIdManager;
22+
use OCP\Federation\ISignedCloudFederationProvider;
2123
use OCP\Notification\IManager as INotificationManager;
2224

23-
class DeckFederationProvider implements ICloudFederationProvider {
25+
class DeckFederationProvider implements ISignedCloudFederationProvider {
2426
public const PROVIDER_ID = 'deck';
2527

2628
public function __construct(
@@ -106,4 +108,13 @@ public function notificationReceived($notificationType, $providerId, $notificati
106108
public function getSupportedShareTypes(): array {
107109
return ['user'];
108110
}
111+
112+
#[\Override]
113+
public function getFederationIdFromSharedSecret(#[\SensitiveParameter] string $sharedSecret, array $payload): string {
114+
try {
115+
return $this->boardMapper->findByShareToken($sharedSecret)->getOwner();
116+
} catch (DoesNotExistException|MultipleObjectsReturnedException) {
117+
return '';
118+
}
119+
}
109120
}

0 commit comments

Comments
 (0)