2 * Copyright (c) 2016 Andreas Schneider <asn@samba.org>
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 3 of the License, or
7 * (at your option) any later version.
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include <gnutls/pkcs7.h>
31 static const char *mac_to_string(enum mscat_mac_algorithm algo
) {
39 case MSCAT_MAC_SHA256
:
41 case MSCAT_MAC_SHA512
:
43 case MSCAT_MAC_UNKNOWN
:
50 int main(int argc
, char *argv
[]) {
52 const char *filename
= NULL
;
53 const char *ca_file
= NULL
;
54 struct mscat_pkcs7
*cat_pkcs7
;
55 struct mscat_ctl
*msctl
;
56 unsigned int member_count
= 0;
57 unsigned int attribute_count
= 0;
66 if (filename
== NULL
|| filename
[0] == '\0') {
70 mem_ctx
= talloc_init("dumpmscat");
71 if (mem_ctx
== NULL
) {
72 fprintf(stderr
, "Failed to initialize talloc\n");
76 /* READ MS ROOT CERTIFICATE */
78 cat_pkcs7
= mscat_pkcs7_init(mem_ctx
);
79 if (cat_pkcs7
== NULL
) {
83 rc
= mscat_pkcs7_import_catfile(cat_pkcs7
,
93 rc
= mscat_pkcs7_verify(cat_pkcs7
, ca_file
);
95 printf("FAILED TO VERIFY CATALOG FILE!\n");
98 printf("CATALOG FILE VERIFIED!\n\n");
100 msctl
= mscat_ctl_init(mem_ctx
);
105 rc
= mscat_ctl_import(msctl
, cat_pkcs7
);
110 member_count
= mscat_ctl_get_member_count(msctl
);
111 printf("CATALOG MEMBER COUNT=%d\n", member_count
);
113 for (i
= 0; i
< member_count
; i
++) {
114 struct mscat_ctl_member
*m
;
117 rc
= mscat_ctl_get_member(msctl
,
125 printf("CATALOG MEMBER\n");
126 if (m
->checksum
.type
== MSCAT_CHECKSUM_STRING
) {
127 printf(" CHECKSUM: %s\n", m
->checksum
.string
);
128 } else if (m
->checksum
.type
== MSCAT_CHECKSUM_BLOB
) {
129 printf(" CHECKSUM: ");
130 for (j
= 0; j
< m
->checksum
.size
; j
++) {
131 printf("%X", m
->checksum
.blob
[j
]);
137 if (m
->file
.name
!= NULL
) {
138 printf(" FILE: %s, FLAGS=0x%08x\n",
143 if (m
->info
.guid
!= NULL
) {
144 printf(" GUID: %s, ID=0x%08x\n",
149 if (m
->osattr
.value
!= NULL
) {
150 printf(" OSATTR: %s, FLAGS=0x%08x\n",
155 if (m
->mac
.type
!= MSCAT_MAC_UNKNOWN
) {
156 printf(" MAC: %s, DIGEST: ",
157 mac_to_string(m
->mac
.type
));
158 for (j
= 0; j
< m
->mac
.digest_size
; j
++) {
159 printf("%X", m
->mac
.digest
[j
]);
167 attribute_count
= mscat_ctl_get_attribute_count(msctl
);
168 printf("CATALOG ATTRIBUTE COUNT=%d\n", attribute_count
);
170 for (i
= 0; i
< attribute_count
; i
++) {
171 struct mscat_ctl_attribute
*a
;
173 rc
= mscat_ctl_get_attribute(msctl
,
181 printf(" NAME=%s, FLAGS=0x%08x, VALUE=%s\n",
186 talloc_free(mem_ctx
);