summaryrefslogtreecommitdiff
path: root/trust/tests/test-data.c
blob: 1decf2e94b487b20052e0dc77efac8a6ea87044e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * Copyright (c) 2012 Red Hat Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *     * Redistributions of source code must retain the above
 *       copyright notice, this list of conditions and the
 *       following disclaimer.
 *     * Redistributions in binary form must reproduce the
 *       above copyright notice, this list of conditions and
 *       the following disclaimer in the documentation and/or
 *       other materials provided with the distribution.
 *     * The names of contributors to this software may not be
 *       used to endorse or promote products derived from this
 *       software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * Author: Stef Walter <stefw@gnome.org>
 */

#include "config.h"
#include "CuTest.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "attrs.h"
#include "test-data.h"

void
test_check_object (CuTest *cu,
                   CK_ATTRIBUTE *attrs,
                   CK_OBJECT_CLASS klass,
                   const char *label)
{
	CK_BBOOL val;
	CK_ULONG ulong;
	CK_ATTRIBUTE *attr;

	if (!p11_attrs_find_bool (attrs, CKA_TOKEN, &val))
		CuFail (cu, "missing CKA_TOKEN");
	CuAssertIntEquals (cu, CK_TRUE, val);

	if (!p11_attrs_find_bool (attrs, CKA_PRIVATE, &val))
		CuFail (cu, "missing CKA_PRIVATE");
	CuAssertIntEquals (cu, CK_FALSE, val);

	if (!p11_attrs_find_bool (attrs, CKA_MODIFIABLE, &val))
		CuFail (cu, "missing CKA_MODIFIABLE");
	CuAssertIntEquals (cu, CK_FALSE, val);

	if (!p11_attrs_find_ulong (attrs, CKA_CLASS, &ulong))
		CuFail (cu, "missing CKA_CLASS");
	CuAssertIntEquals (cu, klass, ulong);

	if (label) {
		attr = p11_attrs_find_valid (attrs, CKA_LABEL);
		CuAssertPtrNotNull (cu, attr);
		CuAssertTrue (cu, p11_attr_match_value (attr, label, -1));
	}
}

void
test_check_cacert3_ca (CuTest *cu,
                      CK_ATTRIBUTE *attrs,
                      const char *label)
{
	CK_ATTRIBUTE *attr;
	CK_ULONG ulong;

	test_check_object (cu, attrs, CKO_CERTIFICATE, label);

	if (!p11_attrs_find_ulong (attrs, CKA_CERTIFICATE_TYPE, &ulong))
		CuFail (cu, "missing CKA_CERTIFICATE_TYPE");
	CuAssertIntEquals (cu, CKC_X_509, ulong);

	/* TODO: Implement */
	if (!p11_attrs_find_ulong (attrs, CKA_CERTIFICATE_CATEGORY, &ulong))
		CuFail (cu, "missing CKA_CERTIFICATE_CATEGORY");
	CuAssertIntEquals (cu, 0, ulong);

	attr = p11_attrs_find (attrs, CKA_VALUE);
	CuAssertPtrNotNull (cu, attr);
	CuAssertTrue (cu, p11_attr_match_value (attr, test_cacert3_ca_der,
	                                        sizeof (test_cacert3_ca_der)));

	attr = p11_attrs_find_valid (attrs, CKA_CHECK_VALUE);
	CuAssertPtrNotNull (cu, attr);
	CuAssertTrue (cu, p11_attr_match_value (attr, "\xad\x7c\x3f", 3));

	attr = p11_attrs_find (attrs, CKA_START_DATE);
	CuAssertPtrNotNull (cu, attr);
	CuAssertTrue (cu, p11_attr_match_value (attr, "20110523", -1));

	attr = p11_attrs_find_valid (attrs, CKA_END_DATE);
	CuAssertPtrNotNull (cu, attr);
	CuAssertTrue (cu, p11_attr_match_value (attr, "20210520", -1));

	attr = p11_attrs_find (attrs, CKA_SUBJECT);
	CuAssertPtrNotNull (cu, attr);
	CuAssertTrue (cu, p11_attr_match_value (attr, test_cacert3_ca_subject,
	                                        sizeof (test_cacert3_ca_subject)));

	attr = p11_attrs_find (attrs, CKA_ISSUER);
	CuAssertPtrNotNull (cu, attr);
	CuAssertTrue (cu, p11_attr_match_value (attr, test_cacert3_ca_issuer,
	                                        sizeof (test_cacert3_ca_issuer)));

	attr = p11_attrs_find (attrs, CKA_SERIAL_NUMBER);
	CuAssertPtrNotNull (cu, attr);
	CuAssertTrue (cu, p11_attr_match_value (attr, test_cacert3_ca_serial,
	                                        sizeof (test_cacert3_ca_serial)));
}