duck030
Goto Top

XML für EapConfigXmlStream (VPN per Powershell mit IKEv2, eigener SmartCard und CertAuth)

Hallo zusammen,

ich versuche per Powershell Skript eine VPN-Verbindung zu erstellen. Das Skript soll später auf alle Notebooks verteilt werden.
Ich versuche eine ganz spezielle VPN-Konfiguration zu erstellen und nutze den in Windows 10 integrierten Client dafür.
Manuell funktioniert es. Aber ich schaffe es nicht, per Skript dieselbe Konfiguration herzustellen.
Da ich EAP-TLS mit Zertifikat und eigener SmartCard (Yubikey) und gegenseitiger zertifikatsbasierter Authentifizierung (Server<>Client) nutzen will, muss ich eine XML-Datei für die Konfiguration nutzen. (Für Eigene SmartCard verwenden gibt es keinen Schalter im Parameter new-eapConfiguration).

Mein code sollte nicht das Problem sein:

$EAPXml = Get-Content -Path C:\Users\Administrator\Documents\MeineSkripte\ProfileXML.xml

Add-VpnConnection -Name "VPN_13" -ServerAddress "vpn.beispiel.de" -TunnelType "IKEv2" -EncryptionLevel "Maximum" -AuthenticationMethod Eap -SplitTunneling -AllUserConnection -RememberCredential -EapConfigXmlStream $EAPXml  

Ich habe schon zig Varianten der XML ausprobiert. Am Ende kommt immer dieselbe Fehlermeldung:
Add-VPNConnection :  Failed to generate the EAP Configuration for the VPN Connection VPN_13. : A call to EAP Host returned an error.

Meine XML scheint nicht in Ordnung zu sein.
Hat eventuell jemand eine für diesen Zweck funktionierende XML-Datei? Sie muss ja nicht die gleiche Konfiguration haben, das kann ich anpassen, aber scheinbar habe ich ein grundsätzlichen Fehler drin.
Eventuell die Namespaces? Ich weiß nicht mehr weiter.

Soll ich die XML posten?
Was ist die "einfachstmögliche" XML, die "-EapConfigXmlStream" bzw "Add-VpnConnection" akzeptieren würde?
Es wäre schon ein Erfolg, dass es überhaupt geht, egal mit welcher Konfiguration.

P.S.
Ich habe auch schon das Konfigurationsprofil eines manuell angelegten, funktionierenden VPN-Profils exportiert in eine XML und versucht, dieses dann zu nutzen.
Ich erhalte genau denselben Fehler.

FG
Duck030

Content-ID: 671499

Url: https://administrator.de/forum/xml-fuer-eapconfigxmlstream-vpn-per-powershell-mit-ikev2-eigener-smartcard-und-certauth-671499.html

Ausgedruckt am: 21.02.2025 um 09:02 Uhr

mediodia
Lösung mediodia 19.02.2025 aktualisiert um 15:46:29 Uhr
Goto Top
Erstelle die Verbindung so wie sie richtig funktioniert, dann mit Get-VPNConnection die erstellte Verbindung auslesen, dort gibt es dann eine Property die die EAP-Config als korrektes XML enthält....

2025-02-19_01

So sollte die XML dann in der Struktur aussehen, natürlich mit deinen Anpassungen
<EapHostConfig xmlns="http://www.microsoft.com/provisioning/EapHostConfig"> 
	    <EapMethod>
		    <Type xmlns="http://www.microsoft.com/provisioning/EapCommon">25</Type> 
		    <VendorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorId> 
		    <VendorType xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorType> 
		    <AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</AuthorId> 
	    </EapMethod>
	    <Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig"> 
		    <Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1"> 
			    <Type>25</Type>
			    <EapType xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV1"> 
				    <ServerValidation>
					    <DisableUserPromptForServerValidation>true</DisableUserPromptForServerValidation>
					    <ServerNames>server.domain.de</ServerNames>
					    <TrustedRootCA>XXXXXXXXXXXXXX</TrustedRootCA>
				    </ServerValidation>
				    <FastReconnect>true</FastReconnect>
				    <InnerEapOptional>false</InnerEapOptional>
				    <Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1"> 
					    <Type>13</Type>
					    <EapType xmlns="http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV1"> 
						    <CredentialsSource>
							    <CertificateStore>
								    <SimpleCertSelection>true</SimpleCertSelection>
							    </CertificateStore>
						    </CredentialsSource>
						    <ServerValidation>
							    <DisableUserPromptForServerValidation>true</DisableUserPromptForServerValidation>
							    <ServerNames>server.domain.de</ServerNames>
							    <TrustedRootCA>XXXXXXXXXXXXXXX</TrustedRootCA>
						    </ServerValidation>
						    <DifferentUsername>false</DifferentUsername>
						    <PerformServerValidation xmlns="http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV2">true</PerformServerValidation> 
						    <AcceptServerName xmlns="http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV2">true</AcceptServerName> 
					    </EapType>
				    </Eap>
				    <EnableQuarantineChecks>false</EnableQuarantineChecks>
				    <RequireCryptoBinding>false</RequireCryptoBinding>
				    <PeapExtensions>
					    <PerformServerValidation xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV2">true</PerformServerValidation> 
					    <AcceptServerName xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV2">true</AcceptServerName> 
				    </PeapExtensions>
			    </EapType>
		    </Eap>
	    </Config>
    </EapHostConfig>
Gruß ,m.
Duck030
Duck030 19.02.2025 aktualisiert um 15:39:42 Uhr
Goto Top
Oh... Hi face-smile
Danke für deine Antwort.

