tickcheck.c
2.62 KB
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
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/unistd.h>
#include <util.h>
#include <PR/bbticket.h>
void usage()
{
printf("ticketcheck <ticket.sys> <cert.sys>\n");
}
int main(int argc, char **argv)
{
FILE *fp;
u8 *tickets=NULL,*certs=NULL;
u32 numTickets,numCerts;
BbTicket *ticket;
BbRsaCert *signer;
int i,j,notok;
if(argc!=3){
usage();
return 1;
}
/* read ticket file */
if((fp = fopen(argv[1], "r"))==NULL){
fprintf(stderr,"Failed to open ticket file, %s\n",argv[1]);
goto exit;
}
fread(&numTickets,1,4,fp);
numTickets = ntohl(numTickets);
tickets = malloc(numTickets*sizeof(BbTicket));
fread(tickets,1,numTickets*sizeof(BbTicket),fp);
fclose(fp);
/* read certs file */
if((fp = fopen(argv[2], "r"))==NULL){
fprintf(stderr,"Failed to open cert file, %s\n",argv[2]);
goto exit;
}
fread(&numCerts,1,4,fp);
numCerts = ntohl(numCerts);
certs = malloc(numCerts*sizeof(BbRsaCert));
fread(certs,1,numCerts*sizeof(BbRsaCert),fp);
fclose(fp);
printf("\n");
for(j=0, ticket=(BbTicket *)tickets; j<numTickets; j++, ticket++){
printf("bb id: 0x%x\n", ntohl(ticket->head.bbId));
printf("ticket id: 0x%x\n", ntohs(ticket->head.tid));
printf("code: 0x%x\n", ntohs(ticket->head.code));
printf("limit: 0x%x\n", ntohs(ticket->head.limit));
printf("ts: %s\n", ticket->head.issuer);
printf("ts crlv: 0x%x\n", ntohl(ticket->head.tsCrlVersion));
printf("content id: 0x%x\n", ntohl(ticket->cmd.head.id));
printf("content size: 0x%x\n", ntohl(ticket->cmd.head.size));
printf("content bb id: 0x%x\n", ntohl(ticket->cmd.head.bbid));
printf("content exec: 0x%x\n", ntohl(ticket->cmd.head.execFlags));
printf("content hw rights: 0x%x\n", ntohl(ticket->cmd.head.hwAccessRights));
printf("content sk rights: 0x%x\n", ntohl(ticket->cmd.head.secureKernelRights));
printf("cp: %s\n", ticket->cmd.head.issuer);
printf("cp crlv: %x\n", ntohl(ticket->cmd.head.cpCrlVersion));
printf("cp ca crlv: %x\n", ntohl(ticket->cmd.head.caCrlVersion));
for(i=0, signer=(BbRsaCert *)certs; i<numCerts; i++, signer++){
if(strcmp(ticket->head.issuer+18,signer->certId.name.server)==0)
break;
}
notok = verifyTicketSig(ticket, signer);
printf("sig check result: ");
if(notok)
printf("BAD\n\n");
else
printf("GOOD\n\n");
}
exit:
if(certs)free(certs);
if(tickets)free(tickets);
return notok;
}