t_spki.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <stdio.h>
  10. #include "internal/cryptlib.h"
  11. #include <openssl/x509.h>
  12. #include <openssl/asn1.h>
  13. #include <openssl/rsa.h>
  14. #include <openssl/dsa.h>
  15. #include <openssl/bn.h>
  16. /* Print out an SPKI */
  17. int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki)
  18. {
  19. EVP_PKEY *pkey;
  20. ASN1_IA5STRING *chal;
  21. ASN1_OBJECT *spkioid;
  22. int i, n;
  23. char *s;
  24. BIO_printf(out, "Netscape SPKI:\n");
  25. X509_PUBKEY_get0_param(&spkioid, NULL, NULL, NULL, spki->spkac->pubkey);
  26. i = OBJ_obj2nid(spkioid);
  27. BIO_printf(out, " Public Key Algorithm: %s\n",
  28. (i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i));
  29. pkey = X509_PUBKEY_get(spki->spkac->pubkey);
  30. if (pkey == NULL)
  31. BIO_printf(out, " Unable to load public key\n");
  32. else {
  33. EVP_PKEY_print_public(out, pkey, 4, NULL);
  34. EVP_PKEY_free(pkey);
  35. }
  36. chal = spki->spkac->challenge;
  37. if (chal->length)
  38. BIO_printf(out, " Challenge String: %.*s\n", chal->length, chal->data);
  39. i = OBJ_obj2nid(spki->sig_algor.algorithm);
  40. BIO_printf(out, " Signature Algorithm: %s",
  41. (i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i));
  42. n = spki->signature->length;
  43. s = (char *)spki->signature->data;
  44. for (i = 0; i < n; i++) {
  45. if ((i % 18) == 0)
  46. BIO_write(out, "\n ", 7);
  47. BIO_printf(out, "%02x%s", (unsigned char)s[i],
  48. ((i + 1) == n) ? "" : ":");
  49. }
  50. BIO_write(out, "\n", 1);
  51. return 1;
  52. }