2 * Copyright (C) 2011 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include "attest_db.h"
19 #include "pts/components/pts_comp_func_name.h"
21 typedef struct private_attest_db_t private_attest_db_t
;
24 * Private data of an attest_db_t object.
26 struct private_attest_db_t
{
29 * Public members of attest_db_state_t
34 * Component Functional Name to be queried
36 pts_comp_func_name_t
*cfn
;
39 * Primary key of the Component Functional Name to be queried
44 * TRUE if Component Functional Name has been set
49 * Directory containing the Measurement file to be queried
54 * Primary key of the directory to be queried
59 * TRUE if directory has been set
64 * Measurement file to be queried
69 * Primary key of measurement file to be queried
74 * TRUE if file has been set
84 * Primary key of the AIK to be queried
89 * TRUE if AIK has been set
94 * Software product to be queried
99 * Primary key of software product to be queried
104 * TRUE if product has been set
109 * File measurement hash algorithm
111 pts_meas_algorithms_t algo
;
114 * Optional owner (user/host name)
119 * Attestation database
125 char* print_cfn(pts_comp_func_name_t
*cfn
)
127 static char buf
[BUF_LEN
];
129 int type
, vid
, name
, qualifier
, n
;
130 enum_name_t
*names
, *types
;
132 vid
= cfn
->get_vendor_id(cfn
),
133 name
= cfn
->get_name(cfn
);
134 qualifier
= cfn
->get_qualifier(cfn
);
135 n
= snprintf(buf
, BUF_LEN
, "0x%06x/0x%08x-0x%02x", vid
, name
, qualifier
);
137 names
= pts_components
->get_comp_func_names(pts_components
, vid
);
138 types
= pts_components
->get_qualifier_type_names(pts_components
, vid
);
139 type
= pts_components
->get_qualifier(pts_components
, cfn
, flags
);
142 n
= snprintf(buf
+ n
, BUF_LEN
- n
, " %N/%N [%s] %N",
143 pen_names
, vid
, names
, name
, flags
, types
, type
);
148 METHOD(attest_db_t
, set_component
, bool,
149 private_attest_db_t
*this, char *comp
, bool create
)
153 int vid
, name
, qualifier
;
154 pts_comp_func_name_t
*cfn
;
158 printf("component has already been set\n");
162 /* parse component string */
163 pos1
= strchr(comp
, '/');
164 pos2
= strchr(comp
, '-');
167 printf("component string must have the form \"vendor_id/name-qualifier\"\n");
171 name
= atoi(pos1
+ 1);
172 qualifier
= atoi(pos2
+ 1);
173 cfn
= pts_comp_func_name_create(vid
, name
, qualifier
);
175 e
= this->db
->query(this->db
,
176 "SELECT id FROM components "
177 "WHERE vendor_id = ? AND name = ? AND qualifier = ?",
178 DB_INT
, vid
, DB_INT
, name
, DB_INT
, qualifier
, DB_INT
);
181 if (e
->enumerate(e
, &this->cid
))
183 this->comp_set
= TRUE
;
195 printf("component '%s' not found in database\n", print_cfn(cfn
));
200 /* Add a new database entry */
201 this->comp_set
= this->db
->execute(this->db
, &this->cid
,
202 "INSERT INTO components (vendor_id, name, qualifier) "
204 DB_INT
, vid
, DB_INT
, name
, DB_INT
, qualifier
) == 1;
206 printf("component '%s' %sinserted into database\n", print_cfn(cfn
),
207 this->comp_set ?
"" : "could not be ");
216 return this->comp_set
;
219 METHOD(attest_db_t
, set_cid
, bool,
220 private_attest_db_t
*this, int cid
)
223 int vid
, name
, qualifier
;
227 printf("component has already been set\n");
232 e
= this->db
->query(this->db
, "SELECT vendor_id, name, qualifier "
233 "FROM components WHERE id = ?",
234 DB_INT
, cid
, DB_INT
, DB_INT
, DB_INT
);
237 if (e
->enumerate(e
, &vid
, &name
, &qualifier
))
239 this->cfn
= pts_comp_func_name_create(vid
, name
, qualifier
);
240 this->comp_set
= TRUE
;
244 printf("no component found with cid %d\n", cid
);
248 return this->comp_set
;
251 METHOD(attest_db_t
, set_directory
, bool,
252 private_attest_db_t
*this, char *dir
, bool create
)
258 printf("directory has already been set\n");
262 this->dir
= strdup(dir
);
264 e
= this->db
->query(this->db
,
265 "SELECT id FROM files WHERE type = 1 AND path = ?",
266 DB_TEXT
, dir
, DB_INT
);
269 if (e
->enumerate(e
, &this->did
))
271 this->dir_set
= TRUE
;
282 printf("directory '%s' not found in database\n", dir
);
286 /* Add a new database entry */
287 this->dir_set
= this->db
->execute(this->db
, &this->did
,
288 "INSERT INTO files (type, path) VALUES (1, ?)",
291 printf("directory '%s' %sinserted into database\n", dir
,
292 this->dir_set ?
"" : "could not be ");
294 return this->dir_set
;
297 METHOD(attest_db_t
, set_did
, bool,
298 private_attest_db_t
*this, int did
)
305 printf("directory has already been set\n");
310 e
= this->db
->query(this->db
, "SELECT path FROM files WHERE id = ?",
311 DB_INT
, did
, DB_TEXT
);
314 if (e
->enumerate(e
, &dir
))
317 this->dir
= strdup(dir
);
318 this->dir_set
= TRUE
;
322 printf("no directory found with did %d\n", did
);
326 return this->dir_set
;
329 METHOD(attest_db_t
, set_file
, bool,
330 private_attest_db_t
*this, char *file
, bool create
)
336 printf("file has already been set\n");
339 this->file
= strdup(file
);
341 e
= this->db
->query(this->db
, "SELECT id FROM files WHERE path = ?",
342 DB_TEXT
, file
, DB_INT
);
345 if (e
->enumerate(e
, &this->fid
))
347 this->file_set
= TRUE
;
358 printf("file '%s' not found in database\n", file
);
362 /* Add a new database entry */
363 this->file_set
= this->db
->execute(this->db
, &this->fid
,
364 "INSERT INTO files (type, path) VALUES (0, ?)",
367 printf("file '%s' %sinserted into database\n", file
,
368 this->file_set ?
"" : "could not be ");
370 return this->file_set
;
373 METHOD(attest_db_t
, set_fid
, bool,
374 private_attest_db_t
*this, int fid
)
381 printf("file has already been set\n");
386 e
= this->db
->query(this->db
, "SELECT path FROM files WHERE id = ?",
387 DB_INT
, fid
, DB_TEXT
);
390 if (e
->enumerate(e
, &file
))
392 this->file
= strdup(file
);
393 this->file_set
= TRUE
;
397 printf("no file found with fid %d\n", fid
);
401 return this->file_set
;
404 METHOD(attest_db_t
, set_key
, bool,
405 private_attest_db_t
*this, char *key
, bool create
)
412 printf("key has already been set\n");
415 this->key
= chunk_from_hex(chunk_create(key
, strlen(key
)), NULL
);
417 e
= this->db
->query(this->db
, "SELECT id, owner FROM keys WHERE keyid= ?",
418 DB_BLOB
, this->key
, DB_INT
, DB_TEXT
);
421 if (e
->enumerate(e
, &this->kid
, &owner
))
423 this->owner
= strdup(owner
);
424 this->key_set
= TRUE
;
435 printf("key '%#B' not found in database\n", &this->key
);
439 /* Add a new database entry */
442 this->owner
= strdup("");
444 this->key_set
= this->db
->execute(this->db
, &this->kid
,
445 "INSERT INTO keys (keyid, owner) VALUES (?, ?)",
446 DB_BLOB
, this->key
, DB_TEXT
, this->owner
) == 1;
448 printf("key '%#B' %sinserted into database\n", &this->key
,
449 this->key_set ?
"" : "could not be ");
451 return this->key_set
;
455 METHOD(attest_db_t
, set_kid
, bool,
456 private_attest_db_t
*this, int kid
)
464 printf("key has already been set\n");
469 e
= this->db
->query(this->db
, "SELECT keyid, owner FROM keys WHERE id = ?",
470 DB_INT
, kid
, DB_BLOB
, DB_TEXT
);
473 if (e
->enumerate(e
, &key
, &owner
))
475 this->owner
= strdup(owner
);
476 this->key
= chunk_clone(key
);
477 this->key_set
= TRUE
;
481 printf("no key found with kid %d\n", kid
);
485 return this->key_set
;
489 METHOD(attest_db_t
, set_product
, bool,
490 private_attest_db_t
*this, char *product
, bool create
)
494 if (this->product_set
)
496 printf("product has already been set\n");
499 this->product
= strdup(product
);
501 e
= this->db
->query(this->db
, "SELECT id FROM products WHERE name = ?",
502 DB_TEXT
, product
, DB_INT
);
505 if (e
->enumerate(e
, &this->pid
))
507 this->product_set
= TRUE
;
511 if (this->product_set
)
518 printf("product '%s' not found in database\n", product
);
522 /* Add a new database entry */
523 this->product_set
= this->db
->execute(this->db
, &this->pid
,
524 "INSERT INTO products (name) VALUES (?)",
525 DB_TEXT
, product
) == 1;
527 printf("product '%s' %sinserted into database\n", product
,
528 this->product_set ?
"" : "could not be ");
530 return this->product_set
;
533 METHOD(attest_db_t
, set_pid
, bool,
534 private_attest_db_t
*this, int pid
)
539 if (this->product_set
)
541 printf("product has already been set\n");
546 e
= this->db
->query(this->db
, "SELECT name FROM products WHERE id = ?",
547 DB_INT
, pid
, DB_TEXT
);
550 if (e
->enumerate(e
, &product
))
552 this->product
= strdup(product
);
553 this->product_set
= TRUE
;
557 printf("no product found with pid %d in database\n", pid
);
561 return this->product_set
;
564 METHOD(attest_db_t
, set_algo
, void,
565 private_attest_db_t
*this, pts_meas_algorithms_t algo
)
570 METHOD(attest_db_t
, set_owner
, void,
571 private_attest_db_t
*this, char *owner
)
574 this->owner
= strdup(owner
);
577 METHOD(attest_db_t
, list_components
, void,
578 private_attest_db_t
*this)
581 pts_comp_func_name_t
*cfn
;
582 int cid
, vid
, name
, qualifier
, count
= 0;
586 e
= this->db
->query(this->db
,
587 "SELECT c.id, c.vendor_id, c.name, c.qualifier "
588 "FROM components AS c "
589 "JOIN key_component AS kc ON c.id = kc.component "
590 "WHERE kc.key = ? ORDER BY c.vendor_id, c.name, c.qualifier",
591 DB_INT
, this->kid
, DB_INT
, DB_INT
, DB_INT
, DB_INT
);
595 e
= this->db
->query(this->db
,
596 "SELECT id, vendor_id, name, qualifier FROM components "
597 "ORDER BY vendor_id, name, qualifier",
598 DB_INT
, DB_INT
, DB_INT
, DB_INT
);
602 while (e
->enumerate(e
, &cid
, &vid
, &name
, &qualifier
))
604 cfn
= pts_comp_func_name_create(vid
, name
, qualifier
);
605 printf("%3d: %s\n", cid
, print_cfn(cfn
));
611 printf("%d component%s found", count
, (count
== 1) ?
"" : "s");
614 printf(" for key %#B", &this->key
);
620 METHOD(attest_db_t
, list_keys
, void,
621 private_attest_db_t
*this)
630 e
= this->db
->query(this->db
,
631 "SELECT k.id, k.keyid, k.owner FROM keys AS k "
632 "JOIN key_component AS kc ON k.id = kc.key "
633 "WHERE kc.component = ? ORDER BY k.keyid",
634 DB_INT
, this->cid
, DB_INT
, DB_BLOB
, DB_TEXT
);
637 while (e
->enumerate(e
, &kid
, &keyid
, &owner
))
639 printf("%3d: %#B '%s'\n", kid
, &keyid
, owner
);
647 e
= this->db
->query(this->db
, "SELECT id, keyid, owner FROM keys "
649 DB_INT
, DB_BLOB
, DB_TEXT
);
652 while (e
->enumerate(e
, &kid
, &keyid
, &owner
))
654 printf("%3d: %#B '%s'\n", kid
, &keyid
, owner
);
661 printf("%d key%s found", count
, (count
== 1) ?
"" : "s");
664 printf(" for component '%s'", print_cfn(this->cfn
));
669 METHOD(attest_db_t
, list_files
, void,
670 private_attest_db_t
*this)
673 char *file
, *file_type
[] = { " ", "d", "r" };
674 int fid
, type
, meas
, meta
, count
= 0;
678 e
= this->db
->query(this->db
,
679 "SELECT f.id, f.type, f.path, pf.measurement, pf.metadata "
681 "JOIN product_file AS pf ON f.id = pf.file "
682 "WHERE pf.product = ? ORDER BY f.path",
683 DB_INT
, this->pid
, DB_INT
, DB_INT
, DB_TEXT
, DB_INT
, DB_INT
);
686 while (e
->enumerate(e
, &fid
, &type
, &file
, &meas
, &meta
))
688 type
= (type
< 0 || type
> 2) ?
0 : type
;
689 printf("%3d: |%s%s| %s %s\n", fid
, meas ?
"M":" ", meta ?
"T":" ",
690 file_type
[type
], file
);
698 e
= this->db
->query(this->db
,
699 "SELECT id, type, path FROM files "
701 DB_INT
, DB_INT
, DB_TEXT
);
704 while (e
->enumerate(e
, &fid
, &type
, &file
))
706 type
= (type
< 0 || type
> 2) ?
0 : type
;
707 printf("%3d: %s %s\n", fid
, file_type
[type
], file
);
714 printf("%d file%s found", count
, (count
== 1) ?
"" : "s");
715 if (this->product_set
)
717 printf(" for product '%s'", this->product
);
722 METHOD(attest_db_t
, list_products
, void,
723 private_attest_db_t
*this)
727 int pid
, meas
, meta
, count
= 0;
731 e
= this->db
->query(this->db
,
732 "SELECT p.id, p.name, pf.measurement, pf.metadata "
733 "FROM products AS p "
734 "JOIN product_file AS pf ON p.id = pf.product "
735 "WHERE pf.file = ? ORDER BY p.name",
736 DB_INT
, this->fid
, DB_INT
, DB_TEXT
, DB_INT
, DB_INT
);
739 while (e
->enumerate(e
, &pid
, &product
, &meas
, &meta
))
741 printf("%3d: |%s%s| %s\n", pid
, meas ?
"M":" ", meta ?
"T":" ",
750 e
= this->db
->query(this->db
, "SELECT id, name FROM products "
755 while (e
->enumerate(e
, &pid
, &product
))
757 printf("%3d: %s\n", pid
, product
);
764 printf("%d product%s found", count
, (count
== 1) ?
"" : "s");
767 printf(" for file '%s'", this->file
);
773 * get the directory if there is one from the files tables
775 static void get_directory(private_attest_db_t
*this, int did
, char **directory
)
781 *directory
= strdup("");
785 e
= this->db
->query(this->db
,
786 "SELECT path from files WHERE id = ?",
787 DB_INT
, did
, DB_TEXT
);
790 if (e
->enumerate(e
, &dir
))
793 *directory
= strdup(dir
);
800 static bool slash(char *directory
, char *file
)
802 return *file
!= '/' && directory
[max(0, strlen(directory
)-1)] != '/';
805 METHOD(attest_db_t
, list_hashes
, void,
806 private_attest_db_t
*this)
810 char *file
, *dir
, *product
;
811 int fid
, fid_old
= 0, did
, did_old
= 0, count
= 0;
815 if (this->pid
&& this->fid
)
817 e
= this->db
->query(this->db
,
818 "SELECT hash FROM file_hashes "
819 "WHERE algo = ? AND file = ? AND directory = ? AND product = ?",
820 DB_INT
, this->algo
, DB_INT
, this->fid
, DB_INT
, this->did
,
821 DB_INT
, this->pid
, DB_BLOB
);
824 while (e
->enumerate(e
, &hash
))
826 if (this->fid
!= fid_old
)
828 printf("%3d: %s%s%s\n", this->fid
, this->dir
,
829 slash(this->dir
, this->file
) ?
"/" : "", this->file
);
832 printf(" %#B\n", &hash
);
837 printf("%d %N value%s found for product '%s'\n", count
,
838 hash_algorithm_names
, pts_meas_algo_to_hash(this->algo
),
839 (count
== 1) ?
"" : "s", this->product
);
844 e
= this->db
->query(this->db
,
845 "SELECT f.id, f. f.path, fh.hash, fh.directory "
846 "FROM file_hashes AS fh "
847 "JOIN files AS f ON f.id = fh.file "
848 "WHERE fh.algo = ? AND fh.product = ? "
849 "ORDER BY fh.directory, f.path",
850 DB_INT
, this->algo
, DB_INT
, this->pid
,
851 DB_INT
, DB_TEXT
, DB_BLOB
, DB_INT
);
854 while (e
->enumerate(e
, &fid
, &file
, &hash
, &did
))
856 if (fid
!= fid_old
|| did
!= did_old
)
860 get_directory(this, did
, &dir
);
862 printf("%3d: %s%s%s\n", fid
,
863 dir
, slash(dir
, file
) ?
"/" : "", file
);
867 printf(" %#B\n", &hash
);
872 printf("%d %N value%s found for product '%s'\n", count
,
873 hash_algorithm_names
, pts_meas_algo_to_hash(this->algo
),
874 (count
== 1) ?
"" : "s", this->product
);
879 e
= this->db
->query(this->db
,
880 "SELECT p.name, fh.hash, fh.directory "
881 "FROM file_hashes AS fh "
882 "JOIN products AS p ON p.id = fh.product "
883 "WHERE fh.algo = ? AND fh.file = ? AND fh.directory = ?"
885 DB_INT
, this->algo
, DB_INT
, this->fid
, DB_INT
, this->did
,
886 DB_TEXT
, DB_BLOB
, DB_INT
);
889 while (e
->enumerate(e
, &product
, &hash
, &did
))
891 printf("%#B '%s'\n", &hash
, product
);
896 printf("%d %N value%s found for file '%s%s%s'\n",
897 count
, hash_algorithm_names
, pts_meas_algo_to_hash(this->algo
),
898 (count
== 1) ?
"" : "s", this->dir
,
899 slash(this->dir
, this->file
) ?
"/" : "", this->file
);
904 e
= this->db
->query(this->db
,
905 "SELECT f.id, f.path, p.name, fh.hash, fh.directory "
906 "FROM file_hashes AS fh "
907 "JOIN files AS f ON f.id = fh.file "
908 "JOIN products AS p ON p.id = fh.product "
910 "ORDER BY fh.directory, f.path, p.name",
912 DB_INT
, DB_TEXT
, DB_TEXT
, DB_BLOB
, DB_INT
);
915 while (e
->enumerate(e
, &fid
, &file
, &product
, &hash
, &did
))
917 if (fid
!= fid_old
|| did
!= did_old
)
921 get_directory(this, did
, &dir
);
924 printf("%3d: %s%s%s\n", fid
,
925 dir
, slash(dir
, file
) ?
"/" : "", file
);
928 printf(" %#B '%s'\n", &hash
, product
);
933 printf("%d %N value%s found\n", count
, hash_algorithm_names
,
934 pts_meas_algo_to_hash(this->algo
), (count
== 1) ?
"" : "s");
940 METHOD(attest_db_t
, list_measurements
, void,
941 private_attest_db_t
*this)
945 pts_comp_func_name_t
*cfn
;
947 int seq_no
, pcr
, vid
, name
, qualifier
;
948 int cid
, cid_old
= 0, kid
, kid_old
= 0, count
= 0;
950 if (this->kid
&& this->cid
)
952 e
= this->db
->query(this->db
,
953 "SELECT ch.seq_no, ch.pcr, ch.hash, k.owner "
954 "FROM component_hashes AS ch "
955 "JOIN keys AS k ON k.id = ch.key "
956 "WHERE ch.algo = ? AND ch.key = ? AND ch.component = ? "
958 DB_INT
, this->algo
, DB_INT
, this->kid
, DB_INT
, this->cid
,
959 DB_INT
, DB_INT
, DB_BLOB
, DB_TEXT
);
962 while (e
->enumerate(e
, &seq_no
, &pcr
, &hash
, &owner
))
964 if (this->kid
!= kid_old
)
966 printf("%3d: %#B '%s'\n", this->kid
, &this->key
, owner
);
969 printf("%5d %02d %#B\n", seq_no
, pcr
, &hash
);
974 printf("%d %N value%s found for component '%s'\n", count
,
975 hash_algorithm_names
, pts_meas_algo_to_hash(this->algo
),
976 (count
== 1) ?
"" : "s", print_cfn(this->cfn
));
981 e
= this->db
->query(this->db
,
982 "SELECT ch.seq_no, ch.pcr, ch.hash, k.id, k.keyid, k.owner "
983 "FROM component_hashes AS ch "
984 "JOIN keys AS k ON k.id = ch.key "
985 "WHERE ch.algo = ? AND ch.component = ? "
986 "ORDER BY keyid, seq_no",
987 DB_INT
, this->algo
, DB_INT
, this->cid
,
988 DB_INT
, DB_INT
, DB_BLOB
, DB_INT
, DB_BLOB
, DB_TEXT
);
991 while (e
->enumerate(e
, &seq_no
, &pcr
, &hash
, &kid
, &keyid
, &owner
))
995 printf("%3d: %#B '%s'\n", kid
, &keyid
, owner
);
998 printf("%5d %02d %#B\n", seq_no
, pcr
, &hash
);
1003 printf("%d %N value%s found for component '%s'\n", count
,
1004 hash_algorithm_names
, pts_meas_algo_to_hash(this->algo
),
1005 (count
== 1) ?
"" : "s", print_cfn(this->cfn
));
1011 e
= this->db
->query(this->db
,
1012 "SELECT ch.seq_no, ch.pcr, ch.hash, "
1013 "c.id, c.vendor_id, c.name, c.qualifier "
1014 "FROM component_hashes AS ch "
1015 "JOIN components AS c ON c.id = ch.component "
1016 "WHERE ch.algo = ? AND ch.key = ? "
1017 "ORDER BY vendor_id, name, qualifier, seq_no",
1018 DB_INT
, this->algo
, DB_INT
, this->kid
, DB_INT
, DB_INT
, DB_BLOB
,
1019 DB_TEXT
, DB_INT
, DB_INT
, DB_INT
, DB_INT
);
1022 while (e
->enumerate(e
, &seq_no
, &pcr
, &hash
, &cid
, &vid
, &name
,
1027 cfn
= pts_comp_func_name_create(vid
, name
, qualifier
);
1028 printf("%3d: %s\n", cid
, print_cfn(cfn
));
1032 printf("%5d %02d %#B\n", seq_no
, pcr
, &hash
);
1037 printf("%d %N value%s found for key %#B '%s'\n", count
,
1038 hash_algorithm_names
, pts_meas_algo_to_hash(this->algo
),
1039 (count
== 1) ?
"" : "s", &this->key
, this->owner
);
1044 METHOD(attest_db_t
, add
, bool,
1045 private_attest_db_t
*this)
1050 METHOD(attest_db_t
, delete, bool,
1051 private_attest_db_t
*this)
1055 if (this->pid
&& (this->fid
|| this->did
))
1057 printf("deletion of product/file entries not supported yet\n");
1061 if (this->kid
&& this->did
)
1063 printf("deletion of key/component entries not supported yet\n");
1069 success
= this->db
->execute(this->db
, NULL
,
1070 "DELETE FROM components WHERE id = ?",
1071 DB_UINT
, this->cid
) > 0;
1073 printf("component '%s' %sdeleted from database\n", print_cfn(this->cfn
),
1074 success ?
"" : "could not be ");
1080 success
= this->db
->execute(this->db
, NULL
,
1081 "DELETE FROM files WHERE type = 1 AND id = ?",
1082 DB_UINT
, this->did
) > 0;
1084 printf("directory '%s' %sdeleted from database\n", this->dir
,
1085 success ?
"" : "could not be ");
1091 success
= this->db
->execute(this->db
, NULL
,
1092 "DELETE FROM files WHERE id = ?",
1093 DB_UINT
, this->fid
) > 0;
1095 printf("file '%s' %sdeleted from database\n", this->file
,
1096 success ?
"" : "could not be ");
1102 success
= this->db
->execute(this->db
, NULL
,
1103 "DELETE FROM keys WHERE id = ?",
1104 DB_UINT
, this->kid
) > 0;
1106 printf("key %#B %sdeleted from database\n", &this->key
,
1107 success ?
"" : "could not be ");
1112 success
= this->db
->execute(this->db
, NULL
,
1113 "DELETE FROM products WHERE id = ?",
1114 DB_UINT
, this->pid
) > 0;
1116 printf("product '%s' %sdeleted from database\n", this->product
,
1117 success ?
"" : "could not be ");
1121 printf("empty delete command\n");
1125 METHOD(attest_db_t
, destroy
, void,
1126 private_attest_db_t
*this)
1128 DESTROY_IF(this->db
);
1129 DESTROY_IF(this->cfn
);
1130 free(this->product
);
1134 free(this->key
.ptr
);
1139 * Described in header.
1141 attest_db_t
*attest_db_create(char *uri
)
1143 private_attest_db_t
*this;
1147 .set_component
= _set_component
,
1148 .set_cid
= _set_cid
,
1149 .set_directory
= _set_directory
,
1150 .set_did
= _set_did
,
1151 .set_file
= _set_file
,
1152 .set_fid
= _set_fid
,
1153 .set_key
= _set_key
,
1154 .set_kid
= _set_kid
,
1155 .set_product
= _set_product
,
1156 .set_pid
= _set_pid
,
1157 .set_algo
= _set_algo
,
1158 .set_owner
= _set_owner
,
1159 .list_products
= _list_products
,
1160 .list_files
= _list_files
,
1161 .list_components
= _list_components
,
1162 .list_keys
= _list_keys
,
1163 .list_hashes
= _list_hashes
,
1164 .list_measurements
= _list_measurements
,
1167 .destroy
= _destroy
,
1170 .algo
= PTS_MEAS_ALGO_SHA256
,
1171 .db
= lib
->db
->create(lib
->db
, uri
),
1176 fprintf(stderr
, "opening database failed.\n");
1181 return &this->public;