Skip to content

.ovpn file parser #295

@cachebag

Description

@cachebag

part of #288.

changes

new file: core/ovpn_parser.rs

parse .ovpn config files into a structured OvpnFile type. the format is one openvpn CLI option per line with inline cert blocks delimited by xml-style tags (<ca>...</ca>).

key directives to handle:

  • remote <host> [port] [proto] (can appear multiple times)
  • port, proto tcp|udp, dev tun|tap
  • auth-user-pass (implies password auth)
  • ca, cert, key — file paths or inline blocks
  • tls-auth, tls-crypt, tls-crypt-v2
  • cipher, data-ciphers, auth
  • redirect-gateway, route
  • compress, comp-lzo

output types:

pub struct OvpnFile {
    pub remotes: Vec<OvpnRemote>,
    pub protocol: Option<OvpnProtocol>,
    pub port: Option<u16>,
    pub auth_type: OpenVpnAuthType,  // inferred
    pub ca: Option<CertSource>,
    pub cert: Option<CertSource>,
    pub key: Option<CertSource>,
    pub tls_auth: Option<TlsAuthConfig>,
    pub tls_crypt: Option<CertSource>,
    pub cipher: Option<String>,
    pub data_ciphers: Option<String>,
    pub auth_digest: Option<String>,
    pub compress: Option<String>,
    pub mtu: Option<u32>,
    pub routes: Vec<OvpnRoute>,
    pub redirect_gateway: bool,
    pub extra_options: HashMap<String, String>,
}

pub enum CertSource {
    Path(String),
    Inline(String),
}

tests

embed sample .ovpn content as &str constants. test cases:

  • password auth ovpn
  • tls-only with inline certs
  • password+tls with file-path certs
  • multiple remote directives
  • redirect-gateway
  • comments, blank lines, unknown directives (graceful)
  • malformed input (proper errors)

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or requestnmrsChanges to nmrsvpnChanges to VPN surface

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions