Back to index

nordugrid-arc-nox  1.1.0~rc6
VOMSAttribute.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <cstring>
00006 
00007 #include "VOMSAttribute.h"
00008 
00009 namespace ArcCredential {
00010 
00011 int i2d_AC_ATTR(AC_ATTR *a, unsigned char **pp)
00012 {
00013   char text[1000];
00014 
00015   M_ASN1_I2D_vars(a);
00016 
00017   if (!i2t_ASN1_OBJECT(text,999,a->type))
00018     return 0;
00019   else if (!((strcmp(text, "idacagroup") == 0) || (strcmp(text,"idatcap") == 0)))
00020     return 0;
00021   
00022   M_ASN1_I2D_len(a->type, i2d_ASN1_OBJECT);
00023 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
00024   M_ASN1_I2D_len_SET_type(AC_IETFATTR, a->ietfattr, i2d_AC_IETFATTR);
00025   M_ASN1_I2D_seq_total();
00026   M_ASN1_I2D_put(a->type, i2d_ASN1_OBJECT);
00027   M_ASN1_I2D_put_SET_type(AC_IETFATTR,a->ietfattr, i2d_AC_IETFATTR);
00028 #elif (OPENSSL_VERSION_NUMBER >= 0x0090800fL)
00029   M_ASN1_I2D_len_SET_type(AC_IETFATTR, a->ietfattr, (int (*)(void*, unsigned char**))i2d_AC_IETFATTR);
00030   M_ASN1_I2D_seq_total();
00031   M_ASN1_I2D_put(a->type, i2d_ASN1_OBJECT);
00032   M_ASN1_I2D_put_SET_type(AC_IETFATTR,a->ietfattr, (int (*)(void*, unsigned char**))i2d_AC_IETFATTR);
00033 #else
00034   M_ASN1_I2D_len_SET_type(AC_IETFATTR, a->ietfattr, (int (*)())i2d_AC_IETFATTR);
00035   M_ASN1_I2D_seq_total();
00036   M_ASN1_I2D_put(a->type, i2d_ASN1_OBJECT);
00037   M_ASN1_I2D_put_SET_type(AC_IETFATTR,a->ietfattr, (int (*)())i2d_AC_IETFATTR);
00038 #endif
00039   M_ASN1_I2D_finish();
00040 }
00041 
00042 AC_ATTR *d2i_AC_ATTR(AC_ATTR **a, SSLCONST unsigned char **pp, long length)
00043 {
00044   char text[1000];
00045 
00046   M_ASN1_D2I_vars(a, AC_ATTR *, AC_ATTR_new);
00047   M_ASN1_D2I_Init();
00048   M_ASN1_D2I_start_sequence();
00049   M_ASN1_D2I_get(ret->type, d2i_ASN1_OBJECT);
00050 
00051   if (!i2t_ASN1_OBJECT(text,999, ret->type)) {
00052     c.error = ASN1_R_NOT_ENOUGH_DATA;
00053     goto err;
00054   }
00055 
00056   if (strcmp(text, "idatcap") == 0)
00057 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
00058     M_ASN1_D2I_get_set_type(AC_IETFATTR, *ret->ietfattr, d2i_AC_IETFATTR, AC_IETFATTR_free);
00059 #else
00060     M_ASN1_D2I_get_set_type(AC_IETFATTR, ret->ietfattr, (AC_IETFATTR* (*)())d2i_AC_IETFATTR, AC_IETFATTR_free);
00061 #endif
00062   M_ASN1_D2I_Finish(a, AC_ATTR_free, ASN1_F_D2I_AC_ATTR);
00063 }
00064 
00065 AC_ATTR *AC_ATTR_new()
00066 {
00067   AC_ATTR *ret = NULL;
00068   ASN1_CTX c;
00069   M_ASN1_New_Malloc(ret, AC_ATTR);
00070   M_ASN1_New(ret->type,  ASN1_OBJECT_new);
00071   M_ASN1_New(ret->ietfattr, sk_AC_IETFATTR_new_null);
00072   return ret;
00073   M_ASN1_New_Error(AC_F_ATTR_New);
00074 }
00075 
00076 void AC_ATTR_free(AC_ATTR *a)
00077 {
00078   if (!a)
00079     return;
00080 
00081   ASN1_OBJECT_free(a->type);
00082   sk_AC_IETFATTR_pop_free(a->ietfattr, AC_IETFATTR_free);
00083   OPENSSL_free(a);
00084 }
00085 
00086 int i2d_AC_IETFATTR(AC_IETFATTR *a, unsigned char **pp)
00087 {
00088   M_ASN1_I2D_vars(a);
00089   M_ASN1_I2D_len_IMP_opt(a->names, i2d_GENERAL_NAMES);
00090 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
00091   M_ASN1_I2D_len_SEQUENCE_type(AC_IETFATTRVAL, a->values, i2d_AC_IETFATTRVAL);
00092 #elif (OPENSSL_VERSION_NUMBER >= 0x0090800fL)
00093   M_ASN1_I2D_len_SEQUENCE_type(AC_IETFATTRVAL, a->values, (int (*)(void*, unsigned char**))i2d_AC_IETFATTRVAL);
00094 #else
00095   M_ASN1_I2D_len_SEQUENCE(a->values,  (int (*)())i2d_AC_IETFATTRVAL);
00096 #endif
00097   M_ASN1_I2D_seq_total();
00098 
00099   M_ASN1_I2D_put_IMP_opt(a->names, i2d_GENERAL_NAMES, 0);
00100 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
00101   M_ASN1_I2D_put_SEQUENCE_type(AC_IETFATTRVAL, a->values, i2d_AC_IETFATTRVAL);
00102 #elif (OPENSSL_VERSION_NUMBER >= 0x0090800fL)
00103   M_ASN1_I2D_put_SEQUENCE_type(AC_IETFATTRVAL, a->values, (int (*)(void*, unsigned char**))i2d_AC_IETFATTRVAL);
00104 #else
00105   M_ASN1_I2D_put_SEQUENCE(a->values,  (int (*)())i2d_AC_IETFATTRVAL);
00106 #endif
00107   M_ASN1_I2D_finish();
00108 }
00109 
00110 AC_IETFATTR *d2i_AC_IETFATTR(AC_IETFATTR **a, SSLCONST unsigned char **pp, long length)
00111 {
00112   M_ASN1_D2I_vars(a, AC_IETFATTR *, AC_IETFATTR_new);
00113 
00114   M_ASN1_D2I_Init();
00115   M_ASN1_D2I_start_sequence();
00116   M_ASN1_D2I_get_IMP_opt(ret->names, d2i_GENERAL_NAMES, 0, V_ASN1_SEQUENCE);
00117 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
00118   M_ASN1_D2I_get_seq_type(AC_IETFATTRVAL, *ret->values, d2i_AC_IETFATTRVAL, AC_IETFATTRVAL_free);
00119 #else
00120   M_ASN1_D2I_get_seq_type(AC_IETFATTRVAL, ret->values, (AC_IETFATTRVAL* (*)())d2i_AC_IETFATTRVAL, AC_IETFATTRVAL_free);
00121 #endif
00122   M_ASN1_D2I_Finish(a, AC_IETFATTR_free, ASN1_F_D2I_AC_IETFATTR);
00123 }
00124 
00125 AC_IETFATTR *AC_IETFATTR_new()
00126 {
00127   AC_IETFATTR *ret = NULL;
00128   ASN1_CTX c;
00129 
00130   M_ASN1_New_Malloc(ret,  AC_IETFATTR);
00131   M_ASN1_New(ret->values, sk_AC_IETFATTRVAL_new_null);
00132   M_ASN1_New(ret->names,  sk_GENERAL_NAME_new_null);
00133   return ret;
00134   M_ASN1_New_Error(AC_F_IETFATTR_New);
00135 }
00136 
00137 void AC_IETFATTR_free (AC_IETFATTR *a)
00138 {
00139   if (a==NULL) return;
00140 
00141   sk_GENERAL_NAME_pop_free(a->names, GENERAL_NAME_free);
00142   sk_AC_IETFATTRVAL_pop_free(a->values, AC_IETFATTRVAL_free);
00143   OPENSSL_free(a);
00144 }
00145 
00146     
00147 int i2d_AC_IETFATTRVAL(AC_IETFATTRVAL *a, unsigned char **pp)
00148 {
00149   if (a->type == V_ASN1_OCTET_STRING || a->type == V_ASN1_OBJECT ||
00150       a->type == V_ASN1_UTF8STRING)
00151     return (i2d_ASN1_bytes((ASN1_STRING *)a, pp, a->type, V_ASN1_UNIVERSAL));
00152 
00153   ASN1err(ASN1_F_I2D_AC_IETFATTRVAL,ASN1_R_WRONG_TYPE);
00154   return -1;
00155 }
00156 
00157 AC_IETFATTRVAL *d2i_AC_IETFATTRVAL(AC_IETFATTRVAL **a, SSLCONST unsigned char **pp, long length)
00158 {
00159   unsigned char tag;
00160   tag = **pp & ~V_ASN1_CONSTRUCTED;
00161   if (tag == (V_ASN1_OCTET_STRING|V_ASN1_UNIVERSAL))
00162     return d2i_ASN1_OCTET_STRING(a, pp, length);
00163   if (tag == (V_ASN1_OBJECT|V_ASN1_UNIVERSAL))
00164     return (AC_IETFATTRVAL *)d2i_ASN1_OBJECT((ASN1_OBJECT **)a, pp, length);
00165   if (tag == (V_ASN1_UTF8STRING|V_ASN1_UNIVERSAL))
00166     return d2i_ASN1_UTF8STRING(a, pp, length);
00167   ASN1err(ASN1_F_D2I_AC_IETFATTRVAL, ASN1_R_WRONG_TYPE);
00168   return (NULL);
00169 }
00170 
00171 AC_IETFATTRVAL *AC_IETFATTRVAL_new()
00172 {
00173   return ASN1_STRING_type_new(V_ASN1_UTF8STRING);
00174 }
00175 
00176 void AC_IETFATTRVAL_free(AC_IETFATTRVAL *a)
00177 {
00178   ASN1_STRING_free(a);
00179 }
00180 
00181 int i2d_AC_DIGEST(AC_DIGEST *a, unsigned char **pp)
00182 {
00183   M_ASN1_I2D_vars(a);
00184   M_ASN1_I2D_len(a->type,          i2d_ASN1_ENUMERATED);
00185   M_ASN1_I2D_len(a->oid,           i2d_ASN1_OBJECT);
00186   M_ASN1_I2D_len(a->algor,         i2d_X509_ALGOR);
00187   M_ASN1_I2D_len(a->digest,        i2d_ASN1_BIT_STRING);
00188   M_ASN1_I2D_seq_total();
00189 
00190   M_ASN1_I2D_put(a->type,         i2d_ASN1_ENUMERATED);
00191   M_ASN1_I2D_put(a->oid,          i2d_ASN1_OBJECT);
00192   M_ASN1_I2D_put(a->algor,        i2d_X509_ALGOR);
00193   M_ASN1_I2D_put(a->digest,       i2d_ASN1_BIT_STRING);
00194   M_ASN1_I2D_finish();
00195 }
00196 
00197 AC_DIGEST *d2i_AC_DIGEST(AC_DIGEST **a, SSLCONST unsigned char **pp, long length)
00198 {
00199   M_ASN1_D2I_vars(a, AC_DIGEST *, AC_DIGEST_new);
00200 
00201   M_ASN1_D2I_Init();
00202   M_ASN1_D2I_start_sequence();
00203   M_ASN1_D2I_get(ret->type,        d2i_ASN1_ENUMERATED);
00204   M_ASN1_D2I_get(ret->oid,         d2i_ASN1_OBJECT);
00205   M_ASN1_D2I_get(ret->algor,       d2i_X509_ALGOR);
00206   M_ASN1_D2I_get(ret->digest,      d2i_ASN1_BIT_STRING);
00207   M_ASN1_D2I_Finish(a, AC_DIGEST_free, AC_F_D2I_AC_DIGEST);
00208 }
00209 
00210 AC_DIGEST *AC_DIGEST_new(void)
00211 {
00212   AC_DIGEST *ret = NULL;
00213   ASN1_CTX c;
00214 
00215   M_ASN1_New_Malloc(ret, AC_DIGEST);
00216   M_ASN1_New(ret->type, M_ASN1_ENUMERATED_new);
00217   ret->oid = NULL;
00218   ret->algor = NULL;
00219   M_ASN1_New(ret->algor,  X509_ALGOR_new);
00220   M_ASN1_New(ret->digest, M_ASN1_BIT_STRING_new);
00221   return(ret);
00222   M_ASN1_New_Error(AC_F_AC_DIGEST_New);
00223 }
00224 
00225 void AC_DIGEST_free(AC_DIGEST *a)
00226 {
00227   if (a==NULL) return;
00228 
00229   ASN1_ENUMERATED_free(a->type);
00230   ASN1_OBJECT_free(a->oid);
00231   X509_ALGOR_free(a->algor);
00232   ASN1_BIT_STRING_free(a->digest);
00233   OPENSSL_free(a);
00234 }
00235 
00236 int i2d_AC_IS(AC_IS *a, unsigned char **pp)
00237 {
00238   M_ASN1_I2D_vars(a);
00239   M_ASN1_I2D_len(a->issuer,      i2d_GENERAL_NAMES);
00240   M_ASN1_I2D_len(a->serial,      i2d_ASN1_INTEGER);
00241   M_ASN1_I2D_len_IMP_opt(a->uid, i2d_ASN1_BIT_STRING);
00242   M_ASN1_I2D_seq_total();
00243 
00244   M_ASN1_I2D_put(a->issuer,      i2d_GENERAL_NAMES);
00245   M_ASN1_I2D_put(a->serial,      i2d_ASN1_INTEGER);
00246   M_ASN1_I2D_put_IMP_opt(a->uid, i2d_ASN1_BIT_STRING, V_ASN1_BIT_STRING);
00247   M_ASN1_I2D_finish();
00248 }
00249 
00250 AC_IS *d2i_AC_IS(AC_IS **a, SSLCONST unsigned char **pp, long length)
00251 {
00252   M_ASN1_D2I_vars(a, AC_IS *, AC_IS_new);
00253 
00254   M_ASN1_D2I_Init();
00255   M_ASN1_D2I_start_sequence();
00256   M_ASN1_D2I_get(ret->issuer,  d2i_GENERAL_NAMES);
00257   M_ASN1_D2I_get(ret->serial,  d2i_ASN1_INTEGER);
00258   M_ASN1_D2I_get_opt(ret->uid, d2i_ASN1_BIT_STRING, V_ASN1_BIT_STRING);
00259   M_ASN1_D2I_Finish(a, AC_IS_free, AC_F_D2I_AC_IS);
00260 }
00261 
00262 AC_IS *AC_IS_new(void)
00263 {
00264   AC_IS *ret = NULL;
00265   ASN1_CTX c;
00266 
00267   M_ASN1_New_Malloc(ret, AC_IS);
00268   M_ASN1_New(ret->issuer, GENERAL_NAMES_new);
00269   M_ASN1_New(ret->serial, M_ASN1_INTEGER_new);
00270   ret->uid = NULL;
00271   return(ret);
00272   M_ASN1_New_Error(AC_F_AC_IS_New);
00273 }
00274 
00275 void AC_IS_free(AC_IS *a)
00276 {
00277   if (a==NULL) return;
00278 
00279   GENERAL_NAMES_free(a->issuer);
00280   M_ASN1_INTEGER_free(a->serial);
00281   M_ASN1_BIT_STRING_free(a->uid);
00282   OPENSSL_free(a);
00283 }
00284 
00285 int i2d_AC_FORM(AC_FORM *a, unsigned char **pp)
00286 {
00287   M_ASN1_I2D_vars(a);
00288 
00289   M_ASN1_I2D_len(a->names,  i2d_GENERAL_NAMES);
00290   M_ASN1_I2D_len_IMP_opt(a->is,     i2d_AC_IS);
00291   M_ASN1_I2D_len_IMP_opt(a->digest, i2d_AC_DIGEST);
00292   M_ASN1_I2D_seq_total();
00293 
00294   M_ASN1_I2D_put(a->names,  i2d_GENERAL_NAMES);
00295   M_ASN1_I2D_put_IMP_opt(a->is,     i2d_AC_IS, 0);
00296   M_ASN1_I2D_put_IMP_opt(a->digest, i2d_AC_DIGEST, 1);
00297   M_ASN1_I2D_finish();
00298 }
00299 
00300 AC_FORM *d2i_AC_FORM(AC_FORM **a, SSLCONST unsigned char **pp, long length)
00301 {
00302   M_ASN1_D2I_vars(a, AC_FORM *, AC_FORM_new);
00303 
00304   M_ASN1_D2I_Init();
00305   M_ASN1_D2I_start_sequence();
00306   M_ASN1_D2I_get(ret->names,  d2i_GENERAL_NAMES);
00307   M_ASN1_D2I_get_IMP_opt(ret->is,     d2i_AC_IS, 0, V_ASN1_SEQUENCE);
00308   M_ASN1_D2I_get_IMP_opt(ret->digest, d2i_AC_DIGEST, 1, V_ASN1_SEQUENCE);
00309   M_ASN1_D2I_Finish(a, AC_FORM_free, ASN1_F_D2I_AC_FORM);
00310 }
00311 
00312 AC_FORM *AC_FORM_new(void)
00313 {
00314   AC_FORM *ret = NULL;
00315   ASN1_CTX c;
00316 
00317   M_ASN1_New_Malloc(ret, AC_FORM);
00318   ret->names = GENERAL_NAMES_new();
00319   ret->is = NULL;
00320   ret->digest = NULL;
00321   return(ret);
00322   M_ASN1_New_Error(AC_F_AC_FORM_New);
00323 }
00324 
00325 void AC_FORM_free(AC_FORM *a)
00326 {
00327   if (a==NULL) return;
00328 
00329   GENERAL_NAMES_free(a->names);
00330   AC_IS_free(a->is);
00331   AC_DIGEST_free(a->digest);
00332   OPENSSL_free(a);
00333 
00334 }
00335 
00336 int i2d_AC_ACI(AC_ACI *a, unsigned char **pp)
00337 {
00338   M_ASN1_I2D_vars(a);
00339   M_ASN1_I2D_len_IMP_opt(a->form, i2d_AC_FORM);
00340   M_ASN1_I2D_seq_total();
00341 
00342   M_ASN1_I2D_put_IMP_opt(a->form, i2d_AC_FORM, 0);
00343   M_ASN1_I2D_finish();
00344 }
00345 
00346 AC_ACI *d2i_AC_ACI(AC_ACI **a, SSLCONST unsigned char **pp, long length)
00347 {
00348   M_ASN1_D2I_vars(a, AC_ACI *, AC_ACI_new);
00349   M_ASN1_D2I_Init();
00350   M_ASN1_D2I_start_sequence();
00351   M_ASN1_D2I_get_IMP_opt(ret->form, d2i_AC_FORM, 0, V_ASN1_SEQUENCE);
00352   M_ASN1_D2I_Finish(a, AC_ACI_free, ASN1_F_D2I_AC_ACI);
00353 }
00354 
00355 AC_ACI *AC_ACI_new(void)
00356 {
00357   AC_ACI *ret = NULL;
00358   ASN1_CTX c;
00359 
00360   M_ASN1_New_Malloc(ret, AC_ACI);
00361   ret->form = AC_FORM_new();
00362   ret->names = NULL;
00363   return (ret);
00364   M_ASN1_New_Error(ASN1_F_AC_ACI_New);
00365 }
00366 
00367 void AC_ACI_free(AC_ACI *a)
00368 {
00369   if (a==NULL) return;
00370   GENERAL_NAMES_free(a->names);
00371   AC_FORM_free(a->form);
00372   OPENSSL_free(a);
00373 }
00374 
00375 int i2d_AC_HOLDER(AC_HOLDER *a, unsigned char **pp)
00376 {
00377   M_ASN1_I2D_vars(a);
00378 
00379   M_ASN1_I2D_len_IMP_opt(a->baseid, i2d_AC_IS);
00380   M_ASN1_I2D_len_IMP_opt(a->name, i2d_GENERAL_NAMES);
00381   M_ASN1_I2D_len_IMP_opt(a->digest, i2d_AC_DIGEST);
00382   M_ASN1_I2D_seq_total();
00383 
00384   M_ASN1_I2D_put_IMP_opt(a->baseid, i2d_AC_IS, 0);             
00385   M_ASN1_I2D_put_IMP_opt(a->name, i2d_GENERAL_NAMES, 1);
00386   M_ASN1_I2D_put_IMP_opt(a->digest, i2d_AC_DIGEST, 2);
00387   M_ASN1_I2D_finish();
00388 }
00389 
00390 AC_HOLDER *d2i_AC_HOLDER(AC_HOLDER **a, SSLCONST unsigned char **pp, long length)
00391 {
00392   M_ASN1_D2I_vars(a, AC_HOLDER *, AC_HOLDER_new);
00393 
00394   M_ASN1_D2I_Init();
00395   M_ASN1_D2I_start_sequence();
00396   M_ASN1_D2I_get_IMP_opt(ret->baseid, d2i_AC_IS, 0, V_ASN1_SEQUENCE);
00397   M_ASN1_D2I_get_IMP_opt(ret->name, d2i_GENERAL_NAMES, 1, V_ASN1_SEQUENCE);
00398   M_ASN1_D2I_get_IMP_opt(ret->digest, d2i_AC_DIGEST, 2, V_ASN1_SEQUENCE);
00399   M_ASN1_D2I_Finish(a, AC_HOLDER_free, ASN1_F_D2I_AC_HOLDER);
00400 }
00401 
00402 AC_HOLDER *AC_HOLDER_new(void)
00403 {
00404   AC_HOLDER *ret = NULL;
00405   ASN1_CTX c;
00406 
00407   M_ASN1_New_Malloc(ret, AC_HOLDER);
00408   M_ASN1_New(ret->baseid, AC_IS_new);
00409   ret->name = NULL;
00410   ret->digest = NULL;
00411   return(ret);
00412   M_ASN1_New_Error(ASN1_F_AC_HOLDER_New);
00413 }
00414 
00415 void AC_HOLDER_free(AC_HOLDER *a)
00416 {
00417   if (!a) return;
00418 
00419   AC_IS_free(a->baseid);
00420   GENERAL_NAMES_free(a->name);
00421   AC_DIGEST_free(a->digest);
00422   OPENSSL_free(a);
00423 }
00424 
00425 AC_VAL *AC_VAL_new(void)
00426 {
00427   AC_VAL *ret = NULL;
00428   ASN1_CTX c;
00429 
00430   M_ASN1_New_Malloc(ret, AC_VAL);
00431 
00432   ret->notBefore = NULL;
00433   ret->notAfter = NULL;
00434   
00435   return(ret);
00436   M_ASN1_New_Error(ASN1_F_AC_VAL_New);
00437 }
00438 
00439 int i2d_AC_VAL(AC_VAL *a, unsigned char **pp) 
00440 {
00441   M_ASN1_I2D_vars(a);
00442 
00443   M_ASN1_I2D_len(a->notBefore, i2d_ASN1_GENERALIZEDTIME);
00444   M_ASN1_I2D_len(a->notAfter,  i2d_ASN1_GENERALIZEDTIME);
00445 
00446   M_ASN1_I2D_seq_total();
00447 
00448   M_ASN1_I2D_put(a->notBefore, i2d_ASN1_GENERALIZEDTIME);
00449   M_ASN1_I2D_put(a->notAfter,  i2d_ASN1_GENERALIZEDTIME);
00450 
00451   M_ASN1_I2D_finish();
00452 }
00453 
00454 AC_VAL *d2i_AC_VAL(AC_VAL **a, SSLCONST unsigned char **pp, long length)
00455 {
00456   M_ASN1_D2I_vars(a, AC_VAL *, AC_VAL_new);
00457 
00458   M_ASN1_D2I_Init();
00459   M_ASN1_D2I_start_sequence();
00460 
00461   M_ASN1_D2I_get(ret->notBefore, d2i_ASN1_GENERALIZEDTIME);
00462   M_ASN1_D2I_get(ret->notAfter,  d2i_ASN1_GENERALIZEDTIME);
00463 
00464   M_ASN1_D2I_Finish(a, AC_VAL_free, AC_F_D2I_AC);
00465 }
00466 
00467 void AC_VAL_free(AC_VAL *a)
00468 {
00469 
00470   if (a==NULL) return;
00471 
00472   M_ASN1_GENERALIZEDTIME_free(a->notBefore);
00473   M_ASN1_GENERALIZEDTIME_free(a->notAfter);
00474 
00475   OPENSSL_free(a);
00476 }
00477 
00478 int i2d_AC_INFO(AC_INFO *a, unsigned char **pp)
00479 {
00480   M_ASN1_I2D_vars(a);
00481 
00482   M_ASN1_I2D_len(a->version,  i2d_ASN1_INTEGER);
00483   M_ASN1_I2D_len(a->holder,   i2d_AC_HOLDER);
00484   M_ASN1_I2D_len_IMP_opt(a->form, i2d_AC_FORM);
00485   M_ASN1_I2D_len(a->alg,      i2d_X509_ALGOR);
00486   M_ASN1_I2D_len(a->serial,   i2d_ASN1_INTEGER);
00487   M_ASN1_I2D_len(a->validity, i2d_AC_VAL);
00488 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
00489   M_ASN1_I2D_len_SEQUENCE_type(AC_ATTR, a->attrib, i2d_AC_ATTR);
00490 #elif (OPENSSL_VERSION_NUMBER >= 0x0090800fL)
00491   M_ASN1_I2D_len_SEQUENCE_type(AC_ATTR, a->attrib, (int (*)(void*, unsigned char**))i2d_AC_ATTR);
00492 #else
00493   M_ASN1_I2D_len_SEQUENCE    (a->attrib, (int(*)())i2d_AC_ATTR);
00494 #endif
00495   M_ASN1_I2D_len_IMP_opt     (a->id, i2d_ASN1_BIT_STRING);
00496 #if (OPENSSL_VERSION_NUMBER >= 0x0090800fL)
00497   M_ASN1_I2D_len_SEQUENCE_opt_type(X509_EXTENSION, a->exts, i2d_X509_EXTENSION);
00498 #else
00499   M_ASN1_I2D_len_SEQUENCE_opt(a->exts,   (int(*)())i2d_X509_EXTENSION);
00500 #endif
00501   M_ASN1_I2D_seq_total();
00502 
00503   M_ASN1_I2D_put(a->version,  i2d_ASN1_INTEGER);
00504   M_ASN1_I2D_put(a->holder,   i2d_AC_HOLDER);
00505   M_ASN1_I2D_put_IMP_opt(a->form,   i2d_AC_FORM, 0);
00506   M_ASN1_I2D_put(a->alg,      i2d_X509_ALGOR);
00507   M_ASN1_I2D_put(a->serial,   i2d_ASN1_INTEGER);
00508   M_ASN1_I2D_put(a->validity, i2d_AC_VAL);
00509 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
00510   M_ASN1_I2D_put_SEQUENCE_type(AC_ATTR, a->attrib, i2d_AC_ATTR);
00511 #elif (OPENSSL_VERSION_NUMBER >= 0x0090800fL)
00512   M_ASN1_I2D_put_SEQUENCE_type(AC_ATTR, a->attrib, (int (*)(void*, unsigned char**))i2d_AC_ATTR);
00513 #else
00514   M_ASN1_I2D_put_SEQUENCE(a->attrib, (int(*)())i2d_AC_ATTR);
00515 #endif
00516   M_ASN1_I2D_put_IMP_opt(a->id, i2d_ASN1_BIT_STRING, V_ASN1_BIT_STRING);
00517 #if (OPENSSL_VERSION_NUMBER >= 0x0090800fL)
00518   M_ASN1_I2D_put_SEQUENCE_opt_type(X509_EXTENSION, a->exts, i2d_X509_EXTENSION);
00519 #else
00520   M_ASN1_I2D_put_SEQUENCE_opt(a->exts, (int(*)())i2d_X509_EXTENSION);
00521 #endif
00522   M_ASN1_I2D_finish();
00523 }
00524 
00525 AC_INFO *d2i_AC_INFO(AC_INFO **a, SSLCONST unsigned char **pp, long length)
00526 {
00527   M_ASN1_D2I_vars(a, AC_INFO *, AC_INFO_new);
00528 
00529   M_ASN1_D2I_Init();
00530   M_ASN1_D2I_start_sequence();
00531   M_ASN1_D2I_get(ret->version,    d2i_ASN1_INTEGER);
00532   M_ASN1_D2I_get(ret->holder,     d2i_AC_HOLDER);
00533   M_ASN1_D2I_get_IMP_opt(ret->form,     d2i_AC_FORM, 0, V_ASN1_SEQUENCE);
00534   M_ASN1_D2I_get(ret->alg,        d2i_X509_ALGOR);
00535   M_ASN1_D2I_get(ret->serial,     d2i_ASN1_INTEGER);
00536   M_ASN1_D2I_get(ret->validity, d2i_AC_VAL);
00537 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
00538   M_ASN1_D2I_get_seq_type(AC_ATTR, *ret->attrib, d2i_AC_ATTR, AC_ATTR_free);
00539 #else
00540   M_ASN1_D2I_get_seq_type(AC_ATTR, ret->attrib, (AC_ATTR* (*)())d2i_AC_ATTR, AC_ATTR_free);
00541 #endif
00542   M_ASN1_D2I_get_opt(ret->id,     d2i_ASN1_BIT_STRING, V_ASN1_BIT_STRING);
00543 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
00544   M_ASN1_D2I_get_seq_opt_type(X509_EXTENSION, *ret->exts, d2i_X509_EXTENSION, X509_EXTENSION_free);
00545 #else
00546   M_ASN1_D2I_get_seq_opt_type(X509_EXTENSION, ret->exts, d2i_X509_EXTENSION, X509_EXTENSION_free);
00547 #endif
00548   M_ASN1_D2I_Finish(a, AC_INFO_free, AC_F_D2I_AC);
00549 }
00550 
00551 AC_INFO *AC_INFO_new(void)
00552 {
00553   AC_INFO *ret = NULL;
00554   ASN1_CTX c;
00555 
00556   M_ASN1_New_Malloc(ret, AC_INFO);
00557   M_ASN1_New(ret->version,  ASN1_INTEGER_new);
00558   M_ASN1_New(ret->holder,   AC_HOLDER_new);
00559   M_ASN1_New(ret->form,     AC_FORM_new);
00560   M_ASN1_New(ret->alg,      X509_ALGOR_new);
00561   M_ASN1_New(ret->serial,   ASN1_INTEGER_new);
00562   M_ASN1_New(ret->validity, AC_VAL_new);
00563   M_ASN1_New(ret->attrib,   sk_AC_ATTR_new_null);
00564   ret->id = NULL;
00565   M_ASN1_New(ret->exts,     sk_X509_EXTENSION_new_null);
00566 /*   ret->exts=NULL; */
00567   return(ret);
00568   M_ASN1_New_Error(AC_F_AC_INFO_NEW);
00569 }
00570 
00571 void AC_INFO_free(AC_INFO *a)
00572 {
00573   if (a==NULL) return;
00574   ASN1_INTEGER_free(a->version);
00575   AC_HOLDER_free(a->holder);
00576   AC_FORM_free(a->form);
00577   X509_ALGOR_free(a->alg);
00578   ASN1_INTEGER_free(a->serial);
00579   AC_VAL_free(a->validity);
00580   sk_AC_ATTR_pop_free(a->attrib, AC_ATTR_free);
00581   ASN1_BIT_STRING_free(a->id);
00582   sk_X509_EXTENSION_pop_free(a->exts, X509_EXTENSION_free);
00583   OPENSSL_free(a);
00584 }
00585 
00586 int i2d_AC(AC *a, unsigned char **pp) 
00587 {
00588   M_ASN1_I2D_vars(a);
00589 
00590   M_ASN1_I2D_len(a->acinfo,    i2d_AC_INFO);
00591   M_ASN1_I2D_len(a->sig_alg,   i2d_X509_ALGOR);
00592   M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING);
00593 
00594   M_ASN1_I2D_seq_total();
00595 
00596   M_ASN1_I2D_put(a->acinfo,    i2d_AC_INFO);
00597   M_ASN1_I2D_put(a->sig_alg,   i2d_X509_ALGOR);
00598   M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING);
00599 
00600   M_ASN1_I2D_finish();
00601 }
00602 
00603 AC *d2i_AC(AC **a, SSLCONST unsigned char **pp, long length)
00604 {
00605   M_ASN1_D2I_vars(a, AC *, AC_new);
00606 
00607   M_ASN1_D2I_Init();
00608   M_ASN1_D2I_start_sequence();
00609   M_ASN1_D2I_get(ret->acinfo,    d2i_AC_INFO);
00610   M_ASN1_D2I_get(ret->sig_alg,   d2i_X509_ALGOR);
00611   M_ASN1_D2I_get(ret->signature, d2i_ASN1_BIT_STRING);
00612   M_ASN1_D2I_Finish(a, AC_free, AC_F_D2I_AC);
00613 }
00614 
00615 AC *AC_new(void)
00616 {
00617   AC *ret = NULL;
00618   ASN1_CTX c;
00619 
00620   M_ASN1_New_Malloc(ret, AC);
00621   M_ASN1_New(ret->acinfo,    AC_INFO_new);
00622   M_ASN1_New(ret->sig_alg,   X509_ALGOR_new);
00623   M_ASN1_New(ret->signature, M_ASN1_BIT_STRING_new);
00624   return(ret);
00625   M_ASN1_New_Error(AC_F_AC_New);
00626 }
00627 
00628 void AC_free(AC *a)
00629 {
00630   if (a==NULL) return;
00631 
00632   AC_INFO_free(a->acinfo);
00633   X509_ALGOR_free(a->sig_alg);
00634   M_ASN1_BIT_STRING_free(a->signature);
00635   OPENSSL_free(a);
00636 }
00637 
00639 int i2d_AC_SEQ(AC_SEQ *a, unsigned char **pp)
00640 {
00641   M_ASN1_I2D_vars(a);
00642 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
00643   M_ASN1_I2D_len_SEQUENCE_type(AC, a->acs, i2d_AC);
00644   M_ASN1_I2D_seq_total();
00645   M_ASN1_I2D_put_SEQUENCE_type(AC, a->acs, i2d_AC);
00646 #elif (OPENSSL_VERSION_NUMBER >= 0x0090800fL)
00647   M_ASN1_I2D_len_SEQUENCE_type(AC, a->acs, (int (*)(void*, unsigned char**))i2d_AC);
00648   M_ASN1_I2D_seq_total();
00649   M_ASN1_I2D_put_SEQUENCE_type(AC, a->acs, (int (*)(void*, unsigned char**))i2d_AC);
00650 #else
00651   M_ASN1_I2D_len_SEQUENCE(a->acs, (int (*)())i2d_AC);
00652   M_ASN1_I2D_seq_total();
00653   M_ASN1_I2D_put_SEQUENCE(a->acs, (int (*)())i2d_AC);
00654 #endif
00655   M_ASN1_I2D_finish();
00656 }
00657 
00658 AC_SEQ *d2i_AC_SEQ(AC_SEQ **a, SSLCONST unsigned char **pp, long length)
00659 {
00660   M_ASN1_D2I_vars(a, AC_SEQ *, AC_SEQ_new);
00661 
00662   M_ASN1_D2I_Init();
00663   M_ASN1_D2I_start_sequence();
00664 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
00665   M_ASN1_D2I_get_seq_type(AC, *ret->acs, d2i_AC, AC_free);
00666 #else
00667   M_ASN1_D2I_get_seq_type(AC, ret->acs, (AC* (*)())d2i_AC, AC_free);
00668 #endif
00669   M_ASN1_D2I_Finish(a, AC_SEQ_free, ASN1_F_D2I_AC_SEQ);
00670 }
00671 
00672 AC_SEQ *AC_SEQ_new()
00673 {
00674   AC_SEQ *ret = NULL;
00675   ASN1_CTX c;
00676 
00677   M_ASN1_New_Malloc(ret, AC_SEQ);
00678   M_ASN1_New(ret->acs, sk_AC_new_null);
00679   return ret;
00680   M_ASN1_New_Error(AC_F_AC_SEQ_new);
00681 }
00682 
00683 void AC_SEQ_free(AC_SEQ *a)
00684 {
00685   if (a==NULL) return;
00686 
00687   sk_AC_pop_free(a->acs, AC_free);
00688   OPENSSL_free(a);
00689 }
00690 
00691 int i2d_AC_TARGETS(AC_TARGETS *a, unsigned char **pp)
00692 {
00693   M_ASN1_I2D_vars(a);
00694 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
00695   M_ASN1_I2D_len_SEQUENCE_type(AC_TARGET, a->targets, i2d_AC_TARGET);
00696   M_ASN1_I2D_seq_total();
00697   M_ASN1_I2D_put_SEQUENCE_type(AC_TARGET, a->targets, i2d_AC_TARGET);
00698 #elif (OPENSSL_VERSION_NUMBER >= 0x0090800fL)
00699   M_ASN1_I2D_len_SEQUENCE_type(AC_TARGET, a->targets, (int (*)(void*, unsigned char**))i2d_AC_TARGET);
00700   M_ASN1_I2D_seq_total();
00701   M_ASN1_I2D_put_SEQUENCE_type(AC_TARGET, a->targets, (int (*)(void*, unsigned char**))i2d_AC_TARGET);
00702 #else
00703   M_ASN1_I2D_len_SEQUENCE(a->targets, (int (*)())i2d_AC_TARGET);
00704   M_ASN1_I2D_seq_total();
00705   M_ASN1_I2D_put_SEQUENCE(a->targets, (int (*)())i2d_AC_TARGET);
00706 #endif
00707   M_ASN1_I2D_finish();
00708 }
00709 
00710 AC_TARGETS *d2i_AC_TARGETS(AC_TARGETS **a, SSLCONST unsigned char **pp, long length)
00711 {
00712   M_ASN1_D2I_vars(a, AC_TARGETS *, AC_TARGETS_new);
00713 
00714   M_ASN1_D2I_Init();
00715   M_ASN1_D2I_start_sequence();
00716 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
00717   M_ASN1_D2I_get_seq_type(AC_TARGET, *ret->targets, d2i_AC_TARGET, AC_TARGET_free);
00718 #else
00719   M_ASN1_D2I_get_seq_type(AC_TARGET, ret->targets, (AC_TARGET* (*)())d2i_AC_TARGET, AC_TARGET_free);
00720 #endif
00721   M_ASN1_D2I_Finish(a, AC_TARGETS_free, ASN1_F_D2I_AC_TARGETS);
00722 }
00723 AC_TARGETS *AC_TARGETS_new()
00724 {
00725   AC_TARGETS *ret=NULL;
00726   ASN1_CTX c;
00727 
00728   M_ASN1_New_Malloc(ret, AC_TARGETS);
00729   M_ASN1_New(ret->targets, sk_AC_TARGET_new_null);
00730   return ret;
00731   M_ASN1_New_Error(AC_F_AC_TARGETS_New);
00732 }
00733 
00734 void AC_TARGETS_free(AC_TARGETS *a)
00735 {
00736   if (a==NULL) return;
00737 
00738   sk_AC_TARGET_pop_free(a->targets, AC_TARGET_free);
00739   OPENSSL_free(a);
00740 }
00741 
00742 int i2d_AC_TARGET(AC_TARGET *a, unsigned char **pp)
00743 {
00744   int v1=0, v2=0, v3=0;
00745 
00746   M_ASN1_I2D_vars(a);
00747   M_ASN1_I2D_len_EXP_opt(a->name, i2d_GENERAL_NAME, 0, v1);
00748   M_ASN1_I2D_len_EXP_opt(a->group, i2d_GENERAL_NAME, 1, v2);
00749   M_ASN1_I2D_len_EXP_opt(a->cert, i2d_AC_IS, 2, v3);
00750   M_ASN1_I2D_seq_total();
00751 
00752   M_ASN1_I2D_put_EXP_opt(a->name, i2d_GENERAL_NAME, 0, v1);
00753   M_ASN1_I2D_put_EXP_opt(a->group, i2d_GENERAL_NAME, 1, v2);
00754   M_ASN1_I2D_put_EXP_opt(a->cert, i2d_AC_IS, 2, v3);
00755   M_ASN1_I2D_finish();
00756 }
00757 
00758 AC_TARGET *d2i_AC_TARGET(AC_TARGET **a, SSLCONST unsigned char **pp, long length)
00759 {
00760   M_ASN1_D2I_vars(a, AC_TARGET *, AC_TARGET_new);
00761 
00762   M_ASN1_D2I_Init();
00763   M_ASN1_D2I_start_sequence();
00764   M_ASN1_D2I_get_EXP_opt(ret->name, d2i_GENERAL_NAME, 0);
00765   M_ASN1_D2I_get_EXP_opt(ret->group, d2i_GENERAL_NAME, 1);
00766   M_ASN1_D2I_get_EXP_opt(ret->cert, d2i_AC_IS, 2);
00767   M_ASN1_D2I_Finish(a, AC_TARGET_free, ASN1_F_D2I_AC_TARGET);
00768 }
00769 
00770 AC_TARGET *AC_TARGET_new(void)
00771 {
00772   AC_TARGET *ret=NULL;
00773   ASN1_CTX c;
00774 
00775   M_ASN1_New_Malloc(ret, AC_TARGET);
00776   ret->name = ret->group = NULL;
00777   ret->cert = NULL;
00778   return ret;
00779   M_ASN1_New_Error(AC_F_AC_TARGET_New);
00780 }
00781 
00782 void AC_TARGET_free(AC_TARGET *a)
00783 {
00784   if (a==NULL) return;
00785   GENERAL_NAME_free(a->name);
00786   GENERAL_NAME_free(a->group);
00787   AC_IS_free(a->cert);
00788   OPENSSL_free(a);
00789 }
00790 
00791 int i2d_AC_CERTS(AC_CERTS *a, unsigned char **pp)
00792 {
00793   //int v1=0, v2=0, v3=0;
00794 
00795   M_ASN1_I2D_vars(a);
00796 #if (OPENSSL_VERSION_NUMBER >= 0x0090800fL)
00797   M_ASN1_I2D_len_SEQUENCE_type(X509, a->stackcert, i2d_X509);
00798   M_ASN1_I2D_seq_total();
00799   M_ASN1_I2D_put_SEQUENCE_type(X509, a->stackcert, i2d_X509);
00800 #else
00801   M_ASN1_I2D_len_SEQUENCE(a->stackcert, (int (*)())i2d_X509);
00802   M_ASN1_I2D_seq_total();
00803   M_ASN1_I2D_put_SEQUENCE(a->stackcert, (int (*)())i2d_X509);
00804 #endif
00805   M_ASN1_I2D_finish();
00806 }
00807 
00808 AC_CERTS *d2i_AC_CERTS(AC_CERTS **a, SSLCONST unsigned char **pp, long length)
00809 {
00810   M_ASN1_D2I_vars(a, AC_CERTS *, AC_CERTS_new);
00811 
00812   M_ASN1_D2I_Init();
00813   M_ASN1_D2I_start_sequence();
00814 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
00815   M_ASN1_D2I_get_seq_type(X509, *ret->stackcert, d2i_X509, X509_free);
00816 #else
00817   M_ASN1_D2I_get_seq_type(X509, ret->stackcert, d2i_X509, X509_free);
00818 #endif
00819   M_ASN1_D2I_Finish(a, AC_CERTS_free, ASN1_F_D2I_AC_CERTS);
00820 }
00821 
00822 AC_CERTS *AC_CERTS_new()
00823 {
00824   AC_CERTS *ret=NULL;
00825   ASN1_CTX c;
00826 
00827   M_ASN1_New_Malloc(ret, AC_CERTS);
00828   M_ASN1_New(ret->stackcert, sk_X509_new_null);
00829   return ret;
00830   M_ASN1_New_Error(AC_F_X509_New);
00831 }
00832 
00833 void AC_CERTS_free(AC_CERTS *a)
00834 {
00835   if (a==NULL) return;
00836 
00837   sk_X509_pop_free(a->stackcert, X509_free);
00838   OPENSSL_free(a);
00839 }
00840 
00841 int i2d_AC_ATTRIBUTE(AC_ATTRIBUTE *a, unsigned char **pp)
00842 {
00843   M_ASN1_I2D_vars(a);
00844   M_ASN1_I2D_len(a->name,      i2d_ASN1_OCTET_STRING);
00845   M_ASN1_I2D_len(a->value,     i2d_ASN1_OCTET_STRING);
00846   M_ASN1_I2D_len(a->qualifier, i2d_ASN1_OCTET_STRING);
00847 
00848   M_ASN1_I2D_seq_total();
00849 
00850   M_ASN1_I2D_put(a->name,      i2d_ASN1_OCTET_STRING);
00851   M_ASN1_I2D_put(a->value,     i2d_ASN1_OCTET_STRING);
00852   M_ASN1_I2D_put(a->qualifier, i2d_ASN1_OCTET_STRING);
00853 
00854   M_ASN1_I2D_finish();
00855 }
00856 
00857 AC_ATTRIBUTE *d2i_AC_ATTRIBUTE(AC_ATTRIBUTE **a, SSLCONST unsigned char **pp, long length)
00858 {
00859   M_ASN1_D2I_vars(a, AC_ATTRIBUTE *, AC_ATTRIBUTE_new);
00860 
00861   M_ASN1_D2I_Init();
00862   M_ASN1_D2I_start_sequence();
00863   M_ASN1_D2I_get(ret->name,      d2i_ASN1_OCTET_STRING);
00864   M_ASN1_D2I_get(ret->value,     d2i_ASN1_OCTET_STRING);
00865   M_ASN1_D2I_get(ret->qualifier, d2i_ASN1_OCTET_STRING);
00866 
00867   M_ASN1_D2I_Finish(a, AC_ATTRIBUTE_free, AC_F_D2I_AC_ATTRIBUTE);
00868 }
00869 
00870 AC_ATTRIBUTE *AC_ATTRIBUTE_new()
00871 {
00872   AC_ATTRIBUTE *ret = NULL;
00873   ASN1_CTX c;
00874   M_ASN1_New_Malloc(ret, AC_ATTRIBUTE);
00875   M_ASN1_New(ret->name,      ASN1_OCTET_STRING_new);
00876   M_ASN1_New(ret->value,     ASN1_OCTET_STRING_new);
00877   M_ASN1_New(ret->qualifier, ASN1_OCTET_STRING_new);
00878 
00879   return ret;
00880   M_ASN1_New_Error(AC_F_ATTRIBUTE_New);
00881 }
00882 
00883 void AC_ATTRIBUTE_free(AC_ATTRIBUTE *a)
00884 {
00885   if (a == NULL) return;
00886 
00887   ASN1_OCTET_STRING_free(a->name);
00888   ASN1_OCTET_STRING_free(a->value);
00889   ASN1_OCTET_STRING_free(a->qualifier);
00890 
00891   OPENSSL_free(a);
00892 }
00893 
00894 int i2d_AC_ATT_HOLDER(AC_ATT_HOLDER *a, unsigned char **pp)
00895 {
00896   M_ASN1_I2D_vars(a);
00897   M_ASN1_I2D_len(a->grantor,      i2d_GENERAL_NAMES);
00898 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
00899   M_ASN1_I2D_len_SEQUENCE_type(AC_ATTRIBUTE, a->attributes, i2d_AC_ATTRIBUTE);
00900   M_ASN1_I2D_seq_total();
00901   M_ASN1_I2D_put(a->grantor, i2d_GENERAL_NAMES);
00902   M_ASN1_I2D_put_SEQUENCE_type(AC_ATTRIBUTE, a->attributes, i2d_AC_ATTRIBUTE);
00903 #elif (OPENSSL_VERSION_NUMBER >= 0x0090800fL)
00904   M_ASN1_I2D_len_SEQUENCE_type(AC_ATTRIBUTE, a->attributes, (int (*)(void*, unsigned char**))i2d_AC_ATTRIBUTE);
00905   M_ASN1_I2D_seq_total();
00906   M_ASN1_I2D_put(a->grantor, i2d_GENERAL_NAMES);
00907   M_ASN1_I2D_put_SEQUENCE_type(AC_ATTRIBUTE, a->attributes, (int (*)(void*, unsigned char**))i2d_AC_ATTRIBUTE);
00908 #else
00909   M_ASN1_I2D_len_SEQUENCE(a->attributes, (int(*)())i2d_AC_ATTRIBUTE);
00910   M_ASN1_I2D_seq_total();
00911   M_ASN1_I2D_put(a->grantor, i2d_GENERAL_NAMES);
00912   M_ASN1_I2D_put_SEQUENCE(a->attributes, (int(*)())i2d_AC_ATTRIBUTE);
00913 #endif
00914   M_ASN1_I2D_finish();
00915 }
00916 
00917 AC_ATT_HOLDER *d2i_AC_ATT_HOLDER(AC_ATT_HOLDER **a, SSLCONST unsigned char **pp, long length)
00918 {
00919   M_ASN1_D2I_vars(a, AC_ATT_HOLDER *, AC_ATT_HOLDER_new);
00920 
00921   M_ASN1_D2I_Init();
00922   M_ASN1_D2I_start_sequence();
00923   M_ASN1_D2I_get(ret->grantor, d2i_GENERAL_NAMES);
00924 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
00925   M_ASN1_D2I_get_seq_type(AC_ATTRIBUTE, *ret->attributes, d2i_AC_ATTRIBUTE, AC_ATTRIBUTE_free);
00926 #else
00927   M_ASN1_D2I_get_seq_type(AC_ATTRIBUTE, ret->attributes, (AC_ATTRIBUTE* (*)())d2i_AC_ATTRIBUTE, AC_ATTRIBUTE_free);
00928 #endif
00929   M_ASN1_D2I_Finish(a, AC_ATT_HOLDER_free, ASN1_F_D2I_AC_ATT_HOLDER);
00930 }
00931 
00932 AC_ATT_HOLDER *AC_ATT_HOLDER_new()
00933 {
00934   AC_ATT_HOLDER *ret = NULL;
00935   ASN1_CTX c;
00936 
00937   M_ASN1_New_Malloc(ret, AC_ATT_HOLDER);
00938   M_ASN1_New(ret->grantor, sk_GENERAL_NAME_new_null);
00939   M_ASN1_New(ret->attributes, sk_AC_ATTRIBUTE_new_null);
00940   return ret;
00941 
00942   M_ASN1_New_Error(AC_F_AC_ATT_HOLDER_New);
00943 }
00944 
00945 void AC_ATT_HOLDER_free(AC_ATT_HOLDER *a)
00946 {
00947   if (a == NULL) return;
00948 
00949   sk_GENERAL_NAME_pop_free(a->grantor, GENERAL_NAME_free);
00950   sk_AC_ATTRIBUTE_pop_free(a->attributes, AC_ATTRIBUTE_free);
00951   OPENSSL_free(a);
00952 }
00953 
00954 int i2d_AC_FULL_ATTRIBUTES(AC_FULL_ATTRIBUTES *a, unsigned char **pp)
00955 {
00956   M_ASN1_I2D_vars(a);
00957 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
00958   M_ASN1_I2D_len_SEQUENCE_type(AC_ATT_HOLDER, a->providers, i2d_AC_ATT_HOLDER);
00959   M_ASN1_I2D_seq_total();
00960   M_ASN1_I2D_put_SEQUENCE_type(AC_ATT_HOLDER, a->providers, i2d_AC_ATT_HOLDER);
00961 #elif (OPENSSL_VERSION_NUMBER >= 0x0090800fL)
00962   M_ASN1_I2D_len_SEQUENCE_type(AC_ATT_HOLDER, a->providers, (int (*)(void*, unsigned char**))i2d_AC_ATT_HOLDER);
00963   M_ASN1_I2D_seq_total();
00964   M_ASN1_I2D_put_SEQUENCE_type(AC_ATT_HOLDER, a->providers, (int (*)(void*, unsigned char**))i2d_AC_ATT_HOLDER);
00965 #else
00966   M_ASN1_I2D_len_SEQUENCE(a->providers, (int (*)())i2d_AC_ATT_HOLDER);
00967   M_ASN1_I2D_seq_total();
00968   M_ASN1_I2D_put_SEQUENCE(a->providers, (int (*)())i2d_AC_ATT_HOLDER);
00969 #endif
00970   M_ASN1_I2D_finish();
00971 }
00972 
00973 AC_FULL_ATTRIBUTES *d2i_AC_FULL_ATTRIBUTES(AC_FULL_ATTRIBUTES **a, SSLCONST unsigned char **pp, long length)
00974 {
00975   M_ASN1_D2I_vars(a, AC_FULL_ATTRIBUTES *, AC_FULL_ATTRIBUTES_new);
00976 
00977   M_ASN1_D2I_Init();
00978   M_ASN1_D2I_start_sequence();
00979 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
00980   M_ASN1_D2I_get_seq_type(AC_ATT_HOLDER, *ret->providers, d2i_AC_ATT_HOLDER, AC_ATT_HOLDER_free);
00981 #else
00982   M_ASN1_D2I_get_seq_type(AC_ATT_HOLDER, ret->providers, (AC_ATT_HOLDER* (*)())d2i_AC_ATT_HOLDER, AC_ATT_HOLDER_free);
00983 #endif
00984   M_ASN1_D2I_Finish(a, AC_FULL_ATTRIBUTES_free, ASN1_F_D2I_AC_FULL_ATTRIBUTES);
00985 }
00986 
00987 AC_FULL_ATTRIBUTES *AC_FULL_ATTRIBUTES_new()
00988 {
00989   AC_FULL_ATTRIBUTES *ret = NULL;
00990   ASN1_CTX c;
00991 
00992   M_ASN1_New_Malloc(ret, AC_FULL_ATTRIBUTES);
00993   M_ASN1_New(ret->providers, sk_AC_ATT_HOLDER_new_null);
00994   return ret;
00995   M_ASN1_New_Error(AC_F_AC_FULL_ATTRIBUTES_New);
00996 }
00997 
00998 void AC_FULL_ATTRIBUTES_free(AC_FULL_ATTRIBUTES *a)
00999 {
01000   if (a == NULL) return;
01001 
01002   sk_AC_ATT_HOLDER_pop_free(a->providers, AC_ATT_HOLDER_free);
01003   OPENSSL_free(a);
01004 }
01005 
01006 static char *norep()
01007 {
01008   static char buffer[] = "";
01009 
01010 /*   buffer=malloc(1); */
01011 /*   if (buffer) */
01012 /*     *buffer='\0'; */
01013   return buffer;
01014 }
01015 
01016 char *acseq_i2s(struct v3_ext_method*, void*)
01017 {
01018   return norep();
01019 }
01020   
01021 char *targets_i2s(struct v3_ext_method*, void*)
01022 {
01023   return norep();
01024 }
01025 
01026 char *certs_i2s(struct v3_ext_method*, void*)
01027 {
01028   return norep();
01029 }
01030 
01031 char *null_i2s(struct v3_ext_method*, void*)
01032 {
01033   return norep();
01034 }
01035 
01036 char *attributes_i2s(struct v3_ext_method*, void*)
01037 {
01038   return norep();
01039 }
01040 
01041 void *acseq_s2i(struct v3_ext_method*, struct v3_ext_ctx*, char *data)
01042 {
01043   AC **list = (AC **)data;
01044   AC_SEQ *a;
01045 
01046   if (!list) return NULL;
01047 
01048   a = AC_SEQ_new();
01049 
01050   while (*list)
01051     sk_AC_push(a->acs, *list++);
01052 
01053   return (void *)a;
01054 }
01055 
01056 void *targets_s2i(struct v3_ext_method*, struct v3_ext_ctx*, char *data)
01057 {
01058   char *pos;
01059   char *list = strdup(data);
01060   AC_TARGETS *a = AC_TARGETS_new();
01061 
01062   int attlist;
01063   do {
01064     pos = strchr(list, ',');
01065     if (pos)
01066       *pos = '\0';
01067     {
01068       GENERAL_NAME *g = GENERAL_NAME_new();
01069       ASN1_IA5STRING *tmpr = ASN1_IA5STRING_new();
01070       AC_TARGET *targ = AC_TARGET_new();
01071 
01072       if (!g || !tmpr || !targ) {
01073         GENERAL_NAME_free(g);
01074         ASN1_IA5STRING_free(tmpr);
01075         AC_TARGET_free(targ);
01076         goto err;
01077       }
01078       ASN1_STRING_set(tmpr, list, strlen(list));
01079       g->type = GEN_URI;
01080       g->d.ia5 = tmpr;
01081       targ->name = g;
01082       sk_AC_TARGET_push(a->targets, targ);
01083       attlist++;
01084     }
01085     if (pos)
01086       list = pos++;
01087   } while (pos);
01088 
01089   return a;
01090 
01091  err:
01092   AC_TARGETS_free(a);
01093   return NULL;    
01094 
01095 }
01096 
01097 void *certs_s2i(struct v3_ext_method*, struct v3_ext_ctx*, char *data)
01098 {
01099   STACK_OF(X509) *certs =
01100     (STACK_OF(X509) *)data;
01101   int i = 0;
01102 
01103   if (data) {
01104     AC_CERTS *a = AC_CERTS_new();
01105 
01106     sk_X509_pop_free(a->stackcert, X509_free);
01107     a->stackcert = sk_X509_new_null();
01108 
01109 /*     a->stackcert = sk_X509_dup(certs); */
01110     for (i =0; i < sk_X509_num(certs); i++)
01111       sk_X509_push(a->stackcert, X509_dup(sk_X509_value(certs, i)));
01112 
01113     return a;
01114   }
01115 
01116   return NULL;    
01117 }
01118 
01119 void *attributes_s2i(struct v3_ext_method*, struct v3_ext_ctx*, char *data)
01120 {
01121   int i = 0;
01122 
01123   STACK_OF(AC_ATT_HOLDER) *stack =
01124     (STACK_OF(AC_ATT_HOLDER) *)data;
01125 
01126   if (data) {
01127     AC_FULL_ATTRIBUTES *a = AC_FULL_ATTRIBUTES_new();
01128     sk_AC_ATT_HOLDER_pop_free(a->providers, AC_ATT_HOLDER_free);
01129     a->providers = sk_AC_ATT_HOLDER_new_null();
01130 /*     a->providers = sk_AC_ATT_HOLDER_dup(stack); */
01131     for (i = 0; i < sk_AC_ATT_HOLDER_num(stack); i++)
01132 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
01133       sk_AC_ATT_HOLDER_push(a->providers,
01134            ASN1_dup_of(AC_ATT_HOLDER, i2d_AC_ATT_HOLDER,
01135            d2i_AC_ATT_HOLDER,
01136            sk_AC_ATT_HOLDER_value(stack, i)));
01137 #elif (OPENSSL_VERSION_NUMBER >= 0x0090800fL)
01138       sk_AC_ATT_HOLDER_push(a->providers,
01139            (AC_ATT_HOLDER *)ASN1_dup((int (*)(void*, unsigned char**))i2d_AC_ATT_HOLDER,
01140            (void*(*)(void**, const unsigned char**, long int))d2i_AC_ATT_HOLDER,
01141            (char *)(sk_AC_ATT_HOLDER_value(stack, i))));
01142 #else
01143       sk_AC_ATT_HOLDER_push(a->providers,
01144            (AC_ATT_HOLDER *)ASN1_dup((int (*)())i2d_AC_ATT_HOLDER,
01145            (char * (*)())d2i_AC_ATT_HOLDER,
01146            (char *)(sk_AC_ATT_HOLDER_value(stack, i))));
01147 #endif
01148     
01149     return a;
01150   }
01151   return NULL;
01152 }
01153 
01154 void *null_s2i(struct v3_ext_method*, struct v3_ext_ctx*, char*)
01155 {
01156   return ASN1_NULL_new();
01157 }
01158 
01159 char *authkey_i2s(struct v3_ext_method*, void*)
01160 {
01161   return norep();
01162 }
01163 
01164 void *authkey_s2i(struct v3_ext_method*, struct v3_ext_ctx*, char *data)
01165 {
01166   X509       *cert = (X509 *)data;
01167   char digest[21];
01168 
01169   ASN1_OCTET_STRING *str = ASN1_OCTET_STRING_new();
01170   AUTHORITY_KEYID *keyid = AUTHORITY_KEYID_new();
01171 
01172   if (str && keyid) {
01173     SHA1(cert->cert_info->key->public_key->data,
01174         cert->cert_info->key->public_key->length,
01175         (unsigned char*)digest);
01176     ASN1_OCTET_STRING_set(str, (unsigned char*)digest, 20);
01177     ASN1_OCTET_STRING_free(keyid->keyid);
01178     keyid->keyid = str;
01179   }
01180   else {
01181     if (str) ASN1_OCTET_STRING_free(str);
01182     if (keyid) AUTHORITY_KEYID_free(keyid);
01183     keyid = NULL;
01184   }
01185   return keyid;
01186 }
01187 
01188 
01189 IMPL_STACK(AC_IETFATTR)
01190 IMPL_STACK(AC_IETFATTRVAL)
01191 IMPL_STACK(AC_ATTR)
01192 IMPL_STACK(AC)
01193 IMPL_STACK(AC_INFO)
01194 IMPL_STACK(AC_VAL)
01195 IMPL_STACK(AC_HOLDER)
01196 IMPL_STACK(AC_ACI)
01197 IMPL_STACK(AC_FORM)
01198 IMPL_STACK(AC_IS)
01199 IMPL_STACK(AC_DIGEST)
01200 IMPL_STACK(AC_TARGETS)
01201 IMPL_STACK(AC_TARGET)
01202 IMPL_STACK(AC_CERTS)
01203 
01204 IMPL_STACK(AC_ATTRIBUTE)
01205 IMPL_STACK(AC_ATT_HOLDER)
01206 IMPL_STACK(AC_FULL_ATTRIBUTES)
01207 
01208 
01209 X509V3_EXT_METHOD * VOMSAttribute_auth_x509v3_ext_meth() {
01210   static X509V3_EXT_METHOD vomsattribute_auth_x509v3_ext_meth =
01211   {
01212     -1,
01213     0,  
01214     NULL, 
01215     (X509V3_EXT_NEW) AUTHORITY_KEYID_new,
01216     (X509V3_EXT_FREE) AUTHORITY_KEYID_free,
01217     (X509V3_EXT_D2I) d2i_AUTHORITY_KEYID,
01218     (X509V3_EXT_I2D) i2d_AUTHORITY_KEYID,
01219     (X509V3_EXT_I2S) authkey_i2s, 
01220     (X509V3_EXT_S2I) authkey_s2i,
01221     NULL,
01222     NULL,
01223     NULL,
01224     NULL,
01225     NULL
01226   };
01227   return (&vomsattribute_auth_x509v3_ext_meth);
01228 }
01229 
01230 X509V3_EXT_METHOD * VOMSAttribute_avail_x509v3_ext_meth() {
01231   static X509V3_EXT_METHOD vomsattribute_avail_x509v3_ext_meth =
01232   {
01233     -1,
01234     0,  
01235     NULL,
01236     (X509V3_EXT_NEW) ASN1_NULL_new,
01237     (X509V3_EXT_FREE) ASN1_NULL_free,
01238     (X509V3_EXT_D2I) d2i_ASN1_NULL,
01239     (X509V3_EXT_I2D) i2d_ASN1_NULL,
01240     (X509V3_EXT_I2S) null_i2s, 
01241     (X509V3_EXT_S2I) null_s2i,
01242     NULL,
01243     NULL,
01244     NULL,
01245     NULL,
01246     NULL
01247   };
01248   return (&vomsattribute_avail_x509v3_ext_meth);
01249 }  
01250 
01251 X509V3_EXT_METHOD * VOMSAttribute_targets_x509v3_ext_meth() {
01252   static X509V3_EXT_METHOD vomsattribute_targets_x509v3_ext_meth =
01253   {
01254     -1,
01255     0,  
01256     NULL,
01257     (X509V3_EXT_NEW) AC_TARGETS_new,
01258     (X509V3_EXT_FREE) AC_TARGETS_free,
01259     (X509V3_EXT_D2I) d2i_AC_TARGETS,
01260     (X509V3_EXT_I2D) i2d_AC_TARGETS,
01261     (X509V3_EXT_I2S) targets_i2s, 
01262     (X509V3_EXT_S2I) targets_s2i,
01263     NULL,
01264     NULL,
01265     NULL,
01266     NULL,
01267     NULL
01268   };
01269   return (&vomsattribute_targets_x509v3_ext_meth);
01270 }  
01271 
01272 X509V3_EXT_METHOD * VOMSAttribute_acseq_x509v3_ext_meth() {
01273   static X509V3_EXT_METHOD vomsattribute_acseq_x509v3_ext_meth =
01274   {
01275     -1,
01276     0,  
01277     NULL,
01278     (X509V3_EXT_NEW) AC_SEQ_new,
01279     (X509V3_EXT_FREE) AC_SEQ_free,
01280     (X509V3_EXT_D2I) d2i_AC_SEQ,
01281     (X509V3_EXT_I2D) i2d_AC_SEQ,
01282     (X509V3_EXT_I2S) acseq_i2s, 
01283     (X509V3_EXT_S2I) acseq_s2i,
01284     NULL,
01285     NULL,
01286     NULL,
01287     NULL,
01288     NULL
01289   };
01290   return (&vomsattribute_acseq_x509v3_ext_meth);
01291 }  
01292 
01293 X509V3_EXT_METHOD * VOMSAttribute_certseq_x509v3_ext_meth() {
01294   static X509V3_EXT_METHOD vomsattribute_certseq_x509v3_ext_meth =
01295   {
01296     -1,
01297     0,  
01298     NULL,
01299     (X509V3_EXT_NEW) AC_CERTS_new,
01300     (X509V3_EXT_FREE) AC_CERTS_free,
01301     (X509V3_EXT_D2I) d2i_AC_CERTS,
01302     (X509V3_EXT_I2D) i2d_AC_CERTS,
01303     (X509V3_EXT_I2S) certs_i2s, 
01304     (X509V3_EXT_S2I) certs_s2i,
01305     NULL,
01306     NULL,
01307     NULL,
01308     NULL,
01309     NULL
01310   };
01311   return (&vomsattribute_certseq_x509v3_ext_meth);
01312 }  
01313 
01314 X509V3_EXT_METHOD * VOMSAttribute_attribs_x509v3_ext_meth() {
01315   static X509V3_EXT_METHOD vomsattribute_attribs_x509v3_ext_meth =
01316   {
01317     -1,
01318     0,
01319     NULL,
01320     (X509V3_EXT_NEW) AC_FULL_ATTRIBUTES_new,
01321     (X509V3_EXT_FREE) AC_FULL_ATTRIBUTES_free,
01322     (X509V3_EXT_D2I) d2i_AC_FULL_ATTRIBUTES,
01323     (X509V3_EXT_I2D) i2d_AC_FULL_ATTRIBUTES,
01324     (X509V3_EXT_I2S) attributes_i2s,  
01325     (X509V3_EXT_S2I) attributes_s2i,
01326     NULL,
01327     NULL,
01328     NULL,
01329     NULL,
01330     NULL
01331   };
01332   return (&vomsattribute_attribs_x509v3_ext_meth);
01333 }
01334 
01335 } //namespace ArcCredential