test-x509v3.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Testing tool for X.509v3 routines
  3. * Copyright (c) 2006-2007, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "includes.h"
  9. #include "common.h"
  10. #include "tls/asn1.h"
  11. #include "tls/x509v3.h"
  12. int main(int argc, char *argv[])
  13. {
  14. char *buf;
  15. size_t len;
  16. struct x509_certificate *certs = NULL, *last = NULL, *cert;
  17. int i, reason;
  18. wpa_debug_level = 0;
  19. if (argc < 3 || strcmp(argv[1], "-v") != 0) {
  20. printf("usage: test_x509v3 -v <cert1.der> <cert2.der> ..\n");
  21. return -1;
  22. }
  23. for (i = 2; i < argc; i++) {
  24. printf("Reading: %s\n", argv[i]);
  25. buf = os_readfile(argv[i], &len);
  26. if (buf == NULL) {
  27. printf("Failed to read '%s'\n", argv[i]);
  28. return -1;
  29. }
  30. cert = x509_certificate_parse((u8 *) buf, len);
  31. if (cert == NULL) {
  32. printf("Failed to parse X.509 certificate\n");
  33. return -1;
  34. }
  35. free(buf);
  36. if (certs == NULL)
  37. certs = cert;
  38. else
  39. last->next = cert;
  40. last = cert;
  41. }
  42. printf("\n\nValidating certificate chain\n");
  43. if (x509_certificate_chain_validate(last, certs, &reason, 0) < 0) {
  44. printf("\nCertificate chain validation failed: %d\n", reason);
  45. return -1;
  46. }
  47. printf("\nCertificate chain is valid\n");
  48. return 0;
  49. }