Make -CSP option work again in pkcs12 utility by checking for
authorDr. Stephen Henson <steve@openssl.org>
Sun, 15 May 2005 00:54:45 +0000 (00:54 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Sun, 15 May 2005 00:54:45 +0000 (00:54 +0000)
attribute in EVP_PKEY structure.

CHANGES
apps/pkcs12.c
crypto/evp/evp.h
crypto/evp/evp_pkey.c
crypto/evp/p_lib.c
crypto/pkcs12/p12_crt.c
crypto/x509/x509.h

diff --git a/CHANGES b/CHANGES
index 0be0a88e1b7c087c6398974e6053060a2cb65b93..cd3dba144e386e49df06307e92136eb35d51c75d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,11 @@
 
  Changes between 0.9.7h and 0.9.8  [xx XXX xxxx]
 
+  *) Add attribute functions to EVP_PKEY structure. Modify
+     PKCS12_create() to recognize a CSP name attribute and
+     use it. Make -CSP option work again in pkcs12 utility.
+     [Steve Henson]
+
   *) Add new functionality to the bn blinding code:
      - automatic re-creation of the BN_BLINDING parameters after
        a fixed number of uses (currently 32)
index 410781e7846a5d2e411179bce698ee8e9978f92a..d77358a239bd974a61aaa2b24add729b76535291 100644 (file)
@@ -538,6 +538,10 @@ int MAIN(int argc, char **argv)
                catmp = (unsigned char *)sk_value(canames, i);
                X509_alias_set1(sk_X509_value(certs, i), catmp, -1);
                }
+
+       if (csp_name && key)
+               EVP_PKEY_add1_attr_by_NID(key, NID_ms_csp_name,
+                               MBSTRING_ASC, (unsigned char *)csp_name, -1);
                
 
 #ifdef CRYPTO_MDEBUG
index 0296badc9eb3521c62df9029f53a7339509ce5bc..4d38425b03d021559c7470937ac44680191955e4 100644 (file)
@@ -795,6 +795,7 @@ struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey);
 
 EVP_PKEY *     EVP_PKEY_new(void);
 void           EVP_PKEY_free(EVP_PKEY *pkey);
+
 EVP_PKEY *     d2i_PublicKey(int type,EVP_PKEY **a, const unsigned char **pp,
                        long length);
 int            i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);
index 925e0e068122161d76321d1cc0bb5f1c1882714a..6510ed54dc45d878ab0778b0412120065f997e6f 100644 (file)
@@ -709,3 +709,65 @@ static int eckey_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey)
        return ret;
 }
 #endif
+
+/* EVP_PKEY attribute functions */
+
+int EVP_PKEY_get_attr_count(const EVP_PKEY *key)
+{
+       return X509at_get_attr_count(key->attributes);
+}
+
+int EVP_PKEY_get_attr_by_NID(const EVP_PKEY *key, int nid,
+                         int lastpos)
+{
+       return X509at_get_attr_by_NID(key->attributes, nid, lastpos);
+}
+
+int EVP_PKEY_get_attr_by_OBJ(const EVP_PKEY *key, ASN1_OBJECT *obj,
+                         int lastpos)
+{
+       return X509at_get_attr_by_OBJ(key->attributes, obj, lastpos);
+}
+
+X509_ATTRIBUTE *EVP_PKEY_get_attr(const EVP_PKEY *key, int loc)
+{
+       return X509at_get_attr(key->attributes, loc);
+}
+
+X509_ATTRIBUTE *EVP_PKEY_delete_attr(EVP_PKEY *key, int loc)
+{
+       return X509at_delete_attr(key->attributes, loc);
+}
+
+int EVP_PKEY_add1_attr(EVP_PKEY *key, X509_ATTRIBUTE *attr)
+{
+       if(X509at_add1_attr(&key->attributes, attr)) return 1;
+       return 0;
+}
+
+int EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key,
+                       const ASN1_OBJECT *obj, int type,
+                       const unsigned char *bytes, int len)
+{
+       if(X509at_add1_attr_by_OBJ(&key->attributes, obj,
+                               type, bytes, len)) return 1;
+       return 0;
+}
+
+int EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key,
+                       int nid, int type,
+                       const unsigned char *bytes, int len)
+{
+       if(X509at_add1_attr_by_NID(&key->attributes, nid,
+                               type, bytes, len)) return 1;
+       return 0;
+}
+
+int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key,
+                       const char *attrname, int type,
+                       const unsigned char *bytes, int len)
+{
+       if(X509at_add1_attr_by_txt(&key->attributes, attrname,
+                               type, bytes, len)) return 1;
+       return 0;
+}
index 934f8ff8be3ef23ada717531b36264b3f130ca74..85caa478caf94118906e201f4060e9e00aa102d9 100644 (file)
@@ -451,6 +451,8 @@ void EVP_PKEY_free(EVP_PKEY *x)
                }
 #endif
        EVP_PKEY_free_it(x);
+       if (x->attributes)
+               sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);
        OPENSSL_free(x);
        }
 
index 77b5845ea95a26e999c0b8320f34295412deff34..dbafda17b681c1711c0001757e9f91a57af09381 100644 (file)
@@ -122,9 +122,21 @@ PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
 
        if (pkey)
                {
+               int cspidx;
                bag = PKCS12_add_key(&bags, pkey, keytype, iter, nid_key, pass);
+
                if (!bag)
                        goto err;
+
+               cspidx = EVP_PKEY_get_attr_by_NID(pkey, NID_ms_csp_name, -1);
+               if (cspidx >= 0)
+                       {
+                       X509_ATTRIBUTE *cspattr;
+                       cspattr = EVP_PKEY_get_attr(pkey, cspidx);
+                       if (!X509at_add1_attr(&bag->attrib, cspattr))
+                               goto err;
+                       }
+
                if(name && !PKCS12_add_friendlyname(bag, name, -1))
                        goto err;
                if(keyidlen && !PKCS12_add_localkeyid(bag, keyid, keyidlen))
index 73c1686d15dcc5f59c8f5b845cfecd00c8f4677f..66990ae5a88e831dab3ea36fd9957515f7257d1f 100644 (file)
@@ -1201,6 +1201,24 @@ int X509_ATTRIBUTE_count(X509_ATTRIBUTE *attr);
 ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr);
 ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx);
 
+int EVP_PKEY_get_attr_count(const EVP_PKEY *key);
+int EVP_PKEY_get_attr_by_NID(const EVP_PKEY *key, int nid,
+                         int lastpos);
+int EVP_PKEY_get_attr_by_OBJ(const EVP_PKEY *key, ASN1_OBJECT *obj,
+                         int lastpos);
+X509_ATTRIBUTE *EVP_PKEY_get_attr(const EVP_PKEY *key, int loc);
+X509_ATTRIBUTE *EVP_PKEY_delete_attr(EVP_PKEY *key, int loc);
+int EVP_PKEY_add1_attr(EVP_PKEY *key, X509_ATTRIBUTE *attr);
+int EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key,
+                       const ASN1_OBJECT *obj, int type,
+                       const unsigned char *bytes, int len);
+int EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key,
+                       int nid, int type,
+                       const unsigned char *bytes, int len);
+int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key,
+                       const char *attrname, int type,
+                       const unsigned char *bytes, int len);
+
 int            X509_verify_cert(X509_STORE_CTX *ctx);
 
 /* lookup a cert from a X509 STACK */