Skip to content

Commit

Permalink
fix(registrar): allow more SSH key types
Browse files Browse the repository at this point in the history
- Extended check on SSH keys validity to support more key types.
  • Loading branch information
zlamalp committed Dec 9, 2021
1 parent 2d3e284 commit 9edd223
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
*/
public class SshKeysTextAreaValidator extends TextAreaValidator {

RegExp regExp = RegExp.compile("^(ssh-rsa|ssh-dsa|ecdsa-sha2-nistp256|ecdsa-sha2-nistp384|ecdsa-sha2-nistp521|ssh-ed25519|sk-ed25519|sk-ecdsa) (([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?)( [^,\n]+)?$");
RegExp regExp = RegExp.compile("^(" +
"(ssh-(rsa|dss|ed25519)([email protected])?)|" +
"(sk-(ssh-ed25519|ecdsa-sha2-nistp256)(-cert-v01)[email protected])|" +
"(ecdsa-sha2-nistp(256|384|521)([email protected])?))" +
" (([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?)( [^,\n]+)?$");

@Override
public boolean validateLocal(TextArea textArea) {
Expand Down Expand Up @@ -65,6 +69,8 @@ public boolean validateLocal(TextArea textArea) {
return false;
}

// FIXME - this doesn't make sense anymore, as we have multiple different SSH keys prefixes, which needs to be checked.
/*
if (sshKeys.indexOf("ssh-") != sshKeys.lastIndexOf("ssh-")) {
// there are at least two keys
if (!sshKeys.contains(",ssh-") && !sshKeys.contains("\nssh-")) {
Expand All @@ -73,6 +79,7 @@ public boolean validateLocal(TextArea textArea) {
return false;
}
}
*/

// normalize value just in case
sshKeys = sshKeys.replaceAll("(\n)+", ",");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
*/
public class SshKeysTextFieldValidator extends TextFieldValidator {

RegExp regExp = RegExp.compile("^(ssh-rsa|ssh-dsa|ecdsa-sha2-nistp256|ecdsa-sha2-nistp384|ecdsa-sha2-nistp521|ssh-ed25519|sk-ed25519|sk-ecdsa) (([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?)( [^,\n]+)?$");
RegExp regExp = RegExp.compile("^(" +
"(ssh-(rsa|dss|ed25519)([email protected])?)|" +
"(sk-(ssh-ed25519|ecdsa-sha2-nistp256)(-cert-v01)[email protected])|" +
"(ecdsa-sha2-nistp(256|384|521)([email protected])?))" +
" (([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?)( [^,\n]+)?$");

@Override
public boolean validateLocal(TextField textField) {
Expand Down Expand Up @@ -53,6 +57,8 @@ public boolean validateLocal(TextField textField) {
return false;
}

// FIXME - this doesn't make sense anymore, as we have multiple different SSH keys prefixes, which needs to be checked.
/*
if (sshKeys.indexOf("ssh-") != sshKeys.lastIndexOf("ssh-")) {
// there are at least two keys
if (!sshKeys.contains(",ssh-")) {
Expand All @@ -61,6 +67,7 @@ public boolean validateLocal(TextField textField) {
return false;
}
}
*/

// normalize value just in case
sshKeys = sshKeys.replaceAll("(,)+", ",");
Expand Down

0 comments on commit 9edd223

Please sign in to comment.