diff options
| author | Ade Lee <alee@redhat.com> | 2017-04-07 12:23:47 -0400 |
|---|---|---|
| committer | Ade Lee <alee@redhat.com> | 2017-04-11 16:48:33 -0400 |
| commit | 77d2064858e4623fa25f4986647f318d8bf8a6f7 (patch) | |
| tree | a2d3690572a51c2a09bbe86af8090e768f762d2f /base/common/src/org | |
| parent | a29888e42c14c9c7e642769b747bb288d39a0809 (diff) | |
| download | pki-77d2064858e4623fa25f4986647f318d8bf8a6f7.tar.gz pki-77d2064858e4623fa25f4986647f318d8bf8a6f7.tar.xz pki-77d2064858e4623fa25f4986647f318d8bf8a6f7.zip | |
Add KRAInfo resource
This resource (which will be accessed at /kra/rest/info)
will initially return the mechanism for archival or retrieval.
This is needed by clients to know how to package secrets when
archiving.
Change-Id: I6990ebb9c9dafc4158e51ba61a30e773d1d953ec
Diffstat (limited to 'base/common/src/org')
3 files changed, 224 insertions, 0 deletions
diff --git a/base/common/src/org/dogtagpki/common/KRAInfo.java b/base/common/src/org/dogtagpki/common/KRAInfo.java new file mode 100644 index 000000000..e17bd642d --- /dev/null +++ b/base/common/src/org/dogtagpki/common/KRAInfo.java @@ -0,0 +1,136 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2017 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package org.dogtagpki.common; + +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.netscape.certsrv.base.ResourceMessage; + +/** + * @author Ade Lee + */ +@XmlRootElement(name="KRAInfo") +public class KRAInfo extends ResourceMessage { + + private static Logger logger = LoggerFactory.getLogger(Info.class); + + public static Marshaller marshaller; + public static Unmarshaller unmarshaller; + + static { + try { + marshaller = JAXBContext.newInstance(KRAInfo.class).createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + unmarshaller = JAXBContext.newInstance(KRAInfo.class).createUnmarshaller(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + } + + String archivalMechanism; + String recoveryMechanism; + + @XmlElement(name="ArchivalMechanism") + public String getArchivalMechanism() { + return archivalMechanism; + } + + public void setArchivalMechanism(String archivalMechanism) { + this.archivalMechanism = archivalMechanism; + } + + @XmlElement(name="RecoveryMechanism") + public String getRecoveryMechanism() { + return recoveryMechanism; + } + + public void setRecoveryMechanism(String recoveryMechanism) { + this.recoveryMechanism = recoveryMechanism; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((archivalMechanism == null) ? 0 : archivalMechanism.hashCode()); + result = prime * result + ((recoveryMechanism == null) ? 0 : recoveryMechanism.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + KRAInfo other = (KRAInfo) obj; + if (archivalMechanism == null) { + if (other.archivalMechanism != null) + return false; + } else if (!archivalMechanism.equals(other.archivalMechanism)) + return false; + if (recoveryMechanism == null) { + if (other.recoveryMechanism != null) + return false; + } else if (!recoveryMechanism.equals(other.recoveryMechanism)) + return false; + return true; + } + + public String toString() { + try { + StringWriter sw = new StringWriter(); + marshaller.marshal(this, sw); + return sw.toString(); + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static KRAInfo valueOf(String string) throws Exception { + return (KRAInfo)unmarshaller.unmarshal(new StringReader(string)); + } + + public static void main(String args[]) throws Exception { + + KRAInfo before = new KRAInfo(); + before.setArchivalMechanism("encrypt"); + before.setRecoveryMechanism("keywrap"); + + String string = before.toString(); + System.out.println(string); + + KRAInfo after = KRAInfo.valueOf(string); + System.out.println(before.equals(after)); + } +} + diff --git a/base/common/src/org/dogtagpki/common/KRAInfoClient.java b/base/common/src/org/dogtagpki/common/KRAInfoClient.java new file mode 100644 index 000000000..c9984018d --- /dev/null +++ b/base/common/src/org/dogtagpki/common/KRAInfoClient.java @@ -0,0 +1,48 @@ +//--- BEGIN COPYRIGHT BLOCK --- +//This program is free software; you can redistribute it and/or modify +//it under the terms of the GNU General Public License as published by +//the Free Software Foundation; version 2 of the License. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License along +//with this program; if not, write to the Free Software Foundation, Inc., +//51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +//(C) 2017 Red Hat, Inc. +//All rights reserved. +//--- END COPYRIGHT BLOCK --- + +package org.dogtagpki.common; + +import java.net.URISyntaxException; + +import javax.ws.rs.core.Response; + +import com.netscape.certsrv.client.Client; +import com.netscape.certsrv.client.PKIClient; + +/** + * @author Ade Lee + */ +public class KRAInfoClient extends Client { + + public KRAInfoResource resource; + + public KRAInfoClient(PKIClient client, String subsystem) throws URISyntaxException { + super(client, subsystem, "info"); + init(); + } + + public void init() throws URISyntaxException { + resource = createProxy(KRAInfoResource.class); + } + + public KRAInfo getInfo() throws Exception { + Response response = resource.getInfo(); + return client.getEntity(response, KRAInfo.class); + } +} diff --git a/base/common/src/org/dogtagpki/common/KRAInfoResource.java b/base/common/src/org/dogtagpki/common/KRAInfoResource.java new file mode 100644 index 000000000..540e3a68a --- /dev/null +++ b/base/common/src/org/dogtagpki/common/KRAInfoResource.java @@ -0,0 +1,40 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2017 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package org.dogtagpki.common; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +import org.jboss.resteasy.annotations.ClientResponseType; + +/** + * @author Ade Lee + */ +@Path("info") +public interface KRAInfoResource { + + String ENCRYPT_MECHANISM = "encrypt"; + String KEYWRAP_MECHANISM = "keywrap"; + + @GET + @ClientResponseType(entityType=KRAInfo.class) + public Response getInfo() throws Exception; +} + |
