Example #1
0
 public int GetCountOfKeysByUpladedDayAndSource(DateTime uploadDate, KeySource keySource)
 {
     return(_dbContext.TemporaryExposureKey
            .Where(key => key.CreatedOn.Date.CompareTo(uploadDate.Date) == 0)
            .Where(key => key.KeySource == keySource)
            .Count());
 }
        public static String GetUserPartitionKey(this ClaimsPrincipal iUserPrincipal,
                                                 KeySource iSource)
        {
            switch (iSource)
            {
            case KeySource.none:
            {
                throw new NotImplementedException("iSource cannot be 'none'.");
            }

            case KeySource.email:
            {
                String pStrEmail = iUserPrincipal.FindFirst(ClaimTypes.Email).Value;
                return(AzureTableHelpers.GetPartitionKeyFromEmailString(pStrEmail));
            }

            case KeySource.custom:
            {
                if (GetuserPartitionKeyCustomDelegate != null)
                {
                    return(GetuserPartitionKeyCustomDelegate(iUserPrincipal));
                }
                else
                {
                    throw new InvalidOperationException("iSource is 'custom' but GetUserPartitionKeyCustomDelegate has not been implemented.");
                }
            }

            default:
            {
                throw new NotImplementedException(String.Format("'{0}' has not been implemented as a user parition key source.", iUserPrincipal.ToString()));
            }
            }
        }
Example #3
0
        // ------------------
        public GamepadProfile()
        {
            this.name = "New Profile";
            this.joystickIdentifier = "Device Identifier";
            this.profileMode        = ProfileMode.Normal;

            this.unityVerFrom = "4.7";
            this.unityVerTo   = "9.9";



            this.dpad       = new JoystickSource();
            this.leftStick  = new JoystickSource();
            this.rightStick = new JoystickSource();

            this.keyFaceU  = KeySource.Empty();
            this.keyFaceR  = KeySource.Empty();
            this.keyFaceD  = KeySource.Empty();
            this.keyFaceL  = KeySource.Empty();
            this.keyStart  = KeySource.Empty();
            this.keySelect = KeySource.Empty();
            this.keyL1     = KeySource.Empty();
            this.keyR1     = KeySource.Empty();
            this.keyL2     = KeySource.Empty();
            this.keyR2     = KeySource.Empty();
            this.keyL3     = KeySource.Empty();
            this.keyR3     = KeySource.Empty();
        }
Example #4
0
 // ----------------------
 public JoystickSource()
 {
     this.keyD = new KeySource();
     this.keyU = new KeySource();
     this.keyL = new KeySource();
     this.keyR = new KeySource();
 }
Example #5
0
        // ------------------
        public KeySource GetKeySource(int id)
        {
            KeySource key = null;

            switch (id)
            {
            case (int)GamepadManager.GamepadKey.FaceBottom:        key = this.keyFaceD; break;

            case (int)GamepadManager.GamepadKey.FaceRight:       key = this.keyFaceR; break;

            case (int)GamepadManager.GamepadKey.FaceLeft:       key = this.keyFaceL; break;

            case (int)GamepadManager.GamepadKey.FaceTop:       key = this.keyFaceU; break;

            case (int)GamepadManager.GamepadKey.Start:       key = this.keyStart; break;

            case (int)GamepadManager.GamepadKey.Select:       key = this.keySelect; break;

            case (int)GamepadManager.GamepadKey.L1:       key = this.keyL1; break;

            case (int)GamepadManager.GamepadKey.R1:       key = this.keyR1; break;

            case (int)GamepadManager.GamepadKey.L2:       key = this.keyL2; break;

            case (int)GamepadManager.GamepadKey.R2:       key = this.keyR2; break;

            case (int)GamepadManager.GamepadKey.L3:       key = this.keyL3; break;

            case (int)GamepadManager.GamepadKey.R3:       key = this.keyR3; break;
            }

            return(key);
        }
 internal Encryption(EncryptionServices services, KeySource keySource, bool?requireInfrastructureEncryption, KeyVaultProperties keyVaultProperties)
 {
     Services  = services;
     KeySource = keySource;
     RequireInfrastructureEncryption = requireInfrastructureEncryption;
     KeyVaultProperties = keyVaultProperties;
 }
Example #7
0
 internal static string ToSerializedValue(this KeySource value)
 {
     switch (value)
     {
     case KeySource.MicrosoftKeyVault:
         return("Microsoft.KeyVault");
     }
     return(null);
 }
        public static bool ProcessInput(Key key, ModifierKeys modifiers, KeySource source)
        {
            if (OnPreviewKeyReceived(key, modifiers))
            {
                return(true);
            }

            bool   isGlobal = source == KeySource.Global;
            string shortcut = GetShortcut(key, modifiers);

            return(ProcessInput(shortcut, isGlobal));
        }
