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

feat(binding_coap): add support for PEM root certificates #207

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/binding_coap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
/// [spec link]: https://www.w3.org/TR/wot-binding-templates/
library binding_coap;

export "package:coap/coap.dart"
show Certificate, DerCertificate, PemCertificate;

export "src/binding_coap/coap_client_factory.dart";
export "src/binding_coap/coap_config.dart";
export "src/binding_coap/coap_server.dart";
9 changes: 6 additions & 3 deletions lib/src/binding_coap/coap_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// SPDX-License-Identifier: BSD-3-Clause

import "dart:async";
import "dart:typed_data";

import "package:coap/coap.dart" as coap;
import "package:coap/config/coap_config_default.dart";
Expand All @@ -26,7 +25,8 @@ class _InternalCoapConfig extends CoapConfigDefault {
dtlsCiphers = coapConfig.dtlsCiphers,
dtlsVerify = coapConfig.dtlsVerify,
dtlsWithTrustedRoots = coapConfig.dtlsWithTrustedRoots,
rootCertificates = coapConfig.rootCertificates;
rootCertificates = coapConfig.rootCertificates,
openSslSecurityLevel = coapConfig.openSslSecurityLevel;

@override
final int preferredBlockSize;
Expand All @@ -41,7 +41,10 @@ class _InternalCoapConfig extends CoapConfigDefault {
final bool dtlsWithTrustedRoots;

@override
final List<Uint8List> rootCertificates;
final List<coap.Certificate> rootCertificates;

@override
final int? openSslSecurityLevel;
}

coap.PskCredentialsCallback? _createPskCallback(
Expand Down
21 changes: 18 additions & 3 deletions lib/src/binding_coap/coap_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
//
// SPDX-License-Identifier: BSD-3-Clause

import "dart:typed_data";

import "package:coap/coap.dart";
import "package:meta/meta.dart";

/// Allows for configuring the behavior of CoAP clients and servers.
Expand All @@ -22,6 +21,7 @@ class CoapConfig {
this.rootCertificates = const [],
this.dtlsWithTrustedRoots = true,
this.dtlsVerify = true,
this.openSslSecurityLevel,
});

/// Whether certificates should be verified by OpenSSL.
Expand All @@ -34,7 +34,7 @@ class CoapConfig {
final String? dtlsCiphers;

/// List of custom root certificates to use with OpenSSL.
final List<Uint8List> rootCertificates;
final List<Certificate> rootCertificates;

/// The port number used by a client or server. Defaults to 5683.
final int port;
Expand All @@ -57,4 +57,19 @@ class CoapConfig {
///
/// Defaults to 60 seconds.
final Duration multicastDiscoveryTimeout;

/// Security level override for using DTLS with OpenSSL.
///
/// The possible values for the security level range from 0 to 5.
///
/// Lowering the security level can be necessary with newer versions of
/// OpenSSL to still be able to use the mandatory CoAP cipher suites
/// (e.g., `TLS_PSK_WITH_AES_128_CCM_8`, see [section 9.1.3.1 of RFC 7252]).
///
/// See the [OpenSSL documentation] for more information on the meaning of the
/// individual security levels.
///
/// [section 9.1.3.1 of RFC 7252]: https://datatracker.ietf.org/doc/html/rfc7252#section-9.1.3.1
/// [OpenSSL documentation]: https://docs.openssl.org/master/man3/SSL_CTX_set_security_level/#default-callback-behaviour
final int? openSslSecurityLevel;
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dev_dependencies:

dependencies:
cbor: ^6.1.0
coap: ^9.0.0
coap: ^9.1.0
collection: ^1.17.2
curie: ^0.1.0
dcaf: ^0.1.0
Expand Down
Loading