Skip to content

[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: FileSystemException: Cannot open file, path = '...' (OS Error: No such file or directory, errno = 2) #43472

Description

@103style

Error info:
[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: FileSystemException: Cannot open file, path = '//crt/crt/cilent.crt' (OS Error: No such file or directory, errno = 2)

Flutter and dart version:

Flutter 1.9.1+hotfix.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 1aedbb1835 (7 days ago) • 2019-10-17 08:37:27 -0700
Engine • revision b863200c37
Tools • Dart 2.5.0

project file dir like this:

project
-crt
--crt
---cilent.crt

when i use the following code, and this error is appear

import 'package:path/path.dart' as path;
Future<int> main() async {
    final String currDir ='${path.current}${path.separator}crt${path.separator}';
    final SecurityContext context = SecurityContext.defaultContext;
    context.setTrustedCertificates(currDir + path.join('crt','client.crt'));
}

this is when i use mqtt_client library, and i also comment in mqtt_client's issues


and i try config the path in the pubspec.yaml

flutter:
  assets:
  - crt/crt/client.crt

and rootBundle.loadString('crt/crt/client.crt') haven't show the error,

import 'dart:async' show Future;
import 'package:flutter/services.dart' show rootBundle;

Future<String> loadAsset() async {
  return await rootBundle.loadString('crt/crt/client.crt');
}

but when i load the client.crt use following code, and the same error OS Error: No such file or directory, errno = 2 appear

final SecurityContext context = SecurityContext.defaultContext;
context.setTrustedCertificates('crt/crt/client.crt');

thanks.

Activity

  1. changed the title [-][ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: FileSystemException: Cannot open file, path = '//crt/crt/cilent.crt' (OS Error: No such file or directory, errno = 2)[/-] [+][ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: FileSystemException: Cannot open file, path = '...' (OS Error: No such file or directory, errno = 2)[/+] on Oct 25, 2019
  2. iapicca commented on Oct 25, 2019

    @iapicca

    Hi @103style
    could you please provide your flutter run --verbose.
    Thank you

  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 25, 2019
  4. 103style commented on Oct 25, 2019

    @103style
    Author

    Hi @103style
    could you please provide your flutter run --verbose.
    Thank you

    @iapicca

    i just copy the log after install apk, if you need more ,please let me know. thanks a lot.

    flutter run --verbose log

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 25, 2019
  6. added
    p: path_providerPlugin that provides resolved paths to some platform directories
    on Oct 25, 2019
  7. 103style commented on Oct 25, 2019

    @103style
    Author

    we are using mqtt_client library, and i coding like code file line 42-45, and then the error info appear.

    maybe this will help you to get more info.

  8. 103style commented on Oct 25, 2019

    @103style
    Author

    Now I am ready to do like this:
    first i witre a file in the getApplicationDocumentsDirectory dir,
    and the use the context.setTrustedCertificates(file.path);

      Future<int> main() async {
        final SecurityContext context = SecurityContext.defaultContext;
        String crtPath = await _getLocalFile("client.crt");
        context.setTrustedCertificates(crtPath);
        client.securityContext = context;
        client.setProtocolV311();
        return 0;
      }
    
      Future<String> _getLocalFile(String filename) async {
        String dir = (await getApplicationDocumentsDirectory()).path;
        File file = new File('$dir/$filename');
        bool exist = await file.exists();
        log('exist = $exist');
        if (!exist) {
           file.writeAsString('''-----BEGIN CERTIFICATE-----
              MIIDQDCCAigCCQCPNMDXN3AfRjANBgkqhkiG9w0BAQsFADBmMQswCQYDVQQGEwJF
              N12AHBWWGeOir6+09zdT1ULBgbwDc8l9mN1G94xe/7UUdN9xNmDe2wV8V181Eau9
              jIL5iFFAogR+hHP9H45VLU3QdNY=
              -----END CERTIFICATE-----
              ''');
        }
        String contents = await file.readAsString();
        log(contents);
        return file.path;
      }
    
  9. 103style commented on Oct 25, 2019

    @103style
    Author

    I suggest add a function to get the file's path which is config in the pubspec.yaml assets:,
    if the function is exist now , please let konw,
    thank a lot.

  10. 103style commented on Nov 5, 2019

    @103style
    Author

    SecurityContext

    void setAlpnProtocols(List<String> protocols, bool isServer);
    void usePrivateKey(String file, {String password});
    void usePrivateKeyBytes(List<int> keyBytes, {String password});
    void setTrustedCertificates(String file, {String password});
    void setTrustedCertificatesBytes(List<int> certBytes, {String password});
    void useCertificateChain(String file, {String password});
    void useCertificateChainBytes(List<int> chainBytes, {String password});
    void setClientAuthorities(String file, {String password});
    void setClientAuthoritiesBytes(List<int> authCertBytes, {String password});
    
  11. github-actions commented on Aug 26, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  12. locked as resolved and limited conversation to collaborators on Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    p: path_providerPlugin that provides resolved paths to some platform directoriespackageflutter/packages repository. See also p: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions