Skip to content

Add WebID-TLS authentication support #67

Closed

Description

@melvincarvalho

Summary

Add WebID-TLS (mutual TLS / client certificate) authentication to JSS, enabling backend services, CLI tools, and automated agents to authenticate without user interaction.

Background

What is WebID-TLS?

WebID-TLS is a decentralized authentication protocol that uses TLS client certificates:

  1. Client presents X.509 certificate during TLS handshake
  2. Certificate's SubjectAlternativeName (SAN) contains a WebID URI
  3. Server fetches the WebID profile document
  4. Server verifies the certificate's public key matches the one published in the profile
sequenceDiagram
    participant C as Client
    participant S as JSS Server
    participant P as WebID Profile
    
    C->>S: TLS Handshake + Client Cert
    Note over S: Extract WebID from SAN
    S->>P: Fetch WebID Profile
    P-->>S: Profile with cert:key
    Note over S: Match modulus + exponent
    S-->>C: Authenticated as WebID
Loading

Why Now?

The W3C Linked Web Storage Use Cases group has raised this need for enterprise adoption:

"As a large tax advisory office, I want our existing backend services to authenticate themselves (without user interaction), such that these services can fetch and crunch private data from our clients."

Key drivers:

  • Enterprise adoption: Organizations with existing PKI/mTLS infrastructure want seamless LWS integration
  • Backend services: Server-to-server communication doesn't need browser UX
  • IoT/Agents: Automated systems need non-interactive authentication
  • CLI tools: Developers using curl or custom tools with client certs

Browser Support Note

While browser support for in-browser certificate generation (<keygen>) has been removed from Chrome and deprecated in Firefox, this does not affect server-side WebID-TLS:

  • Server-to-server: Works perfectly with standard mTLS
  • CLI tools: curl --cert works fine
  • Browser workarounds: YouID extension available

Implementation Guide

Files to Create/Modify

File Purpose
src/auth/webid-tls.js WebID-TLS authentication module
src/server.js Enable requestCert option on HTTPS server
src/config.js Add --webid-tls CLI flag

Step 1: Server Configuration

Modify src/server.js to request client certificates:

// In createServer, when SSL is enabled
if (options.ssl && options.ssl.key && options.ssl.cert) {
  const httpsOptions = {
    key: options.ssl.key,
    cert: options.ssl.cert,
    // Enable WebID-TLS
    requestCert: options.webidTls || false,  // Request client cert
    rejectUnauthorized: false  // Don't reject self-signed (we verify via WebID)
  };
  // ... create HTTPS server
}

Step 2: Create WebID-TLS Auth Module

Create src/auth/webid-tls.js:

import { graph, SPARQLToQuery } from 'rdflib';

const SPARQL_QUERY = `
  PREFIX cert: <http://www.w3.org/ns/auth/cert#>
  SELECT ?webid ?m ?e WHERE {
    ?webid cert:key ?key .
    ?key cert:modulus ?m .
    ?key cert:exponent ?e .
  }
`;

/**
 * Extract WebID from client certificate's SubjectAlternativeName
 */
export function getWebIdFromCert(certificate) {
  if (!certificate?.subjectaltname) return null;
  
  const match = certificate.subjectaltname.match(/URI:([^,\s]+)/);
  return match ? match[1] : null;
}

/**
 * Verify certificate public key matches WebID profile
 */
export async function verifyWebIdTls(certificate, webId) {
  if (!certificate.modulus || !certificate.exponent) {
    throw new Error('Certificate missing modulus or exponent');
  }
  
  // Fetch WebID profile
  const response = await fetch(webId, {
    headers: { 'Accept': 'text/turtle, application/ld+json' }
  });
  
  if (!response.ok) {
    throw new Error(`Failed to fetch WebID profile: ${response.status}`);
  }
  
  const body = await response.text();
  const contentType = response.headers.get('content-type')?.split(';')[0];
  
  // Parse profile and find matching key
  const g = graph();
  // ... parse RDF and run SPARQL query
  
  const certModulus = certificate.modulus.toLowerCase();
  const certExponent = parseInt(certificate.exponent, 16).toString();
  
  // Match modulus and exponent from profile
  // Return true if match found, false otherwise
}

/**
 * Middleware to authenticate via WebID-TLS
 */
export async function webIdTlsAuth(request) {
  const socket = request.raw?.socket || request.socket;
  
  if (!socket?.getPeerCertificate) {
    return null; // Not a TLS connection
  }
  
  const cert = socket.getPeerCertificate();
  if (!cert || Object.keys(cert).length === 0) {
    return null; // No client certificate
  }
  
  const webId = getWebIdFromCert(cert);
  if (!webId) {
    return null; // No WebID in certificate
  }
  
  const verified = await verifyWebIdTls(cert, webId);
  return verified ? webId : null;
}

