%3CLINGO-SUB%20id%3D%22lingo-sub-1454638%22%20slang%3D%22en-US%22%3EFIPs%20and%20.NET%20Core%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1454638%22%20slang%3D%22en-US%22%3E%3CP%3EFIPs%20stands%20for%20Federal%20Information%20Processing%20Standards.%20It%20is%20all%20about%20cryptographic%20algorithms.%20Chances%20are%2C%20if%20you%20are%20not%20working%20on%20a%20healthcare%20or%20government%20related%20system%20%E2%80%93%20you%E2%80%99ve%20never%20even%20heard%20of%20FIPs%2C%20and%20that%E2%80%99s%20okay.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%225%22%3E%3CEM%3EBut%20what%20about%20those%20that%20%3CSTRONG%3E%3CU%3Edo%3C%2FU%3E%3C%2FSTRONG%3E%20have%20to%20worry%20about%20FIPs%3F%3C%2FEM%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ECustomer%20Scenario%3C%2FSTRONG%3E%3CBR%20%2F%3EThis%20particular%20customer%20has%20a%20large%20healthcare%20system%20%E2%80%93%20a%20system%20that%20operates%20under%20mandates%20that%20%3CEM%3Erequires%3C%2FEM%3E%20FIPs%20compliance.%20Currently%20it%20is%20built%20on%20.NET%20Framework%20mostly%204.7.2.%20It%20consists%20of%20server-side%20NT%20Services%20that%20reach%20out%20to%20external%20systems%20to%20gather%20data%20along%20with%20a%20mix%20of%20Web%20Services%20(WCF%20%26amp%3B%20ASMX).%20They%20are%20currently%20FIPs%20compliant.%20They%20are%20in%20the%20process%20of%20migrating%20these%20systems%20to%20.NET%20Core%20%E2%80%93%20the%20Web%20Services%20will%20be%20transformed%20into%20.NET%20Core%20WebAPI%20micro-services%20and%20the%20Win32%20services%20to%20.NET%20Core.%20The%20challenge%3F%20How%20to%20maintain%20FIPs%20compliance%20with%20the%20migration%20and%20refactoring%20process%20taking%20place.%20Although%20FIPs%20complaint%E2%80%A6%20it%E2%80%99s%20something%20they%20haven%E2%80%99t%20had%20to%20concern%20themselves%20with%20in%20a%20while.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ECustomer%20Questions%3C%2FSTRONG%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EWhat%20is%20FIPs%3F%3C%2FLI%3E%0A%3CLI%3EWhat%20is%20FIPs%20%E2%80%9Ccompliance%E2%80%9D%20vs%20%E2%80%9Ccertification%E2%80%9D%20vs%20%E2%80%9Cverification%E2%80%9D%3F%3C%2FLI%3E%0A%3CLI%3EWhat%20is%20%E2%80%9CFIPs%20Policy%E2%80%9D%20and%20Best%20Practices%3F%3C%2FLI%3E%0A%3CLI%3EWhat%20methods%20are%20available%20at%20runtime%20to%20detect%20%E2%80%9CFIPs%20Policy%E2%80%9D%3F%3C%2FLI%3E%0A%3CLI%3EWhat%20methods%20are%20available%20to%20enforce%20FIPs%20Policy%20%E2%80%93%20at%20runtime%3F%3C%2FLI%3E%0A%3COL%3E%0A%3CLI%3EIs%20it%20possible%20to%20(accidentally)%20bypass%20FIPs%20Policy%20enforcement%3F%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CLI%3EWhat%20is%20available%20to%20%3CEM%3Eaudit%3C%2FEM%3E%20FIPs%20Policy%20adherence%3F%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%225%22%3EWhat%20is%20FIPs%3F%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3EAn%20implementation%20of%20an%20approved%20cryptographic%20algorithm%20is%20considered%20FIPS%20compliant%20only%20if%20it%20has%20been%20submitted%20for%20and%20has%20passed%20National%20Institute%20of%20Standards%20and%20Technology%20(%3CA%20href%3D%22http%3A%2F%2Fcsrc.nist.gov%2Fpublications%2Ffips%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3ENIST%3C%2FA%3E)%20validation.%20%26nbsp%3BThere%20is%20a%20program%20called%20%3CA%20href%3D%22https%3A%2F%2Fcsrc.nist.gov%2FProjects%2Fcryptographic-module-validation-program%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3ECryptographic%20Module%20Validation%20Program%3C%2FA%3E%26nbsp%3B(CMVP)%20which%20certifies%20cryptographic%20modules%20%E2%80%93%20for%20a%20full%20list%20of%20the%20modules%20in%20Windows%2010%20(by%20version)%20that%20have%20been%20certified%20go%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fsecurity%2Fthreat-protection%2Ffips-140-validation%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%20A%20particular%20implementation%20of%20an%20algorithm%20that%20has%20not%20been%20submitted%20cannot%20be%20considered%20FIPS-compliant%20even%20if%20it%20produces%20%3CEM%3Eidentical%20data%3C%2FEM%3E%20as%20a%20validated%20implementation%20of%20the%20same%20algorithm.%20Turns%20out%2C%20that%20is%20a%20very%20subtle%20but%20important%20distinction.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%225%22%3EWhat%20is%20FIPs%20%E2%80%9Ccompliance%E2%80%9D%20vs%20%E2%80%9Ccertification%E2%80%9D%20vs%20%E2%80%9Cverification%E2%80%9D%3F%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%E2%80%9CFIPS%20%3CSTRONG%3EValidated%3C%2FSTRONG%3E%E2%80%9D%20translates%20to%20that%20the%20cryptographic%20module%20or%20your%20service%20or%20product%20that%20embeds%20the%20module%20has%20been%20validated%20(%E2%80%9Ccertified%E2%80%9D)%20by%20the%20CMVP%20as%20meeting%20the%20FIPS%20140-2%20requirements.%20%26nbsp%3BBasically%2C%20FIPS%20Validated%20means%20that%20a%20product%20has%20been%20reviewed%2C%20tested%2C%20and%20approved%20by%20an%20accredited%20(NIST%20approved)%20%3CA%20href%3D%22https%3A%2F%2Fcsrc.nist.gov%2Fprojects%2Fcryptographic-module-validation-program%2Fmodule-validation-lists%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Etesting%20lab%3C%2FA%3E.%26nbsp%3B%20That%20seems%20to%20be%20a%20very%20time%20consuming%20and%20expensive%20process.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%E2%80%9CFIPS%20%3CSTRONG%3ECompliant%3C%2FSTRONG%3E%E2%80%9D%20is%20an%20industry%20term%20for%20IT%20products%20that%20rely%20on%20FIPS%20140%20validated%20products%20for%20cryptographic%20functionality.%20In%20this%20case%20%E2%80%93%20the%20entire%20solution%20or%20product%20is%20not%20FIPS%20Validated%2C%20but%20the%20module%20it%20consumes%20are%20validated%20and%20the%20developer%20(and%20testers)%20have%20confirmed%20only%20the%20FIPs%20Validated%20modules%20are%20being%20used.%20Compliant%20does%20not%20mean%20a%20product%20that%20contains%20cryptographic%20modules%20is%20validated.%20Being%20FIPS%20compliant%20means%20only%20certain%20parts%20of%20a%20product%20have%20been%20tested%20and%20approved.%20Yes%2C%20that%20means%20there%20could%20be%20gaps%20in%20the%20security%20of%20the%20product.%26nbsp%3B%20Being%20FIPs%20compliant%20is%20the%20first%20step%20before%20FIPs%20Validation%20by%20NIST%2C%20and%20in%20some%20cases%20being%20FIPs%20Complaint%20alone%20may%20suffice%20for%20the%20customer%E2%80%99s%20implementation.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%E2%80%9CFIPS%20%3CSTRONG%3EVerified%3C%2FSTRONG%3E%E2%80%9D%20%E2%80%93%20once%20an%20implementation%20has%20been%20validated%20by%20NIST%2C%20they%20issue%20a%20%E2%80%9CFIPS%20Verified%E2%80%9D%20certificate%2C%20which%20makes%20it%20eligible%20for%20US%20government%20procurement%20and%20use.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%225%22%3EWhat%20is%20%E2%80%9CFIPs%20Policy%E2%80%9D%20and%20Best%20Practices%3F%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3EWhen%20it%20comes%20to%20Windows%20and%20development%E2%80%A6%20%E2%80%9CFIPs%20Policy%E2%80%9D%20has%20a%20very%20specific%20meaning.%20It%E2%80%99s%20referring%20to%20the%20specific%20%E2%80%9C%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fsecurity%2Fthreat-protection%2Fsecurity-policy-settings%2Fsystem-cryptography-use-fips-compliant-algorithms-for-encryption-hashing-and-signing%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3ESystem%20cryptography%3A%20Use%20FIPS%20compliant%20algorithms%20for%20encryption%2C%20hashing%2C%20and%20signing%3C%2FA%3E%E2%80%9D%20Group%20Policy%20setting%20located%20at%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3EComputer%20Configuration%5CWindows%20Settings%5CSecurity%20Settings%5CLocal%20Policies%5CSecurity%20Options%0A%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22policy.png%22%20style%3D%22width%3A%20703px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F197967i54C968A78418D1CA%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22policy.png%22%20alt%3D%22policy.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESetting%20this%20policy%20to%20Enabled%20will%20set%20the%20corresponding%20Registry%20key%20%3CSTRONG%3EEnabled%3D1%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EHKLM%5CSystem%5CCurrentControlSet%5CControl%5CLsa%5CFIPSAlgorithmPolicy%5CEnabled%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%23FF0000%22%3E%3CSTRONG%3ECaveat%3A%3C%2FSTRONG%3E%3C%2FFONT%3E%20Having%20this%20%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Fhelp%2F811833%2Fsystem-cryptography-use-fips-compliant-algorithms-for-encryption-hashi%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EPolicy%3C%2FA%3E%20set%20to%20%E2%80%9CEnabled%E2%80%9D%20may%20indeed%20be%20required%20as%20part%20of%20your%20journey%20towards%20%E2%80%9CFIPs%20Compliant%E2%80%9D%E2%80%A6%20however%20%E2%80%93%20you%20should%20be%20aware%20that%20there%20are%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fsecurity%2Fthreat-protection%2Ffips-140-validation%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Edramatic%20side-effect%3C%2FA%3E%20impacts%20of%20implementing%20this%20setting%20and%20in%20particular%20as%20you%20migrate%20towards%20.NET%20Core%20this%20setting%20will%20not%20give%20you%20the%20piece%20of%20mind%20you%20are%20seeking.%20%3CEM%3EBe%20warned!%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20is%20an%20%3CA%20href%3D%22https%3A%2F%2Fblogs.technet.microsoft.com%2Fsecguide%2F2014%2F04%2F07%2Fwhy-were-not-recommending-fips-mode-anymore%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Eexcellent%20article%3C%2FA%3E%20that%20explains%20our%20recommended%20best%20practices%20and%20the%20underlying%20reasons%20for%20those%20recommendations%20regarding%20this%20FIPs%20policy.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%225%22%20color%3D%22%230000FF%22%3EIt%20boils%20down%20to%E2%80%A6%20%3CEM%3Eunless%3C%2FEM%3E%20you%20are%20required%20(say%20government%20or%20healthcare%20requirement)%E2%80%A6%20to%20leave%20this%20setting%20%3CEM%3Eundefined%3C%2FEM%3E.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBut%20in%20this%20case%20%E2%80%93%20this%20customer%20scenario%20%E2%80%93%20we%20are%20indeed%20required%20to%20have%20that%20setting%20enabled.%20In%20addition%20%E2%80%93%20we%20must%20determine%20if%20our%20migrated%20solution%20is%20FIPs%20Compliant.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%225%22%3E%3CSTRONG%3EWhat%20methods%20are%20available%20at%20runtime%20to%20detect%20%E2%80%9CFIPs%20Policy%E2%80%9D%3F%20What%20methods%20are%20available%20to%20enforce%20FIPs%20Policy%20%E2%80%93%20at%20runtime%3F%20And%20finally%2C%20is%20it%20possible%20to%20(accidentally)%20bypass%20FIPs%20Policy%20enforcement%3F%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20combine%20these%20questions%20%E2%80%93%20as%20they%20are%20all%20very%20closely%20related%20once%20we%20explore.%3C%2FP%3E%0A%3CP%3EOkay..%20so%20now%20we%20have%20an%20idea%20of%20what%20FIPs%20is%20and%20what%20FIPs%20Policy%20is%E2%80%A6%20various%20articles%20advise%20us%20that%20we%20should%20detect%20(at%20runtime%20in%20the%20code)%20if%20this%20FIPs%20Policy%20is%20enabled%E2%80%A6%20and%20if%20so%20%E2%80%93%20enforce%20that.%20Okay%E2%80%A6%20then%20how%3F%20(Asked%20my%20frustrated%20customer).%20From%20our%20new%20.NET%20Core%20implementation%E2%80%A6%20(1)%20How%20do%20we%20determine%20if%20that%20policy%20is%20even%20enabled%3F%20(2)%20How%20can%20we%20tell%20what%20.NET%20Core%20algorithms%20are%20using%20underlying%20FIPs%20Validated%20modules%3F%3C%2FP%3E%0A%3CP%3EThis%20is%20where%20we%20journey%20down%20the%20rabbit%20hole.%3C%2FP%3E%0A%3CP%3EIndeed%E2%80%A6%20there%20is%20a%20property%20you%20can%20check%20at%20runtime%20to%20determine%20if%20this%20FIPs%20Policy%20is%20enabled%2C%20but%20I%20do%20NOT%20recommend%20using%20this%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fapi%2Fsystem.security.cryptography.cryptoconfig.allowonlyfipsalgorithms%3Fview%3Dnetcore-3.1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3ECryptoConfig.AllowOnlyFipsAlgorithms%3C%2FA%3E%3CSPAN%3E.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20tested%20it%20on%20.NET%20Framework%204.7.2%2C%204.8%20and%20.NET%20Core%203.1%20%E2%80%93%20and%20what%20I%20found%20was%20not%20encouraging%20in%20any%20of%20those%20cases.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20order%20to%20explore%20the%20underlying%20implementation%20in%20each%20case%2C%20I%20stepped%20into%20the%20.NET%20Framework%20(and%20.NET%20Core)%20base%20class%20libraries.%20For%20the%20.NET%20Framework%20to%20step%20into%20the%20BCLs%2C%20I%20needed%20%3CA%20href%3D%22https%3A%2F%2Freferencesource.microsoft.com%2Fdownload.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EDotNet472ZDP%3C%2FA%3E%20for%20.NET%20Framework%204.7.2%20and%20%3CA%20href%3D%22https%3A%2F%2Freferencesource.microsoft.com%2Fdownload.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EDotNet48ZDP2%3C%2FA%3E%20for%204.8.%20You%20can%20download%20the%20zip%20files%20and%20expand%20them%20locally.%20Then%20you%20need%20to%26nbsp%3B%20uncheck%20%E2%80%9CEnable%20Just%20my%20Code%E2%80%9D%20and%20check%20%E2%80%9CEnable%20.NET%20Source%20Stepping%E2%80%9D%20and%20for%20Core%20go%20ahead%20and%20enable%20source%20server.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20this%20case%20I%20was%20exploring%20three%20different%20implementations%20in%20three%20different%20sources%20%E2%80%93%20but%20all%20had%20the%20same%20identical%20CS%20file%20names%20(for%20example%20Sha512Managed.cs)%20so%20what%20I%20discovered%20is%20Visual%20Studio%20caches%20the%20source%20when%20the%20names%20are%20identical.%20So%20while%20I%20thought%20I%20was%20examining%20the%20BCL%20for%204.8%20and%20seeing%20different%20behavior%20than%204.7.2%20I%20discovered%20it%20was%20still%20pointing%20to%204.7.2%20source%20although%20targeting%204.8.%20The%20only%20way%20I%20found%20around%20that%20was%20to%20rename%20the%20old%20CS%20lib%20and%20force%20VS%20to%20prompt%20for%20the%20new%20source%20location.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22source%20stepping.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F197968i4065AE8A861B87BD%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22source%20stepping.png%22%20alt%3D%22source%20stepping.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20.NET%20Framework%204.7.2%20this%20returns%20the%20correct%20value%20but%20apparently%20this%20property%20is%20only%20set%20once%20%E2%80%93when%20the%20process%20loads.%20So%20if%20you%20have%20a%20long%20running%20process%2C%20such%20as%20a%20website%2C%20and%20this%20policy%20is%20updated%20the%20value%20will%20be%20wrong%20when%20you%20read%20it%20%E2%80%93%20which%20will%20lead%20to%20unexpected%20behavior%20as%20enforcement%20relies%20internally%20in%20the%20BCLs%20on%20this%20one%20property.%20The%20.NET%20Framework%20exceptions%20thrown%20%E2%80%93%20depend%20on%20this%20property.%20What%20that%20means%20is%20%E2%80%93%20you%20can%20set%20FIPS%20Policy%20to%20Enabled%20on%20a%20server%20with%20an%20NT%20Service%20and%20Website%20running%20%E2%80%93%20and%20neither%20will%20be%20FIPs%20compliant%20until%20they%20are%20restarted.%20Not%20great%2C%20but%20at%20least%20we%20have%20some%20degree%20of%20runtime%20errors%20thrown%20to%20protect%20against%20using%20a%20non-FIPs%20compliant%20algorithm.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%20%20%20%20%20%20%20%20%20%20%20%20if%20(CryptoConfig.AllowOnlyFipsAlgorithms)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20throw%20new%20InvalidOperationException(Environment.GetResourceString(%22Cryptography_NonCompliantFIPSAlgorithm%22))%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20Contract.EndContractBlock()%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20.NET%20Framework%204.8%20this%20property%20still%20exists%2C%20and%20the%20value%20reading%20behaves%20identical%20to%204.7.2.%20It%20is%20set%20once%20and%20only%20once%20when%20the%20process%20loads.%20However%20%E2%80%93%20the%20difference%20is%20the%20setting%20is%20completely%20ignored.%20I%20examined%20the%20BCL%20to%20find%20out%20why%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3Eif%20(CryptoConfig.AllowOnlyFipsAlgorithms%20%26amp%3B%26amp%3B%20AppContextSwitches.UseLegacyFipsThrow)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20throw%20new%20InvalidOperationException(Environment.GetResourceString(%22Cryptography_NonCompliantFIPSAlgorithm%22))%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20Contract.EndContractBlock()%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAh%E2%80%A6%20so%20it%20is%20referring%20to%20a%20context%20switch%20%3CSTRONG%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fframework%2Fmigration-guide%2Fretargeting%2F4.7.2-4.8%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EAppContextSwitches.UseLegacyFipsThrow%3C%2FA%3E%3C%2FSTRONG%3E%20that%20I%20had%20not%20found%20documented%20anywhere%20previously.%20If%20both%20that%20and%20the%20FIPs%20Policy%20are%20set%E2%80%A6%20then%20and%20only%20then%20we%20get%20the%20exception.%20So%20once%20we%20set%20this%20property%20then%20we%20get%20an%20exception%20when%20the%20Policy%20is%20set%20to%20enabled%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3EAppContext.SetSwitch(%22Switch.System.Security.Cryptography.UseLegacyFipsThrow%22%2C%20true)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20was%20still%20susceptible%20to%20the%20same%20issue%20in%204.7.2%20where%20if%20the%20process%20was%20still%20running%20%E2%80%93%20no%20error%20was%20thrown%20when%20the%20Policy%20was%20updated%20to%20enabled.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThen%20I%20tested%20in%20.NET%20Core%203.1.%20Yes%2C%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fapi%2Fsystem.security.cryptography.cryptoconfig.allowonlyfipsalgorithms%3Fview%3Dnetcore-3.1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3ECryptoConfig.AllowOnlyFipsAlgorithms%3C%2FA%3E%20property%20still%20exists%20in%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fapi%2Fsystem.security.cryptography.cryptoconfig.allowonlyfipsalgorithms%3Fview%3Dnetcore-3.1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3ECore%20version%3C%2FA%3E.%20%26nbsp%3BI%20was%20not%20surprised%20to%20discover%20no%20exception%20was%20thrown%20when%20using%20non-FIPs%20compliant%20algorithms.%20We%20have%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fdotnet%2Fruntime%2Fissues%2F26037%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Edocumented%3C%2FA%3E%20that%20behavior%20change%20in%20.NET%20Core%20we%20are%20no%20longer%20throwing%20exceptions%20%E2%80%9CDoes%26nbsp%3B%3CSTRONG%3Enot%3C%2FSTRONG%3E%26nbsp%3Benforce%20the%20use%20of%20FIPS%20Approved%20algorithms%20or%20key%20sizes%20in%20.NET%20Core%20apps.%E2%80%9D.%20%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHowever%2C%20I%20was%20a%20little%20surprised%20to%20discover%20the%20property%20did%20not%20return%20the%20correct%20value.%20It%20seems%20it%20is%20never%20set.%20Therefore%E2%80%A6%20the%20developer%20cannot%20simply%20read%20this%20value%20to%20determine%20if%20FIPs%20Policy%20is%20enabled%20-%20and%20throw%20their%20own%20exceptions.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EInstead%20we%20went%20with%20reading%20the%20registry%20directly%20and%20leveraging%20cache%20with%20expiration.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%20%20%20%20%20%20%20%20public%20bool%20IsFipsPolicyEnabled()%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20RegistryKey%20uac%20%3D%20Registry.LocalMachine.OpenSubKey(%40%22System%5CCurrentControlSet%5CControl%5CLsa%5CFIPSAlgorithmPolicy%22%2C%20true)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(uac%20%3D%3D%20null)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20false%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20(bool)uac.GetValue(%22Enabled%22)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESo%20to%20summarize%E2%80%A6%20there%20are%20built-in%20methods%20to%20enforce%20FIPs%20compliant%20behavior%20at%20runtime%20in%20.NET%204.7.2%20by%20default%20(though%20restart%20your%20process%20after%20a%20policy%20change).%20Same%20for%204.8%20but%20only%20with%20the%20added%20the%20UseFipsLegacyThrow%20context%20switch.%20None%20in%20.NET%20Core.%20So%20is%20it%20possible%20to%20(accidentally)%20bypass%20FIPs%20Policy%20enforcement%3F%20Absolutely!%20Without%20allot%20of%20work%E2%80%A6%20that%20will%20happen%20by%20default%20in%20.NET%20Core.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBut%20this%20leads%20to%20the%20next%20question%E2%80%A6%20and%20a%20%3CEM%3E%3CSTRONG%3Ephilosophical%3C%2FSTRONG%3E%20%3C%2FEM%3Equestion%20really.%20Perhaps%20there%20is%20a%20very%20good%20reason%20for%20this%20shift%20in%20behavior.%20Runtime%20errors%20are%20always%20worse%20than%20compile%20time%20errors.%20What%20possible%20benefit%20is%20there%20to%20having%20a%20runtime%20exception%20thrown%20for%20a%20system%20that%20is%20using%20a%20non-FIPs%20compliant%20algorithm%3F%20Only%20perhaps%20if%20that%20same%20system%20needed%20to%20run%20in%20both%20a%20FIPs%20compliant%20and%20a%20non-FIPs%20compliant%20environment%2C%20perhaps.%20Typically%2C%20instead%2C%20those%20issues%20should%20be%20discovered%20and%20fixed%20before%20release.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAlso%2C%20to%20make%20matters%20even%20more%20complex%20%E2%80%93%20FIPs%20compliance%20isn%E2%80%99t%20binary.%20There%20are%20cases%20of%20the%20FIPs%20compliant%20algorithms%20%E2%80%93%20within%20modules%20that%20are%20already%20certified%20%E2%80%93%20using%20non-fips%20compliant%20(eg%20SHA1)%20internally.%20So%20the%20compliance%20depends%20on%20the%20implementation%20%2F%20usage.%20In%20some%20cases%20it%E2%80%99s%20okay%20(such%20as%20for%20non-secret%20key%20hashing).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESo%20when%20it%20comes%20to%20the%20runtime%20exceptions%20and%20checking%20for%20FIPs%20compliance%E2%80%A6%20now%20that%20%3CA%20href%3D%22https%3A%2F%2Fblogs.technet.microsoft.com%2Fsecguide%2F2014%2F04%2F07%2Fwhy-were-not-recommending-fips-mode-anymore%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Eexcellent%20article%3C%2FA%3E%20makes%20allot%20more%20sense.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESo%20let%E2%80%99s%20look%20at%20identifying%20and%20correcting%20these%20at%20compile-time%20instead.%20That%20leads%20us%20to%E2%80%A6%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CFONT%20size%3D%225%22%3EWhat%20is%20available%20to%20%3CEM%3E%3CEM%3Eaudit%3C%2FEM%3E%3C%2FEM%3E%20FIPs%20Policy%20adherence%3F%3C%2FFONT%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EI%20installed%20the%20%3CA%20href%3D%22https%3A%2F%2Fwww.nuget.org%2Fpackages%2FMicrosoft.CodeAnalysis.FxCopAnalyzers%2F3.0.0%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EMicrosoft.CodeAnalysis.FxCopAnalyzers%3C%2FA%3E%3CA%20href%3D%22https%3A%2F%2Fwww.nuget.org%2Fpackages%2FMicrosoft.CodeAnalysis.FxCopAnalyzers%2F3.0.0%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%203.0%3C%2FA%3E%20nuget%20package%20and%20set%20my%20project%E2%80%99s%20analysis%20options%20to%20%E2%80%9CEntire%20Solution%E2%80%9D.%20In%20particular%20%E2%80%93%20I%20was%20hopeful%20for%20the%20DoNotUseInsecureCryptographicAlgorithms%20check%20to%20cover%20for%20FIPs%20compliant%20checks.%20However%2C%20I%20quickly%20learned%20that%20check%20did%20not%20check%20for%20all%20of%20the%20non-FIPs%20compliant%20algorithms.%20The%20full%20list%20that%20it%20checks%20is%20here%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22d.png%22%20style%3D%22width%3A%20581px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F197969i731A7D74EC03A97F%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22d.png%22%20alt%3D%22d.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENotability%20missing%2C%20for%20example%2C%20is%20Sha512Managed.%20Okay..%20let%20me%20back%20up%20a%20bit.%20Let%E2%80%99s%20review.%20How%20do%20we%20know%20what%20algorithms%20in%20.NET%20Core%20are%20FIPs%20compliant%20in%20the%20first%20place%3F%20I%20have%20not%20found%20a%20%E2%80%9Cblessed%E2%80%9D%20list%20of%20such%20algorithms%E2%80%A6%20probably%20we%20need%20to%20add%20official%20documentation%20for%20that.%20Let%E2%80%99s%20start%20with%20what%20we%20do%20have.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBased%20on%20the%20%3CA%20href%3D%22https%3A%2F%2Fcsrc.nist.gov%2FCSRC%2Fmedia%2Fprojects%2Fcryptographic-module-validation-program%2Fdocuments%2Fsecurity-policies%2F140sp3197.pdf%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3ECMVP%20listing%3C%2FA%3E%20we%20know%20specific%20exports%20and%20algorithms%20in%20the%20BCRYPTPRIMITIVES.DLL%20are%20FIPs%20Validated.%20So%20based%20on%20that%20%E2%80%93%20I%20then%20stepped%20into%20each%20implementation%20to%20confirm%20that%20(1)%20it%20was%20calling%20into%20BCRYPTPRIMITIVES%20instead%20of%20a%20managed%20implementation%20and%20that%20(2)%20it%20was%20calling%20an%20algorithm%20that%20was%20certified.%20This%20was%20not%20easy.%20The%20same%20certified%20export%20was%20used%20for%20both%20FIPs%20approved%20and%20non-FIPs%20approved%20algorithms%20(eg%20BCryptCreateHash).%20And%20some%20.NET%20Core%20implementations%20of%20the%20same%20algorithm%20do%20not%20use%20the%20BCRYPTPRIMITIVES%20and%20therefore%20even%20though%20they%20are%20the%20same%20exact%20algorithm%E2%80%A6%20they%20cannot%20be%20considered%20FIPs%20compliant.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22de.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F197970i67830C4DD29DBABF%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22de.png%22%20alt%3D%22de.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E*This%20is%20not%20any%20official%20list%20or%20statement*%3CBR%20%2F%3E%3C%2FSTRONG%3EAs%20best%20I%20can%20tell%20from%20that%20exercise%20%E2%80%A6%20these%20implementations%20are%20FIPs%20compliant%3A%3C%2FP%3E%0A%3CP%3EHMACSHA1%3C%2FP%3E%0A%3CP%3EMACTripleDES%3C%2FP%3E%0A%3CP%3ESHA512CryptoServiceProvider%3C%2FP%3E%0A%3CP%3EDESCryptoServiceProvider%3C%2FP%3E%0A%3CP%3ETripleDESCryptoServiceProvider%3C%2FP%3E%0A%3CP%3EDSACryptoServiceProvider%3C%2FP%3E%0A%3CP%3ERSACryptoServiceProvider%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnd%20possibly%20SHA1CryptoServiceProvider%20depending%20on%20the%20usage.%20I%20could%20not%20locate%20any%20Roslyn%20Code%20Analysis%20that%20checked%20for%20all%20cryptographic%20uses%20outside%20that%20list%20%E2%80%93%20on%20a%20blocked-list%20type%20of%20approach.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESo%20I%20wrote%20one%20%E2%80%93%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FWindows-AppConsult-Samples-DesktopBridge%2Ftree%2Fmaster%2FBlog-FIPs%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fmicrosoft%2FWindows-AppConsult-Samples-DesktopBridge%2Ftree%2Fmaster%2FBlog-FIPs%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%2C%20finally%2C%20I%20have%20not%20mentioned%20much%20about%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fframework%2Fnetwork-programming%2Ftls%23audit-your-code-and-make-code-changes%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3ETLS%3C%2FA%3E.%20Not%20only%20is%20the%20local%20cryptographic%20algorithms%20used%20important..%20but%20the%20protocols%20and%20cypher%20suites%20used%20must%20also%20be%20compliant.%20Fortunately%E2%80%A6%20the%20Client%20(and%20Server)%20SCHANNEL%20protocol%20settings%20in%20the%20Registry%20were%20honored%20and%20supported%20and%20blocked%20TSL%201.0%20and%201.1%20in%20all%20three%20of%20my%20tests%20(4.7.2%2C%204.8%20and%20.NET%20Core%203.1).%20In%20addition%20you%20can%20specify%20only%20compliant%20algorithms%20in%20your%20CipherSuites%20in%20either%20the%20Registry%20(SCHANNEL%5CCipherSuites)%20or%20in%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Faspnet%2Fcore%2Ffundamentals%2Fservers%2Fkestrel%3Fview%3Daspnetcore-3.1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ecode%3C%2FA%3E.%20There%20is%20enough%20there%20to%20do%20a%20separate%20blog%20post%E2%80%A6%20but%20really%20there%20is%20more%20details%20out%20there%20for%20that%20problem%2C%20and%20easier%20solutions.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESee%20also%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fdotnet%2Fruntime%2Fissues%2F26048%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fdotnet%2Fruntime%2Fissues%2F26048%3C%2FA%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fapi%2Fsystem.net.security.ciphersuitespolicy%3Fview%3Dnetcore-3.1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fapi%2Fsystem.net.security.ciphersuitespolicy%3Fview%3Dnetcore-3.1%3C%2FA%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fdotnet%2Fruntime%2Fissues%2F26048%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fdotnet%2Fruntime%2Fissues%2F26048%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1454638%22%20slang%3D%22en-US%22%3E%3CP%3EFIPs%20stands%20for%20Federal%20Information%20Processing%20Standards.%20It%20is%20all%20about%20cryptographic%20algorithms.%3C%2FP%3E%3C%2FLINGO-TEASER%3E
Microsoft

