From f93fe09783892d895e376bb4f32c88bece729beb Mon Sep 17 00:00:00 2001 From: xmflsct Date: Wed, 11 Jan 2023 21:01:44 +0100 Subject: [PATCH] Fix push wrong auth key format --- package.json | 1 + src/components/Instance/index.tsx | 4 +++- src/screens/Tabs/Me/Push.tsx | 13 +++++++++++-- yarn.lock | 13 +++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 36c637e7..6f896f9a 100644 --- a/package.json +++ b/package.json @@ -81,6 +81,7 @@ "react-native-language-detection": "^0.2.2", "react-native-mmkv": "^2.5.1", "react-native-pager-view": "^6.1.2", + "react-native-quick-base64": "^2.0.5", "react-native-reanimated": "^2.13.0", "react-native-reanimated-zoom": "^0.3.3", "react-native-safe-area-context": "^4.4.1", diff --git a/src/components/Instance/index.tsx b/src/components/Instance/index.tsx index 2826c8bb..39718ce0 100644 --- a/src/components/Instance/index.tsx +++ b/src/components/Instance/index.tsx @@ -19,12 +19,14 @@ import { import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' import * as AuthSession from 'expo-auth-session' +import * as Random from 'expo-random' import * as WebBrowser from 'expo-web-browser' import { debounce } from 'lodash' import React, { RefObject, useCallback, useState } from 'react' import { Trans, useTranslation } from 'react-i18next' import { Alert, Image, KeyboardAvoidingView, Platform, TextInput, View } from 'react-native' import { ScrollView } from 'react-native-gesture-handler' +import { fromByteArray } from 'react-native-quick-base64' import parse from 'url-parse' import CustomText from '../Text' @@ -158,7 +160,7 @@ const ComponentInstance: React.FC = ({ 'admin.sign_up': false, 'admin.report': false }, - key: Math.random().toString(36).slice(2, 12) + key: fromByteArray(Random.getRandomBytes(16)) }, page_local: { showBoosts: true, diff --git a/src/screens/Tabs/Me/Push.tsx b/src/screens/Tabs/Me/Push.tsx index a62f1c06..09c512bf 100644 --- a/src/screens/Tabs/Me/Push.tsx +++ b/src/screens/Tabs/Me/Push.tsx @@ -17,10 +17,12 @@ import { StyleConstants } from '@utils/styles/constants' import layoutAnimation from '@utils/styles/layoutAnimation' import { useTheme } from '@utils/styles/ThemeManager' import * as Notifications from 'expo-notifications' +import * as Random from 'expo-random' import * as WebBrowser from 'expo-web-browser' import React, { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { AppState, Linking, Platform, ScrollView, View } from 'react-native' +import { fromByteArray } from 'react-native-quick-base64' const TabMePush: React.FC = () => { const { colors } = useTheme() @@ -178,6 +180,11 @@ const TabMePush: React.FC = () => { setAccountStorage([{ key: 'push', value: { ...push, global: false } }]) } else { + // Fix a bug for some users of v4.8.0 + let authKey = push.key + if (push.key.length <= 10) { + authKey = fromByteArray(Random.getRandomBytes(16)) + } // Turning on const randomPath = (Math.random() + 1).toString(36).substring(2) @@ -189,7 +196,7 @@ const TabMePush: React.FC = () => { 'subscription[keys][p256dh]', 'BMn2PLpZrMefG981elzG6SB1EY9gU7QZwmtZ/a/J2vUeWG+zXgeskMPwHh4T/bxsD4l7/8QT94F57CbZqYRRfJo=' ) - formData.append('subscription[keys][auth]', push.key) + formData.append('subscription[keys][auth]', authKey) for (const [key, value] of Object.entries(push.alerts)) { formData.append(`data[alerts][${key}]`, value.toString()) } @@ -225,7 +232,9 @@ const TabMePush: React.FC = () => { } }) - setAccountStorage([{ key: 'push', value: { ...push, global: true } }]) + setAccountStorage([ + { key: 'push', value: { ...push, global: true, key: authKey } } + ]) if (Platform.OS === 'android') { setChannels(true) diff --git a/yarn.lock b/yarn.lock index 9e39eadf..ef1812a4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9718,6 +9718,18 @@ __metadata: languageName: node linkType: hard +"react-native-quick-base64@npm:^2.0.5": + version: 2.0.5 + resolution: "react-native-quick-base64@npm:2.0.5" + dependencies: + base64-js: ^1.5.1 + peerDependencies: + react: "*" + react-native: "*" + checksum: 964599ad68d54dd741357850c72b4a5e08f247fa294590f18866896662107b734b6810703fdd972560cee8087095f14f06fc6ef69944c59c41dbbd885a7832bb + languageName: node + linkType: hard + "react-native-reanimated-zoom@npm:^0.3.3": version: 0.3.3 resolution: "react-native-reanimated-zoom@npm:0.3.3" @@ -11412,6 +11424,7 @@ __metadata: react-native-language-detection: ^0.2.2 react-native-mmkv: ^2.5.1 react-native-pager-view: ^6.1.2 + react-native-quick-base64: ^2.0.5 react-native-reanimated: ^2.13.0 react-native-reanimated-zoom: ^0.3.3 react-native-safe-area-context: ^4.4.1