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 rc
= mscat_ctl_get_member_count(msctl
);
116 printf("CATALOG MEMBER COUNT=%d\n", member_count
);
118 for (i
= 0; i
< member_count
; i
++) {
119 struct mscat_ctl_member
*m
;
122 rc
= mscat_ctl_get_member(msctl
,
130 printf("CATALOG MEMBER\n");
131 if (m
->checksum
.type
== MSCAT_CHECKSUM_STRING
) {
132 printf(" CHECKSUM: %s\n", m
->checksum
.string
);
133 } else if (m
->checksum
.type
== MSCAT_CHECKSUM_BLOB
) {
134 printf(" CHECKSUM: ");
135 for (j
= 0; j
< m
->checksum
.size
; j
++) {
136 printf("%X", m
->checksum
.blob
[j
]);
142 if (m
->file
.name
!= NULL
) {
143 printf(" FILE: %s, FLAGS=0x%08x\n",
148 if (m
->info
.guid
!= NULL
) {
149 printf(" GUID: %s, ID=0x%08x\n",
154 if (m
->osattr
.value
!= NULL
) {
155 printf(" OSATTR: %s, FLAGS=0x%08x\n",
160 if (m
->mac
.type
!= MSCAT_MAC_UNKNOWN
) {
161 printf(" MAC: %s, DIGEST: ",
162 mac_to_string(m
->mac
.type
));
163 for (j
= 0; j
< m
->mac
.digest_size
; j
++) {
164 printf("%X", m
->mac
.digest
[j
]);
172 rc
= mscat_ctl_get_attribute_count(msctl
);
176 attribute_count
= rc
;
177 printf("CATALOG ATTRIBUTE COUNT=%d\n", attribute_count
);
179 for (i
= 0; i
< attribute_count
; i
++) {
180 struct mscat_ctl_attribute
*a
;
182 rc
= mscat_ctl_get_attribute(msctl
,
190 printf(" NAME=%s, FLAGS=0x%08x, VALUE=%s\n",
195 talloc_free(mem_ctx
);