EldoS | Feel safer!

Software components for data protection, secure storage and transfer

DER Decoder

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#28704
Posted: 03/06/2014 08:33:19
by Achille Nana Chimi (Basic support level)
Joined: 03/06/2014
Posts: 4

Hi,

i'm a new user of this library (.NET) and i am looking for one function, that can decode DER-Format (Byte[]) in readable Plain-Text Format.

TElClientTSPInfo timeStampToken = new TElClientTSPInfo();

//don't ignore bad signatures
timeStampToken.IgnoreBadSignature = false;

timeStampToken.ParseCMS(loadedtimeStampTokenFromFile);

DateTime dt = timeStampToken.Time;

byte[] serialNumberByte = timeStampToken.SerialNumber;

//Do something here to decode DER

string serialNumberString = System.Text.Encoding.UTF8.GetString(serialNumberByte);

serialNumberString must be in pain-text.

This is with BouncyCastle by initializing TimeStampToken done.

Is any function for that?

Regards
#28705
Posted: 03/06/2014 08:44:02
by Vsevolod Ievgiienko (EldoS Corp.)

Thank you for contacting us.

TElClientTSPInfo.SerialNumber is an array of bytes. Its not DER encoded. You can convert such array to a string using SBUtils.Unit.BinaryToString method.
#28717
Posted: 03/07/2014 04:39:55
by Achille Nana Chimi (Basic support level)
Joined: 03/06/2014
Posts: 4

Thank you for a quick anwser.

After replace a line
string serialNumberString = System.Text.Encoding.UTF8.GetString(serialNumberByte);
by
string serialNumberString = SBUtils.Unit.BinaryToString(serialNumberByte);
the result is something like 00800327370000014178528BE27A0CB8A6. But i want to convert it as decimal number like 914.

Is here any Documentation for class SBUtils.Unit?

please help.

Regards
#28718
Posted: 03/07/2014 04:47:21
by Vsevolod Ievgiienko (EldoS Corp.)

You can do this next way:

Code
BigInteger b = new BigInteger(serialNumberByte);
string serialNumberString = b.ToString();
#28719
Posted: 03/07/2014 06:08:45
by Achille Nana Chimi (Basic support level)
Joined: 03/06/2014
Posts: 4

I think i shall explain my problem from begin.

i habe a signed data (signed timestamp) as file. this file is a TimeStampToken (TST) according to RFC3161. I want to verfy if this timestamp for a given document (.zip for example). The timestamp ist stored in a .tsp file.

now i want to get all informations abort this TST in plain text-format for initializing variables in my a class that i write my self. i don't want any coded information in this class. i want to use only string, int.

For example

Code
int serialNumberbyte = 914;
string algorith = "RSA";


Question: How schould i process?

I process like this to verifiy:

Code
       //convert a timestamp file as byte array
            byte[] timestampByte = File.ReadAllBytes(fullFilenameOfTimestamp);

            //provide access to every timestamp in the form of the instance of TElClientTSPInfo class
            TElMessageVerifier telMessageVerifier = new TElMessageVerifier();

            byte[] outBuffer = new byte[timestampByte.Length];

            int outBufferSize = timestampByte.Length;

            //This method verifies and extract digitally signed data
            int proccessingMessageNo = telMessageVerifier.Verify(timestampByte, ref outBuffer, ref outBufferSize);

            if (proccessingMessageNo != 0)
            {
                //LogErrors(proccessingMessageNo);

                return;
            }

            //set a extracted TimeStamp with buffered length
            byte[] extractedTimestampByte = new byte[outBufferSize];

            //copy fully from outBuffer to extractedTimestampByte
            Buffer.BlockCopy(outBuffer, 0, extractedTimestampByte, 0, outBufferSize);
         
         //Convert to binary to String
            string s1 = SBUtils.Unit.BinaryToString(timestampByte);

            //Convert to binary to String
            string s2 = SBUtils.Unit.BinaryToString(extractedTimestampByte);
;

Question:
1) Is my Code logicaly correct?

2)Wath's intern diference beetween timestampByte and extractedTimestampByte (or between s1 and s2 )?

3) How schould i get each attrubute of telMessageVerifier as string/int plain text?

i do like this but i'm not able to interprete a result:

Code
            string t2;

            int tag;

            //Use this function to extract the real attribute value from the ASN.1 structure
            byte[] t1 = SBASN1Tree.Unit.UnformatAttributeValue(extractedTimestampToken, out tag);

            //how schoul i derminate a also a lenght

            //Determinate if t1 (object) is a Sequence, SET, PrintableString, etc..
            // do it like this, but wath schould do in case to a a plain text or a specified data structure
             switch (tag)
            {

                case SBASN1Tree.Unit.SB_ASN1_BOOLEAN:
                     //TODO
                    break;
                case SBASN1Tree.Unit.SB_ASN1_GENERALIZEDTIME:
                    //TODO
                    break;
                case SBASN1Tree.Unit.SB_ASN1_ENUMERATED:
                    //TODO
                    break;
                case SBASN1Tree.Unit.SB_ASN1_INTEGER:
                    //TODO
                    break;
                case SBASN1Tree.Unit.SB_ASN1_OCTETSTRING:
                    //TODO
                    break;
                case SBASN1Tree.Unit.SB_ASN1_SEQUENCE:
                    //TODO
                    break;
                case SBASN1Tree.Unit.SB_ASN1_OBJECT:
                    //TODO
                    break;
                case SBASN1Tree.Unit.SB_ASN1_PRINTABLESTRING:
                    t2 = SBASN1Tree.Unit.ASN1ReadString(t1, tag);
                    break;
                case SBASN1Tree.Unit.SB_ASN1_SET:
                    //TODO
                    break;

            }

            //Convert to binary to String, BUT don't work (or able to interprate a result)
            string paintext = SBUtils.Unit.BinaryToString(timestampByte);
      


Regards
#28720
Posted: 03/07/2014 06:12:21
by Eugene Mayevski (EldoS Corp.)

Note, that by the standard, SerialNumber is a BLOB which can be treated as a huge integer number, but it can be huge (actually no limit on length). And it doesn't need to be sequential. So it's not a serial number, but more a Per-CA certificate ID.


Sincerely yours
Eugene Mayevski
#28721
Posted: 03/07/2014 06:22:13
by Eugene Mayevski (EldoS Corp.)

Also what you are trying to do doesn't make much sense to me.

Timestamps without signing are defined in RFC 5544 which is supported by SecureBlackbox and if you have the timestamp made using RFC 5544 procedures, you can verify it that way. If you tried to create your custom format, then you are on your own, sorry.

Now, helping you reinvent the wheel is far beyond the scope of Basic support level available to evaluating users. Your particular questions require expert services, which are offered for a fee (in addition to necessity to purchase a license).


Sincerely yours
Eugene Mayevski
#28722
Posted: 03/07/2014 06:23:36
by Achille Nana Chimi (Basic support level)
Joined: 03/06/2014
Posts: 4

Please look the last questions

Regards
#28723
Posted: 03/07/2014 06:50:52
by Eugene Mayevski (EldoS Corp.)

As said, your questions go far beyond the scope of Basic support.


Sincerely yours
Eugene Mayevski
Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages

Reply

Statistics

Topic viewed 2142 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!