From 1b59b9cb9a9c3cae2eb904305fa6f3899d3dc820 Mon Sep 17 00:00:00 2001 From: Ade Lee Date: Sat, 25 Jan 2014 23:07:49 -0500 Subject: Added SymKeyGen service --- .../certsrv/key/SymKeyGenerationRequest.java | 80 +++++++++++++++++++--- 1 file changed, 71 insertions(+), 9 deletions(-) (limited to 'base/common/src/com/netscape/certsrv/key') diff --git a/base/common/src/com/netscape/certsrv/key/SymKeyGenerationRequest.java b/base/common/src/com/netscape/certsrv/key/SymKeyGenerationRequest.java index 1abaaab00..19e6aa67c 100644 --- a/base/common/src/com/netscape/certsrv/key/SymKeyGenerationRequest.java +++ b/base/common/src/com/netscape/certsrv/key/SymKeyGenerationRequest.java @@ -1,10 +1,16 @@ package com.netscape.certsrv.key; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import javax.ws.rs.core.MultivaluedMap; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; +import org.apache.commons.lang.StringUtils; + /** * @author alee * @@ -14,7 +20,38 @@ import javax.xml.bind.annotation.XmlRootElement; public class SymKeyGenerationRequest extends KeyRequest { private static final String CLIENT_ID = "clientID"; - private static final String DATA_TYPE = "dataType"; + private static final String KEY_SIZE = "keySize"; + private static final String KEY_ALGORITHM = "keyAlgorithm"; + private static final String KEY_USAGE = "keyUsage"; + + // usages + public static final String ENCRYPT_USAGE = "encrypt"; + public static final String DECRYPT_USAGE = "decrypt"; + public static final String SIGN_USAGE = "sign"; + public static final String VERIFY_USAGE = "verify"; + public static final String WRAP_USAGE = "wrap"; + public static final String UWRAP_USAGE = "unwrap"; + + public List getUsages() { + String usageString = properties.get(KEY_USAGE); + if (! StringUtils.isBlank(usageString)) { + return new ArrayList(Arrays.asList(usageString.split(","))); + } + return new ArrayList(); + } + + public void setUsages(List usages) { + this.properties.put(KEY_USAGE, StringUtils.join(usages, ",")); + } + + public void addUsage(String usage) { + List usages = getUsages(); + for (String u: usages) { + if (u.equals(usage)) return; + } + usages.add(usage); + setUsages(usages); + } public SymKeyGenerationRequest() { // required for JAXB (defaults) @@ -22,7 +59,14 @@ public class SymKeyGenerationRequest extends KeyRequest { public SymKeyGenerationRequest(MultivaluedMap form) { this.properties.put(CLIENT_ID, form.getFirst(CLIENT_ID)); - this.properties.put(DATA_TYPE, form.getFirst(DATA_TYPE)); + this.properties.put(KEY_SIZE, form.getFirst(KEY_SIZE)); + this.properties.put(KEY_ALGORITHM, form.getFirst(KEY_ALGORITHM)); + this.properties.put(KEY_USAGE, form.getFirst(KEY_USAGE)); + + String usageString = properties.get(KEY_USAGE); + if (! StringUtils.isBlank(usageString)) { + setUsages(new ArrayList(Arrays.asList(usageString.split(",")))); + } } /** @@ -40,17 +84,31 @@ public class SymKeyGenerationRequest extends KeyRequest { } /** - * @return the dataType + * @return the keySize + */ + public int getKeySize() { + return Integer.parseInt(this.properties.get(KEY_SIZE)); + } + + /** + * @param keySize the key size to set + */ + public void setKeySize(int keySize) { + this.properties.put(KEY_SIZE, Integer.toString(keySize)); + } + + /** + * @return the keyAlgorithm */ - public String getDataType() { - return this.properties.get(DATA_TYPE); + public String getKeyAlgorithm() { + return this.properties.get(KEY_ALGORITHM); } /** - * @param dataType the dataType to set + * @param keyAlgorithm the key algorithm to set */ - public void setDataType(String dataType) { - this.properties.put(DATA_TYPE, dataType); + public void setKeyAlgorithm(String keyAlgorithm) { + this.properties.put(KEY_ALGORITHM, keyAlgorithm); } public String toString() { @@ -73,8 +131,12 @@ public class SymKeyGenerationRequest extends KeyRequest { SymKeyGenerationRequest before = new SymKeyGenerationRequest(); before.setClientId("vek 12345"); - before.setDataType(KeyRequestResource.SYMMETRIC_KEY_TYPE); + before.setKeyAlgorithm("aes"); + before.setKeySize(128); before.setRequestType(KeyRequestResource.KEY_GENERATION_REQUEST); + before.addUsage(SymKeyGenerationRequest.DECRYPT_USAGE); + before.addUsage(SymKeyGenerationRequest.ENCRYPT_USAGE); + before.addUsage(SymKeyGenerationRequest.SIGN_USAGE); String string = before.toString(); System.out.println(string); -- cgit