FIPs stands for Federal Information Processing Standards. It is all about cryptographic algorithms. Chances are, if you are not working on a healthcare or government related system – you’ve never even heard of FIPs, and that’s okay.

 

But what about those that do have to worry about FIPs?

 

Customer Scenario
This particular customer has a large healthcare system – a system that operates under mandates that requires FIPs compliance. Currently it is built on .NET Framework mostly 4.7.2. It consists of server-side NT Services that reach out to external systems to gather data along with a mix of Web Services (WCF & ASMX). They are currently FIPs compliant. They are in the process of migrating these systems to .NET Core – the Web Services will be transformed into .NET Core WebAPI micro-services and the Win32 services to .NET Core. The challenge? How to maintain FIPs compliance with the migration and refactoring process taking place. Although FIPs complaint… it’s something they haven’t had to concern themselves with in a while.

 

Customer Questions

  1. What is FIPs?
  2. What is FIPs “compliance” vs “certification” vs “verification”?
  3. What is “FIPs Policy” and Best Practices?
  4. What methods are available at runtime to detect “FIPs Policy”?
  5. What methods are available to enforce FIPs Policy – at runtime?
    1. Is it possible to (accidentally) bypass FIPs Policy enforcement?
  6. What is available to audit FIPs Policy adherence?

 

