bundlecheck.c 1.61 KB
#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;
}