Esempio n. 1
0
        private async Task EnrollAccount_Should_GenerateNewRecordForService(ServiceTestData serviceTestData)
        {
            var context = this.InitContext(
                serviceTestData.AppToken,
                serviceTestData.ServicePublicKey2,
                serviceTestData.ClientSecretKey2,
                serviceTestData.ServiceSubdomain);

            var protocol     = new Protocol(context);
            var enrollResult = await protocol.EnrollAccountAsync(this.myPassword);

            var rec = DatabaseRecord.Parser.ParseFrom(enrollResult.Record);

            Assert.Equal <uint>(2, rec.Version);
            Assert.NotNull(rec.Record);
            Assert.NotNull(enrollResult.Key);
            Assert.Equal(32, enrollResult.Key.Length);

            System.Threading.Thread.Sleep(4000);

            var result = await protocol.VerifyPasswordAsync(this.myPassword, enrollResult.Record);

            Assert.True(result.IsSuccess);
            Assert.Equal(enrollResult.Key, result.Key);
        }
        public ProtocolContextTests()
        {
            var serviceTestData = new ServiceTestData("passw0rd");

            this.appToken          = serviceTestData.AppToken;
            this.servicePublicKey  = serviceTestData.ServicePublicKey;
            this.clientSecretKey   = serviceTestData.ClientSecretKey;
            this.clientSecretKey2  = serviceTestData.ClientSecretKey2;
            this.servicePublicKey2 = serviceTestData.ServicePublicKey2;
            this.updateTokenV2     = serviceTestData.UpdateTokenV2;
            this.updateTokenV3     = serviceTestData.UpdateTokenV3;
            this.serviceAddress    = serviceTestData.ServiceAddress;
        }
Esempio n. 3
0
        private async Task Enroll_Should_RaiseArgumentExceptionIfEmptyPasswordForService(ServiceTestData serviceTestData)
        {
            var contextWithUpdateToken = this.InitContext(
                serviceTestData.AppToken,
                serviceTestData.ServicePublicKey2,
                serviceTestData.ClientSecretKey2,
                serviceTestData.ServiceSubdomain);

            contextWithUpdateToken.UpdatePheClients(serviceTestData.UpdateTokenV3);
            var protocol = new Protocol(contextWithUpdateToken);

            var ex = await Record.ExceptionAsync(async() =>
            {
                await protocol.EnrollAccountAsync(string.Empty);
            });

            // raise exception
            Assert.IsType <ArgumentException>(ex);
        }
Esempio n. 4
0
        private async Task Updater_Should_RaiseWrongVersionExceptionIfRecordHasTheSameVersionAsUpdaterForService(ServiceTestData serviceTestData)
        {
            // you will get exception if record version == updater version
            var context = this.InitContext(
                serviceTestData.AppToken,
                serviceTestData.ServicePublicKey2,
                serviceTestData.ClientSecretKey2,
                serviceTestData.ServiceSubdomain);

            context.UpdatePheClients(serviceTestData.UpdateTokenV3);

            var protocol     = new Protocol(context);
            var enrollResult = await protocol.EnrollAccountAsync(this.myPassword);

            Assert.Equal <uint>(3, DatabaseRecord.Parser.ParseFrom(enrollResult.Record).Version);

            var recordUpdater = new RecordUpdater(serviceTestData.UpdateTokenV3);

            var ex = Record.Exception(() =>
            {
                recordUpdater.Update(enrollResult.Record);
            });

            Assert.IsType <WrongVersionException>(ex);
        }
Esempio n. 5
0
        private async Task ProtocolWithUpdateToken_Should_VerifyUpdatedRecordForService(ServiceTestData serviceTestData)
        {
            // you can verify updated record if context has updateToken with equal version
            var context = this.InitContext(
                serviceTestData.AppToken,
                serviceTestData.ServicePublicKey2,
                serviceTestData.ClientSecretKey2,
                serviceTestData.ServiceSubdomain);

            var contextWithUpdateToken = this.InitContext(
                serviceTestData.AppToken,
                serviceTestData.ServicePublicKey2,
                serviceTestData.ClientSecretKey2,
                serviceTestData.ServiceSubdomain);

            contextWithUpdateToken.UpdatePheClients(serviceTestData.UpdateTokenV3);

            var protocol     = new Protocol(context);
            var enrollResult = await protocol.EnrollAccountAsync(this.myPassword);

            Assert.Equal <uint>(2, DatabaseRecord.Parser.ParseFrom(enrollResult.Record).Version);

            var recordUpdater   = new RecordUpdater(serviceTestData.UpdateTokenV3);
            var updatedRecBytes = recordUpdater.Update(enrollResult.Record);

            Assert.Equal <uint>(3, DatabaseRecord.Parser.ParseFrom(updatedRecBytes).Version);
            var protocolWithUpdateToken = new Protocol(contextWithUpdateToken);

            var result = await protocol.VerifyPasswordAsync(this.myPassword, enrollResult.Record);

            var result2 = await protocolWithUpdateToken.VerifyPasswordAsync(this.myPassword, updatedRecBytes);

            Assert.Equal(enrollResult.Key, result.Key);
            Assert.Equal(enrollResult.Key, result2.Key);
        }
