Beispiel #1
0
        public override Dictionary <string, string> Answer(byte[] secret)
        {
            byte[] mac_key = DiffieHellmanUtil.SHAHashXorSecret(DiffieHellmanUtil.Lookup(Protocol, SessionType),
                                                                dh, consumerPublicKey, secret);
            var nvc = new Dictionary <string, string>();

            nvc.Add(Protocol.openidnp.dh_server_public, DiffieHellmanUtil.UnsignedToBase64(dh.CreateKeyExchange()));
            nvc.Add(Protocol.openidnp.enc_mac_key, Convert.ToBase64String(mac_key));

            return(nvc);
        }
        void initializeAssociation()
        {
            string assoc_type = Util.GetRequiredArg(Args, Protocol.openidnp.assoc_type);

            if (Array.IndexOf(Protocol.Args.SignatureAlgorithm.All, assoc_type) >= 0)
            {
                byte[] secret;

                string session_type;
                if (!Args.TryGetValue(Protocol.openidnp.session_type, out session_type) ||
                    Protocol.Args.SessionType.NoEncryption.Equals(session_type, StringComparison.Ordinal))
                {
                    secret = getDecoded(Protocol.openidnp.mac_key);
                }
                else
                {
                    try {
                        byte[] dh_server_public = getDecoded(Protocol.openidnp.dh_server_public);
                        byte[] enc_mac_key      = getDecoded(Protocol.openidnp.enc_mac_key);
                        secret = DiffieHellmanUtil.SHAHashXorSecret(DiffieHellmanUtil.Lookup(Protocol, session_type), DH, dh_server_public, enc_mac_key);
                    } catch (ArgumentException ex) {
                        throw new OpenIdException(string.Format(CultureInfo.CurrentCulture,
                                                                Strings.InvalidOpenIdQueryParameterValue,
                                                                Protocol.openid.session_type, session_type), ex);
                    }
                }

                string   assocHandle = Util.GetRequiredArg(Args, Protocol.openidnp.assoc_handle);
                TimeSpan expiresIn   = new TimeSpan(0, 0, Convert.ToInt32(Util.GetRequiredArg(Args, Protocol.openidnp.expires_in), CultureInfo.InvariantCulture));

                try {
                    Association = HmacShaAssociation.Create(Protocol, assoc_type,
                                                            assocHandle, secret, expiresIn);
                } catch (ArgumentException ex) {
                    throw new OpenIdException(string.Format(CultureInfo.CurrentCulture,
                                                            Strings.InvalidOpenIdQueryParameterValue,
                                                            Protocol.openid.assoc_type, assoc_type), ex);
                }
            }
            else
            {
                throw new OpenIdException(string.Format(CultureInfo.CurrentCulture,
                                                        Strings.InvalidOpenIdQueryParameterValue,
                                                        Protocol.openid.assoc_type, assoc_type));
            }
        }