From: Jonathon McKitrick
Subject: How to convert data for use by Ironclad?
Date: 
Message-ID: <1143474119.041582.97290@i39g2000cwa.googlegroups.com>
I'd like to use Ironclad for md5 hashing and http authentication.  Is
there a simple or straight-forward way to convert the string values I
get from http into (simple-array (unsigned-byte 8) (*))?

I keep thinking I've figured this out, but I'm not quite there yet.

(defparameter *data* (make-array 8 :element-type :unsigned-byte
:adjustable nil :fill-pointer nil :displaced-to nil))

works, but

(ironclad:update-digest *digest* *data*)

complains that #(0 0 0 0 0 0 0 0) is not of type (simple-array
(unsigned-byte 8) (*))

and

(type-of *data*) is (simple-vector 8)
and

(type-of (elt *data* 0)) is bit.


Any thoughts?  Much appreciated.

From: Zach Beane
Subject: Re: How to convert data for use by Ironclad?
Date: 
Message-ID: <m3y7yv282b.fsf@unnamed.xach.com>
"Jonathon McKitrick" <···········@bigfoot.com> writes:

> I'd like to use Ironclad for md5 hashing and http authentication.  Is
> there a simple or straight-forward way to convert the string values I
> get from http into (simple-array (unsigned-byte 8) (*))?

Strings generally have more than one possible representation as a
vector of octets. Most implementations that support characters with
character codes >255 also provide some nonstandard way to convert
strings to vectors with a given external format. In Allegro and SBCL
it is named STRING-TO-OCTETS. CLISP provides CONVERT-STRING-TO-BYTES.

The Flexi-Streams package also makes it easy to produce octet vectors
from strings in a portable way. It is located here:

   http://weitz.de/flexi-streams/

Zach
From: Jonathon McKitrick
Subject: Re: How to convert data for use by Ironclad?
Date: 
Message-ID: <1143485301.126242.96230@i39g2000cwa.googlegroups.com>
Zach Beane wrote:
> "Jonathon McKitrick" <···········@bigfoot.com> writes:
>
> > I'd like to use Ironclad for md5 hashing and http authentication.  Is
> > there a simple or straight-forward way to convert the string values I
> > get from http into (simple-array (unsigned-byte 8) (*))?
>
> it is named STRING-TO-OCTETS. CLISP provides CONVERT-STRING-TO-BYTES.

Thanks, that did the trick.

Does anyone know the order in which browsers apply the md5 hash to
username, nonce, and password?  I assume I have to do the same,
correct?
From: Zach Beane
Subject: Re: How to convert data for use by Ironclad?
Date: 
Message-ID: <m3slp31z1k.fsf@unnamed.xach.com>
"Jonathon McKitrick" <···········@bigfoot.com> writes:

> Does anyone know the order in which browsers apply the md5 hash to
> username, nonce, and password?  I assume I have to do the same,
> correct?

This is specified in RFC 2617.

Zach
From: Jonathon McKitrick
Subject: Re: How to convert data for use by Ironclad?
Date: 
Message-ID: <1143490280.547012.6380@j33g2000cwa.googlegroups.com>
> This is specified in RFC 2617.

That seems like a very error-prone approach.  In other words, if I get
one character wrong, I'll never know which one.

Is this the only way?  Is there a tool that can help here?
From: Zach Beane
Subject: Re: How to convert data for use by Ironclad?
Date: 
Message-ID: <m3mzfb1vl8.fsf@unnamed.xach.com>
"Jonathon McKitrick" <···········@bigfoot.com> writes:

> > This is specified in RFC 2617.
> 
> That seems like a very error-prone approach.  In other words, if I get
> one character wrong, I'll never know which one.
> 
> Is this the only way?  Is there a tool that can help here?

The standard that defines a protocol is a good place to start when you
decide to implement software compatible with the protocol. What did
you expect instead?

Zach
From: Jonathon McKitrick
Subject: Re: How to convert data for use by Ironclad?
Date: 
Message-ID: <1143492743.202284.146940@g10g2000cwb.googlegroups.com>
Zach Beane wrote:

