Exemplo n.º 1
0
        internal static unsafe SecurityCredentials CreateFromNative(NativeTypes.FABRIC_SECURITY_CREDENTIALS *nativeCredentials)
        {
            SecurityCredentials managedCredentials = null;

            switch (nativeCredentials->Kind)
            {
            case NativeTypes.FABRIC_SECURITY_CREDENTIAL_KIND.FABRIC_SECURITY_CREDENTIAL_KIND_CLAIMS:
                managedCredentials = ClaimsCredentials.CreateFromNative((NativeTypes.FABRIC_CLAIMS_CREDENTIALS *)nativeCredentials->Value);
                break;

            case NativeTypes.FABRIC_SECURITY_CREDENTIAL_KIND.FABRIC_SECURITY_CREDENTIAL_KIND_WINDOWS:
                managedCredentials = WindowsCredentials.CreateFromNative((NativeTypes.FABRIC_WINDOWS_CREDENTIALS *)nativeCredentials->Value);
                break;

            case NativeTypes.FABRIC_SECURITY_CREDENTIAL_KIND.FABRIC_SECURITY_CREDENTIAL_KIND_X509:
                managedCredentials = X509Credentials.CreateFromNative((NativeTypes.FABRIC_X509_CREDENTIALS *)nativeCredentials->Value);
                break;

            case NativeTypes.FABRIC_SECURITY_CREDENTIAL_KIND.FABRIC_SECURITY_CREDENTIAL_KIND_NONE:
                managedCredentials = NoneSecurityCredentials.CreateFromNative();
                break;

            default:
                AppTrace.TraceSource.WriteError("SecurityCredentials.FromNative", "Unknown credential type: {0}", nativeCredentials->Kind);
                ReleaseAssert.Failfast("Unknown credential type: {0}", nativeCredentials->Kind);
                break;
            }

            return(managedCredentials);
        }
Exemplo n.º 2
0
        internal static unsafe X509Credentials CreateFromNative(NativeTypes.FABRIC_X509_CREDENTIALS *nativeCredentials)
        {
            X509Credentials managedCredentials = new X509Credentials();

            managedCredentials.FindType = CreateFromNative(nativeCredentials->FindType);

            // The only supported find values are currently of type string
            managedCredentials.FindValue = NativeTypes.FromNativeString(nativeCredentials->FindValue);

            managedCredentials.ProtectionLevel = CreateFromNative(nativeCredentials->ProtectionLevel);

            managedCredentials.StoreLocation = CreateFromNative(nativeCredentials->StoreLocation);

            managedCredentials.StoreName = NativeTypes.FromNativeString(nativeCredentials->StoreName);
            Requires.Argument <object>("StoreName", managedCredentials.StoreName).NotNullOrEmpty();

            var remoteCommonNames = new ItemList <string>();

            for (int i = 0; i < nativeCredentials->RemoteCommonNameCount; i++)
            {
                IntPtr location = nativeCredentials->RemoteCommonNames + (i * IntPtr.Size);
                IntPtr value    = *((IntPtr *)location);
                remoteCommonNames.Add(NativeTypes.FromNativeString(value));
            }
            managedCredentials.RemoteCommonNames = remoteCommonNames;

            if (nativeCredentials->Reserved == IntPtr.Zero)
            {
                return(managedCredentials);
            }

            NativeTypes.FABRIC_X509_CREDENTIALS_EX1 *x509Ex1 = (NativeTypes.FABRIC_X509_CREDENTIALS_EX1 *)(nativeCredentials->Reserved);

            var issuerThumbprints = new ItemList <string>();

            for (int i = 0; i < x509Ex1->IssuerThumbprintCount; i++)
            {
                IntPtr location = x509Ex1->IssuerThumbprints + (i * IntPtr.Size);
                IntPtr value    = *((IntPtr *)location);
                issuerThumbprints.Add(NativeTypes.FromNativeString(value));
            }
            managedCredentials.IssuerThumbprints = issuerThumbprints;

            if (x509Ex1->Reserved == IntPtr.Zero)
            {
                return(managedCredentials);
            }

            NativeTypes.FABRIC_X509_CREDENTIALS_EX2 *x509Ex2 = (NativeTypes.FABRIC_X509_CREDENTIALS_EX2 *)(x509Ex1->Reserved);
            var remoteCertThumbprints = new ItemList <string>();

            for (int i = 0; i < x509Ex2->RemoteCertThumbprintCount; ++i)
            {
                IntPtr location = x509Ex2->RemoteCertThumbprints + (i * IntPtr.Size);
                IntPtr value    = *((IntPtr *)location);
                remoteCertThumbprints.Add(NativeTypes.FromNativeString(value));
            }
            managedCredentials.RemoteCertThumbprints = remoteCertThumbprints;

            NativeTypes.FABRIC_X509_NAME *x509Names = (NativeTypes.FABRIC_X509_NAME *)(x509Ex2->RemoteX509Names);
            for (int i = 0; i < x509Ex2->RemoteX509NameCount; ++i)
            {
                managedCredentials.RemoteX509Names.Add(new X509Name(
                                                           NativeTypes.FromNativeString(x509Names[i].Name),
                                                           NativeTypes.FromNativeString(x509Names[i].IssuerCertThumbprint)));
            }

            managedCredentials.FindValueSecondary = NativeTypes.FromNativeString(x509Ex2->FindValueSecondary);

            if (x509Ex2->Reserved == IntPtr.Zero)
            {
                return(managedCredentials);
            }

            NativeTypes.FABRIC_X509_CREDENTIALS_EX3 *x509Ex3     = (NativeTypes.FABRIC_X509_CREDENTIALS_EX3 *)(x509Ex2->Reserved);
            NativeTypes.FABRIC_X509_ISSUER_NAME *    x509Issuers = (NativeTypes.FABRIC_X509_ISSUER_NAME *)(x509Ex3->RemoteCertIssuers);
            for (int i = 0; i < x509Ex3->RemoteCertIssuerCount; ++i)
            {
                var issuerStores = new ItemList <string>();
                for (int j = 0; j < x509Issuers[i].IssuerStoreCount; ++j)
                {
                    IntPtr location = x509Issuers[i].IssuerStores + (j * IntPtr.Size);
                    IntPtr value    = *((IntPtr *)location);
                    issuerStores.Add(NativeTypes.FromNativeString(value));
                }

                managedCredentials.RemoteCertIssuers.Add(new X509IssuerStore(
                                                             NativeTypes.FromNativeString(x509Issuers[i].Name),
                                                             issuerStores));
            }

            return(managedCredentials);
        }
 internal NativeX509CredentialConverter(X509Credentials x509Credentials)
 {
     this.x509Credentials = x509Credentials;
 }