小编shy*_*002的帖子

运行时下载的自签名证书的 Android N 网络安全配置

在 Android N 的 SSL 证书中,我必须添加此代码(根据给定的Android 开发人员链接

 <?xml version="1.0" encoding="utf-8"?>
 <manifest ... >
<application android:networkSecurityConfig="@xml/network_security_config"
                ... >
    ...
</application>
Run Code Online (Sandbox Code Playgroud)

以及 xml 文件夹中的文件 network_security_config.xml -

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config>
    <domain includeSubdomains="true">example.com</domain>
    <trust-anchors>
        <certificates src="@raw/my_ca"/>
    </trust-anchors>
</domain-config>
Run Code Online (Sandbox Code Playgroud)

这对于一个静态域来说工作得很好,但我的问题是——服务器域在我的应用程序中每次都不相同。第二个问题是我在运行时从我的服务器域下载 SSL 证书,所以我如何每次更新原始文件夹中的证书文件,因为我们知道我们无法在运行时在原始文件夹中写入文件。

因此,对于动态流程,我如何使用不同的证书连接到 Android N 中的服务器。

编辑1:如果我不使用此配置文件代码,我的应用程序通信将从服务器停止,所以我无论如何都需要使用此代码。

Edit2:这是我的代码,我在其中连接到我的服务器,它给我响应 200 意味着可以,无需更改 android N 的代码(旧代码)。

  CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC");

                    InputStream caInput = new BufferedInputStream(new FileInputStream(certFile));
                       X509Certificate ca =(X509Certificate) cf.generateCertificate(caInput);
                    String keyStoreType = KeyStore.getDefaultType();
                    KeyStore keyStore = KeyStore.getInstance(keyStoreType);
                    keyStore.load(null, null);
                    keyStore.setCertificateEntry("ca", ca);

                    // …
Run Code Online (Sandbox Code Playgroud)

security https android ssl-certificate android-7.0-nougat

6
推荐指数
1
解决办法
8213
查看次数

如何在 Android 设备中查找以太网连接的子网掩码、网关、DNS 值?

我有通过以太网连接的Android PC 设备手持设备。现在我能够获取设备的 IP 地址和 MAC 地址,但我还需要获取子网掩码、网关、pri-sec DNS 值。请任何人告诉我如何以编程方式找到这些值。

查找IP地址和MAC地址的代码是-

  connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        networkInfo = connectivityManager.getActiveNetworkInfo();
        networkType = networkInfo != null ? networkInfo.getTypeName() : "";
  try {
            for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
                NetworkInterface intf = en.nextElement();

                for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                    InetAddress inetAddress = enumIpAddr.nextElement();
                    if (!inetAddress.isLoopbackAddress()) {
                        ipAddress = inetAddress.getHostAddress().toString();
                        System.out.println("ipaddress=" + ipAddress + " formatter ip" + Formatter.formatIpAddress(inetAddress.hashCode()));
                    }
                }
            }
        } catch (SocketException ex) {

        } …
Run Code Online (Sandbox Code Playgroud)

dns android ethernet gateway subnet

5
推荐指数
1
解决办法
1710
查看次数

Mac 无法通过 Vmware 虚拟机连接应用商店?

我通过 Vmware 工作站版本 11.1.2 在我的 window-7 计算机上安装了 mac OS X 10.7,并且运行良好。我想下载并设置 XCode 进行编码,但无法连接应用商店。它甚至没有登录我。我尝试了此苹果链接中给出的所有解决方案。请任何人给我任何解决方案。另一件事我还尝试通过我现有的苹果ID登录苹果开发者网站,但在我点击登录后,登录后它没有显示下一个屏幕。

macos vmware-workstation ios mac-app-store

4
推荐指数
1
解决办法
2万
查看次数

如何以编程方式在奥利奥中创建wifi热点?

您好,给定的链接问题只是显示如何打开/关闭 wifi 热点,但我想添加使用 SSID 和密码创建 wifi 热点。 我编写了在 android 中创建 wifihotspot 的代码(在 NONE 和 WPA2 PSK 中),它在 android 7 之前工作正常,但在 oreo 中它返回我错误的值。我的代码的摘要是-

private WifiManager wifiManager;
private Method method;
private WifiConfiguration config;
config.SSID = ssid;
config.status = WifiConfiguration.Status.ENABLED;
method = wifiManager.getClass().getMethod("setWifiApEnabled",                                           
WifiConfiguration.class, Boolean.TYPE);
boolean status = (Boolean)  method.invoke(wifiManager, config, true);
Run Code Online (Sandbox Code Playgroud)

所以我的问题是如何为 android oreo 创建 NONE 和 WPA2 PSK 格式的 wifihotspot?是否可以?

passwords android ssid wifi wifimanager

1
推荐指数
1
解决办法
3173
查看次数