summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/certsrv/dbs/keydb
diff options
context:
space:
mode:
Diffstat (limited to 'base/common/src/com/netscape/certsrv/dbs/keydb')
-rw-r--r--base/common/src/com/netscape/certsrv/dbs/keydb/IKeyRecord.java153
-rw-r--r--base/common/src/com/netscape/certsrv/dbs/keydb/IKeyRecordList.java49
-rw-r--r--base/common/src/com/netscape/certsrv/dbs/keydb/IKeyRepository.java174
-rw-r--r--base/common/src/com/netscape/certsrv/dbs/keydb/KeyId.java122
-rw-r--r--base/common/src/com/netscape/certsrv/dbs/keydb/KeyIdAdapter.java37
-rw-r--r--base/common/src/com/netscape/certsrv/dbs/keydb/KeyState.java106
6 files changed, 641 insertions, 0 deletions
diff --git a/base/common/src/com/netscape/certsrv/dbs/keydb/IKeyRecord.java b/base/common/src/com/netscape/certsrv/dbs/keydb/IKeyRecord.java
new file mode 100644
index 000000000..7da212469
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/dbs/keydb/IKeyRecord.java
@@ -0,0 +1,153 @@
+// --- 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) 2007 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package com.netscape.certsrv.dbs.keydb;
+
+import java.math.BigInteger;
+import java.util.Date;
+
+import com.netscape.certsrv.base.EBaseException;
+
+/**
+ * An interface contains constants for key record.
+ *
+ * @version $Revision$, $Date$
+ */
+public interface IKeyRecord {
+ public static final String ATTR_ID = "keySerialNumber";
+ public static final String ATTR_STATE = "keyState";
+ public static final String ATTR_ALGORITHM = "algorithm";
+ public static final String ATTR_KEY_SIZE = "keySize";
+ public static final String ATTR_OWNER_NAME = "keyOwnerName";
+ public static final String ATTR_PRIVATE_KEY_DATA = "privateKey";
+ public static final String ATTR_PUBLIC_KEY_DATA = "publicKey";
+ public static final String ATTR_DATE_OF_RECOVERY = "dateOfRecovery";
+ public static final String ATTR_CREATE_TIME = "keyCreateTime";
+ public static final String ATTR_MODIFY_TIME = "keyModifyTime";
+ public static final String ATTR_META_INFO = "keyMetaInfo";
+ public static final String ATTR_ARCHIVED_BY = "keyArchivedBy";
+ public static final String ATTR_CLIENT_ID = "clientId";
+ public static final String ATTR_DATA_TYPE = "dataType";
+ public static final String ATTR_STATUS = "status";
+
+
+ // key state
+ public static final String STATUS_ANY = "ANY";
+ public static final String STATUS_VALID = "VALID";
+ public static final String STATUS_INVALID = "INVALID";
+
+ /**
+ * Retrieves the state of the key.
+ *
+ * @return key state
+ * @exception EBaseException failed to retrieve state of the key
+ */
+ public KeyState getState() throws EBaseException;
+
+ /**
+ * Retrieves key identifier.
+ *
+ * @return key id
+ * @exception EBaseException failed to retrieve key id
+ */
+ public BigInteger getSerialNumber() throws EBaseException;
+
+ /**
+ * Retrieves key owner name.
+ *
+ * @return key owner name
+ * @exception EBaseException failed to retrieve key owner name
+ */
+ public String getOwnerName() throws EBaseException;
+
+ /**
+ * Retrieves key algorithm.
+ *
+ * @return key algorithm
+ */
+ public String getAlgorithm();
+
+ /**
+ * Retrieves key length.
+ *
+ * @return key length
+ * @exception EBaseException failed to retrieve key length
+ */
+ public Integer getKeySize() throws EBaseException;
+
+ /**
+ * Retrieves client ID.
+ *
+ * @return client id
+ * @exception EBaseException failed to retrieve client id
+ */
+ public String getClientId() throws EBaseException;
+
+ /**
+ * Retrieves key data type.
+ *
+ * @return data type
+ * @exception EBaseException failed to retrieve data type
+ */
+ public String getDataType() throws EBaseException;
+
+ /**
+ * Retrieves key status.
+ *
+ * @return key status
+ * @exception EBaseException failed to retrieve key status
+ */
+ public String getKeyStatus() throws EBaseException;
+
+ /**
+ * Retrieves archiver identifier.
+ *
+ * @return archiver uid
+ */
+
+ public String getArchivedBy();
+
+ /**
+ * Retrieves creation time.
+ *
+ * @return creation time
+ */
+ public Date getCreateTime();
+
+ /**
+ * Retrieves last modification time.
+ *
+ * @return modification time
+ */
+ public Date getModifyTime();
+
+ /**
+ * Retrieves dates of recovery.
+ *
+ * @return recovery history
+ * @exception EBaseException failed to retrieve recovery history
+ */
+ public Date[] getDateOfRevocation() throws EBaseException;
+
+ /**
+ * Retrieves public key data.
+ *
+ * @return public key data
+ * @exception EBaseException failed to retrieve public key data
+ */
+ public byte[] getPublicKeyData() throws EBaseException;
+}
diff --git a/base/common/src/com/netscape/certsrv/dbs/keydb/IKeyRecordList.java b/base/common/src/com/netscape/certsrv/dbs/keydb/IKeyRecordList.java
new file mode 100644
index 000000000..75f833892
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/dbs/keydb/IKeyRecordList.java
@@ -0,0 +1,49 @@
+// --- 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) 2007 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package com.netscape.certsrv.dbs.keydb;
+
+import java.util.Enumeration;
+
+import com.netscape.certsrv.base.EBaseException;
+
+/**
+ * A class represents a list of key records.
+ * <P>
+ *
+ * @version $Revision$, $Date$
+ */
+public interface IKeyRecordList {
+
+ /**
+ * Retrieves the size of key list.
+ *
+ * @return size of key list
+ */
+ public int getSize();
+
+ /**
+ * Retrieves key records.
+ *
+ * @param startidx start index
+ * @param endidx end index
+ * @return key records
+ * @exception EBaseException failed to retrieve key records
+ */
+ public Enumeration<IKeyRecord> getKeyRecords(int startidx, int endidx)
+ throws EBaseException;
+}
diff --git a/base/common/src/com/netscape/certsrv/dbs/keydb/IKeyRepository.java b/base/common/src/com/netscape/certsrv/dbs/keydb/IKeyRepository.java
new file mode 100644
index 000000000..627844286
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/dbs/keydb/IKeyRepository.java
@@ -0,0 +1,174 @@
+// --- 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) 2007 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package com.netscape.certsrv.dbs.keydb;
+
+import java.math.BigInteger;
+import java.security.PublicKey;
+import java.util.Enumeration;
+
+import netscape.security.x509.X500Name;
+
+import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.dbs.ModificationSet;
+import com.netscape.certsrv.dbs.repository.IRepository;
+
+/**
+ * An interface represents a Key repository. This is the
+ * container of archived keys.
+ * <P>
+ *
+ * @version $Revision$, $Date$
+ */
+public interface IKeyRepository extends IRepository {
+
+ /**
+ * Archives a key to the repository.
+ * <P>
+ *
+ * @param record key record
+ * @exception EBaseException failed to archive key
+ */
+ public void addKeyRecord(IKeyRecord record) throws EBaseException;
+
+ /**
+ * Reads an archived key by serial number.
+ * <P>
+ *
+ * @param serialNo serial number
+ * @return key record
+ * @exception EBaseException failed to recover key
+ */
+ public IKeyRecord readKeyRecord(BigInteger serialNo)
+ throws EBaseException;
+
+ /**
+ * Reads an archived key by b64 encoded cert.
+ * <P>
+ *
+ * @param cert b64 encoded cert
+ * @return key record
+ * @exception EBaseException failed to recover key
+ */
+ public IKeyRecord readKeyRecord(String cert)
+ throws EBaseException;
+
+ /**
+ * Reads an archived key by owner name.
+ * <P>
+ *
+ * @param ownerName owner name
+ * @return key record
+ * @exception EBaseException failed to recover key
+ */
+ public IKeyRecord readKeyRecord(X500Name ownerName)
+ throws EBaseException;
+
+ /**
+ * Reads archived key using public key.
+ *
+ * @param publicKey public key that is corresponding
+ * to the private key
+ * @return key record
+ * @exception EBaseException failed to read key
+ */
+ public IKeyRecord readKeyRecord(PublicKey publicKey)
+ throws EBaseException;
+
+ /**
+ * Searches for private keys.
+ *
+ * @param filter LDAP filter for the search
+ * @param maxSize maximium number of entries to be returned
+ * @return a list of private key records
+ * @exception EBaseException failed to search keys
+ */
+ public Enumeration<IKeyRecord> searchKeys(String filter, int maxSize)
+ throws EBaseException;
+
+ /**
+ * Searches for private keys.
+ *
+ * @param filter LDAP filter for the search
+ * @param maxSize maximium number of entries to be returned
+ * @param timeLimt timeout value
+ * @return a list of private key records
+ * @exception EBaseException failed to search keys
+ */
+ public Enumeration<IKeyRecord> searchKeys(String filter, int maxSize, int timeLimt)
+ throws EBaseException;
+
+ /**
+ * Deletes a key record.
+ *
+ * @param serialno key identifier
+ * @exception EBaseException failed to delete key record
+ */
+ public void deleteKeyRecord(BigInteger serialno)
+ throws EBaseException;
+
+ /**
+ * Modifies key record in this repository.
+ *
+ * @param serialNo key identifier
+ * @param mods modification of key records
+ * @exception EBaseException failed to modify key record
+ */
+ public void modifyKeyRecord(BigInteger serialNo,
+ ModificationSet mods) throws EBaseException;
+
+ /**
+ * Searchs for a list of key records.
+ * Here is a list of supported filter attributes:
+ *
+ * <pre>
+ * keySerialNumber
+ * keyState
+ * algorithm
+ * keySize
+ * keyOwnerName
+ * privateKey
+ * publicKey
+ * dateOfRecovery
+ * keyCreateTime
+ * keyModifyTime
+ * keyMetaInfo
+ * </pre>
+ *
+ * @param filter search filter
+ * @param attrs list of attributes to be returned
+ * @param pageSize virtual list page size
+ * @return list of key records
+ * @exception EBaseException failed to search key records
+ */
+ public IKeyRecordList findKeyRecordsInList(String filter,
+ String attrs[], int pageSize) throws EBaseException;
+
+ /**
+ * Searchs for a list of key records.
+ *
+ * @param filter search filter
+ * @param attrs list of attributes to be returned
+ * @param sortKey name of attribute that the list should be sorted by
+ * @param pageSize virtual list page size
+ * @return list of key records
+ * @exception EBaseException failed to search key records
+ */
+ public IKeyRecordList findKeyRecordsInList(String filter,
+ String attrs[], String sortKey, int pageSize)
+ throws EBaseException;
+}
diff --git a/base/common/src/com/netscape/certsrv/dbs/keydb/KeyId.java b/base/common/src/com/netscape/certsrv/dbs/keydb/KeyId.java
new file mode 100644
index 000000000..f998bf97a
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/dbs/keydb/KeyId.java
@@ -0,0 +1,122 @@
+// --- 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) 2007 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package com.netscape.certsrv.dbs.keydb;
+
+import java.math.BigInteger;
+
+/**
+ * The KeyId class represents the identifier for a particular
+ * key record. This identifier may be used to retrieve the key record
+ * from the database.
+ * <p>
+ *
+ * @author Endi S. Dewata
+ * @version $Revision$ $Date$
+ */
+public class KeyId {
+
+ protected BigInteger value;
+
+ /**
+ * Creates a new KeyId from its string representation.
+ * <p>
+ *
+ * @param id
+ * a string containing the decimal or hex value for the identifier.
+ */
+ public KeyId(String id) {
+ if (id != null) {
+ id = id.trim();
+ if (id.startsWith("0x")) { // hex
+ value = new BigInteger(id.substring(2), 16);
+ } else { // decimal
+ value = new BigInteger(id);
+ }
+ }
+ }
+
+ /**
+ * Creates a new KeyId from its BigInteger representation.
+ * <p>
+ *
+ * @param id
+ * a BigInteger containing the identifier.
+ */
+ public KeyId(BigInteger id) {
+ value = id;
+ }
+
+ /**
+ * Creates a new KeyId from its integer representation.
+ * <p>
+ *
+ * @param id
+ * an integer containing the identifier.
+ */
+ public KeyId(int id) {
+ value = BigInteger.valueOf(id);
+ }
+
+ /**
+ * Converts the KeyId into its BigInteger representation.
+ * <p>
+ *
+ * @return
+ * a BigInteger containing the identifier.
+ */
+ public BigInteger toBigInteger() {
+ return value;
+ }
+
+ /**
+ * Converts the KeyId into its string representation. The string
+ * form can be stored in a database (such as the LDAP directory)
+ * <p>
+ *
+ * @return
+ * a string containing the decimal (base 10) value for the identifier.
+ */
+ public String toString() {
+ return value.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((value == null) ? 0 : value.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ KeyId other = (KeyId) obj;
+ if (value == null) {
+ if (other.value != null)
+ return false;
+ } else if (!value.equals(other.value))
+ return false;
+ return true;
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/dbs/keydb/KeyIdAdapter.java b/base/common/src/com/netscape/certsrv/dbs/keydb/KeyIdAdapter.java
new file mode 100644
index 000000000..3232999fd
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/dbs/keydb/KeyIdAdapter.java
@@ -0,0 +1,37 @@
+// --- 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) 2007 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package com.netscape.certsrv.dbs.keydb;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+/**
+ * The KeyIdAdapter class provides custom marshaling for KeyId.
+ *
+ * @author Endi S. Dewata
+ * @version $Revision$ $Date$
+ */
+public class KeyIdAdapter extends XmlAdapter<String, KeyId> {
+
+ public KeyId unmarshal(String value) throws Exception {
+ return new KeyId(value);
+ }
+
+ public String marshal(KeyId value) throws Exception {
+ return value.toString();
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/dbs/keydb/KeyState.java b/base/common/src/com/netscape/certsrv/dbs/keydb/KeyState.java
new file mode 100644
index 000000000..fa8a0d768
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/dbs/keydb/KeyState.java
@@ -0,0 +1,106 @@
+// --- 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) 2007 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package com.netscape.certsrv.dbs.keydb;
+
+import java.io.Serializable;
+
+/**
+ * A class represents key state. This object is to
+ * encapsulate the life cycle of a key.
+ * <P>
+ *
+ * @version $Revision$, $Date$
+ */
+public final class KeyState implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 5452723730414730579L;
+ private int mStateCode;
+
+ /**
+ * Constructs a key state.
+ */
+ private KeyState(int code) {
+ mStateCode = code;
+ }
+
+ /**
+ * Request state.
+ */
+ public final static KeyState ANY = new KeyState(-1);
+ public final static KeyState VALID = new KeyState(0);
+ public final static KeyState INVALID = new KeyState(1);
+
+ /**
+ * Checks if the given object equals to this object.
+ *
+ * @param other object to be compared
+ * @return true if both objects are the same
+ */
+ public boolean equals(Object other) {
+ if (this == other)
+ return true;
+ else if (other instanceof KeyState)
+ return ((KeyState) other).mStateCode == mStateCode;
+ else
+ return false;
+ }
+
+ /**
+ * Returns the hash code.
+ *
+ * @return hash code
+ */
+ public int hashCode() {
+ return mStateCode;
+ }
+
+ /**
+ * Return the string-representation of this object.
+ *
+ * @return string value
+ */
+ public String toString() {
+ if (mStateCode == -1)
+ return "ANY";
+ if (mStateCode == 0)
+ return "VALID";
+ if (mStateCode == 1)
+ return "INVAILD";
+ return "[UNDEFINED]";
+
+ }
+
+ /**
+ * Converts a string into a key state object.
+ *
+ * @param state state in string-representation
+ * @return key state object
+ */
+ public static KeyState toKeyState(String state) {
+ if (state.equalsIgnoreCase("ANY"))
+ return ANY;
+ if (state.equalsIgnoreCase("VALID"))
+ return VALID;
+ if (state.equalsIgnoreCase("INVALID"))
+ return INVALID;
+ return null;
+ }
+}