Radikant Cert C

Device Screen

A lightweight and fast ASN.1 encoder/decoder prototype library written in C, with no external dependencies.

ASN1

If  not enabled all logging macros expand to empty loops and will be removed from the binary.

X509

Filter debug messages at runtime to prevent verbose screen

PEM

Abstracts mutex locking to ensure log messages don't get scrambled when accessed by multiple threads.

Encoding

Define Log Levels, the macros will remove unused logging functions from runtime.

Decoding

Use context instances, allow different parts of your program to have different log levels.

Mint cert

Log to one ore more files as astream simultaneously and independentily withouth any issues

Encoding


        asn1_encoder_t ctx;
        asn1_encoder_init(&ctx, buffer, sizeof(buffer));
        const uint8_t hello_str[] = "hello";
        asn1_encode_octet_string(&ctx, hello_str, sizeof(hello_str) - 1);
        asn1_encode_integer(&ctx, -123);
        size_t content_len = sizeof(buffer) - ctx.current_pos;
        asn1_encode_tag_and_length(&ctx, ASN1_TAG_SEQUENCE, content_len);
        const uint8_t* data = asn1_encoder_get_data(&ctx, &final_len);
    
Encoded 13 bytes: 30 0B 02 02 FF 85 04 05 68 65 6C 6C 6F Dumping encoded structure: 0 : Tag=0x30 (SEQUENCE) Length=11 0 : Tag=0x02 (INTEGER) Length=2 Value: -123 (0xffffffffffffff85) 4 : Tag=0x04 (OCTET STRING) Length=5 Data: 68:65:6C:6C:6F:
§

Create the sender and reciever tasks, create the scheduler with a tickrate of 1 ms . Pass the reciever task handle as user data to the sender task. The sender task is now “aware” of the recievers taskhandle and can send messages

Decoding


	asn1_decoder_t ctx;
	asn1_decoder_init(&ctx, encoded_data, final_len);
	asn1_decoder_t seq_ctx;
	asn1_decoder_enter_constructed(&ctx, &seq_ctx, ASN1_TAG_SEQUENCE);
	int64_t int_val;
	asn1_decode_integer(&seq_ctx, &int_val);
	const uint8_t* str_data;
	size_t str_len;
	asn1_decode_string_like(&seq_ctx, ASN1_TAG_OCTET_STRING, &str_data, &str_len);
    
Decoding encoded structure: - Read INTEGER: -123 - Read OCTET STRING: 'hello' Encode/decode test successful.

Dereference the reciever task handle from user data. Create a static stack variable and send data to the reciever using its dereferenced taskhandle.

Extract key

Key Length: 2048 bits Modulus (n) (256 bytes): DB29967347219CA9D4E117B915704304E8CDCC190E4E5B7A974DB668C7D37379 3B294E5D2E8F4E57F5D50235A2193EFF2F818770808040FFE23BE0C133B4053C 39BA1193DA110B14446917F8139909DFE0E41AE35B5CC7A9A8F677C90ABCF0AD 30D02252BBF58F578D596358B91F260FD1970C66C93EBA3E4097BA5CFF87E404 A5C50C84F116A0EFC5385A4DD1B255E2F022604019AFCD02D631CDE22EA4E78E D889F95639D1C2DDA4C6F965B485C3F07B7AD544F2E6BC3690D46566F75BEEEE 7B75FAFE5572DFADD79365F2C92E546D1D4D0D7A2CA9BF67973C68F8EAA8C3B9 7F44C088F3B6C1598797D465ADBF86795CE72F4E147799DB6D47B1E5FF375065 Exponent (e): 65537 (0x10001)
Key Length: 2048 bits Modulus (n) (256 bytes): DB29967347219CA9D4E117B915704304E8CDCC190E4E5B7A974DB668C7D37379 3B294E5D2E8F4E57F5D50235A2193EFF2F818770808040FFE23BE0C133B4053C 39BA1193DA110B14446917F8139909DFE0E41AE35B5CC7A9A8F677C90ABCF0AD 30D02252BBF58F578D596358B91F260FD1970C66C93EBA3E4097BA5CFF87E404 A5C50C84F116A0EFC5385A4DD1B255E2F022604019AFCD02D631CDE22EA4E78E D889F95639D1C2DDA4C6F965B485C3F07B7AD544F2E6BC3690D46566F75BEEEE 7B75FAFE5572DFADD79365F2C92E546D1D4D0D7A2CA9BF67973C68F8EAA8C3B9 7F44C088F3B6C1598797D465ADBF86795CE72F4E147799DB6D47B1E5FF375065 Exponent (e): 65537 (0x10001)


