16
16
using System . Collections . Generic ;
17
17
using System . Text ;
18
18
using System . Threading ;
19
+ using System . Threading . Tasks ;
19
20
20
21
namespace libsignalservice
21
22
{
@@ -57,7 +58,7 @@ public SignalServiceAccountManager(SignalServiceConfiguration configuration, Can
57
58
{
58
59
Configuration = configuration ;
59
60
UserAgent = userAgent ;
60
- ProvisioningSocket = new ProvisioningSocket ( configuration . SignalServiceUrls [ 0 ] . Url , token ) ;
61
+ ProvisioningSocket = new ProvisioningSocket ( configuration . SignalServiceUrls [ 0 ] . Url ) ;
61
62
PushServiceSocket = new PushServiceSocket ( configuration , new StaticCredentialsProvider ( null , null , null , ( int ) SignalServiceAddress . DEFAULT_DEVICE_ID ) , userAgent ) ;
62
63
}
63
64
@@ -224,10 +225,10 @@ public List<ContactTokenDetails> GetContacts(IList<string> e164numbers)
224
225
/// </summary>
225
226
/// <param name="token">The UUID, Base64 encoded</param>
226
227
/// <returns></returns>
227
- public string GetNewDeviceUuid ( CancellationToken token )
228
+ public async Task < string > GetNewDeviceUuid ( CancellationToken token )
228
229
{
229
- ProvisioningSocket = new ProvisioningSocket ( Configuration . SignalServiceUrls [ 0 ] . Url , token ) ;
230
- return ProvisioningSocket . GetProvisioningUuid ( ) . Uuid ;
230
+ ProvisioningSocket = new ProvisioningSocket ( Configuration . SignalServiceUrls [ 0 ] . Url ) ;
231
+ return ( await ProvisioningSocket . GetProvisioningUuid ( token ) ) . Uuid ;
231
232
}
232
233
233
234
/// <summary>
@@ -241,41 +242,52 @@ public string GetNewDeviceVerificationCode()// throws IOException
241
242
}
242
243
243
244
/// <summary>
244
- /// Finishes a registration as a new device.
245
- /// Called by the new device. This method blocks until the already verified device has verified this device.
245
+ /// Fetch a ProvisionMessage from the server.
246
246
/// </summary>
247
+ /// <param name="token"></param>
247
248
/// <param name="tempIdentity"></param>
248
- /// <param name="signalingKey"></param>
249
- /// <param name="password"></param>
250
- /// <param name="sms"></param>
251
- /// <param name="fetches"></param>
252
- /// <param name="regid"></param>
253
- /// <param name="name"></param>
254
249
/// <returns></returns>
255
- public NewDeviceLinkResult FinishNewDeviceRegistration ( IdentityKeyPair tempIdentity , string signalingKey , string password , bool sms , bool fetches , int regid , string name )
250
+ public async Task < SignalServiceProvisionMessage > GetProvisioningMessage ( CancellationToken token , IdentityKeyPair tempIdentity )
256
251
{
257
- ProvisionMessage pm = ProvisioningSocket . GetProvisioningMessage ( tempIdentity ) ;
258
- string provisioningCode = pm . ProvisioningCode ;
259
- byte [ ] publicKeyBytes = pm . IdentityKeyPublic . ToByteArray ( ) ;
252
+ ProvisionMessage protoPm = await ProvisioningSocket . GetProvisioningMessage ( token , tempIdentity ) ;
253
+ string provisioningCode = protoPm . ProvisioningCode ;
254
+ byte [ ] publicKeyBytes = protoPm . IdentityKeyPublic . ToByteArray ( ) ;
260
255
if ( publicKeyBytes . Length == 32 )
261
256
{
262
257
byte [ ] type = { Curve . DJB_TYPE } ;
263
258
publicKeyBytes = ByteUtil . combine ( type , publicKeyBytes ) ;
264
259
}
265
260
ECPublicKey publicKey = Curve . decodePoint ( publicKeyBytes , 0 ) ;
266
- byte [ ] privateKeyBytes = pm . IdentityKeyPrivate . ToByteArray ( ) ;
261
+ byte [ ] privateKeyBytes = protoPm . IdentityKeyPrivate . ToByteArray ( ) ;
267
262
ECPrivateKey privateKey = Curve . decodePrivatePoint ( privateKeyBytes ) ;
268
263
IdentityKeyPair identity = new IdentityKeyPair ( new IdentityKey ( publicKey ) , privateKey ) ;
269
- PushServiceSocket = new PushServiceSocket ( Configuration , new StaticCredentialsProvider ( pm . Number , password , null , - 1 ) , UserAgent ) ;
270
- int deviceId = PushServiceSocket . FinishNewDeviceRegistration ( provisioningCode , signalingKey , sms , fetches , regid , name ) ;
271
- return new NewDeviceLinkResult ( )
264
+ return new SignalServiceProvisionMessage ( )
272
265
{
273
- DeviceId = deviceId ,
266
+ Number = protoPm . Number ,
274
267
Identity = identity ,
275
- Number = pm . Number
268
+ Code = protoPm . ProvisioningCode
276
269
} ;
277
270
}
278
271
272
+ /// <summary>
273
+ /// Finishes a registration as a new device.
274
+ /// Called by the new device. This method blocks until the already verified device has verified this device.
275
+ /// </summary>
276
+ /// <param name="token"></param>
277
+ /// <param name="provisionMessage"></param>
278
+ /// <param name="signalingKey"></param>
279
+ /// <param name="password"></param>
280
+ /// <param name="sms"></param>
281
+ /// <param name="fetches"></param>
282
+ /// <param name="regid"></param>
283
+ /// <param name="name"></param>
284
+ /// <returns></returns>
285
+ public async Task < int > FinishNewDeviceRegistration ( CancellationToken token , SignalServiceProvisionMessage provisionMessage , string signalingKey , string password , bool sms , bool fetches , int regid , string name )
286
+ {
287
+ PushServiceSocket = new PushServiceSocket ( Configuration , new StaticCredentialsProvider ( provisionMessage . Number , password , null , - 1 ) , UserAgent ) ;
288
+ return await PushServiceSocket . FinishNewDeviceRegistration ( token , provisionMessage . Code , signalingKey , sms , fetches , regid , name ) ;
289
+ }
290
+
279
291
/// <summary>
280
292
/// TODO
281
293
/// </summary>
@@ -414,11 +426,11 @@ private IDictionary<string, string> CreateDirectoryServerTokenMap(IList<string>
414
426
415
427
416
428
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
417
- public class NewDeviceLinkResult
429
+ public class SignalServiceProvisionMessage
418
430
{
419
- public IdentityKeyPair Identity { get ; set ; }
420
- public int DeviceId { get ; set ; }
421
- public string Number { get ; set ; }
431
+ public IdentityKeyPair Identity { get ; internal set ; }
432
+ public string Number { get ; internal set ; }
433
+ public string Code { get ; internal set ; }
422
434
}
423
435
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
424
436
}
0 commit comments