Esempio n. 6
0
        private async Task ProtocolWithWrongServiceKey_Should_RaiseProofOfSuccessNotValidExceptionForService(ServiceTestData serviceTestData)
        {
            var context = this.InitContext(
                serviceTestData.AppToken,
                serviceTestData.ServicePublicKey2,
                serviceTestData.ClientSecretKey2,
                serviceTestData.ServiceSubdomain);

            var contextWithWrongServerKey = this.InitContext(
                serviceTestData.AppToken,
                "PK.2.BK6oQNcAEyMc0fmc7coHbaQHqwoYPTiIM6A4393wEE9vRbCeUjKZSHzluHI80bGhJ61/eg1SUZNtgmMie4U80gI=",
                serviceTestData.ClientSecretKey2,
                serviceTestData.ServiceSubdomain);

            System.Threading.Thread.Sleep(5000);

            var protocol     = new Protocol(context);
            var enrollResult = await protocol.EnrollAccountAsync(this.myPassword);

            var protocolWithWrongServerKey = new Protocol(contextWithWrongServerKey);
            var ex = await Record.ExceptionAsync(async() =>
            {
                await protocolWithWrongServerKey.EnrollAccountAsync(this.myPassword);
            });

            Assert.IsType <ProofOfSuccessNotValidException>(ex);

            var ex2 = await Record.ExceptionAsync(async() =>
            {
                await protocolWithWrongServerKey.VerifyPasswordAsync(this.myPassword, enrollResult.Record);
            });

            Assert.IsType <ProofOfSuccessNotValidException>(ex2);
        }
Esempio n. 7
0
        private async Task VerifyPasswordWithWrongPassword_Should_ReturnResultWithEmptyKeyForService(ServiceTestData serviceTestData)
        {
            // you can't verify database record if provide wrong password
            var context = this.InitContext(
                serviceTestData.AppToken,
                serviceTestData.ServicePublicKey2,
                serviceTestData.ClientSecretKey2,
                serviceTestData.ServiceSubdomain);

            var protocol     = new Protocol(context);
            var enrollResult = await protocol.EnrollAccountAsync(this.myPassword);

            var result = await protocol.VerifyPasswordAsync("wrong password", enrollResult.Record);

            Assert.False(result.IsSuccess);
            Assert.Null(result.Key);
        }
Esempio n. 8
0
 public ProtocolTests()
 {
     this.passw0rdData = new ServiceTestData("passw0rd");
     this.virgilData   = new ServiceTestData("virgilsecurity");
 }
Esempio n. 9
0
        private async Task EncrollAccountWithUpdateToken_Should_GenerateNewRecordWithTokenVersionForService(ServiceTestData serviceTestData)
        {
            // if token has version =  (keys' version + 1), then database record will have token version
            var context = this.InitContext(
                serviceTestData.AppToken,
                serviceTestData.ServicePublicKey2,
                serviceTestData.ClientSecretKey2,
                serviceTestData.ServiceSubdomain);

            context.UpdatePheClients(serviceTestData.UpdateTokenV3);

            var protocol = new Protocol(context);

            System.Threading.Thread.Sleep(5000);

            var enrollResult = await protocol.EnrollAccountAsync(this.myPassword);

            var rec = DatabaseRecord.Parser.ParseFrom(enrollResult.Record);

            Assert.Equal <uint>(3, rec.Version);
            Assert.NotNull(rec.Record);
            Assert.NotNull(enrollResult.Key);
            Assert.Equal(32, enrollResult.Key.Length);

            var result = await protocol.VerifyPasswordAsync(this.myPassword, enrollResult.Record);

            Assert.True(result.IsSuccess);
            Assert.Equal(enrollResult.Key, result.Key);
        }
Esempio n. 10
0
        private async Task Updater_Should_RaiseWrongVersionExceptionIfRecordHasWrongVersionForService(ServiceTestData serviceTestData)
        {
            // you will get exception if record version != (updater version - 1)
            var context = this.InitContext(
                serviceTestData.AppToken,
                serviceTestData.ServicePublicKey2,
                serviceTestData.ClientSecretKey2,
                serviceTestData.ServiceSubdomain);

            context.UpdatePheClients(serviceTestData.UpdateTokenV3);

            var protocol     = new Protocol(context);
            var enrollResult = await protocol.EnrollAccountAsync(this.myPassword);

            var databaseRec = DatabaseRecord.Parser.ParseFrom(enrollResult.Record);

            databaseRec.Version = 1;

            var recordUpdater = new RecordUpdater(serviceTestData.UpdateTokenV3);
            var ex            = Record.Exception(() =>
            {
                recordUpdater.Update(databaseRec.ToByteArray());
            });

            Assert.IsType <WrongVersionException>(ex);

            var ex2 = await Record.ExceptionAsync(async() =>
            {
                await protocol.VerifyPasswordAsync(this.myPassword, databaseRec.ToByteArray());
            });

            Assert.IsType <WrongVersionException>(ex2);
        }