Skip to content

Commit cfd1d05

Browse files
undo changes
1 parent ee7347e commit cfd1d05

File tree

8 files changed

+224
-6
lines changed

8 files changed

+224
-6
lines changed

ffi/dotnet/Devolutions.IronRdp/Generated/CredsspSequence.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public unsafe CredsspSequence(Raw.CredsspSequence* handle)
5353
/// <returns>
5454
/// A <c>CredsspSequenceInitResult</c> allocated on Rust side.
5555
/// </returns>
56-
public static CredsspSequenceInitResult Init(ClientConnector connector, string serverName, byte[] serverPublicKey)
56+
public static CredsspSequenceInitResult Init(ClientConnector connector, string serverName, byte[] serverPublicKey, KerberosConfig? kerberoConfigs)
5757
{
5858
unsafe
5959
{
@@ -66,11 +66,24 @@ public static CredsspSequenceInitResult Init(ClientConnector connector, string s
6666
{
6767
throw new ObjectDisposedException("ClientConnector");
6868
}
69+
Raw.KerberosConfig* kerberoConfigsRaw;
70+
if (kerberoConfigs == null)
71+
{
72+
kerberoConfigsRaw = null;
73+
}
74+
else
75+
{
76+
kerberoConfigsRaw = kerberoConfigs.AsFFI();
77+
if (kerberoConfigsRaw == null)
78+
{
79+
throw new ObjectDisposedException("KerberosConfig");
80+
}
81+
}
6982
fixed (byte* serverPublicKeyPtr = serverPublicKey)
7083
{
7184
fixed (byte* serverNameBufPtr = serverNameBuf)
7285
{
73-
Raw.CredsspFfiResultBoxCredsspSequenceInitResultBoxIronRdpError result = Raw.CredsspSequence.Init(connectorRaw, serverNameBufPtr, serverNameBufLength, serverPublicKeyPtr, serverPublicKeyLength);
86+
Raw.CredsspFfiResultBoxCredsspSequenceInitResultBoxIronRdpError result = Raw.CredsspSequence.Init(connectorRaw, serverNameBufPtr, serverNameBufLength, serverPublicKeyPtr, serverPublicKeyLength, kerberoConfigsRaw);
7487
if (!result.isOk)
7588
{
7689
throw new IronRdpException(new IronRdpError(result.Err));
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// <auto-generated/> by Diplomat
2+
3+
#pragma warning disable 0105
4+
using System;
5+
using System.Runtime.InteropServices;
6+
7+
using Devolutions.IronRdp.Diplomat;
8+
#pragma warning restore 0105
9+
10+
namespace Devolutions.IronRdp;
11+
12+
#nullable enable
13+
14+
public partial class KerberosConfig: IDisposable
15+
{
16+
private unsafe Raw.KerberosConfig* _inner;
17+
18+
/// <summary>
19+
/// Creates a managed <c>KerberosConfig</c> from a raw handle.
20+
/// </summary>
21+
/// <remarks>
22+
/// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free).
23+
/// <br/>
24+
/// This constructor assumes the raw struct is allocated on Rust side.
25+
/// If implemented, the custom Drop implementation on Rust side WILL run on destruction.
26+
/// </remarks>
27+
public unsafe KerberosConfig(Raw.KerberosConfig* handle)
28+
{
29+
_inner = handle;
30+
}
31+
32+
/// <summary>
33+
/// Creates a new KerberosConfig for KDC proxy support.
34+
/// </summary>
35+
/// <remarks>
36+
/// # Arguments
37+
/// * `kdc_proxy_url` - KDC proxy URL (e.g., "https://gateway.example.com/KdcProxy/{token}"), empty string if not used
38+
/// * `hostname` - Client hostname for Kerberos, empty string if not used
39+
/// </remarks>
40+
/// <exception cref="IronRdpException"></exception>
41+
/// <returns>
42+
/// A <c>KerberosConfig</c> allocated on Rust side.
43+
/// </returns>
44+
public static KerberosConfig New(string kdcProxyUrl, string hostname)
45+
{
46+
unsafe
47+
{
48+
byte[] kdcProxyUrlBuf = DiplomatUtils.StringToUtf8(kdcProxyUrl);
49+
byte[] hostnameBuf = DiplomatUtils.StringToUtf8(hostname);
50+
nuint kdcProxyUrlBufLength = (nuint)kdcProxyUrlBuf.Length;
51+
nuint hostnameBufLength = (nuint)hostnameBuf.Length;
52+
fixed (byte* kdcProxyUrlBufPtr = kdcProxyUrlBuf)
53+
{
54+
fixed (byte* hostnameBufPtr = hostnameBuf)
55+
{
56+
Raw.CredsspFfiResultBoxKerberosConfigBoxIronRdpError result = Raw.KerberosConfig.New(kdcProxyUrlBufPtr, kdcProxyUrlBufLength, hostnameBufPtr, hostnameBufLength);
57+
if (!result.isOk)
58+
{
59+
throw new IronRdpException(new IronRdpError(result.Err));
60+
}
61+
Raw.KerberosConfig* retVal = result.Ok;
62+
return new KerberosConfig(retVal);
63+
}
64+
}
65+
}
66+
}
67+
68+
/// <summary>
69+
/// Returns the underlying raw handle.
70+
/// </summary>
71+
public unsafe Raw.KerberosConfig* AsFFI()
72+
{
73+
return _inner;
74+
}
75+
76+
/// <summary>
77+
/// Destroys the underlying object immediately.
78+
/// </summary>
79+
public void Dispose()
80+
{
81+
unsafe
82+
{
83+
if (_inner == null)
84+
{
85+
return;
86+
}
87+
88+
Raw.KerberosConfig.Destroy(_inner);
89+
_inner = null;
90+
91+
GC.SuppressFinalize(this);
92+
}
93+
}
94+
95+
~KerberosConfig()
96+
{
97+
Dispose();
98+
}
99+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// <auto-generated/> by Diplomat
2+
3+
#pragma warning disable 0105
4+
using System;
5+
using System.Runtime.InteropServices;
6+
7+
using Devolutions.IronRdp.Diplomat;
8+
#pragma warning restore 0105
9+
10+
namespace Devolutions.IronRdp.Raw;
11+
12+
#nullable enable
13+
14+
[StructLayout(LayoutKind.Sequential)]
15+
public partial struct CredsspFfiResultBoxKerberosConfigBoxIronRdpError
16+
{
17+
[StructLayout(LayoutKind.Explicit)]
18+
private unsafe struct InnerUnion
19+
{
20+
[FieldOffset(0)]
21+
internal KerberosConfig* ok;
22+
[FieldOffset(0)]
23+
internal IronRdpError* err;
24+
}
25+
26+
private InnerUnion _inner;
27+
28+
[MarshalAs(UnmanagedType.U1)]
29+
public bool isOk;
30+
31+
public unsafe KerberosConfig* Ok
32+
{
33+
get
34+
{
35+
return _inner.ok;
36+
}
37+
}
38+
39+
public unsafe IronRdpError* Err
40+
{
41+
get
42+
{
43+
return _inner.err;
44+
}
45+
}
46+
}

ffi/dotnet/Devolutions.IronRdp/Generated/RawCredsspSequence.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public partial struct CredsspSequence
2020
public static unsafe extern PduHint* NextPduHint(CredsspSequence* self);
2121

2222
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CredsspSequence_init", ExactSpelling = true)]
23-
public static unsafe extern CredsspFfiResultBoxCredsspSequenceInitResultBoxIronRdpError Init(ClientConnector* connector, byte* serverName, nuint serverNameSz, byte* serverPublicKey, nuint serverPublicKeySz);
23+
public static unsafe extern CredsspFfiResultBoxCredsspSequenceInitResultBoxIronRdpError Init(ClientConnector* connector, byte* serverName, nuint serverNameSz, byte* serverPublicKey, nuint serverPublicKeySz, KerberosConfig* kerberoConfigs);
2424

2525
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CredsspSequence_decode_server_message", ExactSpelling = true)]
2626
public static unsafe extern CredsspFfiResultOptBoxTsRequestBoxIronRdpError DecodeServerMessage(CredsspSequence* self, byte* pdu, nuint pduSz);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// <auto-generated/> by Diplomat
2+
3+
#pragma warning disable 0105
4+
using System;
5+
using System.Runtime.InteropServices;
6+
7+
using Devolutions.IronRdp.Diplomat;
8+
#pragma warning restore 0105
9+
10+
namespace Devolutions.IronRdp.Raw;
11+
12+
#nullable enable
13+
14+
[StructLayout(LayoutKind.Sequential)]
15+
public partial struct KerberosConfig
16+
{
17+
private const string NativeLib = "DevolutionsIronRdp";
18+
19+
/// <summary>
20+
/// Creates a new KerberosConfig for KDC proxy support.
21+
/// </summary>
22+
/// <remarks>
23+
/// # Arguments
24+
/// * `kdc_proxy_url` - KDC proxy URL (e.g., "https://gateway.example.com/KdcProxy/{token}"), empty string if not used
25+
/// * `hostname` - Client hostname for Kerberos, empty string if not used
26+
/// </remarks>
27+
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "KerberosConfig_new", ExactSpelling = true)]
28+
public static unsafe extern CredsspFfiResultBoxKerberosConfigBoxIronRdpError New(byte* kdcProxyUrl, nuint kdcProxyUrlSz, byte* hostname, nuint hostnameSz);
29+
30+
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "KerberosConfig_destroy", ExactSpelling = true)]
31+
public static unsafe extern void Destroy(KerberosConfig* self);
32+
}

ffi/dotnet/Devolutions.IronRdp/src/Connection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private static async Task<ConnectionResult> ConnectFinalize(string serverName, C
9797
private static async Task PerformCredsspSteps(ClientConnector connector, string serverName, WriteBuf writeBuf,
9898
Framed<SslStream> framedSsl, byte[] serverpubkey)
9999
{
100-
var credsspSequenceInitResult = CredsspSequence.Init(connector, serverName, serverpubkey);
100+
var credsspSequenceInitResult = CredsspSequence.Init(connector, serverName, serverpubkey, null);
101101
var credsspSequence = credsspSequenceInitResult.GetCredsspSequence();
102102
var tsRequest = credsspSequenceInitResult.GetTsRequest();
103103
var tcpClient = new TcpClient();

ffi/dotnet/Devolutions.IronRdp/src/RDCleanPathConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private static async Task PerformCredsspSteps(
224224
hostname = serverName.Substring(0, colonIndex);
225225
}
226226

227-
var credsspSequenceInitResult = CredsspSequence.Init(connector, hostname, serverpubkey);
227+
var credsspSequenceInitResult = CredsspSequence.Init(connector, hostname, serverpubkey, null);
228228
var credsspSequence = credsspSequenceInitResult.GetCredsspSequence();
229229
var tsRequest = credsspSequenceInitResult.GetTsRequest();
230230
var tcpClient = new System.Net.Sockets.TcpClient();

ffi/src/credssp/mod.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,33 @@ pub mod ffi {
1313
use crate::error::ValueConsumedError;
1414
use crate::pdu::ffi::WriteBuf;
1515

16+
#[diplomat::opaque]
17+
pub struct KerberosConfig(pub ironrdp::connector::credssp::KerberosConfig);
18+
19+
impl KerberosConfig {
20+
/// Creates a new KerberosConfig for KDC proxy support.
21+
///
22+
/// # Arguments
23+
/// * `kdc_proxy_url` - KDC proxy URL (e.g., "https://gateway.example.com/KdcProxy/{token}"), empty string if not used
24+
/// * `hostname` - Client hostname for Kerberos, empty string if not used
25+
pub fn new(kdc_proxy_url: &str, hostname: &str) -> Result<Box<KerberosConfig>, Box<IronRdpError>> {
26+
let kdc_proxy_url_opt = if kdc_proxy_url.is_empty() {
27+
None
28+
} else {
29+
Some(kdc_proxy_url.to_owned())
30+
};
31+
32+
let hostname_opt = if hostname.is_empty() {
33+
None
34+
} else {
35+
Some(hostname.to_owned())
36+
};
37+
38+
let config = ironrdp::connector::credssp::KerberosConfig::new(kdc_proxy_url_opt, hostname_opt)?;
39+
Ok(Box::new(KerberosConfig(config)))
40+
}
41+
}
42+
1643
#[diplomat::opaque]
1744
pub struct CredsspSequence(pub ironrdp::connector::credssp::CredsspSequence);
1845

@@ -50,6 +77,7 @@ pub mod ffi {
5077
connector: &ClientConnector,
5178
server_name: &str,
5279
server_public_key: &[u8],
80+
kerbero_configs: Option<&KerberosConfig>,
5381
) -> Result<Box<CredsspSequenceInitResult>, Box<IronRdpError>> {
5482
let Some(connector) = connector.0.as_ref() else {
5583
return Err(ValueConsumedError::for_item("connector").into());
@@ -63,7 +91,7 @@ pub mod ffi {
6391
selected_protocol,
6492
server_name.into(),
6593
server_public_key.to_owned(),
66-
None,
94+
kerbero_configs.map(|config| config.0.clone()),
6795
)?;
6896

6997
Ok(Box::new(CredsspSequenceInitResult {

0 commit comments

Comments
 (0)