001 /*
002 * Cumulus4j - Securing your data in the cloud - http://cumulus4j.org
003 * Copyright (C) 2011 NightLabs Consulting GmbH
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program. If not, see <http://www.gnu.org/licenses/>.
017 */
018 package org.cumulus4j.keymanager.back.shared;
019
020 import javax.xml.bind.annotation.XmlRootElement;
021
022 /**
023 * <p>
024 * {@link Response} implementation to send a specific symmetric secret key to the app-server.
025 * It is the response to a {@link GetKeyRequest}.
026 * </p>
027 *
028 * @author Marco หงุ่ยตระกูล-Schulze - marco at nightlabs dot de
029 * @see GetKeyRequest
030 */
031 @XmlRootElement
032 public class GetKeyResponse extends Response
033 {
034 private static final long serialVersionUID = 1L;
035
036 private long keyID;
037 private byte[] keyEncodedEncrypted;
038
039 /**
040 * Create an empty instance of <code>GetKeyResponse</code>.
041 * Only used for serialisation/deserialisation.
042 */
043 public GetKeyResponse() { }
044
045 /**
046 * Create an instance of <code>GetKeyResponse</code> in order to reply the given <code>request</code>.
047 *
048 * @param request the request to be replied (an instance of {@link GetActiveEncryptionKeyRequest}).
049 * @param keyID the identifier of the key to be sent to the app-server.
050 * @param keyEncodedEncrypted the {@link KeyEncryptionUtil#encryptKey(byte[], org.cumulus4j.crypto.Cipher) encrypted} symmetric secret key.
051 */
052 public GetKeyResponse(Request request, long keyID, byte[] keyEncodedEncrypted) {
053 super(request);
054
055 if (keyEncodedEncrypted == null)
056 throw new IllegalArgumentException("keyEncodedEncrypted == null");
057
058 this.keyID = keyID;
059 this.keyEncodedEncrypted = keyEncodedEncrypted;
060 }
061
062 /**
063 * Get the identifier of the symmetric secret key transported by this response.
064 * @return the identifier of the symmetric secret key transported by this response.
065 * @see #setKeyID(long)
066 */
067 public long getKeyID() {
068 return keyID;
069 }
070 /**
071 * Set the identifier of the symmetric secret key transported by this response.
072 * @param keyID the identifier of the symmetric secret key transported by this response.
073 * @see #getKeyID()
074 */
075 public void setKeyID(long keyID) {
076 this.keyID = keyID;
077 }
078
079 /**
080 * Get the {@link KeyEncryptionUtil#encryptKey(byte[], org.cumulus4j.crypto.Cipher) encrypted} symmetric secret key.
081 * @return the {@link KeyEncryptionUtil#encryptKey(byte[], org.cumulus4j.crypto.Cipher) encrypted} symmetric secret key.
082 * @see #setKeyEncodedEncrypted(byte[])
083 */
084 public byte[] getKeyEncodedEncrypted() {
085 return keyEncodedEncrypted;
086 }
087 /**
088 * Set the {@link KeyEncryptionUtil#encryptKey(byte[], org.cumulus4j.crypto.Cipher) encrypted} symmetric secret key.
089 * @param key the {@link KeyEncryptionUtil#encryptKey(byte[], org.cumulus4j.crypto.Cipher) encrypted} symmetric secret key.
090 * @see #getKeyEncodedEncrypted()
091 */
092 public void setKeyEncodedEncrypted(byte[] key) {
093 this.keyEncodedEncrypted = key;
094 }
095 }