f7d21dbe412de2e0558eb77378c7617650206f03
[libdcp.git] / src / decrypted_kdm.h
1 /*
2     Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef LIBDCP_DECRYPTED_KDM_H
21 #define LIBDCP_DECRYPTED_KDM_H
22
23 /** @file  src/decrypted_kdm.h
24  *  @brief DecryptedKDM class.
25  */
26
27 #include "key.h"
28 #include "local_time.h"
29 #include "decrypted_kdm_key.h"
30 #include "types.h"
31 #include "certificate.h"
32 #include <boost/filesystem.hpp>
33
34 namespace dcp {
35
36 class DecryptedKDMKey;
37 class EncryptedKDM;
38 class CertificateChain;
39 class CPL;
40
41 /** @class DecryptedKDM
42  *  @brief A decrypted KDM.
43  *
44  *  This is a KDM that has either been decrypted by a target private key, or one which
45  *  has been created (by some other means) ready for encryption later.
46  *
47  *  A DecryptedKDM object can be created either from an EncryptedKDM and private key file,
48  *  or from the details of the assets that the KDM should protect.
49  */
50 class DecryptedKDM
51 {
52 public:
53         /** @param kdm Encrypted KDM.
54          *  @param private_key Private key as a PEM-format string.
55          */
56         DecryptedKDM (EncryptedKDM const & kdm, std::string private_key);
57
58         /** Create an empty DecryptedKDM.  After creation you must call
59          *  add_key() to add each key that you want in the KDM.
60          *
61          *  @param not_valid_before Start time for the KDM.
62          *  @param not_valid_after End time for the KDM.
63          */
64         DecryptedKDM (
65                 LocalTime not_valid_before,
66                 LocalTime not_valid_after,
67                 std::string annotation_text,
68                 std::string content_title_text,
69                 std::string issue_date
70                 );
71
72         /** Create a DecryptedKDM by taking a CPL and setting up to encrypt each of its
73          *  assets with the same symmetric key.
74          *
75          *  @param cpl CPL that the keys are for.
76          *  @param key Key that was used to encrypt the assets.
77          *  @param not_valid_before Start time for the KDM.
78          *  @param not_valid_after End time for the KDM.
79          */
80         DecryptedKDM (
81                 boost::shared_ptr<const CPL> cpl,
82                 Key key,
83                 LocalTime not_valid_before,
84                 LocalTime not_valid_after,
85                 std::string annotation_text,
86                 std::string content_title_text,
87                 std::string issue_date
88                 );
89
90         /** Encrypt this KDM's keys and sign the whole KDM.
91          *  @param signer Chain to sign with.
92          *  @param recipient Certificate of the projector/server which should receive this KDM's keys.
93          *  @param trusted_devices Extra trusted devices which should be written to the KDM (recipient will be written
94          *  as a trusted device automatically and does not need to be included in this list).
95          *  @param formulation Formulation to use for the encrypted KDM.
96          *  @return Encrypted KDM.
97          */
98         EncryptedKDM encrypt (
99                 boost::shared_ptr<const CertificateChain> signer,
100                 Certificate recipient,
101                 std::vector<Certificate> trusted_devices,
102                 Formulation formulation
103                 ) const;
104
105         void add_key (std::string type, std::string key_id, Key key, std::string cpl_id);
106         void add_key (DecryptedKDMKey key);
107
108         /** @return This KDM's (decrypted) keys, which could be used to decrypt assets. */
109         std::list<DecryptedKDMKey> keys () const {
110                 return _keys;
111         }
112
113         std::string annotation_text () const {
114                 return _annotation_text;
115         }
116
117         std::string content_title_text () const {
118                 return _content_title_text;
119         }
120
121         std::string issue_date () const {
122                 return _issue_date;
123         }
124
125 private:
126         LocalTime _not_valid_before;
127         LocalTime _not_valid_after;
128         std::string _annotation_text;
129         std::string _content_title_text;
130         std::string _issue_date;
131         std::list<DecryptedKDMKey> _keys;
132 };
133
134 }
135
136 #endif