help-libtasn1
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PRIVATE tags handling


From: Ivan Shmakov
Subject: PRIVATE tags handling
Date: Mon, 08 Oct 2012 11:21:40 +0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

>>>>> Nikos Mavrogiannopoulos <address@hidden> writes:
>>>>> On 10/07/2012 12:50 PM, Ivan Shmakov wrote:

[…]

 >> One of the ASN.1 definitions I'm interested in is included below.
 >> (I haven't tried it against Libtasn1 yet, but it's similar enough to
 >> the example being discussed.)

 >> --cut: urn:uuid:29fb0a29-dbe3-4133-a2c6-f30e02ed71b0 --
 >> SolidStat1 ::= SEQUENCE {

[…]

 > The libtasn1 library is well tested by me on the PKIX (X.509)
 > structures.  I don't know how it would cope with your example, but I
 > see no issue there.

        Well, it looks like I've just confused a CHOICE with a SEQUENCE.
        OTOH, the SEQUENCE definition above doesn't seem to be handled
        at all (with the references to the Time and ObjectId types
        commented out):

$ printf 
'\x30\x15\x80\x01\x01\x81\x01\x02\x82\x01\x03\x85\x01\x04\x86\x01\x05\x87\x01\x06\x88\x01\x07'
 \
      | asn1Decoding solidstat1 /dev/stdin Example.SolidStat1 
Parse: done.

Decoding: TAG_ERROR
asn1Decoding: :: tag error near element 'inode.'

DECODING RESULT:
$ 

        (Where solidstat1 is MIME'd.)

        Here's a CHOICE definition from the same schema:

--cut: urn:uuid:29fb0a29-dbe3-4133-a2c6-f30e02ed71b0 --

-- SIZE (16) OF OCTET STRING?
UUID ::= OCTET STRING

Object1 ::= CHOICE {
    -- octet sequence-based objects
    uuid                   [0]  UUID,
    blob                   [1]  OCTET STRING,
    -- composite objects
    [... more fields here...]
}
--cut: urn:uuid:29fb0a29-dbe3-4133-a2c6-f30e02ed71b0 --

        (Though I perhaps should place an APPLICATION tag on the UUID
        type itself, and thus avoid the necessity of the PRIVATE tags in
        the CHOICE above altogether.)

        Such a CHOICE might be encoded like:

$ perl -we 'use strict;
            require Convert::ASN1;
            require IO::Handle;
            my $asn = Convert::ASN1->new (qw (encoding DER));
            $asn->prepare (q {
                UUID ::= OCTET STRING
                Object1 ::= CHOICE {
                    uuid [0] UUID,
                    blob [1] OCTET STRING
                }
            })
                or die ();
            my $out = \*STDOUT;
            binmode ($out);
            my $co = $asn->find ("Object1")
                or die ($asn->error ());
            my $enc = $asn->encode ({ qw (blob Foo!) })
                or die ($asn->error ());
            print $out ($enc);' \
      | od -t x1 
0000000 81 04 46 6f 6f 21
0000006
$ 

        And here's how it's handled:

$ printf '\x81\x04Foo!' | openssl asn1parse -inform DER 
    0:d=0  hl=2 l=   4 prim: cont [ 1 ]        
$ printf '\x81\x04Foo!' \
      | asn1Decoding object1 /dev/stdin Example.Object1 
Parse: done.

Decoding: DER_ERROR
asn1Decoding: 

DECODING RESULT:
$ 

-- 
FSF associate member #7257
Example { } DEFINITIONS EXPLICIT TAGS ::=

BEGIN

SolidStat1 ::= SEQUENCE {
    -- FIXME: too many integers here
    inode                  [0]  INTEGER,
    links                  [1]  INTEGER         OPTIONAL,
    type                   [2]  INTEGER         OPTIONAL,
    -- ctime                  [3]  Time,
    -- mtime                  [4]  Time,
    uid                    [5]  INTEGER         OPTIONAL,
    gid                    [6]  INTEGER         OPTIONAL,
    mode                   [7]  INTEGER         OPTIONAL,
    size                   [8]  INTEGER
    -- readlinkId             [9]  ObjectId        OPTIONAL
}

END
Example { } DEFINITIONS EXPLICIT TAGS ::=

BEGIN

-- SIZE (16) OF OCTET STRING?
UUID ::= OCTET STRING

Object1 ::= CHOICE {
    -- octet sequence-based objects
    uuid                   [0]  UUID,
    blob                   [1]  OCTET STRING
    -- composite objects
    -- ... more fields here...
}

END

reply via email to

[Prev in Thread] Current Thread [Next in Thread]