What is FIPs?

An implementation of an approved cryptographic algorithm is considered FIPS compliant only if it has been submitted for and has passed National Institute of Standards and Technology (NIST) validation.  There is a program called Cryptographic Module Validation Program (CMVP) which certifies cryptographic modules – for a full list of the modules in Windows 10 (by version) that have been certified go here. A particular implementation of an algorithm that has not been submitted cannot be considered FIPS-compliant even if it produces identical data as a validated implementation of the same algorithm. Turns out, that is a very subtle but important distinction.

 

What is FIPs “compliance” vs “certification” vs “verification”?

 

“FIPS Validated” translates to that the cryptographic module or your service or product that embeds the module has been validated (“certified”) by the CMVP as meeting the FIPS 140-2 requirements.  Basically, FIPS Validated means that a product has been reviewed, tested, and approved by an accredited (NIST approved) testing lab.  That seems to be a very time consuming and expensive process.

 

“FIPS Compliant” is an industry term for IT products that rely on FIPS 140 validated products for cryptographic functionality. In this case – the entire solution or product is not FIPS Validated, but the module it consumes are validated and the developer (and testers) have confirmed only the FIPs Validated modules are being used. Compliant does not mean a product that contains cryptographic modules is validated. Being FIPS compliant means only certain parts of a product have been tested and approved. Yes, that means there could be gaps in the security of the product.  Being FIPs compliant is the first step before FIPs Validation by NIST, and in some cases being FIPs Complaint alone may suffice for the customer’s implementation.

 

