Skip to content

Commit

Permalink
Fix Javascript and backend to populate the WebUI for ServerSideKeygen
Browse files Browse the repository at this point in the history
This patch:

- Uses javascript to fill up the web UI request for ServerSide Keygen request profile

- Provides 2 drop down boxes: KeyType and Keysize. KeySize autoupdates based on
  the KeyType selected. Example: RSA -> 1024, 2048,.. ; ECC -> nistp521, nistp256

- The keyType and keySize are read from the profile's attr:
  policyset.userCertSet.3.constraint.params.keyParameters

File wise changes:

- ServerKeygenUserKeyDefault.java can now generate Key pair based on the user's
  selection. (NOTE: This logic was added from my previous PR and can be removed.)

- ServerKeygenInput.java sends 2 new fields (keyType and keyRequest) to the request, to be
  displayed on the webUI

- ProfileSelect.template carries the javascript changes. Note that there are 2 new if
  conditions included: "server_side_keygen_key_type" and "server_side_keygen_key_size".
  This ensures that it doesn't meddle with other profile web UIs

- IDescriptor.java and UserMessages.properties carry the appropriate String values to
  be displayed/requested from user.

Signed-off-by: Dinesh Prasanth M K <[email protected]>
  • Loading branch information
SilleBille committed Apr 17, 2020
1 parent 9629944 commit f9dc3be
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 25 deletions.
33 changes: 26 additions & 7 deletions base/ca/shared/webapps/ca/ee/ca/ProfileSelect.template
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ function keyLengthsCurvesOptions (keyPurpose)
if (keyPurpose.length == 0 || (keyPurpose.length > 0 && policySetListSet[i].setId.indexOf(keyPurpose) > -1)) {
keyType = policySetListSet[i].policySet[j].constraintSet[k].value;
}
} else {
if (document.getElementById("keyTypeId").value != "undefined") {
keyType = document.getElementById("keyTypeId").value;
}
}
}

Expand Down Expand Up @@ -346,6 +350,8 @@ function keyLengthsCurvesOptions (keyPurpose)
value != "nistp256" && value != "nistp384" && value != "nistp521" &&
value != "ECDSA_P256" && value != "ECDSA_P384" && value != "ECDSA_P521") {
included = false;
} else if (keyType == "EC" && isNumeric(value)) {
included = false;
}

if (included) {
Expand Down Expand Up @@ -377,6 +383,18 @@ function keyLengthsCurvesOptions (keyPurpose)
return options;
}

function updateKeyLengthsCurvesOptions() {
// get the keySize select element via its known id
var cSelect = document.getElementById("keySizeId");

// remove the current options from the select tag
var len=cSelect.options.length;
while (cSelect.options.length > 0) {
cSelect.remove(0);
}
cSelect.innerHTML = keyLengthsCurvesOptions("");
}

