Improve certificate handling a bit and fix up tests.
[libdcp.git] / test / certificates_test.cc
1 /*
2     Copyright (C) 2012 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 BOOST_AUTO_TEST_CASE (certificates)
21 {
22         libdcp::CertificateChain c;
23
24         c.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate ("test/ref/crypt/ca.self-signed.pem")));
25         c.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate ("test/ref/crypt/intermediate.signed.pem")));
26         c.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate ("test/ref/crypt/leaf.signed.pem")));
27
28         list<shared_ptr<libdcp::Certificate> > leaf_to_root = c.leaf_to_root ();
29
30         list<shared_ptr<libdcp::Certificate> >::iterator i = leaf_to_root.begin ();
31
32         /* Leaf */
33         BOOST_CHECK_EQUAL (*i, c.leaf ());
34         
35         BOOST_CHECK_EQUAL (
36                 c.leaf()->issuer(),
37                 "dnQualifier=bmtwThq3srgxIAeRMjX6BFhgLDw=,CN=.smpte-430-2.INTERMEDIATE.NOT_FOR_PRODUCTION,OU=example.org,O=example.org"
38                 );
39
40         BOOST_CHECK_EQUAL (
41                 c.leaf()->subject(),
42                 "dnQualifier=d95fGDzERNdxfYPgphvAR8A18L4=,CN=CS.smpte-430-2.LEAF.NOT_FOR_PRODUCTION,OU=example.org,O=example.org"
43                 );
44         
45         ++i;
46
47         /* Intermediate */
48         BOOST_CHECK_EQUAL (
49                 (*i)->issuer(),
50                 "dnQualifier=ndND9A/cODo2rTdrbLVmfQnoaSc=,CN=.smpte-430-2.ROOT.NOT_FOR_PRODUCTION,OU=example.org,O=example.org"
51                 );
52
53         BOOST_CHECK_EQUAL (
54                 (*i)->subject(),
55                 "dnQualifier=bmtwThq3srgxIAeRMjX6BFhgLDw=,CN=.smpte-430-2.INTERMEDIATE.NOT_FOR_PRODUCTION,OU=example.org,O=example.org"
56                 );
57         
58         ++i;
59
60         /* Root */
61         BOOST_CHECK_EQUAL (*i, c.root ());
62         BOOST_CHECK_EQUAL (
63                 c.root()->issuer(),
64                 "dnQualifier=ndND9A/cODo2rTdrbLVmfQnoaSc=,CN=.smpte-430-2.ROOT.NOT_FOR_PRODUCTION,OU=example.org,O=example.org"
65                 );
66
67         BOOST_CHECK_EQUAL (c.root()->serial(), "5");
68
69         BOOST_CHECK_EQUAL (
70                 c.root()->subject(),
71                 "dnQualifier=ndND9A/cODo2rTdrbLVmfQnoaSc=,CN=.smpte-430-2.ROOT.NOT_FOR_PRODUCTION,OU=example.org,O=example.org"
72                 );
73
74 }