wstrange / asn1lib

Dart ASN1 Encoder / Decoder
BSD 2-Clause "Simplified" License
30 stars 30 forks source link

'dirName' is not recognized as an ASN.1 object. #67

Closed sbrsubuvga closed 4 months ago

sbrsubuvga commented 5 months ago
const template = '''
# ------------------------------------------------------------------
# Default section for "req" command options
# ------------------------------------------------------------------
[req]
# Password for reading in existing private key file
# input_password = SET_PRIVATE_KEY_PASS
# Prompt for DN field values and CSR attributes in ASCII
prompt = no
utf8 = no
# Section pointer for DN field options
distinguished_name = my_req_dn_prompt
# Extensions
req_extensions = v3_req
[ v3_req ]
#basicConstraints=CA:FALSE
#keyUsage = digitalSignature, keyEncipherment
# Production or Testing Template (TSTZATCA-Code-Signing - ZATCA-Code-Signing)
1.3.6.1.4.1.311.20.2 = ASN1:UTF8String:SET_PRODUCTION_VALUE
subjectAltName=dirName:dir_sect
[ dir_sect ]
# EGS Serial number (1-SolutionName|2-ModelOrVersion|3-serialNumber)
SN = SET_EGS_SERIAL_NUMBER
# VAT Registration number of TaxPayer (Organization identifier [15 digits begins with 3 and ends with 3])
UID = SET_VAT_REGISTRATION_NUMBER
# Invoice type (TSCZ)(1 = supported, 0 not supported) (Tax, Simplified, future use, future use)
title = 0100
# Location (branch address or website)
registeredAddress = SET_BRANCH_LOCATION
# Industry (industry sector name)
businessCategory = SET_BRANCH_INDUSTRY
# ------------------------------------------------------------------
# Section for prompting DN field values to create "subject"
# ------------------------------------------------------------------
[my_req_dn_prompt]
# Common name (EGS TaxPayer PROVIDED ID [FREE TEXT])
commonName = SET_COMMON_NAME
# Organization Unit (Branch name)
organizationalUnitName = SET_BRANCH_NAME
# Organization name (Tax payer name)
organizationName = SET_TAXPAYER_NAME
# ISO2 country code is required with US as default
countryName = SA
'''; 

getting an error "'dirName' is not recognized as an ASN.1 object." when i generate this template's ASN.1 Object

wstrange commented 5 months ago

Hi It is not clear what you are trying to do here. Can you provide a code sample, or even better, a test case?

sbrsubuvga commented 5 months ago
     var sanExtSeq = ASN1Sequence();
      sanExtSeq.add(ASN1ObjectIdentifier.fromName('dirName'));
    ASN1Sequence dirName = ASN1Sequence(elements: [
        // Add ASN.1 objects for each field using appropriate types from basic_utils
        ASN1UTF8String(utf8StringValue:'1-haya|2-234|3-354'), // Replace with actual EGS serial number
        ASN1UTF8String(utf8StringValue:'310175397400003'), // Replace with actual VAT number
        ASN1Integer(BigInt.from(100)), // Assuming title is an integer (replace with actual value)
        ASN1UTF8String(utf8StringValue:'0000 Zatca 3, Khobar'), // Replace with actual branch location
        ASN1UTF8String(utf8StringValue: 'Food'), // Replace with actual branch industry
      ]);

getting an error "'dirName' is not recognized as an ASN.1 object.

This is the ASN1Object i need. Screenshot from 2024-04-15 13-11-42 Screenshot from 2024-04-15 13-12-24

wstrange commented 5 months ago

Have a look at the test https://github.com/wstrange/asn1lib/blob/5932416c36a881d6b21071f73c31729162de0cc8/test/asn1objectidentifier_test.dart#L173

If looks like dirName has to be registered first.

Does that help?

wstrange commented 4 months ago

@sbrsubuvga Did the above hint solve your problem? If so, can you close this issue.

wstrange commented 4 months ago

Closing this pending more feedback. Please feel free to reopen if this is still an issue