-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SP-706 Adds local cryptography to SDK HTML report
- Loading branch information
1 parent
0ebdbec
commit c6452cb
Showing
7 changed files
with
192 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/sdk/Report/DataLayer/DataProviders/CryptographyDataProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { | ||
ComponentCryptography, | ||
DataProvider, | ||
IDataLayers | ||
} from '../DataLayerTypes'; | ||
import { | ||
ScannerComponent, | ||
ScannerResults | ||
} from '../../../scanner/ScannerTypes'; | ||
import { IDependencyResponse } from '../../../Dependencies/DependencyTypes'; | ||
import { | ||
CryptoAlgorithm, | ||
ICryptoItem | ||
} from '../../../Cryptography/CryptographyTypes'; | ||
|
||
export class CryptographyDataProvider implements DataProvider { | ||
private files: Array<ICryptoItem>; | ||
private scanRawResults: ScannerResults; | ||
private componentList: Array<ScannerComponent>; | ||
constructor(files: Array<ICryptoItem>, scanRawResults: ScannerResults,) { | ||
this.files = files; | ||
this.scanRawResults = scanRawResults; | ||
} | ||
async getData():Promise<IDataLayers> { | ||
|
||
if(!this.files && !this.scanRawResults) return <IDataLayers>{ cryptography: null } | ||
|
||
this.componentList = Object.values(this.scanRawResults).flat(); | ||
this.componentList = this.componentList.filter( | ||
(component) => component.id !== 'none' | ||
); | ||
|
||
const componentCryptography = this.getCrypto(this.componentList); | ||
|
||
return <IDataLayers>{ | ||
cryptography:{ | ||
files: this.files, | ||
components: componentCryptography, | ||
} | ||
} | ||
} | ||
|
||
private getCrypto(scanComponents: Array<ScannerComponent>):Array<ComponentCryptography> { | ||
const componentCrypto = []; | ||
scanComponents.forEach((c)=>{ | ||
if(c.cryptography.length > 0){ | ||
const crypto = { | ||
purl: c.purl, | ||
version: c.version, | ||
algorithms: c.cryptography | ||
} | ||
componentCrypto.push(crypto); | ||
} | ||
}); | ||
return this.normalizeAlgorithms(componentCrypto) | ||
} | ||
|
||
private normalizeAlgorithms(crypto: Array<ComponentCryptography>):Array<ComponentCryptography> { | ||
crypto.forEach((c)=>{ | ||
c.algorithms = this.removeRepeatedAlgorithms(c.algorithms); | ||
}) | ||
|
||
return crypto; | ||
|
||
} | ||
|
||
private removeRepeatedAlgorithms(algorithms: Array<CryptoAlgorithm>):Array<CryptoAlgorithm> { | ||
const algorithmsMapper = new Map<string, { algorithm: string, strength: string }>(); | ||
algorithms.forEach((a) => { | ||
const algorithmToLowerCase = a.algorithm.toLowerCase(); | ||
algorithmsMapper.set(algorithmToLowerCase, {...a, algorithm: algorithmToLowerCase}) | ||
}); | ||
return Array.from(algorithmsMapper.values()); | ||
} | ||
|
||
getLayerName(): string { | ||
return ''; | ||
} | ||
} |