Skip to content

ASN.1

Decode ASN.1 BER/DER blobs and SNMP, Kerberos, LDAP, CMS, PKCS and OCSP messages into SQL rows

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/asn1/index.md to help me query ASN.1 with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

See what you can query

Example output · captured
Connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
SELECT p.idx, p.label, (asn1.main.well_formed(p.der)).ok AS ok, (asn1.main.well_formed(p.der)).kind AS kind, len(asn1.main.oids(p.der)) AS n_oids FROM asn1.main.pem_decode('-----BEGIN PRIVATE KEY-----' || chr(10) || 'MBYCAQAwDQYJKoZIhvcNAQEBBQAEAmhp' || chr(10) || '-----END PRIVATE KEY-----' || chr(10) || '-----BEGIN PKCS7-----' || chr(10) || 'ME0CAQExADARBgkqhkiG9w0BBwGgBAQCaGmgBTADAgEFMSwwKgIBAYAEAQIDBDALBglghkgBZQMEAgEwDQYJKoZIhvcNAQEBBQAEA6q7zA==' || chr(10) || '-----END PKCS7-----' || chr(10) || '-----BEGIN CERTIFICATE-----' || chr(10) || 'MAUC' || chr(10) || '-----END CERTIFICATE-----') AS p ORDER BY p.idx;
Result
idx label ok kind n_oids
0 PRIVATE KEY true NULL 1
1 PKCS7 true NULL 3
2 CERTIFICATE false length-overflow 0

Quick start

Choose where to run ASN.1, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach the release directly

Downloads the latest release for your platform and caches it locally.

ATTACH 'asn1' AS asn1 (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-asn1'
);

3. Run a query

query.sql
SELECT p.idx, p.label, (asn1.main.well_formed(p.der)).ok AS ok, (asn1.main.well_formed(p.der)).kind AS kind, len(asn1.main.oids(p.der)) AS n_oids FROM asn1.main.pem_decode('-----BEGIN PRIVATE KEY-----' || chr(10) || 'MBYCAQAwDQYJKoZIhvcNAQEBBQAEAmhp' || chr(10) || '-----END PRIVATE KEY-----' || chr(10) || '-----BEGIN PKCS7-----' || chr(10) || 'ME0CAQExADARBgkqhkiG9w0BBwGgBAQCaGmgBTADAgEFMSwwKgIBAYAEAQIDBDALBglghkgBZQMEAgEwDQYJKoZIhvcNAQEBBQAEA6q7zA==' || chr(10) || '-----END PKCS7-----' || chr(10) || '-----BEGIN CERTIFICATE-----' || chr(10) || 'MAUC' || chr(10) || '-----END CERTIFICATE-----') AS p ORDER BY p.idx;
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach the release directly

Uses the verified release each time you attach the connector.

ATTACH 'asn1' AS asn1 (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/[email protected]'
);

Overview

Generic ASN.1 BER/CER/DER decode plus SNMP/Kerberos/LDAP/CMS/PKCS/OCSP structural decoders for SQL.

Catalog

Everything asn1 exposes once attached — read straight from the worker's released build.

asn1 1 schema
main 1 table · 27 functions

Generic ASN.1 decode + SNMP/Kerberos/LDAP/CMS/PKCS/OCSP structural decoders.

Schema examples (14)
Examples (14)

Decode a DER `SEQUENCE { INTEGER 5 }` into its nested typed JSON projection.

SELECT asn1.main.decode(from_hex('3003020105'));

Project the same blob into self-describing JSON, one object per TLV node.

SELECT asn1.main.to_json(from_hex('3003020105'));

Render an `openssl asn1parse`-style indented text dump of the blob.

SELECT asn1.main.dump(from_hex('3003020105'));

Resolve a dotted OID to its friendly algorithm name ('sha256WithRSAEncryption').

SELECT asn1.main.oid_name('1.2.840.113549.1.1.11');
10 more examples

Triage a truncated blob — `well_formed(...).ok` is false.

SELECT (asn1.main.well_formed(from_hex('300502'))).ok;

Validate a bare INTEGER 5 under strict DER encoding rules.

SELECT asn1.main.is_valid(from_hex('020105'), 'der');

Split a three-block PEM bundle (PRIVATE KEY, PKCS7, CERTIFICATE) and triage each block's DER: well-formedness, the classified failure kind, and how many OIDs it carries. The PRIVATE KEY (1 OID) and PKCS7 (3 OIDs) blocks are well-formed; the CERTIFICATE body is truncated and flagged ok=false with kind 'length-overflow'.

SELECT p.idx, p.label, (asn1.main.well_formed(p.der)).ok AS ok, (asn1.main.well_formed(p.der)).kind AS kind, len(asn1.main.oids(p.der)) AS n_oids FROM asn1.main.pem_decode('-----BEGIN PRIVATE KEY-----' || chr(10) || 'MBYCAQAwDQYJKoZIhvcNAQEBBQAEAmhp' || chr(10) || '-----END PRIVATE KEY-----' || chr(10) || '-----BEGIN PKCS7-----' || chr(10) || 'ME0CAQExADARBgkqhkiG9w0BBwGgBAQCaGmgBTADAgEFMSwwKgIBAYAEAQIDBDALBglghkgBZQMEAgEwDQYJKoZIhvcNAQEBBQAEA6q7zA==' || chr(10) || '-----END PKCS7-----' || chr(10) || '-----BEGIN CERTIFICATE-----' || chr(10) || 'MAUC' || chr(10) || '-----END CERTIFICATE-----') AS p ORDER BY p.idx;
Result
idx label ok kind n_oids
0 PRIVATE KEY true NULL 1
1 PKCS7 true NULL 3
2 CERTIFICATE false length-overflow 0

Find the certificates a PKCS#12 keystore shares with a CMS SignedData: join the keystore's cert bags (cert_sha256) to the SHA-256 of each certificate embedded in the signed message (cms_certs). The keystore holds two certBags; only the one whose certificate is also embedded in the message (417c…d729) is returned.

SELECT b.bag_type, b.cert_sha256
FROM asn1.main.pkcs12_bags(from_hex('3079020103307406092a864886f70d010701a06704653063306106092a864886f70d010701a054045230503026060b2a864886f70d010c0a0103a0173015060a2a864886f70d01091601a007040530030201053026060b2a864886f70d010c0a0103a0173015060a2a864886f70d01091601a00704053003020106')) AS b
JOIN (SELECT unnest(asn1.main.cms_certs(from_hex('304d0201013100301106092a864886f70d010701a00404026869a0053003020105312c302a020101800401020304300b0609608648016503040201300d06092a864886f70d01010105000403aabbcc'))) AS cert) AS c ON sha256(c.cert) = b.cert_sha256
ORDER BY b.cert_sha256;

Shred a CMS SignedData's signers and join the oid_registry table to recover the dotted OIDs behind the named digest and signature algorithms (sha256 → 2.16.840.1.101.3.4.2.1, rsaEncryption → 1.2.840.113549.1.1.1).

SELECT s.digest_alg, d.oid AS digest_oid, s.sig_alg, g.oid AS sig_oid
FROM asn1.main.cms_signers(from_hex('304d0201013100301106092a864886f70d010701a00404026869a0053003020105312c302a020101800401020304300b0609608648016503040201300d06092a864886f70d01010105000403aabbcc')) AS s
LEFT JOIN asn1.main.oid_registry AS d ON d.name = s.digest_alg
LEFT JOIN asn1.main.oid_registry AS g ON g.name = s.sig_alg
ORDER BY s.signer_sid;

Canonicalize an indefinite-length BER blob with to_der, then prove the result: is_valid under strict DER is false before and true after, and decode yields the same value for both encodings. The canonical bytes are 300404024869.

SELECT asn1.main.is_valid(b, 'der') AS der_before,
  hex(asn1.main.to_der(b)) AS der_hex,
  asn1.main.is_valid(asn1.main.to_der(b), 'der') AS der_after,
  asn1.main.decode(b) = asn1.main.decode(asn1.main.to_der(b)) AS same_value
FROM (SELECT from_hex('3080040248690000') AS b) AS t;

Decode a generic DER SEQUENCE { INTEGER 5 } into its nested typed JSON projection.

SELECT asn1.main.decode(from_hex('3003020105')) AS decoded;

Resolve a dotted OID to its friendly name from the bundled registry.

SELECT asn1.main.oid_name('1.2.840.113549.1.1.11') AS name;

Decode a real SNMP GetResponse (community 'public') into JSON with its resolved varbinds.

SELECT asn1.main.snmp_decode(from_hex('302e02010104067075626c6963a2210201010201000201003016301406082b060102010101000408526f757465724f53')) AS msg;

Decode a minimal CMS ContentInfo and read its content type.

SELECT asn1.main.cms_decode(from_hex('301106092a864886f70d010701a00404026869')) AS info;
Tables
oid_registry 2 examples2 cols

The curated OBJECT IDENTIFIER → friendly-name registry as a browsable table (oid, name).

Columns
oidnot null VARCHAR
The dotted-decimal OBJECT IDENTIFIER, e.g. 1.2.840.113549.1.1.11.
namenot null VARCHAR
The friendly name the worker resolves the OID to, e.g. sha256WithRSAEncryption.
ConstraintsPRIMARY KEY (oid)
Examples (2)