“FIPS Verified” – once an implementation has been validated by NIST, they issue a “FIPS Verified” certificate, which makes it eligible for US government procurement and use.

 

What is “FIPs Policy” and Best Practices?

When it comes to Windows and development… “FIPs Policy” has a very specific meaning. It’s referring to the specific “System cryptography: Use FIPS compliant algorithms for encryption, hashing, and signing” Group Policy setting located at:

 

Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options

 

policy.png

 

Setting this policy to Enabled will set the corresponding Registry key Enabled=1.

 

HKLM\System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy\Enabled

 

Caveat: Having this Policy set to “Enabled” may indeed be required as part of your journey towards “FIPs Compliant”… however – you should be aware that there are dramatic side-effect impacts of implementing this setting and in particular as you migrate towards .NET Core this setting will not give you the piece of mind you are seeking. Be warned!

 

There is an excellent article that explains our recommended best practices and the underlying reasons for those recommendations regarding this FIPs policy.

 

It boils down to… unless you are required (say government or healthcare requirement)… to leave this setting undefined.

 

But in this case – this customer scenario – we are indeed required to have that setting enabled. In addition – we must determine if our migrated solution is FIPs Compliant.

 

What methods are available at runtime to detect “FIPs Policy”? What methods are available to enforce FIPs Policy – at runtime? And finally, is it possible to (accidentally) bypass FIPs Policy enforcement?

 

