Exemplo n.º 1
0
        private static string GetSignatureStatusMessage(SignatureStatus status,
                                                        DWORD error,
                                                        string filePath)
        {
            string message        = null;
            string resourceString = null;
            string arg            = null;

            switch (status)
            {
            case SignatureStatus.Valid:
                resourceString = MshSignature.MshSignature_Valid;
                break;

            case SignatureStatus.UnknownError:
                int            intError = SecuritySupport.GetIntFromDWORD(error);
                Win32Exception e        = new Win32Exception(intError);
                message = e.Message;
                break;

            case SignatureStatus.Incompatible:
                if (error == Win32Errors.NTE_BAD_ALGID)
                {
                    resourceString = MshSignature.MshSignature_Incompatible_HashAlgorithm;
                }
                else
                {
                    resourceString = MshSignature.MshSignature_Incompatible;
                }

                arg = filePath;
                break;

            case SignatureStatus.NotSigned:
                resourceString = MshSignature.MshSignature_NotSigned;
                arg            = filePath;
                break;

            case SignatureStatus.HashMismatch:
                resourceString = MshSignature.MshSignature_HashMismatch;
                arg            = filePath;
                break;

            case SignatureStatus.NotTrusted:
                resourceString = MshSignature.MshSignature_NotTrusted;
                arg            = filePath;
                break;

            case SignatureStatus.NotSupportedFileFormat:
                resourceString = MshSignature.MshSignature_NotSupportedFileFormat;
                arg            = System.IO.Path.GetExtension(filePath);

                if (string.IsNullOrEmpty(arg))
                {
                    resourceString = MshSignature.MshSignature_NotSupportedFileFormat_NoExtension;
                    arg            = null;
                }

                break;
            }

            if (message == null)
            {
                if (arg == null)
                {
                    message = resourceString;
                }
                else
                {
                    message = StringUtil.Format(resourceString, arg);
                }
            }

            return(message);
        }
Exemplo n.º 2
0
        private static string GetSignatureStatusMessage(
            SignatureStatus status,
            uint error,
            string filePath)
        {
            using (Signature.tracer.TraceMethod())
            {
                string str1       = (string)null;
                string resourceId = (string)null;
                string str2       = (string)null;
                switch (status)
                {
                case SignatureStatus.Valid:
                    resourceId = "MshSignature_Valid";
                    break;

                case SignatureStatus.UnknownError:
                    str1 = new Win32Exception(SecuritySupport.GetIntFromDWORD(error)).Message;
                    break;

                case SignatureStatus.NotSigned:
                    resourceId = "MshSignature_NotSigned";
                    str2       = filePath;
                    break;

                case SignatureStatus.HashMismatch:
                    resourceId = "MshSignature_HashMismatch";
                    str2       = filePath;
                    break;

                case SignatureStatus.NotTrusted:
                    resourceId = "MshSignature_NotTrusted";
                    str2       = filePath;
                    break;

                case SignatureStatus.NotSupportedFileFormat:
                    resourceId = "MshSignature_NotSupportedFileFormat";
                    str2       = System.IO.Path.GetExtension(filePath);
                    if (string.IsNullOrEmpty(str2))
                    {
                        resourceId = "MshSignature_NotSupportedFileFormat_NoExtension";
                        str2       = (string)null;
                        break;
                    }
                    break;

                case SignatureStatus.Incompatible:
                    resourceId = error != 2148073480U ? "MshSignature_Incompatible" : "MshSignature_Incompatible_HashAlgorithm";
                    str2       = filePath;
                    break;
                }
                if (str1 == null)
                {
                    if (str2 == null)
                    {
                        str1 = ResourceManagerCache.GetResourceString("MshSignature", resourceId);
                    }
                    else
                    {
                        str1 = ResourceManagerCache.FormatResourceString("MshSignature", resourceId, (object)str2);
                    }
                }
                return(str1);
            }
        }
