33. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 6/5/2019 9:23:28 PM Eastern Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

33.1 Files compared

# Location File Last Modified
1 VSE_P2_v2_1_0_iter_11.zip\ClinSchd\Desktop\ClinSchd.Infrastructure\SSOi GetSSOiToken.cs Thu May 30 18:19:42 2019 UTC
2 VSE_P2_v2_1_0_iter_11.zip\ClinSchd\Desktop\ClinSchd.Infrastructure\SSOi GetSSOiToken.cs Tue Jun 4 20:07:18 2019 UTC

33.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 3 598
Changed 2 4
Inserted 0 0
Removed 0 0

33.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

33.4 Active regular expressions

No regular expressions were active.

33.5 Comparison detail

  1   using Syst em;
  2  
  3   using Syst em.IO;
  4   using Syst em.Net;
  5   using Syst em.Net.Net workInform ation;
  6   using Syst em.Reflect ion;
  7   using Syst em.Securit y.Cryptogr aphy.X509C ertificate s;
  8   using Syst em.Windows .Forms;
  9   using Syst em.Xml;
  10   using Syst em.Xml.Sch ema;
  11  
  12  
  13   namespace  ClinSchd.I nfrastruct ure.SSOi
  14   {
  15       public  class Get SSOiToken
  16       {
  17           pu blic stati c string G etSAML()
  18           {
  19                System.N et.Service PointManag er.Securit yProtocol  = (Securit yProtocolT ype)768 |  (SecurityP rotocolTyp e)3072;
  20                HttpWebR equest req  = CreateW ebRequest( get509Cert ificate()) ;
  21                return G etSTSRespo nse(req);
  22           }
  23           // / <summary >
  24           // / Returnin g a SAML w ith a spec fic certif icate sele cted by th e user
  25           // / </summar y>
  26           // / <returns ></returns >
  27           pu blic stati c string G etSAML(Str ing serial )
  28           {
  29                System.N et.Service PointManag er.Securit yProtocol  = (Securit yProtocolT ype)768 |  (SecurityP rotocolTyp e)3072;              
  30                HttpWebR equest req  = CreateW ebRequest( get509Cert ificate(se rial));
  31                return G etSTSRespo nse(req);
  32           }
  33  
  34           pr ivate stat ic string  GetSTSResp onse(HttpW ebRequest  req)
  35           {
  36                string s oapresult;
  37                Cursor.C urrent = C ursors.Wai tCursor;
  38                try
  39                {
  40                    usin g (WebResp onse respo nse = req. GetRespons e())
  41                    {
  42                         XmlReaderS ettings xs dSettings  = new XmlR eaderSetti ngs
  43                         {
  44                             Valida tionType =  Validatio nType.Sche ma,
  45                             DtdPro cessing =  DtdProcess ing.Prohib it
  46                         };
  47  
  48                         xsdSetting s.Validati onFlags |=  XmlSchema Validation Flags.Proc essSchemaL ocation;
  49                         Assembly a  = Assembl y.GetExecu tingAssemb ly();
  50                         Stream str eam = a.Ge tManifestR esourceStr eam("ClinS chd.Infras tructure.S SOi.SAML.x sd");
  51  
  52                         if (stream  != null)
  53                         {
  54                             XmlSch ema x = Xm lSchema.Re ad(stream,  STSRespon seEventHan dler);
  55   #pragma wa rning disa ble 618
  56                             x.Comp ile(STSRes ponseEvent Handler, n ew XmlUrlR esolverHel per(a, "Cl inSchd.Inf rastructur e.SSOi"));
  57   #pragma wa rning rest ore 618
  58  
  59                             xsdSet tings.Sche mas.Add(x) ;
  60                         }
  61  
  62                         using (Xml Reader rd  = XmlReade r.Create(r esponse.Ge tResponseS tream(), x sdSettings ))
  63                         {
  64                             XmlDoc ument xdoc  = new Xml Document() ;
  65                             xdoc.L oad(rd);
  66  
  67                             soapre sult = xdo c.InnerXml ;
  68                             soapre sult = soa presult.Re place("\r" , "");
  69                             soapre sult = soa presult.Re place("\n" , "");
  70                             soapre sult = soa presult.Re place("\r\ n", "");
  71                         }
  72                    }
  73                }
  74                catch (E xception e )
  75                {
  76                    //FF  - 10/18/2 018 - Comm enting out  line to s uprerss Fo rtify Low  warning -   Using Wri teLine() r ather than  a dedicat ed logging  facility  makes it d ifficult t o monitor  the behavi or of the  program.
  77                    //Co nsole.Writ eLine(e);
  78                    Curs or.Current  = Cursors .Default;
  79                    retu rn e.Messa ge;
  80                }
  81                Cursor.C urrent = C ursors.Def ault;
  82                return s oapresult;
  83           }
  84  
  85           pr ivate stat ic void ST SResponseE ventHandle r(object s ender, Val idationEve ntArgs e)
  86           {
  87                TraceLog .LogExcept ion("GetSS OiToken",  "GetSTSRes ponse", e. Exception) ;
  88           }
  89  
  90           pu blic stati c bool isS AMLValid(S tring saml )
  91           {
  92                if (saml .Contains( "<X509Cert ificate>")  &&
  93                    saml .Contains( "saml:Asse rtion") &&
  94                    saml .Contains( "SECID"))
  95                {
  96                    //SA ML is prop erly forme d
  97                    retu rn true;
  98                }
  99                else
  100                {
  101                    retu rn false;
  102                }
  103  
  104           }
  105           pr ivate stat ic X509Cer tificate2  get509Cert ificate()
  106           {
  107                X509Cert ificate2Co llection c ertColl;
  108                var stor e = Open50 9Store(out  certColl) ;
  109  
  110                foreach  (X509Certi ficate2 xc ert in sto re.Certifi cates)
  111                {
  112                    if ( xcert.Frie ndlyName.C ontains("P IV Authent ication"))
  113                    {
  114                         certColl.A dd(xcert);
  115                    }
  116                }
  117                try
  118                {
  119                    X509 Certificat e2 cert =  certColl[0 ];
  120                    retu rn cert;
  121                }
  122                catch (E xception e )
  123                {
  124                    //FF  - 10/17/2 018 - Comm enting out  line to s uprerss Fo rtify Low  warning -   Using Wri teLine() r ather than  a dedicat ed logging  facility  makes it d ifficult t o monitor  the behavi or of the  program.
  125                    //Co nsole.Writ eLine(e);
  126  
  127                    X509 Certificat e2 emptyCe rt = new X 509Certifi cate2();
  128                    retu rn emptyCe rt;
  129                }
  130           
  131           }
  132           pr ivate stat ic X509Cer tificate2  get509Cert ificate(st ring seria l)
  133           {
  134                X509Cert ificate2Co llection c ertColl;
  135                var stor e = Open50 9Store(out  certColl) ;
  136  
  137                foreach  (X509Certi ficate2 xc ert in sto re.Certifi cates)
  138                {
  139                    if ( xcert.Seri alNumber = = serial)
  140                    {
  141                         certColl.A dd(xcert);
  142                    }
  143                }
  144                try
  145                {
  146                    X509 Certificat e2 cert =  certColl[0 ];
  147                    retu rn cert;
  148                }
  149                catch (E xception)
  150                {
  151                    //FF  - 10/18/2 018 - Comm enting out  line to s uprerss Fo rtify Low  warning -   Using Wri teLine() r ather than  a dedicat ed logging  facility  makes it d ifficult t o monitor  the behavi or of the  program.
  152                    //Co nsole.Writ eLine(e);
  153                    X509 Certificat e2 emptyCe rt = new X 509Certifi cate2();
  154                    retu rn emptyCe rt;
  155                }
  156  
  157           }
  158           pr ivate stat ic X509Sto re Open509 Store(out  X509Certif icate2Coll ection cer tColl)
  159           {
  160                X509Stor e store =  new X509St ore("My",  StoreLocat ion.Curren tUser);
  161                store.Op en(OpenFla gs.ReadOnl y);
  162                certColl  = new X50 9Certifica te2Collect ion();
  163                return s tore;
  164           }
  165  
  166           pu blic stati c X509Cert ificate2Co llection G etAllCerti ficates()
  167           {
  168                X509Cert ificate2Co llection c ertCollect ion = new  X509Certif icate2Coll ection();
  169                X509Stor e store =  new X509St ore("My",  StoreLocat ion.Curren tUser);
  170                store.Op en(OpenFla gs.ReadOnl y);
  171    
  172                foreach  (X509Certi ficate2 xc ert in sto re.Certifi cates)
  173                {
  174                    if ( xcert.Seri alNumber ! = null)
  175                    {
  176                         certCollec tion.Add(x cert);                    
  177                    }
  178                    
  179                }
  180  
  181                return c ertCollect ion;
  182           }
  183  
  184           pr ivate stat ic HttpWeb Request Cr eateWebReq uest(X509C ertificate 2 cert)
  185           {
  186                HttpWebR equest req  = null;
  187                try
  188                {
  189                      req = (Htt pWebReques t)WebReque st.Create( "https:// DNS . URL : PORT /STS/Reque stSecurity Token");
  190                }
  191                catch (W ebExceptio n e)
  192                {
  193                    Trac eLog.LogEx ception("C linSchd.In frastructu re.SSOi.Ge tSSOiToken ", "Create WebRequest ", e);
  194                }
  195  
  196                //*zeb 8 65550 11/2 7/18 fail  over to ac cess and v erify code s if SSOi  is not ava ilable
  197                if (req  != null)
  198                {
  199                    req. ClientCert ificates.A dd(cert);
  200                    req. Headers.Ad d(@"SOAP:A ction");
  201                    req. ContentTyp e = @"text /xml; char set=""utf- 8"" ";
  202                    req. Accept = " text/xml";
  203                    req. Method = " POST";
  204                }
  205  
  206                XmlReade rSettings  xsdSetting s = new Xm lReaderSet tings
  207                {
  208                    Vali dationType  = Validat ionType.Sc hema,
  209                    DtdP rocessing  = DtdProce ssing.Proh ibit
  210                };
  211  
  212                xsdSetti ngs.Valida tionFlags  |= XmlSche maValidati onFlags.Pr ocessSchem aLocation;
  213  
  214  
  215                Assembly  a = Assem bly.GetExe cutingAsse mbly();
  216                Stream s tream = a. GetManifes tResourceS tream("Cli nSchd.Infr astructure .SSOi.GetS SOiToken.x sd");
  217                if (stre am != null )
  218                {
  219                    XmlS chema x =  XmlSchema. Read(strea m, CreateW ebRequestE ventHandle r);
  220   #pragma wa rning disa ble 618
  221                    x.Co mpile(Crea teWebReque stEventHan dler, new  XmlUrlReso lverHelper (a, "ClinS chd.Infras tructure.S SOi"));
  222   #pragma wa rning rest ore 618
  223           
  224                    xsdS ettings.Sc hemas.Add( x);
  225                }
  226                var srea der = new  StringRead er(buildSO AP());
  227                
  228                XmlReade r reader =  XmlReader .Create(sr eader, xsd Settings);
  229  
  230                XmlDocum ent soapXm lDocument  = new XmlD ocument()
  231                {
  232                    XmlR esolver =  null
  233                };
  234  
  235                soapXmlD ocument.Lo ad(reader) ;
  236  
  237                //*zeb 8 65550 11/2 7/18 fail  over to ac cess and v erify code s if SSOi  is not ava ilable
  238                if (req  != null)
  239                {
  240                    try
  241                    {
  242                         using (Str eam stm =  req.GetReq uestStream ())
  243                         {
  244                             soapXm lDocument. Save(stm);
  245                         }
  246  
  247                         return req ;
  248                    }
  249                    catc h (WebExce ption e)
  250                    {
  251                         TraceLog.L ogExceptio n("ClinSch d.Infrastr ucture.SSO i.GetSSOiT oken", "Cr eateWebReq uest", e);
  252  
  253                         return nul l;
  254                    }
  255                }
  256                return n ull;
  257           }
  258  
  259           pr ivate stat ic void Cr eateWebReq uestEventH andler(obj ect sender , Validati onEventArg s e)
  260           {
  261                TraceLog .LogExcept ion("GetSS OiToken",  "CreateWeb Request",e .Exception );
  262           }
  263  
  264           pr ivate stat ic String  buildSOAP( )
  265           {
  266                //mbs 20 180517 RTC  # 743679  Fortify Co rrect Secu rity Issue s
  267                //This i s being fl agged by F ortify for  "Often Mi sused: Aut henticatio n." The ho st name is  not being  used for
  268                //authen tication.  The code i s simply g etting the  local hos t's name t o build in to the SOA P message
  269               // string  pcName =  Dns.GetHos tName();
  270  
  271  
  272                //FF - 1 0/05/2018  - Fortify  scan fix,  replacing  call to Dn s.GetHostN ame with E nvironment .MachineNa me
  273                string d omainName  = Environm ent.Machin eName + ". " + IPGlob alProperti es.GetIPGl obalProper ties().Dom ainName;
  274                
  275                String a ppName = A ssembly.Ge tExecuting Assembly() .GetName() .Name;
  276                string i am1 = @"<s oapenv:Env elope xmln s:soapenv= ""http://s chemas.xml soap.org/s oap/envelo pe/"" xmln s:ns=""htt p://docs.o asis-open. org/ws-sx/ ws-trust/2 00512"">"
  277                               + "< soapenv:He ader/>"
  278                               + "< soapenv:Bo dy>"
  279                               + "< ns:Request SecurityTo ken>"
  280                               + "< ns:Base>"
  281                               + @" <wss:TLS x mlns:wss=" "http://do cs.oasis-o pen.org/ws s/2004/01/ oasis-2004 01-wss-wss ecurity-se cext-1.0.x sd""/>"
  282                               + "< /ns:Base>"
  283                               + @" <wsp:Appli esTo xmlns :wsp=""htt p://schema s.xmlsoap. org/ws/200 4/09/polic y"">"
  284                               + @" <wsa:Endpo intReferen ce xmlns:w sa=""http: //schemas. xmlsoap.or g/ws/2004/ 08/address ing"">"
  285                               + "< wsa:Addres s>";
  286                string i am2 = "</w sa:Address >"
  287                               + "< /wsa:Endpo intReferen ce>"
  288                               + "< /wsp:Appli esTo>"
  289                               + "< ns:Issuer> "
  290                                 + @"<wsa:A ddress xml ns:wsa=""h ttp://sche mas.xmlsoa p.org/ws/2 004/08/add ressing""  > https:// DNS               /Issuer/sm token/SAML 2</wsa:Add ress>"
  291                               + "< /ns:Issuer >"
  292                               + "< ns:Request Type>http: //schemas. xmlsoap.or g/ws/2005/ 02/trust/V alidate</n s:RequestT ype>"
  293                               + "< /ns:Reques tSecurityT oken>"
  294                               + "< /soapenv:B ody>"
  295                               + "< /soapenv:E nvelope>";
  296                string I amWholeMes sage = iam 1 + "https ://" + dom ainName +  "/Delphi_R PC_Broker/ " + appNam e + iam2;
  297  
  298                return I amWholeMes sage;
  299           }
  300       }
  301   }