Let’s combine these questions – as they are all very closely related once we explore.

Okay.. so now we have an idea of what FIPs is and what FIPs Policy is… various articles advise us that we should detect (at runtime in the code) if this FIPs Policy is enabled… and if so – enforce that. Okay… then how? (Asked my frustrated customer). From our new .NET Core implementation… (1) How do we determine if that policy is even enabled? (2) How can we tell what .NET Core algorithms are using underlying FIPs Validated modules?

This is where we journey down the rabbit hole.

Indeed… there is a property you can check at runtime to determine if this FIPs Policy is enabled, but I do NOT recommend using this CryptoConfig.AllowOnlyFipsAlgorithms.

 

I tested it on .NET Framework 4.7.2, 4.8 and .NET Core 3.1 – and what I found was not encouraging in any of those cases.

 

In order to explore the underlying implementation in each case, I stepped into the .NET Framework (and .NET Core) base class libraries. For the .NET Framework to step into the BCLs, I needed DotNet472ZDP for .NET Framework 4.7.2 and DotNet48ZDP2 for 4.8. You can download the zip files and expand them locally. Then you need to  uncheck “Enable Just my Code” and check “Enable .NET Source Stepping” and for Core go ahead and enable source server.

 

In this case I was exploring three different implementations in three different sources – but all had the same identical CS file names (for example Sha512Managed.cs) so what I discovered is Visual Studio caches the source when the names are identical. So while I thought I was examining the BCL for 4.8 and seeing different behavior than 4.7.2 I discovered it was still pointing to 4.7.2 source although targeting 4.8. The only way I found around that was to rename the old CS lib and force VS to prompt for the new source location.

 

