diff options
author | Ade Lee <alee@redhat.com> | 2014-01-25 23:07:49 -0500 |
---|---|---|
committer | Ade Lee <alee@redhat.com> | 2014-02-04 13:36:31 -0500 |
commit | 1b59b9cb9a9c3cae2eb904305fa6f3899d3dc820 (patch) | |
tree | ccaab681c52a8c99fd2a627f25b8196299c9e81a /base/common/src/com/netscape | |
parent | 34ecb259d65a979670366a0bf969b21e9ff616b2 (diff) | |
download | pki-1b59b9cb9a9c3cae2eb904305fa6f3899d3dc820.tar.gz pki-1b59b9cb9a9c3cae2eb904305fa6f3899d3dc820.tar.xz pki-1b59b9cb9a9c3cae2eb904305fa6f3899d3dc820.zip |
Added SymKeyGen service
Diffstat (limited to 'base/common/src/com/netscape')
-rw-r--r-- | base/common/src/com/netscape/certsrv/key/SymKeyGenerationRequest.java | 80 | ||||
-rw-r--r-- | base/common/src/com/netscape/certsrv/request/IRequest.java | 5 |
2 files changed, 76 insertions, 9 deletions
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<String> getUsages() { + String usageString = properties.get(KEY_USAGE); + if (! StringUtils.isBlank(usageString)) { + return new ArrayList<String>(Arrays.asList(usageString.split(","))); + } + return new ArrayList<String>(); + } + + public void setUsages(List<String> usages) { + this.properties.put(KEY_USAGE, StringUtils.join(usages, ",")); + } + + public void addUsage(String usage) { + List<String> 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<String, String> 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<String>(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); diff --git a/base/common/src/com/netscape/certsrv/request/IRequest.java b/base/common/src/com/netscape/certsrv/request/IRequest.java index 60c083e6a..05908fc1d 100644 --- a/base/common/src/com/netscape/certsrv/request/IRequest.java +++ b/base/common/src/com/netscape/certsrv/request/IRequest.java @@ -167,6 +167,11 @@ public interface IRequest extends Serializable { public static final String SECURITY_DATA_SESS_WRAPPED_DATA = "sessWrappedSecData"; public static final String SECURITY_DATA_PASS_WRAPPED_DATA = "passPhraseWrappedData"; + // symkey generation request attributes + public static final String SYMKEY_GENERATION_REQUEST = "symkeyGenRequest"; + public static final String SYMKEY_GEN_ALGORITHM = "symkeyGenAlgorithm"; + public static final String SYMKEY_GEN_SIZE = "symkeyGenSize"; + public static final String SYMKEY_GEN_USAGES = "symkeyGenUsages"; // requestor type values. public static final String REQUESTOR_EE = "EE"; |