> The standard that defines a protocol is a good place to start when you
> decide to implement software compatible with the protocol. What did
> you expect instead?

Perhaps a tool that would let me build a response piece by piece and
check it along the way, rather than a chicken-and-egg.  Right now, I
can't check my code until I implement the algorithm.  I can't implement
the algorithm until I check my code.
From: Zach Beane
Subject: Re: How to convert data for use by Ironclad?
Date: 
Message-ID: <m3hd5j1trw.fsf@unnamed.xach.com>
"Jonathon McKitrick" <···········@bigfoot.com> writes:

> Zach Beane wrote:
> 
> > The standard that defines a protocol is a good place to start when you
> > decide to implement software compatible with the protocol. What did
> > you expect instead?
> 
> Perhaps a tool that would let me build a response piece by piece and
> check it along the way, rather than a chicken-and-egg.  Right now, I
> can't check my code until I implement the algorithm.  I can't implement
> the algorithm until I check my code.

This is not a chicken-and-egg problem. First you write the code, then
you test and refine it until it works.

Zach
From: Rob Warnock
Subject: Re: How to convert data for use by Ironclad?
Date: 
Message-ID: <aMKdnSZvfq3UJbXZnZ2dnUVZ_tWdnZ2d@speakeasy.net>
Jonathon McKitrick <···········@bigfoot.com> wrote:
+---------------
| I'd like to use Ironclad for md5 hashing and http authentication.  Is
| there a simple or straight-forward way to convert the string values I
| get from http into (simple-array (unsigned-byte 8) (*))?
| 
| I keep thinking I've figured this out, but I'm not quite there yet.
| 
|   (defparameter *data* (make-array 8 :element-type :unsigned-byte
|                 :adjustable nil :fill-pointer nil :displaced-to nil))
| works, but
|   (ironclad:update-digest *digest* *data*)
| complains that
|   #(0 0 0 0 0 0 0 0) is not of type (simple-array (unsigned-byte 8) (*))
| and
|   (type-of *data*) is (simple-vector 8)
| and
|   (type-of (elt *data* 0)) is bit.
+---------------

The problem is probably that your MAKE-ARRAY is insufficiently-specific
to get what you need. Try executing:

    (upgraded-array-element-type 'unsigned-byte)

and see what your local implementation gives you back -- probably T,
but almost certainly *NOT* (UNSIGNED-BYTE 8)!!  So try this instead:

    > (defparameter *data* (make-array 8 :element-type '(unsigned-byte 8)
					 :initial-element 0))

    *DATA*
    > *data*

    #(0 0 0 0 0 0 0 0)
    > (type-of *data*)

    (SIMPLE-ARRAY (UNSIGNED-BYTE 8) (8))
    > (type-of (elt *data* 0))

    (INTEGER 0 0)
    > 

It would probably also be good to add an ":INITIAL-ELEMENT 0" to your
MAKE-ARRAY [as I did above], rather than assuming the implementation
will default it for you, since:

    If initial-element is not supplied, the consequences of
    later reading an uninitialized element of new-array are
    undefined unless either initial-contents is supplied or
    displaced-to is non-nil.

Conversely, since NIL *is* defined as the default for all of
the :ADJUSTABLE, :FILL-POINTER, & :DISPLACED-TO parameters,
you don't need to specify them here.


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Ivan Boldyrev
Subject: Re: How to convert data for use by Ironclad?
Date: 
Message-ID: <8v0nf3-sl5.ln1@ibhome.cgitftp.uiggm.nsc.ru>
On 9426 day of my life Jonathon McKitrick wrote:
> I keep thinking I've figured this out, but I'm not quite there yet.
>
> (defparameter *data* (make-array 8 :element-type :unsigned-byte
> :adjustable nil :fill-pointer nil :displaced-to nil))

> Any thoughts?  Much appreciated.

There is no such type as :UNSIGNED-BYTE.

-------------------------------------------------------+
                                                       |
                                                       |
                                                       V
(defparameter *data* (make-array 8 :element-type 'unsigned-byte
                                   :adjustable nil
                                   :fill-pointer nil
                                    :displaced-to nil))

-- 
Ivan Boldyrev

                                                  Your bytes are bitten.