-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Nicklas Körtge <nicklas.koertge1@ibm.com>
- Loading branch information
1 parent
6cec400
commit d864bff
Showing
14 changed files
with
376 additions
and
187 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
49 changes: 49 additions & 0 deletions
49
enricher/src/main/java/com/ibm/enricher/algorithm/RSAoaepEnricher.java
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,49 @@ | ||
/* | ||
* SonarQube Cryptography Plugin | ||
* Copyright (C) 2024 IBM | ||
* | ||
* 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.enricher.algorithm; | ||
|
||
import com.ibm.enricher.IEnricher; | ||
import com.ibm.mapper.model.INode; | ||
import com.ibm.mapper.model.Oid; | ||
import com.ibm.mapper.model.Padding; | ||
import com.ibm.mapper.model.Signature; | ||
import com.ibm.mapper.model.algorithms.RSA; | ||
import com.ibm.mapper.model.padding.OAEP; | ||
import java.util.Optional; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class RSAoaepEnricher implements IEnricher { | ||
|
||
@Override | ||
public @NotNull INode enrich(@NotNull INode node) { | ||
if (node instanceof RSA rsa) { | ||
final Optional<INode> padding = rsa.hasChildOfType(Padding.class); | ||
if (padding.isEmpty()) { | ||
return node; | ||
} | ||
if (padding.get() instanceof OAEP) { | ||
final RSA newRSA = new RSA(Signature.class, rsa); | ||
newRSA.put(new Oid("1.2.840.113549.1.1.7", rsa.getDetectionContext())); | ||
return newRSA; | ||
} | ||
} | ||
return node; | ||
} | ||
} |
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
86 changes: 86 additions & 0 deletions
86
mapper/src/main/java/com/ibm/mapper/reorganizer/rules/PaddingReorganizer.java
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,86 @@ | ||
/* | ||
* SonarQube Cryptography Plugin | ||
* Copyright (C) 2024 IBM | ||
* | ||
* 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.reorganizer.rules; | ||
|
||
import com.ibm.mapper.model.INode; | ||
import com.ibm.mapper.model.Padding; | ||
import com.ibm.mapper.model.PrivateKey; | ||
import com.ibm.mapper.model.PublicKeyEncryption; | ||
import com.ibm.mapper.model.functionality.Decrypt; | ||
import com.ibm.mapper.model.padding.OAEP; | ||
import com.ibm.mapper.reorganizer.IReorganizerRule; | ||
import com.ibm.mapper.reorganizer.builder.ReorganizerRuleBuilder; | ||
import java.util.Optional; | ||
|
||
public final class PaddingReorganizer { | ||
|
||
private PaddingReorganizer() { | ||
// nothing | ||
} | ||
|
||
public static final IReorganizerRule MOVE_OAEP_UNDER_ALGORITHM = | ||
new ReorganizerRuleBuilder() | ||
.createReorganizerRule() | ||
.forNodeKind(PrivateKey.class) | ||
.withDetectionCondition( | ||
(node, parent, roots) -> { | ||
final Optional<INode> functionality = | ||
node.hasChildOfType(Decrypt.class); | ||
final Optional<INode> pke = | ||
node.hasChildOfType(PublicKeyEncryption.class); | ||
if (functionality.isEmpty()) { | ||
return false; | ||
} | ||
if (pke.isEmpty()) { | ||
return false; | ||
} | ||
|
||
return functionality | ||
.get() | ||
.hasChildOfType(Padding.class) | ||
.map(OAEP.class::isInstance) | ||
.orElse(false); | ||
}) | ||
.perform( | ||
(node, parent, roots) -> { | ||
final Optional<INode> pke = | ||
node.hasChildOfType(PublicKeyEncryption.class); | ||
final Optional<INode> functionality = | ||
node.hasChildOfType(Decrypt.class); | ||
if (functionality.isEmpty()) { | ||
return roots; | ||
} | ||
if (pke.isEmpty()) { | ||
return roots; | ||
} | ||
|
||
functionality | ||
.get() | ||
.hasChildOfType(Padding.class) | ||
.ifPresent( | ||
p -> { | ||
pke.get().put(p); | ||
functionality | ||
.get() | ||
.removeChildOfType(p.getKind()); | ||
}); | ||
return roots; | ||
}); | ||
} |
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
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
Oops, something went wrong.