diff options
author | Dr. Stephen Henson <steve@openssl.org> | 1999-09-03 01:08:34 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 1999-09-03 01:08:34 +0000 |
commit | 8ce97163a2a3dea3d47e20f956032b50940422a2 (patch) | |
tree | 635388e872ab8c807719bbe9da4447609a816078 /crypto | |
parent | ac8b4ee04a41f89f59e080ae792fe130574e3f36 (diff) |
Add new 'spkac' utility and several SPKAC utility functions.
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/asn1/Makefile.ssl | 21 | ||||
-rw-r--r-- | crypto/asn1/t_spki.c | 116 | ||||
-rw-r--r-- | crypto/x509/Makefile.ssl | 22 | ||||
-rw-r--r-- | crypto/x509/x509.h | 10 | ||||
-rw-r--r-- | crypto/x509/x509_err.c | 3 | ||||
-rw-r--r-- | crypto/x509/x509spki.c | 121 |
6 files changed, 289 insertions, 4 deletions
diff --git a/crypto/asn1/Makefile.ssl b/crypto/asn1/Makefile.ssl index dfdcc4aad6..69b98843bf 100644 --- a/crypto/asn1/Makefile.ssl +++ b/crypto/asn1/Makefile.ssl @@ -30,7 +30,7 @@ LIBSRC= a_object.c a_bitstr.c a_utctm.c a_gentm.c a_time.c a_int.c a_octet.c \ d2i_r_pr.c i2d_r_pr.c d2i_r_pu.c i2d_r_pu.c \ d2i_s_pr.c i2d_s_pr.c d2i_s_pu.c i2d_s_pu.c \ d2i_pu.c d2i_pr.c i2d_pu.c i2d_pr.c\ - t_req.c t_x509.c t_crl.c t_pkey.c \ + t_req.c t_x509.c t_crl.c t_pkey.c t_spki.c \ p7_i_s.c p7_signi.c p7_signd.c p7_recip.c p7_enc_c.c p7_evp.c \ p7_dgst.c p7_s_e.c p7_enc.c p7_lib.c \ f_int.c f_string.c i2d_dhp.c i2d_dsap.c d2i_dhp.c d2i_dsap.c n_pkey.c \ @@ -45,7 +45,7 @@ LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_gentm.o a_time.o a_int.o a_octet.o \ d2i_r_pr.o i2d_r_pr.o d2i_r_pu.o i2d_r_pu.o \ d2i_s_pr.o i2d_s_pr.o d2i_s_pu.o i2d_s_pu.o \ d2i_pu.o d2i_pr.o i2d_pu.o i2d_pr.o \ - t_req.o t_x509.o t_crl.o t_pkey.o \ + t_req.o t_x509.o t_crl.o t_pkey.o t_spki.o \ p7_i_s.o p7_signi.o p7_signd.o p7_recip.o p7_enc_c.o p7_evp.o \ p7_dgst.o p7_s_e.o p7_enc.o p7_lib.o \ f_int.o f_string.o i2d_dhp.o i2d_dsap.o d2i_dhp.o d2i_dsap.o n_pkey.o \ @@ -833,6 +833,23 @@ t_req.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h t_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h t_req.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h t_req.o: ../../include/openssl/x509v3.h ../cryptlib.h +t_spki.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +t_spki.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +t_spki.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +t_spki.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +t_spki.o: ../../include/openssl/des.h ../../include/openssl/dh.h +t_spki.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +t_spki.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +t_spki.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +t_spki.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +t_spki.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +t_spki.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +t_spki.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +t_spki.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +t_spki.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +t_spki.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +t_spki.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +t_spki.o: ../../include/openssl/x509_vfy.h ../cryptlib.h t_x509.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h t_x509.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h t_x509.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h diff --git a/crypto/asn1/t_spki.c b/crypto/asn1/t_spki.c new file mode 100644 index 0000000000..d708434fca --- /dev/null +++ b/crypto/asn1/t_spki.c @@ -0,0 +1,116 @@ +/* t_spki.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include <stdio.h> +#include "cryptlib.h" +#include <openssl/x509.h> +#include <openssl/asn1_mac.h> + +/* Print out an SPKI */ + +int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) +{ + EVP_PKEY *pkey; + ASN1_IA5STRING *chal; + int i, n; + char *s; + BIO_printf(out, "Netscape SPKI:\n"); + i=OBJ_obj2nid(spki->spkac->pubkey->algor->algorithm); + BIO_printf(out," Public Key Algorithm: %s\n", + (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)); + pkey = X509_PUBKEY_get(spki->spkac->pubkey); + if(!pkey) BIO_printf(out, " Unable to load public key\n"); + else { +#ifndef NO_RSA + if (pkey->type == EVP_PKEY_RSA) + { + BIO_printf(out," RSA Public Key: (%d bit)\n", + BN_num_bits(pkey->pkey.rsa->n)); + RSA_print(out,pkey->pkey.rsa,2); + } + else +#endif +#ifndef NO_DSA + if (pkey->type == EVP_PKEY_DSA) + { + BIO_printf(out," DSA Public Key:\n"); + DSA_print(out,pkey->pkey.dsa,2); + } + else +#endif + BIO_printf(out," Unknown Public Key:\n"); + EVP_PKEY_free(pkey); + } + chal = spki->spkac->challenge; + if(chal->length) + BIO_printf(out, " Challenge String: %s\n", chal->data); + i=OBJ_obj2nid(spki->sig_algor->algorithm); + BIO_printf(out," Signature Algorithm: %s", + (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)); + + 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; +} diff --git a/crypto/x509/Makefile.ssl b/crypto/x509/Makefile.ssl index 14bb60d411..6562b6881b 100644 --- a/crypto/x509/Makefile.ssl +++ b/crypto/x509/Makefile.ssl @@ -23,13 +23,13 @@ APPS= LIB=$(TOP)/libcrypto.a LIBSRC= x509_def.c x509_d2.c x509_r2x.c x509_cmp.c \ - x509_obj.c x509_req.c x509_vfy.c \ + x509_obj.c x509_req.c x509spki.c x509_vfy.c \ x509_set.c x509rset.c x509_err.c \ x509name.c x509_v3.c x509_ext.c \ x509type.c x509_lu.c x_all.c x509_txt.c \ by_file.c by_dir.c LIBOBJ= x509_def.o x509_d2.o x509_r2x.o x509_cmp.o \ - x509_obj.o x509_req.o x509_vfy.o \ + x509_obj.o x509_req.o x509spki.o x509_vfy.o \ x509_set.o x509rset.o x509_err.o \ x509name.o x509_v3.o x509_ext.o \ x509type.o x509_lu.o x_all.o x509_txt.o \ @@ -380,6 +380,24 @@ x509rset.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h x509rset.o: ../../include/openssl/sha.h ../../include/openssl/stack.h x509rset.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h x509rset.o: ../cryptlib.h +x509spki.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +x509spki.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +x509spki.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +x509spki.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +x509spki.o: ../../include/openssl/des.h ../../include/openssl/dh.h +x509spki.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +x509spki.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +x509spki.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +x509spki.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x509spki.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x509spki.o: ../../include/openssl/opensslconf.h +x509spki.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +x509spki.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x509spki.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x509spki.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x509spki.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x509spki.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x509spki.o: ../cryptlib.h x509type.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h x509type.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h x509type.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h diff --git a/crypto/x509/x509.h b/crypto/x509/x509.h index 7bb4dbf125..1a3071ce16 100644 --- a/crypto/x509/x509.h +++ b/crypto/x509/x509.h @@ -552,6 +552,13 @@ int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r); int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r); int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r); +NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(char *str, int len); +char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *x); +EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x); +int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey); + +int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki); + int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md); int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md); int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md); @@ -947,6 +954,8 @@ PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken); #define X509_F_BY_FILE_CTRL 101 #define X509_F_DIR_CTRL 102 #define X509_F_GET_CERT_BY_SUBJECT 103 +#define X509_F_NETSCAPE_SPKI_B64_DECODE 129 +#define X509_F_NETSCAPE_SPKI_B64_ENCODE 130 #define X509_F_X509V3_ADD_EXT 104 #define X509_F_X509_CHECK_PRIVATE_KEY 128 #define X509_F_X509_EXTENSION_CREATE_BY_NID 108 @@ -972,6 +981,7 @@ PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken); /* Reason codes. */ #define X509_R_BAD_X509_FILETYPE 100 +#define X509_R_BASE64_DECODE_ERROR 118 #define X509_R_CANT_CHECK_DH_KEY 114 #define X509_R_CERT_ALREADY_IN_HASH_TABLE 101 #define X509_R_ERR_ASN1_LIB 102 diff --git a/crypto/x509/x509_err.c b/crypto/x509/x509_err.c index 9afd4ccde5..a2a0f1184f 100644 --- a/crypto/x509/x509_err.c +++ b/crypto/x509/x509_err.c @@ -69,6 +69,8 @@ static ERR_STRING_DATA X509_str_functs[]= {ERR_PACK(0,X509_F_BY_FILE_CTRL,0), "BY_FILE_CTRL"}, {ERR_PACK(0,X509_F_DIR_CTRL,0), "DIR_CTRL"}, {ERR_PACK(0,X509_F_GET_CERT_BY_SUBJECT,0), "GET_CERT_BY_SUBJECT"}, +{ERR_PACK(0,X509_F_NETSCAPE_SPKI_B64_DECODE,0), "NETSCAPE_SPKI_b64_decode"}, +{ERR_PACK(0,X509_F_NETSCAPE_SPKI_B64_ENCODE,0), "NETSCAPE_SPKI_b64_encode"}, {ERR_PACK(0,X509_F_X509V3_ADD_EXT,0), "X509v3_add_ext"}, {ERR_PACK(0,X509_F_X509_CHECK_PRIVATE_KEY,0), "X509_check_private_key"}, {ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_NID,0), "X509_EXTENSION_create_by_NID"}, @@ -97,6 +99,7 @@ static ERR_STRING_DATA X509_str_functs[]= static ERR_STRING_DATA X509_str_reasons[]= { {X509_R_BAD_X509_FILETYPE ,"bad x509 filetype"}, +{X509_R_BASE64_DECODE_ERROR ,"base64 decode error"}, {X509_R_CANT_CHECK_DH_KEY ,"cant check dh key"}, {X509_R_CERT_ALREADY_IN_HASH_TABLE ,"cert already in hash table"}, {X509_R_ERR_ASN1_LIB ,"err asn1 lib"}, diff --git a/crypto/x509/x509spki.c b/crypto/x509/x509spki.c new file mode 100644 index 0000000000..984e35aaae --- /dev/null +++ b/crypto/x509/x509spki.c @@ -0,0 +1,121 @@ +/* x509spki.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include <stdio.h> +#include "cryptlib.h" +#include <openssl/x509.h> +#include <openssl/asn1_mac.h> + +int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey) +{ + if ((x == NULL) || (x->spkac == NULL)) return(0); + return(X509_PUBKEY_set(&(x->spkac->pubkey),pkey)); +} + +EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x) +{ + if ((x == NULL) || (x->spkac == NULL)) + return(NULL); + return(X509_PUBKEY_get(x->spkac->pubkey)); +} + +/* Load a Netscape SPKI from a base64 encoded string */ + +NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(char *str, int len) +{ + unsigned char *spki_der, *p; + int spki_len; + NETSCAPE_SPKI *spki; + if(len <= 0) len = strlen(str); + if (!(spki_der = Malloc(len + 1))) { + X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, ERR_R_MALLOC_FAILURE); + return NULL; + } + spki_len = EVP_DecodeBlock(spki_der, str, len); + if(spki_len < 0) { + X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, + X509_R_BASE64_DECODE_ERROR); + Free(spki_der); + return NULL; + } + p = spki_der; + spki = d2i_NETSCAPE_SPKI(NULL, &p, spki_len); + Free(spki_der); + return spki; +} + +/* Generate a base64 encoded string from an SPKI */ + +char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki) +{ + unsigned char *der_spki, *p; + char *b64_str; + int der_len; + der_len = i2d_NETSCAPE_SPKI(spki, NULL); + der_spki = Malloc(der_len); + b64_str = Malloc(der_len * 2); + if(!der_spki || !b64_str) { + X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE); + return NULL; + } + p = der_spki; + i2d_NETSCAPE_SPKI(spki, &p); + EVP_EncodeBlock(b64_str, der_spki, der_len); + Free(der_spki); + return b64_str; +} |