| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2016-05-18 02:52:22 +08:00
										 |  |  |  * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											1999-09-03 09:08:34 +08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-12-06 20:17:34 +08:00
										 |  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							| 
									
										
										
										
											2016-05-18 02:52:22 +08:00
										 |  |  |  * this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  |  * in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  |  * https://www.openssl.org/source/license.html
 | 
					
						
							| 
									
										
										
										
											1999-09-03 09:08:34 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							| 
									
										
										
										
											2015-05-14 22:56:48 +08:00
										 |  |  | #include "internal/cryptlib.h"
 | 
					
						
							| 
									
										
										
										
											1999-09-03 09:08:34 +08:00
										 |  |  | #include <openssl/x509.h>
 | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  | #include <openssl/asn1.h>
 | 
					
						
							| 
									
										
										
										
											2016-03-19 02:30:20 +08:00
										 |  |  | #include <openssl/rsa.h>
 | 
					
						
							|  |  |  | #include <openssl/dsa.h>
 | 
					
						
							| 
									
										
										
										
											2004-05-18 03:14:22 +08:00
										 |  |  | #include <openssl/bn.h>
 | 
					
						
							| 
									
										
										
										
											1999-09-03 09:08:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Print out an SPKI */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     EVP_PKEY *pkey; | 
					
						
							|  |  |  |     ASN1_IA5STRING *chal; | 
					
						
							| 
									
										
										
										
											2016-03-22 21:16:42 +08:00
										 |  |  |     ASN1_OBJECT *spkioid; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     int i, n; | 
					
						
							|  |  |  |     char *s; | 
					
						
							|  |  |  |     BIO_printf(out, "Netscape SPKI:\n"); | 
					
						
							| 
									
										
										
										
											2016-03-22 21:16:42 +08:00
										 |  |  |     X509_PUBKEY_get0_param(&spkioid, NULL, NULL, NULL, spki->spkac->pubkey); | 
					
						
							|  |  |  |     i = OBJ_obj2nid(spkioid); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     BIO_printf(out, "  Public Key Algorithm: %s\n", | 
					
						
							|  |  |  |                (i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i)); | 
					
						
							|  |  |  |     pkey = X509_PUBKEY_get(spki->spkac->pubkey); | 
					
						
							| 
									
										
										
										
											2019-09-17 03:28:57 +08:00
										 |  |  |     if (pkey == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         BIO_printf(out, "  Unable to load public key\n"); | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         EVP_PKEY_print_public(out, pkey, 4, NULL); | 
					
						
							|  |  |  |         EVP_PKEY_free(pkey); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     chal = spki->spkac->challenge; | 
					
						
							|  |  |  |     if (chal->length) | 
					
						
							|  |  |  |         BIO_printf(out, "  Challenge String: %s\n", chal->data); | 
					
						
							| 
									
										
										
										
											2015-09-17 21:44:19 +08:00
										 |  |  |     i = OBJ_obj2nid(spki->sig_algor.algorithm); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     BIO_printf(out, "  Signature Algorithm: %s", | 
					
						
							|  |  |  |                (i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i)); | 
					
						
							| 
									
										
										
										
											1999-09-03 09:08:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     n = spki->signature->length; | 
					
						
							|  |  |  |     s = (char *)spki->signature->data; | 
					
						
							|  |  |  |     for (i = 0; i < n; i++) { | 
					
						
							|  |  |  |         if ((i % 18) == 0) | 
					
						
							|  |  |  |             BIO_write(out, "\n      ", 7); | 
					
						
							|  |  |  |         BIO_printf(out, "%02x%s", (unsigned char)s[i], | 
					
						
							|  |  |  |                    ((i + 1) == n) ? "" : ":"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     BIO_write(out, "\n", 1); | 
					
						
							|  |  |  |     return 1; | 
					
						
							| 
									
										
										
										
											1999-09-03 09:08:34 +08:00
										 |  |  | } |