V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
fiveelementgid
V2EX  ›  程序员

微软说的 cross-platform...开发环境一言难尽

  •  1
     
  •   fiveelementgid · 2020-11-24 19:09:32 +08:00 · 5104 次点击
    这是一个创建于 1241 天前的主题,其中的信息可能已经有所发展或是发生改变。

    微软说的 cross-platform,先不说部署的时候一堆奇怪的 bug,这 Linux 下的开发环境的手动配置真是 把人恶心炸了 用的是 Visual Studio Code

    1.png

    也有人问为啥不上 JetBrains 的 Rider

    2.png

    因为目前为止还不支持.net 5,本来就是冲着这个去的,EAP 据说 bug 也很多

    Visual Studio Code 主要是做 C#和 ASP.NET Core,问题来了,他这个配置 develop certificate(self-signed)自签名证书。 微软的他推荐的一键命令: dotnet dev-certs https --trust ,但是这个在 VSC For Linux 下根本没用, 微软只有一句话:

    See the documentation for your Linux distribution on how to trust the HTTPS development certificate.

    微软生成的自签名证书,存在~/dotnet/corefx/cryptography/x509stores/([0-9A-F]+).pfx,查了一下,用 的是微软自己的 pkcs12 算法生成的......搞了一天也没查到去哪里导入..... 欸...开始怀疑自己是不是上错车了,每日骂微软 1/1

    52 条回复    2020-11-26 12:18:24 +08:00
    hjc4869
        1
    hjc4869  
       2020-11-24 19:12:42 +08:00 via Android
    pkcs12 是标准格式吧… openssl 有支持的
    secondwtq
        2
    secondwtq  
       2020-11-24 19:14:59 +08:00
    PKCS12 是一种格式,不是一种算法 ...
    whywhywhy
        4
    whywhywhy  
       2020-11-24 19:16:16 +08:00
    现在刚学 .net ,到处都看到在说不管从什么角度都要转 java,心累,唉。
    aloyuu
        5
    aloyuu  
       2020-11-24 19:18:57 +08:00
    @whywhywhy 已经从 java 转到 C# ,建议不要入 JAVA
    nannanziyu
        6
    nannanziyu  
       2020-11-24 19:20:12 +08:00   ❤️ 19
    1. 你好好问应该怎么做
    自然会回答你。
    2. 你起手就无能吐槽
    那只能跟你说,安装个 pfx 证书搞了一天也没搞定?你改行吧,你解决问题的能力不适合编程
    jiangzm
        7
    jiangzm  
       2020-11-24 19:22:32 +08:00   ❤️ 5
    典型的拉不出屎来怪厕所不好👍
    cxe2v
        8
    cxe2v  
       2020-11-24 19:28:37 +08:00
    linux 不就是以可以自由配置而自豪地吗?
    love
        9
    love  
       2020-11-24 19:38:49 +08:00   ❤️ 1
    @whywhywhy 是什么支持你要选困难模式呢?千万别说是情怀。。。M$有个啥情怀
    securityCoding
        10
    securityCoding  
       2020-11-24 19:42:48 +08:00
    面向工资编程
    fiveelementgid
        11
    fiveelementgid  
    OP
       2020-11-24 19:44:45 +08:00 via Android
    @hjc4869 openssl 导出了 cert 和 key,也不知道咋导入.....

    @secondwtq emmm 谢谢(• ▽ •;),有点表述错误

    @LokiSharp 这个我昨天已经试过了,不行,我这是 fedora 33,你看那个最高赞的答案原本是 48,我昨天点赞成的 49.......
    @whywhywhy .....心疼
    @nannanziyu 啊这,稍等,我重新仔细问一遍
    @jiangzm (ꏿ﹏ꏿ;)我错了,我重新问一遍
    @cxe2v 是啊,但是配置不成功就很痛苦了
    nannanziyu
        12
    nannanziyu  
       2020-11-24 19:45:29 +08:00 via Android   ❤️ 1
    @love
    因为能挣钱可以吧
    每个 dotnet 的帖子都见你来嘲讽下
    zhuangzhuang1988
        13
    zhuangzhuang1988  
       2020-11-24 19:46:53 +08:00
    那就用 Java 呗, 反正不要钱
    nannanziyu
        14
    nannanziyu  
       2020-11-24 19:49:26 +08:00
    @fiveelementgid
    1. export pfx to pem
    2. Copy the certificate pem to /etc/pki/ca-trust/source/anchors
    3. Then run update-ca-trust
    fiveelementgid
        15
    fiveelementgid  
    OP
       2020-11-24 19:55:47 +08:00
    @cxe2v
    @jiangzm
    @nannanziyu
    重新提问:VS Code 的证书存在于.dotnet/corefx/cryptography/x509stores/my/*********.pfx 下,我现在需要将 VSC 中 ASP.NET Core 中的 127.0.0.1 的 CA 证书加入可信任证书。
    openssl pkcs12 -in ~/.dotnet/corefx/cryptography/x509stores/my/***************EA.pfx -out VSC.cert -nodes -nokeys 可以导出 VSC.cert
    openssl pkcs12 -in ~/.dotnet/corefx/cryptography/x509stores/my/01*********0F8EA.pfx -out VSC.key -nodes -nocerts 可以导出 VSC.key
    根据 https://stackoverflow.com/questions/55485511/how-to-run-dotnet-dev-certs-https-trust 所说调整,rpm 系 Linux 应该用`update-ca-trust`进行更新
    根据 man update-ca-trust 文档
    > QUICK HELP 1: To add a certificate in the simple PEM or DER file formats to the list
    of CAs trusted on the system:

    • add it as a new file to directory /etc/pki/ca-trust/source/anchors/

    • run `update-ca-trust extract`

    然后把上面得到的 VSC.cert 导入到 /etc/pki/ca-trust/source/anchors/里面,然后执行`update-ca-trust extract`,进去 127.0.0.1 还是 invalid certificate
    求解决方案
    woahishui
        16
    woahishui  
       2020-11-24 19:59:51 +08:00 via Android
    楼主不要急,慢慢解决
    nannanziyu
        17
    nannanziyu  
       2020-11-24 19:59:59 +08:00
    @fiveelementgid
    不确定,你先判断下是自签名证书信任未生效,还是浏览器没有信任
    你 curl 127.0.0.1 试一下呢
    fiveelementgid
        18
    fiveelementgid  
    OP
       2020-11-24 20:00:04 +08:00
    @securityCoding
    @zhuangzhuang1988 暂时不打算 Java,看看被吊打到啥时候吧.....


    @nannanziyu export pfx to pem 我昨天也查了一下,参考了这个 https://www.sslshopper.com/ssl-converter.html,和上一楼我说的情况操作一样,依旧是无效
    12101111
        19
    12101111  
       2020-11-24 20:04:56 +08:00
    每一个 Linux 管理 openssl 默认密钥的方式都不一样,更何况还有 libressl 和 GNU TLS,这是 Linux 的优点也是缺点, 不会找 Linux 发行版的文档还怪微软没有水晶球不知道你在用哪个 Linux 发行版.
    fiveelementgid
        20
    fiveelementgid  
    OP
       2020-11-24 20:10:19 +08:00
    @woahishui 感谢
    fiveelementgid
        21
    fiveelementgid  
    OP
       2020-11-24 20:12:35 +08:00
    @12101111 这边是 fedora 33
    no1xsyzy
        22
    no1xsyzy  
       2020-11-24 20:53:05 +08:00
    先问下你浏览器是? Firefox 的话独立证书管理器不管系统证书的

    你先 curl 看看配置成功了没
    fiveelementgid
        23
    fiveelementgid  
    OP
       2020-11-24 21:36:33 +08:00
    @nannanziyu 。。。。。我表述不对吗......就是证书是有的,不过一直无法加入信任列表

    结果是
    output:curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to localhost


    @no1xsyzy 我用的 chrome
    qiufengshe
        24
    qiufengshe  
       2020-11-24 21:45:51 +08:00
    楼主说的太偏激了,即使跨平台开发,一般还是在 Windows 开发好,部署到 Linux 上,C#有好用的 VS 不用,偏去用 VS Code,体验肯定不一样呀!
    LokiSharp
        25
    LokiSharp  
       2020-11-24 23:05:03 +08:00
    RHEL 上面是这样的 Fedora 应该也差不多吧

    cp /root/certs/<certname>.cer /etc/pki/ca-trust/source/anchors/
    update-ca-trust extract
    cd /etc/pki/tls/certs/
    openssl x509 -in ca-bundle.crt -text -noout

    https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/security_guide/sec-shared-system-certificates
    https://access.redhat.com/solutions/3220561
    fiveelementgid
        26
    fiveelementgid  
    OP
       2020-11-24 23:09:02 +08:00
    @qiufengshe emmmmmm,个人观点总不能赖在 VS 和 windows 上吧....CLI 总要学学

    @LokiSharp 谢谢!,我去试试
    Mithril
        27
    Mithril  
       2020-11-24 23:15:22 +08:00
    @fiveelementgid 那个体验确实是差的非常多。。基本上在 Windows 也没多少人用 VS Code 写 C#的。。
    fiveelementgid
        28
    fiveelementgid  
    OP
       2020-11-24 23:31:37 +08:00
    @LokiSharp 依旧没用......裂开
    ladypxy
        29
    ladypxy  
       2020-11-24 23:39:29 +08:00 via iPhone
    微软的文档已经是业界最好的了,没有之一……
    你这都搞不定,真的只能像上面说的,可能不适合这行……
    Jirajine
        30
    Jirajine  
       2020-11-24 23:42:38 +08:00 via Android
    换自己的证书啊,开发用 mkcert,部署私有 ca 用 step 。
    beginor
        31
    beginor  
       2020-11-24 23:43:11 +08:00 via Android
    不用 SSL 也可以玩啊,为啥跟 HTTPS 较劲呢?好像是加个这样的参数就行了

    dotnet new mvc --no-https
    fiveelementgid
        32
    fiveelementgid  
    OP
       2020-11-25 00:41:49 +08:00
    @ladypxy 微软的文档我正要喷呢,等我下一个帖子,语法错误和小问题一大把....

    @Jirajine emmmmm,VSC 咋导入证书又是一个问题了

    @beginor 看到了,没有 http 也行,但是部署会出很多其他的问题,顺便说一句 new 创建 MVC Template 模板,MVC 已经被淘汰了
    laminux29
        33
    laminux29  
       2020-11-25 00:45:39 +08:00
    微软每次 VS 更新最新版的预览版,创建一个空项目,只是 F5 也容易遇到一堆问题。

    这个问题的本质是目前软工规模太太太太太太大了,一个 IDE 的复杂度已经不亚于建造一个小区,各种小 bug 那是太正常不过了,何况是微软缺乏 linux 基因,在 linux 上问题会更多。
    fiveelementgid
        34
    fiveelementgid  
    OP
       2020-11-25 01:00:01 +08:00
    @laminux29 兄弟,这是 VSC,还有.net5 在双十一晚上已经发布了稳定版了,在 windows 上没问题
    ericgui
        35
    ericgui  
       2020-11-25 01:10:25 +08:00
    @laminux29 我大微软还没找到怎么从 linux 上挣钱的办法,找到了,就立刻能超越其他任何公司,做出最牛逼、向后兼容性最牛逼的产品。
    LokiSharp
        36
    LokiSharp  
       2020-11-25 01:12:07 +08:00
    @fiveelementgid #28 Emmmm 找到记得方法 @ 我一下,我也打算用 Linux 开发 .net Core 来着,等 RHEL 8 推 .net5 正式版= =貌似目前还是用的预览版
    yexiaoxing
        37
    yexiaoxing  
       2020-11-25 01:37:26 +08:00
    嘛目前这是个 issue,https://github.com/dotnet/aspnetcore/issues/7246 可以跟踪这个的状态,或者把 openssl 升级到 1.1.1h 。自签也是一个解决方案。
    CismonX
        38
    CismonX  
       2020-11-25 01:56:28 +08:00 via iPhone
    正好相反,我倒是觉得在 Linux 上面用 VSCode 需要折腾的东西少
    fiveelementgid
        39
    fiveelementgid  
    OP
       2020-11-25 02:10:07 +08:00
    @ericgui 吐了,一直在踩雷

    @LokiSharp 解决方案正在尝试楼下老哥给的 issue.CentOS 8 对标 RHEL 8 吧,我反正用不来 RHEL,内置功能不全,基本瘸腿,我也有 RedHat 的 developer subscribe,上次用了一下 subscribe,redhat 每天疯狂往我邮箱轰炸邮件,全是[Enhancement Advisory] RHEA-2020:5088 Red Hat CodeReady Workspaces 2.5.0 release 这种推销和安全风险警告,安全风险警告源于我用了一些没签名的应用....我吐了


    @yexiaoxing 感谢!!!!我再测试一下
    fiveelementgid
        40
    fiveelementgid  
    OP
       2020-11-25 02:18:32 +08:00
    @CismonX 人已经被折腾坏了


    @yexiaoxing 根据 openssl 的工作人员说
    > @drwetter, @chrisvdb, et al.
    Finally, the fix for this issue is merged in both the OpenSSL master branch (to be released as version 3.0 in Q4 of 2020)
    and OpenSSL_1_1_1-stable (to be released with the next letter release, 1.1.1h).

    我这里也是`OpenSSL 1.1.1h FIPS 22 Sep 2020`,自签名根证书再签名应该就行了,我再去测试一下
    coldear
        41
    coldear  
       2020-11-25 02:27:49 +08:00   ❤️ 1
    为什么要在 windows 上开发 linux 系统下运行的.net? 想不通为什么要把大把时间浪费在这些无意义的地方?
    linux 平台运行就用 java 不好吗? 随便找个 linux 下可以用的 IDE ( IntelliJ, Eclipse)
    windows 平台就用 MS 技术栈,.net 加 VS 。
    fiveelementgid
        42
    fiveelementgid  
    OP
       2020-11-25 03:30:27 +08:00
    @coldear Linux 下也有 C#和.net 的 IDE 额,JetBrains 家的 Rider 就很不错,看镇楼图,今年年底应该就完全支持.net5 了,我 VS 玩的还算有点熟?既然.net 5 说了跨平台,我觉得帮忙研究看看这些兼容问题也不算无意义的地方吧,就个人而言,不太喜欢 Java 。而且 CLI 也觉得挺好玩的
    fiveelementgid
        43
    fiveelementgid  
    OP
       2020-11-25 03:32:59 +08:00
    @LokiSharp
    @yexiaoxing issue 里面的环境已经可以复现了,我贴在下边,简单来说就是自签名证书无法通过的问题
    明天再按照 openssl 的 issue 说的看一下如何解决
    睡觉了.....早上还有课,我直接 GG

    > curl -v https://localhost:5001/
    * Uses proxy env variable no_proxy == '192.168.0.0/16,localhost'
    * Trying ::1:5001...
    * Connected to localhost (::1) port 5001 (#0)
    * ALPN, offering h2
    * ALPN, offering http/1.1
    * successfully set certificate verify locations:
    * CAfile: /etc/pki/tls/certs/ca-bundle.crt
    CApath: none
    * TLSv1.3 (OUT), TLS handshake, Client hello (1):
    * TLSv1.3 (IN), TLS handshake, Server hello (2):
    * TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
    * TLSv1.3 (IN), TLS handshake, Certificate (11):
    * TLSv1.3 (OUT), TLS alert, unknown CA (560):
    * SSL certificate problem: self signed certificate
    * Closing connection 0
    curl: (60) SSL certificate problem: self signed certificate
    More details here: https://curl.haxx.se/docs/sslcerts.html

    curl failed to verify the legitimacy of the server and therefore could not
    establish a secure connection to it. To learn more about this situation and
    how to fix it, please visit the web page mentioned above.
    crclz
        44
    crclz  
       2020-11-25 09:15:23 +08:00
    开发.net 还是在 Windows 下(或者 mac )下用 VisualStudio 。跨平台 Rider 也可以。但 VSCode...就算了。IDE,重要的就是 Integrated 。Integrated 保证了 IDE 不像插件化的 VSCode 一样一盘散沙。
    quan01994
        45
    quan01994  
       2020-11-25 09:34:00 +08:00
    那你可以不用 https 啊,我开发的时候都把 https 去掉了,等到了部署的时候再去考虑 是否要 https 。反正一般我的证书都配置在 nginx 上,如果你说你要提供 grpc 这种,那就开发的时候就要 https 。
    fiveelementgid
        46
    fiveelementgid  
    OP
       2020-11-25 09:37:21 +08:00 via Android
    @crclz 重点是现在 Rider 还用不了,等年底吧

    @quan01994 反向代理理论上确实只需要反向代理的服务器挂 https,我主要还是用 Apache
    lancelock
        47
    lancelock  
       2020-11-25 11:33:20 +08:00
    我就用 rider 写,也没啥大问题
    fiveelementgid
        48
    fiveelementgid  
    OP
       2020-11-25 12:19:26 +08:00
    @lancelock emmmmm 我还是等等吧
    @yexiaoxing
    @LokiSharp
    暂时的解决方案
    > If you want to trust the certificate, you can add it to your CA certificate store or use it stand-alone as described.
    参考:https://curl.se/docs/sslcerts.html
    简单来说就 3 个方式:
    1.使用--insecure,不验证证书
    2.使用--cacert [file],这里的 file 就是上面的--nokeys 导出的,或者设计环境变量 CURL_CA_BUNDLE
    3.自己重新编译一份 openssl,因为 CA store 是在编译的时候打包进去的,所以 read only 。

    暂时先用环境变量顶着吧

    > * Trying ::1:5001...
    * Connected to localhost (::1) port 5001 (#0)
    * ALPN, offering h2
    * ALPN, offering http/1.1
    * successfully set certificate verify locations:
    * CAfile: x509stores/noprivatekey.pem
    CApath: none
    * TLSv1.3 (OUT), TLS handshake, Client hello (1):
    * TLSv1.3 (IN), TLS handshake, Server hello (2):
    * TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
    * TLSv1.3 (IN), TLS handshake, Certificate (11):
    * TLSv1.3 (IN), TLS handshake, CERT verify (15):
    * TLSv1.3 (IN), TLS handshake, Finished (20):
    * TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
    * TLSv1.3 (OUT), TLS handshake, Finished (20):
    * SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
    * ALPN, server accepted to use h2
    * Server certificate:
    * subject: CN=localhost
    * start date: Nov 23 13:05:24 2020 GMT
    * expire date: Nov 23 13:05:24 2021 GMT
    * subjectAltName: host "localhost" matched cert's "localhost"
    * issuer: CN=localhost
    * SSL certificate verify ok.
    charlie21
        49
    charlie21  
       2020-11-25 13:05:55 +08:00
    马三立!
    whywhywhy
        50
    whywhywhy  
       2020-11-25 17:25:43 +08:00
    @aloyuu 兄弟能细说一点么……目前看主要是说 java 岗位多,热度也够高,全面度也够强。

    @love 别人是这样说的,java 岗位多工资高,C#干私活效率高,爽歪歪……很是迷茫也很是矛盾啊……
    longaiwp
        51
    longaiwp  
       2020-11-26 00:31:58 +08:00
    这不是典型的拉不出屎怪茅坑?配置证书这个跟你用哪个 Linux 发行版就是密切相关的,你是想 MS 把每一个 Linux 发行版的配置方法都写一遍?
    fiveelementgid
        52
    fiveelementgid  
    OP
       2020-11-26 12:18:24 +08:00 via Android
    @longaiwp 难道不应该吗?也不要求每个发行版都有,但是不应该如同.net5 一样,各大发行版都有安装指南么
    https://docs.microsoft.com/en-us/dotnet/core/install/linux
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5726 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 02:24 · PVG 10:24 · LAX 19:24 · JFK 22:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.