Main Page | Modules | Data Structures | File List | Data Fields | Globals

ProxyPolicy

Data Structures

Get a method for ASN1 conversion

New

Free

Duplicate

Compare

Print to a BIO stream

Print to a File Stream

Set the Policy Language Field

Get the Policy Language Field

Set the Policy Field

Get the Policy Field

Convert from Internal to DER encoded form

Convert from DER encoded form to Internal


Detailed Description

Author:
Sam Meder

Sam Lang

The proxypolicy set of data structures and functions provides an interface to generating a PROXYPOLICY structure which is maintained as a field in the PROXYCERTINFO structure, and ultimately gets written to a DER encoded string.

See also:
Further Information about proxy policies is available in the Internet Draft Document:
draft-ietf-pkix-proxy-01.txt

Function Documentation

ASN1_METHOD* PROXYPOLICY_asn1_meth (
)
 

Creates an ASN1_METHOD structure, which contains pointers to routines that convert any PROXYPOLICY structure to its associated ASN1 DER encoded form and vice-versa.

Returns:
the ASN1_METHOD object

Definition at line 40 of file proxypolicy.c.

References d2i_PROXYPOLICY(), i2d_PROXYPOLICY(), PROXYPOLICY_free(), and PROXYPOLICY_new().

00041 {
00042     static ASN1_METHOD proxypolicy_asn1_meth =
00043     {
00044         (int (*)())   i2d_PROXYPOLICY,
00045         (char *(*)()) d2i_PROXYPOLICY,
00046         (char *(*)()) PROXYPOLICY_new,
00047         (void (*)())  PROXYPOLICY_free
00048     };
00049     return (&proxypolicy_asn1_meth);
00050 }

PROXYPOLICY* PROXYPOLICY_new (
)
 

Allocates and initializes a new PROXYPOLICY structure.

Returns:
pointer to the new PROXYPOLICY

Definition at line 65 of file proxypolicy.c.

References ASN1_F_PROXYPOLICY_NEW, IMPERSONATION_PROXY_SN, PROXYPOLICY_st::policy, PROXYPOLICY_st::policy_language, and PROXYPOLICY.

Referenced by d2i_PROXYPOLICY(), PROXYCERTINFO_new(), PROXYPOLICY_asn1_meth(), and PROXYPOLICY_x509v3_ext_meth().

00066 {
00067     ASN1_CTX                            c;
00068     PROXYPOLICY *                       ret;
00069 
00070     ret = NULL;
00071 
00072     M_ASN1_New_Malloc(ret, PROXYPOLICY);
00073     ret->policy_language = OBJ_nid2obj(OBJ_sn2nid(IMPERSONATION_PROXY_SN));
00074     ret->policy = NULL;
00075     return (ret);
00076     M_ASN1_New_Error(ASN1_F_PROXYPOLICY_NEW);
00077 }

void PROXYPOLICY_free (
     PROXYPOLICY * policy )
 

Frees a PROXYPOLICY

Parameters:
policy the proxy policy to free

Definition at line 93 of file proxypolicy.c.

References PROXYPOLICY_st::policy, PROXYPOLICY_st::policy_language, and PROXYPOLICY.

Referenced by d2i_PROXYPOLICY(), PROXYPOLICY_asn1_meth(), and PROXYPOLICY_x509v3_ext_meth().

00095 {
00096     if(policy == NULL) return;
00097     ASN1_OBJECT_free(policy->policy_language);
00098     M_ASN1_OCTET_STRING_free(policy->policy);
00099     OPENSSL_free(policy);
00100 }

PROXYPOLICY* PROXYPOLICY_dup (
     PROXYPOLICY * policy )
 

Makes a copy of the proxypolicy - this function allocates space for a new PROXYPOLICY, so the returned PROXYPOLICY must be freed when its no longer needed

Parameters:
policy the proxy policy to copy
Returns:
the new PROXYPOLICY

Definition at line 121 of file proxypolicy.c.

References d2i_PROXYPOLICY(), i2d_PROXYPOLICY(), and PROXYPOLICY.

Referenced by PROXYCERTINFO_set_policy().

00123 {
00124     return ((PROXYPOLICY *) ASN1_dup((int (*)())i2d_PROXYPOLICY,
00125                                      (char *(*)())d2i_PROXYPOLICY,
00126                                      (char *)policy));
00127 }

int PROXYPOLICY_cmp (
     const PROXYPOLICY * a,
     const PROXYPOLICY * b)
 