Exemplo n.º 3
0
        private static string GetSignatureStatusMessage(SignatureStatus status,
                                                        DWORD error,
                                                        string filePath)
        {
            string message        = null;
            string resourceString = null;
            string arg            = null;

            switch (status)
            {
            case SignatureStatus.Valid:
                resourceString = "Signature verified.";
                break;

            case SignatureStatus.UnknownError:
                int            intError = SecuritySupport.GetIntFromDWORD(error);
                Win32Exception e        = new Win32Exception(intError);
                message = e.Message;
                break;

            case SignatureStatus.Incompatible:
                if (error == Win32Errors.NTE_BAD_ALGID)
                {
                    resourceString = "The signature cannot be verified because it is incompatible with the current system. The hash algorithm is not valid.";
                }
                else
                {
                    resourceString = "The signature cannot be verified because it is incompatible with the current system.";
                }

                arg = filePath;
                break;

            case SignatureStatus.NotSigned:
                resourceString = "The file {0} is not digitally signed. You cannot run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170";
                arg            = filePath;
                break;

            case SignatureStatus.HashMismatch:
                resourceString = "The contents of file {0} might have been changed by an unauthorized user or process, because the hash of the file does not match the hash stored in the digital signature. The script cannot run on the specified system. For more information, run Get-Help about_Signing.";
                arg            = filePath;
                break;

            case SignatureStatus.NotTrusted:
                resourceString = "File {0} is signed but the signer is not trusted on this system.";
                arg            = filePath;
                break;

            case SignatureStatus.NotSupportedFileFormat:
                resourceString = "Cannot sign the file because the system does not support signing operations on {0} files.";
                arg            = System.IO.Path.GetExtension(filePath);

                if (string.IsNullOrEmpty(arg))
                {
                    resourceString = "Cannot sign the file because the system does not support signing operations on files that do not have a file name extension.";
                    arg            = null;
                }

                break;
            }

            if (message == null)
            {
                if (arg == null)
                {
                    message = resourceString;
                }
                else
                {
                    message = string.Format(resourceString, arg);
                }
            }

            return(message);
        }
Exemplo n.º 4
0
        private static string GetSignatureStatusMessage(SignatureStatus status, uint error, string filePath)
        {
            string message    = null;
            string formatSpec = null;
            string extension  = null;

            switch (status)
            {
            case SignatureStatus.Valid:
                formatSpec = MshSignature.MshSignature_Valid;
                goto Label_00A4;

            case SignatureStatus.UnknownError:
            {
                Win32Exception exception = new Win32Exception(SecuritySupport.GetIntFromDWORD(error));
                message = exception.Message;
                goto Label_00A4;
            }

            case SignatureStatus.NotSigned:
                formatSpec = MshSignature.MshSignature_NotSigned;
                extension  = filePath;
                goto Label_00A4;

            case SignatureStatus.HashMismatch:
                formatSpec = MshSignature.MshSignature_HashMismatch;
                extension  = filePath;
                goto Label_00A4;

            case SignatureStatus.NotTrusted:
                formatSpec = MshSignature.MshSignature_NotTrusted;
                extension  = filePath;
                goto Label_00A4;

            case SignatureStatus.NotSupportedFileFormat:
                formatSpec = MshSignature.MshSignature_NotSupportedFileFormat;
                extension  = System.IO.Path.GetExtension(filePath);
                if (string.IsNullOrEmpty(extension))
                {
                    formatSpec = MshSignature.MshSignature_NotSupportedFileFormat_NoExtension;
                    extension  = null;
                }
                goto Label_00A4;

            case SignatureStatus.Incompatible:
                if (error != 0x80090008)
                {
                    formatSpec = MshSignature.MshSignature_Incompatible;
                    break;
                }
                formatSpec = MshSignature.MshSignature_Incompatible_HashAlgorithm;
                break;

            default:
                goto Label_00A4;
            }
            extension = filePath;
Label_00A4:
            if (message != null)
            {
                return(message);
            }
            if (extension == null)
            {
                return(formatSpec);
            }
            return(StringUtil.Format(formatSpec, extension));
        }