public static UsernameToken GetUsernameToken(string username, string password, PasswordOption passwordOption)
        {
            var token = new UsernameToken(username, password, passwordOption);

            var securityTokenManager = SecurityTokenManager.GetSecurityTokenManagerByTokenType(WSTrust.TokenTypes.UsernameToken);

            securityTokenManager.CacheSecurityToken(token);

            return(token);
        }
Beispiel #2
0
        //[System.Web.Services.Protocols.SoapRpcMethod()]
        public string SayHello(string name)
        {
            SoapContext              requestContext  = Microsoft.Web.Services2.RequestSoapContext.Current;
            SoapContext              responseContext = Microsoft.Web.Services2.ResponseSoapContext.Current;
            ISecurityTokenManager    stm             = SecurityTokenManager.GetSecurityTokenManagerByTokenType(WSTrust.TokenTypes.X509v3);
            X509SecurityTokenManager x509tm          = stm as X509SecurityTokenManager;

            x509tm.DefaultSessionKeyAlgorithm = "TripleDES";

            //----------Encryption
            X509SecurityToken x509Token = getToken("client");

            if (x509Token == null)
            {
                //throw new SecurityFault(SecurityFault.FailedAuthenticationMessage, SecurityFault.FailedAuthenticationCode);
                throw new SecurityFault("Could not get encryption token...", SecurityFault.FailedAuthenticationCode);
            }
            else
            {
                EncryptedData ed = new EncryptedData(x509Token);
                responseContext.Security.Tokens.Add(x509Token);
                responseContext.Security.Elements.Add(ed);
            }

            //---------UsernameToken
//			UsernameToken usernameToken = GetSigningToken() as UsernameToken;
//			if (usernameToken == null || usernameToken.PasswordOption == PasswordOption.SendPlainText) {
//				throw new SecurityFault(SecurityFault.FailedAuthenticationMessage, SecurityFault.FailedAuthenticationCode);
//			}
//
            //---------Signature
//			//X509SecurityToken
            x509Token = getToken("server");
            X509SecurityToken x509TokenSigningToken = GetSigningToken() as X509SecurityToken;

            if (x509TokenSigningToken == null)               //|| !CompareArray(x509TokenSigningToken.KeyIdentifier.Value, Convert.FromBase64String(clientKeyIdentifier))) {
            {
                throw new SecurityFault("Could not get signing token...", SecurityFault.FailedAuthenticationCode);
            }
            else
            {
                responseContext.Security.Tokens.Add(x509Token);
                responseContext.Security.Elements.Add(new MessageSignature(x509Token));
            }

            return("Hello," + name);
        }
Beispiel #3
0
        public void Run()
        {
            //WebServiceProxy.Service1 proxy = new WebServiceProxy.Service1();
            WebServiceProxy.Service1Wse proxy = new WebServiceProxy.Service1Wse();

            ISecurityTokenManager    stm    = SecurityTokenManager.GetSecurityTokenManagerByTokenType(WSTrust.TokenTypes.X509v3);
            X509SecurityTokenManager x509tm = stm as X509SecurityTokenManager;

            x509tm.DefaultSessionKeyAlgorithm = "TripleDES";

            //------Encryption
//			X509SecurityToken  token = getToken("server");
//			if (token == null)	throw new ApplicationException("Unable to obtain security token.");
//			EncryptedData ed = new EncryptedData(token);
//			proxy.RequestSoapContext.Security.Tokens.Add(token);
//			proxy.RequestSoapContext.Security.Elements.Add(ed);

            X509SecurityToken token = getToken("client");

            if (token == null)
            {
                throw new ApplicationException("Unable to obtain security token.");
            }
            proxy.RequestSoapContext.Security.Tokens.Add(token);
            proxy.RequestSoapContext.Security.Elements.Add(new MessageSignature(token));

            //------Username
//			string username      = Environment.UserName;
//			Console.Write("Passwort for '" + username + "': ");
//			string password = Console.ReadLine();
//			byte[] passwordBytes = System.Text.Encoding.UTF8.GetBytes(password);
//			//Array.Reverse(passwordBytes);
//
//			//string passwordEquivalent = Convert.ToBase64String( passwordBytes );
//			UsernameToken token = new UsernameToken( username, password, PasswordOption.SendHashed );
//			proxy.RequestSoapContext.Security.Tokens.Add(token);
//
//			//------Signature
//			proxy.RequestSoapContext.Security.Elements.Add( new MessageSignature( token ) );

            Console.WriteLine("Ausgabe: " + proxy.SayHello("test"));
        }