projects
/
libdcp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add Atmos read/write and untested MXF decryption tool.
[libdcp.git]
/
src
/
certificate.cc
diff --git
a/src/certificate.cc
b/src/certificate.cc
index 34f797545cad3cb379b0ef1219012d9f58105fe9..fbe3a80d2c2c9b6667f2085a704749d015df82f8 100644
(file)
--- a/
src/certificate.cc
+++ b/
src/certificate.cc
@@
-1,5
+1,5
@@
/*
/*
- Copyright (C) 2012-201
5
Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-201
6
Carl Hetherington <cth@carlh.net>
This file is part of libdcp.
This file is part of libdcp.
@@
-64,7
+64,6
@@
static string const end_certificate = "-----END CERTIFICATE-----";
Certificate::Certificate (X509* c)
: _certificate (c)
, _public_key (0)
Certificate::Certificate (X509* c)
: _certificate (c)
, _public_key (0)
- , _extra_data (false)
{
}
{
}
@@
-76,7
+75,10
@@
Certificate::Certificate (string cert)
: _certificate (0)
, _public_key (0)
{
: _certificate (0)
, _public_key (0)
{
- _extra_data = read_string (cert);
+ string const s = read_string (cert);
+ if (!s.empty ()) {
+ throw MiscError ("unexpected data after certificate");
+ }
}
/** Copy constructor.
}
/** Copy constructor.
@@
-85,7
+87,6
@@
Certificate::Certificate (string cert)
Certificate::Certificate (Certificate const & other)
: _certificate (0)
, _public_key (0)
Certificate::Certificate (Certificate const & other)
: _certificate (0)
, _public_key (0)
- , _extra_data (other._extra_data)
{
if (other._certificate) {
read_string (other.certificate (true));
{
if (other._certificate) {
read_string (other.certificate (true));
@@
-94,44
+95,65
@@
Certificate::Certificate (Certificate const & other)
/** Read a certificate from a string.
* @param cert String to read.
/** Read a certificate from a string.
* @param cert String to read.
- * @return
true if there is extra stuff after the end of the certificate, false if not
.
+ * @return
remaining part of the input string after the certificate which was read
.
*/
*/
-bool
+string
Certificate::read_string (string cert)
{
/* Reformat cert so that it has line breaks every 64 characters.
See http://comments.gmane.org/gmane.comp.encryption.openssl.user/55593
*/
Certificate::read_string (string cert)
{
/* Reformat cert so that it has line breaks every 64 characters.
See http://comments.gmane.org/gmane.comp.encryption.openssl.user/55593
*/
- l
ocked_stringstream s (cert)
;
+ l
ist<string> lines
;
string line;
string line;
- /* BEGIN */
- do {
- getline (s, line);
+ for (size_t i = 0; i < cert.length(); ++i) {
+ line += cert[i];
+ if (cert[i] == '\r' || cert[i] == '\n') {
+ boost::algorithm::trim (line);
+ lines.push_back (line);
+ line = "";
+ }
+ }
+
+ if (!line.empty()) {
boost::algorithm::trim (line);
boost::algorithm::trim (line);
- } while (s.good() && line != begin_certificate);
+ lines.push_back (line);
+ }
+
+ list<string>::iterator i = lines.begin ();
- if (line != begin_certificate) {
+ /* BEGIN */
+ while (i != lines.end() && *i != begin_certificate) {
+ ++i;
+ }
+
+ if (i == lines.end()) {
throw MiscError ("missing BEGIN line in certificate");
}
throw MiscError ("missing BEGIN line in certificate");
}
+ /* Skip over the BEGIN line */
+ ++i;
+
/* The base64 data */
bool got_end = false;
string base64 = "";
/* The base64 data */
bool got_end = false;
string base64 = "";
- while (getline (s, line)) {
- boost::algorithm::trim (line);
- if (line == end_certificate) {
+ while (i != lines.end()) {
+ if (*i == end_certificate) {
got_end = true;
break;
}
got_end = true;
break;
}
- base64 += line;
+ base64 += *i;
+ ++i;
}
if (!got_end) {
throw MiscError ("missing END line in certificate");
}
}
if (!got_end) {
throw MiscError ("missing END line in certificate");
}
+ /* Skip over the END line */
+ ++i;
+
/* Make up the fixed version */
string fixed = begin_certificate + "\n";
/* Make up the fixed version */
string fixed = begin_certificate + "\n";
@@
-155,12
+177,16
@@
Certificate::read_string (string cert)
BIO_free (bio);
BIO_free (bio);
- /* See if there are any non-blank lines after the certificate that we read */
- line.clear ();
- while (s.good() && line.empty()) {
- getline (s, line);
+ string extra;
+
+ while (i != lines.end()) {
+ if (!i->empty()) {
+ extra += *i + "\n";
+ }
+ ++i;
}
}
- return (s.good() && !line.empty());
+
+ return extra;
}
/** Destructor */
}
/** Destructor */
@@
-184,7
+210,6
@@
Certificate::operator= (Certificate const & other)
_certificate = 0;
RSA_free (_public_key);
_public_key = 0;
_certificate = 0;
RSA_free (_public_key);
_public_key = 0;
- _extra_data = other._extra_data;
read_string (other.certificate (true));
read_string (other.certificate (true));