Re: [strongSwan] Calculating the generated MAC address when identity_lease is enabled

2018-04-09 Thread Micah R Ledbetter
Hello Tobias,

> > 5.  Even better, can I use a single conn section to match all users,
> > no matter their operating system, and enforce that they send their
> > client identifier to the DHCP server the same way?
> 
> Have a look at [1] for my suggestion to Harald (who had a similar
> question) for a possible code modification to do this (i.e. get the
> client certificate, extract the first dNSName SAN and then forward that
> as host name in the DHCP request).
> 
> [1] https://wiki.strongswan.org/issues/2581

Ah hah. I'm not sure that's the right path for my project, but I'll take it 
under consideration.

Thanks for taking the time to answer my questions - you've gone above and 
beyond, and I understand the identity matching and DHCP systems much better now.

- Micah


Re: [strongSwan] Calculating the generated MAC address when identity_lease is enabled

2018-04-09 Thread Tobias Brunner
Hi Micah,

> 1.  Can I configure the strongSwan server to force the clients to send
> the FQDNs as identities?

No, that's a local decision.

> 2.  Alternatively, can I generate certificates differently to force the
> clients to send the FQDNs as identities?

Not that I'm aware.

> 3.  Am I misreading the documentation about rightid=%fqdn? If so, what
> is it intended to do?

It's mostly useful on clients to match the configured identity against
SANs in the server certificate if the server uses the subject DN as
identity.  It doesn't change the IKE identity the peer sends.

> 4.  Can I avoid using two conn sections for each user somehow?

If you want to match their identity, no.

> 5.  Even better, can I use a single conn section to match all users,
> no matter their operating system, and enforce that they send their
> client identifier to the DHCP server the same way?

Have a look at [1] for my suggestion to Harald (who had a similar
question) for a possible code modification to do this (i.e. get the
client certificate, extract the first dNSName SAN and then forward that
as host name in the DHCP request).

Regards,
Tobias

[1] https://wiki.strongswan.org/issues/2581


Re: [strongSwan] Calculating the generated MAC address when identity_lease is enabled

2018-04-08 Thread Micah R Ledbetter
Hello Tobias,


> A MAC address is 48 bits, so the 32 bits after the first two bytes
> are taken from the 64-bit SipHash-2-4 value (just by casting to an
> uint32_t) which is then run through htonl() and copied to the address
> buffer.  To calculate the value the 128-bit key
> 0x000102030405060708090a0b0c0d0e0f is used.

Ahhh. I missed that `id` was uint32_t. That clears up my confusion.
Thanks!

> If you use FQDNs as client identities they will be sent in a hostname
> option (12) in the DHCP request, which you might be able to use
> directly.

Ok, that sounds like a better solution. However, I am having trouble
making it work.

I put a lot of detail into my message below to provide all the context
I could, but the crux of my question now is this: can I configure the
strongSwan server to force all clients to use an FQDN as their
identifier, as you suggest? Or alternatively, can I force this by
changing the way I generate certificates?


Different clients send different identifiers


It seems that different clients send different things as identifiers:

 -  macOS and iOS appear to send the bare Common Name from their
certificate. For example, if the cert CN is macosclient.example.com
a conn section with
rightid=macosclient.example.com
will match when the client attempts to connect.

 -  Windows appears to send a DER-encoded X.509 Common Name object
For example, if the cert CN is windowsclient.example.com, it sends:
30:24:31:22:30:20:06:03:55:04:03:0c:19:77:69:6e:64:6f:77:73:63:
6c:69:65:6e:74:2e:65:78:61:6d:70:6c:65:2e:63:6f:6d
... and that is matched by a conn section like
rightid="/CN=windowsclient.example.com"

 -  strongSwan (clients) are configurable. They appear to send the same
thing that Windows sends by default, but can be configured to work
the same as macOS, and even more ways besides, depending on what
they have set as their 'leftid'


First attempt: rightid=%client.example.com
==

I found some documentation here:


> Since 5.0.1 rightid for IKEv2 connections optionally takes a % as
> prefix in front of the identity. If given it prevents the daemon from
> sending IDr in its IKE_AUTH request and will allow it to verify the
> configured identity against the subject and subjectAltNames contained
> in the responder's certificate (otherwise, it is only compared with
> the IDr returned by the responder). The IDr sent by the initiator
> might otherwise prevent the responder from finding a config if it has
> configured a different value for leftid.

However, I wasn’t able to make that work the way I expected. I
initially read this to mean that it would pluck the FQDN out of the
cert that the client sends and use that as an identity, but that
doesn't appear to be the correct reading.

I put two conn sections in my ipsec.conf:

conn macosclient-ikev2-pubkey
rightid=%macosclient.example.com
auto=add
conn windowsclient-ikev2-pubkey
rightid=%windowsclient.example.com
auto=add

(This isn’t ideal, because it requires a separate conn section for each
user. Is there a way to avoid that?)

