diff --git a/CHANGES b/CHANGES index 32e59ed96a3e8f47a2dc9694980211edb8261dbf..ec9dbc250ec8e2d74db21baa2d68fbe8812fc6be 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,15 @@ Changes between 0.9.1c and 0.9.1d + *) SETs were incorrectly DER encoded. This was a major pain, because they + shared code with SEQUENCEs, which aren't coded the same. This means that + almost everything to do with SETs or SEQUENCEs has either changed name or + number of arguments. + [Ben Laurie, based on a partial fix by GP Jayan ] + + *) Fix test data to work with the above. + [Ben Laurie] + *) Fix the RSA header declarations that hid a bug I fixed in 0.9.0b but was already fixed by Eric for 0.9.1 it seems. [Ben Laurie - pointed out by Ulf Möller ] diff --git a/crypto/asn1/a_set.c b/crypto/asn1/a_set.c index 7fd4807e52a724398caf7f3aee2f4db8e4454200..a140cc14ad865fe39c84d3bb8363f61d6f8804aa 100644 --- a/crypto/asn1/a_set.c +++ b/crypto/asn1/a_set.c @@ -62,17 +62,43 @@ /* ASN1err(ASN1_F_ASN1_TYPE_NEW,ERR_R_MALLOC_FAILURE); */ +typedef struct + { + unsigned char *pbData; + int cbData; + } MYBLOB; -int i2d_ASN1_SET(a,pp,func,ex_tag,ex_class) +/* SetBlobCmp + * This function compares two elements of SET_OF block + */ +static int SetBlobCmp(const void *elem1, const void *elem2 ) + { + MYBLOB *b1 = (MYBLOB *)elem1; + MYBLOB *b2 = (MYBLOB *)elem2; + int r; + + r = memcmp(b1->pbData, b2->pbData, + b1->cbData < b2->cbData ? b1->cbData : b2->cbData); + if(r != 0) + return r; + return b1->cbData-b2->cbData; + } + +int i2d_ASN1_SET(a,pp,func,ex_tag,ex_class,is_set) STACK *a; unsigned char **pp; int (*func)(); int ex_tag; int ex_class; +int is_set; /* if TRUE, then sort the contents (i.e. it isn't a SEQUENCE) */ + { int ret=0,r; int i; unsigned char *p; + unsigned char *pStart, *pTempMem; + MYBLOB *rgSetBlob; + int totSize; if (a == NULL) return(0); for (i=sk_num(a)-1; i>=0; i--) @@ -82,12 +108,55 @@ int ex_class; p= *pp; ASN1_put_object(&p,1,ret,ex_tag,ex_class); - for (i=0; irecipientinfo,i2d_PKCS7_RECIP_INFO); M_ASN1_I2D_len_SET(a->md_algs,i2d_X509_ALGOR); M_ASN1_I2D_len(a->enc_data,i2d_PKCS7_ENC_CONTENT); - M_ASN1_I2D_len_IMP_set_opt(a->cert,i2d_X509,0); - M_ASN1_I2D_len_IMP_set_opt(a->crl,i2d_X509_CRL,1); + M_ASN1_I2D_len_IMP_SEQUENCE_opt(a->cert,i2d_X509,0); + M_ASN1_I2D_len_IMP_SET_opt(a->crl,i2d_X509_CRL,1); M_ASN1_I2D_len_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); M_ASN1_I2D_seq_total(); @@ -86,8 +86,8 @@ unsigned char **pp; M_ASN1_I2D_put_SET(a->recipientinfo,i2d_PKCS7_RECIP_INFO); M_ASN1_I2D_put_SET(a->md_algs,i2d_X509_ALGOR); M_ASN1_I2D_put(a->enc_data,i2d_PKCS7_ENC_CONTENT); - M_ASN1_I2D_put_IMP_set_opt(a->cert,i2d_X509,0); - M_ASN1_I2D_put_IMP_set_opt(a->crl,i2d_X509_CRL,1); + M_ASN1_I2D_put_IMP_SEQUENCE_opt(a->cert,i2d_X509,0); + M_ASN1_I2D_put_IMP_SET_opt(a->crl,i2d_X509_CRL,1); M_ASN1_I2D_put_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); M_ASN1_I2D_finish(); diff --git a/crypto/asn1/p7_signd.c b/crypto/asn1/p7_signd.c index 830617cbf83bb22a0a8577c44fe39728047bafbf..cefa92a2121a67f2227d5a828ea49bc1c0cfd7b5 100644 --- a/crypto/asn1/p7_signd.c +++ b/crypto/asn1/p7_signd.c @@ -75,8 +75,8 @@ unsigned char **pp; M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); M_ASN1_I2D_len_SET(a->md_algs,i2d_X509_ALGOR); M_ASN1_I2D_len(a->contents,i2d_PKCS7); - M_ASN1_I2D_len_IMP_set_opt(a->cert,i2d_X509,0); - M_ASN1_I2D_len_IMP_set_opt(a->crl,i2d_X509_CRL,1); + M_ASN1_I2D_len_IMP_SEQUENCE_opt(a->cert,i2d_X509,0); + M_ASN1_I2D_len_IMP_SET_opt(a->crl,i2d_X509_CRL,1); M_ASN1_I2D_len_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); M_ASN1_I2D_seq_total(); @@ -84,8 +84,8 @@ unsigned char **pp; M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); M_ASN1_I2D_put_SET(a->md_algs,i2d_X509_ALGOR); M_ASN1_I2D_put(a->contents,i2d_PKCS7); - M_ASN1_I2D_put_IMP_set_opt(a->cert,i2d_X509,0); - M_ASN1_I2D_put_IMP_set_opt(a->crl,i2d_X509_CRL,1); + M_ASN1_I2D_put_IMP_SEQUENCE_opt(a->cert,i2d_X509,0); + M_ASN1_I2D_put_IMP_SET_opt(a->crl,i2d_X509_CRL,1); M_ASN1_I2D_put_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); M_ASN1_I2D_finish(); diff --git a/crypto/asn1/p7_signi.c b/crypto/asn1/p7_signi.c index 4bc415d572f7f4e7a4fc6103e885631318ea260a..2a5dcb39fa14028babae1036d898295b94437c63 100644 --- a/crypto/asn1/p7_signi.c +++ b/crypto/asn1/p7_signi.c @@ -75,20 +75,20 @@ unsigned char **pp; M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); M_ASN1_I2D_len(a->issuer_and_serial,i2d_PKCS7_ISSUER_AND_SERIAL); M_ASN1_I2D_len(a->digest_alg,i2d_X509_ALGOR); - M_ASN1_I2D_len_IMP_set_opt(a->auth_attr,i2d_X509_ATTRIBUTE,0); + M_ASN1_I2D_len_IMP_SET_opt(a->auth_attr,i2d_X509_ATTRIBUTE,0); M_ASN1_I2D_len(a->digest_enc_alg,i2d_X509_ALGOR); M_ASN1_I2D_len(a->enc_digest,i2d_ASN1_OCTET_STRING); - M_ASN1_I2D_len_IMP_set_opt(a->unauth_attr,i2d_X509_ATTRIBUTE,1); + M_ASN1_I2D_len_IMP_SET_opt(a->unauth_attr,i2d_X509_ATTRIBUTE,1); M_ASN1_I2D_seq_total(); M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); M_ASN1_I2D_put(a->issuer_and_serial,i2d_PKCS7_ISSUER_AND_SERIAL); M_ASN1_I2D_put(a->digest_alg,i2d_X509_ALGOR); - M_ASN1_I2D_put_IMP_set_opt(a->auth_attr,i2d_X509_ATTRIBUTE,0); + M_ASN1_I2D_put_IMP_SET_opt(a->auth_attr,i2d_X509_ATTRIBUTE,0); M_ASN1_I2D_put(a->digest_enc_alg,i2d_X509_ALGOR); M_ASN1_I2D_put(a->enc_digest,i2d_ASN1_OCTET_STRING); - M_ASN1_I2D_put_IMP_set_opt(a->unauth_attr,i2d_X509_ATTRIBUTE,1); + M_ASN1_I2D_put_IMP_SET_opt(a->unauth_attr,i2d_X509_ATTRIBUTE,1); M_ASN1_I2D_finish(); } diff --git a/crypto/asn1/x_attrib.c b/crypto/asn1/x_attrib.c index d9faf141d3991ee629ffa9278ad1be3b50926db1..68b2648af3c2b6e0fa57e42531998154673e449e 100644 --- a/crypto/asn1/x_attrib.c +++ b/crypto/asn1/x_attrib.c @@ -93,7 +93,7 @@ unsigned char **pp; ret+=i2d_ASN1_OBJECT(a->object,p); if (a->set) ret+=i2d_ASN1_SET(a->value.set,p,i2d_ASN1_TYPE, - V_ASN1_SET,V_ASN1_UNIVERSAL); + V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET); else ret+=i2d_ASN1_TYPE(a->value.single,p); if (k++) return(r); diff --git a/crypto/asn1/x_cinf.c b/crypto/asn1/x_cinf.c index 27aad14c521dab9449aac484a0ca22e166e8cf53..99b9fe7b9f3e73ba4e047008ffb2003e4220faae 100644 --- a/crypto/asn1/x_cinf.c +++ b/crypto/asn1/x_cinf.c @@ -81,7 +81,7 @@ unsigned char **pp; M_ASN1_I2D_len(a->key, i2d_X509_PUBKEY); M_ASN1_I2D_len_IMP_opt(a->issuerUID, i2d_ASN1_BIT_STRING); M_ASN1_I2D_len_IMP_opt(a->subjectUID, i2d_ASN1_BIT_STRING); - M_ASN1_I2D_len_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,3,V_ASN1_SEQUENCE,v2); + M_ASN1_I2D_len_EXP_SEQUENCE_opt(a->extensions,i2d_X509_EXTENSION,3,V_ASN1_SEQUENCE,v2); M_ASN1_I2D_seq_total(); @@ -94,7 +94,7 @@ unsigned char **pp; M_ASN1_I2D_put(a->key, i2d_X509_PUBKEY); M_ASN1_I2D_put_IMP_opt(a->issuerUID, i2d_ASN1_BIT_STRING,1); M_ASN1_I2D_put_IMP_opt(a->subjectUID, i2d_ASN1_BIT_STRING,2); - M_ASN1_I2D_put_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,3,V_ASN1_SEQUENCE,v2); + M_ASN1_I2D_put_EXP_SEQUENCE_opt(a->extensions,i2d_X509_EXTENSION,3,V_ASN1_SEQUENCE,v2); M_ASN1_I2D_finish(); } diff --git a/crypto/asn1/x_crl.c b/crypto/asn1/x_crl.c index fe7b5f175b6c22b8780d1892a9d867f542cf8083..5e1fa796bde2a70021103c57a768d2f3cf7475ee 100644 --- a/crypto/asn1/x_crl.c +++ b/crypto/asn1/x_crl.c @@ -86,13 +86,13 @@ unsigned char **pp; M_ASN1_I2D_len(a->serialNumber,i2d_ASN1_INTEGER); M_ASN1_I2D_len(a->revocationDate,i2d_ASN1_UTCTIME); - M_ASN1_I2D_len_SEQ_opt(a->extensions,i2d_X509_EXTENSION); + M_ASN1_I2D_len_SEQUENCE_opt(a->extensions,i2d_X509_EXTENSION); M_ASN1_I2D_seq_total(); M_ASN1_I2D_put(a->serialNumber,i2d_ASN1_INTEGER); M_ASN1_I2D_put(a->revocationDate,i2d_ASN1_UTCTIME); - M_ASN1_I2D_put_SEQ_opt(a->extensions,i2d_X509_EXTENSION); + M_ASN1_I2D_put_SEQUENCE_opt(a->extensions,i2d_X509_EXTENSION); M_ASN1_I2D_finish(); } @@ -133,8 +133,8 @@ unsigned char **pp; M_ASN1_I2D_len(a->lastUpdate,i2d_ASN1_UTCTIME); if (a->nextUpdate != NULL) { M_ASN1_I2D_len(a->nextUpdate,i2d_ASN1_UTCTIME); } - M_ASN1_I2D_len_SEQ_opt(a->revoked,i2d_X509_REVOKED); - M_ASN1_I2D_len_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,0, + M_ASN1_I2D_len_SEQUENCE_opt(a->revoked,i2d_X509_REVOKED); + M_ASN1_I2D_len_EXP_SEQUENCE_opt(a->extensions,i2d_X509_EXTENSION,0, V_ASN1_SEQUENCE,v1); M_ASN1_I2D_seq_total(); @@ -148,8 +148,8 @@ unsigned char **pp; M_ASN1_I2D_put(a->lastUpdate,i2d_ASN1_UTCTIME); if (a->nextUpdate != NULL) { M_ASN1_I2D_put(a->nextUpdate,i2d_ASN1_UTCTIME); } - M_ASN1_I2D_put_SEQ_opt(a->revoked,i2d_X509_REVOKED); - M_ASN1_I2D_put_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,0, + M_ASN1_I2D_put_SEQUENCE_opt(a->revoked,i2d_X509_REVOKED); + M_ASN1_I2D_put_EXP_SEQUENCE_opt(a->extensions,i2d_X509_EXTENSION,0, V_ASN1_SEQUENCE,v1); M_ASN1_I2D_finish(); diff --git a/crypto/asn1/x_req.c b/crypto/asn1/x_req.c index a0df9982dc4650419c0fd8a008bc924d20997e6b..949632c32549dde204aaab799fe444722acae5aa 100644 --- a/crypto/asn1/x_req.c +++ b/crypto/asn1/x_req.c @@ -87,11 +87,11 @@ unsigned char **pp; */ if (a->req_kludge) { - M_ASN1_I2D_len_IMP_set_opt(a->attributes,i2d_X509_ATTRIBUTE,0); + M_ASN1_I2D_len_IMP_SET_opt(a->attributes,i2d_X509_ATTRIBUTE,0); } else { - M_ASN1_I2D_len_IMP_set(a->attributes, i2d_X509_ATTRIBUTE,0); + M_ASN1_I2D_len_IMP_SET(a->attributes, i2d_X509_ATTRIBUTE,0); } M_ASN1_I2D_seq_total(); @@ -107,11 +107,11 @@ unsigned char **pp; */ if (a->req_kludge) { - M_ASN1_I2D_put_IMP_set_opt(a->attributes,i2d_X509_ATTRIBUTE,0); + M_ASN1_I2D_put_IMP_SET_opt(a->attributes,i2d_X509_ATTRIBUTE,0); } else { - M_ASN1_I2D_put_IMP_set(a->attributes,i2d_X509_ATTRIBUTE,0); + M_ASN1_I2D_put_IMP_SET(a->attributes,i2d_X509_ATTRIBUTE,0); } M_ASN1_I2D_finish(); diff --git a/test/testp7.pem b/test/testp7.pem index b3b6dba8303a6fb5d44eecd16615898fc45453be..6bba16f13765af3357fd5ef8741423ab6b05d62a 100644 --- a/test/testp7.pem +++ b/test/testp7.pem @@ -33,14 +33,14 @@ AQEFAANLADBIAkEA7Fc6zYJw4WwCWa1ni3fYNbzGSQNluuw990024GusjLfhEk1h MsIUukTT/n8yxoO7rYp4x+LS+tHF2tBtuxg7CwIDAQABoyIwIDALBgNVHQ8EBAMC AQYwEQYJYIZIAYb4QgEBBAQDAgIEMA0GCSqGSIb3DQEBAgUAA0EAFKem0cJGg9nd TAbP5o1HIEyNn11ZlvLU5v1Hejs1MKQt72IMm4jjgOH+pjguXW8lB6yzrK4oVOO2 -UNCaNQ1H26GCAa0wgeYwgZEwDQYJKoZIhvcNAQECBQAwYjERMA8GA1UEBxMISW50 -ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytWZXJpU2ln -biBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyFw05NjA3MTcxNzU5 -MjlaFw05NzA3MTgwMDAwMDBaMA0GCSqGSIb3DQEBAgUAA0EAubVWYTsWsQmste9f -+UgMw8BkjDlM25fwQLrCfmmnLxjewey10kSROypUaJLb+r4oRALc0fG9XfZsaiiI -gotQHjCBwTBtMA0GCSqGSIb3DQEBAgUAMD4xCzAJBgNVBAYTAlVTMRcwFQYDVQQK -Ew5WZXJpU2lnbiwgSW5jLjEWMBQGA1UECxMNVEVTVCBSb290IFBDQRcNOTYwNzE3 -MTc0NDA5WhcNOTgwNzE3MDAwMDAwWjANBgkqhkiG9w0BAQIFAANBAHitA0/xAukC -jHzeh1AMT/l2oC68N+yFb+aJPHBBMxc6gG2MaKjBNwb5hcXUllMlExONA3ju10f7 -owIq3s3wx10xAAAAAAA= +UNCaNQ1H26GCAa0wgcEwbTANBgkqhkiG9w0BAQIFADA+MQswCQYDVQQGEwJVUzEX +MBUGA1UEChMOVmVyaVNpZ24sIEluYy4xFjAUBgNVBAsTDVRFU1QgUm9vdCBQQ0EX +DTk2MDcxNzE3NDQwOVoXDTk4MDcxNzAwMDAwMFowDQYJKoZIhvcNAQECBQADQQB4 +rQNP8QLpAox83odQDE/5dqAuvDfshW/miTxwQTMXOoBtjGiowTcG+YXF1JZTJRMT +jQN47tdH+6MCKt7N8MddMIHmMIGRMA0GCSqGSIb3DQEBAgUAMGIxETAPBgNVBAcT +CEludGVybmV0MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVy +aVNpZ24gQ2xhc3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlchcNOTYwNzE3 +MTc1OTI5WhcNOTcwNzE4MDAwMDAwWjANBgkqhkiG9w0BAQIFAANBALm1VmE7FrEJ +rLXvX/lIDMPAZIw5TNuX8EC6wn5ppy8Y3sHstdJEkTsqVGiS2/q+KEQC3NHxvV32 +bGooiIKLUB4xAAAAAAA= -----END PKCS7-----