2 Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
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.
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.
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.
20 #include "dolby_doremi_certificate_panel.h"
21 #include "download_certificate_dialog.h"
23 #include "lib/compose.hpp"
25 #include "lib/signal_manager.h"
26 #include "lib/internet.h"
27 #include <dcp/raw_convert.h>
28 #include <curl/curl.h>
30 #include <boost/foreach.hpp>
36 using boost::function;
37 using boost::optional;
39 DolbyDoremiCertificatePanel::DolbyDoremiCertificatePanel (wxWindow* parent, DownloadCertificateDialog* dialog)
40 : DownloadCertificatePanel (parent, dialog)
42 add_label_to_sizer (_table, this, _("Serial number"), true);
43 _serial = new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, wxSize (300, -1));
44 _table->Add (_serial, 1, wxEXPAND);
46 _serial->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&DownloadCertificateDialog::setup_sensitivity, _dialog));
52 DolbyDoremiCertificatePanel::download (wxStaticText* message)
54 message->SetLabel (_("Downloading certificate"));
56 /* Hack: without this the SetLabel() above has no visible effect */
59 signal_manager->when_idle (boost::bind (&DolbyDoremiCertificatePanel::finish_download, this, wx_to_std (_serial->GetValue ()), message));
63 DolbyDoremiCertificatePanel::finish_download (string serial, wxStaticText* message)
65 /* Try dcp2000, imb and ims prefixes (see mantis #375) */
67 string const prefix = "ftp://anonymous@ftp.cinema.dolby.com/Certificates/";
71 urls.push_back (String::compose ("%1%2xxx/dcp2000-%3.dcicerts.zip", prefix, serial.substr(0, 3), serial));
72 files.push_back (String::compose ("dcp2000-%1.cert.sha256.pem", serial));
74 urls.push_back (String::compose ("%1%2xxx/dcp2000-%3.dcicerts.zip", prefix, serial.substr(0, 3), serial));
75 files.push_back (String::compose ("dcp2000-%1.cert.sha256.pem", serial));
77 urls.push_back (String::compose ("%1%2xxx/dcp2000-%3.certs.zip", prefix, serial.substr(0, 3), serial));
78 files.push_back (String::compose ("dcp2000-%1.cert.sha256.pem", serial));
80 urls.push_back (String::compose ("%1%2xxx/imb-%3.dcicerts.zip", prefix, serial.substr(0, 3), serial));
81 files.push_back (String::compose ("imb-%1.cert.sha256.pem", serial));
83 urls.push_back (String::compose ("%1%2xxx/ims-%3.dcicerts.zip", prefix, serial.substr(0, 3), serial));
84 files.push_back (String::compose ("ims-%1.cert.sha256.pem", serial));
86 int const serial_int = dcp::raw_convert<int> (serial);
89 if (serial_int <= 510999) {
90 cat862 = "CAT862_510999_and_lower";
91 } else if (serial_int >= 617000) {
92 cat862 = "CAT862_617000_and_higher";
94 int const lower = serial_int - (serial_int % 1000);
95 cat862 = String::compose ("CAT862_%1-%2", lower, lower + 999);
98 urls.push_back (String::compose ("%1%2/cert_Dolby256-CAT862-%3.zip", prefix, cat862, serial_int));
99 files.push_back (String::compose ("cert_Dolby256-CAT862-%1.pem.crt", serial_int));
102 if (serial_int <= 999) {
103 dsp100 = "DSP100_053_thru_999";
104 } else if (serial_int >= 3000) {
105 dsp100 = "DSP100_3000_and_higher";
107 int const lower = serial_int - (serial_int % 1000);
108 dsp100 = String::compose ("DSP100_%1_thru_%2", lower, lower + 999);
111 urls.push_back (String::compose ("%1%2/cert_Dolby256-DSP100-%3.zip", prefix, dsp100, serial_int));
112 files.push_back (String::compose ("cert_Dolby256-DSP100-%1.pem.crt", serial_int));
116 list<string>::const_iterator i = urls.begin ();
117 list<string>::const_iterator j = files.begin ();
118 while (!ok && i != urls.end ()) {
119 optional<string> error = get_from_zip_url (*i++, *j++, true, boost::bind (&DownloadCertificatePanel::load, this, _1));
121 errors.push_back (error.get ());
128 message->SetLabel (_("Certificate downloaded"));
129 _dialog->setup_sensitivity ();
131 message->SetLabel (wxT (""));
134 BOOST_FOREACH (string e, errors) {
138 error_dialog (this, std_to_wx (s.str ()));
143 DolbyDoremiCertificatePanel::ready_to_download () const
145 return !_serial->IsEmpty ();