Compares two PROXYPOLICY structs for equality This function first compares the policy language numeric id's, if they're equal, it then compares the two policies.

Returns:
0 if equal, nonzero if not

Definition at line 145 of file proxypolicy.c.

References PROXYPOLICY_st::policy, PROXYPOLICY_st::policy_language, and PROXYPOLICY.

Referenced by PROXYCERTINFO_cmp().

00148 {
00149     
00150     if((a->policy_language->nid != b->policy_language->nid) ||
00151        ASN1_STRING_cmp((ASN1_STRING *)a->policy, (ASN1_STRING *)b->policy))
00152     {
00153         return 1;
00154     }
00155     return 0;
00156 }

int PROXYPOLICY_print (
     BIO * bp,
     PROXYPOLICY * policy)
 

Prints the PROXYPOLICY struct using the BIO stream

Parameters:
bp the BIO stream to print to
policy the PROXYPOLICY to print
Returns:
1 on success, 0 on error

Definition at line 174 of file proxypolicy.c.

References PROXYPOLICY, PROXYPOLICY_x509v3_ext_meth(), and STACK_OF().

Referenced by PROXYPOLICY_print_fp().

00177 {
00178     STACK_OF(CONF_VALUE) *              values = NULL;
00179 
00180     values = i2v_PROXYPOLICY(PROXYPOLICY_x509v3_ext_meth(),
00181                              policy,
00182                              values);
00183     
00184     X509V3_EXT_val_prn(bp, values, 0, 1);
00185     
00186     sk_CONF_VALUE_pop_free(values, X509V3_conf_free);
00187     return 1;
00188 }

int PROXYPOLICY_print_fp (
     FILE * fp,
     PROXYPOLICY * policy)
 

Prints the PROXYPOLICY to the file stream FILE*

Parameters:
fp the FILE* stream to print to
policy the PROXYPOLICY to print
Returns:
number of bytes printed, -2 or -1 on error

Definition at line 206 of file proxypolicy.c.

References PROXYPOLICY, and PROXYPOLICY_print().

00209 {
00210     int                                 ret;
00211 
00212     BIO * bp = BIO_new(BIO_s_file());    
00213     BIO_set_fp(bp, fp, BIO_NOCLOSE);
00214     ret = PROXYPOLICY_print(bp, policy);
00215     BIO_free(bp);
00216 
00217     return (ret);
00218 }

int PROXYPOLICY_set_policy_language (
     PROXYPOLICY * policy,
     ASN1_OBJECT * policy_language)
 

Sets the policy language of the PROXYPOLICY

Parameters:
policy the PROXYPOLICY to set the policy language of
policy_language the policy language to set it to
Returns:
1 on success, 0 on error

Definition at line 236 of file proxypolicy.c.

References PROXYPOLICY_st::policy_language, and PROXYPOLICY.

00239 {
00240     if(policy_language != NULL) 
00241     {
00242         ASN1_OBJECT_free(policy->policy_language);
00243         policy->policy_language = OBJ_dup(policy_language);
00244         return 1;
00245     }
00246     return 0;
00247 }

ASN1_OBJECT* PROXYPOLICY_get_policy_language (
     PROXYPOLICY * policy )
 

Gets the policy language of the PROXYPOLICY

Parameters:
policy the proxy policy to get the policy language of
Returns:
the policy language as an ASN1_OBJECT

Definition at line 264 of file proxypolicy.c.

References PROXYPOLICY_st::policy_language, and PROXYPOLICY.

Referenced by STACK_OF().

00266 {
00267     return policy->policy_language;
00268 }

int PROXYPOLICY_set_policy (
     PROXYPOLICY * proxypolicy,
     unsigned char * policy,
     int length)
 

Sets the policy of the PROXYPOLICY

Parameters:
proxypolicy the proxy policy to set the policy of
policy the policy to set it to
length the lenght of the policy
Returns:
1 on success, 0 on error

Definition at line 286 of file proxypolicy.c.

References PROXYPOLICY_st::policy, and PROXYPOLICY.

00290 {
00291     if(policy != NULL)
00292     {
00293         unsigned char *                 copy = malloc(length);
00294         memcpy(copy, policy, length);
00295 
00296         if(!proxypolicy->policy)
00297         {
00298             proxypolicy->policy = ASN1_OCTET_STRING_new();
00299         }
00300         
00301         ASN1_OCTET_STRING_set(proxypolicy->policy, copy, length);
00302 
00303     }
00304     else
00305     {
00306         if(proxypolicy->policy)
00307         {
00308             ASN1_OCTET_STRING_free(proxypolicy->policy);
00309         }
00310     }
00311 
00312     return 1;
00313 }

