strongswan-sql-1.2.2.0: Interface library for strongSwan SQL backend

Copyright(c) Erick Gonzalez 2019
LicenseBSD3
Maintainererick@codemonkeylabs.de
Safe HaskellNone
LanguageHaskell2010

StrongSwan.SQL

Contents

Description

This library allows for the manipulation of strongSwan connection configuration stored in a MySQL database in a manner that is compatible with the strongSwan SQL plugin for charon.

How to use this module:

The strongSwan IPsec package offers the means to store connection configuration in a SQL database. This module offers some facilities to manipulate these config elements from Haskell code in a simplified abstracted way. This library offers two approaches to manipulating strongswan configuration in an SQL database as expected by the SQL plugin. See Managed vs Manual API below.

Synopsis

Initialization

mkContext :: (Failable m, MonadIO m) => Settings -> m Context Source #

Initialize an SQL context. Use the Default instance of Settings and fine tune parameters as needed. For example:

   context <- init def { dbName = "acmeDB" }
 

Managed API

Since managing each configuration object per hand and establishing the relationships amongst them can be tricky and demands internal knowledge of the SQL plugin inner workings, a special API is offered in which all configuration parameters are bundled together in a single type (see IPSecSettings). The simplified API allows then for writing, reading and deleting these, while behind bars the required elements are created and linked together unbeknownst to the caller. This of course greatly simplifies things but the catch is that the ability to share configuration elements amongst connections is of course lost. Each managed connection configuration gets a separate IKE, Child SA, Peer config etc and no attempt is made to reuse them amongst managed connections.

writeIPSecSettings :: (Failable m, MonadIO m) => IPSecSettings -> Context -> m IPSecSettings Source #

Pushes an IPsec configuration into the DB specified in the given context. Note that if there are any existing elements in the configuration, they are first released (and their inter relationships in the SQL DB removed), before creating them. As a result the different IDs inside the elements etc will probably change. This is the reason why a new IPSecSettings value is returned as a result of the operation and the value "pushed" to the DB originally should not be used any further.

findIPSecSettings :: (Failable m, MonadIO m) => Text -> Context -> m IPSecSettings Source #

Search for an IPsec connection configuration by its unique name. Take note of the Failable context, which means that unless it is desired that this function throws an asynchronous exception upon not finding a configuration, you probably want to run this inside a monadic transformer such as MaybeT or ExceptT

lookupIPSecSettings :: (Failable m, MonadIO m) => Text -> Context -> m (Maybe IPSecSettings) Source #

Lookup an IPsec connection configuration by its unique name. Returns Nothing if the connection is not found. Other errors are reported according to the Failable context the function is called on (MaybeT, ExceptT, IO, etc).

deleteIPSecSettings :: (Failable m, MonadIO m) => IPSecSettings -> Context -> m IPSecSettings Source #

Removes the specified IPSecSettings from the DB, releasing all linked elements. The returned IPSecSettings will contain now "unlinked" elements (i.e. no IDs, etc).

addSecret :: (Failable m, MonadIO m) => Identity -> SharedSecret -> Context -> m Identity Source #

Adds a shared secret to a given identity. If the identity doesn't exist it will get created. If the identity already exists and it already has a secret of the same type, it will be overwritten. This means there can only be one secret of any given type per identity (which makes sense of course from strongswan's perspective).

removeSecret :: (Failable m, MonadIO m) => Identity -> SharedSecretType -> Context -> m () Source #

Removes a secret of the given type (if present) from the specified identity

removeIdentity :: (Failable m, MonadIO m) => Identity -> Context -> m () Source #

Removes an identity and its secrets and related entries altogether

Manual API

The different strongswan configuration elements are mapped to a Haskell type and they can be manually written or read from the SQL database. This offers utmost control in terms of what elements get created and how they are interlinked. So for example one can create a single IKE session configuration to be shared for all connections or have some child SA configurations being shared amongst peers of a given type, etc. The downside of course to this level of control is that it requires for the user of the library to be familiar with the (poorly documented) way in which the plugin expects the relationships to be expressed in terms of entries in the SQL tables etc.

The manual API has been reverse engineered based on the SQL table definitions available here

  • Child SA : All configuration parameters related to an IPsec SA.
  • IKE Configuration : Configuration applicable to the IKE session (phase 1 in IKEv1 parlance).
  • Peer Configuration : All elements related to configuration of a peering connection. A peer connection links to a specific IKE configuration (by means of ID), and it is furthermore associated to the Child SA by means of a Peer2ChildConfig type.
  • Traffic Selectors: These are independent values linked to a Child SA by means of a Child2TSConfig type.