Parse Cert


    asn1_error_t err = x509_parse_and_print_certificate(
        github_der, 
        sizeof(github_der), 
        0
    );

    
=================================== Parsing Github.com Certificate... =================================== Certificate (SEQUENCE): TBSCertificate (SEQUENCE): Version: [0] EXPLICIT Value: 2 (v3) Serial Number: 00:AB:66:86:B5:62:7B:E8:05:96:82:13:30:12:86:49:F5 Algorithm: ecdsa-with-SHA256 (1.2.840.10045.4.3.2) Issuer: countryName (2.5.4.6) Value: 'GB' stateOrProvinceName (2.5.4.8) Value: 'Greater Manchester' localityName (2.5.4.7) Value: 'Salford' organizationName (2.5.4.10) Value: 'Sectigo Limited' commonName (2.5.4.3) Value: 'Sectigo ECC Domain Validation Secure Server CA' Validity: Not Before: '250205000000Z' Not After : '260205235959Z' Subject: commonName (2.5.4.3) Value: 'github.com' Subject Public Key Info: Algorithm: ecPublicKey (1.2.840.10045.2.1) Parameters: (Skipped) Public Key (Unused Bits: 0): 04:20:34:5C:46:FF:2C:CB:F8:24:9A:AE:F0:BB:2F:77: A9:1F:97:21:36:71:BA:C2:26:18:C5:1E:43:FD:9D:49: E0:CC:46:9C:85:FC:29:B4:F9:7C:28:0B:A3:2C:C7:5C: BF:6F:E7:46:DD:04:8A:BA:CB:80:2D:37:88:0D:EE:06: D6 Extensions: [3] EXPLICIT Extension OID: authorityKeyIdentifier (2.5.29.35) Value (OCTET STRING): 30:16:80:14:F6:85:0A:3B:11:86:E1:04:7D:0E:AA:0B:2C:D2:EE:CC:64:7B:7B:AE Extension OID: subjectKeyIdentifier (2.5.29.14) Value (OCTET STRING): 04:14:53:C8:7F:DE:9E:98:4E:C7:4D:D6:BC:DE:AB:95:3E:30:3D:3D:D1:C8 Extension OID: keyUsage (2.5.29.15) Critical: TRUE Value (OCTET STRING): 03:02:07:80 Extension OID: basicConstraints (2.5.29.19) Critical: TRUE Value (OCTET STRING): 30:00 Extension OID: extendedKeyUsage (2.5.29.37) Value (OCTET STRING): 30:14:06:08:2B:06:01:05:05:07:03:01:06:08:2B:06:01:05:05:07:03:02 Extension OID: certificatePolicies (2.5.29.32) Value (OCTET STRING): 30:40:30:34:06:0B:2B:06:01:04:01:B2:31:01:02:02: 07:30:25:30:23:06:08:2B:06:01:05:05:07:02:01:16: 17:68:74:74:70:73:3A:2F:2F:73:65:63:74:69:67:6F: 2E:63:6F:6D:2F:43:50:53:30:08:06:06:67:81:0C:01: 02:01 Extension OID: authorityInfoAccess (1.3.6.1.5.5.7.1.1) Value (OCTET STRING): 30:76:30:4F:06:08:2B:06:01:05:05:07:30:02:86:43: 68:74:74:70:3A:2F:2F:63:72:74:2E:73:65:63:74:69: 67:6F:2E:63:6F:6D:2F:53:65:63:74:69:67:6F:45:43: 43:44:6F:6D:61:69:6E:56:61:6C:69:64:61:74:69:6F: 6E:53:65:63:75:72:65:53:65:72:76:65:72:43:41:2E: 63:72:74:30:23:06:08:2B:06:01:05:05:07:30:01:86: 17:68:74:74:70:3A:2F:2F:6F:63:73:70:2E:73:65:63: 74:69:67:6F:2E:63:6F:6D Extension OID: SCT List (Sectigo) (1.3.6.1.4.1.22112.2.4.2) Value (OCTET STRING): 04:82:01:6A:01:68:00:75:00:96:97:64:BF:55:58:97: AD:F7:43:87:68:37:08:42:77:E9:F0:3A:D5:F6:A4:F3: 36:6E:46:A4:3F:0F:CA:A9:C6:00:00:01:94:D3:6B:94: 4B:00:00:04:03:00:46:30:44:02:20:3B:8B:AA:3E:2E: 94:23:B7:A0:1E:12:39:6D:1E:1B:3F:4E:21:02:9C:77: 74:C5:37:9E:AF:FD:EF:0F:5C:60:B0:02:20:62:51:B0: 46:8B:7E:4A:A1:01:0A:CF:FF:7E:BC:7F:60:74:CF:C2: 8C:7D:40:B7:72:EC:68:D3:2D:61:DF:70:C0:00:77:00: 19:86:D4:C7:28:AA:6F:FE:BA:03:6F:78:2A:4D:01:91: AA:CE:2D:72:31:0F:AE:CE:5D:70:41:2D:25:4C:C7:D4: 00:00:01:94:D3:6B:93:ED:00:00:04:03:00:48:30:46: 02:21:00:E5:AC:89:F1:EC:9F:B7:31:FA:A0:C4:1D:BE: 16:FA:B7:74:C9:64:D6:A8:F8:72:13:B0:FF:E1:E4:61: 57:C6:D0:02:21:00:C4:FE:24:A0:10:7D:4B:88:74:11: B1:7E:BC:AB:1A:BC:2C:38:3D:E9:46:CD:6D:C8:0C:B2: 91:D3:C6:46:0B:13:00:76:00:CB:38:F7:15:89:7C:84: A1:44:5F:5B:C1:DD:FB:C9:6E:F2:9A:59:CD:47:0A:69: 05:85:B0:CB:14:C3:14:58:E7:00:00:01:94:D3:6B:94: 25:00:00:04:03:00:47:30:45:02:21:00:D4:62:96:F7: 66:A0:0C:53:49:21:8A:CC:1F:78:1A:25:D5:EC:74:85: 69:51:C6:4E:7F:11:F5:16:4B:1B:B8:B1:02:20:52:42: 7E:C9:48:36:17:39:DD:0D:13:20:C2:47:75:C1:4E:5B: 6B:60:1B:8B:41:03:57:4B:F3:CD:6D:5D:B3:27 Extension OID: subjectAltName (2.5.29.17) Value (decoded SubjectAltName): DNS Name: 'github.com' DNS Name: 'www.github.com' Algorithm: ecdsa-with-SHA256 (1.2.840.10045.4.3.2) Signature Value (Unused Bits: 0): 30:44:02:20:71:8C:A7:6E:C1:04:12:75:DF:9E:A5:09: ED:96:63:2C:D8:22:9F:DF:00:E3:50:33:70:24:78:4F: DF:CA:6D:2C:02:20:6D:55:F3:77:62:02:19:FA:77:87: 11:FC:1C:46:18:73:E2:E0:E9:73:C1:7E:B4:A9:AD:71: E5:89:4A:27:0C:90 =================================== Successfully parsed certificate.