示例#1
0
 public RpcAcceptedReplyHeader(XdrDataReader reader)
 {
     Verifier     = new RpcAuthentication(reader);
     AcceptStatus = (RpcAcceptStatus)reader.ReadInt32();
     if (AcceptStatus == RpcAcceptStatus.ProgramVersionMismatch)
     {
         MismatchInfo = new RpcMismatchInfo(reader);
     }
 }
 public RpcAcceptedReplyHeader(XdrDataReader reader)
 {
     Verifier = new RpcAuthentication(reader);
     AcceptStatus = (RpcAcceptStatus)reader.ReadInt32();
     if (AcceptStatus == RpcAcceptStatus.ProgramVersionMismatch)
     {
         MismatchInfo = new RpcMismatchInfo(reader);
     }
 }
        private static bool ServerRegisterAuthInfo(RpcAuthentication auth, string serverPrincName)
        {
            Log.Verbose("ServerRegisterAuthInfo({0})", auth);
            RpcError response = RpcServerRegisterAuthInfo(serverPrincName, (uint)auth, IntPtr.Zero, IntPtr.Zero);

            if (response != RpcError.RPC_S_OK)
            {
                Log.Warning("ServerRegisterAuthInfo - unable to register authentication type {0}", auth);
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// Adds authentication information to the client, use the static Self to
        /// authenticate as the currently logged on Windows user.
        /// </summary>
        public void AuthenticateAs(string serverPrincipalName, NetworkCredential credentials)
        {
            RpcAuthentication[] types   = new RpcAuthentication[] { RpcAuthentication.RPC_C_AUTHN_GSS_NEGOTIATE, RpcAuthentication.RPC_C_AUTHN_WINNT };
            RpcProtectionLevel  protect = RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY;

            bool isAnon = (credentials != null && credentials.UserName == Anonymous.UserName && credentials.Domain == Anonymous.Domain);

            if (isAnon)
            {
                protect = RpcProtectionLevel.RPC_C_PROTECT_LEVEL_DEFAULT;
                types   = new RpcAuthentication[] { RpcAuthentication.RPC_C_AUTHN_NONE };
            }

            AuthenticateAs(serverPrincipalName, credentials, protect, types);
        }
示例#5
0
        public void AuthenticateAs(string serverPrincipalName, NetworkCredential credentials)
        {
            RpcAuthentication[] rpcAuthenticationArray = new RpcAuthentication[2]
            {
                RpcAuthentication.RPC_C_AUTHN_GSS_NEGOTIATE,
                RpcAuthentication.RPC_C_AUTHN_WINNT
            };
            RpcProtectionLevel level = RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY;

            if (credentials != null && credentials.UserName == RpcClientApi.Anonymous.UserName && credentials.Domain == RpcClientApi.Anonymous.Domain)
            {
                level = RpcProtectionLevel.RPC_C_PROTECT_LEVEL_DEFAULT;
                rpcAuthenticationArray = new RpcAuthentication[1];
                credentials            = (NetworkCredential)null;
            }
            this.AuthenticateAs(serverPrincipalName, credentials, level, rpcAuthenticationArray);
        }
示例#6
0
        public void RoundTripTest()
        {
            RpcAuthentication authentication = new RpcAuthentication();

            RpcAuthentication clone = null;

            using (MemoryStream stream = new MemoryStream())
            {
                XdrDataWriter writer = new XdrDataWriter(stream);
                authentication.Write(writer);

                stream.Position = 0;
                XdrDataReader reader = new XdrDataReader(stream);
                clone = new RpcAuthentication(reader);
            }

            Assert.Equal(authentication, clone);
        }
示例#7
0
        static void ReversePingTest(RpcProtseq protocol, string[] hostNames, string endpoint, RpcAuthentication auth)
        {
            Guid iid = Guid.NewGuid();
            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.OnExecute += 
                    delegate(IRpcClientInfo client, byte[] arg)
                    {
                        Array.Reverse(arg);
                        return arg;
                    };

                server.AddProtocol(protocol, endpoint, 5);
                server.AddAuthentication(auth);
                server.StartListening();

                byte[] input = Encoding.ASCII.GetBytes("abc");
                byte[] expect = Encoding.ASCII.GetBytes("cba");

                foreach (string hostName in hostNames)
                {
                    using (RpcClientApi client = new RpcClientApi(iid, protocol, hostName, endpoint))
                    {
                        client.AuthenticateAs(null, auth == RpcAuthentication.RPC_C_AUTHN_NONE
                                                      ? RpcClientApi.Anonymous
                                                      : RpcClientApi.Self, 
                                                  auth == RpcAuthentication.RPC_C_AUTHN_NONE
                                                      ? RpcProtectionLevel.RPC_C_PROTECT_LEVEL_NONE
                                                      : RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY,
                                                  auth);

                        Assert.AreEqual(expect, client.Execute(input));
                    }
                }
            }
        }
示例#8
0
 public Win32RpcServer AddAuthentication(RpcAuthentication auth)
 {
     _server.AddAuthentication(auth, ServerPrincipalName);
     return(this);
 }
 /// <summary>
 /// Adds a type of authentication sequence that will be allowed for RPC connections to this process.
 /// </summary>
 public bool AddAuthentication(RpcAuthentication type, string serverPrincipalName)
 {
     return(ServerRegisterAuthInfo(type, serverPrincipalName));
 }
 /// <summary>
 /// Adds a type of authentication sequence that will be allowed for RPC connections to this process.
 /// </summary>
 public bool AddAuthentication(RpcAuthentication type)
 {
     return(AddAuthentication(type, null));
 }
示例#11
0
 private static extern RpcError RpcBindingSetAuthInfo2(IntPtr Binding, String ServerPrincName,
                                                       RpcProtectionLevel AuthnLevel, RpcAuthentication AuthnSvc,
                                                       IntPtr p, uint AuthzSvc);
示例#12
0
 private static extern RpcError RpcBindingSetAuthInfo(IntPtr Binding, String ServerPrincName,
                                                      RpcProtectionLevel AuthnLevel, RpcAuthentication AuthnSvc,
                                                      [In] ref SEC_WINNT_AUTH_IDENTITY AuthIdentity,
                                                      uint AuthzSvc);
 /// <summary>
 /// Adds a type of authentication sequence that will be allowed for RPC connections to this process.
 /// </summary>
 public bool AddAuthentication(RpcAuthentication type)
 {
     return AddAuthentication(type, null);
 }
 private static bool ServerRegisterAuthInfo(RpcAuthentication auth, string serverPrincName)
 {
     Log.Verbose("ServerRegisterAuthInfo({0})", auth);
     RpcError response = RpcServerRegisterAuthInfo(serverPrincName, (uint) auth, IntPtr.Zero, IntPtr.Zero);
     if (response != RpcError.RPC_S_OK)
     {
         Log.Warning("ServerRegisterAuthInfo - unable to register authentication type {0}", auth);
         return false;
     }
     return true;
 }
 /// <summary>
 /// Adds a type of authentication sequence that will be allowed for RPC connections to this process.
 /// </summary>
 public bool AddAuthentication(RpcAuthentication type, string serverPrincipalName)
 {
     return ServerRegisterAuthInfo(type, serverPrincipalName);
 }
示例#16
0
 public Win32RpcServer AddAuthentication(RpcAuthentication auth)
 {
     _server.AddAuthentication(auth, ServerPrincipalName);
     return this;
 }
        static void ReversePingTest(RpcProtseq protocol, string[] hostNames, string endpoint, RpcAuthentication auth)
        {
            Guid iid = Guid.NewGuid();

            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.OnExecute +=
                    delegate(IRpcClientInfo client, byte[] arg)
                {
                    Array.Reverse(arg);
                    return(arg);
                };

                server.AddProtocol(protocol, endpoint, 5);
                server.AddAuthentication(auth);
                server.StartListening();

                byte[] input  = Encoding.ASCII.GetBytes("abc");
                byte[] expect = Encoding.ASCII.GetBytes("cba");

                foreach (string hostName in hostNames)
                {
                    using (RpcClientApi client = new RpcClientApi(iid, protocol, hostName, endpoint))
                    {
                        client.AuthenticateAs(null, auth == RpcAuthentication.RPC_C_AUTHN_NONE
                                                      ? RpcClientApi.Anonymous
                                                      : RpcClientApi.Self,
                                              auth == RpcAuthentication.RPC_C_AUTHN_NONE
                                                      ? RpcProtectionLevel.RPC_C_PROTECT_LEVEL_NONE
                                                      : RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY,
                                              auth);

                        Assert.AreEqual(expect, client.Execute(input));
                    }
                }
            }
        }
        /// <summary>
        /// Adds authentication information to the client, use the static Self to
        /// authenticate as the currently logged on Windows user.
        /// </summary>
        public void AuthenticateAs(string serverPrincipalName, NetworkCredential credentials)
        {
            RpcAuthentication[] types = new RpcAuthentication[] { RpcAuthentication.RPC_C_AUTHN_GSS_NEGOTIATE, RpcAuthentication.RPC_C_AUTHN_WINNT };
            RpcProtectionLevel protect = RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY;

            bool isAnon = (credentials != null && credentials.UserName == Anonymous.UserName && credentials.Domain == Anonymous.Domain);
            if (isAnon)
            {
                protect = RpcProtectionLevel.RPC_C_PROTECT_LEVEL_DEFAULT;
                types = new RpcAuthentication[] { RpcAuthentication.RPC_C_AUTHN_NONE };
                credentials = null;
            }

            AuthenticateAs(serverPrincipalName, credentials, protect, types);
        }
 private static void BindingSetAuthInfo(RpcProtectionLevel level, RpcAuthentication[] authTypes, 
     RpcHandle handle, string serverPrincipalName, NetworkCredential credentails)
 {
     if (credentails == null)
     {
         foreach (RpcAuthentication atype in authTypes)
         {
             RpcError result = RpcBindingSetAuthInfo2(handle.Handle, serverPrincipalName, level, atype, IntPtr.Zero, 0);
             if (result != RpcError.RPC_S_OK)
                 Log.Warning("Unable to register {0}, result = {1}", atype, new RpcException(result).Message);
         }
     }
     else
     {
         SEC_WINNT_AUTH_IDENTITY pSecInfo = new SEC_WINNT_AUTH_IDENTITY(credentails);
         foreach (RpcAuthentication atype in authTypes)
         {
             RpcError result = RpcBindingSetAuthInfo(handle.Handle, serverPrincipalName, level, atype, ref pSecInfo, 0);
             if (result != RpcError.RPC_S_OK)
                 Log.Warning("Unable to register {0}, result = {1}", atype, new RpcException(result).Message);
         }
     }
 }
 private static extern RpcError RpcBindingSetAuthInfo2(IntPtr Binding, String ServerPrincName,
                                                       RpcProtectionLevel AuthnLevel, RpcAuthentication AuthnSvc,
                                                       IntPtr p, uint AuthzSvc);
 private static extern RpcError RpcBindingSetAuthInfo(IntPtr Binding, String ServerPrincName,
                                                      RpcProtectionLevel AuthnLevel, RpcAuthentication AuthnSvc,
                                                      [In] ref SEC_WINNT_AUTH_IDENTITY AuthIdentity,
                                                      uint AuthzSvc);