Step 3: Integrate with Auth Flow

In src/auth/token.js, add WebID-TLS as authentication method:

import { webIdTlsAuth } from './webid-tls.js';

export async function getWebIdFromRequestAsync(request) {
  // Try bearer token first
  let webId = await getWebIdFromToken(request);
  
  // Fall back to WebID-TLS
  if (!webId) {
    webId = await webIdTlsAuth(request);
  }
  
  return { webId };
}

Step 4: CLI Configuration

Add to src/config.js:

.option('--webid-tls', 'Enable WebID-TLS client certificate authentication')

Testing

Manual Testing with curl

# Generate self-signed cert with WebID in SAN
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 \
  -subj "/CN=Test" -addext "subjectAltName=URI:https://example.com/profile/card#me"

# Test authentication
curl --cert cert.pem --key key.pem https://localhost:8443/private/resource

Unit Tests

describe('WebID-TLS Authentication', () => {
  it('should extract WebID from certificate SAN', () => {
    const cert = { subjectaltname: 'URI:https://alice.example/card#me' };
    expect(getWebIdFromCert(cert)).toBe('https://alice.example/card#me');
  });
  
  it('should verify certificate against WebID profile', async () => {
    // Mock profile with matching cert:key
    // Verify returns true
  });
  
  it('should reject mismatched certificate', async () => {
    // Mock profile with different key
    // Verify returns false
  });
});

WebID Profile Requirements

For WebID-TLS to work, the WebID profile must contain the certificate's public key:

@prefix cert: <http://www.w3.org/ns/auth/cert#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<#me> cert:key [
    a cert:RSAPublicKey;
    cert:modulus "abc123..."^^xsd:hexBinary;
    cert:exponent 65537
] .

Use Cases Enabled

  1. Backend Services: Tax advisors fetching client data (W3C use case)
  2. CLI Tools: Developers using curl or custom scripts
  3. IoT Devices: Sensors/actuators with embedded certificates
  4. Automated Agents: Bots and crawlers with verifiable identity
  5. Legacy Integration: Organizations with existing PKI infrastructure

References

Related

  • Solid-OIDC (current default auth) remains primary for browser-based apps
  • WebID-TLS would be an additional authentication method, not a replacement

Activity

  1. melvincarvalho commented on Jan 8, 2026

    @melvincarvalho
    ContributorAuthor

    Note: did:nostr + TLS Client Certificates

    An interesting extension would be supporting did:nostr with TLS client certificates. This would be elegant because did:nostr is self-certifying - the public key IS the identifier, so there's no need for external verification.

    The secp256k1 Challenge

    However, there's a curve compatibility issue:

    TLS Version secp256k1 Support Notes
    TLS 1.2 ✅ Yes Supported via custom config
    TLS 1.3 ❌ No Only supports P-256, P-384, P-521, X25519, X448

    Nostr uses secp256k1 (same as Bitcoin), but TLS 1.3 dropped support for this curve. This means native did:nostr + mTLS would require forcing TLS 1.2.

    Potential Workarounds

    1. Force TLS 1.2 - Configure server to accept TLS 1.2 with secp256k1 curve
    2. Dual-key approach - Use P-256 cert for TLS + Nostr signature in request body
    3. HTTP Signatures - Use Nostr keypair for HTTP Signature header instead of mTLS
    4. Hybrid auth - TLS client cert establishes channel, Nostr event proves identity

    Recommendation

    For did:nostr authentication, HTTP Signatures or NIP-98 (HTTP Auth) may be more practical than mTLS since they work with TLS 1.3 and leverage the existing Nostr key directly.

    References:

  2. melvincarvalho commented on May 9, 2026

    @melvincarvalho
    ContributorAuthor

    For context: WebID-TLS is the existing precedent for 'profile declares its keys' (cert:key / cert:modulus). The design in #386 generalises this pattern under W3C CID v1's verificationMethod + Multikey / JsonWebKey — same shape, broader cryptographic scope.

  3. added
    enhancement
    on May 12, 2026
  4. melvincarvalho commented on Jun 10, 2026

    @melvincarvalho
    ContributorAuthor

    Closing as shipped: WebID-TLS landed (v0.0.75 era) — src/auth/webid-tls.js, --webid-tls / --no-webid-tls CLI flags, README feature bullet. Known defects are tracked separately and stay open: #70 (Accept-header priority for profile fetch, strict data-island regex, @id references not dereferenced) — closing this feature-request issue does not close those. Anyone picking up WebID-TLS work should start at #70.

  5. added
    stale-fixed
    on Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementstale-fixed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions