OpenDNSSEC-enforcer  1.4.10
test_ksm_request.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2009 Nominet UK. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
19  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
21  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
23  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  */
26 
27 /*+
28  * Filename: test_ksm_parameter.c - Test Key Parameter Module
29  *
30  * Description:
31  * This is a short test module to check the functions in the Ksm Parameter
32  * module.
33  *
34  * The test program makes use of the CUnit framework, as described in
35  * http://cunit.sourceforge.net
36 -*/
37 
38 #include <stdlib.h>
39 #include <stdio.h>
40 #include <string.h>
41 #include <time.h>
42 
43 #include "CUnit/Basic.h"
44 
45 #include "ksm/ksm.h"
46 #include "ksm/datetime.h"
47 #include "test_routines.h"
48 
49 int l_keytype = -1;
50 int no_keys = 0;
51 
52 /*
53  * TestCallback Function
54  */
55 static int TestCallbackFn(void* context, KSM_KEYDATA* data)
56 {
57  fprintf(stderr, "\n");
58  fprintf(stderr, "\t\t\t<Key>\n");
59  fprintf(stderr, "\t\t\t\t<Flags>%d</Flags>\n", data->keytype);
60  fprintf(stderr, "\t\t\t\t<Algorithm>%d</Algorithm>\n", data->algorithm);
61  fprintf(stderr, "\t\t\t\t<Locator>%s</Locator>\n", data->location);
62  if (data->keytype == KSM_TYPE_KSK)
63  {
64  fprintf(stderr, "\t\t\t\t<KSK />\n");
65  }
66  else
67  {
68  fprintf(stderr, "\t\t\t\t<ZSK />\n");
69  }
70  fprintf(stderr, "\t\t\t\t<%s />\n", KsmKeywordStateValueToName(data->state));
71  fprintf(stderr, "\t\t\t</Key>\n");
72  fprintf(stderr, "\n");
73 
74  /*printf("%s %lu %d %d %s\n", KsmKeywordStateValueToName(data->state),
75  data->keypair_id, data->keytype, data->algorithm, data->location); */
76 
77  no_keys++;
78 
79  return 0;
80 }
81 
82 
83 /*+
84  * TestKsmRequestKeys - Test Request code
85  *
86  * Description:
87  * Tests that a parameter can be set
88 -*/
89 
90 static void TestKsmRequestKeys(void)
91 {
92  int keytype = 0; /*KSM_TYPE_ZSK;*/ /* Type of key */
93  int rollover = 0; /* Set 1 to roll over the current key */
94  int status = 0;
95  int zone_id = 1; /* opendnssec.org */
96  int newDS = 0;
97  int policy_id = 2;
98  int sm = 1; /* count over all security modules */
99  int bits = 1024; /* count over all sizes */
100  int algorithm = KSM_ALGORITHM_RSASHA1; /* count over all algorithms */
101  int keypair_id;
102  DB_ID dnsseckey_id;
103 
104  char* datetime = DtParseDateTimeString("now");
105 
106  /* Allocate a key to the zone (routines previously tested) */
107  status = KsmKeyGetUnallocated(policy_id, sm, bits, algorithm, zone_id, 1, &keypair_id);
108  CU_ASSERT_EQUAL(status, 0);
109 
110  status = KsmDnssecKeyCreate(zone_id, keypair_id, KSM_TYPE_ZSK,
111  KSM_STATE_GENERATE, 0, datetime, NULL, &dnsseckey_id);
112  CU_ASSERT_EQUAL(status, 0);
113 
114  /* push the key into some state that update can operate on */
115  status = KsmRequestChangeStateN( KSM_TYPE_ZSK, datetime, 1,
117 
118  CU_ASSERT_EQUAL(status, 0);
119 
120  /* Check that keys of a particular type can be requested */
121  KsmRequestKeys(keytype, rollover, datetime, TestCallbackFn, NULL, policy_id, zone_id, 0, &newDS);
122 
123  /*CU_ASSERT_EQUAL(status, 1);*/ /* just make sure that something flags this as needing more work */
124  CU_ASSERT_EQUAL(no_keys, 2);
125 
126  /* TODO work out some test scenarios here and use Callback to check */
127 }
128 
129 /*
130  * TestKsmRequest - Create Test Suite
131  *
132  * Description:
133  * Adds the test suite to the CUnit test registry and adds all the tests
134  * to it.
135  *
136  * Arguments:
137  * None.
138  *
139  * Returns:
140  * int
141  * Return status. 0 => Success.
142  */
143 
144 int TestKsmRequest(void); /* Declaration */
145 int TestKsmRequest(void)
146 {
147  struct test_testdef tests[] = {
148  {"KsmRequest", TestKsmRequestKeys},
149  {NULL, NULL}
150  };
151 
152  /* TODO
153  * have been a bit lazy here and reuse TdbSetup etc...
154  * this has the consequence of all the setups running for each suite
155  * if this gets too slow then we will need to separate them out
156  * */
157  return TcuCreateSuite("KsmRequest", TdbSetup, TdbTeardown, tests);
158 }
#define KSM_TYPE_ZSK
Definition: ksm.h:362
int KsmRequestChangeStateN(int keytype, const char *datetime, int count, int src_state, int dst_state, int zone_id)
Definition: ksm_request.c:1066
char location[KSM_NAME_LENGTH]
Definition: ksm.h:112
int l_keytype
int state
Definition: ksm.h:102
int TcuCreateSuite(const char *title, int(*init)(), int(*teardown)(), struct test_testdef *tests)
const char * KsmKeywordStateValueToName(int value)
Definition: ksm_keyword.c:242
char * DtParseDateTimeString(const char *string)
Definition: datetime.c:614
unsigned long DB_ID
Definition: database.h:78
#define KSM_ALGORITHM_RSASHA1
Definition: ksm.h:336
int TestKsmRequest(void)
int keytype
Definition: ksm.h:103
int algorithm
Definition: ksm.h:104
int TdbTeardown(void)
#define KSM_STATE_PUBLISH
Definition: ksm.h:369
int no_keys
int KsmKeyGetUnallocated(int policy_id, int sm, int bits, int algorithm, int zone_id, int share_keys, int *keypair_id)
Definition: ksm_key.c:881
int KsmDnssecKeyCreate(int zone_id, int keypair_id, int keytype, int state, int rfc5011, const char *time, const char *retTime, DB_ID *id)
Definition: ksm_key.c:141
int TdbSetup(void)
#define KSM_TYPE_KSK
Definition: ksm.h:360
int KsmRequestKeys(int keytype, int rollover, const char *datetime, KSM_REQUEST_CALLBACK callback, void *context, int policy_id, int zone_id, int run_interval, int *NewDS)
Definition: ksm_request.c:95
#define KSM_STATE_GENERATE
Definition: ksm.h:367