function isNumeric(sText)
{
var validChars = "0123456789";
Expand Down Expand Up @@ -753,17 +771,18 @@ for (var m = 0; m < inputPluginListSet.length; m++) {
} else if (inputListSet[n].inputSyntax == 'server_side_keygen_request_type') {
// get PKCS#12 password
document.writeln('<tr>');
document.write('<td align=right><font size="-1" face="PrimaSans BT, Verdana, sans-serif">PKCS #12 Password:</font></td>');
document.write('<td align=left><font size="-1" face="PrimaSans BT, Verdana, sans-serif"><input type=password name="serverSideKeygenP12Passwd" value="" AutoComplete=off ></font></td>');
document.writeln('<td align=right><font size="-1" face="PrimaSans BT, Verdana, sans-serif">PKCS #12 Password:</font></td>');
document.writeln('<td align=left><font size="-1" face="PrimaSans BT, Verdana, sans-serif"><input type=password name="serverSideKeygenP12Passwd" value="" AutoComplete=off ></font></td>');
document.writeln('</tr>');

document.writeln('<tr>');
document.write('<td align=right><font size="-1" face="PrimaSans BT, Verdana, sans-serif">PKCS #12 Password again:</font></td>');
document.write('<td align=left><font size="-1" face="PrimaSans BT, Verdana, sans-serif"><input type=password name="p12PasswordAgain" value="" AutoComplete=off ></font></td>');
document.writeln('<SELECT NAME="keyType">'+getKeyTypesOptionsForKeyGen()+'</SELECT>&nbsp;&nbsp;<SELECT NAME=\"cryptprovider\"></SELECT>');
document.writeln('<SELECT NAME="keySize">'+keyLengthsCurvesOptions("")+'</SELECT>&nbsp;&nbsp;<SELECT NAME=\"cryptprovider\"></SELECT>');
document.writeln('<td align=right><font size="-1" face="PrimaSans BT, Verdana, sans-serif">PKCS #12 Password again:</font></td>');
document.writeln('<td align=left><font size="-1" face="PrimaSans BT, Verdana, sans-serif"><input type=password name="p12PasswordAgain" value="" AutoComplete=off ></font></td>');
document.writeln('</tr>');

} else if (inputListSet[n].inputSyntax == 'server_side_keygen_key_type') {
document.writeln('<SELECT NAME="keyType" ID="keyTypeId" onChange=\"updateKeyLengthsCurvesOptions()\">'+getKeyTypesOptionsForKeyGen() + '</SELECT>&nbsp');
} else if (inputListSet[n].inputSyntax == 'server_side_keygen_key_size') {
document.writeln('<SELECT NAME="keySize" ID="keySizeId">'+keyLengthsCurvesOptions("")+'</SELECT>&nbsp');
} else if (inputListSet[n].inputSyntax == 'cert_request') {
document.writeln('<textarea cols=60 rows=10 name=' + inputListSet[n].inputId + '></textarea>');
} else if (inputListSet[n].inputSyntax == 'cert_request_type') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public interface IDescriptor {
public static String CERT_REQUEST_TYPE = "cert_request_type";
public static String SERVER_SIDE_KEYGEN_REQUEST_TYPE = "server_side_keygen_request_type";
public static String SERVER_SIDE_KEYGEN_PKCS12 = "server_side_keygen_p12";
public static String SERVER_SIDE_KEYGEN_KEY_TYPE = "server_side_keygen_key_type";
public static String SERVER_SIDE_KEYGEN_KEY_SIZE = "server_side_keygen_key_size";
public static String CHOICE = "choice"; // choice of strings
public static String DN = "dn";
public static String IP = "ip";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,22 +336,61 @@ public void populate(IRequest request, X509CertInfo info)
request.setExtData("isServerSideKeygen", "true");
CryptoToken token = cm.getInternalKeyStorageToken();

String keySizeStr = request.getExtDataInString("keySize");
int keySize = 1024;
if (keySizeStr != null) {
CMS.debug("ServerKeygenUserKeyDefault: populate: keySize in request: " + keySizeStr);
keySize = Integer.parseInt(keySizeStr);
String keyTypeStr = request.getExtDataInString("keyType");
String keyType = "RSA";
int keySize = 2048;
String curveName = "nistp521";

// Populate the keyType and keySize/keyCurve

if (keyTypeStr != null && !keyTypeStr.isEmpty()) {
CMS.debug("ServerKeygenUserKeyDefault: populate: keyType in request: " + keyTypeStr);
keyType = keyTypeStr;
} else {
CMS.debug("ServerKeygenUserKeyDefault: populate: keySize in request null; default to 2048");
CMS.debug("ServerKeygenUserKeyDefault: populate: keyType in request null; default to RSA");
}

String keySizeCurveStr = request.getExtDataInString("keySize");

if (keyType.contentEquals("RSA")) {
if (keySizeCurveStr != null && !keySizeCurveStr.isEmpty()) {
CMS.debug("ServerKeygenUserKeyDefault: populate: keySize in request: " + keySizeCurveStr);
keySize = Integer.parseInt(keySizeCurveStr);
} else {
CMS.debug("ServerKeygenUserKeyDefault: populate: keySize in request null; default to" + keySize);
}
// Do things when RSA is selected
} else if (keyType.contentEquals("EC")) {
// TODO: dmoluguw: Fix the following to generate right Key ECC keys

if (keySizeCurveStr != null && !keySizeCurveStr.isEmpty()) {
CMS.debug("ServerKeygenUserKeyDefault: populate: keyCurve in request: " + keySizeCurveStr);
curveName = keySizeCurveStr;
} else {
CMS.debug("ServerKeygenUserKeyDefault: populate: keySize in request null; default to" + curveName);
}
// Do things when EC is selected
} else {
throw new Exception("Unsupported keyType: " + keyType);
}
request.setExtData(IRequest.KEY_GEN_ALGORITHM, keyType);
if(keyType.contentEquals("RSA")) {
request.setExtData(IRequest.KEY_GEN_SIZE, keySize);
}
else if (keyType.contentEquals("EC")) {
// TODO: Check whether IRequest.KEY_GEN_SIZE can accept string value
request.setExtData(IRequest.KEY_GEN_SIZE, curveName);
}
request.setExtData(IRequest.KEY_GEN_ALGORITHM, "RSA");
request.setExtData(IRequest.KEY_GEN_SIZE, keySize);

/*
* it is necessary to put in a static fake key here to prevent
* issue; The fake key will be replaced later once KRA generates
* the real keys
*/

// dmoluguw: TODO: The below values seem to be for development purposes,
// and will probably work only with keyType="RSA"

String pubKeyStr = "";
switch (keySize) {
case 1024:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@
public class ServerKeygenInput extends EnrollInput implements IProfileInput {

public static final String P12PASSWORD = "serverSideKeygenP12Passwd";
/*

public static final String KEY_TYPE = "keyType";
public static final String KEY_SIZE = "keySize";
*/


public ServerKeygenInput() {
addValueName(P12PASSWORD);
/*

addValueName(KEY_TYPE);
addValueName(KEY_SIZE);
*/

}

/**
Expand Down Expand Up @@ -99,16 +99,14 @@ public IDescriptor getValueDescriptor(Locale locale, String name) {
return new Descriptor(IDescriptor.SERVER_SIDE_KEYGEN_REQUEST_TYPE, null,
null,
CMS.getUserMessage(locale, "CMS_PROFILE_SERVER_KEYGEN_P12PASSWD"));
/*
} else if (name.equals(KEY_TYPE)) {
return new Descriptor(IDescriptor.STRING, null,
return new Descriptor(IDescriptor.SERVER_SIDE_KEYGEN_KEY_TYPE, null,
null,
CMS.getUserMessage(locale, "CMS_PROFILE_SERVER_KEYGEN_KEY_TYPE"));
} else if (name.equals(KEY_SIZE)) {
return new Descriptor(IDescriptor.STRING, null,
return new Descriptor(IDescriptor.SERVER_SIDE_KEYGEN_KEY_SIZE, null,
null,
CMS.getUserMessage(locale, "CMS_PROFILE_SERVER_KEYGEN_KEY_SIZE"));
*/
}
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions base/server/cmsbundle/src/UserMessages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,8 @@ CMS_PROFILE_INPUT_FILE_SIGNING_TEXT=Text Being Signed
CMS_PROFILE_INPUT_SERVER_KEYGEN_NAME=Server-Side Key Generation
CMS_PROFILE_INPUT_SERVER_KEYGEN_TEXT=Server-Side Key Generation
CMS_PROFILE_SERVER_KEYGEN_P12PASSWD=Server-Side Key Generation P12 Password
CMS_PROFILE_SERVER_KEYGEN_KEY_TYPE=Server-Side Key Generation KEY TYPE
CMS_PROFILE_SERVER_KEYGEN_KEY_SIZE=Server-Side Key Generation KEY SIZE
CMS_PROFILE_SERVER_KEYGEN_KEY_TYPE=Server-Side Key Generation Key Type
CMS_PROFILE_SERVER_KEYGEN_KEY_SIZE=Server-Side Key Generation Key Size
CMS_PROFILE_INPUT_SUBJECT_ALT_NAME_EXT_NAME=Subject Alternative Name Extension Information
CMS_PROFILE_INPUT_SUBJECT_ALT_NAME_EXT_TEXT=Subject Alternative Name Extension Information
CMS_PROFILE_IMAGE=Image
Expand Down

0 comments on commit f9dc3be

Please sign in to comment.