Add DSA library string. Workaround for IIS .key file invalid
[openssl.git] / crypto / asn1 / n_pkey.c
index edab9feeabc33f106841df521d8937b340bd3b0e..5a7d494ff06f39501b776bcf5939379f5cd0a6df 100644 (file)
  * [including the GNU Public Licence.]
  */
 
+#ifndef NO_RSA
 #include <stdio.h>
 #include "cryptlib.h"
-#include "rsa.h"
-#include "objects.h"
-#include "asn1_mac.h"
-#include "evp.h"
-#include "x509.h"
+#include <openssl/rsa.h>
+#include <openssl/objects.h>
+#include <openssl/asn1_mac.h>
+#include <openssl/evp.h>
+#include <openssl/x509.h>
 
 
 #ifndef NO_RC4
@@ -74,23 +75,10 @@ typedef struct netscape_pkey_st
        ASN1_OCTET_STRING *private_key;
        } NETSCAPE_PKEY;
 
-/*
- * ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ERR_R_ASN1_LENGTH_MISMATCH);
- * ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_DECODING_ERROR);
- * ASN1err(ASN1_F_D2I_NETSCAPE_PKEY,ASN1_R_DECODING_ERROR);
- * ASN1err(ASN1_F_NETSCAPE_PKEY_NEW,ASN1_R_DECODING_ERROR);
- */
-#ifndef NOPROTO
 static int i2d_NETSCAPE_PKEY(NETSCAPE_PKEY *a, unsigned char **pp);
 static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(NETSCAPE_PKEY **a,unsigned char **pp, long length);
 static NETSCAPE_PKEY *NETSCAPE_PKEY_new(void);
 static void NETSCAPE_PKEY_free(NETSCAPE_PKEY *);
-#else
-static int i2d_NETSCAPE_PKEY();
-static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY();
-static NETSCAPE_PKEY *NETSCAPE_PKEY_new();
-static void NETSCAPE_PKEY_free();
-#endif
 
 int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)())
        {
@@ -151,7 +139,7 @@ int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)())
                }
 
        if (pkey->private_key->data != NULL)
-               Free((char *)pkey->private_key->data);
+               Free(pkey->private_key->data);
        if ((pkey->private_key->data=(unsigned char *)Malloc(l[0])) == NULL)
                {
                ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
@@ -217,13 +205,17 @@ RSA *d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)())
                (char *)os->data,os->length) != 0))
                {
                ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_PRIVATE_KEY_HEADER_MISSING);
-               ASN1_BIT_STRING_free(os);
+               M_ASN1_BIT_STRING_free(os);
                goto err;
                }
-       ASN1_BIT_STRING_free(os);
+       M_ASN1_BIT_STRING_free(os);
        c.q=c.p;
        if ((ret=d2i_Netscape_RSA_2(a,&c.p,c.slen,cb)) == NULL) goto err;
-       c.slen-=(c.p-c.q);
+       /* Note: some versions of IIS key files use length values that are
+        * too small for the surrounding SEQUENCEs. This following line
+        * effectively disable length checking.
+        */
+       c.slen = 0;
 
        M_ASN1_D2I_Finish(a,RSA_free,ASN1_F_D2I_NETSCAPE_RSA);
        }
@@ -291,7 +283,7 @@ RSA *d2i_Netscape_RSA_2(RSA **a, unsigned char **pp, long length,
        *pp=c.p;
 err:
        if (pkey != NULL) NETSCAPE_PKEY_free(pkey);
-       if (os != NULL) ASN1_BIT_STRING_free(os);
+       if (os != NULL) M_ASN1_BIT_STRING_free(os);
        if (alg != NULL) X509_ALGOR_free(alg);
        return(ret);
        }
@@ -333,9 +325,9 @@ static NETSCAPE_PKEY *NETSCAPE_PKEY_new(void)
        ASN1_CTX c;
 
        M_ASN1_New_Malloc(ret,NETSCAPE_PKEY);
-       M_ASN1_New(ret->version,ASN1_INTEGER_new);
+       M_ASN1_New(ret->version,M_ASN1_INTEGER_new);
        M_ASN1_New(ret->algor,X509_ALGOR_new);
-       M_ASN1_New(ret->private_key,ASN1_OCTET_STRING_new);
+       M_ASN1_New(ret->private_key,M_ASN1_OCTET_STRING_new);
        return(ret);
        M_ASN1_New_Error(ASN1_F_NETSCAPE_PKEY_NEW);
        }
@@ -343,11 +335,18 @@ static NETSCAPE_PKEY *NETSCAPE_PKEY_new(void)
 static void NETSCAPE_PKEY_free(NETSCAPE_PKEY *a)
        {
        if (a == NULL) return;
-       ASN1_INTEGER_free(a->version);
+       M_ASN1_INTEGER_free(a->version);
        X509_ALGOR_free(a->algor);
-       ASN1_OCTET_STRING_free(a->private_key);
-       Free((char *)a);
+       M_ASN1_OCTET_STRING_free(a->private_key);
+       Free(a);
        }
 
 #endif /* NO_RC4 */
 
+#else /* !NO_RSA */
+
+# if PEDANTIC
+static void *dummy=&dummy;
+# endif
+
+#endif