addcerts.c 1.24 KB
#include<stdio.h>
#include <bbtoolsapi.h>

int main(int argc, char **argv){
  int i;
  FILE *file1ptr;
  FILE *file2ptr;
  FILE *file3ptr;
  int numcerts1, numcerts2, numcerts3;
  unsigned long tempcert[SIZE_RSA_CERTBLOB_WORDS];


  if(argc < 4){
    fprintf(stderr,"usage : %s cert1fname cert2fname outputfname \n", argv[0]);
    exit(1);
  }
  
  file1ptr = fopen(argv[1], "r");
  
  file2ptr = fopen(argv[2], "r");
  
  if((file1ptr ==0) || (file2ptr ==0)){
    fprintf(stderr,"cannot open input cert file \n");
    exit(1);
  }

  fread(&numcerts1, 4, 1, file1ptr);
  fread(&numcerts2, 4, 1, file2ptr);

  numcerts3 = htonl(numcerts1) + htonl(numcerts2);

  file3ptr = fopen(argv[3], "w");

  if(file3ptr ==0){
    fprintf(stderr,"cannot open output cert file \n");
    exit(1);
  }
  numcerts3 = htonl(numcerts3);

  fwrite(&numcerts3, 4, 1, file3ptr);

  for(i =0; i< htonl(numcerts1); i++){
    fread(tempcert, 4, SIZE_RSA_CERTBLOB_WORDS, file1ptr);
    fwrite(tempcert, 4, SIZE_RSA_CERTBLOB_WORDS, file3ptr);
  }


  for(i =0; i< htonl(numcerts2); i++){
    fread(tempcert, 4, SIZE_RSA_CERTBLOB_WORDS, file2ptr);
    fwrite(tempcert, 4, SIZE_RSA_CERTBLOB_WORDS, file3ptr);
  }

  fclose(file1ptr);
  fclose(file2ptr);
  fclose(file3ptr);

  return 0;

}