protected override async Task <string> ExecuteAsync() { //if (!TextSecurePreferences.isPushRegistered()) return; int availableKeys = await App.Current.accountManager.getPreKeysCount(); if (availableKeys >= PREKEY_MINIMUM && TextSecurePreferences.isSignedPreKeyRegistered()) { Debug.WriteLine("Available keys sufficient: " + availableKeys); return(""); } List <PreKeyRecord> preKeyRecords = await PreKeyUtil.generatePreKeys(/*context, masterSecret*/); PreKeyRecord lastResortKeyRecord = await PreKeyUtil.generateLastResortKey(/*context, masterSecret*/); IdentityKeyPair identityKey = IdentityKeyUtil.GetIdentityKeyPair(/*context, masterSecret*/); SignedPreKeyRecord signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(/*context, masterSecret, */ identityKey); Debug.WriteLine("Registering new prekeys..."); await App.Current.accountManager.setPreKeys(identityKey.getPublicKey(), lastResortKeyRecord, signedPreKeyRecord, preKeyRecords); TextSecurePreferences.setSignedPreKeyRegistered(true); //App.Current.Worker.AddTaskActivities(new CleanPreKeysTask()); return(""); }
private async Task <bool> handleRegistration(string receivedSmsVerificationCode) { try { var registrationId = KeyHelper.generateRegistrationId(false); TextSecurePreferences.setLocalRegistrationId((int)registrationId); await App.Current.accountManager.verifyAccountWithCode(receivedSmsVerificationCode, signalingKey, registrationId, false); //await PushHelper.getInstance().OpenChannelAndUpload(); // also updates push channel id Recipient self = DatabaseFactory.getRecipientDatabase().GetSelfRecipient(number); IdentityKeyUtil.generateIdentityKeys(); IdentityKeyPair identityKey = IdentityKeyUtil.GetIdentityKeyPair(); List <PreKeyRecord> records = await PreKeyUtil.generatePreKeys(); PreKeyRecord lastResort = await PreKeyUtil.generateLastResortKey(); SignedPreKeyRecord signedPreKey = await PreKeyUtil.generateSignedPreKey(identityKey); await App.Current.accountManager.setPreKeys(identityKey.getPublicKey(), lastResort, signedPreKey, records); DatabaseFactory.getIdentityDatabase().SaveIdentity(self.getRecipientId(), identityKey.getPublicKey()); //await DirectoryHelper.refreshDirectory(App.Current.accountManager, TextSecurePreferences.getLocalNumber()); markAsVerified(number, password, signalingKey); } catch (RateLimitException ex) { return(false); } catch (AuthorizationFailedException ex) { return(false); } catch (PushNetworkException ex) { return(false); } catch (NonSuccessfulResponseCodeException ex) { return(false); } catch (Exception ex) { return(false); //throw new Exception(ex.Message); } return(true); }
protected override string Execute() { if (TextSecurePreferences.isSignedPreKeyRegistered()) { Log.Warn("Signed prekey already registered..."); return(""); } IdentityKeyPair identityKeyPair = IdentityKeyUtil.GetIdentityKeyPair(); var signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(identityKeyPair); App.Current.accountManager.setSignedPreKey(signedPreKeyRecord); TextSecurePreferences.setSignedPreKeyRegistered(true); return(""); }