Repository navigation
Feat/python pycryptodome detection #556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
san-zrl
wants to merge
24
commits into
main
Choose a base branch
from
feat/python-pycryptodome-detection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+8,721
−303
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
0236660
feat(mapper): extend model for PyCryptodome support
san-zrl 5ddb380
feat(mapper): extend pyca mappers with new algorithm entries
san-zrl 5e8baef
feat(mapper/python): add ECDH→XDH and signature reorganizer rules, wi…
san-zrl 9e97579
chore(python): reorganise pyca detection rules into pyca/ subpackage
san-zrl 80efc72
feat(python): add PyCryptodome (pycryptodome/pycrypto) detection rules
san-zrl e5a70b0
feat(python): wire new translator contexts for key and random
san-zrl b7bc7c4
feat(python): update existing context translators for PyCryptodome
san-zrl e99c3c9
chore(python): move pyca test fixtures and test classes into pyca/ su…
san-zrl 71d1ff1
test(python): add PyCryptodome test fixtures and test classes
san-zrl 83c7681
fix/DH.key_agreement detection rule
san-zrl 343be20
fix/MGF1 parameter name is mgfSeed
san-zrl 40d4374
fix/place holder size in X25519TestFile.py and X448TestFile.py
san-zrl 612572f
fix/PSS option is salt_bytes
san-zrl 8710625
fix/PCD SHA512 requires truncate as str parameter
san-zrl 42957e7
fix/PKCS1_OAEP option is spelled mgfunc
san-zrl dab8ca3
fix/allow named parameters for key and mode in AES, DES, 3DES, Blowfi…
san-zrl 64d51b6
style: apply spotless formatting
san-zrl 98586ad
fix/simplify enrcypt and decrpyt rules
san-zrl fd61210
fix/add EdDSA-specific sign/verify rules without requiring a hash child
san-zrl a84fa00
fix/use RFC 8410 OIDs for Ed25519, Ed448, X25519, X448 in PycaCurveMa…
san-zrl b7f0849
fix: stop exporting KMAC security strength as a digest size
san-zrl d05bd7a
fix: model TupleHash128/256 as a parameter set, not a digest size
san-zrl fc0ace2
test: check KMAC and TupleHash parameter set identifiers in the CBOM
san-zrl ceca12d
feat: use named parameters for PyCryptodome MAC rules
san-zrl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
109 changes: 109 additions & 0 deletions
109
mapper/src/main/java/com/ibm/mapper/mapper/pyca/PycaCurveMapper.java
This file contains hidden or 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,109 @@ | ||
| /* | ||
| * Sonar Cryptography Plugin | ||
| * Copyright (C) 2024 PQCA | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to you under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.ibm.mapper.mapper.pyca; | ||
|
|
||
| import com.ibm.mapper.mapper.IMapper; | ||
| import com.ibm.mapper.model.Algorithm; | ||
| import com.ibm.mapper.model.EllipticCurveAlgorithm; | ||
| import com.ibm.mapper.model.algorithms.Ed25519; | ||
| import com.ibm.mapper.model.algorithms.Ed448; | ||
| import com.ibm.mapper.model.algorithms.X25519; | ||
| import com.ibm.mapper.model.algorithms.X448; | ||
| import com.ibm.mapper.model.curves.Brainpoolp256r1; | ||
| import com.ibm.mapper.model.curves.Brainpoolp384r1; | ||
| import com.ibm.mapper.model.curves.Brainpoolp512r1; | ||
| import com.ibm.mapper.model.curves.Secp192r1; | ||
| import com.ibm.mapper.model.curves.Secp224r1; | ||
| import com.ibm.mapper.model.curves.Secp256k1; | ||
| import com.ibm.mapper.model.curves.Secp256r1; | ||
| import com.ibm.mapper.model.curves.Secp384r1; | ||
| import com.ibm.mapper.model.curves.Secp521r1; | ||
| import com.ibm.mapper.model.curves.Sect163k1; | ||
| import com.ibm.mapper.model.curves.Sect163r2; | ||
| import com.ibm.mapper.model.curves.Sect233k1; | ||
| import com.ibm.mapper.model.curves.Sect233r1; | ||
| import com.ibm.mapper.model.curves.Sect283k1; | ||
| import com.ibm.mapper.model.curves.Sect283r1; | ||
| import com.ibm.mapper.model.curves.Sect409k1; | ||
| import com.ibm.mapper.model.curves.Sect409r1; | ||
| import com.ibm.mapper.model.curves.Sect571k1; | ||
| import com.ibm.mapper.model.curves.Sect571r1; | ||
| import com.ibm.mapper.utils.DetectionLocation; | ||
| import java.util.Optional; | ||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| public final class PycaCurveMapper implements IMapper { | ||
|
|
||
| @Nonnull | ||
| @Override | ||
| public Optional<? extends Algorithm> parse( | ||
| @Nullable String str, @Nonnull DetectionLocation detectionLocation) { | ||
| if (str == null) { | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| return switch (str.toUpperCase().trim()) { | ||
| case "SECP192R1", "PRIME192V1", "P-192", "P192", "NIST P-192" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Secp192r1(detectionLocation))); | ||
| case "SECP224R1", "PRIME224V1", "P-224", "P224", "NIST P-224" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Secp224r1(detectionLocation))); | ||
| case "SECP256R1", "PRIME256V1", "P-256", "P256", "NIST P-256" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Secp256r1(detectionLocation))); | ||
| case "SECP384R1", "PRIME384V1", "P-384", "P384", "NIST P-384" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Secp384r1(detectionLocation))); | ||
| case "SECP521R1", "PRIME521V1", "P-521", "P521", "NIST P-521" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Secp521r1(detectionLocation))); | ||
| case "SECP256K1" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Secp256k1(detectionLocation))); | ||
| case "CURVE25519" -> Optional.of(new X25519(detectionLocation)); | ||
| case "ED25519" -> Optional.of(new Ed25519(detectionLocation)); | ||
| case "CURVE448" -> Optional.of(new X448(detectionLocation)); | ||
| case "ED448" -> Optional.of(new Ed448(detectionLocation)); | ||
| case "BRAINPOOLP256R1" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Brainpoolp256r1(detectionLocation))); | ||
| case "BRAINPOOLP384R1" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Brainpoolp384r1(detectionLocation))); | ||
| case "BRAINPOOLP512R1" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Brainpoolp512r1(detectionLocation))); | ||
| case "SECT571K1" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Sect571k1(detectionLocation))); | ||
| case "SECT409K1" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Sect409k1(detectionLocation))); | ||
| case "SECT283K1" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Sect283k1(detectionLocation))); | ||
| case "SECT233K1" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Sect233k1(detectionLocation))); | ||
| case "SECT163K1" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Sect163k1(detectionLocation))); | ||
| case "SECT571R1" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Sect571r1(detectionLocation))); | ||
| case "SECT409R1" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Sect409r1(detectionLocation))); | ||
| case "SECT283R1" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Sect283r1(detectionLocation))); | ||
| case "SECT233R1" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Sect233r1(detectionLocation))); | ||
| case "SECT163R2" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Sect163r2(detectionLocation))); | ||
| default -> Optional.empty(); | ||
| }; | ||
| } | ||
| } |
This file contains hidden or 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
64 changes: 64 additions & 0 deletions
64
mapper/src/main/java/com/ibm/mapper/mapper/pyca/PycaKeyBasedAlgorithmMapper.java
This file contains hidden or 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,64 @@ | ||
| /* | ||
| * Sonar Cryptography Plugin | ||
| * Copyright (C) 2026 PQCA | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to you under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.ibm.mapper.mapper.pyca; | ||
|
|
||
| import com.ibm.mapper.mapper.IMapper; | ||
| import com.ibm.mapper.model.Algorithm; | ||
| import com.ibm.mapper.model.EllipticCurveAlgorithm; | ||
| import com.ibm.mapper.model.algorithms.DH; | ||
| import com.ibm.mapper.model.algorithms.DSA; | ||
| import com.ibm.mapper.model.algorithms.Ed25519; | ||
| import com.ibm.mapper.model.algorithms.Ed448; | ||
| import com.ibm.mapper.model.algorithms.ElGamal; | ||
| import com.ibm.mapper.model.algorithms.Fernet; | ||
| import com.ibm.mapper.model.algorithms.RSA; | ||
| import com.ibm.mapper.model.curves.Curve25519; | ||
| import com.ibm.mapper.model.curves.Curve448; | ||
| import com.ibm.mapper.utils.DetectionLocation; | ||
| import java.util.Optional; | ||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| public final class PycaKeyBasedAlgorithmMapper implements IMapper { | ||
|
|
||
| @Override | ||
| public @Nonnull Optional<Algorithm> parse( | ||
| @Nullable String str, @Nonnull DetectionLocation detectionLocation) { | ||
| if (str == null) { | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| return switch (str.toUpperCase().trim()) { | ||
| case "RSA" -> Optional.of(new RSA(detectionLocation)); | ||
| case "DSA" -> Optional.of(new DSA(detectionLocation)); | ||
| case "DH" -> Optional.of(new DH(detectionLocation)); | ||
| case "EC" -> Optional.of(new EllipticCurveAlgorithm(detectionLocation)); | ||
| case "CURVE25519" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Curve25519(detectionLocation))); | ||
| case "CURVE448" -> | ||
| Optional.of(new EllipticCurveAlgorithm(new Curve448(detectionLocation))); | ||
| case "ED25519" -> Optional.of(new Ed25519(detectionLocation)); | ||
| case "ED448" -> Optional.of(new Ed448(detectionLocation)); | ||
| case "ELGAMAL" -> Optional.of(new ElGamal(detectionLocation)); | ||
| case "FERNET" -> Optional.of(new Fernet(detectionLocation)); | ||
| default -> Optional.empty(); | ||
| }; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.