ASN.1 Decoder UNIX Code


 
Thread Tools Search this Thread
Top Forums Programming ASN.1 Decoder UNIX Code
# 8  
Old 02-10-2014
Quote:
Originally Posted by teefa
my case i got a schema and a binary file , i need to decode it (thats simply)

sorry for asking alot Smilie . so i need the decoder , while i gcc for the decoder it got error related to the efi.h , kindly help
Sorry but I am not going to do all your work for you. As I said to you before you need to remove or replace the EFI related code. That is something you are expected to be capable of doing. If you do not wish to do that, simply find other source code for an ASN.1 decoder. A simple Internet search will return many sources of ASN.1 decoder source code.
# 9  
Old 02-12-2014
seem you don't know how to use it and you cant know how to reply me ,, i got a schema and binary file
my target is to decode this binary file with the given schema , how would i use this thing
by gcc -o any xxx.c getting errors including header after including header in compiling it get errors related to the code , what part to change or what i can do i dont any and you just say i wont do yr work , any tool got steps or any details how to use it the only file can be compiled its the x509.asn , what can i do with it nothing
# 10  
Old 02-12-2014
Thread moved to programming... has nothing to do with shell scripting stuff...
# 11  
Old 02-15-2014
ok , shall any one reply me how to use it
# 12  
Old 02-16-2014
Given your apparent difficulties following my GNU_EFI ASN.1 X.509 parser code, here is an example of another way to parse X509 .pem files using the OpenSSL development library.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

#include <openssl/pem.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>


int 
main(int argc, char *argv[])
{
    FILE *fp = NULL;
    char *filename;
    struct stat fstat;

    if (argc != 2) {
        fprintf(stdout, "ERROR - No filename provided\n");
        exit(1);
    }

    filename = argv[1];

    if ((stat(filename, &fstat) != 0) || (fp = fopen(filename, "r")) == NULL) {
        fprintf(stdout, "ERROR - File could not be opened\n");
        exit(1);
    }

    // parse certificate
    X509 *cert = PEM_read_X509(fp, NULL, NULL, NULL);
    if (!cert) {
        fprintf(stderr, "ERROR - Unable to parse certificate\n");
        fclose(fp);
        exit(1);
    }
    
    // version number
    int version = ((int) X509_get_version(cert)) + 1;
    printf("Version: %d\n", version);

    // serial number
    ASN1_INTEGER *serial = X509_get_serialNumber(cert);
    
    BIGNUM *bn = ASN1_INTEGER_to_BN(serial, NULL);
    if (!bn) {
        fprintf(stderr, "ERROR - Unable to convert ASN1INTEGER to BN\n");
        exit(1);
    }
    
    char *tmp = BN_bn2dec(bn);
    if (!tmp) {
        fprintf(stderr, "ERROR - Unable to convert BN to decimal string\n");
        BN_free(bn);
        exit(1);
    }
    
    printf("Serial Number: %s\n", tmp);

    BN_free(bn);
    OPENSSL_free(tmp);

    // subject
    tmp = X509_NAME_oneline(X509_get_subject_name(cert), NULL, 0);
    printf("Subject: %s\n", tmp);
    OPENSSL_free(tmp);

    // issuer
    tmp = X509_NAME_oneline(X509_get_issuer_name(cert), NULL, 0);
    printf("Issuer: %s\n", tmp);
    OPENSSL_free(tmp);

    // signature algorithm
    int pkey_nid = OBJ_obj2nid(cert->cert_info->key->algor->algorithm);
    if (pkey_nid == NID_undef) {
        fprintf(stderr, "ERROR - Signature algorithm name\n");
        exit(1);
    }

    const char* buf  = OBJ_nid2ln(pkey_nid);
    printf("Algorithm: %s\n", buf);

    X509_free(cert);
    fclose(fp);
}

This User Gave Thanks to fpmurphy For This Post:
# 13  
Old 02-16-2014
thanks alot , but if this code is in a file named code.c , how will i use it
i got a schema and binary.air file
shall i gcc -o code.sh code.c
then code.sh binary schema > output

kindly tell me if you dont understand what i want
# 14  
Old 02-16-2014
I have no idea what you want as you never bothered to explain it to us in detail. It seems that you now wish to decode an Abobe AIR binary using an ASN.1 schema. Is this correct?

Vague query:
Quote:
i got a schema and binary file. my target is to decode this binary file with the given schema
Just having a schema is not sufficient to decode a binary file. That is only the start of the required work. That is just a blueprint for the layout of the various elements that make up the binary file.

You need to provide specific information on what you want if you want specific answers. Vague information leads to vague answers. What schema? What type of binary file? What language do you wish to code in?

Last edited by fpmurphy; 02-16-2014 at 11:13 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Python Programming for ASN.1 file

Hi. Has anyone here got an experience doing conversion from asn1 format to a readable format so that it can be processed by Oracle? I want to load the data into a table. This is a CDR file. Attached is the pairing file. Please remove the .txt at the end. Someone said that it is possible... (1 Reply)
Discussion started by: aimy
1 Replies

2. Solaris

ASN Binary to ASCII

Dears, I need help to convert the binary file into ASCII format. Actually we have CDRs which is generated by telecom switch at this is in ASN1 format or binary format, I need to convert those binary formatted file into ASCII format using Perl, or shell scripting. Is there any way to solve... (3 Replies)
Discussion started by: PRINCESS_RORO
3 Replies

3. Programming

ASN.1 decoder

Hi All, I am fairly new to this so please forgive me, Currently I have an ASN.1 which I would like the ability to load this to my work server in order to enter a string of output decode and display the output. There are methods online as shown on ASN.1 JavaScript decoder however I have... (3 Replies)
Discussion started by: mutley2202
3 Replies

4. UNIX for Dummies Questions & Answers

core file decoder needed

All, Remotely logged in to the UNIX server (HP B1000 Visual Server) (Version HP-UX 10.20) by using the program Xapplauncher. This is a application runs under Exceed. (Exceed "version 6.1" is a Windows application to communicate with UNIX servers) With no pre warnings the application was... (2 Replies)
Discussion started by: pbekker
2 Replies
Login or Register to Ask a Question