unsigned char* PROXYPOLICY_get_policy (
     PROXYPOLICY * policy,
     int * length)
 

Gets the policy of a PROXYPOLICY

Parameters:
policy the PROXYPOLICY to get the policy of
length the length of the returned policy - this value gets set by this function
Returns:
the policy

Definition at line 332 of file proxypolicy.c.

References PROXYPOLICY_st::policy, and PROXYPOLICY.

Referenced by STACK_OF().

00335 {
00336     if(policy->policy)
00337     { 
00338         (*length) = policy->policy->length;
00339         if(*length > 0 && policy->policy->data)
00340         {
00341             unsigned char *                 copy = malloc(*length);
00342             memcpy(copy, policy->policy->data, *length);
00343             return copy;
00344         }
00345     }
00346     
00347     return NULL;
00348 }

int i2d_PROXYPOLICY (
     PROXYPOLICY * a,
     unsigned char ** pp)
 

Converts a PROXYPOLICY from its internal structure to a DER encoded form

Parameters:
a the PROXYPOLICY to convert
pp the buffer to put the DER encoding in
Returns:
the length of the DER encoding in bytes

Definition at line 367 of file proxypolicy.c.

References PROXYPOLICY_st::policy, PROXYPOLICY_st::policy_language, and PROXYPOLICY.

Referenced by i2d_PROXYCERTINFO(), i2d_PROXYCERTINFO_OLD(), PROXYPOLICY_asn1_meth(), PROXYPOLICY_dup(), and PROXYPOLICY_x509v3_ext_meth().

00370 {
00371     M_ASN1_I2D_vars(a);
00372 
00373     M_ASN1_I2D_len(a->policy_language, i2d_ASN1_OBJECT);
00374 
00375     if(a->policy)
00376     { 
00377         M_ASN1_I2D_len(a->policy, i2d_ASN1_OCTET_STRING);
00378     }
00379     
00380     M_ASN1_I2D_seq_total();
00381     M_ASN1_I2D_put(a->policy_language, i2d_ASN1_OBJECT);
00382     if(a->policy)
00383     { 
00384         M_ASN1_I2D_put(a->policy, i2d_ASN1_OCTET_STRING);
00385     }
00386     M_ASN1_I2D_finish();
00387 }

PROXYPOLICY* d2i_PROXYPOLICY (
     PROXYPOLICY ** a,
     unsigned char ** pp,
     long length)
 

Converts the PROXYPOLICY from its DER encoded form to an internal PROXYPOLICY structure

Parameters:
a the PROXYPOLICY struct to set
pp the DER encoding to get the PROXYPOLICY from
length the length of the DER encoding
Returns:
the resulting PROXYPOLICY in its internal structure form - this variable has been allocated using _new routines, so it needs to be freed once its no longer used

Definition at line 409 of file proxypolicy.c.

References ASN1_F_D2I_PROXYPOLICY, PROXYPOLICY, PROXYPOLICY_free(), and PROXYPOLICY_new().

Referenced by d2i_PROXYCERTINFO(), d2i_PROXYCERTINFO_OLD(), PROXYPOLICY_asn1_meth(), PROXYPOLICY_dup(), and PROXYPOLICY_x509v3_ext_meth().

00413 {
00414     M_ASN1_D2I_vars(a, PROXYPOLICY *, PROXYPOLICY_new);
00415     
00416     M_ASN1_D2I_Init();
00417     M_ASN1_D2I_start_sequence();
00418     M_ASN1_D2I_get(ret->policy_language, d2i_ASN1_OBJECT);
00419 
00420     /* need to try getting the policy using
00421      *     a) a call expecting no tags
00422      *     b) a call expecting tags
00423      * one of which should succeed
00424      */
00425     
00426     M_ASN1_D2I_get_opt(ret->policy,
00427                        d2i_ASN1_OCTET_STRING,
00428                        V_ASN1_OCTET_STRING);
00429     
00430     M_ASN1_D2I_get_IMP_opt(ret->policy,
00431                            d2i_ASN1_OCTET_STRING,
00432                            0,
00433                            V_ASN1_OCTET_STRING);
00434 
00435     M_ASN1_D2I_Finish(a, 
00436                       PROXYPOLICY_free, 
00437                       ASN1_F_D2I_PROXYPOLICY);
00438 }


about globus | grid research | globus toolkit | software development

Comments? webmaster@globus.org