source stepping.png

 

 

In .NET Framework 4.7.2 this returns the correct value but apparently this property is only set once –when the process loads. So if you have a long running process, such as a website, and this policy is updated the value will be wrong when you read it – which will lead to unexpected behavior as enforcement relies internally in the BCLs on this one property. The .NET Framework exceptions thrown – depend on this property. What that means is – you can set FIPS Policy to Enabled on a server with an NT Service and Website running – and neither will be FIPs compliant until they are restarted. Not great, but at least we have some degree of runtime errors thrown to protect against using a non-FIPs compliant algorithm.

 

            if (CryptoConfig.AllowOnlyFipsAlgorithms)
                throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NonCompliantFIPSAlgorithm"));
            Contract.EndContractBlock();

 

In .NET Framework 4.8 this property still exists, and the value reading behaves identical to 4.7.2. It is set once and only once when the process loads. However – the difference is the setting is completely ignored. I examined the BCL to find out why:

 

if (CryptoConfig.AllowOnlyFipsAlgorithms && AppContextSwitches.UseLegacyFipsThrow)
                throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NonCompliantFIPSAlgorithm"));
            Contract.EndContractBlock();

 

Ah… so it is referring to a context switch AppContextSwitches.UseLegacyFipsThrow that I had not found documented anywhere previously. If both that and the FIPs Policy are set… then and only then we get the exception. So once we set this property then we get an exception when the Policy is set to enabled:

 

