Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pure dart dtls #166

Open
vincent-iQontrol opened this issue Jan 26, 2023 · 1 comment
Open

Pure dart dtls #166

vincent-iQontrol opened this issue Jan 26, 2023 · 1 comment

Comments

@vincent-iQontrol
Copy link
Contributor

vincent-iQontrol commented Jan 26, 2023

Is it possible to use just pure dart for DTLS instead of openssl like this:

`
import 'dart:io';
import 'dart:async';

Future createDtlsConnection() async {
// Create a SecurityContext object
final securityContext = SecurityContext();
securityContext.setAlpnProtocols(['dtls1.2'], true);
securityContext.setPSKIdentity("client_identity");
securityContext.setPSK("client_secret".codeUnits);

// Create a SecureSocket object
final socket = await SecureSocket.connect(
'dtls.example.com', 
8443, 
context: securityContext,
);

// Send and receive data over the socket
socket.write('Hello, DTLS!');
final response = await socket.read();
print(String.fromCharCodes(response));

}
`

or

`import 'dart:io';
import 'dart:async';

Future createDtlsConnection() async {
// Load the certificate and private key from files
final certificate = await File('path/to/certificate.pem').readAsString();
final privateKey = await File('path/to/private_key.pem').readAsString();
final caCertificate = await File('path/to/ca_certificate.pem').readAsString();

// Create a SecurityContext object
final securityContext = SecurityContext();
securityContext.useCertificateChainBytes(certificate.codeUnits);
securityContext.usePrivateKeyBytes(privateKey.codeUnits);
securityContext.setTrustedCertificatesBytes(caCertificate.codeUnits);

// Create a SecureSocket object
final socket = await SecureSocket.connect(
'dtls.example.com',
8443,
context: securityContext,
);

// Send and receive data over the socket
socket.write('Hello, DTLS!');
final response = await socket.read();
print(String.fromCharCodes(response));
}`

@JKRhb
Copy link
Contributor

JKRhb commented Jan 26, 2023

That is definitely the goal and would be very desirable! However, the SecureSocket class from dart:io currently only supports TLS, therefore the code you posted does not work at the moment :/ (Also see this issue: dart-lang/sdk#43378) However, based on the foundations laid in the DTLS packages, maybe it will be possible to create an integration into the Dart SDK in the not too distant future :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants