Ejemplo n.º 1
0
 static void ValidateDeviceAuthentication(AuthenticationMechanism authenticationMechanism)
 {
     if (authenticationMechanism.SymmetricKey != null)
     {
         // either both keys should be specified or neither once should be specified (in which case
         // we will create both the keys in the service)
         if (string.IsNullOrWhiteSpace(authenticationMechanism.SymmetricKey.PrimaryKey) ^ string.IsNullOrWhiteSpace(authenticationMechanism.SymmetricKey.SecondaryKey))
         {
             throw new ArgumentException(ApiResources.DeviceKeysInvalid);
         }
     }
 }
Ejemplo n.º 2
0
        static void NormalizeAuthenticationInfo(AuthenticationMechanism authenticationInfo)
        {
            //to make it backward compatible we set the type according to the values
            //we don't set CA type - that has to be explicit
            if (authenticationInfo.SymmetricKey != null && !authenticationInfo.SymmetricKey.IsEmpty())
            {
                authenticationInfo.Type = AuthenticationType.Sas;
            }

            if (authenticationInfo.X509Thumbprint != null && !authenticationInfo.X509Thumbprint.IsEmpty())
            {
                authenticationInfo.Type = AuthenticationType.SelfSigned;
            }
        }
Ejemplo n.º 3
0
        static void ValidateDeviceAuthentication(AuthenticationMechanism authentication, string deviceId)
        {
            if (authentication != null)
            {
                // Both symmetric keys and X.509 cert thumbprints cannot be specified for the same device
                bool symmetricKeyIsSet   = !authentication.SymmetricKey?.IsEmpty() ?? false;
                bool x509ThumbprintIsSet = !authentication.X509Thumbprint?.IsEmpty() ?? false;

                if (symmetricKeyIsSet && x509ThumbprintIsSet)
                {
                    throw new ArgumentException(ApiResources.DeviceAuthenticationInvalid.FormatInvariant(deviceId ?? string.Empty));
                }

                // Validate X.509 thumbprints or SymmetricKeys since we should not have both at the same time
                if (x509ThumbprintIsSet)
                {
                    authentication.X509Thumbprint.IsValid(true);
                }
                else if (symmetricKeyIsSet)
                {
                    authentication.SymmetricKey.IsValid(true);
                }
            }
        }
 static void ValidateDeviceAuthentication(AuthenticationMechanism authenticationMechanism)
 {
     if (authenticationMechanism.SymmetricKey != null)
     {
         // either both keys should be specified or neither once should be specified (in which case 
         // we will create both the keys in the service)
         if (string.IsNullOrWhiteSpace(authenticationMechanism.SymmetricKey.PrimaryKey) ^ string.IsNullOrWhiteSpace(authenticationMechanism.SymmetricKey.SecondaryKey))
         {
             throw new ArgumentException(ApiResources.DeviceKeysInvalid);
         }
     }
 }