Beispiel #1
0
        private void CallSwisscomWsMockAsync(IndexViewModel model, string datenbankBez, string mandantUrl)
        {
            var ctxt = new SessionContext()
            {
                DatenbankId = model.datenbankId,
                Handynummer = model.handynummer,
                IsAdmin     = model.isAdmin,
                Shortname   = model.shortname
            };

            Session["SessionContext"] = ctxt;

            Task.Run(() =>
            {
                var enUs = new CultureInfo("en-us");
                var data = string.Format(
                    "<?xml version='1.0' encoding='utf-8' ?>" +
                    "<data>" +
                    "<user>{0}</user>" +
                    "<database>{1}</database>" +
                    "<module>{2}</module>" +
                    "<timestamp>{3}</timestamp>" +
                    "</data>",
                    model.shortname, datenbankBez, model.module, DateTime.Now.ToString(enUs.DateTimeFormat));

                var entities = new DialogConfigBLEntities();
                using (entities)
                {
                    var token = Convert.ToBase64String(Encoding.UTF8.GetBytes(data));
                    var hash  = Sign(token, _TokenSigningCertificate2);
                    var req   = new MIDRequest()
                    {
                        DatenbankId     = model.datenbankId,
                        Erfolgreich     = true,
                        Handynummer     = model.handynummer,
                        Hash            = hash,
                        IsAdmin         = model.isAdmin,
                        RequestId       = model.requestId,
                        ResponseMessage = "Mobile ID korrekt eingegeben",
                        Shortname       = model.shortname,
                        Status          = "ready",
                        //Url = "http://" + mandantUrl,
                        Url   = mandantUrl.StartsWith("http") ? mandantUrl : "http://" + mandantUrl,
                        Token = token
                    };
                    entities.MIDRequests.Add(req);
                    entities.SaveChanges();
                }
            });
        }
Beispiel #2
0
        private void CallSwisscomWsAsync(IndexViewModel model, string datenbankBez, string mandantUrl)
        {
            if (BypassMobileId)
            {
                CallSwisscomWsMockAsync(model, datenbankBez, mandantUrl);
                return;
            }

            var ctxt = new SessionContext()
            {
                DatenbankId = model.datenbankId,
                Handynummer = model.handynummer,
                IsAdmin     = model.isAdmin,
                Shortname   = model.shortname
            };

            Session["SessionContext"] = ctxt;

            var certDir = Server.MapPath("~/Certificates");

            Task.Run(() =>
            {
                var message = string.Format("DIALOG: {0}", ConfigurationManager.AppSettings["MobileIdText"]);
                var mid     = new SwisscomMobileID(true, true, model.handynummer, message, "de", Server.MapPath("/"), certDir);
                try
                {
                    var entities = new DialogConfigBLEntities();
                    using (entities)
                    {
                        var req = new MIDRequest()
                        {
                            DatenbankId     = model.datenbankId,
                            Erfolgreich     = false,
                            Handynummer     = model.handynummer,
                            Hash            = "",
                            IsAdmin         = model.isAdmin,
                            RequestId       = model.requestId,
                            ResponseMessage = "",
                            Shortname       = model.shortname,
                            Status          = "pending",
                            Url             = "",
                            Token           = ""
                        };
                        entities.MIDRequests.Add(req);
                        entities.SaveChanges();

                        var returnCode = 0;
                        mid.Execute(out returnCode);
                        // ...
                        // ...
                        // ...

                        var q = from x in entities.MIDRequests
                                where x.RequestId == model.requestId
                                select x;
                        if (q.Any())
                        {
                            var x             = q.First();
                            x.Status          = "ready";
                            x.Erfolgreich     = false;
                            x.ResponseMessage = "";
                            //x.Url = "http://" + mandantUrl;
                            x.Url       = mandantUrl.StartsWith("http") ? mandantUrl : "http://" + mandantUrl;
                            x.Shortname = model.shortname;

                            var enUs = new CultureInfo("en-us");
                            var data = string.Format(
                                "<?xml version='1.0' encoding='utf-8' ?>" +
                                "<data>" +
                                "<user>{0}</user>" +
                                "<database>{1}</database>" +
                                "<module>{2}</module>" +
                                "<timestamp>{3}</timestamp>" +
                                "</data>",
                                model.shortname, datenbankBez, model.module, DateTime.Now.ToString(enUs.DateTimeFormat));
                            x.Token       = Convert.ToBase64String(Encoding.UTF8.GetBytes(data));
                            x.Hash        = Sign(x.Token, _TokenSigningCertificate2);
                            x.Handynummer = model.handynummer;
                            x.DatenbankId = model.datenbankId;
                            switch (returnCode)
                            {
                            case RETURN_OK:
                                x.ResponseMessage = "Mobile ID korrekt eingegeben.";
                                x.Erfolgreich     = true;
                                break;

                            case RETURN_REJECT:
                                x.ResponseMessage = "MID Abfrage abgelehnt/storniert.";
                                break;

                            case RETURN_FAIL:
                                x.ResponseMessage = "Ausnahme während der Bearbeitung der Abfrage. Mögliche Ursache: Mobile-ID beim Provider nicht aktiviert.";
                                break;

                            case RETURN_INVALID:
                                x.ResponseMessage = "Ungültige Abfrage/Konfiguration.";
                                break;

                            case RETURN_BLOCKED:
                                x.ResponseMessage = "Benutzer oder Token blockiert.";
                                break;

                            case RETURN_NOTFOUND:
                                x.ResponseMessage = "Benutzer nicht gefunden.";
                                break;
                            }
                            entities.SaveChanges();
                        }
                    }
                }
                catch (Exception ex)
                {
                    var entities = new DialogConfigBLEntities();
                    using (entities)
                    {
                        var q = from x in entities.MIDRequests
                                where x.RequestId == model.requestId
                                select x;
                        if (q.Any())
                        {
                            var x             = q.First();
                            x.Erfolgreich     = false;
                            x.ResponseMessage = "Ausnahme: " + ex.Message;
                            x.Status          = "ready";
                            entities.SaveChanges();
                        }
                    }
                }
            });
        }