-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 #33210 from appsmithorg/cp/20240506
fix: Start using SHA2 instead of SHA1 algorithms for signing during git operations (#33166)
- Loading branch information
Showing
7 changed files
with
213 additions
and
52 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
12 changes: 12 additions & 0 deletions
12
...r/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/SSHConstants.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,12 @@ | ||
package com.appsmith.external.git.constants; | ||
|
||
public class SSHConstants { | ||
public static final String RSA_TYPE = "ssh-rsa"; | ||
public static final String RSA_TYPE_PREFIX = RSA_TYPE + " "; | ||
private static final String ECDSA_TYPE = "ecdsa-sha2-nistp256"; | ||
public static final String ECDSA_TYPE_PREFIX = ECDSA_TYPE + " "; | ||
|
||
public static final String RSA_KEY_FACTORY_IDENTIFIER = "RSA"; | ||
public static final String ECDSA_KEY_FACTORY_IDENTIFIER = "EC"; | ||
public static final String ECDSA_KEY_FACTORY_IDENTIFIER_BC = "ECDSA"; | ||
} |
42 changes: 42 additions & 0 deletions
42
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/utils/CryptoUtil.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,42 @@ | ||
package com.appsmith.external.git.utils; | ||
|
||
import java.math.BigInteger; | ||
import java.nio.ByteBuffer; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.spec.RSAPublicKeySpec; | ||
import java.util.Base64; | ||
|
||
import static com.appsmith.external.git.constants.SSHConstants.RSA_TYPE; | ||
|
||
public class CryptoUtil { | ||
public static RSAPublicKeySpec decodeOpenSSHRSA(byte[] input) { | ||
String[] fields = new String(input, StandardCharsets.US_ASCII).split(" "); | ||
if ((fields.length < 2) || (!fields[0].equals(RSA_TYPE))) | ||
throw new IllegalArgumentException("Unsupported type"); | ||
byte[] std = Base64.getDecoder().decode(fields[1]); | ||
return decodeRSAPublicSSH(std); | ||
} | ||
|
||
static RSAPublicKeySpec decodeRSAPublicSSH(byte[] encoded) { | ||
ByteBuffer input = ByteBuffer.wrap(encoded); | ||
String type = asString(input); | ||
if (!RSA_TYPE.equals(type)) throw new IllegalArgumentException("Unsupported type"); | ||
BigInteger exp = sshInt(input); | ||
BigInteger mod = sshInt(input); | ||
return new RSAPublicKeySpec(mod, exp); | ||
} | ||
|
||
private static String asString(ByteBuffer buf) { | ||
return new String(lenVal(buf), StandardCharsets.US_ASCII); | ||
} | ||
|
||
private static BigInteger sshInt(ByteBuffer buf) { | ||
return new BigInteger(+1, lenVal(buf)); | ||
} | ||
|
||
private static byte[] lenVal(ByteBuffer buf) { | ||
byte[] copy = new byte[buf.getInt()]; | ||
buf.get(copy); | ||
return copy; | ||
} | ||
} |
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