summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/certsrv/key
diff options
context:
space:
mode:
authorAbhishek Koneru <akoneru@redhat.com>2014-04-09 13:59:26 -0400
committerAbhishek Koneru <akoneru@redhat.com>2014-04-16 17:24:57 -0400
commit6de5b60438f0edeb3d18f715d90a94191bd05cc8 (patch)
tree11e16238fe3c181ac43cafdcf9c244a181e461af /base/common/src/com/netscape/certsrv/key
parent8be0ac12ab0c1ff77c2b93a363352fe99aea5343 (diff)
downloadpki-6de5b60438f0edeb3d18f715d90a94191bd05cc8.tar.gz
pki-6de5b60438f0edeb3d18f715d90a94191bd05cc8.tar.xz
pki-6de5b60438f0edeb3d18f715d90a94191bd05cc8.zip
Fixes for comments on patches 87 and 89
Diffstat (limited to 'base/common/src/com/netscape/certsrv/key')
-rw-r--r--base/common/src/com/netscape/certsrv/key/Key.java13
-rw-r--r--base/common/src/com/netscape/certsrv/key/KeyClient.java13
-rw-r--r--base/common/src/com/netscape/certsrv/key/KeyTemplate.java18
-rw-r--r--base/common/src/com/netscape/certsrv/key/SymKeyGenerationRequest.java23
-rw-r--r--base/common/src/com/netscape/certsrv/key/Template.java21
5 files changed, 60 insertions, 28 deletions
diff --git a/base/common/src/com/netscape/certsrv/key/Key.java b/base/common/src/com/netscape/certsrv/key/Key.java
index 1b88075e4..5f5baf707 100644
--- a/base/common/src/com/netscape/certsrv/key/Key.java
+++ b/base/common/src/com/netscape/certsrv/key/Key.java
@@ -1,5 +1,10 @@
package com.netscape.certsrv.key;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
import com.netscape.cmsutil.util.Utils;
/**
@@ -10,18 +15,26 @@ import com.netscape.cmsutil.util.Utils;
* @author akoneru
*
*/
+@XmlRootElement(name="Key")
+@XmlAccessorType(XmlAccessType.NONE)
public class Key {
+ @XmlElement
private byte[] encryptedData;
+ @XmlElement
private byte[] nonceData;
+ @XmlElement
private String p12Data;
+ @XmlElement
private String algorithm;
+ @XmlElement
private Integer size;
+ @XmlElement
private byte[] data;
public Key() {
diff --git a/base/common/src/com/netscape/certsrv/key/KeyClient.java b/base/common/src/com/netscape/certsrv/key/KeyClient.java
index 97793ab39..9363a6a8c 100644
--- a/base/common/src/com/netscape/certsrv/key/KeyClient.java
+++ b/base/common/src/com/netscape/certsrv/key/KeyClient.java
@@ -195,7 +195,8 @@ public class KeyClient extends Client {
if (id == null || status == null) {
throw new IllegalArgumentException("Key Id and status must be specified.");
}
- if ((!status.equalsIgnoreCase(KeyResource.KEY_STATUS_ACTIVE)) && (!status.equalsIgnoreCase(KeyResource.KEY_STATUS_INACTIVE))) {
+ if (!status.equalsIgnoreCase(KeyResource.KEY_STATUS_ACTIVE)
+ && !status.equalsIgnoreCase(KeyResource.KEY_STATUS_INACTIVE)) {
throw new IllegalArgumentException("Invalid status value.");
}
Response response = keyClient.modifyKeyStatus(id, status);
@@ -670,7 +671,15 @@ public class KeyClient extends Client {
if (clientKeyId == null) {
throw new IllegalArgumentException("Client Key Identifier must be specified.");
}
-
+ //Validate the usages list
+ List<String> validUsages = SymKeyGenerationRequest.getValidUsagesList();
+ if (usages != null) {
+ for (String usage : usages) {
+ if (!validUsages.contains(usage)) {
+ throw new IllegalArgumentException("Invalid usage \"" + usage + "\" specified.");
+ }
+ }
+ }
SymKeyGenerationRequest data = new SymKeyGenerationRequest();
data.setClientKeyId(clientKeyId);
data.setKeyAlgorithm(keyAlgorithm);
diff --git a/base/common/src/com/netscape/certsrv/key/KeyTemplate.java b/base/common/src/com/netscape/certsrv/key/KeyTemplate.java
new file mode 100644
index 000000000..25d0d30ff
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/key/KeyTemplate.java
@@ -0,0 +1,18 @@
+package com.netscape.certsrv.key;
+
+public class KeyTemplate {
+
+ String id;
+ String description;
+
+ public KeyTemplate(String id, String description) {
+ this.id = id;
+ this.description = description;
+ }
+
+ public void printTemplateInfo() {
+ System.out.println();
+ System.out.println(" Template ID: " + id);
+ System.out.println(" Template Description: " + description);
+ }
+} \ No newline at end of file
diff --git a/base/common/src/com/netscape/certsrv/key/SymKeyGenerationRequest.java b/base/common/src/com/netscape/certsrv/key/SymKeyGenerationRequest.java
index 27dc69fd5..a2440d7cb 100644
--- a/base/common/src/com/netscape/certsrv/key/SymKeyGenerationRequest.java
+++ b/base/common/src/com/netscape/certsrv/key/SymKeyGenerationRequest.java
@@ -17,7 +17,7 @@ import com.netscape.certsrv.base.ResourceMessage;
* @author alee
*
*/
-@XmlRootElement(name="SymKeyGenerationRequest")
+@XmlRootElement(name = "SymKeyGenerationRequest")
@XmlAccessorType(XmlAccessType.FIELD)
public class SymKeyGenerationRequest extends ResourceMessage {
@@ -37,7 +37,7 @@ public class SymKeyGenerationRequest extends ResourceMessage {
public List<String> getUsages() {
String usageString = attributes.get(KEY_USAGE);
- if (! StringUtils.isBlank(usageString)) {
+ if (!StringUtils.isBlank(usageString)) {
return new ArrayList<String>(Arrays.asList(usageString.split(",")));
}
return new ArrayList<String>();
@@ -49,8 +49,9 @@ public class SymKeyGenerationRequest extends ResourceMessage {
public void addUsage(String usage) {
List<String> usages = getUsages();
- for (String u: usages) {
- if (u.equals(usage)) return;
+ for (String u : usages) {
+ if (u.equals(usage))
+ return;
}
usages.add(usage);
setUsages(usages);
@@ -69,7 +70,7 @@ public class SymKeyGenerationRequest extends ResourceMessage {
attributes.put(TRANS_WRAPPED_SESSION_KEY, form.getFirst(TRANS_WRAPPED_SESSION_KEY));
String usageString = attributes.get(KEY_USAGE);
- if (! StringUtils.isBlank(usageString)) {
+ if (!StringUtils.isBlank(usageString)) {
setUsages(new ArrayList<String>(Arrays.asList(usageString.split(","))));
}
setClassName(getClass().getName());
@@ -156,6 +157,18 @@ public class SymKeyGenerationRequest extends ResourceMessage {
}
}
+ public static List<String> getValidUsagesList() {
+ List<String> list = new ArrayList<String>();
+ list.add(WRAP_USAGE);
+ list.add(UWRAP_USAGE);
+ list.add(DECRYPT_USAGE);
+ list.add(ENCRYPT_USAGE);
+ list.add(KEY_USAGE);
+ list.add(SIGN_USAGE);
+
+ return list;
+ }
+
public static void main(String args[]) throws Exception {
SymKeyGenerationRequest before = new SymKeyGenerationRequest();
diff --git a/base/common/src/com/netscape/certsrv/key/Template.java b/base/common/src/com/netscape/certsrv/key/Template.java
deleted file mode 100644
index bfcf61eb7..000000000
--- a/base/common/src/com/netscape/certsrv/key/Template.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.netscape.certsrv.key;
-
-
-public class Template{
- String templateID;
- String templateName;
- String templateDescription;
- public Template(String templateID, String templateName, String templateDescription) {
- super();
- this.templateID = templateID;
- this.templateName = templateName;
- this.templateDescription = templateDescription;
- }
-
- public void printTemplateInfo(){
- System.out.println();
- System.out.println(" Template ID: " + templateID);
- System.out.println(" Template Name: " + templateName);
- System.out.println(" Template Description: " + templateDescription);
- }
-} \ No newline at end of file