├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── SECURITY.md ├── SUPPORT.md ├── TMFileParser ├── TMFileConverter │ ├── Program.cs │ └── TMFileConverter.csproj ├── TMFileParser.sln ├── TMFileParser │ ├── Interfaces │ │ └── ITMFileReader.cs │ ├── Models │ │ ├── output │ │ │ ├── TM7All.cs │ │ │ ├── TM7Asset.cs │ │ │ ├── TM7Boundary.cs │ │ │ ├── TM7BoundaryBasic.cs │ │ │ ├── TM7CommonBoundary.cs │ │ │ ├── TM7Connector.cs │ │ │ ├── TM7Diagram.cs │ │ │ └── TM7Threat.cs │ │ ├── tb7 │ │ │ ├── TB7Attribute.cs │ │ │ ├── TB7AttributeValues.cs │ │ │ ├── TB7Attributes.cs │ │ │ ├── TB7ElementType.cs │ │ │ ├── TB7GenerationFilters.cs │ │ │ ├── TB7GenericElements.cs │ │ │ ├── TB7KnowledgeBase.cs │ │ │ ├── TB7Manifest.cs │ │ │ ├── TB7PropertiesMetaData.cs │ │ │ ├── TB7StandardElements.cs │ │ │ ├── TB7ThreatCategories.cs │ │ │ ├── TB7ThreatCategory.cs │ │ │ ├── TB7ThreatMetaData.cs │ │ │ ├── TB7ThreatMetaDatum.cs │ │ │ ├── TB7ThreatType.cs │ │ │ ├── TB7ThreatTypes.cs │ │ │ └── TB7Values.cs │ │ └── tm7 │ │ │ ├── TM7AnyType.cs │ │ │ ├── TM7Attribute.cs │ │ │ ├── TM7AttributeValues.cs │ │ │ ├── TM7Attributes.cs │ │ │ ├── TM7Borders.cs │ │ │ ├── TM7BordersKeyValueOfguidanyType.cs │ │ │ ├── TM7BordersValue.cs │ │ │ ├── TM7DrawingSurfaceList.cs │ │ │ ├── TM7DrawingSurfaceModel.cs │ │ │ ├── TM7ElementType.cs │ │ │ ├── TM7GenerationFilters.cs │ │ │ ├── TM7GenericElements.cs │ │ │ ├── TM7KeyValueOfstringThreatpc_P0_PhOB.cs │ │ │ ├── TM7KeyValueOfstringstring.cs │ │ │ ├── TM7KnowledgeBase.cs │ │ │ ├── TM7Lines.cs │ │ │ ├── TM7LinesKeyValueOfguidanyType.cs │ │ │ ├── TM7LinesValue.cs │ │ │ ├── TM7Manifest.cs │ │ │ ├── TM7MetaInformation.cs │ │ │ ├── TM7Note.cs │ │ │ ├── TM7Notes.cs │ │ │ ├── TM7Profile.cs │ │ │ ├── TM7Properties.cs │ │ │ ├── TM7PropertiesMetaData.cs │ │ │ ├── TM7StandardElements.cs │ │ │ ├── TM7StencilConstraint.cs │ │ │ ├── TM7StencilConstraints.cs │ │ │ ├── TM7ThreatCategories.cs │ │ │ ├── TM7ThreatCategory.cs │ │ │ ├── TM7ThreatInstanceProperties.cs │ │ │ ├── TM7ThreatInstances.cs │ │ │ ├── TM7ThreatInstancesValue.cs │ │ │ ├── TM7ThreatMetaData.cs │ │ │ ├── TM7ThreatMetaDatum.cs │ │ │ ├── TM7ThreatModel.cs │ │ │ ├── TM7ThreatType.cs │ │ │ ├── TM7ThreatTypes.cs │ │ │ ├── TM7Validations.cs │ │ │ ├── TM7Value.cs │ │ │ └── TM7Values.cs │ ├── Parser.cs │ ├── TB7FileReader.cs │ ├── TM7FileReader.cs │ └── TMFileParser.csproj └── TMFileParserTest │ ├── ParserTest.cs │ ├── Sample │ ├── BillionLaughs.tb7 │ ├── BillionLaughs.tm7 │ ├── EmptyDiagram.tm7 │ ├── MedicalDeviceTemplate.tb7 │ ├── NoDiagram.tm7 │ ├── ThreatsEnabledNull.tm7 │ ├── sample1.json │ ├── sample1.tm7 │ ├── sample2-all.json │ └── sample2.tm7 │ ├── TB7FileReaderTest.cs │ ├── TM7FileReaderTest.cs │ └── TMFileParserTest.csproj └── pipelines └── build-pipeline.yml /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | 352 | **/launchSettings.json 353 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TM File Parser 2 | 3 | This repo contains code for the parser to extract data from .tm7 and .tb7 files. 4 | 5 | The repo contains two projects 6 | 7 | - TMFileParser 8 | - TMFileConverter 9 | 10 | ## TMFileParser 11 | 12 | TMFileParser is .NET core (Currently .NET core 5.0) class library published as a nuget package. 13 | The NuGet package can be consumed from NuGet.org . 14 | 15 | ### Features 16 | 17 | * Class Library Built on . NET 5.0. 18 | * Support to parse all the data in .tm7 and .tb7 files or get specific data like Data Flows. 19 | 20 | ## TMFileConverter 21 | 22 | TMFileParser is cross-platform .NET core console application that can be used to extract data from .tm7 and .tb7 files. 23 | 24 | ### Features 25 | 26 | * Cross-Platform CLI Built on .NET 5.0. 27 | * Self-contained .NET Core Application. 28 | * Support to convert to JSON. 29 | * Support to convert all the data in .tm7 and .tb7 files or get specific data like Data Flows. 30 | 31 | ### Instructions 32 | 33 | Download the OS specific binaries (Windows, Mac OS, Linux). Extract TMFileConverter.zip. Navigate TMFileConverter from the command prompt or terminal and invoke 'TMFileConverter.exe' or 'TMFileConverter'. 34 | 35 | Options: 36 | -i, --input-path (REQUIRED) Input tm7 file path. 37 | -s, --save-format (REQUIRED) Output file format to convert. 38 | -o, --output-path (REQUIRED) Path to store output. 39 | -g, --get (REQUIRED) Data to be retieved. 40 | --version Display version information 41 | 42 | Supported Save Formats: 43 | json 44 | 45 | Supported Get Options: 46 | raw 47 | all 48 | boundaries 49 | assets 50 | connectors 51 | threats 52 | 53 | ## Contributing 54 | 55 | This project welcomes contributions and suggestions. Most contributions require you to agree to a 56 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us 57 | the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. 58 | 59 | When you submit a pull request, a CLA bot will automatically determine whether you need to provide 60 | a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions 61 | provided by the bot. You will only need to do this once across all repos using our CLA. 62 | 63 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 64 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or 65 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 66 | 67 | ## Trademarks 68 | 69 | This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft 70 | trademarks or logos is subject to and must follow 71 | [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). 72 | Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. 73 | Any use of third-party trademarks or logos are subject to those third-party's policies. 74 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd). 40 | 41 | -------------------------------------------------------------------------------- /SUPPORT.md: -------------------------------------------------------------------------------- 1 | # TODO: The maintainer of this repo has not yet edited this file 2 | 3 | **REPO OWNER**: Do you want Customer Service & Support (CSS) support for this product/project? 4 | 5 | - **No CSS support:** Fill out this template with information about how to file issues and get help. 6 | - **Yes CSS support:** Fill out an intake form at [aka.ms/spot](https://aka.ms/spot). CSS will work with/help you to determine next steps. More details also available at [aka.ms/onboardsupport](https://aka.ms/onboardsupport). 7 | - **Not sure?** Fill out a SPOT intake as though the answer were "Yes". CSS will help you decide. 8 | 9 | *Then remove this first heading from this SUPPORT.MD file before publishing your repo.* 10 | 11 | # Support 12 | 13 | ## How to file issues and get help 14 | 15 | This project uses GitHub Issues to track bugs and feature requests. Please search the existing 16 | issues before filing new issues to avoid duplicates. For new issues, file your bug or 17 | feature request as a new Issue. 18 | 19 | For help and questions about using this project, please **REPO MAINTAINER: INSERT INSTRUCTIONS HERE 20 | FOR HOW TO ENGAGE REPO OWNERS OR COMMUNITY FOR HELP. COULD BE A STACK OVERFLOW TAG OR OTHER 21 | CHANNEL. WHERE WILL YOU HELP PEOPLE?**. 22 | 23 | ## Microsoft Support Policy 24 | 25 | Support for this **PROJECT or PRODUCT** is limited to the resources listed above. 26 | -------------------------------------------------------------------------------- /TMFileParser/TMFileConverter/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CommandLine; 3 | using System.CommandLine.Invocation; 4 | using System.Diagnostics.CodeAnalysis; 5 | using System.IO; 6 | using System.Text.Json; 7 | using System.Threading.Tasks; 8 | using TMFileParser; 9 | 10 | namespace TMFileConverter 11 | { 12 | [ExcludeFromCodeCoverage] 13 | class Program 14 | { 15 | static async Task Main(string[] args) 16 | { 17 | var rootCommand = new RootCommand(); 18 | var inputPathOption = new Option( 19 | "--input-path", 20 | "Input tm7 file path."); 21 | inputPathOption.AddAlias("-i"); 22 | inputPathOption.Required = true; 23 | 24 | var formatOption = new Option( 25 | "--save-format", 26 | "Output file format to convert."); 27 | formatOption.AddAlias("-s"); 28 | formatOption.Required = true; 29 | 30 | var actionOption = new Option( 31 | "--get", 32 | "Data to be retieved."); 33 | actionOption.AddAlias("-g"); 34 | actionOption.Required = true; 35 | 36 | var outputPathOption = new Option( 37 | "--output-path", 38 | "Path to store output."); 39 | outputPathOption.AddAlias("-o"); 40 | outputPathOption.Required = true; 41 | 42 | rootCommand.AddOption(inputPathOption); 43 | rootCommand.AddOption(formatOption); 44 | rootCommand.AddOption(outputPathOption); 45 | rootCommand.AddOption(actionOption); 46 | rootCommand.Description = "Command line tool to parser tm7 and tb7 files."; 47 | rootCommand.Handler = CommandHandler.Create(RunCommand); 48 | await rootCommand.InvokeAsync(args); 49 | } 50 | 51 | public static void PrintError(string errorMessage) 52 | { 53 | Console.ForegroundColor = ConsoleColor.Red; 54 | Console.WriteLine(errorMessage); 55 | Console.ResetColor(); 56 | } 57 | 58 | public static void RunCommand(FileInfo inputpath, string saveformat, string[] get, FileInfo outputpath) 59 | { 60 | try 61 | { 62 | if (inputpath == null || saveformat == null || get == null || outputpath == null) 63 | { 64 | throw new ArgumentNullException("Missing inputs. -i/--input-path, -g/--get, -o/--output-path and -s/--save-format are required."); 65 | } 66 | var extenison = inputpath.Extension.ToLower(); 67 | if (extenison != ".tm7" && extenison != ".tb7") 68 | { 69 | throw new ArgumentException("Invalid -i/--input-path."); 70 | } 71 | var parser = new Parser(inputpath); 72 | foreach (string category in get) 73 | { 74 | var result = parser.GetData(category); 75 | switch (saveformat) 76 | { 77 | case "json": 78 | string outputJson = JsonSerializer.Serialize(result); 79 | var outputFilePath = Path.Combine(outputpath.FullName, Path.GetFileNameWithoutExtension(inputpath.FullName) + "-" + category + ".json"); 80 | try 81 | { 82 | File.WriteAllText(outputFilePath, outputJson); 83 | } 84 | catch 85 | { 86 | throw new Exception("Error occured while converting the file."); 87 | } 88 | 89 | Console.WriteLine(); 90 | Console.WriteLine("File saved. Path : " + outputFilePath); 91 | break; 92 | default: 93 | throw new ArgumentException("Invalid -s/--save-format:" + saveformat); 94 | } 95 | } 96 | } 97 | catch (Exception e) 98 | { 99 | PrintError(e.Message); 100 | } 101 | } 102 | 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /TMFileParser/TMFileConverter/TMFileConverter.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net7.0 6 | Microsoft.ThreatModeling.TMFileConverter 7 | Microsoft 8 | MIT 9 | https://github.com/microsoft/tm-file-parser 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31019.35 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TMFileParser", "TMFileParser\TMFileParser.csproj", "{C8E41553-0AEE-42CF-9862-0206F4471CB4}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TMFileParserTest", "TMFileParserTest\TMFileParserTest.csproj", "{D3BBDA04-A8C8-48B1-A606-9412283C5ACC}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TMFileConverter", "TMFileConverter\TMFileConverter.csproj", "{3C897A7C-087E-433C-BC1F-44595B15FF01}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {C8E41553-0AEE-42CF-9862-0206F4471CB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {C8E41553-0AEE-42CF-9862-0206F4471CB4}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {C8E41553-0AEE-42CF-9862-0206F4471CB4}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {C8E41553-0AEE-42CF-9862-0206F4471CB4}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {D3BBDA04-A8C8-48B1-A606-9412283C5ACC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {D3BBDA04-A8C8-48B1-A606-9412283C5ACC}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {D3BBDA04-A8C8-48B1-A606-9412283C5ACC}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {D3BBDA04-A8C8-48B1-A606-9412283C5ACC}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {3C897A7C-087E-433C-BC1F-44595B15FF01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {3C897A7C-087E-433C-BC1F-44595B15FF01}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {3C897A7C-087E-433C-BC1F-44595B15FF01}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {3C897A7C-087E-433C-BC1F-44595B15FF01}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {F03C4096-E919-4955-919E-AA10523CB96C} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Interfaces/ITMFileReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace TMFileParser.Interfaces 6 | { 7 | public interface ITMFileReader 8 | { 9 | public object GetData(string category); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/output/TM7All.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace TMFileParser.Models.output 9 | { 10 | [ExcludeFromCodeCoverage] 11 | public class TM7All 12 | { 13 | public List diagrams { get; set; } 14 | public List threats { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/output/TM7Asset.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace TMFileParser.Models.output 9 | { 10 | [ExcludeFromCodeCoverage] 11 | public class TM7Asset 12 | { 13 | public string Name { get; set; } 14 | public string DisplayName { get; set; } 15 | public string Guid { get; set; } 16 | public decimal Left { get; set; } 17 | public decimal Top { get; set; } 18 | public decimal Width { get; set; } 19 | public decimal Height { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/output/TM7Boundary.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace TMFileParser.Models.output 9 | { 10 | [ExcludeFromCodeCoverage] 11 | public class TM7Boundary 12 | { 13 | public string Name { get; set; } 14 | public string DisplayName { get; set; } 15 | public string Guid { get; set; } 16 | public string Type { get; set; } 17 | public decimal Left { get; set; } 18 | public decimal Top { get; set; } 19 | public decimal Width { get; set; } 20 | public decimal Height { get; set; } 21 | public List Assets { get; set; } 22 | public List AssetsOnBoundary { get; set; } 23 | public List CrossingDataflows { get; set; } 24 | public List Connectors { get; set; } 25 | public List ChildBoundaries { get; set; } 26 | public List CommonBoundaries { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/output/TM7BoundaryBasic.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace TMFileParser.Models.output 9 | { 10 | [ExcludeFromCodeCoverage] 11 | public class TM7BoundaryBasic 12 | { 13 | public TM7BoundaryBasic(TM7Boundary boundary) { 14 | this.Name = boundary.Name; 15 | this.Guid = boundary.Guid; 16 | this.Top = boundary.Top; 17 | this.Left = boundary.Left; 18 | this.Width = boundary.Width; 19 | this.Height = boundary.Height; 20 | this.DisplayName = boundary.DisplayName; 21 | this.Type = boundary.Type; 22 | this.Assets = boundary.Assets; 23 | } 24 | public string Name { get; set; } 25 | public string DisplayName { get; set; } 26 | public string Guid { get; set; } 27 | public string Type { get; set; } 28 | public decimal Left { get; set; } 29 | public decimal Top { get; set; } 30 | public decimal Width { get; set; } 31 | public decimal Height { get; set; } 32 | public List Assets { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/output/TM7CommonBoundary.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace TMFileParser.Models.output 9 | { 10 | [ExcludeFromCodeCoverage] 11 | public class TM7CommonBoundary 12 | { 13 | public TM7BoundaryBasic Boundary { get; set; } 14 | public List CommonAssets { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/output/TM7Connector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace TMFileParser.Models.output 9 | { 10 | [ExcludeFromCodeCoverage] 11 | public class TM7Connector 12 | { 13 | public string Name { get; set; } 14 | public string DisplayName { get; set; } 15 | public string Guid { get; set; } 16 | public TM7Asset SourceAsset { get; set; } 17 | public TM7Asset TargetAsset { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/output/TM7Diagram.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | 4 | namespace TMFileParser.Models.output 5 | { 6 | [ExcludeFromCodeCoverage] 7 | public class TM7Diagram 8 | { 9 | public string diagram { get; set; } 10 | public List boundaries { get; set; } 11 | public List connectors { get; set; } 12 | public List assets { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/output/TM7Threat.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace TMFileParser.Models.output 9 | { 10 | [ExcludeFromCodeCoverage] 11 | public class TM7Threat 12 | { 13 | public string id { get; set; } 14 | public string diagram { get; set; } 15 | public string changedBy { get; set; } 16 | public DateTime lastModified { get; set; } 17 | public string title { get; set; } 18 | public string category { get; set; } 19 | public string description { get; set; } 20 | public string justifications { get; set; } 21 | public string interaction { get; set; } 22 | public string priority { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tb7/TB7Attribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tb7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TB7Attribute 11 | { 12 | [XmlElement("IsInherited")] 13 | public bool isInherited { get; set; } 14 | [XmlElement("DisplayName")] 15 | public string displayName { get; set; } 16 | [XmlElement("Id")] 17 | public string id { get; set; } 18 | [XmlElement("Inheritance")] 19 | public string inheritance { get; set; } 20 | [XmlElement("Mode")] 21 | public string mode { get; set; } 22 | [XmlElement("Name")] 23 | public string name { get; set; } 24 | [XmlElement("Type")] 25 | public string type { get; set; } 26 | [XmlElement("AttributeValues")] 27 | public TB7AttributeValues attributeValues { get; set; } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tb7/TB7AttributeValues.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tb7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TB7AttributeValues 11 | { 12 | [XmlElement("Value")] 13 | public List value { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tb7/TB7Attributes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tb7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TB7Attributes 11 | { 12 | [XmlElement("Attribute")] 13 | public List attribute { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tb7/TB7ElementType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tb7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TB7ElementType 11 | { 12 | [XmlElement("Name")] 13 | public string name { get; set; } 14 | [XmlElement("Description")] 15 | public string description { get; set; } 16 | [XmlElement("Hidden")] 17 | public bool hidden { get; set; } 18 | [XmlElement("Representation")] 19 | public string representation { get; set; } 20 | [XmlElement("Id")] 21 | public string id { get; set; } 22 | [XmlElement("ImageLocation")] 23 | public string imageLocation { get; set; } 24 | [XmlElement("ParentElement")] 25 | public string parentElement { get; set; } 26 | [XmlElement("Image")] 27 | public string image { get; set; } 28 | [XmlElement("Attributes")] 29 | public TB7Attributes attributes { get; set; } 30 | [XmlElement("StrokeThickness")] 31 | public float strokeThickness { get; set; } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tb7/TB7GenerationFilters.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tb7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TB7GenerationFilters 11 | { 12 | [XmlElement("Include")] 13 | public string include { get; set; } 14 | [XmlElement("Exclude")] 15 | public string exclude { get; set; } 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tb7/TB7GenericElements.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tb7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TB7GenericElements 11 | { 12 | [XmlElement("ElementType")] 13 | public List elementType { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tb7/TB7KnowledgeBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tb7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | [XmlRoot("KnowledgeBase")] 11 | public class TB7KnowledgeBase 12 | { 13 | [XmlElement("Manifest")] 14 | public TB7Manifest manifest { get; set; } 15 | [XmlElement("ThreatMetaData")] 16 | public TB7ThreatMetaData threatMetaData { get; set; } 17 | [XmlElement("GenericElements")] 18 | public TB7GenericElements genericElements { get; set; } 19 | [XmlElement("StandardElements")] 20 | public TB7StandardElements standardElements { get; set; } 21 | [XmlElement("ThreatCategories")] 22 | public TB7ThreatCategories threatCategories { get; set; } 23 | [XmlElement("ThreatTypes")] 24 | public TB7ThreatTypes threatTypes { get; set; } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tb7/TB7Manifest.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using System.Xml.Serialization; 3 | 4 | namespace TMFileParser.Models.tb7 5 | { 6 | [ExcludeFromCodeCoverage] 7 | public class TB7Manifest 8 | { 9 | [XmlAttribute("name")] 10 | public string name { get; set; } 11 | [XmlAttribute("id")] 12 | public string id { get; set; } 13 | [XmlAttribute("version")] 14 | public string version { get; set; } 15 | [XmlAttribute("author")] 16 | public string author { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tb7/TB7PropertiesMetaData.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Xml.Serialization; 4 | 5 | namespace TMFileParser.Models.tb7 6 | { 7 | [ExcludeFromCodeCoverage] 8 | public class TB7PropertiesMetaData 9 | { 10 | [XmlElement("ThreatMetaDatum")] 11 | public List threatMetaDatum { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tb7/TB7StandardElements.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tb7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TB7StandardElements 11 | { 12 | [XmlElement("ElementType")] 13 | public List elementType { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tb7/TB7ThreatCategories.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tb7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TB7ThreatCategories 11 | { 12 | [XmlElement("ThreatCategory")] 13 | public List threatCategory { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tb7/TB7ThreatCategory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tb7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TB7ThreatCategory 11 | { 12 | [XmlElement("Id")] 13 | public string id { get; set; } 14 | [XmlElement("Name")] 15 | public string name { get; set; } 16 | [XmlElement("ShortDescription")] 17 | public string shortDescription { get; set; } 18 | [XmlElement("LongDescription")] 19 | public string longDescription { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tb7/TB7ThreatMetaData.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using System.Xml.Serialization; 3 | 4 | namespace TMFileParser.Models.tb7 5 | { 6 | [ExcludeFromCodeCoverage] 7 | public class TB7ThreatMetaData 8 | { 9 | [XmlElement("IsPriorityUsed")] 10 | public bool isPriorityUsed { get; set; } 11 | 12 | [XmlElement("IsStatusUsed")] 13 | public bool isStatusUsed { get; set; } 14 | 15 | [XmlElement("PropertiesMetaData")] 16 | public TB7PropertiesMetaData propertiesMetaData { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tb7/TB7ThreatMetaDatum.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using System.Xml.Serialization; 3 | 4 | namespace TMFileParser.Models.tb7 5 | { 6 | [ExcludeFromCodeCoverage] 7 | public class TB7ThreatMetaDatum 8 | { 9 | [XmlElement("Name")] 10 | public string name { get; set; } 11 | [XmlElement("Label")] 12 | public string label { get; set; } 13 | [XmlElement("HideFromUI")] 14 | public bool hideFromUI { get; set; } 15 | [XmlElement("Values")] 16 | public TB7Values values { get; set; } 17 | [XmlElement("Description")] 18 | public string description { get; set; } 19 | [XmlElement("Id")] 20 | public string id { get; set; } 21 | [XmlElement("AttributeType")] 22 | public int attributeType { get; set; } 23 | } 24 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tb7/TB7ThreatType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tb7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TB7ThreatType 11 | { 12 | [XmlElement("GenerationFilters")] 13 | public TB7GenerationFilters generationFilters { get; set; } 14 | [XmlElement("Id")] 15 | public string id { get; set; } 16 | [XmlElement("ShortTitle")] 17 | public string shortTitle { get; set; } 18 | [XmlElement("RelatedCategory")] 19 | public string relatedCategory { get; set; } 20 | [XmlElement("Category")] 21 | public string category { get; set; } 22 | [XmlElement("Description")] 23 | public string description { get; set; } 24 | [XmlElement("PropertiesMetaData")] 25 | public TB7PropertiesMetaData propertiesMetaData { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tb7/TB7ThreatTypes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tb7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TB7ThreatTypes 11 | { 12 | [XmlElement("ThreatType")] 13 | public List threatType { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tb7/TB7Values.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Xml.Serialization; 4 | 5 | namespace TMFileParser.Models.tb7 6 | { 7 | [ExcludeFromCodeCoverage] 8 | public class TB7Values 9 | { 10 | [XmlElement("Value")] 11 | public List valueList { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7AnyType.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Xml.Serialization; 4 | 5 | namespace TMFileParser.Models.tm7 6 | { 7 | [ExcludeFromCodeCoverage] 8 | public class TM7AnyType 9 | { 10 | [XmlElement("DisplayName")] 11 | public string DisplayName { get; set; } 12 | [XmlElement("Name")] 13 | public string Name { get; set; } 14 | [XmlAttribute("type")] 15 | public string type { get; set; } 16 | [XmlElement("Value")] 17 | public TM7Value value { get; set; } 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7Attribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tm7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TM7Attribute 11 | { 12 | [XmlElement("IsExtension")] 13 | public bool isExtension { get; set; } 14 | [XmlElement("AttributeValues")] 15 | public TM7AttributeValues attributeValues { get; set; } 16 | [XmlElement("DisplayName")] 17 | public string displayName { get; set; } 18 | [XmlElement("Inheritance")] 19 | public string inheritance { get; set; } 20 | [XmlElement("Mode")] 21 | public string mode { get; set; } 22 | [XmlElement("Name")] 23 | public string name { get; set; } 24 | [XmlElement("Type")] 25 | public string type { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7AttributeValues.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tm7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TM7AttributeValues 11 | { 12 | [XmlElement("Value")] 13 | public List value { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7Attributes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tm7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TM7Attributes 11 | { 12 | [XmlElement("Attribute")] 13 | public List attribute { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7Borders.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Xml.Serialization; 4 | 5 | namespace TMFileParser.Models.tm7 6 | { 7 | [ExcludeFromCodeCoverage] 8 | public class TM7Borders 9 | { 10 | [XmlElement("KeyValueOfguidanyType")] 11 | public List keyValueOfguidanyType { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7BordersKeyValueOfguidanyType.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Xml.Serialization; 4 | 5 | namespace TMFileParser.Models.tm7 6 | { 7 | [ExcludeFromCodeCoverage] 8 | public class TM7BordersKeyValueOfguidanyType 9 | { 10 | [XmlElement("Key")] 11 | public string key { get; set; } 12 | [XmlElement("Value")] 13 | public TM7BordersValue value { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7BordersValue.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Xml.Serialization; 4 | 5 | namespace TMFileParser.Models.tm7 6 | { 7 | [ExcludeFromCodeCoverage] 8 | public class TM7BordersValue 9 | { 10 | [XmlElement("GenericTypeId", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 11 | public string genericTypeId { get; set; } 12 | [XmlElement("Guid", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 13 | public string guid { get; set; } 14 | [XmlElement("Properties", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 15 | public TM7Properties properties { get; set; } 16 | [XmlElement("TypeId", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 17 | public string typeId { get; set; } 18 | [XmlElement("Height", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 19 | public decimal height { get; set; } 20 | [XmlElement("Left", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 21 | public decimal left { get; set; } 22 | [XmlElement("StrokeThickness", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 23 | public decimal strokeThickness { get; set; } 24 | [XmlElement("StrokeDashArray", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 25 | public string strokeDashArray { get; set; } 26 | [XmlElement("Top", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 27 | public decimal top { get; set; } 28 | [XmlElement("Width", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 29 | public decimal width { get; set; } 30 | [XmlAttribute("type")] 31 | public string type { get; set; } 32 | [XmlAttribute("Id")] 33 | public string id { get; set; } 34 | } 35 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7DrawingSurfaceList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Xml.Serialization; 4 | 5 | namespace TMFileParser.Models.tm7 6 | { 7 | [ExcludeFromCodeCoverage] 8 | public class TM7DrawingSurfaceList 9 | { 10 | [XmlElement("DrawingSurfaceModel")] 11 | public List drawingSurfaceModel { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7DrawingSurfaceModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Xml.Serialization; 4 | 5 | namespace TMFileParser.Models.tm7 6 | { 7 | [ExcludeFromCodeCoverage] 8 | public class TM7DrawingSurfaceModel 9 | { 10 | [XmlElement("GenericTypeId", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 11 | public string genericTypeId { get; set; } 12 | [XmlElement("Guid", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 13 | public string guid { get; set; } 14 | [XmlElement("TypeId", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 15 | public string typeId { get; set; } 16 | [XmlElement("Header")] 17 | public string header { get; set; } 18 | [XmlElement("Zoom")] 19 | public decimal zoom { get; set; } 20 | [XmlElement("Properties", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 21 | public TM7Properties properties { get; set; } 22 | [XmlElement("Borders")] 23 | public TM7Borders borders { get; set; } 24 | [XmlElement("Lines")] 25 | public TM7Lines lines { get; set; } 26 | } 27 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7ElementType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tm7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TM7ElementType 11 | { 12 | [XmlElement("IsExtension")] 13 | public bool isExtension { get; set; } 14 | [XmlElement("AvailableToBaseModels")] 15 | public string availableToBaseModels { get; set; } 16 | [XmlElement("Name")] 17 | public string name { get; set; } 18 | [XmlElement("Behavior")] 19 | public string behavior { get; set; } 20 | [XmlElement("Description")] 21 | public string description { get; set; } 22 | [XmlElement("Hidden")] 23 | public bool hidden { get; set; } 24 | [XmlElement("Representation")] 25 | public string representation { get; set; } 26 | [XmlElement("Id")] 27 | public string id { get; set; } 28 | [XmlElement("ImageLocation")] 29 | public string imageLocation { get; set; } 30 | [XmlElement("ImageSource")] 31 | public string imageSource { get; set; } 32 | [XmlElement("ParentId")] 33 | public string parentId { get; set; } 34 | [XmlElement("Shape")] 35 | public string shape { get; set; } 36 | [XmlElement("ImageStream")] 37 | public string imageStream { get; set; } 38 | [XmlElement("Attributes")] 39 | public TM7Attributes attributes { get; set; } 40 | [XmlElement("StencilConstraints")] 41 | public TM7StencilConstraints stencilConstraints { get; set; } 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7GenerationFilters.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tm7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TM7GenerationFilters 11 | { 12 | [XmlElement("Include")] 13 | public string include { get; set; } 14 | [XmlElement("Exclude")] 15 | public string exclude { get; set; } 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7GenericElements.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tm7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TM7GenericElements 11 | { 12 | [XmlElement("ElementType")] 13 | public List elementType { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7KeyValueOfstringThreatpc_P0_PhOB.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Xml.Serialization; 4 | 5 | namespace TMFileParser.Models.tm7 6 | { 7 | [ExcludeFromCodeCoverage] 8 | public class TM7KeyValueOfstringThreatpc_P0_PhOB 9 | { 10 | [XmlElement("Key")] 11 | public string key { get; set; } 12 | [XmlElement("Value")] 13 | public TM7ThreatInstancesValue value { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7KeyValueOfstringstring.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Xml.Serialization; 4 | 5 | namespace TMFileParser.Models.tm7 6 | { 7 | [ExcludeFromCodeCoverage] 8 | public class TM7KeyValueOfstringstring 9 | { 10 | [XmlElement("Key")] 11 | public string key { get; set; } 12 | [XmlElement("Value")] 13 | public string value { get; set; } 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7KnowledgeBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tm7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TM7KnowledgeBase 11 | { 12 | [XmlAttribute("Id")] 13 | public string id { get; set; } 14 | [XmlElement("Manifest")] 15 | public TM7Manifest manifest { get; set; } 16 | [XmlElement("ThreatMetaData")] 17 | public TM7ThreatMetaData threatMetaData { get; set; } 18 | [XmlElement("GenericElements")] 19 | public TM7GenericElements genericElements { get; set; } 20 | [XmlElement("StandardElements")] 21 | public TM7StandardElements standardElements { get; set; } 22 | [XmlElement("ThreatCategories")] 23 | public TM7ThreatCategories threatCategories { get; set; } 24 | [XmlElement("ThreatTypes")] 25 | public TM7ThreatTypes threatTypes { get; set; } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7Lines.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Xml.Serialization; 4 | 5 | namespace TMFileParser.Models.tm7 6 | { 7 | [ExcludeFromCodeCoverage] 8 | public class TM7Lines 9 | { 10 | [XmlElement("KeyValueOfguidanyType")] 11 | public List keyValueOfguidanyType { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7LinesKeyValueOfguidanyType.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Xml.Serialization; 4 | 5 | namespace TMFileParser.Models.tm7 6 | { 7 | [ExcludeFromCodeCoverage] 8 | public class TM7LinesKeyValueOfguidanyType 9 | { 10 | [XmlElement("Key")] 11 | public string key { get; set; } 12 | [XmlElement("Value")] 13 | public TM7LinesValue value { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7LinesValue.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Xml.Serialization; 4 | 5 | namespace TMFileParser.Models.tm7 6 | { 7 | [ExcludeFromCodeCoverage] 8 | public class TM7LinesValue 9 | { 10 | [XmlElement("GenericTypeId", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 11 | public string genericTypeId { get; set; } 12 | [XmlElement("Guid", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 13 | public string guid { get; set; } 14 | [XmlElement("SourceGuid", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 15 | public string sourceGuid { get; set; } 16 | [XmlElement("TargetGuid", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 17 | public string targetGuid { get; set; } 18 | [XmlElement("PortSource", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 19 | public string portSource { get; set; } 20 | [XmlElement("PortTarget", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 21 | public string portTarget { get; set; } 22 | [XmlElement("Properties", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 23 | public TM7Properties properties { get; set; } 24 | [XmlElement("TypeId", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 25 | public string typeId { get; set; } 26 | [XmlElement("HandleX", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 27 | public decimal handleX { get; set; } 28 | [XmlElement("HandleY", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 29 | public decimal handleY { get; set; } 30 | [XmlElement("SourceX", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 31 | public decimal sourceX { get; set; } 32 | [XmlElement("SourceY", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 33 | public decimal sourceY { get; set; } 34 | [XmlElement("TargetX", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 35 | public decimal targetX { get; set; } 36 | [XmlElement("TargetY", Namespace = "http://schemas.datacontract.org/2004/07/ThreatModeling.Model.Abstracts")] 37 | public decimal targetY { get; set; } 38 | [XmlAttribute("type")] 39 | public string type { get; set; } 40 | [XmlAttribute("id")] 41 | public string id { get; set; } 42 | } 43 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7Manifest.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using System.Xml.Serialization; 3 | 4 | namespace TMFileParser.Models.tm7 5 | { 6 | [ExcludeFromCodeCoverage] 7 | public class TM7Manifest 8 | { 9 | [XmlElement("Name")] 10 | public string name { get; set; } 11 | [XmlElement("Id")] 12 | public string id { get; set; } 13 | [XmlElement("Version")] 14 | public string version { get; set; } 15 | [XmlElement("Author")] 16 | public string author { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7MetaInformation.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using System.Xml.Serialization; 3 | 4 | namespace TMFileParser.Models.tm7 5 | { 6 | [ExcludeFromCodeCoverage] 7 | public class TM7MetaInformation 8 | { 9 | [XmlElement("Assumptions")] 10 | public string assumptions { get; set; } 11 | [XmlElement("Contributors")] 12 | public string contributors { get; set; } 13 | [XmlElement("ExternalDependencies")] 14 | public string externalDependencies { get; set; } 15 | [XmlElement("HighLevelSystemDescription")] 16 | public string highLevelSystemDescription { get; set; } 17 | [XmlElement("Owner")] 18 | public string owner { get; set; } 19 | [XmlElement("Reviewer")] 20 | public string reviewer { get; set; } 21 | [XmlElement("ThreatModelName")] 22 | public string threatModelName { get; set; } 23 | } 24 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7Note.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Xml.Serialization; 5 | 6 | namespace TMFileParser.Models.tm7 7 | { 8 | [ExcludeFromCodeCoverage] 9 | public class TM7Note 10 | { 11 | [XmlElement("AddedBy")] 12 | public string addedBy { get; set; } 13 | [XmlElement("Date")] 14 | public DateTime date { get; set; } 15 | [XmlAttribute("Id")] 16 | public decimal id { get; set; } 17 | [XmlElement("Message")] 18 | public string message { get; set; } 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7Notes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tm7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TM7Notes 11 | { 12 | [XmlElement("Note")] 13 | public List note { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7Profile.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | 3 | namespace TMFileParser.Models.tm7 4 | { 5 | [ExcludeFromCodeCoverage] 6 | public class TM7Profile 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7Properties.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Xml.Serialization; 4 | 5 | namespace TMFileParser.Models.tm7 6 | { 7 | [ExcludeFromCodeCoverage] 8 | 9 | public class TM7Properties 10 | { 11 | [XmlElement("anyType")] 12 | public List anyType { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7PropertiesMetaData.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Xml.Serialization; 4 | 5 | namespace TMFileParser.Models.tm7 6 | { 7 | [ExcludeFromCodeCoverage] 8 | public class TM7PropertiesMetaData 9 | { 10 | [XmlElement("ThreatMetaDatum")] 11 | public List threatMetaDatum { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7StandardElements.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tm7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TM7StandardElements 11 | { 12 | [XmlElement("ElementType")] 13 | public List elementType { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7StencilConstraint.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tm7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TM7StencilConstraint 11 | { 12 | [XmlElement("IsExtension")] 13 | public bool isExtension { get; set; } 14 | [XmlElement("SelectedStencilConnection")] 15 | public string selectedStencilConnection { get; set; } 16 | [XmlElement("SelectedStencilType")] 17 | public string selectedStencilType { get; set; } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7StencilConstraints.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tm7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TM7StencilConstraints 11 | { 12 | [XmlElement("StencilConstraint")] 13 | public List stencilConstraint { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7ThreatCategories.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tm7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TM7ThreatCategories 11 | { 12 | [XmlElement("ThreatCategory")] 13 | public List threatCategory { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7ThreatCategory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tm7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TM7ThreatCategory 11 | { 12 | [XmlElement("IsExtension")] 13 | public bool isExtension { get; set; } 14 | [XmlElement("Id")] 15 | public string id { get; set; } 16 | [XmlElement("Name")] 17 | public string name { get; set; } 18 | [XmlElement("ShortDescription")] 19 | public string shortDescription { get; set; } 20 | [XmlElement("LongDescription")] 21 | public string longDescription { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7ThreatInstanceProperties.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tm7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TM7ThreatInstanceProperties 11 | { 12 | [XmlElement("KeyValueOfstringstring")] 13 | public List keyValueOfstringstring { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7ThreatInstances.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Xml.Serialization; 4 | 5 | namespace TMFileParser.Models.tm7 6 | { 7 | [ExcludeFromCodeCoverage] 8 | public class TM7ThreatInstances 9 | { 10 | [XmlElement("KeyValueOfstringThreatpc_P0_PhOB")] 11 | public List keyValueOfstringThreatpc_P0_PhOB { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7ThreatInstancesValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Xml.Serialization; 5 | 6 | namespace TMFileParser.Models.tm7 7 | { 8 | [ExcludeFromCodeCoverage] 9 | public class TM7ThreatInstancesValue 10 | { 11 | [XmlElement("ChangedBy")] 12 | public string changedBy { get; set; } 13 | [XmlElement("DrawingSurfaceGuid")] 14 | public string drawingSurfaceGuid { get; set; } 15 | [XmlElement("Properties")] 16 | public TM7ThreatInstanceProperties properties { get; set; } 17 | [XmlElement("FlowGuid")] 18 | public string flowGuid { get; set; } 19 | [XmlElement("Id")] 20 | public string id { get; set; } 21 | [XmlElement("InteractionKey")] 22 | public string interactionKey { get; set; } 23 | [XmlElement("InteractionString")] 24 | public string interactionString { get; set; } 25 | [XmlElement("ModifiedAt")] 26 | public DateTime ModifiedAt { get; set; } 27 | [XmlElement("Priority")] 28 | public string Priority { get; set; } 29 | [XmlElement("SourceGuid")] 30 | public string sourceGuid { get; set; } 31 | [XmlElement("State")] 32 | public string state { get; set; } 33 | [XmlElement("StateInformation")] 34 | public string stateInformation { get; set; } 35 | [XmlElement("TargetGuid")] 36 | public string targetGuid { get; set; } 37 | [XmlElement("Title")] 38 | public string title { get; set; } 39 | [XmlElement("TypeId")] 40 | public string typeId { get; set; } 41 | [XmlElement("Upgraded")] 42 | public bool upgraded { get; set; } 43 | [XmlElement("UserThreatCategory")] 44 | public string userThreatCategory { get; set; } 45 | [XmlElement("UserThreatDescription")] 46 | public string userThreatDescription { get; set; } 47 | [XmlElement("UserThreatShortDescription")] 48 | public string userThreatShortDescription { get; set; } 49 | [XmlElement("Wide")] 50 | public bool wide { get; set; } 51 | 52 | } 53 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7ThreatMetaData.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using System.Xml.Serialization; 3 | 4 | namespace TMFileParser.Models.tm7 5 | { 6 | [ExcludeFromCodeCoverage] 7 | public class TM7ThreatMetaData 8 | { 9 | [XmlElement("IsPriorityUsed")] 10 | public bool isPriorityUsed { get; set; } 11 | 12 | [XmlElement("IsStatusUsed")] 13 | public bool isStatusUsed { get; set; } 14 | 15 | [XmlElement("PropertiesMetaData")] 16 | public TM7PropertiesMetaData propertiesMetaData { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7ThreatMetaDatum.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using System.Xml.Serialization; 3 | 4 | namespace TMFileParser.Models.tm7 5 | { 6 | [ExcludeFromCodeCoverage] 7 | public class TM7ThreatMetaDatum 8 | { 9 | [XmlElement("Name")] 10 | public string name { get; set; } 11 | [XmlElement("Label")] 12 | public string label { get; set; } 13 | [XmlElement("HideFromUI")] 14 | public bool hideFromUI { get; set; } 15 | [XmlElement("Values")] 16 | public TM7Values values { get; set; } 17 | [XmlElement("Id")] 18 | public string id { get; set; } 19 | [XmlElement("AttributeType")] 20 | public decimal attributeType { get; set; } 21 | } 22 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7ThreatModel.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using System.Xml.Serialization; 3 | using TMFileParser.Models.tb7; 4 | 5 | namespace TMFileParser.Models.tm7 6 | { 7 | 8 | [ExcludeFromCodeCoverage] 9 | [XmlRoot("ThreatModel")] 10 | public class TM7ThreatModel 11 | { 12 | [XmlElement("DrawingSurfaceList")] 13 | public TM7DrawingSurfaceList drawingSurfaceList { get; set; } 14 | 15 | [XmlElement("MetaInformation")] 16 | public TM7MetaInformation metaInformation { get; set; } 17 | 18 | [XmlElement("Notes")] 19 | public TM7Notes notes { get; set; } 20 | 21 | [XmlElement("ThreatInstances")] 22 | public TM7ThreatInstances threatInstances { get; set; } 23 | 24 | [XmlElement("ThreatGenerationEnabled")] 25 | private string threatGenerationEnabledString { get; set; } 26 | 27 | public bool threatGenerationEnabled 28 | { 29 | get 30 | { 31 | if (string.IsNullOrEmpty(this.threatGenerationEnabledString)) 32 | { 33 | return true; 34 | } 35 | return bool.Parse(this.threatGenerationEnabledString); 36 | } 37 | } 38 | 39 | [XmlElement("Validations")] 40 | public TM7Validations validations { get; set; } 41 | 42 | [XmlElement("KnowledgeBase")] 43 | public TM7KnowledgeBase knowledgeBase { get; set; } 44 | 45 | [XmlElement("Profile")] 46 | public TM7Profile profile { get; set; } 47 | 48 | [XmlElement("Version")] 49 | public string version { get; set; } 50 | 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7ThreatType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tm7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TM7ThreatType 11 | { 12 | [XmlElement("IsExtension")] 13 | public bool isExtension { get; set; } 14 | [XmlElement("GenerationFilters")] 15 | public TM7GenerationFilters generationFilters { get; set; } 16 | [XmlElement("Id")] 17 | public string id { get; set; } 18 | [XmlElement("ShortTitle")] 19 | public string shortTitle { get; set; } 20 | [XmlElement("Category")] 21 | public string category { get; set; } 22 | [XmlElement("RelatedCategory")] 23 | public string relatedCategory { get; set; } 24 | [XmlElement("Description")] 25 | public string description { get; set; } 26 | [XmlElement("PropertiesMetaData")] 27 | public TM7PropertiesMetaData propertiesMetaData { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7ThreatTypes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace TMFileParser.Models.tm7 8 | { 9 | [ExcludeFromCodeCoverage] 10 | public class TM7ThreatTypes 11 | { 12 | [XmlElement("ThreatType")] 13 | public List threatType { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7Validations.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | 3 | namespace TMFileParser.Models.tm7 4 | { 5 | [ExcludeFromCodeCoverage] 6 | public class TM7Validations 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7Value.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Xml.Serialization; 4 | 5 | namespace TMFileParser.Models.tm7 6 | { 7 | [ExcludeFromCodeCoverage] 8 | public class TM7Value 9 | { 10 | [XmlText] 11 | public string value { get; set; } 12 | [XmlAttribute("type")] 13 | public string type { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Models/tm7/TM7Values.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Xml.Serialization; 4 | 5 | namespace TMFileParser.Models.tm7 6 | { 7 | [ExcludeFromCodeCoverage] 8 | public class TM7Values 9 | { 10 | [XmlElement("Value")] 11 | public List value { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/Parser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Text; 5 | using TMFileParser.Interfaces; 6 | 7 | namespace TMFileParser 8 | { 9 | public class Parser 10 | { 11 | private FileInfo _inputFile; 12 | public ITMFileReader _reader; 13 | 14 | public Parser(FileInfo inputFile) 15 | { 16 | this._inputFile = inputFile; 17 | SelectReader(); 18 | } 19 | 20 | private void SelectReader() 21 | { 22 | switch (_inputFile.Extension.ToLower()) 23 | { 24 | case ".tm7": 25 | _reader = _reader ?? new TM7FileReader(this._inputFile); 26 | break; 27 | case ".tb7": 28 | _reader = _reader ?? new TB7FileReader(this._inputFile); 29 | break; 30 | default: 31 | throw new NotSupportedException("Invalid File Format/Path"); 32 | } 33 | } 34 | 35 | public object GetData(string category) 36 | { 37 | category = category.ToLower(); 38 | return _reader.GetData(category); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/TB7FileReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.IO; 5 | using System.Text; 6 | using System.Xml; 7 | using System.Xml.Serialization; 8 | using TMFileParser.Interfaces; 9 | using TMFileParser.Models.tb7; 10 | 11 | namespace TMFileParser 12 | { 13 | public class TB7FileReader : ITMFileReader 14 | { 15 | protected string _fileContent; 16 | private TB7KnowledgeBase _tmData; 17 | [ExcludeFromCodeCoverage] 18 | public TB7FileReader(FileInfo inputFile) 19 | { 20 | _fileContent = File.ReadAllText(inputFile.FullName); 21 | this.ReadTMFile(); 22 | } 23 | 24 | private void ReadTMFile() 25 | { 26 | StringReader stringReader = new StringReader(_fileContent); 27 | XmlReaderSettings settings = new XmlReaderSettings(); 28 | settings.DtdProcessing = DtdProcessing.Prohibit; 29 | settings.XmlResolver = null; 30 | XmlReader xmlReader = XmlReader.Create(stringReader, settings); 31 | XmlSerializer serializer = new XmlSerializer(typeof(TB7KnowledgeBase), new XmlRootAttribute("KnowledgeBase")); 32 | this._tmData = (TB7KnowledgeBase)serializer.Deserialize(xmlReader); 33 | } 34 | 35 | public object GetData(string category) 36 | { 37 | switch (category) 38 | { 39 | case "all": 40 | return this._tmData; 41 | default: 42 | throw new InvalidDataException("Invalid Get Operation:" + category ); 43 | } 44 | } 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/TM7FileReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.IO; 5 | using System.Text; 6 | using System.Xml.Serialization; 7 | using TMFileParser.Interfaces; 8 | using TMFileParser.Models.tm7; 9 | using System.Linq; 10 | using System.Text.RegularExpressions; 11 | using System.Xml; 12 | using TMFileParser.Models.output; 13 | 14 | namespace TMFileParser 15 | { 16 | public class TM7FileReader : ITMFileReader 17 | { 18 | protected string _fileContent; 19 | private TM7ThreatModel _tmRawData; 20 | private TM7All _tmAllData; 21 | [ExcludeFromCodeCoverage] 22 | public TM7FileReader(FileInfo inputFile) 23 | { 24 | this._tmAllData = new TM7All(); 25 | _fileContent = File.ReadAllText(inputFile.FullName); 26 | this.ReadTMFile(); 27 | } 28 | 29 | private void ReadTMFile() 30 | { 31 | StringReader stringReader = new StringReader(this.PreProcessData(_fileContent)); 32 | XmlReaderSettings settings = new XmlReaderSettings(); 33 | settings.DtdProcessing = DtdProcessing.Prohibit; 34 | settings.XmlResolver = null; 35 | XmlReader xmlReader = XmlReader.Create(stringReader, settings); 36 | XmlSerializer serializer = new XmlSerializer(typeof(TM7ThreatModel), "http://schemas.datacontract.org/2004/07/ThreatModeling.Model"); 37 | this._tmRawData = (TM7ThreatModel)serializer.Deserialize(xmlReader); 38 | this.ReadDiagramElements(); 39 | this.ReadThreats(); 40 | } 41 | 42 | private void ReadThreats() 43 | { 44 | var threats = new List(); 45 | foreach (TM7KeyValueOfstringThreatpc_P0_PhOB threatInstance in _tmRawData.threatInstances.keyValueOfstringThreatpc_P0_PhOB) 46 | { 47 | var threat = new TM7Threat(); 48 | threat.id = threatInstance.value.id; 49 | threat.diagram = this._tmRawData.drawingSurfaceList.drawingSurfaceModel 50 | .Where(x => x.guid == threatInstance.value.drawingSurfaceGuid).FirstOrDefault()? 51 | .properties.anyType.Where(d => d.type == "StringDisplayAttribute" && d.DisplayName == "Name") 52 | .FirstOrDefault()?.value.value; 53 | threat.changedBy = threatInstance.value.changedBy; 54 | threat.lastModified = threatInstance.value.ModifiedAt; 55 | threat.title = threatInstance.value.properties.keyValueOfstringstring 56 | .Where(x => x.key == "Title").FirstOrDefault()?.value; 57 | threat.category = threatInstance.value.properties.keyValueOfstringstring 58 | .Where(x => x.key == "UserThreatCategory").FirstOrDefault()?.value; 59 | threat.description = threatInstance.value.properties.keyValueOfstringstring 60 | .Where(x => x.key == "UserThreatDescription").FirstOrDefault()?.value; 61 | threat.justifications = threatInstance.value.properties.keyValueOfstringstring 62 | .Where(x => x.key == "StateInformation").FirstOrDefault()?.value; 63 | threat.interaction = threatInstance.value.properties.keyValueOfstringstring 64 | .Where(x => x.key == "InteractionString").FirstOrDefault()?.value; 65 | threat.priority = threatInstance.value.properties.keyValueOfstringstring 66 | .Where(x => x.key == "Priority").FirstOrDefault()?.value; 67 | 68 | threats.Add(threat); 69 | } 70 | this._tmAllData.threats = threats; 71 | } 72 | 73 | private void ReadDiagramElements() 74 | { 75 | var diagrams = new List(); 76 | foreach (TM7DrawingSurfaceModel model in this._tmRawData.drawingSurfaceList.drawingSurfaceModel) 77 | { 78 | var diagram = new TM7Diagram(); 79 | diagram.diagram = model.properties.anyType.Where(d => d.type == "StringDisplayAttribute" && d.DisplayName == "Name") 80 | .FirstOrDefault()?.value.value; 81 | var boundaries = new List(); 82 | var connectors = new List(); 83 | var assets = new List(); 84 | 85 | foreach (TM7BordersKeyValueOfguidanyType border in model.borders.keyValueOfguidanyType) 86 | { 87 | if (border.value.type.ToLower() == "BorderBoundary".ToLower() || border.value.type.ToLower() == "LineBoundary".ToLower()) 88 | { 89 | var boundary = new TM7Boundary(); 90 | boundary.Name = border.value.properties.anyType 91 | .Where(x => x.type == "HeaderDisplayAttribute").FirstOrDefault()?.DisplayName; 92 | boundary.DisplayName = border.value.properties.anyType 93 | .Where(x => x.type == "StringDisplayAttribute" && x.DisplayName == "Name").FirstOrDefault()?.value.value; 94 | boundary.Guid = border.value.guid; 95 | boundary.Type = border.value.type; 96 | boundary.Height = border.value.height; 97 | boundary.Width = border.value.width; 98 | boundary.Left = border.value.left; 99 | boundary.Top = border.value.top; 100 | boundaries.Add(boundary); 101 | } 102 | else 103 | { 104 | var asset = new TM7Asset(); 105 | asset.Name = border.value.properties.anyType 106 | .Where(x => x.type == "HeaderDisplayAttribute").FirstOrDefault()?.DisplayName; 107 | asset.DisplayName = border.value.properties.anyType 108 | .Where(x => x.type == "StringDisplayAttribute" && x.DisplayName == "Name").FirstOrDefault()?.value.value; 109 | asset.Guid = border.value.guid; 110 | asset.Height = border.value.height; 111 | asset.Width = border.value.width; 112 | asset.Left = border.value.left; 113 | asset.Top = border.value.top; 114 | asset.Guid = border.value.guid; 115 | assets.Add(asset); 116 | } 117 | } 118 | 119 | foreach (TM7LinesKeyValueOfguidanyType line in model.lines.keyValueOfguidanyType) 120 | { 121 | if (line.value.type.ToLower() == "BorderBoundary".ToLower() || line.value.type.ToLower() == "LineBoundary".ToLower()) 122 | { 123 | var boundary = new TM7Boundary(); 124 | boundary.Name = line.value.properties.anyType 125 | .Where(x => x.type == "HeaderDisplayAttribute").FirstOrDefault()?.DisplayName; 126 | boundary.DisplayName = line.value.properties.anyType 127 | .Where(x => x.type == "StringDisplayAttribute" && x.DisplayName == "Name").FirstOrDefault()?.value.value; 128 | boundary.Type = line.value.type; 129 | boundary.Guid = line.value.guid; 130 | boundaries.Add(boundary); 131 | } 132 | else if (line.value.type.ToLower() == "Connector".ToLower()) 133 | { 134 | var connector = new TM7Connector(); 135 | connector.Name = line.value.properties.anyType 136 | .Where(x => x.type == "HeaderDisplayAttribute").FirstOrDefault()?.DisplayName; 137 | connector.DisplayName = line.value.properties.anyType 138 | .Where(x => x.type == "StringDisplayAttribute" && x.DisplayName == "Name").FirstOrDefault()?.value.value; 139 | connector.SourceAsset = assets.Where(x => x.Guid == line.value.sourceGuid).FirstOrDefault(); 140 | connector.TargetAsset = assets.Where(x => x.Guid == line.value.targetGuid).FirstOrDefault(); 141 | connector.Guid= line.value.guid; 142 | connectors.Add(connector); 143 | } 144 | } 145 | 146 | foreach (TM7Boundary boundary in boundaries) 147 | { 148 | if (boundary.Type == "BorderBoundary") 149 | { 150 | boundary.Assets = assets.Where(x => x.Left > boundary.Left 151 | && x.Left + x.Width < boundary.Left + boundary.Width 152 | && x.Top > boundary.Top 153 | && x.Top + x.Height < boundary.Top + boundary.Height).ToList(); 154 | 155 | boundary.AssetsOnBoundary = assets.Where(x => x.Left >= boundary.Left - x.Width 156 | && x.Left + x.Width <= boundary.Left + boundary.Width + x.Width 157 | && x.Top >= boundary.Top - x.Height 158 | && x.Top + x.Height <= boundary.Top + boundary.Height + x.Height 159 | &&!boundary.Assets.Contains(x)).ToList(); 160 | 161 | boundary.ChildBoundaries = boundaries.Where(x => x.Left > boundary.Left 162 | && x.Left + x.Width < boundary.Left + boundary.Width 163 | && x.Top > boundary.Top 164 | && x.Top + x.Height < boundary.Top + boundary.Height).ToList(); 165 | 166 | 167 | 168 | boundary.Connectors = new List(); 169 | boundary.CrossingDataflows = new List(); 170 | foreach (TM7Connector connector in connectors) 171 | { 172 | bool containsSource = boundary.Assets.Contains(connector.SourceAsset); 173 | bool containsTarget = boundary.Assets.Contains(connector.TargetAsset); 174 | if (containsSource && containsTarget) { 175 | boundary.Connectors.Add(connector); 176 | } else if ((!containsSource && containsTarget) || (containsSource && !containsTarget)) 177 | { 178 | boundary.CrossingDataflows.Add(connector); 179 | } 180 | } 181 | } 182 | } 183 | 184 | foreach (TM7Boundary boundary in boundaries) { 185 | if (boundary.Type == "BorderBoundary") { 186 | var commonBoundaries = boundaries.Where(x => x.Left >= boundary.Left - x.Width 187 | && x.Left + x.Width <= boundary.Left + boundary.Width + x.Width 188 | && x.Top >= boundary.Top - x.Height 189 | && x.Top + x.Height <= boundary.Top + boundary.Height + x.Height 190 | && !boundary.ChildBoundaries.Contains(x) 191 | && x != boundary).ToList(); 192 | 193 | boundary.CommonBoundaries = new List(); 194 | 195 | foreach (TM7Boundary commonBoundary in commonBoundaries) 196 | { 197 | var common = new TM7CommonBoundary(); 198 | common.Boundary = new TM7BoundaryBasic(commonBoundary); 199 | 200 | boundary.CommonBoundaries.Add(common); 201 | 202 | } 203 | foreach (TM7CommonBoundary commonBoundary in boundary.CommonBoundaries) { 204 | if (boundary.Assets != null && commonBoundary.Boundary.Assets != null) { 205 | commonBoundary.CommonAssets = boundary.Assets?.ToList().Intersect(commonBoundary.Boundary.Assets?.ToList()).ToList(); 206 | } 207 | } 208 | } 209 | } 210 | 211 | 212 | diagram.boundaries = boundaries; 213 | diagram.connectors = connectors; 214 | diagram.assets = assets; 215 | diagrams.Add(diagram); 216 | this._tmAllData.diagrams = diagrams; 217 | } 218 | } 219 | 220 | private string PreProcessData(string fileContent) 221 | { 222 | return Regex.Replace(fileContent, "[abiz]:", ""); 223 | } 224 | 225 | public object GetData(string category) 226 | { 227 | switch (category) 228 | { 229 | case "raw": 230 | return this._tmRawData; 231 | case "all": 232 | return this._tmAllData; 233 | case "threats": 234 | return this._tmAllData.threats; 235 | case "boundaries": 236 | return this._tmAllData.diagrams.Select(x => new { 237 | x.diagram, 238 | x.boundaries 239 | }); 240 | case "connectors": 241 | return this._tmAllData.diagrams.Select(x => new { 242 | x.diagram, 243 | x.connectors 244 | }); 245 | case "assets": 246 | return this._tmAllData.diagrams.Select(x => new { 247 | x.diagram, 248 | x.assets 249 | }); 250 | default: 251 | throw new InvalidDataException("Invalid Get Operation:" + category); 252 | } 253 | } 254 | } 255 | } 256 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParser/TMFileParser.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | true 6 | Microsoft.ThreatModeling.TMFileParser 7 | true 8 | Microsoft 9 | © Microsoft Corporation. All rights reserved. 10 | MIT 11 | https://github.com/microsoft/tm-file-parser 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParserTest/ParserTest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System; 3 | using System.IO; 4 | using TMFileParser; 5 | using TMFileParser.Models.tm7; 6 | 7 | 8 | namespace TMFileParserTest 9 | { 10 | [TestClass] 11 | public class ParserTest 12 | { 13 | 14 | Parser parser; 15 | string tm7FilePath = @"Sample\sample1.tm7"; 16 | string jsonFilePath = @"Sample\sample1.json"; 17 | string tb7FilePath = @"Sample\MedicalDeviceTemplate.tb7"; 18 | [TestInitialize] 19 | public void Initialize() 20 | { 21 | 22 | } 23 | 24 | [TestMethod] 25 | public void Parse_TM7File() 26 | { 27 | parser = new Parser(new FileInfo(tm7FilePath)); 28 | var parserType = parser._reader.GetType(); 29 | Assert.AreEqual(parserType.Name, "TM7FileReader"); 30 | } 31 | 32 | [TestMethod] 33 | public void Parse_TB7File() 34 | { 35 | parser = new Parser(new FileInfo(tb7FilePath)); 36 | var parserType = parser._reader.GetType(); 37 | Assert.AreEqual(parserType.Name, "TB7FileReader"); 38 | } 39 | 40 | [TestMethod] 41 | public void Parse_Invalid_File_Format() 42 | { 43 | Assert.ThrowsException(() => new Parser(new FileInfo(jsonFilePath))); 44 | } 45 | 46 | [TestMethod] 47 | public void Parser_Check_Data() 48 | { 49 | parser = new Parser(new FileInfo(tm7FilePath)); 50 | var tmData = (TM7ThreatModel)parser.GetData("Raw"); 51 | Assert.AreEqual(tmData.version, "4.3"); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParserTest/Sample/BillionLaughs.tb7: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | ]> 12 | 13 | &tm9; -------------------------------------------------------------------------------- /TMFileParser/TMFileParserTest/Sample/BillionLaughs.tm7: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | ]> 12 | 13 | &tm9; -------------------------------------------------------------------------------- /TMFileParser/TMFileParserTest/Sample/sample1.json: -------------------------------------------------------------------------------- 1 | {"drawingSurfaceList":{"drawingSurfaceModel":[{"genericTypeId":"DRAWINGSURFACE","guid":"4aa07a4e-f2ef-4c38-bd93-5e15f28d08ef","typeId":"DRAWINGSURFACE","header":"Diagram 1","zoom":1,"properties":{"anyType":[{"DisplayName":"Diagram","Name":"","type":"HeaderDisplayAttribute"},{"DisplayName":"Name","Name":"","type":"StringDisplayAttribute"}]},"borders":{"keyValueOfguidanyType":[{"BordersKey":"72dd0225-194c-4817-8512-36bb028fa529","value":{"genericTypeId":"GE.DS","guid":"72dd0225-194c-4817-8512-36bb028fa529","properties":{"anyType":[{"DisplayName":"Azure Cosmos DB","Name":"","type":"HeaderDisplayAttribute"},{"DisplayName":"Name","Name":"","type":"StringDisplayAttribute"},{"DisplayName":"Out Of Scope","Name":"71f3d9aa-b8ef-4e54-8126-607a1d903103","type":"BooleanDisplayAttribute"},{"DisplayName":"Reason For Out Of Scope","Name":"752473b6-52d4-4776-9a24-202153f7d579","type":"StringDisplayAttribute"},{"DisplayName":"Configurable Attributes","Name":"","type":"HeaderDisplayAttribute"},{"DisplayName":"API Type","Name":"d456e645-5642-41ad-857f-951af1a3d968","type":"ListDisplayAttribute"},{"DisplayName":"Azure Cosmos DB Firewall Settings","Name":"b646c6da-6894-432a-8925-646ae6d1d0ea","type":"ListDisplayAttribute"},{"DisplayName":"As Generic Data Store","Name":"","type":"HeaderDisplayAttribute"}]},"typeId":"SE.P.TMCore.AzureDocumentDB","height":100,"left":568,"strokeThickness":1,"top":175,"width":100,"type":"StencilParallelLines"}},{"BordersKey":"d19592b5-fb5d-47a8-ab2f-45f6865332d5","value":{"genericTypeId":"GE.DS","guid":"d19592b5-fb5d-47a8-ab2f-45f6865332d5","properties":{"anyType":[{"DisplayName":"Azure Key Vault","Name":"","type":"HeaderDisplayAttribute"},{"DisplayName":"Name","Name":"","type":"StringDisplayAttribute"},{"DisplayName":"Out Of Scope","Name":"71f3d9aa-b8ef-4e54-8126-607a1d903103","type":"BooleanDisplayAttribute"},{"DisplayName":"Reason For Out Of Scope","Name":"752473b6-52d4-4776-9a24-202153f7d579","type":"StringDisplayAttribute"},{"DisplayName":"Configurable Attributes","Name":"","type":"HeaderDisplayAttribute"},{"DisplayName":"Azure Key Vault Firewall Settings","Name":"cd610fb8-4fbd-49c0-966f-8b4634b39262","type":"ListDisplayAttribute"},{"DisplayName":"Azure Key Vault Audit Logging Enabled","Name":"78bf9482-5267-41c6-84fd-bac2fb6ca0b9","type":"ListDisplayAttribute"},{"DisplayName":"Authenticating to Key Vault","Name":"ae94fa17-596d-476e-a283-0afc166dcf26","type":"ListDisplayAttribute"},{"DisplayName":"As Generic Data Store","Name":"","type":"HeaderDisplayAttribute"}]},"typeId":"SE.DS.TMCore.AzureKeyVault","height":100,"left":302,"strokeThickness":1,"top":100,"width":100,"type":"StencilParallelLines"}},{"BordersKey":"7c23f27d-711a-4bd1-adf2-58c156383b13","value":{"genericTypeId":"GE.TB.B","guid":"7c23f27d-711a-4bd1-adf2-58c156383b13","properties":{"anyType":[{"DisplayName":"Azure IaaS VM Trust Boundary","Name":"","type":"HeaderDisplayAttribute"},{"DisplayName":"Name","Name":"","type":"StringDisplayAttribute"},{"DisplayName":"Dataflow Order","Name":"15ccd509-98eb-49ad-b9c2-b4a2926d1780","type":"StringDisplayAttribute"},{"DisplayName":"Configurable Attributes","Name":"","type":"HeaderDisplayAttribute"},{"DisplayName":"As Generic Trust Border Boundary","Name":"","type":"HeaderDisplayAttribute"},{"DisplayName":"Trust Boundary Area","Name":"","type":"HeaderDisplayAttribute"}]},"typeId":"SE.TB.TMCore.AzureIaaSVMTrustBoundary","height":245,"left":179,"strokeThickness":0,"top":62,"width":274,"type":"BorderBoundary"}}]},"lines":{"keyValueOfguidanyType":[{"linesKey":"7b771d6c-ba83-43cb-8888-cad14a06e895","value":{"genericTypeId":"GE.DF","guid":"7b771d6c-ba83-43cb-8888-cad14a06e895","sourceGuid":"d19592b5-fb5d-47a8-ab2f-45f6865332d5","targetGuid":"72dd0225-194c-4817-8512-36bb028fa529","portSource":"South","portTarget":"South","properties":{"anyType":[{"DisplayName":"Response","Name":"","type":"HeaderDisplayAttribute"},{"DisplayName":"Name","Name":"","type":"StringDisplayAttribute"},{"DisplayName":"Dataflow Order","Name":"15ccd509-98eb-49ad-b9c2-b4a2926d1780","type":"StringDisplayAttribute"},{"DisplayName":"Out Of Scope","Name":"71f3d9aa-b8ef-4e54-8126-607a1d903103","type":"BooleanDisplayAttribute"},{"DisplayName":"Reason For Out Of Scope","Name":"752473b6-52d4-4776-9a24-202153f7d579","type":"StringDisplayAttribute"},{"DisplayName":"Configurable Attributes","Name":"","type":"HeaderDisplayAttribute"},{"DisplayName":"As Generic Data Flow","Name":"","type":"HeaderDisplayAttribute"},{"DisplayName":"Show Boundary Threats","Name":"23e2b6f4-fcd8-4e76-a04a-c9ff9aff4f59","type":"ListDisplayAttribute"}]},"typeId":"SE.DF.TMCore.Response","handleX":525,"handleY":220,"sourceX":352,"sourceY":195,"targetX":618,"targetY":270,"type":"Connector"}},{"linesKey":"4bc02f7f-8c06-448b-a9ae-a21dbc2f15b1","value":{"genericTypeId":"GE.DF","guid":"4bc02f7f-8c06-448b-a9ae-a21dbc2f15b1","sourceGuid":"d19592b5-fb5d-47a8-ab2f-45f6865332d5","targetGuid":"72dd0225-194c-4817-8512-36bb028fa529","portSource":"East","portTarget":"West","properties":{"anyType":[{"DisplayName":"Request","Name":"","type":"HeaderDisplayAttribute"},{"DisplayName":"Name","Name":"","type":"StringDisplayAttribute"},{"DisplayName":"Dataflow Order","Name":"15ccd509-98eb-49ad-b9c2-b4a2926d1780","type":"StringDisplayAttribute"},{"DisplayName":"Out Of Scope","Name":"71f3d9aa-b8ef-4e54-8126-607a1d903103","type":"BooleanDisplayAttribute"},{"DisplayName":"Reason For Out Of Scope","Name":"752473b6-52d4-4776-9a24-202153f7d579","type":"StringDisplayAttribute"},{"DisplayName":"Configurable Attributes","Name":"","type":"HeaderDisplayAttribute"},{"DisplayName":"As Generic Data Flow","Name":"","type":"HeaderDisplayAttribute"},{"DisplayName":"Show Boundary Threats","Name":"23e2b6f4-fcd8-4e76-a04a-c9ff9aff4f59","type":"ListDisplayAttribute"}]},"typeId":"SE.DF.TMCore.Request","handleX":488,"handleY":202,"sourceX":397,"sourceY":150,"targetX":573,"targetY":225,"type":"Connector"}}]}}]},"metaInformation":{"assumptions":"","contributors":"","externalDependencies":"","highLevelSystemDescription":"","owner":"","reviewer":"","threatModelName":""},"notes":"","threatInstances":{},"threatGenerationEnabled":true,"validations":{},"knowledgeBase":{"manifest":null,"threatMetaData":null,"genericElements":null,"threatCategories":null,"threatTypes":null},"profile":{},"version":"4.3"} -------------------------------------------------------------------------------- /TMFileParser/TMFileParserTest/Sample/sample2-all.json: -------------------------------------------------------------------------------- 1 | {"diagrams":[{"diagram":"Diagram 1","boundaries":[{"Name":"Azure Trust Boundary","DisplayName":"Azure Trust Boundary","Type":"BorderBoundary","Left":142,"Top":91,"Width":616,"Height":435,"Assets":[{"Name":"Azure Key Vault","DisplayName":"Azure Key Vault","Guid":"bbe8a0c9-a167-4ea5-be62-86b30ae070f2","Left":223,"Top":261,"Width":100,"Height":100},{"Name":"Azure Cosmos DB","DisplayName":"Azure Cosmos DB","Guid":"245829fe-01c6-4cc4-8913-1736b28e2fdc","Left":452,"Top":160,"Width":100,"Height":100},{"Name":"IoT Device","DisplayName":"IoT Device","Guid":"3043c1b3-4729-4e9f-81b9-68674aaa5e59","Left":526,"Top":357,"Width":100,"Height":100},{"Name":"Mobile Client","DisplayName":"Mobile Client","Guid":"19538dbd-728a-45ce-9a08-c6049d6a1757","Left":271,"Top":390,"Width":100,"Height":100},{"Name":"Azure Storage","DisplayName":"Azure Storage","Guid":"053cade6-9792-456b-b5f3-901bf035c686","Left":220,"Top":122,"Width":100,"Height":100}],"AssetsOnBoundary":[{"Name":"Azure Key Vault","DisplayName":"Azure Key Vault 555","Guid":"dd62ea18-0c96-4baf-8a3e-24b4236d39d9","Left":54,"Top":197,"Width":100,"Height":100},{"Name":"Azure Key Vault","DisplayName":"Azure Key Vault","Guid":"613bfb82-216f-4df6-9dae-9a6a9c00a700","Left":704,"Top":342,"Width":100,"Height":100},{"Name":"Azure Redis Cache","DisplayName":"Azure Redis Cache","Guid":"7af20653-a48a-46be-a6df-a6a5d1d69473","Left":195,"Top":509,"Width":100,"Height":100},{"Name":"Azure Cosmos DB","DisplayName":"Azure Cosmos DB","Guid":"4443e6e3-0ee7-4d4a-9398-458e9679c4c9","Left":565,"Top":10,"Width":100,"Height":100}],"CrossingDataflows":[],"Connectors":[{"Name":"Request","DisplayName":"Request","SourceAsset":{"Name":"Azure Key Vault","DisplayName":"Azure Key Vault","Guid":"bbe8a0c9-a167-4ea5-be62-86b30ae070f2","Left":223,"Top":261,"Width":100,"Height":100},"TargetAsset":{"Name":"Azure Cosmos DB","DisplayName":"Azure Cosmos DB","Guid":"245829fe-01c6-4cc4-8913-1736b28e2fdc","Left":452,"Top":160,"Width":100,"Height":100}},{"Name":"Request","DisplayName":"Request","SourceAsset":{"Name":"Mobile Client","DisplayName":"Mobile Client","Guid":"19538dbd-728a-45ce-9a08-c6049d6a1757","Left":271,"Top":390,"Width":100,"Height":100},"TargetAsset":{"Name":"IoT Device","DisplayName":"IoT Device","Guid":"3043c1b3-4729-4e9f-81b9-68674aaa5e59","Left":526,"Top":357,"Width":100,"Height":100}}],"ChildBoundaries":[{"Name":"Machine Trust Boundary","DisplayName":"Machine Trust Boundary","Type":"BorderBoundary","Left":475,"Top":274,"Width":200,"Height":237,"Assets":[{"Name":"IoT Device","DisplayName":"IoT Device","Guid":"3043c1b3-4729-4e9f-81b9-68674aaa5e59","Left":526,"Top":357,"Width":100,"Height":100}],"AssetsOnBoundary":[],"CrossingDataflows":[{"Name":"Request","DisplayName":"Request","SourceAsset":{"Name":"Mobile Client","DisplayName":"Mobile Client","Guid":"19538dbd-728a-45ce-9a08-c6049d6a1757","Left":271,"Top":390,"Width":100,"Height":100},"TargetAsset":{"Name":"IoT Device","DisplayName":"IoT Device","Guid":"3043c1b3-4729-4e9f-81b9-68674aaa5e59","Left":526,"Top":357,"Width":100,"Height":100}}],"Connectors":[],"ChildBoundaries":[],"CommonBoundaries":[{"Boundary":{"Name":"Azure Trust Boundary","DisplayName":"Azure Trust Boundary","Type":"BorderBoundary","Left":142,"Top":91,"Width":616,"Height":435,"Assets":[{"Name":"Azure Key Vault","DisplayName":"Azure Key Vault","Guid":"bbe8a0c9-a167-4ea5-be62-86b30ae070f2","Left":223,"Top":261,"Width":100,"Height":100},{"Name":"Azure Cosmos DB","DisplayName":"Azure Cosmos DB","Guid":"245829fe-01c6-4cc4-8913-1736b28e2fdc","Left":452,"Top":160,"Width":100,"Height":100},{"Name":"IoT Device","DisplayName":"IoT Device","Guid":"3043c1b3-4729-4e9f-81b9-68674aaa5e59","Left":526,"Top":357,"Width":100,"Height":100},{"Name":"Mobile Client","DisplayName":"Mobile Client","Guid":"19538dbd-728a-45ce-9a08-c6049d6a1757","Left":271,"Top":390,"Width":100,"Height":100},{"Name":"Azure Storage","DisplayName":"Azure Storage","Guid":"053cade6-9792-456b-b5f3-901bf035c686","Left":220,"Top":122,"Width":100,"Height":100}]},"CommonAssets":[{"Name":"IoT Device","DisplayName":"IoT Device","Guid":"3043c1b3-4729-4e9f-81b9-68674aaa5e59","Left":526,"Top":357,"Width":100,"Height":100}]}]}],"CommonBoundaries":[{"Boundary":{"Name":"Remote User Zone","DisplayName":"Remote User Zone","Type":"BorderBoundary","Left":704,"Top":34,"Width":287,"Height":202,"Assets":[]},"CommonAssets":[]},{"Boundary":{"Name":"IoT Field Gateway Zone","DisplayName":"IoT Field Gateway Zone","Type":"BorderBoundary","Left":190,"Top":10,"Width":164,"Height":237,"Assets":[{"Name":"Azure Storage","DisplayName":"Azure Storage","Guid":"053cade6-9792-456b-b5f3-901bf035c686","Left":220,"Top":122,"Width":100,"Height":100}]},"CommonAssets":[{"Name":"Azure Storage","DisplayName":"Azure Storage","Guid":"053cade6-9792-456b-b5f3-901bf035c686","Left":220,"Top":122,"Width":100,"Height":100}]}]},{"Name":"Machine Trust Boundary","DisplayName":"Machine Trust Boundary","Type":"BorderBoundary","Left":475,"Top":274,"Width":200,"Height":237,"Assets":[{"Name":"IoT Device","DisplayName":"IoT Device","Guid":"3043c1b3-4729-4e9f-81b9-68674aaa5e59","Left":526,"Top":357,"Width":100,"Height":100}],"AssetsOnBoundary":[],"CrossingDataflows":[{"Name":"Request","DisplayName":"Request","SourceAsset":{"Name":"Mobile Client","DisplayName":"Mobile Client","Guid":"19538dbd-728a-45ce-9a08-c6049d6a1757","Left":271,"Top":390,"Width":100,"Height":100},"TargetAsset":{"Name":"IoT Device","DisplayName":"IoT Device","Guid":"3043c1b3-4729-4e9f-81b9-68674aaa5e59","Left":526,"Top":357,"Width":100,"Height":100}}],"Connectors":[],"ChildBoundaries":[],"CommonBoundaries":[{"Boundary":{"Name":"Azure Trust Boundary","DisplayName":"Azure Trust Boundary","Type":"BorderBoundary","Left":142,"Top":91,"Width":616,"Height":435,"Assets":[{"Name":"Azure Key Vault","DisplayName":"Azure Key Vault","Guid":"bbe8a0c9-a167-4ea5-be62-86b30ae070f2","Left":223,"Top":261,"Width":100,"Height":100},{"Name":"Azure Cosmos DB","DisplayName":"Azure Cosmos DB","Guid":"245829fe-01c6-4cc4-8913-1736b28e2fdc","Left":452,"Top":160,"Width":100,"Height":100},{"Name":"IoT Device","DisplayName":"IoT Device","Guid":"3043c1b3-4729-4e9f-81b9-68674aaa5e59","Left":526,"Top":357,"Width":100,"Height":100},{"Name":"Mobile Client","DisplayName":"Mobile Client","Guid":"19538dbd-728a-45ce-9a08-c6049d6a1757","Left":271,"Top":390,"Width":100,"Height":100},{"Name":"Azure Storage","DisplayName":"Azure Storage","Guid":"053cade6-9792-456b-b5f3-901bf035c686","Left":220,"Top":122,"Width":100,"Height":100}]},"CommonAssets":[{"Name":"IoT Device","DisplayName":"IoT Device","Guid":"3043c1b3-4729-4e9f-81b9-68674aaa5e59","Left":526,"Top":357,"Width":100,"Height":100}]}]},{"Name":"Remote User Zone","DisplayName":"Remote User Zone","Type":"BorderBoundary","Left":704,"Top":34,"Width":287,"Height":202,"Assets":[],"AssetsOnBoundary":[],"CrossingDataflows":[],"Connectors":[],"ChildBoundaries":[],"CommonBoundaries":[{"Boundary":{"Name":"Azure Trust Boundary","DisplayName":"Azure Trust Boundary","Type":"BorderBoundary","Left":142,"Top":91,"Width":616,"Height":435,"Assets":[{"Name":"Azure Key Vault","DisplayName":"Azure Key Vault","Guid":"bbe8a0c9-a167-4ea5-be62-86b30ae070f2","Left":223,"Top":261,"Width":100,"Height":100},{"Name":"Azure Cosmos DB","DisplayName":"Azure Cosmos DB","Guid":"245829fe-01c6-4cc4-8913-1736b28e2fdc","Left":452,"Top":160,"Width":100,"Height":100},{"Name":"IoT Device","DisplayName":"IoT Device","Guid":"3043c1b3-4729-4e9f-81b9-68674aaa5e59","Left":526,"Top":357,"Width":100,"Height":100},{"Name":"Mobile Client","DisplayName":"Mobile Client","Guid":"19538dbd-728a-45ce-9a08-c6049d6a1757","Left":271,"Top":390,"Width":100,"Height":100},{"Name":"Azure Storage","DisplayName":"Azure Storage","Guid":"053cade6-9792-456b-b5f3-901bf035c686","Left":220,"Top":122,"Width":100,"Height":100}]},"CommonAssets":[]}]},{"Name":"IoT Field Gateway Zone","DisplayName":"IoT Field Gateway Zone","Type":"BorderBoundary","Left":190,"Top":10,"Width":164,"Height":237,"Assets":[{"Name":"Azure Storage","DisplayName":"Azure Storage","Guid":"053cade6-9792-456b-b5f3-901bf035c686","Left":220,"Top":122,"Width":100,"Height":100}],"AssetsOnBoundary":[],"CrossingDataflows":[],"Connectors":[],"ChildBoundaries":[],"CommonBoundaries":[{"Boundary":{"Name":"Azure Trust Boundary","DisplayName":"Azure Trust Boundary","Type":"BorderBoundary","Left":142,"Top":91,"Width":616,"Height":435,"Assets":[{"Name":"Azure Key Vault","DisplayName":"Azure Key Vault","Guid":"bbe8a0c9-a167-4ea5-be62-86b30ae070f2","Left":223,"Top":261,"Width":100,"Height":100},{"Name":"Azure Cosmos DB","DisplayName":"Azure Cosmos DB","Guid":"245829fe-01c6-4cc4-8913-1736b28e2fdc","Left":452,"Top":160,"Width":100,"Height":100},{"Name":"IoT Device","DisplayName":"IoT Device","Guid":"3043c1b3-4729-4e9f-81b9-68674aaa5e59","Left":526,"Top":357,"Width":100,"Height":100},{"Name":"Mobile Client","DisplayName":"Mobile Client","Guid":"19538dbd-728a-45ce-9a08-c6049d6a1757","Left":271,"Top":390,"Width":100,"Height":100},{"Name":"Azure Storage","DisplayName":"Azure Storage","Guid":"053cade6-9792-456b-b5f3-901bf035c686","Left":220,"Top":122,"Width":100,"Height":100}]},"CommonAssets":[{"Name":"Azure Storage","DisplayName":"Azure Storage","Guid":"053cade6-9792-456b-b5f3-901bf035c686","Left":220,"Top":122,"Width":100,"Height":100}]}]},{"Name":"Generic Trust Line Boundary","DisplayName":"Generic Trust Line Boundary","Type":"LineBoundary","Left":0,"Top":0,"Width":0,"Height":0,"Assets":null,"AssetsOnBoundary":null,"CrossingDataflows":null,"Connectors":null,"ChildBoundaries":null,"CommonBoundaries":null}],"connectors":[{"Name":"Request","DisplayName":"Request","SourceAsset":{"Name":"Azure Key Vault","DisplayName":"Azure Key Vault","Guid":"bbe8a0c9-a167-4ea5-be62-86b30ae070f2","Left":223,"Top":261,"Width":100,"Height":100},"TargetAsset":{"Name":"Azure Cosmos DB","DisplayName":"Azure Cosmos DB","Guid":"245829fe-01c6-4cc4-8913-1736b28e2fdc","Left":452,"Top":160,"Width":100,"Height":100}},{"Name":"Request","DisplayName":"Request","SourceAsset":{"Name":"Mobile Client","DisplayName":"Mobile Client","Guid":"19538dbd-728a-45ce-9a08-c6049d6a1757","Left":271,"Top":390,"Width":100,"Height":100},"TargetAsset":{"Name":"IoT Device","DisplayName":"IoT Device","Guid":"3043c1b3-4729-4e9f-81b9-68674aaa5e59","Left":526,"Top":357,"Width":100,"Height":100}}],"assets":[{"Name":"Azure Key Vault","DisplayName":"Azure Key Vault","Guid":"bbe8a0c9-a167-4ea5-be62-86b30ae070f2","Left":223,"Top":261,"Width":100,"Height":100},{"Name":"Azure Cosmos DB","DisplayName":"Azure Cosmos DB","Guid":"245829fe-01c6-4cc4-8913-1736b28e2fdc","Left":452,"Top":160,"Width":100,"Height":100},{"Name":"Azure Cosmos DB","DisplayName":"Azure Cosmos DB","Guid":"91a2239c-4124-41fa-8dde-635b9a14f74e","Left":1498,"Top":871,"Width":100,"Height":100},{"Name":"IoT Device","DisplayName":"IoT Device","Guid":"3043c1b3-4729-4e9f-81b9-68674aaa5e59","Left":526,"Top":357,"Width":100,"Height":100},{"Name":"Mobile Client","DisplayName":"Mobile Client","Guid":"19538dbd-728a-45ce-9a08-c6049d6a1757","Left":271,"Top":390,"Width":100,"Height":100},{"Name":"Azure Key Vault","DisplayName":"Azure Key Vault 555","Guid":"dd62ea18-0c96-4baf-8a3e-24b4236d39d9","Left":54,"Top":197,"Width":100,"Height":100},{"Name":"Azure Key Vault","DisplayName":"Azure Key Vault","Guid":"613bfb82-216f-4df6-9dae-9a6a9c00a700","Left":704,"Top":342,"Width":100,"Height":100},{"Name":"Azure Storage","DisplayName":"Azure Storage","Guid":"053cade6-9792-456b-b5f3-901bf035c686","Left":220,"Top":122,"Width":100,"Height":100},{"Name":"Azure Redis Cache","DisplayName":"Azure Redis Cache","Guid":"7af20653-a48a-46be-a6df-a6a5d1d69473","Left":195,"Top":509,"Width":100,"Height":100},{"Name":"Azure Cosmos DB","DisplayName":"Azure Cosmos DB","Guid":"4443e6e3-0ee7-4d4a-9398-458e9679c4c9","Left":565,"Top":10,"Width":100,"Height":100},{"Name":"Azure Redis Cache","DisplayName":"Azure Redis Cache","Guid":"fc8b4a2f-88b0-4efc-8242-092c32f0070b","Left":906,"Top":259,"Width":100,"Height":100},{"Name":"Azure Key Vault","DisplayName":"Azure Key Vault","Guid":"6d61b8ef-3baa-4074-ae27-b1cda92d75fd","Left":23,"Top":376,"Width":100,"Height":100},{"Name":"Azure Storage","DisplayName":"Azure Storage","Guid":"3f0c551a-71e9-4997-8bef-44f2c864cb34","Left":521,"Top":554,"Width":100,"Height":100}]}],"threats":[{"id":"4","diagram":"Diagram 1","changedBy":"","lastModified":"0001-01-01T00:00:00","title":"A compromised access key may permit an adversary to have more access than intended to an Azure Cosmos DB instance ","category":"Elevation of Privileges","description":"A compromised access key may permit an adversary to have over-privileged access to an Azure Cosmos DB instance ","justifications":null,"interaction":"Request","priority":"High"},{"id":"1","diagram":"Diagram 1","changedBy":"","lastModified":"0001-01-01T00:00:00","title":"An adversary can gain unauthorized access to Azure Cosmos DB instances due to weak network security configuration","category":"Elevation of Privileges","description":"An adversary can gain unauthorized access to Azure Cosmos DB instances due to weak network security configuration","justifications":null,"interaction":"Request","priority":"High"},{"id":"2","diagram":"Diagram 1","changedBy":"","lastModified":"0001-01-01T00:00:00","title":"An adversary having access to Azure Cosmos DB may read sensitive clear-text data","category":"Information Disclosure","description":"An adversary having access to Azure Cosmos DB may read sensitive clear-text data","justifications":null,"interaction":"Request","priority":"High"},{"id":"3","diagram":"Diagram 1","changedBy":"","lastModified":"0001-01-01T00:00:00","title":"An adversary may reuse a stolen long-lived resource token, access key or connection string to access an Azure Cosmos DB instance","category":"Elevation of Privileges","description":"An adversary may reuse a stolen long-lived resource token, access key or connection string to access an Azure Cosmos DB instance","justifications":null,"interaction":"Request","priority":"High"},{"id":"5","diagram":"Diagram 1","changedBy":"","lastModified":"0001-01-01T00:00:00","title":"An adversary may jail break into a mobile device and gain elevated privileges","category":"Elevation of Privileges","description":"An adversary may jail break into a mobile device and gain elevated privileges","justifications":null,"interaction":"Request","priority":"High"},{"id":"6","diagram":"Diagram 1","changedBy":"","lastModified":"0001-01-01T00:00:00","title":"An adversary may gain unauthorized access to data on host machines","category":"Elevation of Privileges","description":"An adversary may gain unauthorized access to data on host machines","justifications":null,"interaction":"Request","priority":"High"},{"id":"7","diagram":"Diagram 1","changedBy":"","lastModified":"0001-01-01T00:00:00","title":"An adversary may gain elevated privileges and execute malicious code on host machines","category":"Elevation of Privileges","description":"If an application runs under a high-privileged account, it may provide an opportunity for an adversary to gain elevated privileges and execute malicious code on host machines. E.g., If the developed executable runs under the logged-in user\u0027s identity and the user has admin rights on the machine, the executable will be running with administrator privileges. Any unnoticed vulnerability in the application could be used by adversaries to execute malicious code on the host machines that run the application.","justifications":null,"interaction":"Request","priority":"High"},{"id":"8","diagram":"Diagram 1","changedBy":"","lastModified":"0001-01-01T00:00:00","title":"An adversary may gain access to sensitive data stored on host machines","category":"Information Disclosure","description":"An adversary may gain access to sensitive data stored on host machines","justifications":null,"interaction":"Request","priority":"High"},{"id":"9","diagram":"Diagram 1","changedBy":"","lastModified":"0001-01-01T00:00:00","title":"An adversary can gain access to sensitive data by sniffing traffic from Mobile client","category":"Information Disclosure","description":"An adversary can gain access to sensitive data by sniffing traffic from Mobile client","justifications":null,"interaction":"Request","priority":"High"},{"id":"10","diagram":"Diagram 1","changedBy":"","lastModified":"0001-01-01T00:00:00","title":"An adversary can gain sensitive data from mobile device","category":"Information Disclosure","description":"If application saves sensitive PII or HBI data on phone SD card or local storage, then it ay get stolen.","justifications":null,"interaction":"Request","priority":"High"},{"id":"11","diagram":"Diagram 1","changedBy":"","lastModified":"0001-01-01T00:00:00","title":"An adversary may spread malware, steal or tamper data due to lack of endpoint protection on devices","category":"Tampering","description":"An adversary may spread malware, steal or tamper data due to lack of endpoint protection on devices. Scenarios such as stealing a user\u0027s laptop and extracting data from hard disk, luring users to install malware, exploit unpatched OS etc. ","justifications":null,"interaction":"Request","priority":"High"},{"id":"12","diagram":"Diagram 1","changedBy":"","lastModified":"0001-01-01T00:00:00","title":"An adversary may reverse engineer deployed binaries","category":"Tampering","description":"An adversary may reverse engineer deployed binaries","justifications":null,"interaction":"Request","priority":"High"},{"id":"13","diagram":"Diagram 1","changedBy":"","lastModified":"0001-01-01T00:00:00","title":"An adversary may tamper deployed binaries","category":"Tampering","description":"An adversary may tamper deployed binaries","justifications":null,"interaction":"Request","priority":"High"},{"id":"14","diagram":"Diagram 1","changedBy":"","lastModified":"0001-01-01T00:00:00","title":"An adversary may execute unknown code on IoT Device","category":"Tampering","description":"An adversary may launch malicious code into IoT Device and execute it","justifications":null,"interaction":"Request","priority":"High"},{"id":"15","diagram":"Diagram 1","changedBy":"","lastModified":"0001-01-01T00:00:00","title":"An adversary can reverse engineer and tamper binaries","category":"Tampering","description":"An adversary can use various tools, reverse engineer binaries and abuse them by tampering","justifications":null,"interaction":"Request","priority":"High"}]} -------------------------------------------------------------------------------- /TMFileParser/TMFileParserTest/TB7FileReaderTest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System; 3 | using System.IO; 4 | using TMFileParser; 5 | using TMFileParser.Models.tb7; 6 | 7 | namespace TMFileParserTest 8 | { 9 | [TestClass] 10 | public class TB7FileReaderTest 11 | { 12 | string tb7FilePath = @"Sample\MedicalDeviceTemplate.tb7"; 13 | string billionLaughsPath = @"Sample\BillionLaughs.tb7"; 14 | private TB7FileReader reader; 15 | [TestInitialize] 16 | public void Initialize() 17 | { 18 | reader = new TB7FileReader(new FileInfo(tb7FilePath)); 19 | } 20 | 21 | [TestMethod] 22 | public void Get_All_Test() 23 | { 24 | var kbData = (TB7KnowledgeBase)reader.GetData("all"); 25 | } 26 | 27 | [TestMethod] 28 | public void Get_Invalid_Category_Test() 29 | { 30 | Assert.ThrowsException(() => reader.GetData("invalid")); 31 | } 32 | 33 | [TestMethod] 34 | public void Billion_Laughs_Test() 35 | { 36 | Assert.ThrowsException(() => new TB7FileReader(new FileInfo(billionLaughsPath))); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParserTest/TM7FileReaderTest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System; 3 | using System.IO; 4 | using System.Linq; 5 | using TMFileParser; 6 | using TMFileParser.Models.tm7; 7 | using System.Collections.Generic; 8 | using TMFileParser.Models.output; 9 | using Microsoft.VisualStudio.TestPlatform.ObjectModel; 10 | using System.Reflection.PortableExecutable; 11 | 12 | namespace TMFileParserTest 13 | { 14 | [TestClass] 15 | public class TM7FileReaderTest 16 | { 17 | private TM7FileReader reader; 18 | string tm7FilePath = @"Sample\sample1.tm7"; 19 | string tm7BoundariesFilePath = @"Sample\sample2.tm7"; 20 | string tm7EmptyFilePath = @"Sample\EmptyDiagram.tm7"; 21 | string tm7NoDiagramFilePath = @"Sample\NoDiagram.tm7"; 22 | string billionLaughsPath = @"Sample\BillionLaughs.tm7"; 23 | string tm7ThreatsEnabledNullPath = @"Sample\ThreatsEnabledNull.tm7"; 24 | 25 | [TestInitialize] 26 | public void Initialize() { } 27 | 28 | [TestMethod] 29 | public void ReadTMFile_Test() 30 | { 31 | reader = new TM7FileReader(new FileInfo(tm7FilePath)); 32 | var tmData = (TM7All)reader.GetData("all"); 33 | Assert.AreEqual(tmData.diagrams.FirstOrDefault().assets.FirstOrDefault().DisplayName, "Azure Cosmos DB"); 34 | } 35 | 36 | [TestMethod] 37 | public void ReadEmptyTMFile_Test() 38 | { 39 | reader = new TM7FileReader(new FileInfo(tm7EmptyFilePath)); 40 | var tmData = (TM7All)reader.GetData("all"); 41 | Assert.AreEqual(tmData.diagrams.FirstOrDefault().assets.Count(), 0); 42 | Assert.AreEqual(tmData.diagrams.FirstOrDefault().boundaries.Count(), 0); 43 | Assert.AreEqual(tmData.diagrams.FirstOrDefault().connectors.Count(), 0); 44 | Assert.AreEqual(tmData.threats.Count(), 0); 45 | } 46 | 47 | [TestMethod] 48 | public void ReadNoDiagramTMFile_Test() 49 | { 50 | reader = new TM7FileReader(new FileInfo(tm7NoDiagramFilePath)); 51 | var tmData = (TM7All)reader.GetData("all"); 52 | Assert.AreEqual(tmData.diagrams, null); 53 | Assert.AreEqual(tmData.threats.Count(), 0); 54 | } 55 | 56 | [TestMethod] 57 | public void Get_Raw_Test() 58 | { 59 | reader = new TM7FileReader(new FileInfo(tm7FilePath)); 60 | var tmData = (TM7ThreatModel)reader.GetData("raw"); 61 | Assert.AreEqual(tmData.version, "4.3"); 62 | } 63 | 64 | [TestMethod] 65 | public void NullThreatsGenerationEnabled_Test() 66 | { 67 | reader = new TM7FileReader(new FileInfo(tm7ThreatsEnabledNullPath)); 68 | var tmData = (TM7ThreatModel)reader.GetData("raw"); 69 | Assert.AreEqual(tmData.version, "4.3"); 70 | Assert.AreEqual(tmData.threatGenerationEnabled, true); 71 | } 72 | 73 | [TestMethod] 74 | public void Get_Threats_Test() 75 | { 76 | reader = new TM7FileReader(new FileInfo(tm7FilePath)); 77 | var tmData = (IEnumerable)reader.GetData("threats"); 78 | var diagramName = tmData.FirstOrDefault().GetType().GetProperty("diagram").GetValue(tmData.FirstOrDefault()); 79 | Assert.AreEqual(diagramName, "Diagram 1"); 80 | } 81 | 82 | [TestMethod] 83 | public void Get_Boundaries_Test() 84 | { 85 | reader = new TM7FileReader(new FileInfo(tm7FilePath)); 86 | var tmData = (IEnumerable)reader.GetData("boundaries"); 87 | var diagramName = tmData.FirstOrDefault().GetType().GetProperty("diagram").GetValue(tmData.FirstOrDefault()); 88 | Assert.AreEqual(diagramName, "Diagram 1"); 89 | } 90 | 91 | [TestMethod] 92 | public void Get_Assets_Test() 93 | { 94 | reader = new TM7FileReader(new FileInfo(tm7FilePath)); 95 | var tmData = (IEnumerable)reader.GetData("assets"); 96 | var diagramName = tmData.FirstOrDefault().GetType().GetProperty("diagram").GetValue(tmData.FirstOrDefault()); 97 | Assert.AreEqual(diagramName, "Diagram 1"); 98 | } 99 | 100 | [TestMethod] 101 | public void Get_Connectors_Test() 102 | { 103 | reader = new TM7FileReader(new FileInfo(tm7FilePath)); 104 | var tmData = (IEnumerable)reader.GetData("connectors"); 105 | var diagramName = tmData.FirstOrDefault().GetType().GetProperty("diagram").GetValue(tmData.FirstOrDefault()); 106 | Assert.AreEqual(diagramName, "Diagram 1"); 107 | } 108 | 109 | [TestMethod] 110 | public void Get_Invalid_Category_Test() 111 | { 112 | reader = new TM7FileReader(new FileInfo(tm7FilePath)); 113 | Assert.ThrowsException(() => reader.GetData("invalid")); 114 | } 115 | 116 | [TestMethod] 117 | public void Billion_Laughs_Test() 118 | { 119 | Assert.ThrowsException (() => new TM7FileReader(new FileInfo(billionLaughsPath))); 120 | } 121 | 122 | [TestMethod] 123 | public void Get_Child_Boundaries_Test() 124 | { 125 | reader = new TM7FileReader(new FileInfo(tm7BoundariesFilePath)); 126 | var tmData = reader.GetData("all") as TM7All; 127 | var childBoundary = tmData.diagrams.FirstOrDefault().boundaries.FirstOrDefault().ChildBoundaries; 128 | Assert.AreEqual(childBoundary.Count, 1); 129 | Assert.AreEqual(childBoundary.FirstOrDefault().Name, "Machine Trust Boundary"); 130 | Assert.AreEqual(childBoundary.FirstOrDefault().Assets.FirstOrDefault().Name, "IoT Device"); 131 | } 132 | 133 | public void Get_Common_Boundaries_Test() 134 | { 135 | reader = new TM7FileReader(new FileInfo(tm7BoundariesFilePath)); 136 | var tmData = reader.GetData("all") as TM7All; 137 | var commonAsset = tmData.diagrams.FirstOrDefault().boundaries.FirstOrDefault().CommonBoundaries.ElementAt(1).CommonAssets.FirstOrDefault(); 138 | Assert.AreEqual(commonAsset.Name, "Azure Storage"); 139 | Assert.AreEqual(commonAsset.Guid, "053cade6-9792-456b-b5f3-901bf035c686"); 140 | } 141 | 142 | public void Get_Connector_Source_And_Target_Test() 143 | { 144 | reader = new TM7FileReader(new FileInfo(tm7BoundariesFilePath)); 145 | var tmData = reader.GetData("all") as TM7All; 146 | var sourceAsset = tmData.diagrams.FirstOrDefault().connectors.FirstOrDefault().SourceAsset; 147 | var targetAsset = tmData.diagrams.FirstOrDefault().connectors.FirstOrDefault().TargetAsset; 148 | Assert.AreEqual(sourceAsset.Name, "Azure Key Vault"); 149 | Assert.AreEqual(targetAsset.Name, "Azure Cosmos DB"); 150 | } 151 | 152 | public void Get_Crossing_Dataflow_Test() 153 | { 154 | reader = new TM7FileReader(new FileInfo(tm7BoundariesFilePath)); 155 | var tmData = reader.GetData("all") as TM7All; 156 | var connector = tmData.diagrams.FirstOrDefault().boundaries.ElementAt(1).CrossingDataflows.FirstOrDefault(); 157 | Assert.AreEqual(connector.Name, "Request"); 158 | } 159 | 160 | public void Get_Assets_On_Boundaries_Test() 161 | { 162 | reader = new TM7FileReader(new FileInfo(tm7BoundariesFilePath)); 163 | var tmData = reader.GetData("all") as TM7All; 164 | var asset = tmData.diagrams.FirstOrDefault().boundaries.FirstOrDefault().AssetsOnBoundary.FirstOrDefault(); 165 | Assert.AreEqual(asset.Name, "Azure Key Vault"); 166 | } 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /TMFileParser/TMFileParserTest/TMFileParserTest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0 5 | false 6 | MIT 7 | https://github.com/microsoft/tm-file-parser 8 | Microsoft 9 | Microsoft.ThreatModeling.TMFileParserTest 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | Always 25 | 26 | 27 | Always 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /pipelines/build-pipeline.yml: -------------------------------------------------------------------------------- 1 | parameters: 2 | - name: nugetVersionParameter 3 | displayName: NuGet Version 4 | type: string 5 | default: 1.0.0-dev 6 | - name: publishCLIForWindows_x64 7 | displayName: Publish for Windows-x64 8 | type: boolean 9 | default: true 10 | - name: publishCLIForLinux_x64 11 | displayName: Publish for Linux-x64 12 | type: boolean 13 | default: true 14 | - name: publishCLIForMacOS_arm64 15 | displayName: Publish for MacOS-arm64 16 | type: boolean 17 | default: true 18 | - name: packNuGet 19 | displayName: Pack NuGet 20 | type: boolean 21 | default: true 22 | 23 | trigger: 24 | - main 25 | 26 | schedules: 27 | - cron: '0 0 * * *' 28 | displayName: Daily build 29 | branches: 30 | include: 31 | - main 32 | 33 | pr: 34 | branches: 35 | include: 36 | - main 37 | 38 | pool: 39 | vmImage: windows-2019 40 | 41 | variables: 42 | nugetVersion: ${{ parameters.nugetVersionParameter }} 43 | Codeql.Enabled: true 44 | 45 | steps: 46 | 47 | - task: CodeQL3000Init@0 48 | 49 | - task: UseDotNet@2 50 | inputs: 51 | packageType: 'sdk' 52 | version: '7.x' 53 | 54 | - task: DotNetCoreCLI@2 55 | displayName: 'DotNetBuild' 56 | inputs: 57 | command: 'build' 58 | projects: '**/*.csproj' 59 | 60 | - task: DotNetCoreCLI@2 61 | displayName: 'DotNetTest' 62 | inputs: 63 | command: 'test' 64 | projects: '**/*.csproj' 65 | 66 | - task: CredScan@3 67 | inputs: 68 | verboseOutput: true 69 | 70 | - task: RoslynAnalyzers@3 71 | inputs: 72 | userProvideBuildInfo: 'msBuildInfo' 73 | msBuildVersion: '16.0' 74 | msBuildArchitecture: 'amd64' 75 | msBuildCommandline: 'dotnet.exe build $(Build.SourcesDirectory)\TMFileParser\TMFileParser.sln' 76 | 77 | - task: BinSkim@4 78 | inputs: 79 | InputType: 'CommandLine' 80 | arguments: 'analyze $(Build.SourcesDirectory)\* --recurse --sympath "Srv*http://msdl.microsoft.com/download/symbols" --verbose' 81 | 82 | - task: SdtReport@2 83 | inputs: 84 | GdnExportHtmlFile: true 85 | GdnExportAllTools: false 86 | GdnExportGdnToolBinSkim: true 87 | GdnExportGdnToolSemmle: true 88 | 89 | - task: PublishSecurityAnalysisLogs@3 90 | inputs: 91 | ArtifactName: 'CodeAnalysisLogs' 92 | ArtifactType: 'Container' 93 | AllTools: false 94 | AntiMalware: false 95 | APIScan: false 96 | Armory: false 97 | Bandit: false 98 | BinSkim: true 99 | CodesignValidation: false 100 | CredScan: true 101 | CSRF: false 102 | ESLint: false 103 | Flawfinder: false 104 | FortifySCA: false 105 | FxCop: false 106 | ModernCop: false 107 | MSRD: false 108 | PoliCheck: false 109 | RoslynAnalyzers: true 110 | SDLNativeRules: false 111 | Semmle: true 112 | SpotBugs: false 113 | TSLint: false 114 | WebScout: false 115 | ToolLogsNotFoundAction: 'Standard' 116 | 117 | - task: UseDotNet@2 118 | inputs: 119 | packageType: 'sdk' 120 | version: '2.x' 121 | 122 | - task: EsrpCodeSigning@1 123 | inputs: 124 | ConnectedServiceName: 'ESRP Signing' 125 | FolderPath: '$(Build.SourcesDirectory)' 126 | Pattern: 'TMFileParser.dll' 127 | signConfigType: 'inlineSignParams' 128 | inlineOperation: | 129 | [ 130 | { 131 | "KeyCode" : "CP-230012", 132 | "OperationCode" : "SigntoolSign", 133 | "Parameters" : { 134 | "OpusName" : "Microsoft", 135 | "OpusInfo" : "http://www.microsoft.com", 136 | "FileDigest" : "/fd \"SHA256\"", 137 | "PageHash" : "/NPH", 138 | "TimeStamp" : "/tr \"http://rfc3161.gtm.corp.microsoft.com/TSS/HttpTspServer\" /td sha256" 139 | }, 140 | "ToolName" : "sign", 141 | "ToolVersion" : "1.0" 142 | }, 143 | { 144 | "KeyCode" : "CP-230012", 145 | "OperationCode" : "SigntoolVerify", 146 | "Parameters" : {}, 147 | "ToolName" : "sign", 148 | "ToolVersion" : "1.0" 149 | } 150 | ] 151 | SessionTimeout: '60' 152 | MaxConcurrency: '50' 153 | MaxRetryAttempts: '5' 154 | 155 | - task: UseDotNet@2 156 | inputs: 157 | packageType: 'sdk' 158 | version: '7.x' 159 | 160 | - ${{ if eq(parameters.packNuGet, true) }}: 161 | - task: DotNetCoreCLI@2 162 | inputs: 163 | command: 'pack' 164 | packagesToPack: 'TMFileParser/TMFileParser/TMFileParser.csproj' 165 | nobuild: true 166 | versioningScheme: 'byEnvVar' 167 | versionEnvVar: 'nugetVersion' 168 | 169 | - ${{ if eq(parameters.publishCLIForLinux_x64, true) }}: 170 | - task: DotNetCoreCLI@2 171 | displayName: 'DotNetPublishLinux' 172 | inputs: 173 | command: 'publish' 174 | publishWebProjects: false 175 | projects: 'TMFileParser/TMFileConverter/TMFileConverter.csproj' 176 | arguments: '-r linux-x64 --self-contained true -p:PublishSingleFile=True -o $(Build.ArtifactStagingDirectory)/linux' 177 | zipAfterPublish: false 178 | 179 | - ${{ if eq(parameters.publishCLIForMacOS_arm64, true) }}: 180 | - task: DotNetCoreCLI@2 181 | displayName: 'DotNetPublishMacOS' 182 | inputs: 183 | command: 'publish' 184 | publishWebProjects: false 185 | projects: 'TMFileParser/TMFileConverter/TMFileConverter.csproj' 186 | arguments: '-r osx.11.0-x64 --self-contained true -p:PublishSingleFile=True -o $(Build.ArtifactStagingDirectory)/macOS' 187 | zipAfterPublish: false 188 | 189 | - ${{ if eq(parameters.publishCLIForWindows_x64, true) }}: 190 | - task: DotNetCoreCLI@2 191 | displayName: 'DotNetPublishWindows' 192 | inputs: 193 | command: 'publish' 194 | publishWebProjects: false 195 | projects: 'TMFileParser/TMFileConverter/TMFileConverter.csproj' 196 | arguments: '-r win-x64 --self-contained true -p:PublishSingleFile=True -o $(Build.ArtifactStagingDirectory)/windows' 197 | zipAfterPublish: false 198 | 199 | - task: UseDotNet@2 200 | inputs: 201 | packageType: 'sdk' 202 | version: '3.x' 203 | 204 | - task: EsrpCodeSigning@1 205 | inputs: 206 | ConnectedServiceName: 'ESRP Signing' 207 | FolderPath: '$(Build.ArtifactStagingDirectory)' 208 | Pattern: 'TMFileParser.dll,TMFileConverter.exe' 209 | signConfigType: 'inlineSignParams' 210 | inlineOperation: | 211 | [ 212 | { 213 | "KeyCode" : "CP-230012", 214 | "OperationCode" : "SigntoolSign", 215 | "Parameters" : { 216 | "OpusName" : "Microsoft", 217 | "OpusInfo" : "http://www.microsoft.com", 218 | "FileDigest" : "/fd \"SHA256\"", 219 | "PageHash" : "/NPH", 220 | "TimeStamp" : "/tr \"http://rfc3161.gtm.corp.microsoft.com/TSS/HttpTspServer\" /td sha256" 221 | }, 222 | "ToolName" : "sign", 223 | "ToolVersion" : "1.0" 224 | }, 225 | { 226 | "KeyCode" : "CP-230012", 227 | "OperationCode" : "SigntoolVerify", 228 | "Parameters" : {}, 229 | "ToolName" : "sign", 230 | "ToolVersion" : "1.0" 231 | } 232 | ] 233 | SessionTimeout: '60' 234 | MaxConcurrency: '50' 235 | MaxRetryAttempts: '5' 236 | 237 | - task: EsrpCodeSigning@1 238 | inputs: 239 | ConnectedServiceName: 'ESRP Signing' 240 | FolderPath: '$(Build.ArtifactStagingDirectory)' 241 | Pattern: 'Microsoft.ThreatModeling.TMFileParser*.nupkg' 242 | signConfigType: 'inlineSignParams' 243 | inlineOperation: | 244 | [ 245 | { 246 | "KeyCode" : "CP-401405", 247 | "OperationCode" : "NuGetSign", 248 | "Parameters" : {}, 249 | "ToolName" : "sign", 250 | "ToolVersion" : "1.0" 251 | }, 252 | { 253 | "KeyCode" : "CP-401405", 254 | "OperationCode" : "NuGetVerify", 255 | "Parameters" : {}, 256 | "ToolName" : "sign", 257 | "ToolVersion" : "1.0" 258 | } 259 | ] 260 | SessionTimeout: '60' 261 | MaxConcurrency: '50' 262 | MaxRetryAttempts: '5' 263 | 264 | - ${{ if eq(parameters.publishCLIForLinux_x64, true) }}: 265 | - task: CopyFiles@2 266 | inputs: 267 | SourceFolder: '$(Build.ArtifactStagingDirectory)/linux/TMFileConverter' 268 | Contents: 'TMFileConverter' 269 | TargetFolder: '$(Build.ArtifactStagingDirectory)/release/TMFileConverter-linux' 270 | - task: ArchiveFiles@2 271 | inputs: 272 | rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/release/TMFileConverter-linux' 273 | includeRootFolder: true 274 | archiveType: 'zip' 275 | archiveFile: '$(Build.ArtifactStagingDirectory)/release/TMFileConverter-linux.zip' 276 | replaceExistingArchive: true 277 | 278 | - ${{ if eq(parameters.publishCLIForMacOS_arm64, true) }}: 279 | - task: CopyFiles@2 280 | inputs: 281 | SourceFolder: '$(Build.ArtifactStagingDirectory)/macOS/TMFileConverter' 282 | Contents: 'TMFileConverter' 283 | TargetFolder: '$(Build.ArtifactStagingDirectory)/release/TMFileConverter-macOS' 284 | - task: ArchiveFiles@2 285 | inputs: 286 | rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/release/TMFileConverter-macOS' 287 | includeRootFolder: true 288 | archiveType: 'zip' 289 | archiveFile: '$(Build.ArtifactStagingDirectory)/release/TMFileConverter-macOS.zip' 290 | replaceExistingArchive: true 291 | 292 | - ${{ if eq(parameters.publishCLIForWindows_x64, true) }}: 293 | - task: CopyFiles@2 294 | inputs: 295 | SourceFolder: '$(Build.ArtifactStagingDirectory)/windows/TMFileConverter' 296 | Contents: | 297 | *.dll 298 | TMFileConverter.exe 299 | TargetFolder: '$(Build.ArtifactStagingDirectory)/release/TMFileConverter-windows' 300 | - task: ArchiveFiles@2 301 | inputs: 302 | rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/release/TMFileConverter-windows' 303 | includeRootFolder: true 304 | archiveType: 'zip' 305 | archiveFile: '$(Build.ArtifactStagingDirectory)/release/TMFileConverter-windows.zip' 306 | replaceExistingArchive: true 307 | 308 | - task: PublishBuildArtifacts@1 309 | inputs: 310 | PathtoPublish: '$(Build.ArtifactStagingDirectory)' 311 | ArtifactName: 'drop' 312 | publishLocation: 'Container' 313 | 314 | - task: CodeQL3000Finalize@0 315 | 316 | --------------------------------------------------------------------------------