flutter dart의 dart_amqp 라이브러리에서 tls 설정할 수 있다고 한다.
https://pub.dev/packages/dart_amqp/example
ConnectionSettings({
this.host = "127.0.0.1",
this.port = 5672,
this.virtualHost = "/",
this.authProvider = const PlainAuthenticator("guest", "guest"),
this.maxConnectionAttempts = 1,
this.reconnectWaitTime = const Duration(milliseconds: 1500),
TuningSettings? tuningSettings,
this.tlsContext,
this.onBadCertificate,
}) : tuningSettings = tuningSettings ?? TuningSettings();
여기에서 tlsContext 부분이 tls 설정 부분이다.
Security Context 공식 문서 https://api.flutter.dev/flutter/dart-io/SecurityContext-class.html
tls관련
http://gjchoi.github.io/rabbit/rabbit-mq-TLS/
https://www.youtube.com/results?search_query=SSL+in+flutter
https://doc.xuwenliang.com/docs/dart-flutter/1378 [TLS/SSL with Dart]
https://github.com/xoltawn/mtls_example_flutter/blob/main/lib/main.dart [mtls 예제]
SecurityContext sc = SecurityContext(withTrustedRoots: true);
sc.useCertificateChainBytes(certificateChainBytes);
sc.usePrivateKeyBytes(keyBytes);
Future<List<int>> getKeyBytes() async {
return (await rootBundle.load('assets/keys/private.key'))
.buffer
.asInt8List();
}
Future<List<int>> getCertificateChainBytes() async {
return (await rootBundle.load('assets/keys/certificate.crt'))
.buffer
.asInt8List();
}
Future<SecurityContext> get globalContext async {
List<int> keyBytes = await getKeyBytes();
List<int> certificateChainBytes = await getCertificateChainBytes();
SecurityContext sc = SecurityContext(withTrustedRoots: false);
sc.usePrivateKeyBytes(keyBytes);
sc.useCertificateChainBytes(certificateChainBytes);
return sc;
}
https://api.flutter.dev/flutter/dart-io/SecurityContext/usePrivateKeyBytes.html
https://api.flutter.dev/flutter/dart-io/SecurityContext/useCertificateChainBytes.html
Future<SecurityContext> get globalContext async {
final List<int> keyBytes =
(await rootBundle.load(‘assets/resources/key.key’))
.buffer
.asInt8List();
final List<int> certificateChainBytes =
(await rootBundle.load(‘assets/resources/key_crt.crt’))
.buffer
.asInt8List();
SecurityContext sc = SecurityContext(withTrustedRoots: false);
sc.usePrivateKeyBytes(keyBytes);
sc.useCertificateChainBytes(certificateChainBytes);
return sc;
}
https://xoltawn.medium.com/how-to-use-mtls-in-flutter-da698e5700ef
https://github.com/xoltawn/mtls_example_flutter/blob/main/lib/main.dart
SSL pinning
https://medium.com/surfstudio/ssl-pinning-in-flutter-apps-254e01e57965
[중요]
client 에서 tls관련 설정은 아래와 같다.
ByteData data = await rootBundle.load('assets/raw/certificate.crt');
SecurityContext context = SecurityContext.defaultContext;
context.setTrustedCertificatesBytes(data.buffer.asUint8List());
client = HttpClient(context: context);
참고 :: https://stackoverflow.com/questions/54104685/flutter-add-self-signed-certificate-from-asset-folder
openssl로-ssltls-통신-절차-확인하기
https://kthan.tistory.com/entry/openssl%EB%A1%9C-ssltls-%ED%86%B5%EC%8B%A0-%EC%A0%88%EC%B0%A8-%ED%99%95%EC%9D%B8%ED%95%98%EA%B8%B0
openssl로 인증서 만들기
https://blusky10.tistory.com/352