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

fix:signature mistmatch with encrypted data #122

Merged
merged 4 commits into from
Jan 22, 2024
Merged

fix:signature mistmatch with encrypted data #122

merged 4 commits into from
Jan 22, 2024

Conversation

mohitpubnub
Copy link
Contributor

fix: signature mismatch due to encoding difference

Fixes issue of getting signature mismatch exception while publishing encrypted data.

@@ -55,3 +55,6 @@ ${'$body' == 'null' ? '' : '$body'}''';
.replaceAll(RegExp(r'\/'), '_')
.replaceAll(RegExp(r'\=*$'), '');
}

String encodePathSegament(String pathSegment) =>
Uri.encodeFull(pathSegment).replaceAll('/', '%2F').replaceAll('#', '%23');

Choose a reason for hiding this comment

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

I'm just curious, why Uri.encodeFull method doesn't encode the whole path segment? Looks like you have to still replace / with %2F and # with %23

Copy link
Contributor Author

Choose a reason for hiding this comment

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

encodeFull consider / as path segment separation character which is correct.
We may use encodecomponent but It encodes all special characters which doesn't fit our requirement for signature calculation and we may need to reverse by selecting like this:

Uri.encodeComponent(pathSegment).replaceAllMapped(
        RegExp('%3D|%2B|%3A|%2A|%2C|%40|%24|%26|%28|%29'),
        (match) => {
              '%3D': '=',
              '%2B': '+',
              '%3A': ':',
              '%2A': '*',
              '%2C': ',',
              '%40': '@',
              '%24': '\$',
              '%26': '&',
              '%28': '(',
              '%29': ')',
            }[match.group(0)]!);

@mohitpubnub
Copy link
Contributor Author

@pubnub-release-bot release dart as v4.3.2

@mohitpubnub mohitpubnub merged commit 2a5f47e into master Jan 22, 2024
5 checks passed
@mohitpubnub mohitpubnub deleted the CLEN-1781 branch January 22, 2024 09:45
@pubnub-release-bot
Copy link
Contributor

🚀 Release successfully completed 🚀

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.

4 participants