The manual API consists mainly of one writeXXX, findXXX, lookupXXX and a deleteXXX function for each object to be stored as an SQL row in its respective table. The writeXXX functions trigger an insertion or an update of the given row in the SQL database depending on whether the given object owns a key already or not (usually an ID). The search functions (findXXX and lookupXXX) perform a search in the DB for the given key. The difference is that a findXXX will trigger a failure in the Failable context with a NotFound error and that the lookupXXX functions simply return Nothing if a key doesn't exist in the DB (they can of course trigger other errors in the Failable context)

Lenses

There are lenses exported to facilitate access to the records in the type section below.

dbCharSet :: Lens' Settings MySQLCharacterEncoding Source #

Types

type Context = MVar Context_ Source #

data Identity Source #

Constructors

AnyID (Maybe Int) 
IPv4AddrID (Maybe Int) IPv4 
NameID (Maybe Int) Text 
EmailID (Maybe Int) Text Text

RFC 822 Email Address mailbox@domain

IPv6AddrID (Maybe Int) IPv6 
ASN1ID (Maybe Int) [ASN1] 
OpaqueID (Maybe Int) ByteString 
Instances
Eq Identity Source # 
Instance details

Defined in StrongSwan.SQL.Types

Show Identity Source # 
Instance details

Defined in StrongSwan.SQL.Types

Default Identity Source # 
Instance details

Defined in StrongSwan.SQL.Types

Methods

def :: Identity #

SQLRow Identity Source # 
Instance details

Defined in StrongSwan.SQL.Encoding

data IKEConfig Source #

Instances
Eq IKEConfig Source # 
Instance details

Defined in StrongSwan.SQL.Types

Show IKEConfig Source # 
Instance details

Defined in StrongSwan.SQL.Types

Default IKEConfig Source # 
Instance details

Defined in StrongSwan.SQL.Types

Methods

def :: IKEConfig #

SQLRow IKEConfig Source # 
Instance details

Defined in StrongSwan.SQL.Encoding

data IPSecSettings Source #

The managed IPsec configuration type encompasses a complete set of elements which are pushed and interlinked as necessary by the Managed API (see above). Note that there are lenses available to facilitate accessing all these fields (see StrongSwan.SQL.Lenses)

data Result a Source #

Constructors

Result 

Fields

data SAMode Source #

Constructors

Transport 
Tunnel 
Beet 
Pass 
Drop 
Instances
Enum SAMode Source # 
Instance details

Defined in StrongSwan.SQL.Types

Eq SAMode Source # 
Instance details

Defined in StrongSwan.SQL.Types

Methods

(==) :: SAMode -> SAMode -> Bool #

(/=) :: SAMode -> SAMode -> Bool #

Show SAMode Source # 
Instance details

Defined in StrongSwan.SQL.Types

data Settings Source #

Constructors

Settings 

Fields

Instances
Show Settings Source # 
Instance details

Defined in StrongSwan.SQL

Default Settings Source # 
Instance details

Defined in StrongSwan.SQL

Methods

def :: Settings #

data OK #

You may get interested in OK packet because it provides information about successful operations.

Constructors

OK 

Fields

Instances
Eq OK 
Instance details

Defined in Database.MySQL.Protocol.Packet

Methods

(==) :: OK -> OK -> Bool #

(/=) :: OK -> OK -> Bool #

Show OK 
Instance details

Defined in Database.MySQL.Protocol.Packet

Methods

showsPrec :: Int -> OK -> ShowS #

show :: OK -> String #

showList :: [OK] -> ShowS #

Binary OK 
Instance details

Defined in Database.MySQL.Protocol.Packet

Methods

put :: OK -> Put #

get :: Get OK #

putList :: [OK] -> Put #

class SQLRow a Source #

Minimal complete definition

toValues, fromValues

Instances
SQLRow SharedSecretIdentity Source # 
Instance details

Defined in StrongSwan.SQL.Encoding

SQLRow SharedSecret Source # 
Instance details

Defined in StrongSwan.SQL.Encoding

SQLRow Child2TSConfig Source # 
Instance details

Defined in StrongSwan.SQL.Encoding

SQLRow TrafficSelector Source # 
Instance details

Defined in StrongSwan.SQL.Encoding

SQLRow Peer2ChildConfig Source # 
Instance details

Defined in StrongSwan.SQL.Encoding

SQLRow PeerConfig Source # 
Instance details

Defined in StrongSwan.SQL.Encoding

SQLRow ChildSAConfig Source # 
Instance details

Defined in StrongSwan.SQL.Encoding

SQLRow IKEConfig Source # 
Instance details

Defined in StrongSwan.SQL.Encoding

SQLRow Identity Source # 
Instance details

Defined in StrongSwan.SQL.Encoding