Resolve one OID to its friendly name by browsing the registry table.

SELECT name FROM asn1.main.oid_registry WHERE oid = '1.2.840.113549.1.1.11';

Count the digest/signature algorithm OIDs the worker knows whose name mentions 'RSA'.

SELECT count(*) AS rsa_oids
FROM asn1.main.oid_registry
WHERE name ILIKE '%rsa%';
Link
Scalar functions
at_path (blob ANY, path VARCHAR) 1 example

Return the JSON value of the node at a JSONPath-ish path (e.g. '$.0.2') within a blob, or JSON null if the path does not resolve.

Arguments
blob ANY
The ASN.1 DER/BER/CER bytes to navigate — raw binary, or text holding those bytes.
path VARCHAR
A JSONPath-ish node locator produced by tlv(): `$` selects the root and each following `.N` descends into the N-th child (so `$.0.2` is the third child of the first child). Any depth resolves; an unmatched path yields JSON null.
ReturnsVARCHAR
Example

Pull the node at path '$.0' (the first child — the INTEGER) of a DER `SEQUENCE { INTEGER 5 }`.

SELECT asn1.main.at_path(from_hex('3003020105'), '$.0') AS node;
Link
cms_certs (blob ANY) 1 example

Return the embedded DER certificates of a CMS SignedData as a LIST(BLOB) — the join key to vgi-x509 (hash each with sha256).

Arguments
blob ANY
A CMS / PKCS#7 SignedData DER blob. Returns its embedded certificates; a non-SignedData blob yields an empty list.
ReturnsBLOB[]
Example

Extract the embedded certificate LIST<BLOB> from a CMS blob (an empty list for this minimal id-data ContentInfo, which carries no certs).

SELECT asn1.main.cms_certs(from_hex('301106092a864886f70d010701a00404026869')) AS certs;
Link
cms_content (blob ANY) 1 example

Return the encapsulated eContent (BLOB) of a CMS SignedData — often a nested CMS/DER, re-feed to decode(). NULL when absent.

Arguments
blob ANY
A CMS / PKCS#7 SignedData DER blob. Returns its eContent bytes, or NULL when detached / not a SignedData.
ReturnsBLOB
Example

Extract the encapsulated eContent BLOB from a CMS SignedData (NULL for this minimal id-data ContentInfo, which wraps no SignedData).

SELECT asn1.main.cms_content(from_hex('301106092a864886f70d010701a00404026869')) AS econtent;
Link
cms_decode (blob ANY) 1 example

Decode a CMS / PKCS#7 ContentInfo to JSON (named content_type + dispatched content).

Arguments
blob ANY
The ASN.1 DER/BER/CER bytes to decode — raw binary, or text holding those bytes. NULL input yields NULL.
ReturnsVARCHAR
Example

Decode a minimal CMS ContentInfo (content_type 'id-data') into JSON.

SELECT asn1.main.cms_decode(from_hex('301106092a864886f70d010701a00404026869')) AS info;
Link
decode (blob ANY, mode VARCHAR) +1 overload 2 examples

Decode a BER/CER/DER blob to its nested typed JSON projection (the 'auto' mode). NULL → NULL; a malformed blob yields {error,kind}. Call the two-argument overload to choose a different mode.

Arguments
blob ANY
The ASN.1 DER/BER/CER bytes to decode — raw binary, or text holding those bytes.
mode VARCHAR
Output shape: 'auto' (default), 'struct', 'json' (the nested typed JSON), or 'tlv' (the flat TLV-node list).
Overloads
decode(blob ANY) → VARCHARdecode(blob ANY, mode VARCHAR) → VARCHAR
ReturnsVARCHAR
Examples (2)

Decode a DER `SEQUENCE { INTEGER 5 }` to a nested JSON tree (yields the JSON array `[5]`).

SELECT asn1.main.decode(from_hex('3003020105')) AS decoded;

Decode a DER `SEQUENCE { INTEGER 5 }` with mode 'tlv' to its flat list of TLV nodes (path, class, tag, length, value).

SELECT asn1.main.decode(from_hex('3003020105'), 'tlv') AS nodes;
Link
dump (blob ANY, format VARCHAR) +1 overload 2 examples

Render an indented human-debug TLV dump of a blob in the default openssl asn1parse style (offset, depth, header/length, tag name, primitive value). A malformed blob renders a parse-error line, never an error. Pass a second argument to choose the 'dumpasn1' style.

