[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: (ITS#6741)



The ITS doesn't really handle MIME messages very well. Please just follow the 
guidelines on the OpenLDAP web site.

http://www.openldap.org/devel/contributing.html


jgcardoso@seguridata.com wrote:
> This is a multi-part message in MIME format.
>
> ------_=_NextPart_001_01CBA7B8.A7EC1D62
> Content-Type: text/plain;
> 	charset="us-ascii"
> Content-Transfer-Encoding: quoted-printable
>
> I created a function to support conversion from DER BitString encoded
> data to RFC4517 Bit String Format.
>
> I tested it alone and it seems to work fine with normal and abnormal
> situations.
>
> =20
>
> I also wrote a proposal to the call that must be included at
> ldap_X509dn2bv() function.
>
> =20
>
> First comes the conversion function and after comes the proposal.
>
> =20
>
> =20
>
> /*****************************************************/
>
> =20
>
> #define BITS_PER_BYTE     8
>
> #define SQUOTE_LENGTH     1
>
> #define B_CHAR_LENGTH     1
>
> #define STR_OVERHEAD    (2*SQUOTE_LENGTH + B_CHAR_LENGTH)
>
> =20
>
> int ldap_der_to_rfc4517_BitString (struct berval *berValue,
>
>                                     struct berval *rfc4517Value) {
>
>
> ber_len_t bitPadding=3D0;
>
> ber_len_t bits, maxBits;
>
> char *tmpStr;
>
> unsigned char byte;
>
> ber_len_t bitLength;
>
> ber_len_t valLen;
>
> unsigned char* valPtr;
>
> =20
>
>     rfc4517Value->bv_len=3D0;
>
>     rfc4517Value->bv_val=3DNULL;
>
> =20
>
>     /* Gets padding and points to binary data */
>
>     valLen=3DberValue->bv_len;
>
>     valPtr=3D(unsigned char*)berValue->bv_val;
>
>     if (valLen) {
>
>        bitPadding=3D(ber_len_t)(valPtr[0]);
>
>        valLen--;
>
>        valPtr++;
>
>     }
>
>     /* If Block is non DER encoding fixes to DER encoding */
>
>     if (bitPadding>=3D BITS_PER_BYTE) {
>
>        if (valLen*BITS_PER_BYTE>  bitPadding ) {
>
>           valLen-=3D(bitPadding/BITS_PER_BYTE);
>
>           bitPadding%=3DBITS_PER_BYTE;
>
>        } else {
>
>           valLen=3D0;
>
>           bitPadding=3D0;
>
>        }
>
>     }
>
>     /* Just in case bad encoding */
>
>     if (valLen*BITS_PER_BYTE<  bitPadding ) {
>
>        bitPadding=3D0;
>
>        valLen=3D0;
>
>     }
>
> =20
>
>     /* Gets buffer to hold RFC4517 Bit String format */
>
>     bitLength=3DvalLen*BITS_PER_BYTE-bitPadding;
>
>     tmpStr=3DLDAP_MALLOC(bitLength + STR_OVERHEAD + 1);
>
>    =20
>
>     if (!tmpStr)
>
>        return LDAP_NO_MEMORY;
>
> =20
>
>     rfc4517Value->bv_val=3DtmpStr;
>
>     rfc4517Value->bv_len=3DbitLength + STR_OVERHEAD;
>
> =20
>
>     /* Formatting in '*binary-digit'B format */
>
>     maxBits=3DBITS_PER_BYTE;
>
>     *tmpStr=3D'\'';
>
>     tmpStr++;
>
>     while(valLen) {
>
>        byte=3D*valPtr;
>
>        if (valLen=3D=3D1)
>
>           maxBits-=3DbitPadding;
>
>        for (bits=3D0; bits<maxBits; bits++) {
>
>           if (0x80&  byte)
>
>              *tmpStr=3D'1';
>
>           else
>
>              *tmpStr=3D'0';
>
>           tmpStr++;
>
>           byte<<=3D1;
>
>        }
>
>        valPtr++;
>
>        valLen--;
>
>     }
>
>     *tmpStr=3D'\'';
>
>     tmpStr++;
>
>     *tmpStr=3D'B';
>
>     tmpStr++;
>
>     *tmpStr=3D0;
>
> =20
>
>     return LDAP_SUCCESS;
>
> }
>
> =20
>
> =20
>
> /*****************************************************/
>
> /*****************************************************/
>
> =20
>
> =20
>
> /*
>
> * Other tags found in AVAs (X.520)
>
> */
>
> #define LBER_TAG_BITSTRING     ((ber_tag_t) 0x03UL)
>
> =20
>
> =20
>
> ldap_X509dn2bv function updated:
>
> =20
>
>                  switch(tag) {
>
>                  case LBER_TAG_UNIVERSAL:
>
>                       /* This uses 32-bit ISO 10646-1 */
>
>                       csize =3D 4; goto to_utf8;
>
>                  case LBER_TAG_BMP:
>
>                       /* This uses 16-bit ISO 10646-1 */
>
>                       csize =3D 2; goto to_utf8;
>
>                  case LBER_TAG_BITSTRING:
>
>                       /* X.690 bitString value converted to RFC4517 Bit
> String */
>
>                       rc =3D ldap_der_to_rfc4517_BitString(&Val,
> &newAVA->la_value );
>
>                       goto after_utf8;
>
>                  case LBER_TAG_TELETEX:
>
>                       /* This uses 8-bit, assume ISO 8859-1 */
>
>                       csize =3D 1;
>
> to_utf8:             rc =3D ldap_ucs_to_utf8s(&Val, csize,
> &newAVA->la_value );
>
> after_utf8:          newAVA->la_flags |=3D LDAP_AVA_FREE_VALUE;
>
>                       if (rc !=3D LDAP_SUCCESS) goto nomem;
>
>                       newAVA->la_flags =3D LDAP_AVA_NONPRINTABLE;
>
>                       break;
>
>                  case LBER_TAG_UTF8:
>
>                       newAVA->la_flags =3D LDAP_AVA_NONPRINTABLE;
>
>                       /* This is already in UTF-8 encoding */
>
>                  case LBER_TAG_IA5:
>
>                  case LBER_TAG_PRINTABLE:
>
>                       /* These are always 7-bit strings */
>
>                       newAVA->la_value =3D Val;
>
>                  default:
>
>                       ;
>
>                  }
>
> =20
>
>
> ------_=_NextPart_001_01CBA7B8.A7EC1D62
> Content-Type: text/html;
> 	charset="us-ascii"
> Content-Transfer-Encoding: quoted-printable
>
> <html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
> xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
> xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
> xmlns:x=3D"urn:schemas-microsoft-com:office:excel" =


-- 
   -- Howard Chu
   CTO, Symas Corp.           http://www.symas.com
   Director, Highland Sun     http://highlandsun.com/hyc/
   Chief Architect, OpenLDAP  http://www.openldap.org/project/