| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Collections.Generic; |
| | | 5 | | using System.ComponentModel; |
| | | 6 | | using System.Diagnostics; |
| | | 7 | | |
| | | 8 | | namespace System.Net |
| | | 9 | | { |
| | | 10 | | internal static class SecurityStatusAdapterPal |
| | | 11 | | { |
| | | 12 | | private const int StatusDictionarySize = 46; |
| | | 13 | | |
| | | 14 | | #if DEBUG |
| | | 15 | | static SecurityStatusAdapterPal() |
| | 0 | 16 | | { |
| | 0 | 17 | | Debug.Assert(s_statusDictionary.Count == StatusDictionarySize, $"Expected size {StatusDictionarySize}, got s |
| | 0 | 18 | | } |
| | | 19 | | #endif |
| | | 20 | | |
| | 0 | 21 | | private static readonly BidirectionalDictionary<Interop.SECURITY_STATUS, SecurityStatusPalErrorCode> s_statusDic |
| | 0 | 22 | | { |
| | 0 | 23 | | { Interop.SECURITY_STATUS.AlgorithmMismatch, SecurityStatusPalErrorCode.AlgorithmMismatch }, |
| | 0 | 24 | | { Interop.SECURITY_STATUS.ApplicationProtocolMismatch, SecurityStatusPalErrorCode.ApplicationProtocolMismatc |
| | 0 | 25 | | { Interop.SECURITY_STATUS.BadBinding, SecurityStatusPalErrorCode.BadBinding }, |
| | 0 | 26 | | { Interop.SECURITY_STATUS.BufferNotEnough, SecurityStatusPalErrorCode.BufferNotEnough }, |
| | 0 | 27 | | { Interop.SECURITY_STATUS.CannotInstall, SecurityStatusPalErrorCode.CannotInstall }, |
| | 0 | 28 | | { Interop.SECURITY_STATUS.CannotPack, SecurityStatusPalErrorCode.CannotPack }, |
| | 0 | 29 | | { Interop.SECURITY_STATUS.CertExpired, SecurityStatusPalErrorCode.CertExpired }, |
| | 0 | 30 | | { Interop.SECURITY_STATUS.CertUnknown, SecurityStatusPalErrorCode.CertUnknown }, |
| | 0 | 31 | | { Interop.SECURITY_STATUS.CompAndContinue, SecurityStatusPalErrorCode.CompAndContinue }, |
| | 0 | 32 | | { Interop.SECURITY_STATUS.CompleteNeeded, SecurityStatusPalErrorCode.CompleteNeeded }, |
| | 0 | 33 | | { Interop.SECURITY_STATUS.ContextExpired, SecurityStatusPalErrorCode.ContextExpired }, |
| | 0 | 34 | | { Interop.SECURITY_STATUS.ContextExpiredError, SecurityStatusPalErrorCode.ContextExpiredError }, |
| | 0 | 35 | | { Interop.SECURITY_STATUS.ContinueNeeded, SecurityStatusPalErrorCode.ContinueNeeded }, |
| | 0 | 36 | | { Interop.SECURITY_STATUS.CredentialsNeeded, SecurityStatusPalErrorCode.CredentialsNeeded }, |
| | 0 | 37 | | { Interop.SECURITY_STATUS.DecryptFailure, SecurityStatusPalErrorCode.DecryptFailure }, |
| | 0 | 38 | | { Interop.SECURITY_STATUS.DowngradeDetected, SecurityStatusPalErrorCode.DowngradeDetected }, |
| | 0 | 39 | | { Interop.SECURITY_STATUS.IllegalMessage, SecurityStatusPalErrorCode.IllegalMessage }, |
| | 0 | 40 | | { Interop.SECURITY_STATUS.IncompleteCredentials, SecurityStatusPalErrorCode.IncompleteCredentials }, |
| | 0 | 41 | | { Interop.SECURITY_STATUS.IncompleteMessage, SecurityStatusPalErrorCode.IncompleteMessage }, |
| | 0 | 42 | | { Interop.SECURITY_STATUS.InternalError, SecurityStatusPalErrorCode.InternalError }, |
| | 0 | 43 | | { Interop.SECURITY_STATUS.InvalidHandle, SecurityStatusPalErrorCode.InvalidHandle }, |
| | 0 | 44 | | { Interop.SECURITY_STATUS.InvalidToken, SecurityStatusPalErrorCode.InvalidToken }, |
| | 0 | 45 | | { Interop.SECURITY_STATUS.LogonDenied, SecurityStatusPalErrorCode.LogonDenied }, |
| | 0 | 46 | | { Interop.SECURITY_STATUS.MessageAltered, SecurityStatusPalErrorCode.MessageAltered }, |
| | 0 | 47 | | { Interop.SECURITY_STATUS.MutualAuthFailed, SecurityStatusPalErrorCode.MutualAuthFailed }, |
| | 0 | 48 | | { Interop.SECURITY_STATUS.NoAuthenticatingAuthority, SecurityStatusPalErrorCode.NoAuthenticatingAuthority }, |
| | 0 | 49 | | { Interop.SECURITY_STATUS.NoImpersonation, SecurityStatusPalErrorCode.NoImpersonation }, |
| | 0 | 50 | | { Interop.SECURITY_STATUS.NoCredentials, SecurityStatusPalErrorCode.NoCredentials }, |
| | 0 | 51 | | { Interop.SECURITY_STATUS.NotOwner, SecurityStatusPalErrorCode.NotOwner }, |
| | 0 | 52 | | { Interop.SECURITY_STATUS.OK, SecurityStatusPalErrorCode.OK }, |
| | 0 | 53 | | { Interop.SECURITY_STATUS.OutOfMemory, SecurityStatusPalErrorCode.OutOfMemory }, |
| | 0 | 54 | | { Interop.SECURITY_STATUS.OutOfSequence, SecurityStatusPalErrorCode.OutOfSequence }, |
| | 0 | 55 | | { Interop.SECURITY_STATUS.PackageNotFound, SecurityStatusPalErrorCode.PackageNotFound }, |
| | 0 | 56 | | { Interop.SECURITY_STATUS.QopNotSupported, SecurityStatusPalErrorCode.QopNotSupported }, |
| | 0 | 57 | | { Interop.SECURITY_STATUS.Renegotiate, SecurityStatusPalErrorCode.Renegotiate }, |
| | 0 | 58 | | { Interop.SECURITY_STATUS.SecurityQosFailed, SecurityStatusPalErrorCode.SecurityQosFailed }, |
| | 0 | 59 | | { Interop.SECURITY_STATUS.SmartcardLogonRequired, SecurityStatusPalErrorCode.SmartcardLogonRequired }, |
| | 0 | 60 | | { Interop.SECURITY_STATUS.TargetUnknown, SecurityStatusPalErrorCode.TargetUnknown }, |
| | 0 | 61 | | { Interop.SECURITY_STATUS.TimeSkew, SecurityStatusPalErrorCode.TimeSkew }, |
| | 0 | 62 | | { Interop.SECURITY_STATUS.UnknownCredentials, SecurityStatusPalErrorCode.UnknownCredentials }, |
| | 0 | 63 | | { Interop.SECURITY_STATUS.UnsupportedPreauth, SecurityStatusPalErrorCode.UnsupportedPreauth }, |
| | 0 | 64 | | { Interop.SECURITY_STATUS.Unsupported, SecurityStatusPalErrorCode.Unsupported }, |
| | 0 | 65 | | { Interop.SECURITY_STATUS.UntrustedRoot, SecurityStatusPalErrorCode.UntrustedRoot }, |
| | 0 | 66 | | { Interop.SECURITY_STATUS.WrongPrincipal, SecurityStatusPalErrorCode.WrongPrincipal }, |
| | 0 | 67 | | { Interop.SECURITY_STATUS.NoRenegotiation, SecurityStatusPalErrorCode.NoRenegotiation }, |
| | 0 | 68 | | { Interop.SECURITY_STATUS.KeySetDoesNotExist, SecurityStatusPalErrorCode.KeySetDoesNotExist } |
| | 0 | 69 | | }; |
| | | 70 | | |
| | | 71 | | internal static SecurityStatusPal GetSecurityStatusPalFromNativeInt(int win32SecurityStatus) |
| | 0 | 72 | | { |
| | 0 | 73 | | return GetSecurityStatusPalFromInterop((Interop.SECURITY_STATUS)win32SecurityStatus); |
| | 0 | 74 | | } |
| | | 75 | | |
| | | 76 | | internal static SecurityStatusPal GetSecurityStatusPalFromInterop(Interop.SECURITY_STATUS win32SecurityStatus, b |
| | 0 | 77 | | { |
| | | 78 | | SecurityStatusPalErrorCode statusCode; |
| | | 79 | | |
| | 0 | 80 | | if (!s_statusDictionary.TryGetForward(win32SecurityStatus, out statusCode)) |
| | 0 | 81 | | { |
| | 0 | 82 | | Debug.Fail("Unknown Interop.SecurityStatus value: " + win32SecurityStatus); |
| | | 83 | | throw new InternalException(win32SecurityStatus); |
| | | 84 | | } |
| | | 85 | | |
| | 0 | 86 | | if (attachException) |
| | 0 | 87 | | { |
| | 0 | 88 | | return new SecurityStatusPal(statusCode, new Win32Exception((int)win32SecurityStatus)); |
| | | 89 | | } |
| | | 90 | | else |
| | 0 | 91 | | { |
| | 0 | 92 | | return new SecurityStatusPal(statusCode); |
| | | 93 | | } |
| | 0 | 94 | | } |
| | | 95 | | |
| | | 96 | | internal static Interop.SECURITY_STATUS GetInteropFromSecurityStatusPal(SecurityStatusPal status) |
| | 0 | 97 | | { |
| | | 98 | | Interop.SECURITY_STATUS interopStatus; |
| | 0 | 99 | | if (!s_statusDictionary.TryGetBackward(status.ErrorCode, out interopStatus)) |
| | 0 | 100 | | { |
| | 0 | 101 | | Debug.Fail("Unknown SecurityStatus value: " + status); |
| | | 102 | | throw new InternalException(status.ErrorCode); |
| | | 103 | | } |
| | 0 | 104 | | return interopStatus; |
| | 0 | 105 | | } |
| | | 106 | | } |
| | | 107 | | } |
| | | 108 | | |