You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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));
}`
The text was updated successfully, but these errors were encountered:
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 :)
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);
}
`
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));
}`
The text was updated successfully, but these errors were encountered: