-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from usdAG/feat/add-sm-algorithm-support
Add SM Cipher Suite Support
- Loading branch information
Showing
9 changed files
with
137 additions
and
5 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
13 changes: 13 additions & 0 deletions
13
src/main/java/de/usd/cstchef/operations/encryption/SM4Decryption.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,13 @@ | ||
package de.usd.cstchef.operations.encryption; | ||
|
||
import de.usd.cstchef.operations.OperationCategory; | ||
import de.usd.cstchef.operations.Operation.OperationInfos; | ||
|
||
@OperationInfos(name = "SM4 Decryption", category = OperationCategory.ENCRYPTION, description = "Decrypts via the SM4 algorithm.") | ||
public class SM4Decryption extends DecryptionOperation { | ||
|
||
public SM4Decryption() { | ||
super("SM4"); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/de/usd/cstchef/operations/encryption/SM4Encryption.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,13 @@ | ||
package de.usd.cstchef.operations.encryption; | ||
|
||
import de.usd.cstchef.operations.OperationCategory; | ||
import de.usd.cstchef.operations.Operation.OperationInfos; | ||
|
||
@OperationInfos(name = "SM4 Encryption", category = OperationCategory.ENCRYPTION, description = "Encrypts via the SM4 algorithm.") | ||
public class SM4Encryption extends EncryptionOperation { | ||
|
||
public SM4Encryption() { | ||
super("SM4"); | ||
} | ||
|
||
} |
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,13 @@ | ||
package de.usd.cstchef.operations.hashing; | ||
|
||
import de.usd.cstchef.operations.OperationCategory; | ||
import de.usd.cstchef.operations.Operation.OperationInfos; | ||
|
||
@OperationInfos(name = "SM3", category = OperationCategory.HASHING, description = "The SM3 algorithm") | ||
public class SM3 extends HashOperation { | ||
|
||
public SM3() { | ||
super("SM3"); | ||
} | ||
|
||
} |
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
70 changes: 70 additions & 0 deletions
70
src/main/java/de/usd/cstchef/operations/signature/SM2Signature.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,70 @@ | ||
package de.usd.cstchef.operations.signature; | ||
|
||
import java.security.Signature; | ||
|
||
import javax.swing.JComboBox; | ||
|
||
import org.bouncycastle.util.encoders.Base64; | ||
import org.bouncycastle.util.encoders.Hex; | ||
|
||
import burp.api.montoya.core.ByteArray; | ||
import de.usd.cstchef.Utils.MessageType; | ||
import de.usd.cstchef.operations.Operation.OperationInfos; | ||
import de.usd.cstchef.operations.OperationCategory; | ||
|
||
@OperationInfos(name = "SM2 Signature", category = OperationCategory.SIGNATURE, description = "Create a SM2 signature") | ||
public class SM2Signature extends KeystoreOperation { | ||
|
||
private static String[] inOutModes = new String[] { "Raw", "Hex", "Base64" }; | ||
|
||
protected JComboBox<String> algos; | ||
protected JComboBox<String> inputMode; | ||
protected JComboBox<String> outputMode; | ||
|
||
public SM2Signature() { | ||
super(); | ||
this.createMyUI(); | ||
} | ||
|
||
protected ByteArray perform(ByteArray input, MessageType messageType) throws Exception { | ||
if( !this.keyAvailable.isSelected() ) | ||
throw new IllegalArgumentException("No private key available."); | ||
|
||
String algo = (String)algos.getSelectedItem(); | ||
Signature signature = Signature.getInstance(algo); | ||
|
||
String selectedInputMode = (String)inputMode.getSelectedItem(); | ||
String selectedOutputMode = (String)outputMode.getSelectedItem(); | ||
|
||
if( selectedInputMode.equals("Hex") ) | ||
input = factory.createByteArray(Hex.decode(input.getBytes())); | ||
if( selectedInputMode.equals("Base64") ) | ||
input = factory.createByteArray(Base64.decode(input.getBytes())); | ||
|
||
signature.initSign(this.selectedEntry.getPrivateKey()); | ||
signature.update(input.getBytes()); | ||
ByteArray result = factory.createByteArray(signature.sign()); | ||
|
||
if( selectedOutputMode.equals("Hex") ) | ||
result = factory.createByteArray(Hex.encode(result.getBytes())); | ||
if( selectedOutputMode.equals("Base64") ) | ||
result = factory.createByteArray(Base64.encode(result.getBytes())); | ||
|
||
return result; | ||
} | ||
|
||
public void createMyUI() { | ||
|
||
super.createMyUI(); | ||
SignatureUtils utils = SignatureUtils.getInstance(); | ||
|
||
this.algos = new JComboBox<>(utils.getAlgos("SM2")); | ||
this.addUIElement("Padding", this.algos); | ||
|
||
this.inputMode = new JComboBox<>(inOutModes); | ||
this.addUIElement("Input", this.inputMode); | ||
|
||
this.outputMode = new JComboBox<>(inOutModes); | ||
this.addUIElement("Output", this.outputMode); | ||
} | ||
} |
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