AppContext.SetSwitch("Switch.System.Security.Cryptography.UseLegacyFipsThrow", true);

 

This was still susceptible to the same issue in 4.7.2 where if the process was still running – no error was thrown when the Policy was updated to enabled.

 

Then I tested in .NET Core 3.1. Yes, the CryptoConfig.AllowOnlyFipsAlgorithms property still exists in Core version.  I was not surprised to discover no exception was thrown when using non-FIPs compliant algorithms. We have documented that behavior change in .NET Core we are no longer throwing exceptions “Does not enforce the use of FIPS Approved algorithms or key sizes in .NET Core apps.”.  

 

However, I was a little surprised to discover the property did not return the correct value. It seems it is never set. Therefore… the developer cannot simply read this value to determine if FIPs Policy is enabled - and throw their own exceptions.

 

Instead we went with reading the registry directly and leveraging cache with expiration.

 

        public bool IsFipsPolicyEnabled()
        {
            RegistryKey uac = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy", true);
            if (uac == null)
            {
                return false;
            }
            return (bool)uac.GetValue("Enabled");
        }

 

So to summarize… there are built-in methods to enforce FIPs compliant behavior at runtime in .NET 4.7.2 by default (though restart your process after a policy change). Same for 4.8 but only with the added the UseFipsLegacyThrow context switch. None in .NET Core. So is it possible to (accidentally) bypass FIPs Policy enforcement? Absolutely! Without allot of work… that will happen by default in .NET Core.

 

