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
- Query Farm hosting
- Available · $10/month organization minimum
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;
| 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.
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;
INSTALL vgi FROM community;
LOAD vgi;
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'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'asn1' AS asn1 (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-asn1:0.5.0'
);
3. Run a query
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;
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connector’s deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
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;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'asn1' AS asn1
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
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;
Query Farm operates ASN.1 for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
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;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use asn1 as the catalog alias for the query below.
4. Run a query
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;
Technical details
- Verified connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
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]'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'asn1' AS asn1 (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-asn1:0.5.0'
);
Overview
Generic ASN.1 BER/CER/DER decode plus SNMP/Kerberos/LDAP/CMS/PKCS/OCSP structural decoders for SQL.
Decode generic ASN.1 (BER/CER/DER) and the security/telecom modules that ride on it — SNMP, Kerberos, LDAP, CMS/PKCS#7, PKCS#8/#12, OCSP — directly in DuckDB SQL. Walk any DER blob into a typed JSON tree, dump it openssl asn1parse-style, inventory every OBJECT IDENTIFIER, and shred the named modules into joinable rows — signers, SNMP varbinds, LDAP messages, PKCS#12 bags. The flagship pairing is vgi-x509: the CMS and PKCS#12 decoders surface embedded-certificate SHA-256 hashes so you can join them straight to cert metadata and revocation.
The worker is structural-decode only — signatures, MACs, and encrypted parts are surfaced (algorithm OID + bytes) but never verified or decrypted, and PKCS#8/#12 never expose plaintext key material. Decoding is robust against hostile input: bounded recursion and allocation, and per-row error capture (the validator classifies the failure kind) so a malformed blob never aborts a scan.
Sources and references
Catalog
Everything asn1 exposes once attached — read straight from the worker's
released build.
main 1 table · 27 functions
Generic ASN.1 decode + SNMP/Kerberos/LDAP/CMS/PKCS/OCSP structural decoders.
Schema 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;
| 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;
oid_registry
The curated OBJECT IDENTIFIER → friendly-name registry as a browsable table (oid, name).
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%';
at_path (blob ANY, path VARCHAR)
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.
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;
cms_certs (blob ANY)
Return the embedded DER certificates of a CMS SignedData as a LIST(BLOB) — the join key to vgi-x509 (hash each with sha256).
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;
cms_content (blob ANY)
Return the encapsulated eContent (BLOB) of a CMS SignedData — often a nested CMS/DER, re-feed to decode(). NULL when absent.
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;
cms_decode (blob ANY)
Decode a CMS / PKCS#7 ContentInfo to JSON (named content_type + dispatched content).
Decode a minimal CMS ContentInfo (content_type 'id-data') into JSON.
SELECT asn1.main.cms_decode(from_hex('301106092a864886f70d010701a00404026869')) AS info;
decode (blob ANY, mode VARCHAR) +1 overload
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.
decode(blob ANY) → VARCHARdecode(blob ANY, mode VARCHAR) → VARCHAR
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;
dump (blob ANY, format VARCHAR) +1 overload
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.
dump(blob ANY) → VARCHARdump(blob ANY, format VARCHAR) → VARCHAR
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;
is_valid (blob ANY, rules VARCHAR) +1 overload
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.
is_valid(blob ANY) → BOOLEANis_valid(blob ANY, rules VARCHAR) → BOOLEAN
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;
krb_decode (blob ANY)
Decode a Kerberos V5 message to JSON, dispatched on its [APPLICATION n] message tag.
Decode an [APPLICATION 1] Kerberos Ticket (tkt-vno 5) into JSON (msg_type 'Ticket').
SELECT asn1.main.krb_decode(from_hex('61073005a003020105')) AS msg;
krb_ticket (blob ANY)
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).
-
tkt_vnoBIGINT
-
realmVARCHAR
-
snameVARCHAR
-
name_typeVARCHAR
-
enc_part_etypeVARCHAR
-
enc_part_kvnoBIGINT
-
enc_part_cipherBLOB
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;
ldap_decode (blob ANY)
Decode the first LDAPMessage of a blob to JSON (message_id, protocolOp, dn/filter/…).
Decode a real LDAP searchRequest into JSON (RFC 4515 filter '(uid=jdoe)').
SELECT asn1.main.ldap_decode(from_hex('3033020102632e040a64633d6578616d706c650a01020a0100020100020100010100a30b040375696404046a646f6530040402636e')) AS msg;
ocsp_decode (blob ANY)
Decode an OCSP request or response to JSON (status, responder, per-cert responses).
Decode a minimal OCSPResponse into JSON (response_status 'successful').
SELECT asn1.main.ocsp_decode(from_hex('30030a0100')) AS msg;
oid (name VARCHAR)
Resolve a friendly OID name to its dotted form from the bundled registry, or NULL if unknown.
Resolve a name to '2.5.4.3'.
SELECT asn1.main.oid('id-at-commonName');
oid_name (oid VARCHAR)
Resolve a dotted OID to its friendly name from the bundled registry, or NULL if unknown.
Resolve an OID to 'sha256WithRSAEncryption'.
SELECT asn1.main.oid_name('1.2.840.113549.1.1.11');
oids (blob ANY)
Return every OBJECT IDENTIFIER in a blob as a LIST of STRUCT(oid, name, path) — the OID inventory / join surface.
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;
pem_label (text VARCHAR)
Return the label of the first PEM block in a text (e.g. 'CERTIFICATE'), or NULL if there is no PEM block.
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;
pkcs8_info (blob ANY)
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.
-
versionBIGINT
-
algorithmVARCHAR
-
paramsVARCHAR
-
public_keyBLOB
-
encryptedBOOLEAN
-
kdfVARCHAR
-
enc_algVARCHAR
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;
reencode (blob ANY, rules VARCHAR) +1 overload
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.
reencode(blob ANY) → BLOBreencode(blob ANY, rules VARCHAR) → BLOB
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;
snmp_decode (blob ANY)
Decode an SNMP v1/v2c/v3 message to JSON (version, community, PDU, resolved varbinds).
Decode a real SNMP GetResponse (community 'public') into JSON with its resolved varbinds.
SELECT asn1.main.snmp_decode(from_hex('302e02010104067075626c6963a2210201010201000201003016301406082b060102010101000408526f757465724f53')) AS msg;
tlv (blob ANY)
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.
-
pathVARCHAR
-
classVARCHAR
-
tagUINTEGER
-
tag_nameVARCHAR
-
constructedBOOLEAN
-
header_lenUINTEGER
-
lenUBIGINT
-
valueVARCHAR
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;
to_der (blob ANY)
Re-encode a BER/CER blob to canonical DER (definite minimal lengths, sorted SET OF). Idempotent on DER; NULL → NULL; a malformed blob → NULL.
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;
to_json (blob ANY)
Project a BER/CER/DER blob into self-describing JSON, one object per TLV node.
Project a DER `SEQUENCE { INTEGER 5 }` into self-describing JSON nodes.
SELECT asn1.main.to_json(from_hex('3003020105')) AS json;
well_formed (blob ANY)
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.
Triage a DER `SEQUENCE { INTEGER 5 }`: returns STRUCT(ok=true, error=NULL, kind=NULL).
SELECT asn1.main.well_formed(from_hex('3003020105')) AS w;
cms_signers (blob ANY)
Shred a CMS SignedData into one row per SignerInfo
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;
ldap_messages (blob ANY)
Fan a blob's LDAP messages into one row each
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;
pem_decode (text VARCHAR)
Split a PEM bundle into its DER blocks (idx, label, der)
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;
| idx | label | ok | kind | n_oids |
|---|---|---|---|---|
| 0 | PRIVATE KEY | true | NULL | 1 |
| 1 | PKCS7 | true | NULL | 3 |
| 2 | CERTIFICATE | false | length-overflow | 0 |
pkcs12_bags (blob ANY)
Walk a PKCS#12 keystore into one row per SafeBag
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;
snmp_varbinds (blob ANY)
Fan an SNMP PDU into one row per varbind
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;
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.
Related workers
CBOR
File formats & encodings
Decode and encode CBOR and MessagePack, inspect security payloads, and import or export row files from SQL
BSON
File formats & encodings
Query BSON documents and move them between files and tables
Charset
File formats & encodings
Detect text encodings, convert legacy bytes to and from UTF-8, and repair mojibake