Genau das habe ich gerade noch als P.S. ergänzt. face-smile
Hat leider auch nicht funktioniert. Soll ich mal die XML posten?
Moment. Ich versuche das nochmal.
mediodia
mediodia 19.02.2025 aktualisiert um 15:41:56 Uhr
Goto Top
Habe oben ein XML-Beispiel gepostet das du anpassen kannst.
mediodia
mediodia 19.02.2025 aktualisiert um 15:49:51 Uhr
Goto Top
Doku für das XML-Schema wie immer auch hier nachzulesen
https://learn.microsoft.com/de-de/windows/win32/eaphost/eaphost-schemas
Duck030
Duck030 19.02.2025 um 17:34:00 Uhr
Goto Top
Super. Vielen Dank. Endlich meckert er nicht mehr über die XML. Er lädt sie erfolgreich.
Aber wenn ich den SmartCard-Tag einfüge, geht es wieder nicht. Muss ich noch herausfinden, wo und wie man den korrekt einfügt.

Aber jetzt bin ich definitiv einen großen Schritt weiter.

Wenn ich das auch noch hinkriege, poste ich das Ergebnis.

Ich hoffe, man kann das hier noch so lange offen lassen.
mediodia
mediodia 19.02.2025 aktualisiert um 18:04:23 Uhr
Goto Top
Zitat von @Duck030:
Aber wenn ich den SmartCard-Tag einfüge, geht es wieder nicht. Muss ich noch herausfinden, wo und wie man den korrekt einfügt.
Die Doku zeigt es dir
https://learn.microsoft.com/de-de/windows/win32/eaphost/eaptlsconnection ...
Einfach am Schema runterhangeln, oder aus dem Quell-Stream abgucken.

Statt
...
<CredentialsSource>
    <CertificateStore>
	<SimpleCertSelection>true</SimpleCertSelection>
    </CertificateStore>
</CredentialsSource>
...
sollte für die Auswahl einer Smartcard i.d.R. das hier reichen
<CredentialsSource>
   <SmartCard />
</CredentialsSource>

!!Und immer schön auf Groß- und Kleinschreibung und paarweise geschlossene Tags achten XML ist Case-Sensitive und sehr kleinlich wenn es um inkorrekte Syntax geht!!
Duck030
Lösung Duck030 20.02.2025 um 14:24:36 Uhr
Goto Top
Also,

es funktioniert nun vollständig. Riesen Dank an Mediodia. Alles in allem würde ich sagen, war mein erster Beitrag hier ein voller Erfolg ^^.

Ich stelle hier mal das Skript inklusive XML ein für Bedürftige face-smile)
Dieses Skript erstellt eine VPN Verbindung mit dem integrierten Windows VPN Client (Windows 10).
Eigenschaften der Verbindung:
- EAP-TLS mit IKEv2
- Authentifizierung Client mit SmartCard (Yubikey mit Zertifikat, sollte aber eigentlich keine Rolle spielen)
- Authentifizierung des Servers per Zertifikat (also mutual certificate based)
- Ablehnung bei Anfrage einer unverschlüsselten Verbindung durch einen Client
- Proxy Server und Ausnahmen für LAN
- SHA384 und AES256

$vpnName = "vpnName" 
$serverAddress = "Adresse VPN Server" 
$proxyServer = "IP & Port proxyServer" 
$exceptionPrefix = '5.21.x.', '*.domain.de' 

$EAPXml = @" 
<EapHostConfig xmlns="http://www.microsoft.com/provisioning/EapHostConfig"> 
	<EapMethod>
		<Type xmlns="http://www.microsoft.com/provisioning/EapCommon">13</Type> 
		<VendorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorId> 
		<VendorType xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorType> 
		<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</AuthorId> 
	</EapMethod>
	<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig"> 
		<Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1"> 
			<Type>13</Type>
			<EapType xmlns="http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV1"> 
				<CredentialsSource>
					<SmartCard />
				</CredentialsSource>
				<ServerValidation>
					<DisableUserPromptForServerValidation>true</DisableUserPromptForServerValidation>
					<ServerNames>Adresse des Servers für Identitätsprüfung mit Zertifikat</ServerNames>
					<TrustedRootCA>Hashwert des auszuwählenden Zertifikats in den Adaptereinstellungen</TrustedRootCA>
				</ServerValidation>
				<DifferentUsername>false</DifferentUsername>
				<PerformServerValidation xmlns="http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV2">true</PerformServerValidation> 
				<AcceptServerName xmlns="http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV2">true</AcceptServerName> 
			</EapType>
		</Eap>
	</Config>
</EapHostConfig>
"@ 

#Write-Output $EAPXml
Add-VpnConnection -Name $vpnName -ServerAddress $serverAddress -TunnelType "IKEv2" -EncryptionLevel "Maximum" -AuthenticationMethod Eap -AllUserConnection -RememberCredential -EapConfigXmlStream $EAPXml 

Set-VpnConnectionIPsecConfiguration -ConnectionName $vpnName -AuthenticationTransformConstants None -CipherTransformConstants AES256 -EncryptionMethod AES256 -IntegrityCheckMethod SHA384 -PfsGroup None -DHGroup ECP384 -PassThru -Force

Set-VpnConnectionProxy -ConnectionName $vpnName -ProxyServer $proxyServer -ExceptionPrefix $exceptionPrefix -BypassProxyForLocal
mediodia
mediodia 20.02.2025 aktualisiert um 14:27:36 Uhr
Goto Top
Glückwunsch! Dann fehlt ja nur noch das "Gelöst" markieren am hiesigen Beitrag.