But this leads to the next question… and a philosophical question really. Perhaps there is a very good reason for this shift in behavior. Runtime errors are always worse than compile time errors. What possible benefit is there to having a runtime exception thrown for a system that is using a non-FIPs compliant algorithm? Only perhaps if that same system needed to run in both a FIPs compliant and a non-FIPs compliant environment, perhaps. Typically, instead, those issues should be discovered and fixed before release.

 

Also, to make matters even more complex – FIPs compliance isn’t binary. There are cases of the FIPs compliant algorithms – within modules that are already certified – using non-fips compliant (eg SHA1) internally. So the compliance depends on the implementation / usage. In some cases it’s okay (such as for non-secret key hashing).

 

So when it comes to the runtime exceptions and checking for FIPs compliance… now that excellent article makes allot more sense.

 

So let’s look at identifying and correcting these at compile-time instead. That leads us to…

 

What is available to audit FIPs Policy adherence?

I installed the Microsoft.CodeAnalysis.FxCopAnalyzers 3.0 nuget package and set my project’s analysis options to “Entire Solution”. In particular – I was hopeful for the DoNotUseInsecureCryptographicAlgorithms check to cover for FIPs compliant checks. However, I quickly learned that check did not check for all of the non-FIPs compliant algorithms. The full list that it checks is here:

d.png

 

Notability missing, for example, is Sha512Managed. Okay.. let me back up a bit. Let’s review. How do we know what algorithms in .NET Core are FIPs compliant in the first place? I have not found a “blessed” list of such algorithms… probably we need to add official documentation for that. Let’s start with what we do have.

 

Based on the CMVP listing we know specific exports and algorithms in the BCRYPTPRIMITIVES.DLL are FIPs Validated. So based on that – I then stepped into each implementation to confirm that (1) it was calling into BCRYPTPRIMITIVES instead of a managed implementation and that (2) it was calling an algorithm that was certified. This was not easy. The same certified export was used for both FIPs approved and non-FIPs approved algorithms (eg BCryptCreateHash). And some .NET Core implementations of the same algorithm do not use the BCRYPTPRIMITIVES and therefore even though they are the same exact algorithm… they cannot be considered FIPs compliant.

 

de.png

 

 

 

*This is not any official list or statement*
As best I can tell from that exercise … these implementations are FIPs compliant:

HMACSHA1

MACTripleDES

SHA512CryptoServiceProvider

DESCryptoServiceProvider

TripleDESCryptoServiceProvider

DSACryptoServiceProvider

RSACryptoServiceProvider

 

And possibly SHA1CryptoServiceProvider depending on the usage. I could not locate any Roslyn Code Analysis that checked for all cryptographic uses outside that list – on a blocked-list type of approach.

 

So I wrote one – https://github.com/microsoft/Windows-AppConsult-Samples-DesktopBridge/tree/master/Blog-FIPs

 

Now, finally, I have not mentioned much about TLS. Not only is the local cryptographic algorithms used important.. but the protocols and cypher suites used must also be compliant. Fortunately… the Client (and Server) SCHANNEL protocol settings in the Registry were honored and supported and blocked TSL 1.0 and 1.1 in all three of my tests (4.7.2, 4.8 and .NET Core 3.1). In addition you can specify only compliant algorithms in your CipherSuites in either the Registry (SCHANNEL\CipherSuites) or in code. There is enough there to do a separate blog post… but really there is more details out there for that problem, and easier solutions.

 

 

See also

https://github.com/dotnet/runtime/issues/26048
https://docs.microsoft.com/en-us/dotnet/api/system.net.security.ciphersuitespolicy?view=netcore-3.1
https://github.com/dotnet/runtime/issues/26048