Arguments
blob ANY
The ASN.1 DER/BER/CER bytes to render — raw binary, or text holding those bytes.
format VARCHAR
Dump style: 'openssl' (default, like `openssl asn1parse`) or 'dumpasn1' (Gutmann's annotated style with OID names).
Overloads
dump(blob ANY) → VARCHARdump(blob ANY, format VARCHAR) → VARCHAR
ReturnsVARCHAR
Examples (2)

Produce an openssl-asn1parse-style dump of a DER `SEQUENCE { INTEGER 5 }`.

SELECT asn1.main.dump(from_hex('3003020105')) AS text;

Dump a DER `SEQUENCE { INTEGER 5 }` in dumpasn1 (Gutmann annotated) style.

SELECT asn1.main.dump(from_hex('3003020105'), 'dumpasn1') AS text;
Link
is_valid (blob ANY, rules VARCHAR) +1 overload 2 examples

Whether a blob is well-formed under the default DER encoding rules (canonical: minimal lengths, no indefinite length). NULL → NULL; a malformed blob returns FALSE, never an error. Pass a second argument to validate as 'ber' or 'cer' instead.

Arguments
blob ANY
The ASN.1 bytes to validate — raw binary, or text holding those bytes.
rules VARCHAR
Encoding rules to validate against: 'der' (default), 'cer', or 'ber'.
Overloads
is_valid(blob ANY) → BOOLEANis_valid(blob ANY, rules VARCHAR) → BOOLEAN
ReturnsBOOLEAN
Examples (2)

Check that a DER `SEQUENCE { INTEGER 5 }` is well-formed (returns true).

SELECT asn1.main.is_valid(from_hex('3003020105')) AS valid;

Check that a DER `SEQUENCE { INTEGER 5 }` is valid under the strict DER rules (returns true).

SELECT asn1.main.is_valid(from_hex('3003020105'), 'der') AS valid;
Link
krb_decode (blob ANY) 1 example

Decode a Kerberos V5 message to JSON, dispatched on its [APPLICATION n] message tag.

Arguments
blob ANY
The ASN.1 DER/BER/CER bytes to decode — raw binary, or text holding those bytes. NULL input yields NULL.
ReturnsVARCHAR
Example

Decode an [APPLICATION 1] Kerberos Ticket (tkt-vno 5) into JSON (msg_type 'Ticket').

SELECT asn1.main.krb_decode(from_hex('61073005a003020105')) AS msg;
Link
krb_ticket (blob ANY) 1 example

Parse the outer Kerberos Ticket (RFC 4120) into a STRUCT(tkt_vno, realm, sname, name_type, enc_part_etype, enc_part_kvno, enc_part_cipher). The EncTicketPart stays encrypted (etype named, cipher as BLOB).

Arguments
blob ANY
A Kerberos Ticket ([APPLICATION 1]) DER/BER blob. NULL or a non-Ticket blob yields a NULL struct.
ReturnsSTRUCT of 7 fields
STRUCT 7 fields
  • tkt_vnoBIGINT
  • realmVARCHAR
  • snameVARCHAR
  • name_typeVARCHAR
  • enc_part_etypeVARCHAR
  • enc_part_kvnoBIGINT
  • enc_part_cipherBLOB
Example

Project the outer [APPLICATION 1] Ticket envelope to a STRUCT (here tkt_vno = 5; realm/sname/enc-part NULL on this minimal ticket).

SELECT asn1.main.krb_ticket(from_hex('61073005a003020105')) AS ticket;
Link
ldap_decode (blob ANY) 1 example

Decode the first LDAPMessage of a blob to JSON (message_id, protocolOp, dn/filter/…).

Arguments
blob ANY
The ASN.1 DER/BER/CER bytes to decode — raw binary, or text holding those bytes. NULL input yields NULL.
ReturnsVARCHAR
Example

Decode a real LDAP searchRequest into JSON (RFC 4515 filter '(uid=jdoe)').

SELECT asn1.main.ldap_decode(from_hex('3033020102632e040a64633d6578616d706c650a01020a0100020100020100010100a30b040375696404046a646f6530040402636e')) AS msg;
Link
ocsp_decode (blob ANY) 1 example

Decode an OCSP request or response to JSON (status, responder, per-cert responses).

Arguments
blob ANY
The ASN.1 DER/BER/CER bytes to decode — raw binary, or text holding those bytes. NULL input yields NULL.
ReturnsVARCHAR
Example

Decode a minimal OCSPResponse into JSON (response_status 'successful').

SELECT asn1.main.ocsp_decode(from_hex('30030a0100')) AS msg;
Link
oid (name VARCHAR) 1 example

Resolve a friendly OID name to its dotted form from the bundled registry, or NULL if unknown.

Arguments
name VARCHAR
A friendly OID name, e.g. 'sha256WithRSAEncryption' (case-insensitive). Resolved to its dotted form; NULL if not in the registry.
ReturnsVARCHAR
Example

Resolve a name to '2.5.4.3'.

SELECT asn1.main.oid('id-at-commonName');
Link
oid_name (oid VARCHAR) 1 example

Resolve a dotted OID to its friendly name from the bundled registry, or NULL if unknown.

Arguments
oid VARCHAR
A dotted OID, e.g. '1.2.840.113549.1.1.11'. Resolved to its friendly name; NULL if not in the registry.
ReturnsVARCHAR
Example

Resolve an OID to 'sha256WithRSAEncryption'.

SELECT asn1.main.oid_name('1.2.840.113549.1.1.11');
Link
oids (blob ANY) 1 example

Return every OBJECT IDENTIFIER in a blob as a LIST of STRUCT(oid, name, path) — the OID inventory / join surface.

Arguments
blob ANY
The ASN.1 DER/BER/CER bytes to inventory for OBJECT IDENTIFIERs — raw binary, or text holding those bytes.
ReturnsSTRUCT(oid VARCHAR, "name" VARCHAR, path VARCHAR)[]
Example

Inventory every OID in an AlgorithmIdentifier blob — here 1.2.840.113549.1.1.11 (sha256WithRSAEncryption), with its resolved name and node path.

SELECT asn1.main.oids(from_hex('300d06092a864886f70d01010b0500')) AS oids;
Link
pem_label (text VARCHAR) 1 example

Return the label of the first PEM block in a text (e.g. 'CERTIFICATE'), or NULL if there is no PEM block.

Arguments
text VARCHAR
PEM-armored text. Returns the first block's label, or NULL if none.
ReturnsVARCHAR
Example

Identify the label of the first PEM block in a text (returns 'CERTIFICATE').

SELECT asn1.main.pem_label('-----BEGIN CERTIFICATE-----' || chr(10) || 'MIIBAg==' || chr(10) || '-----END CERTIFICATE-----') AS label;
Link
pkcs8_info (blob ANY) 1 example

Structural PKCS#8 info: STRUCT(version, algorithm, params JSON, public_key BLOB, encrypted BOOL, kdf, enc_alg). Plaintext private-key octets are NEVER surfaced; encrypted keys name their PBES2/PBKDF2 OIDs.

Arguments
blob ANY
A PKCS#8 PrivateKeyInfo or EncryptedPrivateKeyInfo DER blob. NULL or a non-PKCS#8 blob yields a NULL struct.
ReturnsSTRUCT of 7 fields
STRUCT 7 fields
  • versionBIGINT
  • algorithmVARCHAR
  • paramsVARCHAR
  • public_keyBLOB
  • encryptedBOOLEAN
  • kdfVARCHAR
  • enc_algVARCHAR
Example

Inspect a minimal PKCS#8 PrivateKeyInfo's structure (version 0, algorithm 'rsaEncryption') without exposing key material.

SELECT asn1.main.pkcs8_info(from_hex('3016020100300d06092a864886f70d010101050004026869')) AS info;
Link
reencode (blob ANY, rules VARCHAR) +1 overload 2 examples

Re-encode a parsed blob to canonical DER (definite minimal lengths, sorted SET OF). NULL → NULL; a malformed blob → NULL. Pass a second 'rules' argument to name the target encoding explicitly.

Arguments
blob ANY
The ASN.1 bytes to re-encode — raw binary, or text holding those bytes. NULL/malformed → NULL.
rules VARCHAR
Target encoding rules: 'der' (default), 'cer', or 'ber'. The worker emits canonical DER for any value.
Overloads
reencode(blob ANY) → BLOBreencode(blob ANY, rules VARCHAR) → BLOB
ReturnsBLOB
Examples (2)

Re-encode a blob to canonical DER (an already-canonical SEQUENCE round-trips unchanged).

SELECT asn1.main.reencode(from_hex('3003020105')) AS der;

Re-encode a blob to canonical DER under an explicit 'der' rules set.

SELECT asn1.main.reencode(from_hex('3003020105'), 'der') AS der;
Link
snmp_decode (blob ANY) 1 example

Decode an SNMP v1/v2c/v3 message to JSON (version, community, PDU, resolved varbinds).

Arguments
blob ANY
The ASN.1 DER/BER/CER bytes to decode — raw binary, or text holding those bytes. NULL input yields NULL.
ReturnsVARCHAR
Example

Decode a real SNMP GetResponse (community 'public') into JSON with its resolved varbinds.

SELECT asn1.main.snmp_decode(from_hex('302e02010104067075626c6963a2210201010201000201003016301406082b060102010101000408526f757465724f53')) AS msg;
Link
tlv (blob ANY) 1 example

Flatten a blob into a LIST of TLV nodes in document order: STRUCT(path, class, tag, tag_name, constructed, header_len, len, value JSON). The raw-structure escape hatch.

Arguments
blob ANY
The ASN.1 DER/BER/CER bytes to walk into a flat node list — raw binary, or text holding those bytes.
ReturnsSTRUCT of 8 fields[]
STRUCT[] 8 fields
  • pathVARCHAR
  • classVARCHAR
  • tagUINTEGER
  • tag_nameVARCHAR
  • constructedBOOLEAN
  • header_lenUINTEGER
  • lenUBIGINT
  • valueVARCHAR
Example

List every TLV node of a DER `SEQUENCE { INTEGER 5 }` (the SEQUENCE and its child INTEGER).

SELECT asn1.main.tlv(from_hex('3003020105')) AS nodes;
Link
to_der (blob ANY) 2 examples

Re-encode a BER/CER blob to canonical DER (definite minimal lengths, sorted SET OF). Idempotent on DER; NULL → NULL; a malformed blob → NULL.

Arguments
blob ANY
The ASN.1 bytes to canonicalize — raw binary, or text holding those bytes. NULL/malformed → NULL.
ReturnsBLOB
Examples (2)

Canonicalize a blob to DER; an already-canonical `SEQUENCE { INTEGER 5 }` round-trips to the same bytes.

SELECT asn1.main.to_der(from_hex('3003020105')) AS der;

Canonicalize an indefinite-length BER blob with to_der, then prove the result: is_valid under strict DER is false before and true after, and decode yields the same value for both encodings. The canonical bytes are 300404024869.

SELECT asn1.main.is_valid(b, 'der') AS der_before,
  hex(asn1.main.to_der(b)) AS der_hex,
  asn1.main.is_valid(asn1.main.to_der(b), 'der') AS der_after,
  asn1.main.decode(b) = asn1.main.decode(asn1.main.to_der(b)) AS same_value
FROM (SELECT from_hex('3080040248690000') AS b) AS t;
Link
to_json (blob ANY) 1 example

Project a BER/CER/DER blob into self-describing JSON, one object per TLV node.

Arguments
blob ANY
The ASN.1 DER/BER/CER bytes to decode — raw binary, or text holding those bytes. NULL input yields NULL.
ReturnsVARCHAR
Example

Project a DER `SEQUENCE { INTEGER 5 }` into self-describing JSON nodes.

SELECT asn1.main.to_json(from_hex('3003020105')) AS json;
Link
well_formed (blob ANY) 1 example

Structured well-formedness of a blob: STRUCT(ok BOOL, error VARCHAR, kind VARCHAR). kind ∈ {truncated, trailing-bytes, invalid-tag, length-overflow, indefinite-in-der, non-canonical, bad-time, bad-oid, bad-utf8, nesting-limit, alloc-limit}. Never errors.

Arguments
blob ANY
The ASN.1 bytes to check — raw binary, or text holding those bytes. NULL yields a NULL struct.
ReturnsSTRUCT(ok BOOLEAN, "error" VARCHAR, kind VARCHAR)
Example

Triage a DER `SEQUENCE { INTEGER 5 }`: returns STRUCT(ok=true, error=NULL, kind=NULL).

SELECT asn1.main.well_formed(from_hex('3003020105')) AS w;
Link
Table functions
cms_signers (blob ANY) 2 examples

Shred a CMS SignedData into one row per SignerInfo

Arguments
blob ANY
A CMS / PKCS#7 SignedData payload (a literal value or scalar subquery). Fans into one row per SignerInfo.
Returns columns
version INTEGER
SignerInfo version (CMSVersion).
signer_sid VARCHAR
Signer identifier kind.
signer_issuer VARCHAR
Signer cert issuer (CN=…,O=…).
signer_serial VARCHAR
Signer cert serial (decimal).
signer_skid VARCHAR
Subject key identifier (hex), if SKID-based.
digest_alg VARCHAR
Named digest algorithm OID.
sig_alg VARCHAR
Named signature algorithm OID.
signing_time TIMESTAMP
signingTime signed attribute (UTC).
content_type VARCHAR
contentType (eContentType / signed attr).
message_digest BLOB
messageDigest signed attribute bytes.
signature BLOB
The signature bytes (surfaced, not verified).
signer_cert_sha256 VARCHAR
SHA-256 (hex) of the matching embedded cert — join to vgi-x509.
signed_attrs VARCHAR
Remaining signed attributes as JSON.
Examples (2)

Shred a CMS SignedData into one row per SignerInfo and project the signer identity kind and the named digest/signature algorithms.

SELECT signer_sid, digest_alg, sig_alg
FROM asn1.main.cms_signers(from_hex('304d0201013100301106092a864886f70d010701a00404026869a0053003020105312c302a020101800401020304300b0609608648016503040201300d06092a864886f70d01010105000403aabbcc'))
ORDER BY signer_sid;

Shred a CMS SignedData's signers and join the oid_registry table to recover the dotted OIDs behind the named digest and signature algorithms (sha256 → 2.16.840.1.101.3.4.2.1, rsaEncryption → 1.2.840.113549.1.1.1).

SELECT s.digest_alg, d.oid AS digest_oid, s.sig_alg, g.oid AS sig_oid
FROM asn1.main.cms_signers(from_hex('304d0201013100301106092a864886f70d010701a00404026869a0053003020105312c302a020101800401020304300b0609608648016503040201300d06092a864886f70d01010105000403aabbcc')) AS s
LEFT JOIN asn1.main.oid_registry AS d ON d.name = s.digest_alg
LEFT JOIN asn1.main.oid_registry AS g ON g.name = s.sig_alg
ORDER BY s.signer_sid;
Link
ldap_messages (blob ANY) 1 example

Fan a blob's LDAP messages into one row each

Arguments
blob ANY
An LDAP wire payload (a literal value or scalar subquery), possibly several LDAPMessages back-to-back.
Returns columns
message_id INTEGER
The LDAP messageID.
op VARCHAR
The protocolOp name, e.g. SearchRequest.
dn VARCHAR
The base/object DN (op-dependent).
scope VARCHAR
Search scope (SearchRequest).
filter VARCHAR
RFC 4515 filter string (SearchRequest).
attributes VARCHAR[]
Requested/returned attribute names.
result_code VARCHAR
Named LDAPResult code (result ops).
matched_dn VARCHAR
The matchedDN (result ops).
diagnostic VARCHAR
The diagnosticMessage (result ops).
Example

Shred an LDAP SearchRequest into rows and project the operation, base DN, and RFC 4515 filter.

SELECT op, dn, filter
FROM asn1.main.ldap_messages(from_hex('3033020102632e040a64633d6578616d706c650a01020a0100020100020100010100a30b040375696404046a646f6530040402636e'))
ORDER BY message_id;
Link
pem_decode (text VARCHAR) 2 examples

Split a PEM bundle into its DER blocks (idx, label, der)

Arguments
text VARCHAR
The PEM-armored text bundle to split into its BEGIN/END blocks.
Returns columns
idx INTEGER
Zero-based index of the PEM block within the bundle.
label VARCHAR
The block label, e.g. 'CERTIFICATE' or 'PRIVATE KEY'.
der BLOB
The base64-decoded DER bytes of the block (feed to asn1.decode).
Examples (2)

Split a one-block PEM bundle and list each block's index, label, and decoded DER length.

SELECT idx, label, octet_length(der) AS der_bytes FROM asn1.main.pem_decode('-----BEGIN CERTIFICATE-----' || chr(10) || 'AQID' || chr(10) || '-----END CERTIFICATE-----') ORDER BY idx;

Split a three-block PEM bundle (PRIVATE KEY, PKCS7, CERTIFICATE) and triage each block's DER: well-formedness, the classified failure kind, and how many OIDs it carries. The PRIVATE KEY (1 OID) and PKCS7 (3 OIDs) blocks are well-formed; the CERTIFICATE body is truncated and flagged ok=false with kind 'length-overflow'.

SELECT p.idx, p.label, (asn1.main.well_formed(p.der)).ok AS ok, (asn1.main.well_formed(p.der)).kind AS kind, len(asn1.main.oids(p.der)) AS n_oids FROM asn1.main.pem_decode('-----BEGIN PRIVATE KEY-----' || chr(10) || 'MBYCAQAwDQYJKoZIhvcNAQEBBQAEAmhp' || chr(10) || '-----END PRIVATE KEY-----' || chr(10) || '-----BEGIN PKCS7-----' || chr(10) || 'ME0CAQExADARBgkqhkiG9w0BBwGgBAQCaGmgBTADAgEFMSwwKgIBAYAEAQIDBDALBglghkgBZQMEAgEwDQYJKoZIhvcNAQEBBQAEA6q7zA==' || chr(10) || '-----END PKCS7-----' || chr(10) || '-----BEGIN CERTIFICATE-----' || chr(10) || 'MAUC' || chr(10) || '-----END CERTIFICATE-----') AS p ORDER BY p.idx;
Result
idx label ok kind n_oids
0 PRIVATE KEY true NULL 1
1 PKCS7 true NULL 3
2 CERTIFICATE false length-overflow 0
Link
pkcs12_bags (blob ANY) 2 examples

Walk a PKCS#12 keystore into one row per SafeBag

Arguments
blob ANY
A PKCS#12 (PFX) payload (a literal value or scalar subquery). Fans into one row per SafeBag.
Returns columns
bag_type VARCHAR
SafeBag type, e.g. certBag, pkcs8ShroudedKeyBag.
friendly_name VARCHAR
friendlyName attribute, if present.
local_key_id VARCHAR
localKeyID attribute (hex), if present.
alg VARCHAR
Named key algorithm (key bags).
cert_sha256 VARCHAR
SHA-256 (hex) of the cert (cert bags) — join to vgi-x509.
encrypted BOOLEAN
Whether the bag's key material is encrypted.
Examples (2)

Walk a minimal PKCS#12 PFX and list each SafeBag's type, encryption flag, and (for cert bags) the vgi-x509 join hash.

SELECT bag_type, encrypted, cert_sha256
FROM asn1.main.pkcs12_bags(from_hex('3051020103304c06092a864886f70d010701a03f043d303b303906092a864886f70d010701a02c042a30283026060b2a864886f70d010c0a0103a0173015060a2a864886f70d01091601a00704053003020105'))
ORDER BY bag_type;

Find the certificates a PKCS#12 keystore shares with a CMS SignedData: join the keystore's cert bags (cert_sha256) to the SHA-256 of each certificate embedded in the signed message (cms_certs). The keystore holds two certBags; only the one whose certificate is also embedded in the message (417c…d729) is returned.

SELECT b.bag_type, b.cert_sha256
FROM asn1.main.pkcs12_bags(from_hex('3079020103307406092a864886f70d010701a06704653063306106092a864886f70d010701a054045230503026060b2a864886f70d010c0a0103a0173015060a2a864886f70d01091601a007040530030201053026060b2a864886f70d010c0a0103a0173015060a2a864886f70d01091601a00704053003020106')) AS b
JOIN (SELECT unnest(asn1.main.cms_certs(from_hex('304d0201013100301106092a864886f70d010701a00404026869a0053003020105312c302a020101800401020304300b0609608648016503040201300d06092a864886f70d01010105000403aabbcc'))) AS cert) AS c ON sha256(c.cert) = b.cert_sha256
ORDER BY b.cert_sha256;
Link
snmp_varbinds (blob ANY) 1 example

Fan an SNMP PDU into one row per varbind

Arguments
blob ANY
An SNMP message payload (a literal value or scalar subquery). Fans into one row per varbind.
Returns columns
request_id INTEGER
The PDU request-id (NULL for v1 traps).
pdu_type VARCHAR
The PDU type, e.g. GetResponse, SNMPv2-Trap.
oid VARCHAR
The varbind OID, dotted-decimal.
oid_name VARCHAR
The resolved OID name (NULL if unknown).
type VARCHAR
The SMI value type, e.g. Counter32, TimeTicks.
value VARCHAR
The varbind value as JSON.
Example

Shred an SNMP v2c GetResponse into its varbinds and project each OID, resolved name, and SMI type.

SELECT oid, oid_name, type
FROM asn1.main.snmp_varbinds(from_hex('302e02010104067075626c6963a2210201010201000201003016301406082b060102010101000408526f757465724f53'))
ORDER BY oid;
Link

Try these queries

Decode a DER `SEQUENCE { INTEGER 5 }` into its nested typed JSON projection.

SELECT asn1.main.decode(from_hex('3003020105'));

Uses decode

Project the same blob into self-describing JSON, one object per TLV node.

SELECT asn1.main.to_json(from_hex('3003020105'));

Uses to_json

Render an `openssl asn1parse`-style indented text dump of the blob.

SELECT asn1.main.dump(from_hex('3003020105'));

Uses dump

Resolve a dotted OID to its friendly algorithm name ('sha256WithRSAEncryption').

SELECT asn1.main.oid_name('1.2.840.113549.1.1.11');

Uses oid_name

Triage a truncated blob — `well_formed(...).ok` is false.

SELECT (asn1.main.well_formed(from_hex('300502'))).ok;

Uses well_formed

Validate a bare INTEGER 5 under strict DER encoding rules.

SELECT asn1.main.is_valid(from_hex('020105'), 'der');

Uses is_valid

36 more examples in the Catalog, each listed under the table or function it uses.

ASN.1 is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.