With that configuration, the macOS client can connect just fine, but
the Windows client cannot. (Note that the certificates were generated
the same way, but of course with different hostnames.)

Am I misreading the documentation? Is there some way to work around
this for built-in IPSEC clients, like on Windows, which don’t appear to
let me configure what is sent as the identifier?


Further exploration: two conn sections per user
===

As I mentioned above, I found that Windows clients will connect if
the rightid is something like

rightid="/CN=windowsclient.example.com"

However, the biggest problem with this is that I don’t know the
operating system that my users will be on in advance. I provide VPN
profiles for macOS and iOS (as .mobileconfig files), Windows (as a
Powershell script), and Linux (as strongSwan configuration files); my
users install whatever is appropriate for their operating system.

That means that I’d need to have two conn sections for each user.

conn USER-macos-ikev2-pubkey
rightid=%user.example.com
auto=add
conn USER-windows-ikev2-pubkey
rightid="/CN=%user.example.com"
auto=add

That’s not ideal, but I could make it work if I have to.

Is there a better way?


Open questions
==

A recap of my questions, since this got pretty long:

1.  Can I configure the strongSwan server to force the clients to send
the FQDNs as identities?

2.  Alternatively, can I generate certificates differently to force the
clients to send the FQDNs as identities?

3.  Am I misreading the documentation about rightid=%fqdn? If so, what
is it intended to do?

4.  Can I avoid 

Re: [strongSwan] Calculating the generated MAC address when identity_lease is enabled

2018-04-04 Thread Tobias Brunner
Hi Micah,

> However, I became confused here, because the MAC address I am seeing on my 
> DHCP server is 7a:a7:bc:8b:b5:ec. After the hardcoded 0x7A and 0xA7 bytes, 
> there are only four bytes, but the SipHash-2-4 documentation I'm reading, as 
> well as the commit message for commit 
> 1255de5a2076dc591dfa1ffefffea077bd218319 which appears to have added this 
> functionality, claims that SipHash-2-4 returns 64 bits / 8 bytes.

A MAC address is 48 bits, so the 32 bits after the first two bytes are
taken from the 64-bit SipHash-2-4 value (just by casting to an uint32_t)
which is then run through htonl() and copied to the address buffer.  To
calculate the value the 128-bit key 0x000102030405060708090a0b0c0d0e0f
is used.

> Have I missed something? And more importantly, is there a better way to do 
> this?

If you use FQDNs as client identities they will be sent in a hostname
option (12) in the DHCP request, which you might be able to use directly.

Regards,
Tobias


[strongSwan] Calculating the generated MAC address when identity_lease is enabled

2018-03-31 Thread Micah R Ledbetter
Hello,

I am trying to configure my DHCP server to provide a domain name for each 
connected strongSwan client. To do that, I need to know the MAC address before 
the client connects, so that I can configure the DHCP server to assign it the 
correct IP address that corresponds to its DNS entry.

I am using IKEv2 and the dhcp plugin, I have enabled identity_lease, and when 
my clients connect, they are assigned an IP address from my DHCP server. 
However, I haven't yet found a way to precalculate the MAC address that 
strongSwan will assign to the client. Because of this, the DHCP server doesn't 
know to assign the IP address that corresponds to the IKEv2 identity, so 
currently, all my clients are getting a random address from the DHCP pool.

Is there a way to do this? Assuming so, how likely is it for the hash algorithm 
to change in the future - that is, how much of a bad idea is it to depend on 
strongSwan's current MAC-generating behavior?

## My failed attempt from reading the source code

Note for future readers: I am looking at git revision 
c21fff303aa09aca6495643fe98fb5e164b4f6c1

I found the prepare_dhcp() function in 
src/libcharon/plugins/dhcp/dhcp_socket.c. It appears to set the first two bytes 
of the  MAC to 0x7A and 0xA7 (lines 223 and 224), then calculates SipHash-2-4 
of the client's identity and sets the remaining MAC bytes to the result (line 
228).

However, I became confused here, because the MAC address I am seeing on my DHCP 
server is 7a:a7:bc:8b:b5:ec. After the hardcoded 0x7A and 0xA7 bytes, there are 
only four bytes, but the SipHash-2-4 documentation I'm reading, as well as the 
commit message for commit 1255de5a2076dc591dfa1ffefffea077bd218319 which 
appears to have added this functionality, claims that SipHash-2-4 returns 64 
bits / 8 bytes.

I did attempt to generate a SipHash-2-4 hash of what I believe my client is 
sending as its identity, and looked for even a partial match, thinking that 
perhaps the remaining 4 bytes are simply discarded at some later time. However, 
I could not find such a partial match.

It is quite possible I messed something up related to byte ordering, or out of 
a misunderstanding of SipHash-2-4, or because I am wrong about what my client 
is sending as its IKEv2 identity. Also, I'm afraid I have only some familiarity 
with C, so I am floundering trying to decide where to go from here in my 
investigation.

Have I missed something? And more importantly, is there a better way to do this?

Thanks very much for any help.