Example #9
0
        // --------------------
        public GamepadProfile(
            string name,
            string deviceIdentifier,
            ProfileMode profileMode,
            string unityVerFrom,
            string unityVerTo,
            JoystickSource leftStick,
            JoystickSource rightStick,
            JoystickSource dpad,
            KeySource keyFaceD,
            KeySource keyFaceR,
            KeySource keyFaceL,
            KeySource keyFaceU,
            KeySource keySelect,
            KeySource keyStart,
            KeySource keyL1,
            KeySource keyR1,
            KeySource keyL2,
            KeySource keyR2,
            KeySource keyL3,
            KeySource keyR3)
        {
            this.name = name;
            this.joystickIdentifier = deviceIdentifier;
            this.profileMode        = profileMode;
            //this.platformFlags        = platformFlags;
            this.unityVerFrom = (string.IsNullOrEmpty(unityVerFrom)   ? "4.3" : unityVerFrom);
            this.unityVerTo   = (string.IsNullOrEmpty(unityVerTo)     ? "9.9" : unityVerTo);



            //this.sticks	= new JoystickSource[GamepadManager.GamepadStickCount];
            //this.keys	= new KeySource[GamepadManager.GamepadKeyCount];

            this.leftStick  = (leftStick != null)   ? leftStick     : JoystickSource.Empty();
            this.rightStick = (rightStick != null)  ? rightStick    : JoystickSource.Empty();
            this.dpad       = (dpad != null)                ? dpad                  : JoystickSource.Empty();

            this.keyFaceU = (keyFaceU != null)    ? keyFaceU              : KeySource.Empty();
            this.keyFaceR = (keyFaceR != null)    ? keyFaceR              : KeySource.Empty();
            this.keyFaceD = (keyFaceD != null)    ? keyFaceD              : KeySource.Empty();
            this.keyFaceL = (keyFaceL != null)    ? keyFaceL              : KeySource.Empty();

            this.keyStart  = (keyStart != null)    ? keyStart              : KeySource.Empty();
            this.keySelect = (keySelect != null)   ? keySelect             : KeySource.Empty();

            this.keyL1 = (keyL1 != null)               ? keyL1         : KeySource.Empty();
            this.keyR1 = (keyR1 != null)               ? keyR1         : KeySource.Empty();
            this.keyL2 = (keyL2 != null)               ? keyL2         : KeySource.Empty();
            this.keyR2 = (keyR2 != null)               ? keyR2         : KeySource.Empty();
            this.keyL3 = (keyL3 != null)               ? keyL3         : KeySource.Empty();
            this.keyR3 = (keyR3 != null)               ? keyR3         : KeySource.Empty();
        }
Example #10
0
 // Sonify Key
 public void SonifyKey()
 {
     // If chair is behind the subject, say "turn around"
     AimingError = Vector3.Angle(TargetPosition - Camera.main.transform.position, Camera.main.transform.forward);
     if (Math.Abs(AimingError) > BackThreshold)
     {
         TurnAroundSource.Play();
         AimingError = 0f;
     }
     else
     {
         KeySource.pitch = Math.Max(1.5f - 0.5f * (float)Math.Log10(TargetDistance + 1f), 0.5f);
         KeySource.Play();
     }
 }
 /// <summary>
 /// Releases all resources consumed by the current <see cref="SecureSymmetricKey" />.
 /// </summary>
 /// <param name="disposing">
 /// A value indicating whether or not managed resources should be released.
 /// </param>
 protected override void Dispose(Boolean disposing)
 {
     try
     {
         if (disposing)
         {
             BufferEncryptionKey.Dispose();
             KeySource.Dispose();
             LazyPbkdf2Provider.Dispose();
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
Example #12
0
        private static DateTime ConvertFromBinaryTime(byte[] binaryTime, KeySource source, KeyCredentialVersion version)
        {
            long timeStamp = BitConverter.ToInt64(binaryTime, 0);

            // AD and AAD use a different time encoding.
            switch (version)
            {
            case KeyCredentialVersion.Version0:
                return(new DateTime(timeStamp));

            case KeyCredentialVersion.Version1:
                return(DateTime.FromBinary(timeStamp));

            case KeyCredentialVersion.Version2:
            default:
                return(source == KeySource.AD ? DateTime.FromFileTime(timeStamp) : DateTime.FromBinary(timeStamp));
            }
        }
        /// <summary>
        /// Converts the value of the current <see cref="SecureSymmetricKey" /> to its equivalent binary representation.
        /// </summary>
        /// <returns>
        /// A binary representation of the current <see cref="SecureSymmetricKey" />.
        /// </returns>
        public SecureBuffer ToBuffer()
        {
            var resultBuffer = new SecureBuffer(SerializedLength);

            try
            {
                using (var controlToken = StateControl.Enter())
                {
                    using (var plaintextBuffer = new PinnedBuffer(SerializedPlaintextLength, true))
                    {
                        KeySource.Access(pinnedKeySourceBuffer =>
                        {
                            Array.Copy(pinnedKeySourceBuffer, 0, plaintextBuffer, KeySourceBufferIndex, KeySourceLengthInBytes);
                        });

                        plaintextBuffer[AlgorithmBufferIndex]      = (Byte)Algorithm;
                        plaintextBuffer[DerivationModeBufferIndex] = (Byte)DerivationMode;

                        using (var cipher = BufferEncryptionAlgorithm.ToCipher(RandomnessProvider))
                        {
                            using (var initializationVector = new PinnedBuffer(cipher.BlockSizeInBytes, true))
                            {
                                RandomnessProvider.GetBytes(initializationVector);

                                resultBuffer.Access(pinnedResultBuffer =>
                                {
                                    using (var ciphertext = cipher.Encrypt(plaintextBuffer, BufferEncryptionKey, initializationVector))
                                    {
                                        Array.Copy(ciphertext, 0, pinnedResultBuffer, 0, SerializedLength);
                                    }
                                });
                            }
                        }
                    }
                }

                return(resultBuffer);
            }
            catch
            {
                resultBuffer.Dispose();
                throw new SecurityException("Key serialization failed.");
            }
        }
        public static bool ProcessInput(Key key, ModifierKeys modifiers, KeySource source)
        {
            if (OnPreviewKeyReceived(key, modifiers))
            {
                return(true);
            }

            if (!IsEnabled)
            {
                return(false);
            }

            bool   isGlobal = source == KeySource.Global;
            string shortcut = GetShortcut(key, modifiers);

            InputMapping mapping = CommandMappings.FirstOrDefault(
                c => c.KeyboardShortcut == shortcut &&
                c.IsGlobal == isGlobal);

            if (mapping == null)
            {
                return(false);
            }

            Debug.WriteLine($"Processing '{shortcut}' from {source} => {mapping.CommandId}");

            if (!Commands.ContainsKey(mapping.CommandId))
            {
                return(false);
            }

            ScriptplayerCommand command = Commands[mapping.CommandId];

            if (!command.CanExecute(null))
            {
                return(false);
            }

            command.Execute(null);
            return(true);
        }
        private Rfc2898DeriveBytes InitializePbkdf2Algorithm()
        {
            Rfc2898DeriveBytes result = null;

            KeySource.Access(buffer =>
            {
                var iterationSumBuffer = buffer.Take(Pbkdf2IterationSumLengthInBytes);
                var saltBuffer         = buffer.Skip(Pbkdf2IterationSumLengthInBytes).Take(Pbkdf2SaltLengthInBytes);
                var passwordBuffer     = buffer.Skip(Pbkdf2IterationSumLengthInBytes + Pbkdf2SaltLengthInBytes).Take(Pbkdf2PasswordLengthInBytes);
                var iterationCount     = Pbkdf2MinimumIterationCount;

                foreach (var iterationSumValue in iterationSumBuffer)
                {
                    iterationCount += iterationSumValue;
                }

                result = new Rfc2898DeriveBytes(passwordBuffer.ToArray(), saltBuffer.ToArray(), iterationCount);
            });

            return(result);
        }
Example #16
0
        private static byte[] ConvertToBinaryTime(DateTime time, KeySource source, KeyCredentialVersion version)
        {
            long timeStamp;

            switch (version)
            {
            case KeyCredentialVersion.Version0:
                timeStamp = time.Ticks;
                break;

            case KeyCredentialVersion.Version1:
                timeStamp = time.ToBinary();
                break;

            case KeyCredentialVersion.Version2:
            default:
                timeStamp = source == KeySource.AD ? time.ToFileTime() : time.ToBinary();
                break;
            }

            return(BitConverter.GetBytes(timeStamp));
        }
 /// <summary>
 /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider"
 /// /> and <see cref="ignoreCase" />
 /// </summary>
 /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param>
 /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param>
 /// <param name="formatProvider">not used by this TypeConverter.</param>
 /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param>
 /// <returns>
 /// an instance of <see cref="KeySource" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => KeySource.CreateFrom(sourceValue);
Example #18
0
 // ----------------
 public bool IsDuplicateOf(KeySource a)
 {
     return((this.keyId == a.keyId) && (this.axisId == a.axisId) && (this.axisSign == a.axisSign));
 }
Example #19
0
 public Encryption(KeySource keySource)
 {
     KeySource = keySource;
 }
        internal PinnedBuffer DeriveKey()
        {
            var result = (PinnedBuffer)null;

            try
            {
                using (var controlToken = StateControl.Enter())
                {
                    if (DerivationMode == SecureSymmetricKeyDerivationMode.Pbkdf2)
                    {
                        try
                        {
                            // Perform PBKDF2 key-derivation.
                            result = new PinnedBuffer(Pbkdf2Provider.GetBytes(DerivedKeyLength), true);
                        }
                        finally
                        {
                            Pbkdf2Provider.Reset();
                        }

                        return(result);
                    }

                    result = new PinnedBuffer(DerivedKeyLength, true);

                    using (var sourceWords = new PinnedStructureArray <UInt32>(KeySourceWordCount, true))
                    {
                        KeySource.Access((PinnedBuffer buffer) =>
                        {
                            // Convert the source buffer to an array of 32-bit words.
                            Buffer.BlockCopy(buffer, 0, sourceWords, 0, KeySourceLengthInBytes);
                        });

                        using (var transformedWords = new PinnedStructureArray <UInt32>(BlockWordCount, true))
                        {
                            // Copy out the first block. If nothing further is done, this satisfies truncation mode.
                            Array.Copy(sourceWords, transformedWords, BlockWordCount);

                            switch (DerivationMode)
                            {
                            case SecureSymmetricKeyDerivationMode.Truncation:

                                break;

                            case SecureSymmetricKeyDerivationMode.XorLayering:

                                for (var i = 1; i < BlockCount; i++)
                                {
                                    for (var j = 0; j < BlockWordCount; j++)
                                    {
                                        // Perform the XOR layering operation.
                                        transformedWords[j] = (transformedWords[j] ^ sourceWords[(i * BlockWordCount) + j]);
                                    }
                                }

                                break;

                            case SecureSymmetricKeyDerivationMode.XorLayeringWithSubstitution:

                                for (var i = 1; i < BlockCount; i++)
                                {
                                    for (var j = 0; j < BlockWordCount; j++)
                                    {
                                        // Perform the XOR layering operation with substitution.
                                        transformedWords[j] = (SubstituteWord(transformedWords[j]) ^ sourceWords[(i * BlockWordCount) + j]);
                                    }
                                }

                                break;

                            default:

                                throw new InvalidOperationException($"The specified key derivation mode, {DerivationMode}, is not supported.");
                            }

                            // Copy out the key bits.
                            Buffer.BlockCopy(transformedWords, 0, result, 0, DerivedKeyLength);
                        }
                    }

                    return(result);
                }
            }
            catch
            {
                result?.Dispose();
                throw new SecurityException("Key derivation failed.");
            }
        }
 public TestTemporaryExposureKeyBuilder SetKeySource(KeySource keySource)
 {
     _prototype.KeySource = keySource;
     return(this);
 }
Example #22
0
        public async Task CreateKeysInDatabase(TemporaryExposureKeyBatchDto parameters, KeySource apiVersion)
        {
            var newTemporaryExposureKeys = await GetFilteredKeysEntitiesFromDTO(parameters);

            if (newTemporaryExposureKeys.Any())
            {
                await CreateNewKeysInDatabase(parameters, newTemporaryExposureKeys, apiVersion);
            }
        }
Example #23
0
 internal Encryption(EncryptionServices services, KeySource keySource, KeyVaultProperties keyVaultProperties)
 {
     Services           = services;
     KeySource          = keySource;
     KeyVaultProperties = keyVaultProperties;
 }
Example #24
0
        private async Task CreateNewKeysInDatabase(TemporaryExposureKeyBatchDto parameters, IList <TemporaryExposureKey> newTemporaryExposureKeys, KeySource apiVersion)
        {
            var origin = _countryRepository.FindByIsoCode(parameters.regions[0]);

            foreach (var key in newTemporaryExposureKeys)
            {
                key.Origin     = origin;
                key.KeySource  = apiVersion;
                key.ReportType = ReportType.CONFIRMED_TEST;
            }

            var visitedCountries = parameters.visitedCountries.FindAll(countryCode => countryCode.ToLower() != origin.Code.ToLower());
            await _temporaryExposureKeyRepository.AddTemporaryExposureKeysAsync(newTemporaryExposureKeys);

            await CreateKeyCountryRelationships(visitedCountries, newTemporaryExposureKeys);
        }