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 java.util.Date;
021    
022    import javax.xml.bind.annotation.XmlRootElement;
023    
024    /**
025     * <p>
026     * {@link Response} implementation to send the currently active encryption key to the app-server.
027     * It is the response to a {@link GetActiveEncryptionKeyRequest}.
028     * </p>
029     *
030     * @author Marco หงุ่ยตระกูล-Schulze - marco at nightlabs dot de
031     * @see GetActiveEncryptionKeyRequest
032     */
033    @XmlRootElement
034    public class GetActiveEncryptionKeyResponse extends GetKeyResponse
035    {
036            private static final long serialVersionUID = 1L;
037    
038            private Date activeUntilExcl;
039    
040            /**
041             * Create an empty instance of <code>GetActiveEncryptionKeyResponse</code>.
042             * Only used for serialisation/deserialisation.
043             */
044            public GetActiveEncryptionKeyResponse() { }
045    
046            /**
047             * Create an instance of <code>GetActiveEncryptionKeyResponse</code> in order to reply the given <code>request</code>.
048             *
049             * @param request the request to be replied (an instance of {@link GetActiveEncryptionKeyRequest}).
050             * @param keyID the identifier of the key to be sent to the app-server.
051             * @param keyEncodedEncrypted the {@link KeyEncryptionUtil#encryptKey(byte[], org.cumulus4j.crypto.Cipher) encrypted} symmetric secret key.
052             * @param activeUntilExcl the timestamp until which this key should be used for encryption. As soon as this timestamp
053             * is reached, the app-server should again send a {@link GetActiveEncryptionKeyRequest} to the key-manager.
054             */
055            public GetActiveEncryptionKeyResponse(Request request, long keyID, byte[] keyEncodedEncrypted, Date activeUntilExcl)
056            {
057                    super(request, keyID, keyEncodedEncrypted);
058                    this.activeUntilExcl = activeUntilExcl;
059            }
060    
061            /**
062             * Get the moment in time until (excluding) which the key transported by this response should be used for encryption.
063             * After this timestamp (or more precisely when it is reached), the app-server should request it again.
064             * @return the moment in time until which the key transported by this response should be used for encryption.
065             * @see #setActiveUntilExcl(Date)
066             */
067            public Date getActiveUntilExcl() {
068                    return activeUntilExcl;
069            }
070            /**
071             * Set the moment in time until (excluding) which the key transported by this response should be used for encryption.
072             * @param activeUntilExcl the moment in time until which the key transported by this response should be used for encryption.
073             * @see #getActiveUntilExcl()
074             */
075            public void setActiveUntilExcl(Date activeUntilExcl) {
076                    this.activeUntilExcl = activeUntilExcl;
077            }
078    }