public AuthenticationResponse Authenticate(string authmethod, ChallengeDetails extra)
        {
            if (authmethod == WAMP_CRA)
            {
                WampCraChallengeDetails challengeDetails =
                    extra.OriginalValue.Deserialize <WampCraChallengeDetails>();

                string signature;

                if (challengeDetails.Salt == null)
                {
                    signature =
                        WampCraHelpers.Sign(mAuthenticationKey,
                                            challengeDetails.Challenge);
                }
                else
                {
                    signature =
                        WampCraHelpers.AuthSignature(challengeDetails.Challenge,
                                                     mSecret,
                                                     challengeDetails);
                }

                AuthenticationResponse result =
                    new AuthenticationResponse {
                    Signature = signature
                };

                return(result);
            }
            else
            {
                throw new WampAuthenticationException("don't know how to authenticate using '" + authmethod + "'");
            }
        }
 /// <summary>
 /// Initializes a new instance of a <see cref="WampCraClientAuthenticator"/>.
 /// </summary>
 /// <param name="authenticationId">The authentication id to use (for example, the user name)</param>
 /// <param name="secret">The secret to use.</param>
 /// <param name="salt">The salt to use.</param>
 /// <param name="iterations">The number of iterations to use (default value = 1000).</param>
 /// <param name="keyLen">The key length to use (default value = 32).</param>
 public WampCraClientAuthenticator(string authenticationId,
                                   string secret,
                                   string salt    = null,
                                   int?iterations = null,
                                   int?keyLen     = null)
 {
     mSecret            = secret;
     AuthenticationId   = authenticationId;
     mAuthenticationKey = WampCraHelpers.DeriveKey(secret, salt, iterations, keyLen);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Authenticate the WAMP session to server.
        /// </summary>
        /// <param name="proxy">The proxy.</param>
        /// <param name="formatter">The formatter.</param>
        /// <param name="authKey">The key of the authentication credentials, something like a user or
        /// application name.</param>
        /// <param name="authExtra">Any extra authentication information.</param>
        /// <param name="authSecret">The secret of the authentication credentials, something like the user
        /// password or application secret key.</param>
        /// <returns>The WampCraPermissions.</returns>
        static WampCraPermissions Authenticate(IWampCraProcedures proxy, IWampFormatter <JToken> formatter, string authKey, IDictionary <string, string> authExtra, string authSecret)
        {
            string challenge = proxy.AuthReq(authKey, authExtra);

            if (string.IsNullOrEmpty(authKey))
            {
                return(proxy.Auth(null));
            }
            WampCraChallenge info = formatter.Deserialize <WampCraChallenge>(JObject.Parse(challenge));
            string           sig  = WampCraHelpers.AuthSignature(challenge, authSecret, info.authextra);

            return(proxy.Auth(sig));
        }
        public override void Authenticate(string signature, AuthenticateExtraData extra)
        {
            string computedSignature =
                WampCraHelpers.Sign(Secret, AuthenticationChallenge);

            if (computedSignature == signature)
            {
                IsAuthenticated = true;
            }
            else
            {
                throw new WampAuthenticationException("signature is invalid",
                                                      WampErrors.NotAuthorized);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// RPC endpoint for clients to initiate the authentication handshake.
        /// </summary>
        /// <seealso cref="M:WampSharp.Cra.IWampCraProcedures.AuthReq(string,IDictionary{string,string})"/>
        public string AuthReq(string authKey, IDictionary <string, string> extra)
        {
            ValidateAuthReqStatus(authKey);

            string authSecret = GetAuthReqSecret(authKey);

            // each authentication request gets a unique authid, which can only be used (later) once!
            string authid = mIdGenerator.Generate();

            //check extra
            if (extra == null)
            {
                extra = new Dictionary <string, string>();
            }

            Dictionary <string, string> extraAuth = new Dictionary <string, string>(extra);

            WampCraPermissions permissions = GetAuthReqPermissions(authKey, extraAuth);

            WampCraChallenge info =
                new WampCraChallenge(authid, authKey, DateTime.UtcNow, mClientSessionId, extra, permissions, extraAuth);

            mAuthKey = authKey;

            if (string.IsNullOrEmpty(authKey))
            {
                // anonymous session
                mPendingAuth = new WampCraPendingAuth(info, null, permissions);
                return(null);
            }

            // authenticated session
            string infoser = mFormatter.Serialize(info).ToString();
            string sig     = WampCraHelpers.AuthSignature(infoser, authSecret, info.authextra);

            mPendingAuth = new WampCraPendingAuth(info, sig, permissions);
            return(infoser);
        }