bundlecheck.c
1.61 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
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/unistd.h>
#include <util.h>
#include <PR/bbticket.h>
#include <PR/bbcrl.h>
#include <PR/bbskapi.h>
void usage()
{
printf("bundlecheck <cmdhBundle>\n");
}
int main(int argc, char **argv)
{
FILE *fp;
u8 *tickets=NULL,*certs=NULL;
u32 numTickets,numCerts;
BbCrlHead *head;
BbRsaCert *signer;
BbAppLaunchCrls *appRlBundle;
int i,j,notok;
if(argc!=2){
usage();
return 1;
}
/* read ticket file */
if((fp = fopen(argv[1], "r"))==NULL){
fprintf(stderr,"Failed to open bundle file, %s\n",argv[1]);
goto exit;
}
tickets = malloc(16384);
fread(tickets,1,16384,fp);
fclose(fp);
appRlBundle = (BbAppLaunchCrls *)
(tickets + sizeof(BbContentMetaDataHead) + 2*sizeof(BbRsaCert));
head = (BbCrlHead *)(tickets + (u32)ntohl(appRlBundle->cprl.head));
numCerts = 2;
certs = tickets + sizeof(BbContentMetaDataHead);
for(i=0, signer=(BbRsaCert *)certs; i<numCerts; i++, signer++){
/* XXX: just CPRL for now */
if(strcmp(head->issuer+5,signer->certId.name.server)==0)
break;
}
if(i==numCerts){
fprintf(stderr,"Could not find cert!\n");
return 1;
}
/* XXX: just CPRL for now */
notok = verifyRlSig(head, tickets + (u32)(ntohl(appRlBundle->cprl.list)),
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;
}